/* =============================================================================
   Torchtimer styles
   ============================================================================= */

:root {
  --torch-head-bg: linear-gradient(
    to bottom,
    #3a2210 0%,
    #26160a 50%,
    #1c1006 100%
  );
}

/* App-specific reset */
/*--------------------*/

html, body {
  height: 100%;
}

a {
  color: var(--ll-accent);
  text-decoration-color: currentColor;
}

a:hover {
  color: var(--ll-accent-hover);
}

body {
  background: var(--ll-bg);
  color: var(--ll-text);
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Full-screen flame overlay canvas */
/*----------------------------------*/

#flame-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: screen;
}
[data-theme="light"] #flame-overlay {
  mix-blend-mode: multiply;
}

/* Page content sits above smoke/glow; glow element above content for ambient bleed */
/*----------------------------------------------------------------------------------*/

header, main, #global-bar, footer {
  position: relative;
  z-index: 2;
}

/* Flame particles render on top of everything */
/*---------------------------------------------*/

#fire-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

/* Stage */
/*-------*/

#stage {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 200px 32px;
  max-width: 1400px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  padding: 370px 16px 24px;
}

/* Torch unit */
/*------------*/

.torch-unit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 300px;
}
.torch-unit.dragging {
  z-index: 10;
}
.btn-add-torch-unit {
  position: absolute;
  top: -100px;
  right: 6px;
  border: none;
  background: none;
  color: var(--ll-text-muted);
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 0;
  padding: 0 0 5px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  z-index: 5;
}
.btn-add-torch-unit:hover:not(:disabled) {
  color: #f5a848;
  background: none;
}

/* Label */
/*-------*/

.torch-label {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.torch-name {
  font-size: 1rem;
  color: var(--ll-text-muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  outline: none;
  border-bottom: 1px solid transparent;
  padding: 2px 6px;
  border-radius: 2px;
  cursor: text;
  display: inline-block;
  min-width: 40px;
}
.torch-name:focus {
  border-bottom-color: var(--ll-border);
  color: var(--ll-text);
}

/* Visual area */
/*-------------*/

.torch-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: grab;
  transform-origin: center bottom;
}
.torch-unit.dragging .torch-visual {
  cursor: grabbing;
}

/* Ambient glow: 1x1px at emitter, position + box-shadow updated each frame by JS */
/*--------------------------------------------------------------------------------*/

.torch-glow {
  position: fixed;
  width: 1px;
  height: 1px;
  pointer-events: none;
  border-radius: 50%;
  z-index: 3;
}
.torch-unit.unlit .torch-glow {
  display: none;
}

/* Torch body CSS shapes */
/*-----------------------*/

.torch-body {
  position: relative;
  width: 45px;
  height: 195px;
  margin: 0 auto;
  z-index: 1;
}
.torch-head {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 39px;
  height: 72px;
  background: var(--torch-head-bg);
  border-radius: 6px 6px 3px 3px;
  z-index: 2;
  overflow: hidden;
}
.torch-head::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/></filter><rect width='200' height='200' filter='url(%23n)'/></svg>");
  background-size: 70px 70px;
  mix-blend-mode: overlay;
  opacity: 0.95;
  pointer-events: none;
}
.torch-stick {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 21px;
  height: 135px;
  background: linear-gradient(to right, #3c1e08, #7a4018, #3c1e08);
  clip-path: path("M 3 0 L 18 0 L 21 122 A 10.5 13 0 0 1 0 122 Z");
  z-index: 1;
}
.torch-stick::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/></filter><rect width='200' height='200' filter='url(%23n)'/></svg>");
  background-size: 60px 60px;
  mix-blend-mode: overlay;
  opacity: 0.85;
  pointer-events: none;
}
/* Flame-light overlay; same shape, position, and SVG displacement filter as
   the stick so its edges align with the displaced stick beneath. */
/*----------------------------------------------------------------*/

.torch-stick-light {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 21px;
  height: 135px;
  clip-path: path("M 3 0 L 18 0 L 21 122 A 10.5 13 0 0 1 0 122 Z");
  pointer-events: none;
  z-index: 1;
}
.torch-unit.dead .torch-head {
  background: linear-gradient(to bottom, #221408 0%, #140e04 100%);
}

/* Torch head top-fade glow; gradient element, top bright -> transparent bottom */
/*------------------------------------------------------------------------------*/

.torch-head-glow {
  position: absolute;
  top: -22px;
  left: -24px;
  right: -24px;
  bottom: 0;
  pointer-events: none;
  mix-blend-mode: screen;
  z-index: 3;
}

.torch-crack-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: 6px 6px 3px 3px;
  z-index: 1;
}

/* Timer display */
/*---------------*/

