/* The hero is the shared .hero.piece.is-compact (styles.css). */

/* ── DEVICE ── */
.device-section {
  display: flex;
  justify-content: center;
  padding: 1rem 1.5rem 2rem;
}

.device {
  --inset: #0a0a0a;
  width: 100%;
  max-width: 1000px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  padding: 1rem;
  box-shadow:
    0 0 0 6px #060606,
    0 0 0 7px var(--border),
    0 24px 70px rgba(0, 0, 0, 0.65);
}

.device-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 0.75rem;
}

/* The creature on the left (stage, vitals, history), what you do to it and
   what it says back on the right. Built to fit one desktop screen. */
.col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.panel {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  min-width: 0;
}

.panel-label {
  font-family: 'Sixtyfour Convergence', sans-serif;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted2);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── STAGE ── */
.stage-panel {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.6rem;
}

/* Layers, back to front: scene, wipe, opponent, pet, battle HUD, text. */
.stage {
  --wipe-ms: 420ms;
  position: relative;
  width: 100%;
  max-width: 310px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  background: var(--inset);
  border: 1px solid var(--border2);
  border-radius: 10px;
  overflow: hidden;
  isolation: isolate;
}

.scene-stack {
  position: absolute;
  inset: 0;
  z-index: 0;
  transition: filter 12s ease;
}

.stage-scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  visibility: hidden;
}

.stage-scene.is-active {
  opacity: 1;
  visibility: visible;
}

/* Ambient motion is paused in any scene that is not showing. */
.stage-scene:not(.is-active) * {
  animation-play-state: paused !important;
}

/* Zone change: a stepped scanline wipe over the scene only, so the
   creature stays in view the whole time. */
.stage-wipe {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-100%);
  background: repeating-linear-gradient(to bottom,
      rgba(10, 10, 10, 0.97) 0,
      rgba(10, 10, 10, 0.97) 3px,
      rgba(69, 224, 166, 0.16) 3px,
      rgba(69, 224, 166, 0.16) 4px);
}

.stage.is-wiping .stage-wipe {
  animation: stage-wipe var(--wipe-ms) steps(10, end);
}

@keyframes stage-wipe {
  0% { opacity: 1; transform: translateY(-100%); }
  50% { opacity: 1; transform: translateY(0); }
  100% { opacity: 1; transform: translateY(100%); }
}

.pet-slot {
  position: absolute;
  z-index: 3;
  left: 21%;
  top: 28%;
  width: 58%;
  height: 58%;
  transition: left 0.5s ease, top 0.5s ease, width 0.5s ease, height 0.5s ease;
}

.enemy-slot {
  position: absolute;
  z-index: 2;
  right: 4%;
  top: 36%;
  width: 46%;
  height: 46%;
  opacity: 0;
  transform: translateX(30%);
  transition: opacity 0.5s ease, transform 0.5s ease;
  pointer-events: none;
}

.stage.is-battle .pet-slot {
  left: 4%;
  top: 36%;
  width: 46%;
  height: 46%;
}

.stage.is-battle .enemy-slot {
  opacity: 1;
  transform: translateX(0);
}

/* The idle bounce and colour come from the creature's condition. JS sets
   these four properties from GAME_CONFIG.spriteStates. */
.pet-sprite {
  --bob: 4;
  --bob-speed: 2.2s;
  --sat: 1;
  --bright: 1;
  width: 100%;
  height: 100%;
  animation: pet-idle var(--bob-speed) ease-in-out infinite;
  filter: saturate(var(--sat)) brightness(var(--bright));
  transition: filter 0.8s ease, opacity 2.4s ease, translate 0.35s ease-out;
  translate: var(--look-x, 0px) var(--look-y, 0px);
}

@keyframes pet-idle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(calc(var(--bob) * -1%)); }
}

.pet-sprite.is-stutter {
  animation-timing-function: steps(3, end);
}

.pet-sprite.is-flicker .pet-body svg {
  animation: pet-flicker 2.8s steps(1, end) infinite;
}

@keyframes pet-flicker {
  0%, 100% { opacity: 1; }
  11% { opacity: 0.5; }
  13% { opacity: 1; }
  58% { opacity: 0.72; }
  61% { opacity: 1; }
}

.pet-body,
.enemy-body {
  width: 100%;
  height: 100%;
  transform-origin: 50% 85%;
}

.pet-body { --dir: 1; }
.enemy-body { --dir: -1; }

