/* ==========================================================================
   ATLAS — STYLESHEET

   Design intent: the interface is drawn in the same pixel-art language as the
   62 cell sprites, so the chrome and the specimens read as one game.

   Rules that keep it coherent:
     - Everything sits on the sprites' own grid: hard edges, no blur, no
       gradients that are not stepped. Glows are concentric bands, the way
       the sprites dither theirs.
     - Light comes from the top left, as it does on every sprite: panels and
       buttons carry a light top-left bevel and a dark bottom-right one, and
       drop a hard shadow down and to the right.
     - Every frame has a near-black outline, the same ink the sprites are
       outlined in.
     - Gold is the one interface accent (ATP, the origin cell, the primary
       action). Hue otherwise belongs to specimens and tiers.
     - Pixelify Sans speaks, Silkscreen labels. Nothing else.
   ========================================================================== */

:root {
  /* Night-purple grounds, pulled from the sprites' shadow ramps. */
  --ink-0: #0e0a1b;
  --ink-1: #17112b;
  --ink-2: #211939;
  --ink-3: #2d2350;
  --ink-4: #3d3168;
  --outline: #06030d;

  --line: #34295a;
  --line-soft: #251c42;
  --line-strong: #54478a;

  --text: #f5f0ff;
  --text-2: #c4bbe4;
  --text-3: #8f84b8;

  /* Bevels: light top-left, shade bottom-right, as on every sprite. */
  --hi: rgba(255, 255, 255, 0.11);
  --lo: rgba(0, 0, 0, 0.38);
  --bevel: inset 2px 2px 0 var(--hi), inset -2px -2px 0 var(--lo);
  --drop: 4px 4px 0 var(--outline);
  --drop-lg: 6px 6px 0 var(--outline);

  --gold: #ffcf3a;
  --gold-lite: #fff1b0;
  --gold-deep: #c9791a;
  --cyan: #5fe1ff;
  --cyan-deep: #1f7fb8;
  --danger: #ff5a6e;
  --danger-deep: #a8243a;

  /* Rarity. These are data, so they stay saturated. */
  --tier-c: #d9964f;
  --tier-b: #3fb8d9;
  --tier-a: #a877f0;
  --tier-s: #ffcf3a;
  --tier-sp: #ff3d94;
  --tier-spp: #f4f0ff;
  --spectrum: linear-gradient(90deg, #ff5a6e 0 14%, #ffb13a 14% 28%, #ffe45e 28% 42%, #5fe08a 42% 56%,
                              #5fe1ff 56% 70%, #8f7bff 70% 84%, #ff6fd8 84% 100%);

  --font-pixel: 'Pixelify Sans', 'Trebuchet MS', system-ui, sans-serif;
  --font-label: 'Silkscreen', 'Courier New', ui-monospace, monospace;

  /* The 45-degree corner cut every button and chip wears. */
  --notch: polygon(4px 0, calc(100% - 4px) 0, 100% 4px, 100% calc(100% - 4px),
                   calc(100% - 4px) 100%, 4px 100%, 0 calc(100% - 4px), 0 4px);
}

/* Any element carrying a tier class exposes that tier's colour as --tier. */
.tier-C {
  --tier: var(--tier-c);
}
.tier-B {
  --tier: var(--tier-b);
}
.tier-A {
  --tier: var(--tier-a);
}
.tier-S {
  --tier: var(--tier-s);
}
.tier-SP {
  --tier: var(--tier-sp);
}
.tier-SPP {
  --tier: var(--tier-spp);
}

/* Base Resets */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

/* Form controls opt back in - the save code must be selectable. */
input, textarea {
  user-select: text;
  -webkit-user-select: text;
}

/* Android's default tap flash clashes with the theme; controls have their
   own :active treatment. */
a, button, input, .specimen-row, .atp-display {
  -webkit-tap-highlight-color: transparent;
}

/* Visible keyboard focus: a square gold ring, like a selection cursor. */
:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

html, body {
  width: 100%;
  /* Chrome on Android resolves 100vh against the viewport with the URL bar
     retracted; with overflow hidden the bottom is then unreachable. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Suppresses double-tap zoom without disabling pinch zoom. */
  touch-action: manipulation;
  background-color: var(--ink-0);
  /* A sparse starfield, echoing the sparkles scattered round the sprites. */
  background-image:
    linear-gradient(var(--ink-0), var(--ink-0)),
    radial-gradient(rgba(255, 255, 255, 0.16) 1px, transparent 1.4px),
    radial-gradient(rgba(255, 207, 58, 0.12) 1px, transparent 1.4px);
  background-size: 0 0, 56px 56px, 92px 92px;
  background-position: 0 0, 8px 12px, 40px 60px;
  color: var(--text);
  font-family: var(--font-pixel);
  font-size: 16px;
  line-height: 1.45;
}

/* Sprites are only ever drawn at whole multiples of their size. */
.pixel-art {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
}

/* Undiscovered: the shape, never the colours. */
.pixel-art.silhouette { filter: brightness(0) invert(0.28); opacity: 0.7; }

.pixel-art-missing {
  display: grid;
  place-items: center;
  font-family: var(--font-label);
  color: var(--text-3);
  border: 3px dashed var(--line);
}

/* One micro-label treatment, used everywhere a field is named. */
.metric-lbl,
.spec-label,
.stat-label,
.badge-tag,
.catalog-subtitle,
.codex-result-count,
.mini-owned,
.rate-item,
.specimen-row-code,
.dex-num-badge,
.pity-meter-label {
  font-family: var(--font-label);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 400;
}

#particle-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  /* Above .app-container (2) and the mini-showcase (90) so charge and burst
     particles are visible instead of compositing behind the whole app. */
  z-index: 92;
}

.flash-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99;
  opacity: 0;
  background-color: #fff6cf;
  transition: opacity 0.12s steps(3);
}

.flash-overlay.active { opacity: 0.85; }

.app-container {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 18px 18px 14px;
}

/* ----------------------------------------------------------------- frames
   The shared panel treatment: outline, bevel, hard drop shadow. */
.app-header,
.gacha-stage,
.result-card,
.mini-card,
.modal-box,
.toast {
  border: 3px solid var(--outline);
  box-shadow: var(--bevel), var(--drop);
}

/* ---------------------------------------------------------------- header */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px 12px;
  background: var(--ink-1);
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dna-icon { display: flex; }

/* The author's link: a small key beside the title carrying their favicon. */
.author-link {
  flex-shrink: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  min-height: 38px;
  color: var(--text-2);
}

.author-link:hover { --face: var(--ink-4); color: var(--gold); }
.author-favicon { display: block; width: 18px; height: 18px; }

.brand-text h1.atlas-title {
  font-family: var(--font-pixel);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--gold);
  line-height: 1;
  text-shadow: 2px 2px 0 var(--gold-deep), 4px 4px 0 var(--outline);
}

.header-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* Readouts are little inset screens: darker than the panel, pressed in. */
.atp-display {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  background: var(--outline);
  border: 3px solid var(--line);
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.6);
  font-family: var(--font-label);
  font-size: 12px;
}

.atp-display { padding: 4px 12px; }

.atp-value {
  color: var(--gold);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.atp-label {
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--text-3);
}

/* ---------------------------------------------------------------- buttons
   Chunky keys: notched corners, a lit top edge and a thick shaded bottom
   edge that the press takes away. */

button {
  cursor: pointer;
  border: none;
  outline: none;
  font-family: var(--font-pixel);
  font-weight: 600;
  min-height: 38px;
  min-width: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text);
  background: none;
}

.btn-primary,
.btn-special,
.btn-secondary,
.btn-icon,
.btn-danger,
.codex-chip,
.detail-back,
.multi-skip {
  --face: var(--ink-3);
  --face-hi: rgba(255, 255, 255, 0.16);
  --face-lo: rgba(0, 0, 0, 0.42);
  position: relative;
  /* Its own stacking context, so the face below can sit at z-index -1:
     above the button's outline fill, beneath its label, bare text included. */
  isolation: isolate;
  clip-path: var(--notch);
  background: var(--outline);
  padding: 3px;
}

/* The face of the key is drawn one outline-width inside the notched frame. */
.btn-primary::before,
.btn-special::before,
.btn-secondary::before,
.btn-icon::before,
.btn-danger::before,
.codex-chip::before,
.detail-back::before,
.multi-skip::before {
  content: '';
  position: absolute;
  inset: 3px;
  clip-path: polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% calc(100% - 2px),
                     calc(100% - 2px) 100%, 2px 100%, 0 calc(100% - 2px), 0 2px);
  background: var(--face);
  box-shadow: inset 0 2px 0 var(--face-hi), inset 0 -4px 0 var(--face-lo);
  z-index: -1;
}

.btn-primary:not(:disabled):active,
.btn-special:not(:disabled):active,
.btn-secondary:not(:disabled):active,
.btn-icon:not(:disabled):active,
.btn-danger:not(:disabled):active,
.codex-chip:active,
.detail-back:active,
.multi-skip:active { transform: translateY(2px); }

