/* ===== Grubs TD — picnic-sticker design language =====
   ink #2b1a10 · cream #fff3d6 · picnic red #e2472f · leaf #63a832 · honey #f5a623 */

/* Baloo 2 (SIL OFL, self-hosted variable font) — the chunky-rounded display voice */
@font-face {
  font-family: 'Baloo 2';
  src: url('../assets/fonts/Baloo2-var.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #2b1a10;
  --cream: #fff3d6;
  --paper: #f8efd4;
  --red: #e2472f;
  --leaf: #63a832;
  --leaf-dark: #3f7a22;
  --honey: #f5a623;
  --amber: #8a5400;
  --wood: #8a5a33;
  --sky: #8fd3e8;
  /* the foil: one gold gradient shared by every clipped header */
  --foil: linear-gradient(168deg, #fff3c8 8%, #ffd166 32%, #f5a623 55%, #c97a10 78%, #ffd166 96%);
  /* procedural paper tooth — two offset speckle grids + a soft sheen, all gradients */
  --tex-paper:
    radial-gradient(rgba(43, 26, 16, 0.05) 1px, transparent 1.1px),
    radial-gradient(rgba(255, 255, 255, 0.6) 1px, transparent 1.15px),
    linear-gradient(rgba(255, 255, 255, 0.05), rgba(43, 26, 16, 0.04));
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: 'Baloo 2', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  /* dusk-table backdrop: deep warm ink-browns with a honey key light from above —
     the board is the bright thing on the table, the chrome recedes (was lawn green,
     which fought the playfield for attention) */
  background:
    radial-gradient(ellipse at 50% 18%, rgba(255, 209, 102, 0.12) 0%, transparent 58%),
    radial-gradient(ellipse at 50% 118%, #5c3a1e 0%, transparent 72%),
    linear-gradient(180deg, #241407 0%, #33200f 55%, #3d2712 100%);
  overflow: hidden;
}

.hidden { display: none !important; }

/* Auto margins center the content when it fits and collapse to 0 when it
   overflows — so tall menus scroll from the top instead of clipping their head
   (the old centered-flex bug hit every window shorter than the menu). */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  overflow: auto;
}
.title-inner, .menu-inner { margin: auto; }

/* ---------- sticker language ---------- */

.sticker {
  background: var(--cream);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85);
  color: var(--ink);
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.sticker:hover:not(:disabled) {
  transform: translate(-1px, -1px) rotate(-0.4deg);
  box-shadow: 5px 5px 0 rgba(43, 26, 16, 0.85);
}
.sticker:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(43, 26, 16, 0.85);
}
.sticker:disabled { cursor: default; opacity: 0.75; }
.sticker:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

/* ---------- menu ---------- */

.menu-inner {
  text-align: center;
  padding: 24px;
  max-width: 760px;
}
/* the Levels screen is a workbench, not the marquee — logo shrinks, tagline rests */
#screen-menu .logo { font-size: clamp(34px, 5vw, 52px); }
#screen-menu .tagline { display: none; }

.logo {
  font-size: clamp(52px, 9vw, 88px);
  font-weight: 900;
  letter-spacing: -2px;
  color: var(--cream);
  text-shadow: 4px 4px 0 var(--ink), -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink);
  transform: rotate(-2deg);
}
.logo-td {
  display: inline-block;
  margin-left: 10px;
  color: var(--honey);
  transform: rotate(4deg);
}

.tagline {
  color: var(--cream);
  font-weight: 700;
  font-size: 17px;
  text-shadow: 2px 2px 0 rgba(43, 26, 16, 0.6);
  margin: 10px 0 22px;
}

/* ---------- title screen: cinematic key art, drawn live by the game ---------- */
#title-scene { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
/* the Levels screen looks over the same meadow, a step out of focus; fixed so the
   decision column scrolls OVER the world (z:-1 keeps every unpositioned child above it) */
#menu-scene { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -1; }
.title-inner { position: relative; z-index: 1; text-align: center; padding: 24px; max-width: 620px; }
/* soft scrim so type and buttons sit ON the scene, not fight it */
.title-inner::before {
  content: ''; position: absolute; inset: -24px 0; /* stays inside the viewport — an overhanging scrim created phantom h-scroll */
  background: radial-gradient(ellipse at 50% 42%, rgba(43, 26, 16, 0.16), transparent 68%);
  z-index: -1; pointer-events: none;
}

/* the logo goes foil-gold: gradient fill, ink stroke, extrusion, sheen sweep.
   The clip lives on .logo-g so no TRANSFORMED child sits inside a clipped box —
   background-clip:text + transformed descendants paints ghost glyphs in Chromium.
   The Levels screen wears the same foil at workbench size. */
#screen-title .logo, #screen-menu .logo {
  text-shadow: none;
  filter: drop-shadow(3px 4px 0 var(--ink)) drop-shadow(0 10px 18px rgba(120, 60, 10, 0.45));
}
#screen-title .logo { animation: logo-drop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }
#screen-title .logo-g, #screen-menu .logo-g {
  display: inline-block;
  background: var(--foil);
  background-size: 100% 220%;
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  -webkit-text-stroke: 2.5px var(--ink);
  animation: logo-sheen 7s ease-in-out 2s infinite;
}
#screen-title .logo-td, #screen-menu .logo-td { -webkit-text-stroke: 2.5px var(--ink); }
#screen-menu .logo-g, #screen-menu .logo-td { -webkit-text-stroke-width: 2px; }
@keyframes logo-drop {
  from { opacity: 0; transform: translateY(-46px) rotate(-2deg) scale(0.92); }
  to { opacity: 1; transform: translateY(0) rotate(-2deg) scale(1); }
}
@keyframes logo-sheen {
  0%, 82%, 100% { background-position: 0 0; }
  90% { background-position: 0 90%; }
}

