/* =============================================================================
   torch.css: The torch component: stage layout, unit, label, visual area,
   ambient glow, CSS-shape body, head glow, crack canvas, and the timer display.
   ============================================================================= */

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

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

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

.torch-unit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 300px;
  user-select: none;
  -webkit-user-select: none;
}
.torch-unit.dragging {
  z-index: 10;
}
.btn-add-torch-unit {
  position: absolute;
  top: -100px;
  right: 6px;
  border: none;
  background: none;
  color: var(--rb-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(--rb-text-muted);
  letter-spacing: 0.1em;
  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(--rb-border);
  color: var(--rb-text);
  user-select: text;
  -webkit-user-select: text;
}

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

.torch-visual {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: grab;
  transform-origin: center bottom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
}
.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 {
  position: relative;
  font-size: 2rem;
  font-variant-numeric: tabular-nums;
  color: var(--rb-text);
  letter-spacing: 0.04em;
  font-weight: 300;
  min-height: 1.5em;
  text-align: center;
  white-space: nowrap;
}
.torch-timer-display.hidden {
  display: none;
}
.torch-unit.unlit .torch-timer-display,
.torch-unit.dead .torch-timer-display {
  cursor: pointer;
}
.torch-unit.unlit .torch-timer-display:hover,
.torch-unit.dead .torch-timer-display:hover {
  color: #f5a848;
}
.torch-unit.unlit .torch-timer-display::after,
.torch-unit.dead .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;
}