.torch-timer-display {
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  color: var(--ll-text);
  letter-spacing: 0.04em;
  font-weight: 300;
  min-height: 1.5em;
  text-align: center;
}
.torch-timer-display.hidden {
  visibility: hidden;
}
.torch-unit.unlit .torch-timer-display {
  cursor: pointer;
}
.torch-unit.unlit .torch-timer-display:hover {
  color: #f5a848;
}
.torch-unit.unlit .torch-timer-display::after {
  content: " ▾";
  font-size: 1.5em;
  opacity: 0.8;
  display: inline-block;
  line-height: 0;
  transform: translateY(0.1em);
}
.torch-unit.paused .torch-timer-display {
  opacity: 0.45;
}
.torch-timer-display.critical {
  color: #c55;
}

/* Controls */
/*----------*/

.torch-controls,
.torch-controls-secondary {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}
.btn-remove {
  flex-basis: 100%;
}
#stage.viewer-mode .torch-controls,
#stage.viewer-mode .torch-controls-secondary {
  display: none;
}
#stage.viewer-mode .torch-unit.unlit .torch-timer-display {
  cursor: default;
}
#stage.viewer-mode .torch-unit.unlit .torch-timer-display:hover {
  color: inherit;
}
#stage.viewer-mode .torch-unit.unlit .torch-timer-display::after {
  content: none;
}

/* Buttons */
/*---------*/

button {
  cursor: pointer;
  border: 1px solid var(--ll-accent);
  background: transparent;
  color: var(--ll-accent);
  border-radius: var(--ll-radius);
  padding: 0.5rem 1rem;
  font-size: 1rem;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) {
  background: var(--ll-accent);
  color: var(--ll-bg);
  border-color: var(--ll-accent);
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button:focus-visible {
  outline: 2px solid var(--ll-accent);
  outline-offset: 2px;
}

.btn-light {
  background: var(--ll-accent);
  border-color: var(--ll-accent);
  color: var(--ll-bg);
  font-weight: 500;
}
.btn-light:hover:not(:disabled) {
  background: var(--ll-accent-hover);
  border-color: var(--ll-accent-hover);
  color: var(--ll-bg);
}

.btn-light.btn-extinguish {
  background: none;
  border-color: #c55;
  color: #c55;
}
.btn-light.btn-extinguish:hover:not(:disabled) {
  background: #c55;
  border-color: #c55;
  color: #fff;
}

.btn-remove {
  background: none;
  border: none;
  color: var(--ll-text-muted);
  font-size: 1.25rem;
  padding: 0.25rem 0.5rem;
}
.btn-remove:hover:not(:disabled) {
  color: #ff5555;
  background: none;
  border-color: transparent;
}

.btn-flame-color {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid var(--ll-border);
  background: #ffb43c;
  flex-shrink: 0;
}
.btn-flame-color:hover:not(:disabled) {
  border-color: var(--ll-text);
  /* background intentionally not overridden; inline style has the swatch color */
}
.btn-flame-reset {
  background: none;
  border: none;
  color: var(--ll-text-muted);
  font-size: 0.85rem;
  padding: 0;
  line-height: 1;
}
.btn-flame-reset:hover:not(:disabled) {
  color: var(--ll-text);
  background: none;
  border-color: transparent;
}
.flame-color-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* Duration select; hidden but rendered so showPicker() works */
/*------------------------------------------------------------*/

.duration-select {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

/* Global bar */
/*------------*/

#global-bar button {
  font-size: 0.875rem;
  padding: 0.4rem 0.9rem;
}
#global-bar-multi {
  display: flex;
  gap: 8px;
  flex-basis: 100%;
  justify-content: center;
}
#global-bar-multi[hidden] {
  display: none;
}
#global-bar-row2 {
  display: flex;
  gap: 8px;
  flex-basis: 100%;
  justify-content: center;
}

#global-bar-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px;
}

/* Live badge */
/*------------*/

#header-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
}

#live-badge {
  flex-basis: 100%;
  text-align: right;
  padding: 0.3rem 0 0;
  font-size: 11px;
  color: #4a9;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  display: block;
}
#live-badge::before {
  content: "●";
  font-size: 8px;
  margin-right: 6px;
  animation: pulse-dot 2s infinite;
}
#live-badge.reconnecting,
#live-badge.ended {
  color: var(--ll-muted);
}
#live-badge.ended::before {
  animation: none;
}
@keyframes pulse-dot {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* QR modal */
/*----------*/

#qr-modal-content {
  display: flex;
  justify-content: center;
  padding: 12px 0 20px;
}
#qr-modal-content svg {
  width: 220px;
  height: 220px;
  border: 8px solid #fff;
  border-radius: 4px;
  background: #fff;
  display: block;
}
#qr-modal-close {
  flex: 1;
  margin-top: 8px;
}

/* Toast */
/*-------*/

#toast {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: rgba(20, 16, 12, 0.97);
  border: 1px solid var(--ll-border);
  border-radius: 8px;
  padding: 12px 28px;
  font-size: 28px;
  font-weight: 600;
  color: var(--ll-text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 100;
  white-space: normal;
  max-width: calc(100vw - 2rem);
  text-align: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}
#toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Pass Time modal */
/*-----------------*/