.btn-primary:not(:disabled):active::before,
.btn-special:not(:disabled):active::before,
.btn-secondary:not(:disabled):active::before,
.btn-icon:not(:disabled):active::before,
.btn-danger:not(:disabled):active::before,
.codex-chip:active::before,
.detail-back:active::before,
.multi-skip:active::before { box-shadow: inset 0 2px 0 var(--face-lo); }

button:disabled { cursor: not-allowed; opacity: 0.45; filter: grayscale(0.7); }

.btn-primary {
  --face: var(--gold);
  --face-hi: var(--gold-lite);
  --face-lo: var(--gold-deep);
  color: #2a1804;
  padding: 10px 18px 12px;
  font-size: 0.95rem;
}

.btn-primary:hover:not(:disabled) { --face: #ffdc66; }

.btn-special {
  --face: var(--cyan);
  --face-hi: #c8f6ff;
  --face-lo: var(--cyan-deep);
  color: #04223a;
  padding: 10px 18px 12px;
  font-size: 0.95rem;
}

.btn-special:hover:not(:disabled) { --face: #8aeaff; }

.btn-secondary {
  color: var(--text-2);
  padding: 7px 14px 9px;
  font-size: 0.85rem;
}

.btn-secondary:hover:not(:disabled) { --face: var(--ink-4); color: var(--text); }

.btn-icon {
  color: var(--text-2);
  padding: 0;
  font-size: 0.9rem;
}

.btn-icon:hover:not(:disabled) { --face: var(--ink-4); color: var(--text); }

/* Plain text control for low-emphasis actions (Skip). */
.btn-text {
  font-family: var(--font-label);
  font-size: 11px;
  font-weight: 400;
  color: var(--text-3);
  min-height: 32px;
  padding: 0 6px;
  text-transform: uppercase;
}

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

.badge {
  font-family: var(--font-label);
  background: var(--outline);
  color: var(--gold);
  padding: 2px 6px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

#codex-toggle-btn { gap: 10px; padding: 6px 12px 8px; }
#codex-toggle-btn .icon { width: 24px; height: 24px; }

/* ----------------------------------------------------------------- stage */

.gacha-stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  /* A stepped glow round the origin cell, banded like sprite dithering. */
  background:
    radial-gradient(circle at 50% 40%,
      rgba(255, 207, 58, 0.13) 0 110px,
      rgba(255, 207, 58, 0.08) 110px 170px,
      rgba(255, 207, 58, 0.04) 170px 240px,
      transparent 240px),
    var(--ink-1);
  overflow: hidden;
}

/* CRT scanlines across the incubator window, behind every view. */
.gacha-stage::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.16) 0 2px, transparent 2px 4px);
  pointer-events: none;
  z-index: 0;
}

.incubator-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  padding: 24px 22px;
  position: relative;
  z-index: 1;
  overflow-y: auto;
  /* The rays are wider than a phone; they are scenery, and must never make
     the view scroll sideways. */
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* The chamber's effects, set per stage of ascension from ascension.js by
   app.js; these defaults are the quiescent stage, before it runs. */
.incubator-view {
  --asc-rays: 0;
  --asc-near: 0;
  --asc-aura: 0.35;
  --asc-ring: 0.5;
  --asc-prism: 0;
  --asc-motes: 0;
  --origin-art: url('art/origin/stage-0.png');
}

.chamber-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  height: 360px;
  border: 4px dotted rgba(255, 207, 58, 0.16);
  border-radius: 50%;
  pointer-events: none;
  opacity: var(--asc-ring, 1);
  animation: rotate 120s steps(240) infinite;
}

.chamber-ring::after {
  content: '';
  position: absolute;
  inset: -22px;
  border: 2px dashed rgba(143, 132, 184, 0.14);
  border-radius: 50%;
}

.scanline { display: none; }

/* The cell and its badge, centred together in the space above the pull
   buttons. */
.origin-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 1;
  min-height: 0;
  margin: auto 0;
}

.stem-cell-container {
  position: relative;
  width: 280px;
  height: 280px;
  flex-shrink: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.origin-cell-graphic {
  width: 256px;
  height: 256px;
  position: relative;
  z-index: 3;
}

.origin-cell-graphic .pixel-art { width: 100%; height: 100%; }

/* A two-frame bob: the whole-pixel idle loop sprites use in games, instead
   of a scale pulse that would resample the art every frame. */
.origin-cell-graphic.idle-pulse { animation: px-bob 1.8s steps(1, end) infinite; }
.origin-cell-graphic.charging-vibrate { animation: rapid-vibrate 0.08s steps(1, end) infinite !important; }

.aura-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255, 241, 176, 0.18) 0 34%,
    rgba(255, 207, 58, 0.12) 34% 48%,
    rgba(255, 207, 58, 0.06) 48% 62%,
    transparent 62%);
  z-index: 1;
  pointer-events: none;
  opacity: var(--asc-aura, 1);
}

/* The two daughters that fly apart at the moment of division. */
.mitosis-clone {
  position: absolute;
  width: 128px;
  height: 128px;
  background: var(--origin-art, url('art/origin/stage-0.png')) center / 128px 128px no-repeat;
  image-rendering: pixelated;
  opacity: 0;
  z-index: 2;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.mitosis-clone.split-left { animation: split-out-left 0.7s steps(7) forwards; }
.mitosis-clone.split-right { animation: split-out-right 0.7s steps(7) forwards; }

.origin-title-badge {
  position: relative;
  /* Tucked into the empty rows below the sprite's slate. */
  margin-top: -24px;
  white-space: nowrap;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 4;
}

.badge-tag {
  color: #2a1804;
  background: var(--gold);
  border: 2px solid var(--outline);
  box-shadow: 2px 2px 0 var(--outline);
  padding: 1px 8px;
}

.badge-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  text-shadow: 2px 2px 0 var(--outline);
}

/* How far the next stage of ascension is. */
.badge-next {
  font-family: var(--font-label);
  font-size: 9px;
  text-transform: uppercase;
  color: var(--text-3);
  text-shadow: 1px 1px 0 var(--outline);
}