/* staged entrance: hero first, then the supporting cast, all inside 500ms of stagger */
#screen-title .title-primer,
#screen-title #btn-title-play,
#screen-title .title-newhint,
#screen-title .title-row,
#screen-title .title-foot {
  animation: title-rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1.15) both;
}
#screen-title .title-primer { animation-delay: 0.18s; }
#screen-title #btn-title-play { animation-delay: 0.28s; }
#screen-title .title-newhint { animation-delay: 0.36s; animation-name: title-rise, pulse; animation-duration: 0.45s, 1.6s; animation-iteration-count: 1, infinite; }
#screen-title .title-row { animation-delay: 0.38s; }
#screen-title .title-foot { animation-delay: 0.46s; }
@keyframes title-rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: none; }
}
#screen-title .title-primer {
  color: #fffbef;
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink), 0 4px 10px rgba(43, 26, 16, 0.5);
}
#btn-title-play {
  background: linear-gradient(180deg, #ffd97a, var(--honey) 60%, #e08f0e);
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85), 0 0 26px rgba(255, 209, 102, 0.55);
}
.title-primer {
  color: var(--cream); font-weight: 700; font-size: 16px; line-height: 1.5;
  text-shadow: 2px 2px 0 rgba(43, 26, 16, 0.55); margin: 14px auto 26px; max-width: 440px;
}
#btn-title-play { font-size: 24px; padding: 16px 52px; }
.title-newhint {
  color: var(--cream); font-weight: 700; font-size: 13px; margin-top: 12px; opacity: 0.95;
  animation: pulse 1.6s infinite;
}
.title-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 22px; }
.title-row .mini-btn { font-size: 15px; padding: 11px 18px; }
.title-foot { display: flex; gap: 10px; justify-content: center; margin-top: 26px; }
.title-foot .mini-btn { font-size: 18px; padding: 8px 12px; background: var(--paper); }
.menu-back { position: absolute; top: 16px; left: 16px; }
@media (prefers-reduced-motion: reduce) {
  .title-newhint, .wave-warn, .bug-card, .ach-toast,
  .mc-start, .sr-chip.next,
  #screen-title .logo, #screen-title .logo-g, #screen-title .title-primer,
  #screen-title #btn-title-play, #screen-title .title-row, #screen-title .title-foot,
  #screen-menu .logo, #screen-menu .logo-g,
  #screen-menu.enter .logo, #screen-menu.enter #trail-wrap, #screen-menu.enter #diff-row,
  #screen-menu.enter #loadout, #screen-menu.enter #cta-dock, #screen-menu.enter #star-rewards,
  #screen-menu.enter .menu-foot { animation: none; }
}