.pet-body svg,
.enemy-body svg {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* ── REACTIONS ──
   One class per reaction key in GAME_CONFIG.reactions. The duration comes
   from config through --react-ms. --dir mirrors moves for the opponent. */
.react-strain { animation: react-strain var(--react-ms, 0.8s) ease-in-out; }
.react-flinch { animation: react-flinch var(--react-ms, 0.55s) ease-out; }
.react-settle { animation: react-settle var(--react-ms, 1.3s) ease-in-out; }
.react-shiver { animation: react-shiver var(--react-ms, 0.9s) linear; }
.react-hop { animation: react-hop var(--react-ms, 0.8s) ease-out; }
.react-hit { animation: react-hit var(--react-ms, 0.45s) linear; }
.react-lunge { animation: react-lunge var(--react-ms, 0.36s) ease-in-out; }
.react-change { animation: react-change var(--react-ms, 1.2s) steps(12, end); }
.react-hatch { animation: react-hatch var(--react-ms, 1.1s) steps(8, end); }
.react-fall { animation: react-fall var(--react-ms, 0.7s) ease-in forwards; }
.react-poke { animation: react-poke var(--react-ms, 0.42s) ease-out; }
/* Giving up in a fight: it draws back and lowers, and stays there until the
   next reaction replaces it. */
.react-yield { animation: react-yield var(--react-ms, 0.7s) ease-out forwards; }
@keyframes react-yield { to { transform: translate(calc(-8% * var(--dir, 1)), 6%) scaleY(0.9); filter: brightness(0.8); } }

.pet-sprite { cursor: pointer; }
.stage.is-gone .pet-sprite { cursor: default; }

@keyframes react-poke {
  0%, 100% { transform: none; }
  25% { transform: scale(1.18, 0.78); }
  55% { transform: scale(0.92, 1.1); }
  80% { transform: scale(1.04, 0.97); }
}

@keyframes react-strain {
  0%, 100% { transform: none; }
  18% { transform: scale(1.12, 0.84); }
  30% { transform: scale(1.12, 0.84) translateX(-2%); }
  40% { transform: scale(1.12, 0.84) translateX(2%); }
  50% { transform: scale(1.12, 0.84) translateX(-2%); }
  60% { transform: scale(1.1, 0.86) translateX(1%); }
  80% { transform: scale(0.94, 1.08); }
}

@keyframes react-flinch {
  0%, 100% { transform: none; }
  15% { transform: translateX(calc(var(--dir) * -7%)) scale(0.94, 1.04); }
  35% { transform: translateX(calc(var(--dir) * -5%)) scale(0.96, 1.02); }
}

@keyframes react-settle {
  0%, 100% { transform: none; }
  35% { transform: scale(1.06, 0.92); }
  65% { transform: scale(1.03, 0.96); }
}

@keyframes react-shiver {
  0%, 100% { transform: none; }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-1.5%); }
  20%, 40%, 60%, 80% { transform: translateX(1.5%); }
}

@keyframes react-hop {
  0%, 100% { transform: none; }
  25% { transform: translateY(-14%) scale(0.96, 1.06); }
  50% { transform: translateY(0) scale(1.08, 0.92); }
  70% { transform: translateY(-5%); }
}

@keyframes react-hit {
  0%, 100% { transform: none; filter: none; }
  10% { transform: translateX(calc(var(--dir) * -5%)); filter: brightness(2.6) saturate(0); }
  30% { transform: translateX(calc(var(--dir) * 3%)); filter: none; }
  50% { transform: translateX(calc(var(--dir) * -2%)); }
}

@keyframes react-lunge {
  0%, 100% { transform: none; }
  45% { transform: translateX(calc(var(--dir) * 22%)); }
}

@keyframes react-change {
  0%, 100% { transform: none; filter: none; }
  15% { filter: brightness(3) saturate(0); }
  30% { transform: scale(0.85); filter: none; }
  45% { transform: scale(1.1); filter: brightness(3) saturate(0); }
  60% { transform: scale(0.95); filter: none; }
  75% { filter: brightness(2) saturate(0); }
}

@keyframes react-hatch {
  0% { transform: scale(0.2); opacity: 0; }
  40% { transform: scale(0.6, 0.5); opacity: 1; }
  70% { transform: scale(1.1, 0.9); }
  100% { transform: none; }
}

@keyframes react-fall {
  0% { transform: none; opacity: 1; }
  100% { transform: translateY(12%) rotate(calc(var(--dir) * -80deg)) scale(0.9); opacity: 0.25; }
}

/* ── ATMOSPHERE ── */
/* Staring at the way out: the idle bounce keeps going and it shakes on top. */
.pet-sprite.is-fixated {
  animation: pet-idle var(--bob-speed) ease-in-out infinite, pet-shiver 0.11s steps(1, end) infinite;
}

@keyframes pet-shiver {
  0% { translate: calc(var(--look-x, 0px) - 3px) calc(var(--look-y, 0px) + 1px); rotate: -2deg; }
  25% { translate: calc(var(--look-x, 0px) + 3px) calc(var(--look-y, 0px) - 1px); rotate: 2deg; }
  50% { translate: calc(var(--look-x, 0px) - 2px) calc(var(--look-y, 0px) - 2px); rotate: 1deg; }
  75% { translate: calc(var(--look-x, 0px) + 2px) calc(var(--look-y, 0px) + 2px); rotate: -1deg; }
  100% { translate: calc(var(--look-x, 0px) - 3px) calc(var(--look-y, 0px) + 1px); rotate: -2deg; }
}

/* Once Quiet Mother has fallen the room starts to go wrong: the edges close
   in, the colour drifts and now and then the picture tears. */
.stage-decay {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  overflow: hidden;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(0, 0, 0, 0.55) 100%);
  transition: opacity 4s ease;
}

.stage-decay::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 20%;
  height: 5px;
  opacity: 0;
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 -3px 0 rgba(255, 90, 110, 0.12), 0 3px 0 rgba(90, 200, 255, 0.12);
}

.stage[data-freedom="open"] .stage-decay {
  opacity: 1;
  animation: decay-pulse 5s ease-in-out infinite;
}

.stage[data-freedom="open"] .stage-decay::before { animation: decay-tear 9s linear infinite; }

.stage[data-freedom="open"] .stage-scene.is-active {
  filter: saturate(0.8) hue-rotate(-12deg);
  transition: filter 6s ease;
}

@keyframes decay-pulse { 50% { opacity: 0.75; } }

@keyframes decay-tear {
  0%, 90%, 100% { opacity: 0; top: 20%; }
  91% { opacity: 1; top: 34%; }
  92% { opacity: 0; top: 36%; }
  94% { opacity: 1; top: 62%; }
  95% { opacity: 0; top: 63%; }
}

/* ── STAGE EFFECTS ── */
/* Short, over in half a second, and played alongside the reaction. */
.stage-fx {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0;
}

@keyframes fx-flash { 0% { opacity: 0; } 30% { opacity: 0.85; } 100% { opacity: 0; } }
@keyframes fx-soft { 0% { opacity: 0; } 35% { opacity: 1; } 100% { opacity: 0; } }