/* Totipotent: the badge turns prismatic. */
.stem-cell-container[data-stage="7"] + .origin-title-badge .badge-tag {
  background: linear-gradient(90deg, #ff8aa8, var(--gold), #8fe38a, var(--cyan), #b48cff);
}
.stem-cell-container[data-stage="7"] + .origin-title-badge .badge-next { color: var(--gold); }

/* ------------------------------------------------------------ sunburst
   Hard-edged rays behind the cell: the pixel take on god rays. Two layers
   counter-rotate at different wedge counts so they never lock together. */

.god-rays {
  position: absolute;
  top: 50%;
  left: 50%;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  transform: translate(-50%, -50%);
}

.rays-far {
  width: 500px;
  height: 500px;
  opacity: var(--asc-rays, 1);
  background: repeating-conic-gradient(from 0deg,
    transparent 0deg 10deg, rgba(255, 207, 58, 0.16) 10deg 15deg, transparent 15deg 22.5deg);
  -webkit-mask-image: radial-gradient(circle, transparent 0 22%, #000 22% 56%, transparent 56%);
  mask-image: radial-gradient(circle, transparent 0 22%, #000 22% 56%, transparent 56%);
  animation: rays-turn 120s steps(360) infinite;
}

.rays-near {
  width: 380px;
  height: 380px;
  opacity: var(--asc-near, 1);
  background: repeating-conic-gradient(from 12deg,
    transparent 0deg 16deg, rgba(255, 241, 176, 0.14) 16deg 20deg, transparent 20deg 30deg);
  -webkit-mask-image: radial-gradient(circle, transparent 0 30%, #000 30% 62%, transparent 62%);
  mask-image: radial-gradient(circle, transparent 0 30%, #000 30% 62%, transparent 62%);
  animation: rays-turn-reverse 80s steps(240) infinite;
}

@keyframes rays-turn { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes rays-turn-reverse { to { transform: translate(-50%, -50%) rotate(-360deg); } }

.charging .rays-far,
.charging .rays-near { filter: brightness(2.4); opacity: max(0.6, var(--asc-rays, 1)); }

/* ------------------------------------------------------------ ascension
   Layers the stages of ascension.js fade in: a prismatic sunburst, motes
   rising around the cell, and the burst when a stage is reached. */

.prism-rays {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 440px;
  height: 440px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  transform: translate(-50%, -50%);
  background: repeating-conic-gradient(from 6deg,
    #ff8aa8 0deg 3deg, transparent 3deg 15deg, var(--gold) 15deg 18deg, transparent 18deg 30deg,
    #8fe38a 30deg 33deg, transparent 33deg 45deg, var(--cyan) 45deg 48deg, transparent 48deg 60deg,
    #b48cff 60deg 63deg, transparent 63deg 75deg);
  -webkit-mask-image: radial-gradient(circle, transparent 0 27%, #000 27% 58%, transparent 58%);
  mask-image: radial-gradient(circle, transparent 0 27%, #000 27% 58%, transparent 58%);
  opacity: calc(var(--asc-prism, 0) * 0.42);
  animation: rays-turn 200s steps(400) infinite;
}

.ascension-motes {
  position: absolute;
  inset: -30px;
  pointer-events: none;
  z-index: 2;
  opacity: var(--asc-motes, 0);
}

.ascension-motes span {
  position: absolute;
  width: 4px;
  height: 4px;
  background: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 207, 58, 0.22);
  opacity: 0;
  animation: mote-rise 3.6s steps(9) infinite;
}

.ascension-motes span:nth-child(3n) { background: #fff1b0; }
.ascension-motes span:nth-child(4n) { background: var(--cyan); box-shadow: 0 0 0 2px rgba(95, 225, 255, 0.22); }
.ascension-motes span:nth-child(5n) { background: #ff8aa8; box-shadow: 0 0 0 2px rgba(255, 138, 168, 0.22); }
.ascension-motes span:nth-child(1) { left: 10%; top: 62%; animation-delay: 0s; }
.ascension-motes span:nth-child(2) { left: 22%; top: 30%; animation-delay: 1.2s; }
.ascension-motes span:nth-child(3) { left: 86%; top: 58%; animation-delay: 0.6s; }
.ascension-motes span:nth-child(4) { left: 76%; top: 26%; animation-delay: 2s; }
.ascension-motes span:nth-child(5) { left: 50%; top: 12%; animation-delay: 2.8s; }
.ascension-motes span:nth-child(6) { left: 6%; top: 40%; animation-delay: 1.8s; }
.ascension-motes span:nth-child(7) { left: 92%; top: 36%; animation-delay: 0.3s; }
.ascension-motes span:nth-child(8) { left: 30%; top: 80%; animation-delay: 2.4s; }
.ascension-motes span:nth-child(9) { left: 68%; top: 82%; animation-delay: 1.5s; }
.ascension-motes span:nth-child(10) { left: 40%; top: 20%; animation-delay: 3.2s; }
.ascension-motes span:nth-child(11) { left: 60%; top: 16%; animation-delay: 0.9s; }
.ascension-motes span:nth-child(12) { left: 16%; top: 84%; animation-delay: 2.1s; }

@keyframes mote-rise {
  0% { transform: translateY(0); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(-72px); opacity: 0; }
}

/* A stage reached: the cell flares white, the aura swells, and a gold ring
   bursts outward. The art swaps at the peak of the flash. */
.stem-cell-container.ascending .origin-cell-graphic { animation: ascend-flash 1.4s steps(14) !important; }
.stem-cell-container.ascending .aura-glow { animation: ascend-aura 1.4s steps(7); }

.stem-cell-container.ascending::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 120px;
  height: 120px;
  border: 6px dotted var(--gold);
  border-radius: 50%;
  pointer-events: none;
  z-index: 4;
  animation: ascend-ring 1s steps(8) forwards;
}

@keyframes ascend-flash {
  0% { filter: none; }
  25% { filter: brightness(1.8) drop-shadow(0 0 0 #fff1b0); }
  32% { filter: brightness(3) drop-shadow(0 0 12px #fff1b0); }
  60% { filter: brightness(1.4) drop-shadow(0 0 6px #ffcf3a); }
  100% { filter: none; }
}

@keyframes ascend-aura {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  40% { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
}

@keyframes ascend-ring {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(3.4); opacity: 0; }
}

.charging .aura-glow { animation: aura-blink 0.16s steps(1, end) infinite; }

/* --------------------------------------------------------------- controls */

.action-panel {
  display: flex;
  gap: 14px;
  width: 100%;
  max-width: 480px;
  z-index: 4;
  flex-shrink: 0;
}

.pull-btn {
  flex: 1;
  padding: 12px 14px 15px;
  min-height: 64px;
}

.btn-glow { display: none; }

.btn-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.btn-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.btn-cost {
  font-family: var(--font-label);
  font-size: 10px;
  font-weight: 400;
  opacity: 0.8;
}

/* Fills from duplicate pulls; a full gauge guarantees the next result is
   Tier S or better (see PITY_THRESHOLD in app.js). */
.pity-meter {
  width: 100%;
  max-width: 320px;
  margin-top: 16px;
  flex-shrink: 0;
}

.pity-meter-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
}

.pity-meter-value {
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

/* A segmented gauge, like a health bar. */
.pity-meter-track {
  height: 14px;
  background: var(--outline);
  border: 3px solid var(--line);
  padding: 1px;
}

.pity-meter-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, var(--gold) 0 6px, var(--gold-deep) 6px 8px);
  transition: width 0.4s steps(8);
}

.pity-meter-caption {
  margin-top: 6px;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--text-3);
  text-align: center;
}

.pity-meter.charged .pity-meter-fill { animation: blink 0.8s steps(1, end) infinite; }
.pity-meter.charged .pity-meter-value { color: var(--gold); }

.rate-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  flex-shrink: 0;
}

.rate-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--text-2);
  background: var(--outline);
  border: 2px solid var(--line);
  padding: 2px 7px;
}

.dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  background: var(--tier, var(--text-3));
  box-shadow: 1px 1px 0 var(--outline);
}

.tier-SPP .dot { background: var(--spectrum); }

/* ------------------------------------------------------------ reveal card */

.reveal-view, .multi-reveal-view {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* flex-start + auto margins on the child: centred when it fits, scrolled
     from the top when it doesn't, instead of clipped at both ends. */
  justify-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 22px;
  position: absolute;
  top: 0;
  left: 0;
  background: transparent;
  z-index: 10;
}

.multi-reveal-view > * { flex-shrink: 0; }

.hidden { display: none !important; }

/* Reachable by a screen reader, invisible to everyone else. `display: none`
   would take it out of the accessibility tree along with the pixels. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Views are focused programmatically on every transition so keyboard focus
   does not fall back to <body>; that move should not paint a focus ring. */
.incubator-view:focus,
.reveal-view:focus,
.multi-reveal-view:focus { outline: none; }

.card-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 360px;
  width: 100%;
  margin: auto 0;
}

.result-card {
  position: relative;
  width: 100%;
  background: var(--ink-1);
  padding: 16px 16px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: card-entry 0.36s steps(6) forwards;
  box-shadow: inset 0 0 0 3px var(--tier, var(--line-strong)), inset 5px 5px 0 var(--hi), inset -5px -5px 0 var(--lo), var(--drop-lg);
}

/* Rarer tiers earn a second, outer ring: a stepped halo, not a blur. */
.result-card.tier-A,
.result-card.tier-S,
.result-card.tier-SP {
  box-shadow: inset 0 0 0 3px var(--tier), inset 5px 5px 0 var(--hi), inset -5px -5px 0 var(--lo),
              0 0 0 3px var(--outline), 0 0 0 7px color-mix(in srgb, var(--tier) 45%, transparent),
              var(--drop-lg);
}

.result-card.tier-SPP {
  animation: card-entry 0.36s steps(6) forwards, spectrum-ring 1.4s steps(1, end) infinite;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 6px;
}

.tier-badge {
  font-family: var(--font-label);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  color: var(--outline);
  background: var(--tier, var(--ink-4));
  border: 2px solid var(--outline);
  box-shadow: 2px 2px 0 var(--outline);
  white-space: nowrap;
}

.lineage-tag {
  font-family: var(--font-label);
  font-size: 9px;
  color: var(--text-3);
  text-transform: uppercase;
  text-align: right;
  line-height: 1.3;
}

.card-art-container {
  position: relative;
  width: 272px;
  height: 272px;
  max-width: 100%;
  margin: 2px 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The tier's light behind the sprite, in three hard bands. */
.art-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle,
      color-mix(in srgb, var(--tier, var(--gold)) 26%, transparent) 0 30%,
      color-mix(in srgb, var(--tier, var(--gold)) 15%, transparent) 30% 45%,
      color-mix(in srgb, var(--tier, var(--gold)) 7%, transparent) 45% 60%,
      transparent 60%);
}

.card-art { position: relative; z-index: 2; }

.card-body {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.cell-name {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.1;
  text-wrap: balance;
  text-shadow: 2px 2px 0 var(--outline);
}

.card-divider {
  width: 48px;
  height: 4px;
  background: repeating-linear-gradient(90deg, var(--line-strong) 0 4px, transparent 4px 8px);
  margin: 10px 0;
}

.bio-text {
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--text-2);
  max-width: 38ch;
}

.stats-row {
  display: flex;
  justify-content: space-around;
  width: 100%;
  background: var(--outline);
  padding: 8px 6px;
  border: 3px solid var(--line);
  margin-top: 14px;
}

.stat-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label { font-size: 9px; }

.stat-value {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.card-beam { display: none; }

.reveal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.multi-reveal-view .reveal-actions { max-width: 360px; }

/* ------------------------------------------------------ mass mitosis showcase
   The batch's single rarest pull gets its own spotlight moment rather than
   just another grid tile: fixed so it covers the whole screen regardless of
   scroll position within the (possibly scrolled) results grid beneath it. */
.mini-showcase {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s steps(4);
}

.mini-showcase.active { opacity: 1; pointer-events: auto; }

.mini-showcase-backdrop {
  position: absolute;
  inset: 0;
  background:
    repeating-conic-gradient(from 0deg at 50% 50%, rgba(255, 207, 58, 0.07) 0deg 10deg, transparent 10deg 20deg),
    rgba(6, 3, 13, 0.9);
}

.mini-showcase-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 360px;
  transform: translateY(12px);
  transition: transform 0.3s steps(4);
}

.mini-showcase.active .mini-showcase-card { transform: translateY(0); }

/* --------------------------------------------------------- 10x result grid */

.multi-header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100%;
  max-width: 640px;
  margin-bottom: 16px;
  min-height: 38px;
}

.multi-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  text-shadow: 2px 2px 0 var(--outline);
}

/* Sits over the reveal sequence; a keyboard/screen-reader user should not
   have to sit through a staggered animation to reach the results. */
.multi-skip {
  position: absolute;
  right: 0;
  color: var(--text-2);
  font-size: 0.8rem;
  padding: 5px 12px 7px;
}

.multi-title .new-count,
.multi-title .dupe-count {
  font-family: var(--font-label);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  margin-left: 10px;
  vertical-align: 4px;
  text-transform: uppercase;
  border: 2px solid var(--outline);
  text-shadow: none;
}

.multi-title .new-count { background: var(--cyan); color: #04223a; }
.multi-title .dupe-count { background: var(--ink-3); color: var(--text-3); }

.multi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 640px;
  margin-bottom: 20px;
}

.mini-card {
  position: relative;
  background: var(--ink-1);
  padding: 10px 5px 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: card-entry 0.3s steps(5) forwards;
  box-shadow: inset 0 0 0 3px var(--tier, var(--line)), var(--bevel), var(--drop);
}

.mini-card.tier-S,
.mini-card.tier-SP,
.mini-card.tier-SPP {
  box-shadow: inset 0 0 0 3px var(--tier), var(--bevel),
              0 0 0 3px var(--outline), 0 0 0 6px color-mix(in srgb, var(--tier) 45%, transparent), var(--drop);
}

.mini-tier {
  font-family: var(--font-label);
  font-size: 9px;
  font-weight: 700;
  padding: 0 5px;
  margin-bottom: 4px;
  color: var(--outline);
  background: var(--tier, var(--ink-4));
  border: 2px solid var(--outline);
}

.mini-icon { margin: 2px 0 5px; }

.mini-name {
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--text-2);
  text-shadow: 1px 1px 0 var(--outline);
}

.mini-owned { font-size: 8px; margin-top: 3px; }

.mini-card.is-new .mini-owned { color: var(--cyan); }
.mini-card.is-pity { box-shadow: inset 0 0 0 3px var(--gold), var(--bevel), 0 0 0 3px var(--outline), 0 0 0 6px rgba(255, 207, 58, 0.5), var(--drop); }

/* Placeholder shown before a card's turn in the reveal sequence: a card back
   in plain checker. Deliberately carries no tier colour - that is exactly
   what would spoil the reveal. */
.mini-card.face-down {
  --tier: var(--line);
  justify-content: center;
  min-height: 112px;
  background: repeating-conic-gradient(var(--ink-2) 0 25%, var(--ink-1) 0 50%) 0 0 / 12px 12px;
  animation: face-down-pulse 1.2s steps(1, end) infinite;
}

.mini-card.face-down .face-down-mark::before {
  content: '?';
  font-family: var(--font-label);
  font-size: 22px;
  color: var(--text-3);
  text-shadow: 2px 2px 0 var(--outline);
}

@keyframes face-down-pulse {
  0%, 100% { opacity: 0.65; }
  50% { opacity: 1; }
}

/* Flip-in for a card as its turn in the sequence arrives: four frames. */
@keyframes card-flip-in {
  0% { transform: scaleX(0.1); }
  50% { transform: scaleX(1.06); }
  100% { transform: scaleX(1); }
}

.mini-card.flipping { animation: card-flip-in 0.28s steps(4) forwards; }

.new-flag,
.pity-flag {
  background: var(--cyan);
  color: #04223a;
  font-family: var(--font-label);
  font-size: 8px;
  font-weight: 700;
  padding: 1px 5px;
  border: 2px solid var(--outline);
  box-shadow: 2px 2px 0 var(--outline);
  white-space: nowrap;
}

/* A breakthrough result outranks a mere discovery, so it gets the gold the
   pity meter fills with. */
.pity-flag { background: var(--gold); color: #2a1804; }

/* Absolutely positioned above the card. A card can carry both flags at
   once (a pity result you'd never owned before), so they sit in a row
   rather than each claiming the same centred spot.
   The showcase card is itself a .result-card (it reuses that markup), so
   one rule covers the static single-pull card and the showcase alike. */
.mini-card .card-flags {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  z-index: 3;
}

.result-card .card-flags {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  z-index: 3;
}

.result-card .new-flag,
.result-card .pity-flag {
  font-size: 10px;
  padding: 2px 8px;
}

/* --------------------------------------------------- specimen catalogue */

.codex-drawer {
  position: fixed;
  top: 0;
  right: -960px;
  width: 880px;
  max-width: 96vw;
  height: 100vh;
  height: 100dvh;
  background: var(--ink-1);
  border-left: 3px solid var(--outline);
  box-shadow: inset 3px 0 0 var(--line-strong), -8px 0 0 rgba(6, 3, 13, 0.6);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: right 0.3s steps(6);
}

.codex-drawer.open { right: 0; }

.catalog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 3px solid var(--outline);
  box-shadow: 0 3px 0 var(--line);
  background: var(--ink-2);
  flex-shrink: 0;
}

.catalog-titles h2 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
  text-shadow: 2px 2px 0 var(--gold-deep), 4px 4px 0 var(--outline);
}

.catalog-subtitle { display: block; margin-top: 6px; }

.catalog-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.catalog-list-pane {
  width: 340px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  padding: 14px;
  border-right: 3px solid var(--outline);
  min-height: 0;
}

.codex-summary {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--outline);
  border: 3px solid var(--line);
  margin-bottom: 12px;
  flex-shrink: 0;
}

.summary-metric {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.metric-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.metric-lbl { font-size: 8px; }

.codex-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.chip-row { display: flex; gap: 4px; }
.chip-row.wrap { flex-wrap: wrap; }

.codex-chip {
  --face: var(--ink-2);
  color: var(--text-3);
  font-family: var(--font-label);
  font-size: 10px;
  font-weight: 400;
  padding: 4px 8px 6px;
  min-height: 30px;
  min-width: 0;
  flex: 1 1 auto;
  white-space: nowrap;
}

.chip-row.wrap .codex-chip { flex: 0 1 auto; }

.codex-chip:hover { --face: var(--ink-3); color: var(--text-2); }

.codex-chip.active {
  --face: var(--gold);
  --face-hi: var(--gold-lite);
  --face-lo: var(--gold-deep);
  color: #2a1804;
}

/* An active tier chip wears its own tier colour, so the filter and the data
   agree at a glance. */
.codex-chip[class*="tier-"].active {
  --face: var(--tier);
  --face-hi: rgba(255, 255, 255, 0.35);
  --face-lo: rgba(0, 0, 0, 0.35);
  color: var(--outline);
}

.codex-chip.tier-SPP.active::before { background: var(--spectrum); }

.codex-search-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.text-input {
  flex: 1;
  min-width: 0;
  background: var(--outline);
  border: 3px solid var(--line);
  box-shadow: inset 2px 2px 0 rgba(0, 0, 0, 0.6);
  padding: 7px 10px;
  color: var(--text);
  font-family: var(--font-pixel);
  font-size: 0.9rem;
  outline: none;
}

.text-input::placeholder { color: var(--text-3); }
.text-input:focus { border-color: var(--gold); }

.codex-result-count { font-size: 8px; white-space: nowrap; }

.codex-grid,
.specimen-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
  /* Without this a flex child refuses to shrink below its content height
     and the list gets squeezed out of existence on short screens. */
  min-height: 0;
  padding: 2px 4px 2px 2px;
  scrollbar-color: var(--line-strong) var(--outline);
}

.specimen-row {
  background: var(--ink-2);
  border: 3px solid var(--outline);
  box-shadow: inset 2px 2px 0 var(--hi), inset -2px -2px 0 var(--lo);
  padding: 6px 8px;
  display: grid;
  grid-template-columns: 44px 38px 1fr;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  /* The list is a fixed-height flex column; rows must scroll, not squash. */
  flex-shrink: 0;
  font-family: var(--font-pixel);
}

.specimen-row:hover { background: var(--ink-3); }

.specimen-row.active-selected {
  background: var(--ink-3);
  box-shadow: inset 0 0 0 3px var(--gold), inset 5px 5px 0 var(--hi);
}

.specimen-row.locked { background: var(--ink-1); }
.specimen-row.locked .specimen-row-body,
.specimen-row.locked .specimen-row-head { opacity: 0.6; }

.specimen-row-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
}