#map-cards {
  display: flex;
  gap: 16px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.map-card {
  width: 168px;
  padding: 7px;
  text-align: left;
  font-size: 12px;
  position: relative;
  /* elevated sticker: the brand's hard offset + a real ambient drop underneath */
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85), 0 14px 26px rgba(18, 30, 12, 0.35);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;
}
.map-card canvas {
  width: 100%;
  border: 2.5px solid var(--ink);
  border-radius: 8px;
  display: block;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.map-card:hover:not(.locked) {
  transform: translate(-2px, -4px) rotate(-0.8deg);
  box-shadow: 6px 8px 0 rgba(43, 26, 16, 0.85), 0 22px 38px rgba(18, 30, 12, 0.42);
}
.map-card:hover:not(.locked) canvas { transform: scale(1.03); }
.map-card:active:not(.locked) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(43, 26, 16, 0.85), 0 6px 12px rgba(18, 30, 12, 0.3);
}
.map-card.selected {
  background-color: #ffe9a8;
  transform: rotate(-1deg) scale(1.04);
  box-shadow: 0 0 0 3px var(--honey), 4px 4px 0 rgba(43, 26, 16, 0.85), 0 16px 30px rgba(18, 30, 12, 0.4);
}
.map-card.selected:hover { transform: rotate(-1deg) scale(1.05) translate(-1px, -2px); }
/* locked maps sit flat on the page — elevation is for cards you can actually pick */
.map-card.locked {
  opacity: 0.8; cursor: not-allowed; background-color: #d9d2c0;
  box-shadow: 3px 3px 0 rgba(43, 26, 16, 0.7), 0 6px 12px rgba(18, 30, 12, 0.22);
}
.mc-name { font-size: 15px; font-weight: 900; margin-top: 6px; }
.mc-tag { font-size: 11px; padding: 1px 7px; border-radius: 8px; border: 2px solid var(--ink); vertical-align: 2px; }
.mc-tag.gentle { background: #b8e08a; }
.mc-tag.tricky { background: #ffd166; }
.mc-tag.brutal { background: #ff9d8a; }
.mc-tag.cruel { background: #d0b3f0; }
.mc-tag.midnight { background: #4c4468; color: #ffe9a8; }
.mc-start {
  position: absolute; top: 8px; right: -10px; z-index: 2;
  background: var(--honey); border: 2.5px solid var(--ink); border-radius: 8px;
  padding: 2px 10px; font-size: 11px; font-weight: 900; letter-spacing: 1px;
  transform: rotate(6deg); box-shadow: 2px 2px 0 rgba(43, 26, 16, 0.85);
  animation: pulse 1.4s infinite;
}
.mc-blurb {
  font-weight: 400; margin: 3px 0; min-height: 0;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.mc-best { color: var(--wood); font-size: 12px; }

/* ---------- The Backyard Trail: campaign journey view ---------- */

#trail-wrap { margin-bottom: 18px; }
.trail-head { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.trail-title {
  color: var(--cream); font-weight: 900; letter-spacing: 1.5px; font-size: 14px;
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink);
}
.trail-stars {
  background: var(--cream); border: 2.5px solid var(--ink); border-radius: 10px;
  padding: 3px 10px; font-weight: 900; font-size: 12px;
  box-shadow: 2px 2px 0 rgba(43, 26, 16, 0.85);
}
.view-toggle { font-size: 11px; padding: 4px 10px; min-height: 0; }
/* the strip scrolls inside itself on phones — the menu never pans sideways */
#trail-scroll { overflow-x: auto; width: 100%; max-width: calc(100vw - 48px); margin: 0 auto; padding: 14px 2px 6px; }
#trail { position: relative; min-width: 640px; max-width: 760px; height: 250px; margin: 0 auto; }
.trail-path { position: absolute; inset: 0; width: 100%; height: 100%; }
.trail-node {
  position: absolute; transform: translate(-50%, -50%);
  width: 108px; padding: 6px 4px 5px; border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 12px;
}
.trail-node:hover:not(:disabled):not(.locked) { transform: translate(-50%, -50%) rotate(-1deg) scale(1.05); }
.trail-node:active:not(:disabled):not(.locked) { transform: translate(-50%, -50%) scale(0.97); }
.trail-node.selected {
  background-color: #ffe9a8; z-index: 2;
  transform: translate(-50%, -50%) rotate(-2deg) scale(1.08);
  box-shadow: 0 0 0 3px var(--honey), 4px 4px 0 rgba(43, 26, 16, 0.85), 0 14px 24px rgba(18, 30, 12, 0.38);
}
.trail-node.selected:hover { transform: translate(-50%, -50%) rotate(-2deg) scale(1.08); }
.trail-node.locked { background-color: #d9d2c0; cursor: not-allowed; opacity: 0.9; }
.trail-node.locked:hover { transform: translate(-50%, -50%); }
.tn-emblem { width: 52px; height: 52px; border-radius: 50%; border: 2.5px solid var(--ink); display: block; }
.tn-medal { position: absolute; top: -9px; right: -7px; font-size: 18px; filter: drop-shadow(1px 1px 0 rgba(43, 26, 16, 0.6)); }
.tn-lock { position: absolute; top: 22px; font-size: 17px; }
.tn-stars { font-size: 11px; letter-spacing: 1px; }
.tn-name { font-weight: 900; font-size: 12px; line-height: 1.05; text-align: center; }
.tn-best { font-size: 11px; color: var(--wood); font-weight: 700; text-align: center; line-height: 1.15; }
/* Golden Anthill (⭐12): the whole trail wears gold trim */
.trail-node.gold:not(.locked) { box-shadow: 0 0 0 2.5px var(--honey), 3px 3px 0 rgba(43, 26, 16, 0.85); }
.trail-node.gold:not(.locked) .tn-emblem { border-color: var(--honey); }

/* ---------- Star Rewards: the track under the trail ---------- */

#star-rewards { margin-top: 12px; }
.sr-title {
  color: var(--cream); font-weight: 900; letter-spacing: 1.5px; font-size: 12px; margin-bottom: 6px;
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink);
}
.sr-chips { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.sr-chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px;
  border-radius: 10px; font-size: 11px; font-weight: 800; cursor: default;
}
.sr-chip.locked { opacity: 0.72; background: #d9d2c0; }
.sr-chip.got { background: #ffe9a8; }
.sr-chip.next { box-shadow: 0 0 0 3px var(--honey), 2px 2px 0 rgba(43, 26, 16, 0.85); animation: pulse 1.4s infinite; }
.sr-at { font-size: 11px; color: var(--wood); font-weight: 900; }

/* Backyard Legend (⭐18): the logo goes gold */
.logo.legend { color: var(--honey); }
.logo.legend .logo-td { color: var(--cream); text-shadow: 0 0 14px rgba(245, 166, 35, 0.85); }

#diff-row { display: flex; gap: 12px; justify-content: center; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.diff-label {
  color: var(--cream); font-weight: 900; letter-spacing: 1.5px; font-size: 13px;
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink);
}
.diff-btn { padding: 8px 26px; font-size: 16px; }
.diff-btn.selected { background-color: #ffe9a8; transform: rotate(-1.5deg) scale(1.08); }
/* the pick tells you what you signed up for: gentle green, honey, or trouble */
.diff-btn.selected.easy { background-color: #cdeaa8; }
.diff-btn.selected.medium { background-color: #ffe9a8; }
.diff-btn.selected.hard { background-color: #ffbfa8; box-shadow: 0 0 0 2.5px var(--red), 4px 4px 0 rgba(43, 26, 16, 0.85); }

/* the commitment dock: map + difficulty + go, pinned while the page scrolls.
   Its shade is an oversized soft pool (::before overhangs the column and fades to
   zero before its own edges) — any background on the box itself prints hard seams
   over the living meadow. #screen-menu clips X so the overhang can't cause h-scroll. */
#cta-dock {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap;
  padding: 14px 8px 10px; margin-top: 6px;
}
#cta-dock::before {
  content: ''; position: absolute; z-index: -1; pointer-events: none;
  inset: -36px -180px 0;
  background: radial-gradient(55% 64% at 50% 58%,
    rgba(28, 48, 22, 0.9) 0%, rgba(28, 48, 22, 0.48) 52%, rgba(28, 48, 22, 0) 78%);
}
#screen-menu { overflow-x: hidden; }
.menu-settings { position: absolute; top: 16px; right: 16px; font-size: 18px; padding: 8px 12px; z-index: 6; }

.big-btn { padding: 14px 34px; font-size: 20px; font-weight: 900; background: var(--honey); }

#hero-row { display: flex; gap: 12px; justify-content: center; align-items: center; margin-bottom: 20px; flex-wrap: wrap; }
.hero-row-title { width: 100%; color: var(--cream); font-weight: 900; font-size: 13px; letter-spacing: 1.5px;
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); }
.hero-card { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 8px; font-size: 13px; text-align: left; }
.hero-card.selected { background-color: #ffe9a8; transform: rotate(-1deg) scale(1.06); }
.hero-card canvas { width: 40px; height: 40px; }
.hc-name { font-weight: 900; }
.hc-ab { font-size: 11px; color: var(--wood); }

.shop-card.hero-deploy { width: 100%; margin-bottom: 8px; background: #ffe9a8; flex-direction: row; gap: 10px; padding: 8px; text-align: left; }
.shop-card.hero-deploy .sc-cost.hero-free { color: var(--leaf-dark); font-weight: 900; }

.hud-btn.ability { background: #d0b3f0; font-weight: 900; }
.hud-btn.ability:disabled { background: #cfc7bd; }
.hud-btn.power { background: #cdeaf7; font-weight: 900; }
.hud-btn.power:disabled { background: #cfc7bd; }
.hud-btn.power.casting { background: #ffe14d; transform: scale(1.06); }
.hud-btn.power.decoy { background: #f2f6fb; }
.rival-line { font-weight: 800; }
.rival-note { margin-top: 10px; font-size: 11px; color: var(--wood); font-weight: 400; }
.hero-lvl { font-size: 13px; background: var(--honey); border: 2px solid var(--ink); border-radius: 8px; padding: 1px 8px; vertical-align: 3px; }
.hero-xp { height: 10px; border: 2px solid var(--ink); border-radius: 6px; background: #e8dfca; overflow: hidden; margin: 6px 0 2px; }
.hero-xp-fill { height: 100%; background: linear-gradient(90deg, var(--honey), #ffd166); width: 0%; transition: width 0.3s ease-out; }
.menu-foot { margin-top: 18px; color: var(--cream); font-size: 13px; font-weight: 700;
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink); }

/* ---------- game screen ---------- */

#screen-game { flex-direction: column; align-items: center; gap: 10px; padding: 10px; }

#hud {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--wood);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85);
  padding: 8px 14px;
  width: min(1240px, calc(100vw - 20px));
}
.hud-chip {
  background: var(--cream);
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  padding: 4px 12px;
  font-size: 17px;
  font-weight: 900;
  white-space: nowrap;
}
.hud-chip.sugar b { color: var(--amber); }
.hud-chip.crumbs b { color: var(--red); }
.hud-btn { padding: 6px 14px; font-size: 16px; }
.hud-btn.primary { background: var(--leaf-dark); color: var(--cream); text-shadow: 1px 1px 0 var(--ink); font-weight: 900; }
.hud-btn.primary:disabled { background: #9a9a8a; }
.hud-btn.pulse { animation: pulse 1.1s infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06) rotate(-1deg); }
}
.hud-auto { color: var(--cream); font-weight: 700; font-size: 14px; display: flex; align-items: center; gap: 4px; }
.hud-spacer { flex: 1; }

#main-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: min(1240px, calc(100vw - 20px));
}

#playfield { flex: 1; min-width: 0; position: relative; }
#game-canvas {
  width: 100%;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  border: 4px solid var(--ink);
  border-radius: 12px;
  box-shadow: 6px 6px 0 rgba(43, 26, 16, 0.85);
  background: #f8efd4;
  cursor: crosshair;
}

#sidebar {
  width: 268px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}

.shop-title {
  font-weight: 900;
  color: var(--cream);
  text-shadow: 1px 1px 0 var(--ink), -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink);
  letter-spacing: 1px;
  margin-bottom: 6px;
  text-align: center;
}
.shop-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.shop-card {
  padding: 6px 4px;
  text-align: center;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.shop-card canvas { width: 44px; height: 44px; }
.shop-card .sc-name { font-weight: 900; line-height: 1.1; }
.shop-card .sc-cost { color: var(--amber); }
.shop-card.poor { opacity: 0.55; filter: grayscale(0.6); }

.panel-card { padding: 12px; font-size: 13px; }
.pc-title { font-size: 17px; font-weight: 900; margin-bottom: 6px; }
.pc-desc { margin-bottom: 6px; }
.pc-hint { color: var(--wood); font-size: 12px; }
.pc-row { display: flex; gap: 8px; margin-bottom: 10px; }
.mini-btn { padding: 8px 12px; font-size: 13px; border-radius: 9px; min-height: 36px; }
.mini-btn.sell { background: #ffd9c2; }

.pc-stats { margin-bottom: 10px; display: flex; flex-direction: column; gap: 3px; }
.stat-row.mini { font-size: 11px; gap: 6px; display: flex; align-items: center; }
.stat-row.mini .stat-name { width: 52px; font-weight: 700; }
.stat-row.mini .stat-bar { flex: 1; height: 9px; border-width: 1.5px; }
.stat-row.mini .stat-val { width: 52px; text-align: right; color: var(--wood); font-weight: 700; font-size: 10px; }
.pc-record { font-size: 11px; color: var(--wood); font-weight: 700; margin-top: 3px; }
.sc-type { font-size: 10px; color: var(--wood); }

.pc-paths { display: flex; gap: 8px; }
.pc-path { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.pc-path-name { font-weight: 900; text-align: center; font-size: 12px; letter-spacing: 0.5px; padding: 2px; border-radius: 6px; border: 2px solid var(--ink); }
.pc-path-name.a { background: #ffe9a8; }
.pc-path-name.b { background: #cdeaf7; }

.pc-tier {
  border: 2.5px solid var(--ink);
  border-radius: 10px;
  background: var(--cream);
  padding: 5px 6px;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.pc-tier .tier-name { font-weight: 900; font-size: 12px; }
.pc-tier .tier-info { color: var(--amber); font-weight: 700; }
.pc-tier .tier-desc { color: #6b5b49; }
.pc-tier .tier-delta { color: var(--leaf-dark); font-weight: 800; font-size: 10px; }
.pc-tier.owned { background: #d3edb7; }
.pc-tier.owned .tier-info { color: var(--leaf-dark); }
.pc-tier.locked { background: #ddd6c4; opacity: 0.75; cursor: not-allowed; }
.pc-tier.buyable:hover { background: #ffe9a8; transform: translate(-1px, -1px); }
.pc-tier.buyable.poor { opacity: 0.6; }
.pc-tier:focus-visible { outline: 3px solid var(--sky); }

.resume-btn { display: block; margin: 0 auto 12px; background: #b8e08a; }
.forage-btn { background: #b8e08a; margin-left: 12px; }
.daily-btn { background: #cdeaf7; margin-left: 12px; }

/* ---------- loadout: hero + challenges behind one collapsible sticker ---------- */
#loadout { margin-bottom: 20px; }
.loadout-toggle { padding: 10px 22px; font-size: 15px; font-weight: 900; background: #ffe9a8; }
.loadout-body { display: none; margin-top: 14px; }
.loadout-body.open { display: block; }
.mc-tag.soaked { background: #a9dcec; }

.draft-row { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }
.draft-card { width: 128px; padding: 12px 8px; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; text-align: center; background-color: #fff9e8; }
.draft-card:hover { background-color: #ffe9a8; }
.dc-ico { font-size: 28px; }
.draft-card small { color: var(--wood); font-weight: 400; }

.perk-dots { color: var(--honey); letter-spacing: 2px; }
.set-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; font-weight: 700; }
.set-row span { width: 128px; text-align: left; line-height: 1.15; }
.set-row input[type="range"] { flex: 1; accent-color: var(--honey); height: 22px; }

#coach, #coach-camo, #coach-decoy {
  position: fixed; z-index: 90; max-width: 240px; padding: 10px 14px;
  background: #ffe9a8; font-size: 13px; font-weight: 700; text-align: center;
  animation: pulse 1.4s infinite;
}
/* first-run tutorial spotlight: one glowing hole, everything else dimmed.
   pointer-events:none so it never blocks the very click it's pointing at. */
#coach-spot {
  position: fixed; z-index: 89; pointer-events: none;
  border-radius: 16px; border: 3px solid #ffd166;
  box-shadow: 0 0 0 9999px rgba(20, 12, 6, 0.55), 0 0 18px 4px rgba(255, 209, 102, 0.7);
  transition: left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease;
}
@media (prefers-reduced-motion: reduce) { #coach-spot { transition: none; } }
/* guided tutorial: off-script controls are locked out so only the lit step works */
.coach-locked { pointer-events: none; opacity: 0.35; filter: grayscale(0.65); }
/* tiny build stamp — confirms the loaded version (helps catch stale phone caches) */
#build-tag { position: fixed; left: 4px; bottom: 3px; z-index: 100; pointer-events: none;
  font: 700 9px/1 monospace; color: rgba(255,255,255,0.5); text-shadow: 0 1px 1px rgba(0,0,0,0.5); }
#diag-panel { position: fixed; right: 6px; top: 6px; z-index: 100; pointer-events: none;
  font: 700 11px/1.35 monospace; white-space: pre; color: #7CFC00; background: rgba(0,0,0,0.72);
  padding: 6px 8px; border-radius: 6px; }
.sc-air { font-size: 9px; color: var(--wood); font-weight: 700; }
.sc-air.no-air { color: var(--red); }
.pc-ground { color: var(--red); font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.hc-blurb { font-size: 10.5px; font-weight: 400; color: var(--ink); max-width: 210px; }
.hc-ab { max-width: 210px; }
.mod-chip { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.mod-desc { font-size: 10px; font-weight: 400; color: var(--wood); max-width: 170px; }
.mini-btn.ascend { background: #ffd166; font-weight: 900; display: block; margin-bottom: 8px; }
.shop-card.locked-type { opacity: 0.5; filter: grayscale(0.8); }
.resume-btn.hidden { display: none; }

.wave-preview { border: 2.5px solid var(--ink); border-radius: 10px; padding: 8px; margin: 8px 0; background: #fff9e8; }
.wave-preview.danger { background: #ffe4d6; }
.wp-title { font-weight: 900; font-size: 12px; letter-spacing: 0.5px; margin-bottom: 6px; }
.wp-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.wave-chip { display: inline-flex; align-items: center; gap: 4px; border: 2px solid var(--ink); border-radius: 8px; padding: 2px 7px; font-size: 11px; font-weight: 700; background: var(--cream); }
.wave-chip.boss { background: #ffb020; }
/* Scout's Eye (⭐9): the round after next, dimmed under the main preview */
.wp-title.wp-after { margin: 8px 0 4px; opacity: 0.8; border-top: 2px dashed rgba(43, 26, 16, 0.25); padding-top: 6px; }
.wp-after-chips { opacity: 0.8; }
.wave-chip i { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink); display: inline-block; }
/* camo-blindness callout: the preview tells you BEFORE the round that you can't see it */
.wave-warn { margin-top: 6px; border: 2.5px solid var(--ink); border-radius: 8px; padding: 6px 8px; font-size: 11.5px; font-weight: 800; background: #3c3549; color: #ffe9a8; animation: warnPulse 1.6s ease-in-out infinite; }
.wave-warn-hint { display: block; font-weight: 700; opacity: 0.85; font-size: 10.5px; margin-top: 2px; }
@keyframes warnPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(226, 71, 47, 0); } 50% { box-shadow: 0 0 0 3px rgba(226, 71, 47, 0.45); } }
.set-toggle { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.set-toggle input { width: 20px; height: 20px; accent-color: var(--honey); }
.set-note { font-size: 11px; opacity: 0.75; margin: 2px 0 0; }
.save-code { width: 100%; min-height: 90px; font: 11px/1.4 monospace; border: 2px solid var(--ink); border-radius: 8px; padding: 8px; background: var(--cream); word-break: break-all; resize: vertical; }

#mod-row { display: flex; gap: 8px; justify-content: center; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.mod-chip { padding: 5px 12px; font-size: 12px; border-radius: 10px; background: #e8dfca; }
.mod-chip.selected { background: #ff9d8a; transform: rotate(-1deg) scale(1.06); }

.stat-list { text-align: left; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.stat-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.stat-name { width: 118px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-bar { flex: 1; height: 12px; border: 2px solid var(--ink); border-radius: 6px; background: #e8dfca; overflow: hidden; }
.stat-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--honey), #ffd166); }
.stat-val { width: 86px; text-align: right; color: var(--wood); font-weight: 700; white-space: nowrap; }

#toasts { position: fixed; top: 14px; right: 14px; z-index: 120; display: flex; flex-direction: column; gap: 10px; }
/* species intro card: one-time "new bug" sticker, top-right over the field */
.bug-card {
  position: fixed; top: 64px; right: 12px; z-index: 92;
  max-width: 250px; padding: 10px 14px; background: #fff3d6; text-align: left;
  animation: toast-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.bug-card.gone { opacity: 0; transform: translateX(30px); transition: all 0.35s ease-in; }
.bug-card .bc-head { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 900; letter-spacing: 0.4px; }
.bug-card .bc-dot { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--ink); flex: none; display: inline-block; }
.bug-card .bc-desc { font-size: 12px; color: var(--wood); margin-top: 4px; }
.bug-card .bc-hint { font-size: 12px; font-weight: 800; margin-top: 5px; }

.ach-toast { padding: 10px 16px; background: #ffe9a8; max-width: 280px; animation: toast-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.ach-toast.gone { opacity: 0; transform: translateX(30px); transition: all 0.35s ease-in; }
.at-title { font-weight: 900; font-size: 15px; }
.at-desc { font-size: 12px; color: var(--wood); }
@keyframes toast-in { from { opacity: 0; transform: translateX(60px) scale(0.8); } to { opacity: 1; transform: none; } }

.ach-btn { margin-left: 12px; vertical-align: 6px; }
.ach-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: left; max-height: 320px; overflow-y: auto; margin-top: 8px; }
.ach-item { display: flex; gap: 8px; align-items: center; border: 2px solid var(--ink); border-radius: 10px; padding: 6px 8px; font-size: 12px; background: #fff9e8; }
.ach-item.locked { opacity: 0.55; background: #e6dfd0; }
.ach-ico { font-size: 20px; }

.coin-fly {
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, #f5a623 60%, #b46e00);
  border: 2px solid var(--ink);
  z-index: 6;
  pointer-events: none;
}

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

#modal {
  position: fixed;
  inset: 0;
  background: rgba(43, 26, 16, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  overscroll-behavior: contain;
}
#modal-card {
  max-width: 440px;
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px 30px;
  text-align: center;
  font-size: 15px;
  cursor: default;
}
.modal-title { font-size: 30px; font-weight: 900; margin-bottom: 10px; letter-spacing: -0.5px; }
.modal-title.win { color: var(--leaf-dark); }
.modal-title.lose { color: var(--red); }
.modal-stats { margin-top: 8px; color: var(--wood); }
.modal-btns { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.modal-btns .big-btn { font-size: 16px; padding: 10px 18px; }

.howto { text-align: left; max-width: 420px; margin: 0 auto; }
.howto p { font-size: 15px; line-height: 1.5; margin: 10px 0; font-weight: 600; }
.howto b { color: var(--amber); }
.howto-tip {
  background: #fff3cf; border: 2.5px dashed var(--honey); border-radius: 10px;
  padding: 10px 12px; margin-top: 14px !important; font-weight: 700;
}

/* ---------- the big-team finish: foil, paper, choreography ---------- */

/* foil section headers: the logo's gold, scaled down to label size — small type
   drops the bronze stops (they mud out below ~20px) and thins the stroke.
   Clipped elements stay leaf nodes — no transformed children (Chromium ghost-glyph trap). */
.trail-title, .sr-title, .diff-label, .hero-row-title, .shop-title {
  background: linear-gradient(180deg, #fff1bd 0%, #ffcf5a 52%, #f2a41b 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  -webkit-text-stroke: 0.75px var(--ink);
  paint-order: stroke fill;
  text-shadow: none;
  filter: drop-shadow(1.5px 2px 0 rgba(43, 26, 16, 0.82));
}
/* gold leaf needs a little size to sparkle — labels step up a notch */
.trail-title { font-size: 15px; }
.diff-label { font-size: 15px; }
.sr-title { font-size: 14px; }
.hero-row-title { font-size: 14px; }

/* paper tooth on the big sticker surfaces (variants above use background-color,
   so the texture survives selection/hover states) */
.map-card, .trail-node, .hero-card, .draft-card, #modal-card, .panel-card,
.shop-card, .ach-toast, .bug-card, #coach, #coach-camo, #coach-decoy {
  background-image: var(--tex-paper);
  background-size: 9px 9px, 13px 13px, 100% 100%;
  background-position: 0 0, 4px 6px, 0 0;
}

/* trail nodes sit off the page like the cards do */
.trail-node { box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85), 0 10px 20px rgba(18, 30, 12, 0.32); }
/* the scout ant that walks the trail to your selection */
.trail-walker {
  position: absolute; pointer-events: none; z-index: 3;
  transform: translate(-50%, -50%);
  filter: drop-shadow(1px 2px 1.5px rgba(43, 26, 16, 0.45));
}

/* ---------- Levels & Modes entrance: one choreographed arrival ----------
   .enter lives on #screen-menu only for the choreography window (JS removes it),
   so re-renders mid-stay never replay the stagger. Keyframes end at the element's
   natural pose ('to' omits transform) so selected-card transforms land seamlessly. */
#screen-menu.enter .logo { animation: logo-drop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }
#screen-menu.enter #trail-wrap { animation: title-rise 0.42s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.05s both; }
#screen-menu.enter .map-card { animation: card-in 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }
/* trail nodes self-center with translate(-50%,-50%): their entrance keeps it */
#screen-menu.enter .trail-node { animation: node-in 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }
#screen-menu.enter .map-card:nth-child(1), #screen-menu.enter .trail-node:nth-child(2) { animation-delay: 0.08s; }
#screen-menu.enter .map-card:nth-child(2), #screen-menu.enter .trail-node:nth-child(3) { animation-delay: 0.12s; }
#screen-menu.enter .map-card:nth-child(3), #screen-menu.enter .trail-node:nth-child(4) { animation-delay: 0.16s; }
#screen-menu.enter .map-card:nth-child(4), #screen-menu.enter .trail-node:nth-child(5) { animation-delay: 0.20s; }
#screen-menu.enter .map-card:nth-child(5), #screen-menu.enter .trail-node:nth-child(6) { animation-delay: 0.24s; }
#screen-menu.enter .map-card:nth-child(6), #screen-menu.enter .trail-node:nth-child(7) { animation-delay: 0.28s; }
#screen-menu.enter #diff-row { animation: title-rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.30s both; }
#screen-menu.enter #loadout { animation: title-rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.34s both; }
#screen-menu.enter #cta-dock { animation: dock-rise 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.38s both; }
#screen-menu.enter #star-rewards { animation: title-rise 0.42s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.44s both; }
#screen-menu.enter .menu-foot { animation: title-rise 0.42s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.48s both; }
#screen-menu.enter .menu-back, #screen-menu.enter .menu-settings {
  animation: title-rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.42s both;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(22px) scale(0.92); }
  to { opacity: 1; }
}
@keyframes node-in {
  from { opacity: 0; transform: translate(-50%, -50%) translateY(22px) scale(0.92); }
  to { opacity: 1; }
}
@keyframes dock-rise {
  from { opacity: 0; transform: translateY(28px); }
  to { opacity: 1; }
}

/* ---------- in-game chrome: the HUD is furniture, the shop is a card tray ---------- */

/* the HUD bar reads as actual wood: grain, a lit top edge, weight underneath */
#hud {
  background:
    linear-gradient(rgba(255, 235, 200, 0.08), rgba(43, 26, 16, 0.14)),
    repeating-linear-gradient(94deg,
      rgba(43, 26, 16, 0.09) 0 2px, transparent 2px 11px,
      rgba(255, 230, 190, 0.05) 11px 13px, transparent 13px 26px),
    var(--wood);
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85), 0 10px 24px rgba(20, 12, 4, 0.32),
    inset 0 1.5px 0 rgba(255, 240, 210, 0.25);
}
/* chips get a pressed-tin bevel */
.hud-chip {
  box-shadow: inset 0 1.5px 0 rgba(255, 255, 255, 0.7), inset 0 -2px 0 rgba(43, 26, 16, 0.08),
    2px 2px 0 rgba(43, 26, 16, 0.5);
}

/* shop cards sit in a tray; the armed one lifts and wears the honey ring */
.shop-card {
  box-shadow: 3px 3px 0 rgba(43, 26, 16, 0.85), 0 8px 16px rgba(20, 12, 4, 0.22);
}
.shop-card canvas { transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1); }
.shop-card:hover:not(:disabled) canvas { transform: scale(1.12) rotate(-3deg); }
.shop-card.placing {
  background-color: #ffe9a8;
  transform: translate(-1px, -2px);
  box-shadow: 0 0 0 3px var(--honey), 3px 3px 0 rgba(43, 26, 16, 0.85), 0 10px 20px rgba(20, 12, 4, 0.3);
}
.shop-card.placing:hover { transform: translate(-1px, -2px); }

/* tower panel: owned tiers read stamped-in, buyable tiers sit proud */
.panel-card { box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85), 0 10px 22px rgba(20, 12, 4, 0.25); }
.pc-tier { box-shadow: 2px 2px 0 rgba(43, 26, 16, 0.55); transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease; }
.pc-tier.owned { box-shadow: inset 0 2px 3px rgba(43, 26, 16, 0.18), inset 0 0 0 1.5px rgba(63, 122, 34, 0.3); }
.pc-tier.buyable:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 rgba(43, 26, 16, 0.7); }

/* stepping onto the board: HUD settles, field breathes in, the tray deals */
#screen-game.enter #hud { animation: title-rise 0.38s cubic-bezier(0.2, 0.7, 0.2, 1.15) both; }
#screen-game.enter #playfield { animation: field-in 0.45s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.06s both; }
#screen-game.enter #panel .panel-card { animation: title-rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.2s both; }
#screen-game.enter .shop-card { animation: card-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.12s both; }
#screen-game.enter .shop-grid .shop-card:nth-child(2) { animation-delay: 0.15s; }
#screen-game.enter .shop-grid .shop-card:nth-child(3) { animation-delay: 0.18s; }
#screen-game.enter .shop-grid .shop-card:nth-child(4) { animation-delay: 0.21s; }
#screen-game.enter .shop-grid .shop-card:nth-child(5) { animation-delay: 0.24s; }
#screen-game.enter .shop-grid .shop-card:nth-child(6) { animation-delay: 0.27s; }
#screen-game.enter .shop-grid .shop-card:nth-child(7) { animation-delay: 0.30s; }
#screen-game.enter .shop-grid .shop-card:nth-child(8) { animation-delay: 0.33s; }
#screen-game.enter .shop-grid .shop-card:nth-child(9) { animation-delay: 0.36s; }
@keyframes field-in {
  from { opacity: 0; transform: scale(0.985) translateY(8px); }
  to { opacity: 1; }
}

/* defeat: the color drains from the field for a beat before the verdict card.
   Pure overlay — the gameplay canvas itself is untouched. */
#playfield::after {
  content: ''; position: absolute; inset: 0; border-radius: 12px;
  pointer-events: none; opacity: 0;
  background:
    radial-gradient(120% 90% at 50% 100%, rgba(226, 100, 47, 0.16), transparent 55%),
    linear-gradient(rgba(30, 18, 44, 0.12), rgba(22, 12, 34, 0.5));
  transition: opacity 0.7s ease;
}
#screen-game.defeat #playfield::after { opacity: 1; }

/* first paint blooms up from ink instead of popping into place */
body.boot #screen-title { animation: boot-bloom 0.55s ease-out both; }
@keyframes boot-bloom {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* shape carries meaning alongside color: square = armored, diamond = flyer */
.wave-chip i.shape-armored, .bc-dot.shape-armored { border-radius: 3px; }
.wave-chip i.shape-flying, .bc-dot.shape-flying { border-radius: 3px; transform: rotate(45deg) scale(0.92); }

/* the iris: an ink circle that closes on your click and opens on the new screen */
#iris { position: fixed; inset: 0; z-index: 300; display: none; pointer-events: all; }
#iris-hole { position: absolute; border-radius: 50%; box-shadow: 0 0 0 250vmax var(--ink); will-change: transform; }
.iris-ant { position: absolute; filter: drop-shadow(2px 3px 0 rgba(0, 0, 0, 0.4)); }

/* the morph: the chosen card grows into the board over an ink scrim */
#morph { position: fixed; inset: 0; z-index: 300; display: none; pointer-events: all; }
#morph-scrim { position: absolute; inset: 0; background: var(--ink); opacity: 0; }
#morph-card {
  position: absolute;
  border: 3px solid var(--ink); border-radius: 10px;
  box-shadow: 6px 6px 0 rgba(43, 26, 16, 0.85), 0 22px 50px rgba(0, 0, 0, 0.5);
}

/* ---------- modal cinema ----------
   Every dialog arrives the same way (Playful, ~380ms). Win and lose are the two
   big moments: a golden celebration and a dusk-ember mood. The clipped win title
   is a leaf node under the animated card — the safe side of the ghost-glyph trap. */
#modal { animation: modal-dim 0.26s ease-out both; }
#modal-card {
  animation: modal-in 0.38s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
  box-shadow: 6px 6px 0 rgba(43, 26, 16, 0.85), 0 26px 60px rgba(16, 9, 4, 0.5);
}
@keyframes modal-dim { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(30px) scale(0.9) rotate(-1deg); }
  to { opacity: 1; }
}
#modal-fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
/* the victory lap marches the bottom of the screen, behind the card */
.win-parade { position: absolute; left: 0; right: 0; bottom: 0; height: 140px; }
.confetti { position: absolute; border: 1.5px solid rgba(43, 26, 16, 0.5); }
.ember {
  position: absolute; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ffd166, #e2472f 72%);
  box-shadow: 0 0 7px rgba(255, 150, 40, 0.8);
}

/* backdrops: golden hour for triumph, dusk for the fall */
#modal.win { background: radial-gradient(120% 90% at 50% 30%, rgba(122, 80, 12, 0.5), rgba(53, 32, 8, 0.74)); }
#modal.lose { background: radial-gradient(120% 90% at 50% 100%, rgba(84, 32, 16, 0.45), rgba(14, 8, 20, 0.82)); }
#modal.lose #modal-card { background-color: #efe2ca; }

/* STASH DEFENDED — the game's biggest foil moment. Exact logo layering: the
   WRAPPER carries filter + entrance (it may transform), the leaf span carries
   the clip and animates only background-position. Mixing them corrupts paint. */
#modal.win #modal-card .modal-title {
  font-size: 34px;
  filter: drop-shadow(2px 3px 0 var(--ink)) drop-shadow(0 8px 16px rgba(120, 60, 10, 0.4));
}
.foil-t {
  background: var(--foil);
  background-size: 100% 240%;
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1.6px var(--ink);
  animation: logo-sheen 5s ease-in-out 1.1s infinite;
}
/* THE SUGAR IS GONE — ember-lit, breathing slow */
#modal.lose #modal-card .modal-title {
  text-shadow: 0 0 14px rgba(255, 110, 40, 0.4), 1px 2px 0 rgba(43, 26, 16, 0.55);
  animation: title-rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1.15) 0.1s both, ember-breathe 2.8s ease-in-out infinite;
}
@keyframes ember-breathe {
  0%, 100% { text-shadow: 0 0 10px rgba(255, 110, 40, 0.3), 1px 2px 0 rgba(43, 26, 16, 0.55); }
  50% { text-shadow: 0 0 24px rgba(255, 140, 60, 0.65), 1px 2px 0 rgba(43, 26, 16, 0.55); }
}

/* the run's verdict: grade stamps down beside the score */
.score-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }
.score-text small { color: var(--wood); font-weight: 700; }
.grade-stamp {
  display: inline-block; min-width: 52px; padding: 6px 10px;
  font-size: 30px; font-weight: 900; line-height: 1;
  color: var(--amber);
  background-color: #ffe9a8;
  background-image: var(--tex-paper);
  background-size: 9px 9px, 13px 13px, 100% 100%;
  border: 3px solid var(--ink); border-radius: 12px;
  transform: rotate(-7deg);
  box-shadow: 3px 3px 0 rgba(43, 26, 16, 0.85);
}
#modal.lose .grade-stamp { background-color: #ddd2c2; color: #6b5b49; }
#modal.win .grade-stamp, #modal.lose .grade-stamp {
  animation: stamp-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.5s both;
}
@keyframes stamp-in {
  from { opacity: 0; transform: rotate(6deg) scale(2.4); }
  55% { opacity: 1; }
  to { opacity: 1; }
}
.new-best {
  display: inline-block; margin-left: 6px; padding: 1px 8px;
  background: var(--honey); border: 2px solid var(--ink); border-radius: 8px;
  font-size: 12px; font-weight: 900; animation: pulse 1.4s infinite;
}

/* every other dialog wears label-gold too — the win title keeps the sheen crown,
   the lose title keeps its ember red, so those two exclude themselves here */
.modal-title:not(.win):not(.lose) {
  background: linear-gradient(180deg, #fff1bd 0%, #ffcf5a 52%, #f2a41b 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  -webkit-text-stroke: 1.2px var(--ink);
  paint-order: stroke fill;
  filter: drop-shadow(1.5px 2px 0 rgba(43, 26, 16, 0.85));
}

/* toasts, species cards and coach bubbles sit off the page like the cards do */
.ach-toast, .bug-card, #coach, #coach-camo, #coach-decoy {
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.85), 0 12px 26px rgba(20, 12, 4, 0.35);
}
/* coach bubbles pop in once, then keep their attention pulse */
#coach, #coach-camo, #coach-decoy {
  animation: coach-pop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275) both, pulse 1.4s 0.35s infinite;
}
@keyframes coach-pop {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; }
}
/* the forage draft deals its three options like cards off a deck */
.draft-card { animation: card-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) both; }
.draft-card:nth-child(2) { animation-delay: 0.07s; }
.draft-card:nth-child(3) { animation-delay: 0.14s; }

/* the end cards deal their lines one at a time */
#modal.win #modal-card > *, #modal.lose #modal-card > * {
  animation: title-rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1.15) both;
}
#modal.win #modal-card > :nth-child(1), #modal.lose #modal-card > :nth-child(1) { animation-delay: 0.10s; }
#modal.win #modal-card > :nth-child(2), #modal.lose #modal-card > :nth-child(2) { animation-delay: 0.18s; }
#modal.win #modal-card > :nth-child(3), #modal.lose #modal-card > :nth-child(3) { animation-delay: 0.24s; }
#modal.win #modal-card > :nth-child(4), #modal.lose #modal-card > :nth-child(4) { animation-delay: 0.30s; }
#modal.win #modal-card > :nth-child(5), #modal.lose #modal-card > :nth-child(5) { animation-delay: 0.36s; }
#modal.win #modal-card > :nth-child(6), #modal.lose #modal-card > :nth-child(6) { animation-delay: 0.42s; }

/* ---------- debug ---------- */

#debug-panel {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 99;
  background: rgba(20, 12, 6, 0.92);
  color: #9be34a;
  border: 2px solid #9be34a;
  border-radius: 8px;
  padding: 8px;
  font: 12px monospace;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.dbg-title { font-weight: bold; letter-spacing: 2px; }
.dbg-row { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
#debug-panel button, #debug-panel select, #debug-panel input {
  font: 11px monospace;
  background: #17301a;
  color: #9be34a;
  border: 1px solid #9be34a;
  border-radius: 4px;
  padding: 2px 7px;
  cursor: pointer;
}
#debug-panel button.on { background: #9be34a; color: #17301a; }
#debug-panel input[type="number"] { width: 54px; }
#dbg-fps { margin-left: auto; color: #ffd166; }

/* ---------- small screens ---------- */

@media (max-width: 980px) {
  #main-row { flex-direction: column; }
  #sidebar { width: 100%; max-height: none; }
  .shop-grid { grid-template-columns: repeat(4, 1fr); }
  .pc-paths { max-width: 560px; }
}

/* content taller than the viewport must scroll from the TOP (centered flex
   clips its own head unreachably), so small screens start-align and scroll */
@media (max-width: 700px), (max-height: 560px) {
  .screen { align-items: flex-start; justify-content: flex-start; }
  .menu-inner { margin: 0 auto; }
  #screen-game { align-items: center; justify-content: flex-start; }
}

/* phone portrait: slim wrap-friendly HUD bar, full-width canvas,
   shop as a horizontal scroll strip below */
@media (max-width: 700px) {
  #cta-dock::before { inset: -24px -48px 0; } /* narrow screens need less pool spread */
  #screen-game { padding: 6px; gap: 6px; }
  #hud { flex-wrap: wrap; gap: 5px; padding: 6px 8px; width: 100%; }
  .hud-chip { font-size: 13px; padding: 3px 8px; }
  /* fingers, not cursors: every HUD button ≥ 44px tall */
  .hud-btn { padding: 5px 10px; font-size: 13px; min-height: 44px; }
  .hud-auto { font-size: 12px; min-height: 44px; }
  #main-row { width: 100%; gap: 6px; }
  #sidebar { overflow: visible; }
  .shop-grid { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 6px; }
  .shop-card { min-width: 88px; flex-shrink: 0; }
}

/* phone landscape: keep canvas+sidebar side by side, compact chrome, page scrolls */
@media (max-height: 560px) and (min-width: 701px) {
  #screen-game { padding: 6px; gap: 6px; }
  #hud { flex-wrap: wrap; gap: 5px; padding: 4px 8px; width: 100%; }
  .hud-chip { font-size: 12px; padding: 2px 7px; }
  .hud-btn { padding: 4px 8px; font-size: 12px; min-height: 44px; }
  .hud-auto { min-height: 44px; }
  #main-row { flex-direction: row; width: 100%; }
  #playfield { max-width: calc((100vh - 72px) * 1.5); } /* 960:640 canvas fits the fold */
  #sidebar { width: 220px; flex-shrink: 0; max-height: none; }
  .shop-grid { grid-template-columns: 1fr 1fr; }
}

/* ---- mobile board camera companions ---- */
/* staged placement: ✓/✗ float beside the parked ghost (thumb-sized targets) */
#place-confirm { position: absolute; z-index: 6; display: flex; gap: 10px; }
#place-confirm.hidden { display: none; }
#place-confirm .sticker {
  min-width: 52px; min-height: 52px; border-radius: 999px;
  font-size: 24px; font-weight: 900; line-height: 1; padding: 0 12px;
  touch-action: manipulation;
  animation: chip-pop 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
#pc-yes { background: var(--leaf); color: var(--cream); }
#pc-no { background: var(--red); color: var(--cream); }
@keyframes chip-pop {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* one-time rotate hint: a friendly card at the fold, never a wall */
#rotate-hint {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  z-index: 60; display: flex; align-items: center; gap: 10px;
  max-width: min(92vw, 420px); padding: 10px 12px;
  background: var(--paper); border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: 4px 4px 0 rgba(43, 26, 16, 0.4);
  animation: chip-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
#rotate-hint .rh-icon { font-size: 26px; }
#rotate-hint .rh-text { font-size: 13px; line-height: 1.35; }
#rotate-hint .rh-btn { min-height: 44px; padding: 6px 14px; flex-shrink: 0; touch-action: manipulation; }

@media (prefers-reduced-motion: reduce) {
  .sticker, .hud-btn.pulse { transition: none; animation: none !important; }
  #place-confirm .sticker, #rotate-hint { animation: none !important; }
  /* the cinematic layer stands down as one: modal entrances/backdrop dims, foil
     sheens, grade stamps, content staggers, and both screen-arrival cascades.
     (Confetti and embers are skipped in JS; the scenes render a single frame.) */
  #modal, #modal-card, #modal-card *,
  #screen-menu.enter *, #screen-game.enter *,
  body.boot #screen-title { animation: none !important; }
  .map-card canvas, .shop-card canvas, .pc-tier, #playfield::after { transition: none; }
}