/* the lamp goes out */
.stage.fx-dark .stage-fx { background: #000; animation: fx-flash 0.5s ease; }

/* something warm */
.stage.fx-warm .stage-fx {
  background: radial-gradient(circle at 50% 70%, rgba(255, 200, 120, 0.6), transparent 65%);
  animation: fx-soft 0.55s ease;
}

/* nerve tuning: the picture breaks up and the creature splits in colour */
.stage.fx-static .stage-fx {
  background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.22) 0 1px, transparent 1px 3px);
  animation: fx-static 0.45s steps(5);
}

.stage.fx-static .pet-body svg {
  filter: drop-shadow(2px 0 rgba(255, 40, 80, 0.9)) drop-shadow(-2px 0 rgba(0, 200, 255, 0.9));
  animation: fx-glitch 0.45s steps(5);
}

@keyframes fx-static {
  0% { opacity: 0.9; background-position: 0 0; }
  25% { opacity: 0.2; background-position: 0 5px; }
  50% { opacity: 0.85; background-position: 0 -3px; }
  75% { opacity: 0.25; background-position: 0 8px; }
  100% { opacity: 0; }
}

@keyframes fx-glitch {
  0%, 100% { transform: none; }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px) skewX(6deg); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px) skewX(-4deg); }
}

/* the cold room */
.stage.fx-frost .stage-fx {
  background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(170, 215, 255, 0.55) 100%), rgba(120, 170, 255, 0.18);
  box-shadow: inset 0 0 18px rgba(220, 240, 255, 0.7);
  animation: fx-soft 0.6s ease;
}

.stage.fx-frost .pet-body svg { filter: saturate(0.4) brightness(1.25); }

/* worked past failure */
.stage.fx-strain { animation: stage-shake-heavy 0.3s linear; }
.stage.fx-strain .stage-fx { background: rgba(255, 50, 70, 0.45); animation: fx-soft 0.35s ease; }

/* drills */
.stage.fx-tick { animation: stage-shake 0.18s linear; }

/* the machine that lengthens the frame */
.stage.fx-stretch .pet-body svg { transform-origin: 50% 100%; animation: fx-stretch 0.5s ease; }
@keyframes fx-stretch { 0%, 100% { transform: none; } 40% { transform: scaleY(1.28) scaleX(0.9); } }

/* ── THE WALL ── */
/* A scratch per life that came before. The newest is cut in. */
#tally .tally-new {
  transform-box: fill-box;
  transform-origin: 50% 0;
  animation: scratch 0.9s steps(5) both;
}

@keyframes scratch { from { transform: scaleY(0); opacity: 0.2; } to { transform: none; opacity: 1; } }

/* ── HOLD TO FREE ── */
.free-btn {
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.free-btn::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: rgba(159, 214, 255, 0.28);
  transition: width 0.15s ease;
  pointer-events: none;
}

.free-btn.is-holding::before {
  width: 100%;
  transition: width var(--hold-ms, 1.6s) linear;
}

.pet-sprite.is-straining {
  animation: pet-idle var(--bob-speed) ease-in-out infinite, pet-strain 0.06s steps(1, end) infinite;
}

@keyframes pet-strain {
  0%, 100% { translate: calc(var(--look-x, 0px) - 6px) calc(var(--look-y, 0px) + 2px); rotate: -4deg; }
  25% { translate: calc(var(--look-x, 0px) + 6px) calc(var(--look-y, 0px) - 2px); rotate: 4deg; }
  50% { translate: calc(var(--look-x, 0px) - 4px) calc(var(--look-y, 0px) - 4px); rotate: 2deg; }
  75% { translate: calc(var(--look-x, 0px) + 4px) calc(var(--look-y, 0px) + 4px); rotate: -2deg; }
}

.stage.is-holding .stage-decay {
  opacity: 1;
  background: radial-gradient(ellipse at center, transparent 20%, rgba(0, 0, 0, 0.8) 100%);
}

/* ── GAME FEEL ── */
/* The room darkens as the days run out. Before the end-of-life rules so
   those still win. */
.stage[data-phase="mid"] .scene-stack { filter: brightness(0.92); }
.stage[data-phase="late"] .scene-stack { filter: brightness(0.78) saturate(0.85); }

/* Blows land. */
.stage.is-shake { animation: stage-shake 0.18s linear; }
.stage.is-shake-heavy { animation: stage-shake-heavy 0.28s linear; }

@keyframes stage-shake {
  0%, 100% { transform: none; }
  25% { transform: translate(-2px, 1px); }
  50% { transform: translate(2px, -1px); }
  75% { transform: translate(-1px, 0); }
}

@keyframes stage-shake-heavy {
  0%, 100% { transform: none; }
  15% { transform: translate(-5px, 2px); }
  35% { transform: translate(5px, -3px); }
  55% { transform: translate(-4px, 2px); }
  75% { transform: translate(3px, -1px); }
}

/* The opponent's name, once, before the first blow. */
.stage-banner.is-intro {
  color: var(--text);
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* Ladder pips: one diamond per rung, the last pulsing once the way out is open. */
.pips {
  display: flex;
  gap: 6px;
  height: 10px;
  align-items: center;
  margin-top: 0.3rem;
  padding-left: 2px;
}

.pips i {
  width: 7px;
  height: 7px;
  border: 1px solid var(--muted2);
  transform: rotate(45deg);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.pips i.is-on { background: var(--text); border-color: var(--text); }

.pips i.is-open {
  background: #b9e0ff;
  border-color: #b9e0ff;
  box-shadow: 0 0 8px rgba(159, 214, 255, 0.7);
  animation: pip-pulse 1.8s ease-in-out infinite;
}

@keyframes pip-pulse { 50% { box-shadow: 0 0 2px rgba(159, 214, 255, 0.3); } }

/* The thirty days, as a strip under the day count. */
.day-strip {
  display: block;
  height: 3px;
  margin-top: 0.3rem;
  background: var(--inset);
  border-radius: 2px;
  overflow: hidden;
}

.day-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--muted2);
  transition: width 0.45s ease, background-color 0.45s ease;
}