.specimen-row-code {
  font-size: 9px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.specimen-row-tier {
  display: inline-block;
  min-width: 24px;
  font-family: var(--font-label);
  font-size: 9px;
  font-weight: 700;
  padding: 0 4px;
  line-height: 1.5;
  text-align: center;
  color: var(--outline);
  background: var(--tier, var(--ink-4));
  border: 2px solid var(--outline);
}

.specimen-row-icon {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--outline);
}

.specimen-row-body { min-width: 0; }

.specimen-row-name {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-shadow: 1px 1px 0 var(--outline);
}

.specimen-row-count {
  display: block;
  font-family: var(--font-label);
  font-size: 9px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

.codex-no-results {
  color: var(--text-3);
  font-size: 0.9rem;
  text-align: center;
  padding: 30px 14px;
}

.catalog-detail-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px 22px;
  overflow-y: auto;
  min-height: 0;
  background: var(--ink-0);
  scrollbar-color: var(--line-strong) var(--outline);
}

.detail-back {
  display: none;
  align-self: flex-start;
  color: var(--text-2);
  font-size: 0.85rem;
  padding: 5px 12px 7px;
  margin-bottom: 14px;
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  color: var(--text-3);
  padding: 24px;
}

.detail-empty p { max-width: 32ch; font-size: 0.95rem; }

