/* THE GOD TERMINAL — typing speed dialog (js/wpm.js).
 * Window chrome comes from windows.css. Heat arrives from JS as numbers on the window
 * (--wpm-heat, colour stops --wpm-a/-b/-c, title-bar --wpm-char); every colour is mixed
 * here from the palette, so all seven palettes heat up from their own accent. */

/* The palette's own values, captured before the window overrides them with hotter ones. */
:root {
  --wpm-line0: var(--line-bright);
  --wpm-glow0: var(--glow);
}

.wpm-win {
  --wpm-heat: 0;
  --wpm-a: 0;
  --wpm-b: 0;
  --wpm-c: 0;
  --wpm-char: 0;
  /* accent → orange → gold → white-hot */
  --wpm-hot: color-mix(in oklab,
    color-mix(in oklab,
      color-mix(in oklab, var(--accent), #ff7a1a calc(var(--wpm-a) * 100%)),
      #ffc14a calc(var(--wpm-b) * 100%)),
    #fff4dc calc(var(--wpm-c) * 100%));
  --line-bright: color-mix(in oklab, var(--wpm-line0), var(--wpm-hot) calc(var(--wpm-a) * 100%));
  --glow: color-mix(in srgb, var(--wpm-glow0), color-mix(in srgb, var(--wpm-hot) 72%, transparent) calc(var(--wpm-a) * 100%));
}
.wpm-win > .win-body { overflow: visible; }

/* A hot halo outside the frame, fading in from gold on up. */
.wpm-win::after {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius);
  box-shadow: 0 0 42px 4px color-mix(in srgb, var(--wpm-hot) 70%, transparent), inset 0 0 36px -10px var(--wpm-hot);
  opacity: calc(var(--wpm-b) * 0.9);
  pointer-events: none;
}

/* Charred title bar: soot blooms from the corners, embers glow along the seam. */
.wpm-win .win-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border-radius: inherit;
  background:
    radial-gradient(55% 160% at 6% 0%, rgba(0, 0, 0, 0.85), transparent 70%),
    radial-gradient(38% 140% at 64% 0%, rgba(14, 6, 2, 0.8), transparent 72%),
    radial-gradient(30% 120% at 97% 100%, rgba(0, 0, 0, 0.85), transparent 70%),
    radial-gradient(20% 90% at 34% 100%, rgba(255, 110, 30, 0.45), transparent 70%),
    linear-gradient(180deg, #24120a, #120804);
  box-shadow: inset 0 -2px 7px -2px #ff6a1a, inset 0 0 22px rgba(0, 0, 0, 0.7);
  opacity: var(--wpm-char);
  pointer-events: none;
}
.wpm-win .win-title { color: color-mix(in oklab, var(--text-bright), #ffb46a calc(var(--wpm-char) * 100%)); }
.wpm-win .win-icon { color: var(--wpm-hot); }

/* The fire canvas: drawn over the window and well past it on every side. */
.wpm-fire {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  transition: opacity 160ms ease-out;
}
.wpm-fire.is-out { opacity: 0; }

/* ───────── layout ───────── */
.wpm {
  container-type: inline-size;
  display: grid;
  gap: 1rem;
  padding: 0.2rem 0.15rem 1rem;
}

/* ───────── readout ───────── */
.wpm-readout {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0.9rem;
  padding-top: 0.35rem;
}
.wpm-readout.is-shimmer { filter: url(#wpm-shimmer); }
.wpm-odo {
  display: flex;
  font-family: var(--font-display);
  font-size: clamp(5.25rem, 24cqi, 8.5rem);
  line-height: 1;
  color: color-mix(in oklab, var(--text-bright), #fff calc(var(--wpm-c) * 100%));
  text-shadow:
    0 0 2px color-mix(in oklab, var(--text-bright), #fff 50%),
    0 0 calc(16px * var(--glow-k) + 6px) var(--wpm-hot),
    0 0 calc(40px * var(--glow-k) + 6px) color-mix(in srgb, var(--wpm-hot) calc(25% + var(--wpm-heat) * 45%), transparent);
}
/* Each drum shows one digit cell; the padding gives the glow room before the mask clips it. */
.wpm-drum {
  display: block;
  height: 1em;
  padding: 0 0.34em;
  margin: 0 -0.34em;
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 16%, #000 84%, transparent);
  mask-image: linear-gradient(180deg, transparent, #000 16%, #000 84%, transparent);
}
.wpm-strip { display: flex; flex-direction: column; will-change: transform; }
.wpm-strip > span { display: block; height: 1em; text-align: center; }
.wpm-comma { align-self: flex-end; margin: 0 0.04em 0.08em -0.04em; line-height: 1; transition: opacity 240ms; }
/* Below 1,000 the leading drum and comma are parked dim. */
.wpm-odo.is-short > .wpm-drum:first-child,
.wpm-odo.is-short > .wpm-comma { opacity: 0.16; }
.wpm-drum:first-child { transition: opacity 240ms; }
.wpm-unit {
  padding-bottom: 1.05rem;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: var(--wpm-hot);
  text-shadow: 0 0 calc(12px * var(--glow-k) + 2px) var(--wpm-hot);
}

.wpm-cpk {
  margin: -0.5rem 0 0;
  text-align: center;
  font-size: 1.0625rem;
  color: var(--text);
  text-shadow: var(--text-glow);
}
.wpm-cpk b {
  color: var(--text-bright);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ───────── slider ───────── */
.wpm-slider {
  --p: 0;
  --thumb-w: 2.5rem;
  position: relative;
  padding: 0 calc(var(--thumb-w) / 2);
  cursor: pointer;
  touch-action: none;
  outline: none;
}
.wpm-rail { position: relative; height: 3.6rem; }
.wpm-track {
  position: absolute;
  top: 50%;
  left: calc(var(--thumb-w) / -2);
  right: calc(var(--thumb-w) / -2);
  height: 1.2rem;
  translate: 0 -50%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  box-shadow: inset 0 2px 7px rgba(0, 0, 0, 0.75), 0 0 calc(16px * var(--glow-k)) calc(-6px * var(--glow-k)) var(--glow);
}
/* The full heat scale lies along the track; the fill reveals it up to the thumb. */
.wpm-fill {
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  background: linear-gradient(90deg,
    var(--accent) 0%, var(--accent) 16%, #ff8a2a 50%, #ff5a14 68%, #ffc14a 86%, #fff4dc 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -2px 4px rgba(0, 0, 0, 0.35);
  clip-path: inset(0 calc((1 - var(--p)) * (100% - var(--thumb-w) + 4px) + var(--thumb-w) / 2 - 2px) 0 0 round 999px);
  transition: clip-path 150ms cubic-bezier(.3, 1.3, .5, 1);
}
.wpm-ticks { position: absolute; inset: 0; pointer-events: none; }
.wpm-tick {
  position: absolute;
  top: 50%;
  width: 2px;
  height: 0.45rem;
  border-radius: 1px;
  translate: -50% -50%;
  background: color-mix(in srgb, var(--text) 30%, transparent);
  transition: background-color 160ms, box-shadow 160ms;
}
.wpm-tick.is-major { height: 0.8rem; background: color-mix(in srgb, var(--text) 55%, transparent); }
.wpm-tick.is-lit { background: rgba(255, 255, 255, 0.85); box-shadow: 0 0 4px rgba(0, 0, 0, 0.6); }

.wpm-thumb {
  position: absolute;
  top: 50%;
  left: calc(var(--p) * 100%);
  width: var(--thumb-w);
  height: 3.1rem;
  translate: -50% -50%;
  border: 2px solid var(--wpm-hot);
  border-radius: 11px;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 255, 255, 0.55), transparent 60%),
    linear-gradient(180deg, color-mix(in oklab, var(--text-bright), #fff 40%), color-mix(in oklab, var(--wpm-hot) 60%, var(--bg)));
  box-shadow:
    0 0 0 4px color-mix(in srgb, var(--wpm-hot) 22%, transparent),
    0 0 calc(18px * var(--glow-k) + 6px) var(--wpm-hot),
    0 8px 16px -6px rgba(0, 0, 0, 0.9);
  transition: left 150ms cubic-bezier(.3, 1.45, .5, 1), scale 170ms cubic-bezier(.2, 1.6, .4, 1);
}
/* Grip: three engraved ridges. */
.wpm-grip {
  position: absolute;
  inset: 28% 30%;
  background: repeating-linear-gradient(90deg,
    rgba(0, 0, 0, 0.42) 0 2px, rgba(255, 255, 255, 0.5) 2px 3px, transparent 3px calc((100% - 3px) / 2));
  border-radius: 1px;
}
/* From the Illegal tier up the knob burns too. */
.wpm-thumb::before {
  content: '';
  position: absolute;
  inset: -0.9rem -0.6rem;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--wpm-hot) 75%, transparent), transparent);
  opacity: var(--wpm-b);
  animation: wpm-flicker 0.37s steps(2, jump-none) infinite alternate;
  pointer-events: none;
}
@keyframes wpm-flicker { from { opacity: calc(var(--wpm-b) * 0.6); } to { opacity: var(--wpm-b); } }
.wpm-slider:hover .wpm-thumb { scale: 1.05; }
.wpm-slider.is-grabbed .wpm-thumb { scale: 1.16; }
.wpm-slider:focus-visible .wpm-thumb { outline: 2px solid var(--line-bright); outline-offset: 4px; }

/* Tier names, each under its stretch of the track. */
.wpm-tiers { position: relative; height: 2rem; margin-top: 0.1rem; }
.wpm-tier {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 2px solid color-mix(in srgb, var(--line) 80%, transparent);
  transition: border-color 200ms;
}
.wpm-tier + .wpm-tier { box-shadow: inset 1px 0 0 color-mix(in srgb, var(--line) 70%, transparent); }
.wpm-tier-name {
  display: inline-block;
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--dim);
  transition: color 200ms, text-shadow 200ms;
}
.wpm-tier.is-active { border-top-color: var(--wpm-hot); }
.wpm-tier.is-active .wpm-tier-name { color: var(--text-bright); text-shadow: 0 0 calc(10px * var(--glow-k) + 2px) var(--wpm-hot); }

/* ───────── status strip ───────── */
.wpm-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 2.75rem;
  padding: 0.3rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-strong) 60%, transparent);
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}
.wpm-status-text { display: inline-block; }
/* Thermometer: the mercury tracks the heat. */
.wpm-thermo {
  flex: none;
  width: 0.8rem;
  height: 1.85rem;
}
.wpm-thermo svg { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 0 3px var(--wpm-hot)); }
.wpm-thermo path { fill: none; stroke: currentColor; stroke-width: 1.6; }
.wpm-thermo rect,
.wpm-thermo circle { fill: var(--wpm-hot); }
.wpm-thermo rect {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  transform: scaleY(calc(0.12 + 0.88 * var(--wpm-heat)));
}
.wpm-status.is-caution {
  color: #ffd66b;
  border-color: color-mix(in srgb, #ffb43b 75%, transparent);
  background:
    repeating-linear-gradient(-45deg, rgba(255, 180, 60, 0.16) 0 12px, transparent 12px 24px),
    color-mix(in srgb, var(--panel-strong) 70%, transparent);
  text-shadow: 0 0 8px rgba(255, 180, 60, 0.6);
}
.wpm-status.is-warning {
  color: #fff;
  border-color: #ff7a1a;
  background: repeating-linear-gradient(-45deg, #e5560f 0 14px, #1a0802 14px 28px);
  background-size: 39.6px 39.6px;
  box-shadow: 0 0 22px -4px #ff6a1a, inset 0 0 14px rgba(0, 0, 0, 0.6);
  animation: wpm-hazard 0.9s linear infinite;
}
/* On the stripes, the words sit on a dark plate so they stay readable. */
.wpm-status.is-warning .wpm-status-text,
.wpm-status.is-warning .wpm-thermo {
  background-color: rgba(10, 3, 0, 0.82);
  box-shadow: 0 0 0 0.35rem rgba(10, 3, 0, 0.82);
  border-radius: 4px;
}
.wpm-status.is-warning .wpm-status-text {
  text-shadow: 0 0 10px #ff8a2a;
  animation: wpm-blink 1.1s ease-in-out infinite;
}
@keyframes wpm-hazard { to { background-position: 39.6px 0; } }
@keyframes wpm-blink { 50% { opacity: 0.7; } }

/* ───────── outside the window: firelight, steam, filter defs ───────── */
.layer-modal > .wpm-light {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle 75vmax at var(--lx, 50%) var(--ly, 50%),
    rgba(255, 150, 60, 0.42), rgba(255, 96, 24, 0.2) 24%, rgba(255, 70, 10, 0.07) 48%, transparent 72%);
  mix-blend-mode: screen;
  will-change: opacity;
}
.layer-modal > .wpm-steam { position: fixed; inset: 0; pointer-events: none; }
.wpm-puff {
  position: absolute;
  border-radius: 50%;
  background:
    radial-gradient(circle closest-side at 50% 56%, rgba(255, 255, 255, 0.95), rgba(236, 243, 248, 0.6) 45%, transparent),
    radial-gradient(circle closest-side at 28% 40%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(circle closest-side at 72% 36%, rgba(255, 255, 255, 0.65), transparent);
  mix-blend-mode: screen;
}
.wpm-puff.is-smoke {
  background:
    radial-gradient(circle closest-side at 50% 56%, rgba(150, 140, 132, 0.85), rgba(110, 102, 96, 0.4) 50%, transparent),
    radial-gradient(circle closest-side at 30% 40%, rgba(140, 130, 124, 0.6), transparent);
  mix-blend-mode: normal;
}
.wpm-puff.is-flash {
  border-radius: 30%;
  background: radial-gradient(closest-side, rgba(255, 255, 255, 0.9), rgba(235, 244, 250, 0.45) 55%, transparent);
}
.wpm-defs { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }

/* ───────── narrow windows ───────── */
@container (max-width: 26rem) {
  .wpm-unit { font-size: 1.25rem; padding-bottom: 0.8rem; }
  .wpm-cpk { font-size: 0.9375rem; }
  .wpm-tier-name { letter-spacing: 0.04em; }
  .wpm-status { gap: 0.55rem; padding: 0.3rem 0.6rem; font-size: 0.8125rem; letter-spacing: 0.05em; }
}

/* ───────── reduced motion: steady glow, no flicker or blinking ───────── */
html[data-reduced-motion="on"] .wpm-thumb::before,
html[data-reduced-motion="on"] .wpm-status.is-warning,
html[data-reduced-motion="on"] .wpm-status.is-warning .wpm-status-text { animation: none; }
html[data-reduced-motion="on"] .wpm-thumb { transition-duration: 90ms; transition-timing-function: ease-out; }
html[data-reduced-motion="on"] .wpm-fill { transition: none; }