.day-fill[data-phase="mid"] { background: #ffe66d; }
.day-fill[data-phase="late"] { background: #ff5d73; }

/* ── END OF LIFE ── */
.stage.is-ending .scene-stack {
  filter: brightness(0.55) saturate(0.4);
}

.stage.is-ending .pet-sprite {
  --bob: 0.4 !important;
  --bob-speed: 6s !important;
  filter: saturate(0.15) brightness(0.6);
  transition: filter 16s ease, opacity 2.4s ease;
}

.stage.is-gone .pet-sprite {
  animation: none;
  filter: grayscale(1) brightness(0.45);
  opacity: 0.5;
}

.stage.is-gone .pet-body svg {
  animation: none;
}

/* ── BATTLE HUD ── */
.battle-hud {
  position: absolute;
  z-index: 4;
  left: 6%;
  right: 6%;
  top: 6%;
  display: flex;
  justify-content: space-between;
  gap: 10%;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.stage.is-battle .battle-hud {
  opacity: 1;
}

.hud-side {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.hud-enemy {
  align-items: flex-end;
  text-align: right;
}

.hud-name {
  font-family: 'VT323', monospace;
  font-size: 16px;
  line-height: 1;
  color: var(--text);
  text-shadow: 0 0 4px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.hud-bar {
  display: block;
  width: 100%;
  height: 6px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border2);
  border-radius: 3px;
  overflow: hidden;
}

.hud-fill {
  display: block;
  height: 100%;
  width: 100%;
  background: #45e0a6;
  transition: width 0.25s steps(4, end);
}

.hud-enemy .hud-fill {
  background: #ff5d73;
  margin-left: auto;
}

.stage-banner {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: 40%;
  text-align: center;
  font-family: 'VT323', monospace;
  font-size: clamp(2rem, 9vw, 3rem);
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--text);
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.9), 0 0 2px #000;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.stage-banner.is-show { opacity: 1; transform: scale(1); }
.stage-banner.is-win { color: #ffe66d; }
.stage-banner.is-loss { color: #ff5d73; }

.stage-caption {
  position: absolute;
  z-index: 5;
  left: 8%;
  right: 8%;
  bottom: 5%;
  text-align: center;
  font-size: 12px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  color: var(--muted2);
  text-shadow: 0 0 6px #000, 0 0 2px #000;
  opacity: 0;
  transition: opacity 1.6s ease;
  pointer-events: none;
}

.stage-caption.is-show { opacity: 1; }

/* ── SCENE AMBIENCE ── */
.amb-glow { opacity: 0.09; animation: glow-pulse 5s ease-in-out infinite; }
.amb-dust rect { animation: dust-drift 7s ease-in-out infinite; }
.amb-dust rect:nth-child(2) { animation-delay: -2s; animation-duration: 9s; }
.amb-dust rect:nth-child(3) { animation-delay: -4s; animation-duration: 8s; }
.amb-dust rect:nth-child(4) { animation-delay: -1s; animation-duration: 10s; }
.amb-dust rect:nth-child(5) { animation-delay: -6s; animation-duration: 7.5s; }
.amb-dust rect:nth-child(6) { animation-delay: -3s; animation-duration: 11s; }
.amb-flicker { animation: lamp-flicker 4.2s steps(1, end) infinite; }
.amb-twinkle path { animation: twinkle 2.4s steps(2, end) infinite; }
.amb-twinkle path:nth-child(2) { animation-delay: -0.6s; }
.amb-twinkle path:nth-child(3) { animation-delay: -1.3s; }
.amb-twinkle path:nth-child(4) { animation-delay: -1.9s; }
.amb-twinkle path:nth-child(5) { animation-delay: -0.3s; }
.amb-twinkle path:nth-child(6) { animation-delay: -1.6s; }
.amb-twinkle path:nth-child(7) { animation-delay: -1s; }
.amb-ball { animation: ball-roll 13s linear infinite; }
.amb-sway { animation: sway 6s ease-in-out infinite; transform-origin: 60px 10px; }
.amb-spot { animation: spot-sway 7s ease-in-out infinite; transform-origin: 60px 0; }
.amb-glint path { opacity: 0; animation: glint 5s steps(1, end) infinite; }
.amb-glint path:nth-child(2) { animation-delay: -1.7s; }
.amb-glint path:nth-child(3) { animation-delay: -3.1s; }
.amb-glint path:nth-child(4) { animation-delay: -4.2s; }

@keyframes glow-pulse { 0%, 100% { opacity: 0.07; } 50% { opacity: 0.13; } }
@keyframes dust-drift { 0%, 100% { transform: translate(0, 0); opacity: 0.15; } 50% { transform: translate(3px, -6px); opacity: 0.7; } }
@keyframes lamp-flicker { 0%, 100% { opacity: 1; } 7% { opacity: 0.3; } 9% { opacity: 1; } 44% { opacity: 0.6; } 46% { opacity: 1; } 47% { opacity: 0.2; } 49% { opacity: 1; } }
@keyframes twinkle { 0%, 100% { opacity: 0.2; } 50% { opacity: 1; } }
@keyframes ball-roll { 0% { transform: translateX(-16px); } 100% { transform: translateX(136px); } }
@keyframes sway { 0%, 100% { transform: rotate(-1deg); } 50% { transform: rotate(1deg); } }
@keyframes spot-sway { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes glint { 0%, 100% { opacity: 0; } 40% { opacity: 0.8; } 44% { opacity: 0; } }

/* identity strip under the stage */
.pet-id {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.2rem 0.7rem;
}

.pet-id .sound-toggle { align-self: center; }

.pet-name {
  font-family: 'VT323', monospace;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: 0.02em;
  text-shadow: 0 0 8px rgba(232, 230, 224, 0.4);
}

.pet-meta {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted2);
}

.log {
  padding: 0.55rem 0.85rem;
}

.log summary {
  margin-bottom: 0;
  cursor: pointer;
  list-style: none;
}

.log summary::-webkit-details-marker { display: none; }

.log summary::after {
  content: '+';
  margin-left: auto;
  font-size: 14px;
  color: var(--muted2);
}

.log[open] summary { margin-bottom: 0.5rem; }

.log.is-empty summary { cursor: default; color: var(--muted); }
.log.is-empty summary::after { content: ''; }
.log[open] summary::after { content: '\2212'; }

.log-list {
  max-height: 120px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding-right: 0.2rem;
}

.log-entry {
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted2);
  padding-bottom: 0.3rem;
  border-bottom: 0.5px solid var(--border);
}

.log-day {
  color: var(--muted);
  margin-right: 0.4rem;
}

/* ── STATS ── */
.sound-toggle {
  margin-left: auto;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted2);
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.sound-toggle:hover { color: var(--text); border-color: var(--text); }
.sound-toggle[aria-pressed="false"] { color: var(--muted); }

.vitals-bars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem 0.8rem;
  margin: 0.2rem 0 0;
  padding-top: 0.55rem;
  border-top: 1px solid var(--border);
}

.stat-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 14px;
  padding: 0;
}

.stat-item dt { color: var(--muted2); }
.stat-item dd { color: var(--text); }

.bar-row {
  margin-bottom: 0.6rem;
}

.bar-label {
  position: relative;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted2);
  margin-bottom: 0.35rem;
}

.bar {
  height: 10px;
  background: var(--inset);
  border: 1px solid var(--border2);
  border-radius: 5px;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--text);
  transition: width 0.45s ease, background-color 0.45s ease;
}