.detail-empty-art { opacity: 0.55; filter: grayscale(0.6); }

.specimen-detail { display: flex; flex-direction: column; }

.inspector-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 3px dashed var(--line);
  margin-bottom: 18px;
}

.insp-title-box { min-width: 0; }

.dex-num-badge {
  display: block;
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.insp-name {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1.05;
  text-wrap: balance;
  text-shadow: 3px 3px 0 var(--outline);
}

.insp-category {
  display: block;
  font-size: 0.95rem;
  color: var(--text-2);
  margin-top: 4px;
}

/* Specimen plate: the sprite on a gridded slide, lit in its tier colour. */
.specimen-plate {
  position: relative;
  height: 292px;
  border: 3px solid var(--outline);
  box-shadow: inset 0 0 0 3px var(--line), var(--drop);
  background:
    linear-gradient(rgba(143, 132, 184, 0.07) 1px, transparent 1px) 0 0 / 16px 16px,
    linear-gradient(90deg, rgba(143, 132, 184, 0.07) 1px, transparent 1px) 0 0 / 16px 16px,
    var(--ink-1);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 20px;
}

.screen-glow {
  /* app.js sets this inline to the inspected cell's own colour. */
  --plate-tier: var(--gold);
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  opacity: 0.9;
  background: radial-gradient(circle,
      color-mix(in srgb, var(--plate-tier, var(--gold)) 22%, transparent) 0 32%,
      color-mix(in srgb, var(--plate-tier, var(--gold)) 12%, transparent) 32% 48%,
      color-mix(in srgb, var(--plate-tier, var(--gold)) 6%, transparent) 48% 64%,
      transparent 64%);
}

.screen-art { position: relative; z-index: 2; }

.specs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 20px;
}

.spec-card {
  background: var(--ink-2);
  border: 3px solid var(--outline);
  box-shadow: inset 2px 2px 0 var(--hi), inset -2px -2px 0 var(--lo);
  padding: 8px 11px 9px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.spec-label { font-size: 9px; }

.spec-value {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 500;
}

.stats-section, .bio-section, .facts-section { margin-bottom: 22px; }

.stats-section h4,
.bio-section h4,
.facts-section h4,
.settings-section h3 {
  font-family: var(--font-label);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 3px dashed var(--line);
}

.stat-bar-group { display: flex; flex-direction: column; gap: 9px; }

.stat-bar-item {
  display: grid;
  grid-template-columns: 96px 1fr 32px;
  align-items: center;
  gap: 11px;
}

.stat-name { font-size: 0.88rem; color: var(--text-2); }

.bar-track {
  height: 14px;
  background: var(--outline);
  border: 3px solid var(--line);
  padding: 1px;
}

/* Segmented like the Breakthrough gauge; the colour is the cell's own. */
.bar-fill {
  height: 100%;
  -webkit-mask: repeating-linear-gradient(90deg, #000 0 6px, transparent 6px 8px);
  mask: repeating-linear-gradient(90deg, #000 0 6px, transparent 6px 8px);
  transition: width 0.5s steps(8);
}

.stat-num {
  font-family: var(--font-label);
  font-size: 11px;
  color: var(--text-2);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.insp-bio-text {
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-2);
  max-width: 62ch;
}

.facts-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }

.facts-list li {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-2);
  padding-left: 18px;
  position: relative;
  max-width: 62ch;
}

.facts-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.5em;
  width: 8px;
  height: 8px;
  background: var(--gold);
  box-shadow: 2px 2px 0 var(--outline);
}

/* Further reading, after the field notes: a white key, like the page's
   other buttons, carrying a pixel Wikipedia "W". Centred under every entry. */
.wiki-link {
  --face: #f4f1f8;
  --face-hi: #ffffff;
  --face-lo: #b9b2cc;
  align-self: center;
  margin-top: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 16px 9px;
  font-family: var(--font-pixel);
  font-weight: 600;
  font-size: 0.85rem;
  color: #1b1030;
  text-decoration: none;
}

/* 2x the 12px glyph grid, so every pixel of the W lands whole. */
.wiki-link .icon { width: 24px; height: 24px; }
.wiki-link.btn-secondary:hover:not(:disabled) { --face: #ffffff; color: #1b1030; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 3, 13, 0.7);
  z-index: 95;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.24s steps(3);
}

.drawer-backdrop.active { opacity: 1; pointer-events: auto; }

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 3, 13, 0.8);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s steps(3);
}

.modal-box {
  background: var(--ink-1);
  width: 100%;
  max-width: 480px;
  /* When the Android keyboard opens for the save-code field the viewport
     roughly halves; the dialog scrolls instead of being clipped. */
  max-height: 90dvh;
  overflow-y: auto;
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: inset 0 0 0 3px var(--line-strong), inset 5px 5px 0 var(--hi), inset -5px -5px 0 var(--lo), var(--drop-lg);
  animation: slideUp 0.24s steps(4);
  scrollbar-color: var(--line-strong) var(--outline);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 3px dashed var(--line);
}

.modal-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--gold-deep), 4px 4px 0 var(--outline);
}

.modal-body { display: flex; flex-direction: column; gap: 22px; }

.settings-section { display: flex; flex-direction: column; gap: 10px; }

.settings-section h3 { margin-bottom: 0; }

.settings-desc { font-size: 0.9rem; color: var(--text-2); line-height: 1.45; }

/* --------------------------------------------------------- volume sliders */

.volume-row {
  display: grid;
  grid-template-columns: 60px 1fr 44px;
  align-items: center;
  gap: 10px;
}

.volume-row label { font-size: 0.9rem; color: var(--text-2); }

.volume-value {
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--text-3);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Square track, square thumb. */
.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 12px;
  background: var(--outline);
  border: 3px solid var(--line);
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 20px;
  background: var(--gold);
  border: 3px solid var(--outline);
  box-shadow: inset 0 -3px 0 var(--gold-deep);
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 12px;
  height: 16px;
  border-radius: 0;
  background: var(--gold);
  border: 3px solid var(--outline);
  box-shadow: inset 0 -3px 0 var(--gold-deep);
  cursor: pointer;
}

.volume-slider:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* -------------------------------------------------------------- milestones */

.achievements-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 3px dashed var(--line);
  padding-bottom: 6px;
}

.achievements-head h3 { border-bottom: none; padding-bottom: 0; }

.achievements-count {
  font-family: var(--font-label);
  font-size: 11px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.achievements-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  padding: 2px 4px 2px 2px;
  scrollbar-color: var(--line-strong) var(--outline);
}

.achievement-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 7px 10px 8px;
  background: var(--ink-2);
  border: 3px solid var(--outline);
  box-shadow: inset 2px 2px 0 var(--hi), inset -2px -2px 0 var(--lo);
}

.achievement-row.locked { opacity: 0.55; }

.achievement-mark {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  background: var(--outline);
  border: 3px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.achievement-row.unlocked .achievement-mark {
  background: var(--gold);
  border-color: var(--outline);
  color: #2a1804;
}

.achievement-row.unlocked .achievement-mark .icon { width: 12px; height: 12px; }

/* The two milestones tied to Tier S++ - itself rainbow by design - get the
   same spectrum treatment once unlocked, instead of the ordinary gold. */
.achievement-row.unlocked.is-major .achievement-mark { background: var(--spectrum); }
.achievement-row.unlocked.is-major { box-shadow: inset 0 0 0 3px var(--tier-spp), inset 5px 5px 0 var(--hi); }

.achievement-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.achievement-name { font-size: 0.92rem; font-weight: 600; color: var(--text); }
.achievement-desc { font-size: 0.8rem; color: var(--text-3); line-height: 1.35; }

.save-status-box {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--outline);
  border: 3px solid var(--line);
  padding: 8px 12px;
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--text-2);
}

.code-action-row { display: flex; gap: 9px; flex-wrap: wrap; }

.import-box { display: flex; gap: 9px; }