#pass-time-modal,
#custom-duration-modal,
#confirm-remove-modal,
#qr-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
#pass-time-modal[hidden],
#custom-duration-modal[hidden],
#confirm-remove-modal[hidden],
#qr-modal[hidden] {
  display: none;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}
.modal-inner {
  position: relative;
  background: #1a1510;
  border: 1px solid var(--ll-border);
  border-radius: 8px;
  padding: 22px 24px 20px;
  width: 360px;
  z-index: 1;
}
[data-theme="light"] .modal-inner {
  background: var(--ll-surface);
}
.modal-inner h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--ll-text);
  margin-bottom: 20px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.modal-quick-btns {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
}
.modal-quick-btns button {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.5rem;
}
.modal-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 20px;
}
.modal-input-row input {
  flex: 0 0 76px;
  width: 96px;
  min-width: 0;
  background: transparent;
  border: 1px solid var(--ll-border);
  border-radius: var(--ll-radius);
  color: var(--ll-text);
  padding: 0.4rem 0.5rem;
  font-size: 1rem;
  text-align: center;
}
.modal-input-row input:focus {
  outline: none;
  border-color: var(--ll-accent);
}
.modal-time-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.modal-time-label {
  font-size: 0.75rem;
  color: var(--ll-muted);
  white-space: nowrap;
}
#modal-apply {
  flex: 1;
  align-self: flex-start;
  margin-left: auto;
  height: 76px;
}
.modal-body-text {
  font-size: 0.9rem;
  color: var(--ll-text);
  margin-bottom: 20px;
  line-height: 1.5;
}
.modal-footer {
  display: flex;
  gap: 8px;
}
#modal-apply, #custom-duration-apply, #btn-go-live {
  border-color: #4a9;
  color: #4a9;
}
#modal-apply:hover:not(:disabled),
#custom-duration-apply:hover:not(:disabled),
#btn-go-live:hover:not(:disabled) {
  background: #4a9;
  color: #111;
}
#btn-go-live.live-active {
  border-color: #c55;
  color: #c55;
}
#btn-go-live.live-active:hover:not(:disabled) {
  background: #c55;
  color: #fff;
}
#modal-cancel,
#custom-duration-cancel,
#confirm-remove-cancel {
  border-color: #c55;
  color: #c55;
  flex: 1;
}
#modal-cancel:hover:not(:disabled),
#custom-duration-cancel:hover:not(:disabled),
#confirm-remove-cancel:hover:not(:disabled) {
  background: #c55;
  color: #fff;
}
#confirm-remove-ok {
  border-color: #c55;
  color: #c55;
  flex: 1;
}
#confirm-remove-ok:hover:not(:disabled) {
  background: #c55;
  color: #fff;
}

/* Noscript */
/*----------*/

.noscript-notice {
  padding: 40px;
  text-align: center;
  color: var(--ll-text);
}

/* Dungeon Mode */
/*--------------*/

#dungeon-vignette {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.97);
  /* Two mask layers punch independent transparent holes: cursor spotlight + grabbed torch head.
     intersect (multiply) of the two masks means either hole reveals the content beneath. */
  mask-image:
    radial-gradient(
      circle 350px at var(--cursor-x, 50%) var(--cursor-y, 50%),
      transparent 0%,
      black 75%
    ),
    radial-gradient(
    circle 500px at var(--torch-x, -9999px) var(--torch-y, -9999px),
    transparent 0%,
    black 75%
  );
  mask-composite: intersect;
  -webkit-mask-image:
    radial-gradient(
      circle 350px at var(--cursor-x, 50%) var(--cursor-y, 50%),
      transparent 0%,
      black 75%
    ),
    radial-gradient(
    circle 500px at var(--torch-x, -9999px) var(--torch-y, -9999px),
    transparent 0%,
    black 75%
  );
  -webkit-mask-composite: destination-in;
}
body.dungeon-mode #dungeon-vignette {
  display: block;
}
body.dungeon-mode #btn-timer-toggle {
  background: #f5a848;
  border-color: #f5a848;
  color: #1a1a1a;
}
body.dungeon-mode #theme-toggle:disabled {
  cursor: not-allowed;
}
body.dungeon-mode #btn-timer-toggle:hover {
  background: #a8650a;
  border-color: #a8650a;
  color: #fff;
}
body.dungeon-mode main {
  /* Break main's stacking context so torch-visual can float above the vignette */
  z-index: auto;
}
body.dungeon-mode .torch-visual {
  /* Torch visual and glow always visible above vignette */
  z-index: 15;
}
body.dungeon-mode .torch-glow {
  z-index: 15;
}
body.dungeon-mode #flame-overlay {
  z-index: 15;
}

/* Responsive */
/*------------*/

@media (max-width: 768px) {
  #stage {
    padding-top: 180px;
  }
}
@media (max-width: 479px) {
  #stage {
    flex-direction: column;
    gap: 220px;
  }
  .torch-unit {
    width: min(300px, 88vw);
  }
}