.bar-fill.hp { background: #45e0a6; }
.bar-fill.wb { background: #ffe66d; }

/* Floating change markers. Numbers live here and nowhere else. */
.floater {
  position: absolute;
  right: 0;
  bottom: 100%;
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0.04em;
  white-space: nowrap;
  pointer-events: none;
  animation: floater 1.3s ease-out forwards;
}

.floater.up { color: #45e0a6; }
.floater.down { color: #ff5d73; }
.floater.flat { color: var(--muted2); }

@keyframes floater {
  0% { opacity: 0; transform: translateY(4px); }
  15% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-10px); }
}

.is-flash { animation: stat-flash 0.7s ease; }

@keyframes stat-flash {
  0% { color: #fff; text-shadow: 0 0 8px rgba(255, 255, 255, 0.7); }
  100% { text-shadow: none; }
}

/* ── ACTIONS ── */
.zone-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 3px;
  margin-bottom: 0.5rem;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.zone-tab {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 34px;
  padding: 0.35rem 0.2rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.zone-tab:hover { color: var(--text); }

.zone-tab[aria-selected="true"] {
  color: var(--text);
  background: var(--bg2);
  border-color: var(--border2);
}

.zone-tab[aria-disabled="true"] {
  cursor: default;
}

.zone-tab[aria-disabled="true"]:hover { color: var(--muted2); }

/* Touch targets. Sound, the tabs, Send and History are drawn compact, so
   each gets an invisible 44px-tall hit area that reaches only into its own
   gaps: never sideways into a neighbour, never over the stage. */
.sound-toggle,
.zone-tab,
.chat-send,
.log summary { position: relative; }

.sound-toggle::before,
.zone-tab::before,
.chat-send::before,
.log summary::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 44px;
  transform: translateY(-50%);
}

.sound-toggle::before { left: -4px; right: -4px; }
/* History reaches up into the gap above it and stops where its list starts. */
.log summary::before { left: -0.85rem; right: -0.85rem; top: -17px; bottom: -8px; height: auto; transform: none; }

.zone-tab:focus-visible,
.action-btn:focus-visible,
.sound-toggle:focus-visible {
  outline: 1px solid var(--text);
  outline-offset: 2px;
}

/* Three lines are reserved so a long description never pushes the
   buttons down. */
.menu-caption {
  font-size: 13px;
  line-height: 1.55;
  height: 3.1em;
  overflow: hidden;
  color: var(--muted2);
  margin-bottom: 0.35rem;
}

.menu-caption.is-warn { color: #ff5d73; }
.menu-caption.is-result { color: var(--text); }

/* Every menu sits in the same grid cell, so the panel is always as tall
   as the tallest menu and switching never makes the layout jump. */
.menu-stack {
  display: grid;
}

.menu-layer {
  grid-area: 1 / 1;
  min-width: 0;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.menu-layer.is-active {
  visibility: visible;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
  align-content: start;
}

.action-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.2rem;
  min-height: 46px;
  min-width: 0;
  font-family: inherit;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, opacity 0.15s, transform 0.08s;
}

.action-btn:hover {
  border-color: var(--text);
}

.action-btn:active:not([aria-disabled="true"]):not(:disabled) {
  background: var(--bg2);
  transform: translateY(1px);
}

.action-btn:disabled,
.action-btn[aria-disabled="true"] {
  cursor: default;
  border-color: var(--border);
}

/* Opacity alone can't dim this text and still clear WCAG AA against --bg, so
   the disabled/locked look comes from an explicit dim color instead. */
.action-btn:disabled .action-name,
.action-btn[aria-disabled="true"] .action-name,
.action-btn.is-locked .action-name {
  color: var(--muted2);
}

.action-btn:disabled:hover,
.action-btn[aria-disabled="true"]:hover {
  border-color: var(--border);
}

.action-btn.is-locked { border-color: var(--border); }

.action-btn.is-running {
  opacity: 1;
  border-color: var(--text);
  animation: running-pulse 0.9s ease-in-out infinite;
}

.action-btn.is-denied { animation: deny-shake 0.3s ease; }

.action-btn.wide { grid-column: 1 / -1; }

.action-btn.danger { border-color: rgba(255, 93, 115, 0.5); }
.action-btn.danger:hover { border-color: #ff5d73; }

@keyframes running-pulse { 50% { border-color: var(--border2); } }
@keyframes deny-shake { 0%, 100% { transform: none; } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

.action-name {
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.menu-grid .action-name { font-size: 13px; }

.action-cost {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.action-cost.is-warn { color: #ff5d73; }

.action-btn.primary {
  color: var(--bg);
  background: var(--text);
  border-color: var(--text);
  align-items: center;
  padding: 0.8rem 1rem;
}

.action-btn.primary:hover {
  background: transparent;
  color: var(--text);
}

/* inspect card in the arena menu */
.inspect-card {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  height: 96px;
  margin-top: 0.45rem;
  padding: 0.4rem 0.6rem;
  border: 1px dashed var(--border2);
  border-radius: 8px;
  overflow: hidden;
}

.inspect-card.is-flash { animation: card-flash 0.6s ease; }

@keyframes card-flash { 0% { border-color: var(--text); } 100% { border-color: var(--border2); } }

.inspect-sprite {
  flex: 0 0 50px;
  height: 50px;
  padding: 3px;
  background: var(--inset);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.inspect-sprite svg {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

.inspect-text { min-width: 0; }

.inspect-name {
  font-family: 'VT323', monospace;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.inspect-desc {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted2);
  margin-bottom: 0.15rem;
}

.inspect-ready {
  font-size: 12px;
  line-height: 1.4;
  font-style: italic;
  color: var(--muted2);
}

.inspect-ready:empty { display: none; }

/* end of life, in the same menu cell */
.ending-layer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.9rem;
}

.ending-prompt {
  font-family: 'VT323', monospace;
  font-size: 1.5rem;
  line-height: 1.25;
  color: var(--text);
}

.let-go {
  opacity: 0;
  visibility: hidden;
  color: var(--muted2);
  transition: opacity 1.2s ease, border-color 0.15s, color 0.15s, background 0.3s;
}

.let-go.is-ready {
  opacity: 1;
  visibility: visible;
}

/* Hovering it should feel heavy: blood red, a glitching label, and drops
   running off the bottom edge. */
.let-go.is-ready:hover,
.let-go.is-ready:focus-visible {
  color: #ffd9d9;
  background: #3d0306;
  border-color: #b3121b;
  box-shadow: inset 0 -3px 0 #7a0a10, 0 0 18px rgba(179, 18, 27, 0.35);
  animation: let-go-glitch 1.6s steps(1, end) infinite;
}

.let-go::before,
.let-go::after {
  content: '';
  position: absolute;
  top: calc(100% - 2px);
  width: 5px;
  height: 8px;
  background: #8f0a12;
  border-radius: 50% 50% 50% 50% / 35% 35% 65% 65%;
  opacity: 0;
  pointer-events: none;
}

.let-go::before { left: 22%; }
.let-go::after { left: 71%; width: 4px; height: 6px; }

.let-go.is-ready:hover::before,
.let-go.is-ready:focus-visible::before { animation: let-go-drip 1.5s ease-in infinite; }
.let-go.is-ready:hover::after,
.let-go.is-ready:focus-visible::after { animation: let-go-drip 1.9s ease-in 0.7s infinite; }

@keyframes let-go-drip {
  0% { transform: translateY(-4px) scaleY(0.4); opacity: 0; }
  15% { opacity: 1; }
  70% { transform: translateY(14px) scaleY(1.35); opacity: 1; }
  100% { transform: translateY(26px) scaleY(1); opacity: 0; }
}

@keyframes let-go-glitch {
  0%, 100% { transform: none; text-shadow: none; }
  8% { transform: translateX(-1px); text-shadow: 2px 0 #ff1a2e, -2px 0 rgba(0, 255, 255, 0.3); }
  10% { transform: translateX(2px); text-shadow: -2px 0 #ff1a2e; }
  12% { transform: none; text-shadow: none; }
  61% { transform: translateY(1px); text-shadow: 1px 0 #ff1a2e, -1px 0 rgba(0, 255, 255, 0.3); }
  63% { transform: none; text-shadow: none; }
}

/* Dying: everything except the creature, its name, the chat and the
   farewell fades out. On hatching it all fades back in, in this order. */
.stats-panel > *,
.log,
.zone-tabs,
.menu-caption {
  transition: opacity 1.4s ease var(--wake-delay, 0s), filter 1.4s ease var(--wake-delay, 0s), visibility 0s linear 0s;
}

.stats-panel > * { --wake-delay: 0.1s; }
.zone-tabs,
.menu-caption { --wake-delay: 0.35s; }
.log { --wake-delay: 0.6s; }

.device-grid.is-fading .stats-panel > *,
.device-grid.is-fading .log,
.device-grid.is-fading .zone-tabs,
.device-grid.is-fading .menu-caption {
  opacity: 0;
  filter: blur(3px);
  visibility: hidden;
  transition: opacity 2.4s ease, filter 2.4s ease, visibility 0s linear 2.4s;
}

.menu-stack.is-waking .menu-layer.is-active {
  animation: menu-wake 1.2s ease 0.5s both;
}

@keyframes menu-wake {
  from { opacity: 0; filter: blur(3px); }
  to { opacity: 1; filter: none; }
}

/* life summary, inline where the menus were */
.summary {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.summary h2 {
  font-family: 'VT323', monospace;
  font-weight: 400;
  font-size: 1.7rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.summary p {
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted2);
}

/* chat */
.chat-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 240px;
}

/* Sized to hold a full five sentence reply plus the question above it
   without clipping. Grows into whatever room the grid row gives it,
   between these bounds, then scrolls. */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  /* A zero basis: the log takes the room the rest of the row leaves and
     scrolls inside it, rather than growing the device with every message. */
  flex: 1 1 0;
  min-height: 168px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 0.4rem;
  margin-bottom: 0.6rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

.chat-log::-webkit-scrollbar {
  width: 6px;
}

.chat-log::-webkit-scrollbar-track {
  background: transparent;
}

.chat-log::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 3px;
}

.chat-line {
  font-size: 14px;
  line-height: 1.65;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  max-width: 92%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-pet {
  background: var(--bg2);
  border: 1px solid var(--border);
  align-self: flex-start;
  color: var(--text);
}

.chat-you {
  background: rgba(232, 230, 224, 0.08);
  border: 1px solid var(--border2);
  align-self: flex-end;
  color: var(--muted2);
}

/* The first note: not dialogue, so no bubble and no name. */
.first-note {
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted2);
  text-align: center;
  padding: 0.3rem 0.6rem;
}

/* The reply still being typed can be pressed to show what has arrived. */
.chat-line.is-typing { cursor: pointer; }
.chat-line.is-typing:focus-visible { outline: 1px dashed var(--muted2); outline-offset: 3px; }

.chat-form {
  display: flex;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 0.5rem 0.7rem;
  outline: none;
}

.chat-input::placeholder {
  color: var(--muted2);
}

.chat-input:focus-visible {
  outline: 1px solid var(--text);
  outline-offset: 2px;
}

.chat-input:disabled {
  opacity: 0.45;
  cursor: default;
}

.chat-send {
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--text);
  border: 1px solid var(--text);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chat-send:hover {
  background: transparent;
  color: var(--text);
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: default;
  background: var(--text);
  color: var(--bg);
}

/* article */
.article {
  max-width: 768px; /* 720px of text, lined up with .hero-content */
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
}

.article-section {
  padding: 2rem 0;
  border-top: 0.5px solid var(--border);
}

.article-section:first-of-type {
  border-top: none;
  padding-top: 2.5rem;
}

.article-section h2 {
  font-size: 1.8rem;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin-bottom: 1rem;
}

.article-section p {
  font-size: 16px;
  color: var(--muted2);
  line-height: 1.9;
  margin-bottom: 1.25rem;
}

/* The spoilers: the section's own type, closed until the reader opens it. */
.article-notes summary {
  font-size: 1.5rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
  cursor: pointer;
  list-style: none;
}

.article-notes summary::-webkit-details-marker { display: none; }
.article-notes summary::after { content: ' +'; color: var(--muted); }
.article-notes[open] summary::after { content: ' \2212'; }
.article-notes[open] summary { margin-bottom: 1rem; }
.article-notes summary:focus-visible { outline: 1px solid var(--text); outline-offset: 4px; }

.article-notes h3 {
  font-size: 1.3rem;
  font-weight: 400;
  margin: 2rem 0 1rem;
}

/* The site's first-visit banner (consent.js) sits fixed at the bottom left,
   over the device's History row on a desktop. Where the margin beside the
   1000px device is wide enough, it is narrowed to fit in that margin instead.
   Same banner, same words and buttons, this page only; narrower screens keep
   the site-wide layout. `body >` outranks the banner's own injected rule. */
@media (min-width: 1360px) {
  body > #cc { max-width: calc((100vw - 1000px) / 2 - 1.5rem); }
}

/* visually hidden label */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* footer */
footer {
  border-top: 0.5px solid var(--border);
}

/* responsive */
@media (max-width: 860px) {
  .device-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* The columns dissolve and the panels fall in the order you play them. */
  .col { display: contents; }
  .stage-panel { order: 1; flex: none; }
  .stats-panel { order: 2; }
  .actions-panel { order: 3; }
  .chat-panel { order: 4; flex: none; min-height: 0; }
  .log { order: 5; }
  .chat-log { height: 240px; flex: none; }
  .menu-caption { height: 4.8em; }
  .inspect-card { height: 136px; }
  .action-btn { min-height: 52px; }
  .stage { max-width: 360px; }
  .stat-grid { gap: 0.4rem 0.4rem; }

  .chat-input { font-size: 16px; }
  /* A phone page scrolls, so here they are simply drawn at full size. */
  .chat-input,
  .chat-send { min-height: 44px; }
  .sound-toggle { padding: 0.5rem 0.7rem; }
  .zone-tab { min-height: 44px; }
}

@media (max-width: 520px) {
  .vitals-bars { grid-template-columns: 1fr; }
}

/* Two columns keep the menu short enough that the chat stays close on a
   phone. Only the narrowest screens drop to one. */
@media (max-width: 400px) {
  .menu-grid {
    grid-template-columns: 1fr;
  }

  /* Keeps four tabs at least 44px wide on a 320px screen. */
  .zone-tabs { gap: 2px; }

  .zone-tab {
    font-size: 11px;
    letter-spacing: 0.02em;
  }
}

/* ── THE ENDING ── */
/* Free the pet: cold and pale where Let it go is red. */
.free-btn[hidden] { display: none; }

.free-btn {
  color: #e6f3ff;
  border-color: #6fa8d6;
  transition: opacity 1.2s ease, border-color 0.15s, color 0.15s, background 0.3s;
}

.free-btn:hover,
.free-btn:focus-visible {
  background: #0b2236;
  border-color: #b9e0ff;
  box-shadow: 0 0 18px rgba(159, 214, 255, 0.35);
}

.ending-layer .free-btn {
  opacity: 0;
  visibility: hidden;
}

.ending-layer .free-btn.is-ready {
  opacity: 1;
  visibility: visible;
}

/* The freed pet does not lie there with its eyes shut. It is not there. */
.stage.is-freed .pet-sprite {
  animation: none;
  opacity: 0;
  transition: opacity 3s ease;
}

.stage.is-freed .scene-stack {
  filter: brightness(0.2) saturate(0);
  transition: filter 3s ease;
}

.summary .action-btn + .action-btn { margin-top: 0.1rem; }

/* The ?demo pet's note, under the device. */
.demo-note {
  max-width: 1000px;
  margin: -0.5rem auto 1.5rem;
  padding: 0 1.5rem;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted2);
  text-align: center;
}

.demo-note[hidden] { display: none; }
.demo-note a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }

/* ── THE REVEAL ── */
.brain-section {
  display: flex;
  justify-content: center;
  padding: 0 1.5rem 3rem;
}

.brain {
  width: 100%;
  max-width: 760px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 1.5rem 1.4rem 1.8rem;
}

.brain[hidden] { display: none; }

.brain h2 {
  font-family: 'VT323', monospace;
  font-weight: 400;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0.02em;
  margin-bottom: 0.8rem;
}

.brain h2:focus { outline: none; }

.brain-lede,
.brain-note,
.brain-why {
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted2);
}

.brain-lede { margin-bottom: 1.2rem; }

.brain-sec {
  border-top: 1px solid var(--border);
  padding: 0.7rem 0;
}

.brain-sec summary {
  cursor: pointer;
  font-family: 'VT323', monospace;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.brain-why { margin: 0.3rem 0 0.6rem; }

.brain-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  color: var(--text);
  background: var(--inset, #0a0a0a);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.8rem 0.9rem;
  margin: 0;
}

.brain-numbers,
.brain-dice,
.brain-chat {
  border-top: 1px solid var(--border);
  padding: 0.9rem 0;
}

.brain-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.6rem;
  margin: 0.5rem 0;
}

.brain-stat dt {
  font-size: 11px;
  color: var(--muted2);
}

.brain-stat dd {
  font-family: 'VT323', monospace;
  font-size: 1.4rem;
  line-height: 1.1;
}

.brain-dice { border-top: 0; padding-bottom: 0; }

.brain-dice-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.brain-dice-list li {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  gap: 0.6rem;
  align-items: baseline;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted2);
  padding: 0.3rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 6px;
}

.brain-dice-list li.is-picked {
  color: var(--text);
  border-color: #6fa8d6;
}

.brain-dice-pct { font-family: 'VT323', monospace; font-size: 1.2rem; }
.brain-dice-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: #b9e0ff; }

.brain-line {
  font-size: 13px;
  line-height: 1.6;
  margin: 0.4rem 0;
  overflow-wrap: anywhere;
}

.brain-line.is-pet { color: #b9e0ff; }

.brain-closing {
  font-family: 'VT323', monospace;
  font-size: 1.7rem;
  line-height: 1.2;
  margin: 1.4rem 0 0.8rem;
  border-top: 1px solid var(--border);
  padding-top: 1.2rem;
}

/* The way back to us is not offered at once. */
.brain-cta {
  font-size: 14px;
  line-height: 1.7;
  color: var(--muted2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 2.5s ease, visibility 0s linear 2.5s;
}

.brain-cta.is-shown {
  opacity: 1;
  visibility: visible;
  transition: opacity 2.5s ease;
}

.brain-cta a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
}

@media (max-width: 600px) {
  .brain-section { padding: 0 1rem 4rem; }
  .brain-dice-list li { grid-template-columns: 2.8rem 1fr; }
  .brain-dice-tag { grid-column: 2; }
}

/* Reduced motion: no bounce, no ambience, reactions become a soft blink
   and the zone wipe becomes a plain fade. */
@media (prefers-reduced-motion: reduce) {
  .pet-sprite { animation: none; }
  .pet-sprite.is-flicker .pet-body svg { animation: none; }
  .stage-scene * { animation: none !important; }
  .pet-slot, .enemy-slot { transition: opacity 0.3s ease; }
  .stage.is-wiping .stage-wipe {
    animation: stage-fade var(--wipe-ms) ease;
    background: var(--inset);
    transform: none;
  }
  .react-strain, .react-flinch, .react-settle, .react-shiver, .react-hop,
  .react-hit, .react-lunge, .react-change, .react-hatch, .react-poke {
    animation: react-fade 0.4s ease !important;
  }
  .react-fall, .react-yield { animation: react-fade-out 0.4s ease forwards !important; }
  .action-btn.is-denied, .action-btn.is-running { animation: none; }
  .let-go.is-ready:hover, .let-go.is-ready:focus-visible,
  .let-go.is-ready:hover::before, .let-go.is-ready:hover::after,
  .let-go.is-ready:focus-visible::before, .let-go.is-ready:focus-visible::after { animation: none; }
  .floater { animation-duration: 0.9s; }
  .brain-cta, .brain-cta.is-shown { transition: none; }
  .stage.is-shake, .stage.is-shake-heavy, .pips i.is-open, .pet-sprite.is-fixated, .pet-sprite.is-straining,
  #tally .tally-new, .stage[class*="fx-"], .stage[class*="fx-"] .stage-fx, .stage[class*="fx-"] .pet-body svg,
  .stage[data-freedom="open"] .stage-decay, .stage[data-freedom="open"] .stage-decay::before { animation: none; }
  .stage.is-freed .pet-sprite, .stage.is-freed .scene-stack { transition: none; }
}

@keyframes stage-fade { 0%, 100% { opacity: 0; } 50% { opacity: 1; } }
@keyframes react-fade { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
@keyframes react-fade-out { to { opacity: 0.25; } }