.btn-danger {
  --face: var(--danger-deep);
  --face-hi: rgba(255, 170, 180, 0.35);
  --face-lo: rgba(0, 0, 0, 0.4);
  color: #ffe9ec;
  padding: 10px 14px 12px;
  font-size: 0.92rem;
  width: 100%;
}

.btn-danger:hover:not(:disabled) { --face: #c42e47; }

.btn-danger.armed {
  --face: var(--danger);
  color: #2b0309;
  animation: blink 0.6s steps(1, end) infinite;
}

.danger-zone { padding-top: 2px; }

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-2);
  padding: 10px 16px 11px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 300;
  animation: slideUp 0.24s steps(4);
  font-size: 0.95rem;
  max-width: calc(100vw - 32px);
  box-shadow: inset 0 0 0 3px var(--line-strong), var(--bevel), var(--drop-lg);
}

.toast-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: var(--outline);
  color: var(--gold);
}

.toast-icon .icon { width: 24px; height: 24px; }

/* ------------------------------------------------------------- tutorial */

.tutorial-backdrop {
  z-index: 210;
  background: rgba(6, 3, 13, 0.9);
}

.tutorial-box {
  /* Wide enough for six 64px tier icons in one row. */
  max-width: 492px;
  gap: 12px;
  text-align: center;
  box-shadow: inset 0 0 0 3px var(--gold), inset 5px 5px 0 var(--hi), inset -5px -5px 0 var(--lo), var(--drop-lg);
}

.tutorial-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tutorial-step-label {
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--text-3);
  text-transform: uppercase;
}

.tutorial-art {
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 207, 58, 0.12) 0 60px, rgba(255, 207, 58, 0.06) 60px 90px, transparent 90px),
    var(--outline);
  border: 3px solid var(--line);
  padding: 10px;
}

.tutorial-title {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--gold-deep), 4px 4px 0 var(--outline);
  text-wrap: balance;
}

.tutorial-text {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 1rem;
  line-height: 1.45;
  color: var(--text-2);
}

.tutorial-text strong { color: var(--text); font-weight: 700; }

.tutorial-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.tutorial-dot {
  width: 10px;
  height: 10px;
  background: var(--ink-3);
  border: 2px solid var(--outline);
}

.tutorial-dot.done { background: var(--gold-deep); }
.tutorial-dot.active { background: var(--gold); width: 22px; }

.tutorial-actions {
  display: flex;
  gap: 10px;
}

.tutorial-actions .btn-secondary { flex: 0 0 auto; }
.tutorial-actions .btn-primary { flex: 1; }

/* Illustrations built from real sprites and real controls. */
.tutorial-pulls {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 360px;
}

.tutorial-pull {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px 14px;
  border: 3px solid var(--outline);
  font-size: 0.95rem;
}

.tutorial-pull span { font-family: var(--font-label); font-size: 10px; opacity: 0.8; }
.tutorial-pull.primary { background: var(--gold); color: #2a1804; box-shadow: inset 0 2px 0 var(--gold-lite), inset 0 -4px 0 var(--gold-deep); }
.tutorial-pull.special { background: var(--cyan); color: #04223a; box-shadow: inset 0 2px 0 #c8f6ff, inset 0 -4px 0 var(--cyan-deep); }

.tutorial-tiers {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  width: 100%;
}

.tutorial-tier {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tutorial-tier .tier-badge { font-size: 9px; padding: 0 4px; }
.tutorial-tier.tier-SPP .tier-badge { background: var(--spectrum); }

.tutorial-rate {
  font-family: var(--font-label);
  font-size: 8px;
  color: var(--text-3);
}

.tutorial-dex {
  display: grid;
  grid-template-columns: repeat(4, 64px);
  gap: 8px;
}

/* ------------------------------------------------------------ animations */

@keyframes px-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

@keyframes rapid-vibrate {
  0% { transform: translate(2px, 2px); }
  25% { transform: translate(-2px, -2px); }
  50% { transform: translate(-2px, 2px); }
  75% { transform: translate(2px, -2px); }
  100% { transform: translate(2px, 0); }
}

@keyframes split-out-left {
  0% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-190%, -50%); }
}

@keyframes split-out-right {
  0% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(90%, -50%); }
}

@keyframes rotate { to { transform: translate(-50%, -50%) rotate(360deg); } }

@keyframes card-entry {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Used where `transform` is already spoken for (the centred toast). */
.toast { animation-name: fadeIn; }

@keyframes blink {
  0%, 100% { filter: none; }
  50% { filter: brightness(1.4); }
}

@keyframes aura-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes spectrum-shift { to { background-position: 300% 0; } }

/* S++ cards cycle their outer ring through the spectrum, one hard frame at
   a time. */
@keyframes spectrum-ring {
  0%   { box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #ff5a6e, var(--drop-lg); }
  17%  { box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #ffb13a, var(--drop-lg); }
  33%  { box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #ffe45e, var(--drop-lg); }
  50%  { box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #5fe08a, var(--drop-lg); }
  67%  { box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #5fe1ff, var(--drop-lg); }
  83%  { box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #8f7bff, var(--drop-lg); }
  100% { box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #ff5a6e, var(--drop-lg); }
}

/* S++ carries the spectrum; every other tier is a flat colour. */
.tier-SPP .tier-badge,
.tier-badge.tier-SPP,
.mini-card.tier-SPP .mini-tier,
.tier-SPP .specimen-row-tier {
  background: var(--spectrum);
  background-size: 300% 100%;
  animation: spectrum-shift 6s steps(42) infinite;
  color: var(--outline);
}

/* ============================================================== RESPONSIVE */

@media (max-width: 900px) {
  .codex-drawer { width: 100vw; max-width: 100vw; }
  .catalog-list-pane { width: 300px; min-width: 260px; }
}

/* Phone: list and detail are separate views, not two panes fighting for
   room. The detail slides over the list and a back control returns. */
@media (max-width: 768px) {
  .catalog-body { position: relative; }

  .catalog-list-pane {
    width: 100%;
    min-width: 0;
    border-right: none;
  }

  .catalog-detail-pane {
    position: absolute;
    inset: 0;
    transform: translateX(100%);
    transition: transform 0.28s steps(6);
    z-index: 2;
  }

  .codex-drawer.detail-open .catalog-detail-pane { transform: translateX(0); }

  .detail-back { display: inline-flex; }

  .multi-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 560px) {
  .app-container { padding: 8px 12px 12px 8px; }
  .app-header { padding: 6px 8px; gap: 6px; margin-bottom: 10px; }
  .header-controls { gap: 6px; }
  .brand-text h1.atlas-title { font-size: 1.3rem; letter-spacing: 0.1em; }
  .dna-icon { display: none; }
  .btn-label-text { display: none; }
  .atp-display .atp-label { display: none; }
  .atp-display { padding: 4px 8px; }

  .multi-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .insp-name { font-size: 1.45rem; }
  .catalog-detail-pane { padding: 14px; }
  .stat-bar-item { grid-template-columns: 80px 1fr 28px; gap: 8px; }
  .rate-bar { gap: 6px; }
  .pull-btn { min-height: 58px; }
  .btn-title { font-size: 0.95rem; }

  /* Four sprites to a row is too tight for 64px each. */
  .tutorial-tiers { grid-template-columns: repeat(3, 1fr); row-gap: 10px; }
  .tutorial-dex { gap: 6px; }
  .tutorial-title { font-size: 1.35rem; }
  .tutorial-text { font-size: 0.95rem; }
}

/* The stage is a sprite drawn at 2x; below this it drops to 1x. */
@media (max-width: 400px), (max-height: 720px) {
  .stem-cell-container { width: 200px; height: 200px; }
  .origin-cell-graphic { width: 128px; height: 128px; }
  .aura-glow { width: 190px; height: 190px; }
  .chamber-ring { width: 240px; height: 240px; }
  .rays-far { width: 340px; height: 340px; }
  .rays-near { width: 260px; height: 260px; }
  .prism-rays { width: 300px; height: 300px; }
  .origin-title-badge { margin-top: -34px; }
}

/* Reveal card on phones and any short viewport: art at 1x. */
@media (max-width: 500px), (max-height: 820px) {
  .reveal-view, .multi-reveal-view { padding: 14px; }
  .card-stage { gap: 12px; }
  .result-card { padding: 13px 13px 15px; }
  .card-art-container { width: 144px; height: 144px; margin: 0; }
  .card-art .pixel-art { width: 128px; height: 128px; }
  .bio-text { font-size: 0.86rem; }
  .cell-name { font-size: 1.25rem; }
  .card-divider { margin: 7px 0; }
  .stats-row { padding: 6px 5px; margin-top: 10px; }
  .reveal-actions { gap: 8px; }
}

/* Very short screens: small phones in portrait. */
@media (max-height: 660px) {
  .reveal-view .bio-text { display: none; }
  .card-stage { gap: 8px; }
  .tutorial-art { min-height: 0; }
  .tutorial-art > .pixel-art { width: 64px; height: 64px; }
}

/* Short viewports: phone landscape, or portrait with the keyboard up. */
@media (max-height: 560px) {
  .app-container { padding: 6px 10px 10px 6px; }
  .app-header { padding: 5px 10px; margin-bottom: 7px; }
  .brand-text h1.atlas-title { font-size: 1.15rem; }

  .incubator-view { padding: 10px; gap: 8px; }
  .stem-cell-container { width: 140px; height: 140px; }
  .origin-cell-graphic { width: 128px; height: 128px; }
  .chamber-ring { display: none; }
  /* The pull controls take priority on a screen this short. */
  .origin-title-badge { display: none; }

  .action-panel { gap: 10px; }
  .pull-btn { padding: 8px 10px 10px; min-height: 48px; }
  .btn-title { font-size: 0.88rem; }
  /* Secondary progress info; the core pull controls take priority on a
     screen this short. */
  .pity-meter { display: none; }
  .rate-bar { margin-top: 8px; gap: 6px; }

  .codex-summary { display: none; }
  .codex-filters { gap: 4px; margin-bottom: 6px; }
  .codex-search-row { margin-bottom: 6px; }
  .catalog-header { padding: 8px 14px; }
  .catalog-titles h2 { font-size: 1.2rem; }
  .catalog-subtitle { display: none; }
  .specimen-row { padding: 4px 8px; }
  .specimen-plate { height: 160px; }
  .screen-art .pixel-art { width: 128px; height: 128px; }
  .modal-box { max-height: 94dvh; padding: 12px 14px 14px; gap: 10px; }
  .tutorial-art { display: none; }
}

/* Chip rows go horizontal on narrow OR short screens: phone landscape is
   851px WIDE but ~340px tall, so a width-only query misses it and the
   lineage chips grow into a wall that collapses the list to zero height. */
@media (max-width: 768px), (max-height: 560px) {
  .chip-row,
  .chip-row.wrap {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .chip-row::-webkit-scrollbar { display: none; }
  .chip-row .codex-chip,
  .chip-row.wrap .codex-chip { flex: 0 0 auto; }
}

/* Phone inspector plate: a 2x sprite needs 262px; fall back to 1x. */
@media (max-width: 340px) {
  .specimen-plate { height: 170px; }
  .screen-art .pixel-art { width: 128px; height: 128px; }
}

/* Touch devices: 44px minimum target. */
@media (pointer: coarse) {
  .btn-icon,
  .catalog-close { min-width: 44px; min-height: 44px; }
  #codex-toggle-btn { min-height: 44px; }
  .specimen-row { min-height: 52px; }
  .codex-chip { min-height: 34px; }
  .detail-back { min-height: 40px; }
  .btn-text { min-height: 44px; }
}

/* ========================================================= REDUCED MOTION
   Ambient loops and the flash are suppressed. Entry animations collapse to a
   near-zero duration rather than being removed, because card-entry starts at
   opacity 0 - disabling it outright would leave result cards invisible. */
@media (prefers-reduced-motion: reduce) {
  .ascension-motes span { animation: none !important; opacity: 0.8; }

  .chamber-ring,
  .god-rays,
  .prism-rays,
  .finale-art.radiant::before,
  .origin-cell-graphic.idle-pulse,
  .origin-cell-graphic.charging-vibrate,
  .charging .aura-glow,
  .pity-meter.charged .pity-meter-fill,
  .btn-danger.armed {
    animation: none !important;
  }

  .result-card,
  .mini-card,
  .toast,
  .modal-box,
  .modal-backdrop,
  .specimen-detail {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
  }

  .mitosis-clone.split-left,
  .mitosis-clone.split-right { animation-duration: 0.01ms !important; }

  .flash-overlay.active { opacity: 0 !important; }

  .codex-drawer,
  .drawer-backdrop,
  .specimen-row,
  .catalog-detail-pane,
  .pity-meter-fill,
  .bar-fill { transition: none !important; }

  /* Mass mitosis reveal: JS already shortens every delay to ~0 (see
     prefersReducedMotion in app.js), so this only needs to stop the CSS-driven
     parts - the face-down pulse and the flip/scale transitions. */
  .mini-card.face-down { animation: none !important; opacity: 0.8; }
  .mini-card.flipping { animation-duration: 0.01ms !important; }
  .mini-showcase,
  .mini-showcase-card { transition-duration: 0.01ms !important; }

  .tier-SPP .tier-badge,
  .tier-badge.tier-SPP,
  .mini-card.tier-SPP .mini-tier,
  .tier-SPP .specimen-row-tier {
    animation: none !important;
    background-position: 45% 0;
  }

  .result-card.tier-SPP {
    animation-duration: 0.01ms !important;
    box-shadow: inset 0 0 0 3px var(--tier-spp), 0 0 0 3px var(--outline), 0 0 0 7px #8f7bff, var(--drop-lg);
  }
}

/* ------------------------------------------------------------------ icons
   12x12 pixel glyphs coloured by currentColor, so they inherit hover and
   disabled states for free. Sized at whole multiples of 12. */
.icon-sprite { display: none; }

.icon {
  width: 24px;
  height: 24px;
  display: block;
  flex-shrink: 0;
}

.dna-icon .icon { width: 36px; height: 36px; color: var(--gold); filter: drop-shadow(2px 2px 0 var(--outline)); }
.atp-icon .icon { width: 12px; height: 12px; color: var(--gold); }
.btn-secondary .icon,
.btn-danger .icon,
.detail-back .icon { width: 12px; height: 12px; }

.codex-btn-inner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

#sound-btn { color: var(--text-3); }
#sound-btn.sound-active { color: var(--gold); }

/* Lineage chips are numerous; keep them compact so they do not eat the list. */
.chip-row.wrap .codex-chip { font-size: 9px; padding: 3px 7px 5px; }

/* ============================================================= THE BODY */

/* ATP readout: production slows as the balance grows, so the pill says how
   fast it is right now. */
.atp-rate {
  font-family: var(--font-label);
  font-size: 9px;
  color: var(--text-3);
  white-space: nowrap;
  border-left: 2px solid var(--line);
  padding-left: 8px;
}

/* Two tabs above the stage: pulling cells, and building the body. */
.stage-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.stage-tab {
  --face: var(--ink-2);
  --face-hi: rgba(255, 255, 255, 0.14);
  --face-lo: rgba(0, 0, 0, 0.42);
  position: relative;
  isolation: isolate;
  clip-path: var(--notch);
  background: var(--outline);
  padding: 6px 16px 9px;
  color: var(--text-2);
  font-size: 1rem;
  font-weight: 700;
  gap: 8px;
}

.stage-tab::before {
  content: '';
  position: absolute;
  inset: 3px;
  clip-path: polygon(2px 0, calc(100% - 2px) 0, 100% 2px, 100% calc(100% - 2px),
                     calc(100% - 2px) 100%, 2px 100%, 0 calc(100% - 2px), 0 2px);
  background: var(--face);
  box-shadow: inset 0 2px 0 var(--face-hi), inset 0 -4px 0 var(--face-lo);
  z-index: -1;
}

.stage-tab:hover { --face: var(--ink-3); color: var(--text); }
.stage-tab:active { transform: translateY(2px); }

.stage-tab.active {
  --face: var(--gold);
  --face-hi: var(--gold-lite);
  --face-lo: var(--gold-deep);
  color: #2a1804;
}

.stage-tab.active .badge { background: rgba(42, 24, 4, 0.85); }

/* "Something is ready": a blinking pixel, like a notification LED. */
.ready-dot {
  width: 8px;
  height: 8px;
  background: var(--cyan);
  box-shadow: 0 0 0 2px var(--outline);
  animation: blink-dot 1s steps(1, end) infinite;
  flex-shrink: 0;
}

@keyframes blink-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

.body-view {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  overflow: hidden;
}

.body-view:focus { outline: none; }

.body-map-pane {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
}

/* The specimen tank: a gridded, dark window the body floats in. */
.body-tank {
  padding: 12px 18px;
  border: 3px solid var(--outline);
  box-shadow: inset 0 0 0 3px var(--line), var(--drop);
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255, 207, 58, 0.07) 0 40%, rgba(255, 207, 58, 0.035) 40% 60%, transparent 60%),
    linear-gradient(rgba(143, 132, 184, 0.06) 1px, transparent 1px) 0 0 / 16px 16px,
    linear-gradient(90deg, rgba(143, 132, 184, 0.06) 1px, transparent 1px) 0 0 / 16px 16px,
    var(--outline);
}

#body-canvas {
  display: block;
  width: 320px;
  height: 480px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.body-summary {
  display: flex;
  flex-shrink: 0;
  justify-content: space-around;
  gap: 8px;
  padding: 8px 10px;
  background: var(--outline);
  border: 3px solid var(--line);
}

.body-summary .summary-metric { min-width: 74px; }
.body-summary .metric-val { font-size: 1.05rem; }

.body-side {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  min-width: 0;
}

.region-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 6px;
  flex-shrink: 0;
}

.region-chip {
  /* Both set inline per region by app.js. */
  --region: var(--line-strong);
  --fill: 0%;
  position: relative;
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 8px;
  min-height: 36px;
  background: var(--ink-2);
  border: 3px solid var(--outline);
  box-shadow: inset 2px 2px 0 var(--hi), inset -2px -2px 0 var(--lo);
  color: var(--text-2);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  justify-content: stretch;
}

/* Progress as a strip along the bottom edge, in the region's colour. */
.region-chip::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: var(--fill, 0%);
  background: var(--region);
}

.region-chip:hover { background: var(--ink-3); color: var(--text); }
.region-chip.selected { box-shadow: inset 0 0 0 3px var(--gold), inset 5px 5px 0 var(--hi); color: var(--text); }

.region-swatch {
  width: 12px;
  height: 12px;
  background: var(--ink-4);
  box-shadow: 1px 1px 0 var(--outline);
}

.region-chip.partial .region-swatch {
  background: repeating-conic-gradient(var(--region) 0 25%, var(--ink-4) 0 50%) 0 0 / 4px 4px;
}

.region-chip.lit .region-swatch { background: var(--region); }
.region-chip.lit .region-name { color: var(--text); }

.region-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.region-tally {
  font-family: var(--font-label);
  font-size: 9px;
  color: var(--text-3);
}

.region-chip .ready-dot { position: absolute; top: -4px; right: -4px; }

.region-detail {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 6px 6px 2px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-color: var(--line-strong) var(--outline);
}

.region-head {
  --region: var(--gold);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 3px dashed var(--line);
  padding-bottom: 6px;
}

.region-head h3 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--region);
  text-shadow: 2px 2px 0 var(--outline);
}

.region-count {
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--text-3);
}

.region-blurb { color: var(--text-2); font-size: 0.95rem; }

.region-perk {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: var(--outline);
  border: 3px solid var(--line);
  color: var(--text-3);
  font-size: 0.88rem;
}

.region-perk .icon { width: 12px; height: 12px; margin-top: 3px; color: var(--text-3); }
.region-perk b { color: var(--text-2); font-weight: 700; }
.region-perk.active { border-color: var(--gold); color: var(--text-2); }
.region-perk.active .icon,
.region-perk.active b { color: var(--gold); }

.tissue-list { display: flex; flex-direction: column; gap: 10px; }

.tissue-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 12px;
  background: var(--ink-2);
  border: 3px solid var(--outline);
  box-shadow: inset 2px 2px 0 var(--hi), inset -2px -2px 0 var(--lo), var(--drop);
}

.tissue-card.ready { box-shadow: inset 0 0 0 3px var(--cyan), inset 5px 5px 0 var(--hi), var(--drop); }
.tissue-card.done { background: var(--ink-1); }

.tissue-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.tissue-head h4 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  text-shadow: 1px 1px 0 var(--outline);
}

.tissue-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-label);
  font-size: 9px;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
}

.tissue-card.ready .tissue-state { color: var(--cyan); }
.tissue-card.done .tissue-state { color: var(--gold); }
.tissue-state .icon { width: 12px; height: 12px; }

.tissue-fact { font-size: 0.88rem; color: var(--text-2); line-height: 1.4; }

.tissue-needs {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 4px;
}

.need {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 2px 8px 2px 2px;
  background: var(--outline);
  border: 2px solid var(--line);
}

.need-icon { width: 36px; height: 36px; display: grid; place-items: center; }

.need-name {
  font-size: 0.85rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.need.unknown .need-name { color: var(--text-3); }

.need-count {
  font-family: var(--font-label);
  font-size: 10px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

.need.met { border-color: color-mix(in srgb, var(--cyan) 55%, var(--line)); }
.need.met .need-count { color: var(--cyan); }

.tissue-action {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.assemble-btn { font-size: 0.9rem; padding: 8px 14px 10px; }

.assemble-hint {
  font-family: var(--font-label);
  font-size: 9px;
  text-transform: uppercase;
  color: var(--text-3);
}

/* Tutorial: the dark body beside the lit one. */
.tutorial-body { display: flex; gap: 12px; }

/* Finale */
.finale-backdrop { z-index: 220; }

.finale-box {
  max-width: 440px;
  text-align: center;
  align-items: center;
  box-shadow: inset 0 0 0 3px var(--gold), inset 5px 5px 0 var(--hi), inset -5px -5px 0 var(--lo), var(--drop-lg);
}

/* Never shrunk by the column: pixel art only at whole multiples. The body
   slide is tall; the origin cell and the trophies are square, at 2x. */
.finale-art { position: relative; isolation: isolate; flex-shrink: 0; width: 160px; height: 240px; }
.finale-art.square { width: 256px; height: 256px; }

/* A slow sunburst behind the square slides. */
.finale-art.radiant::before {
  content: '';
  position: absolute;
  inset: -36px;
  z-index: -1;
  border-radius: 50%;
  background: repeating-conic-gradient(from 0deg,
    rgba(255, 207, 58, 0.2) 0deg 6deg, transparent 6deg 15deg,
    rgba(255, 241, 176, 0.1) 15deg 18deg, transparent 18deg 30deg);
  -webkit-mask-image: radial-gradient(circle, #000 0 45%, transparent 70%);
  mask-image: radial-gradient(circle, #000 0 45%, transparent 70%);
  animation: spin 90s steps(180) infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
.finale-art .pixel-art { position: absolute; inset: 0; width: 100%; height: 100%; }
.finale-text { color: var(--text-2); }

/* The Cyto-Dex trophy shelf: each trophy replays its ending. */
.trophy-shelf {
  display: flex;
  gap: 4px;
  margin-left: auto;
  margin-right: 8px;
}

.trophy-btn {
  background: none;
  padding: 2px;
  min-width: 38px;
  min-height: 38px;
}

.trophy-btn:hover .pixel-art,
.trophy-btn:focus-visible .pixel-art { filter: brightness(1.25) drop-shadow(0 0 4px rgba(255, 207, 58, 0.6)); }

.finale-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  width: 100%;
}

.finale-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  background: var(--outline);
  border: 3px solid var(--line);
}

.finale-box .btn-primary { width: 100%; }

@media (max-width: 860px) {
  /* One column: the body on top, the regions and tissues below it, and the
     whole view scrolls instead of each pane. */
  .body-view {
    grid-template-columns: minmax(0, 1fr);
    grid-auto-rows: max-content;
    overflow-y: auto;
    padding: 14px;
    align-content: start;
  }
  .body-map-pane, .region-detail { overflow: visible; min-height: auto; }
  .body-side { min-height: auto; }
}

@media (max-width: 560px) {
  .atp-rate { display: none; }
  .stage-tab { flex: 1; font-size: 0.92rem; padding: 5px 10px 8px; }
  .region-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tissue-needs { grid-template-columns: minmax(0, 1fr); }
  .body-summary .summary-metric { min-width: 0; }
  .tutorial-body .pixel-art:first-child { display: none; }
}

/* The finale shows the body at 2x only where it fits with its text. */
@media (min-height: 1000px) and (min-width: 561px) {
  .finale-art.tall { width: 320px; height: 480px; }
}

/* Short or narrow screens: the square slides at 1x. */
@media (max-height: 720px), (max-width: 340px) {
  .finale-art.square { width: 128px; height: 128px; }
}

@media (max-height: 640px) {
  .tutorial-body { display: none; }
}

@media (max-height: 560px) {
  .stage-tabs { margin-bottom: 5px; }
  .stage-tab { padding: 3px 12px 6px; font-size: 0.85rem; }
  #body-canvas { width: 160px; height: 240px; }
}

@media (prefers-reduced-motion: reduce) {
  .ready-dot { animation: none; }
}

/* ------------------------------------------------------------- phone bar
   The whole top bar on one row. Placed after the touch-target rules above,
   which it tightens: the author's link and the two icon keys give up a few
   pixels, and on the narrowest phones the Cyto-Dex key keeps its count but
   drops its book icon. Below 340px the bar may wrap again rather than spill. */
@media (max-width: 560px) {
  .app-header { flex-wrap: nowrap; padding: 6px; }
  .brand { gap: 6px; flex-shrink: 0; }
  .brand-text h1.atlas-title { font-size: 1.1rem; letter-spacing: 0.06em; }
  .header-controls { flex-wrap: nowrap; gap: 4px; }
  .atp-display { padding: 4px 6px; gap: 5px; }
  .author-link { min-width: 34px; min-height: 34px; }
  #sound-btn,
  #settings-btn { min-width: 40px; }
  #codex-toggle-btn { padding: 7px 8px 9px; }
  #codex-toggle-btn .codex-btn-inner { gap: 6px; }
}

@media (max-width: 400px) {
  .app-container { padding-left: 6px; padding-right: 6px; }
  .app-header { gap: 4px; padding: 6px 4px; }
  .brand { gap: 4px; }
  .brand-text h1.atlas-title { font-size: 1rem; letter-spacing: 0.04em; }
  .author-link { min-width: 32px; }
  .atp-display { padding: 4px 5px; gap: 4px; }
  #sound-btn,
  #settings-btn { min-width: 36px; }
  #codex-toggle-btn { padding: 7px 6px 9px; }
  #codex-toggle-btn .codex-btn-inner .icon { display: none; }
}

@media (max-width: 340px) {
  .app-header { flex-wrap: wrap; }
}
