@font-face { font-family: 'Fredoka'; src: url('assets/fonts/fredoka-500.woff2') format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Fredoka'; src: url('assets/fonts/fredoka-700.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Caveat'; src: url('assets/fonts/caveat-600.woff2') format('woff2'); font-weight: 600; font-display: swap; }

:root {
  --night: #243c30;
  --forest: #304735;
  --moss: #96ac6d;
  --moss-deep: #405e39;
  --paper: #f4e8cb;
  --paper-2: #e6d8b5;
  --paper-3: #c9b78d;
  --ink: #2f402f;
  --ink-soft: #575b45;
  --clay: #bd7047;
  --clay-deep: #934a2e;
  --gold: #e5b35c;
  --go: #527742;
  --go-deep: #243e2b;
  --go-a: #587b42;
  --go-b: #365b35;
  --shadow: 0 3px 0 rgba(0,0,0,.25), 0 12px 28px rgba(0,0,0,.3);
  /* Motion: presses spring back, panels ease out. */
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.2, .8, .2, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  /* The rail's share of the right inset: iPhones report the notch's inset on
     both sides in landscape, so it shrinks when the notch is on the left
     (data-notch, set by app.fit()); the screen's rounded corner still clears. */
  --rail-safe-r: var(--safe-r);

  /* Sizing scale: desktop / tablet defaults, compacted for phones below.
     The in-game HUD grows with the screen's height, like the HUD art. */
  --rail-w: clamp(190px, 19vw, 320px);
  --gap: clamp(10px, 2vh, 20px);
  --pill-h: clamp(42px, 7.4vh, 72px);
  --pill-font: calc(var(--pill-h) * .54);
  --hud-btn: calc(var(--pill-h) * 1.12);
  --tile-icon: 54px;
  --go-h: clamp(60px, 11vh, 108px);
}
:root[data-notch="left"] { --rail-safe-r: min(var(--safe-r), 22px); }

/* ---- Woodland palette --------------------------------------------------
   Pine frames, moss-green cards and warm parchment, with autumn copper. */
:root {
  color-scheme: normal;
  --bg: #243c30;
  --text: #fff4dc;
  --text-soft: #d5d9bb;
  --text-mute: #b5bda1;
  --text-shadow: 0 2px 0 rgba(20,31,22,.4);
  --focus: #efb85c;
  --heart: #f28b70;
  --glass: rgba(33,53,41,.94);
  --glass-strong: rgba(33,53,41,.98);
  --glass-hover: #3d5742;
  --glass-line: rgba(231,196,135,.45);
  --rail-top: #1a3c28; --rail-bot: #0a2318; --rail-edge: #5c3519; --rail-glow: rgba(245,200,130,.22);
  /* In-game HUD frames (top bar, rail cards, Start): pine fill, gold ring, bark hairline, outlined white text. */
  --hud-fill: linear-gradient(180deg, #2c4828 0%, #1a3420 16%, #0d1e11 36%, #0b1b0f 76%, #1b3822 90%, #13291a 100%);
  --hud-ring: linear-gradient(180deg, #ffe596 0%, #e3a54b 42%, #a0621f 78%, #6e3f12 100%);
  --hud-bark: #24160a;
  --go-ink: 0 2px 0 #0b3a15, 0 -1px 0 #0b3a15, 1px 0 0 #0b3a15, -1px 0 0 #0b3a15, 1px 1px 0 #0b3a15, -1px 1px 0 #0b3a15, 0 3px 4px rgba(0,0,0,.35);
  --hud-ink: 0 2px 0 #0c1a0e, 0 -1px 0 #0c1a0e, 1px 0 0 #0c1a0e, -1px 0 0 #0c1a0e, 1px 1px 0 #0c1a0e, -1px 1px 0 #0c1a0e, 0 3px 4px rgba(0,0,0,.4);
  --well: rgba(16,30,22,.3); --well-line: rgba(222,203,155,.15);
  --ghost: rgba(245,224,180,.09); --ghost-hover: rgba(245,224,180,.17); --ghost-line: rgba(231,196,135,.28); --ghost-drop: rgba(14,28,19,.4);
  --card-a: #4f6444; --card-b: #394f38; --card-line: #829060; --card-hover-line: #e9bd74; --card-drop: #1d3024;
  --card-text: #fff4dc; --card-soft: #d9dfc0;
  --card-on-a: #87603a; --card-on-b: #63482d;
  --card-off-a: #46503b; --card-off-b: #343e2f; --card-off-drop: #1b2b20; --card-off-text: #c5cbb4;
  --card-max-a: #486740; --card-max-b: #304c33; --card-max-drop: #1d3223; --card-max-text: #def0b5;
  --pip-off: rgba(246,231,193,.25);
  --track: rgba(19,31,22,.32);
  --seed: #efc16a;
  --btn-off: #4d5842; --btn-off-text: #c5cbb4; --btn-off-drop: #293c2c;
  --sheet: #f4e8cb; --sheet-2: #e6d8b5; --sheet-3: #c9b78d; --sheet-edge: #b18a55; --sheet-drop: #b6a077;
  --sheet-text: #2f402f; --sheet-soft: #575b45;
  --accent: #a24f2d;
  --accent-good: #3d672f;
  --good-text: #c5e6a6; --bad-text: #ffb49a; --gold-text: #f9d891;
  --tag: rgba(20,32,23,.3); --tag-text: #f0e3bf; --tag-good: rgba(150,185,108,.25); --tag-good-text: #e1efc3;
  --dim: rgba(22,35,27,.74);
  --band: 29, 47, 35;
  --menu-fade: 34, 43, 25;
  --title: #fff2d5; --title-shadow: 0 4px 0 #213124, 0 0 30px rgba(221,171,88,.25);
  --eyebrow: #edbd70;
  --best-text: #f9d891; --best-bg: rgba(239,193,106,.14); --best-line: rgba(239,193,106,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Fredoka', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
kbd {
  font: 700 10px/1 'Fredoka', sans-serif;
  padding: 2px 5px; border-radius: 5px;
  background: rgba(128,128,128,.16); border: 1px solid rgba(128,128,128,.4);
}
svg { display: block; width: 1em; height: 1em; }
[hidden] { display: none !important; }

.app {
  position: fixed; inset: 0; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1fr) calc(var(--rail-w) + var(--rail-safe-r));
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.app[data-screen="menu"] { grid-template-columns: minmax(0, 1fr); }
.app[data-screen="menu"] .rail,
.app[data-screen="menu"] .hud-top,
.app[data-screen="menu"] .ability-tray,
.app[data-screen="menu"] .place-bar,
.app[data-screen="menu"] .banner,
.app[data-screen="menu"] .toast { display: none !important; }

/* ---- Stage (map) ------------------------------------------------------ */
.stage { position: relative; min-width: 0; overflow: hidden; background: #22361b; }
#game { position: absolute; inset: 0; }
#game canvas { display: block; touch-action: none; }

.hud-top {
  position: absolute; z-index: 3; pointer-events: none;
  top: calc(var(--gap) + var(--safe-t)); left: calc(var(--gap) + var(--safe-l)); right: var(--gap);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 8px;
}
.hud-top > * { pointer-events: auto; }
.pills, .hud-right { display: flex; gap: 8px; align-items: center; }
/* In-game frames: dark pine inside a gold ring, with a hairline of bark
   around it. No backdrop blur here: blurring the live 60 fps map costs
   phones a lot of GPU time. */
.pills, .round-badge, .hud-btn {
  position: relative; height: var(--pill-h); border-radius: 999px; border: 3px solid transparent;
  background: var(--hud-fill) padding-box, var(--hud-ring) border-box;
  box-shadow: 0 0 0 1.5px var(--hud-bark), 0 3px 0 1.5px rgba(0,0,0,.32), inset 0 1px 0 rgba(255,255,255,.1);
}
/* Lives and seeds share one bar, split by a gold rule; leaves tuck in at each end. */
.pills { gap: 0; padding: 0 4px; }
.pills::before, .pills::after, .round-badge::before {
  content: ''; position: absolute; z-index: -1; pointer-events: none;
  width: calc(var(--pill-h) * .8); height: calc(var(--pill-h) * .6); top: calc(var(--pill-h) * -.3);
  background: url('assets/ui/hud-sprig.svg') center / contain no-repeat;
}
.pills::before, .round-badge::before { left: calc(var(--pill-h) * -.22); }
.pills::after { right: calc(var(--pill-h) * -.22); background-image: url('assets/ui/hud-sprig-r.svg'); }
.pill { position: relative; height: 100%; display: flex; align-items: center; gap: calc(var(--pill-h) * .18); padding: 0 calc(var(--pill-h) * .42) 0 calc(var(--pill-h) * .26); border-radius: 999px; }
.pill + .pill::before { content: ''; position: absolute; left: -1px; top: 16%; bottom: 16%; width: 2px; border-radius: 1px;
  background: linear-gradient(rgba(240,190,100,0), #e0a751 30%, #e0a751 70%, rgba(240,190,100,0)); }
.pill .ico { width: calc(var(--pill-h) * .66); height: calc(var(--pill-h) * .66); filter: drop-shadow(0 2px 0 rgba(0,0,0,.4)); }
.pill .ico svg { width: 100%; height: 100%; }
.pill b { font-size: var(--pill-font); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 2ch; color: #fff; text-shadow: var(--hud-ink); }
.pill.lives .ico path { fill: url(#hud-red); stroke: #4d0e06; stroke-width: 1.4; paint-order: stroke; }
.pill.cash .ico svg, .tile-cost svg { transform: rotate(30deg); }
.pill.cash .ico path:first-child, .tile-cost svg path:first-child, .hud-btn.powers .mi path {
  fill: url(#hud-gold); stroke: #5c3008; stroke-width: 1.4; paint-order: stroke; }
.pill.bump { animation: bump .4s var(--spring); }
.pill.cash.flash { animation: flash .5s ease; }
.pill.cash.flash b { animation: flash-text .5s ease; }
.pill.cash .ico, .pill.cash b { display: inline-block; }
.pill.cash.gain b, .pill.cash.gain .ico { animation: gain .5s var(--spring); }
@keyframes gain { 35% { transform: scale(1.22); } }
@keyframes flash-text { 30% { color: #ffd2c4; } }
@keyframes bump { 30% { transform: scale(1.1); background: rgba(200,60,40,.7); } }
@keyframes flash { 30% { background: rgba(160,44,26,.75); } }
.round-badge { display: flex; align-items: center; gap: 6px; padding: 0 16px 0 18px; }
.round-badge small, .round-badge b { font-size: calc(var(--pill-font) * .82); font-weight: 700; color: #fff; text-shadow: var(--hud-ink); white-space: nowrap; }
.round-badge b { display: inline-block; font-variant-numeric: tabular-nums; }
.round-badge.pop b { animation: badge-pop .5s var(--spring); }
@keyframes badge-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.18); } }
.hud-btn {
  width: var(--hud-btn); height: var(--hud-btn); padding: 0; cursor: pointer; color: #fff;
  background: radial-gradient(circle at 50% 28%, #33502f 0%, #183020 50%, #0b1b10 100%) padding-box, var(--hud-ring) border-box;
  display: grid; place-items: center; transition: transform .18s var(--spring), filter .15s;
}
.hud-btn::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; } /* bigger hit area for thumbs */
.hud-btn svg { width: calc(var(--hud-btn) * .5); height: calc(var(--hud-btn) * .5); filter: drop-shadow(0 2px 0 rgba(0,0,0,.35)); }
#btn-pause svg rect { fill: #fff; stroke: #0d1b0f; stroke-width: 1.5; paint-order: stroke; }
.hud-btn:active { transform: scale(.9); transition-duration: .05s; }

.ability-tray {
  position: absolute; z-index: 3;
  left: calc(var(--gap) + var(--safe-l)); bottom: calc(var(--gap) + var(--safe-b));
  display: flex; gap: 8px;
}
.ability-tray:empty, .app.placing .ability-tray { display: none; }

/* Placement hint only: releasing on a valid footprint plants immediately. */
.place-bar {
  position: absolute; z-index: 4; left: 50%; bottom: calc(var(--gap) + var(--safe-b));
  transform: translateX(-50%); width: max-content; max-width: calc(100% - 2 * var(--gap));
  display: flex; align-items: center; gap: 10px; padding: 5px 5px 5px 7px;
  border-radius: 999px; background: var(--glass-strong); border: 2px solid var(--glass-line);
  box-shadow: var(--shadow); animation: up .3s var(--spring); pointer-events: none;
}
@keyframes up { from { transform: translate(-50%, 10px); opacity: 0; } }
.pb-icon { width: 40px; height: 40px; flex: none; }
.pb-text { min-width: 0; display: grid; line-height: 1.15; padding-right: 2px; }
.pb-text b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-text small { font-size: 12.5px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place-bar.bad .pb-text small { color: var(--bad-text); }
.place-bar.good .pb-text small { color: var(--good-text); }
.pb-btn {
  width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; color: #fff;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); transition: transform .2s var(--spring);
}
.pb-btn svg { width: 22px; height: 22px; }
.pb-btn.cancel { background: #6a3a2c; }
.pb-btn.ok { background: linear-gradient(var(--go-a), var(--go-b)); }
.pb-btn.ok:disabled { background: var(--btn-off); color: var(--btn-off-text); }
.pb-btn:active:not(:disabled) { transform: scale(.88); transition-duration: .05s; }
.app:not(.touch) .pb-btn.ok { display: none; }

/* Toast: short messages under the HUD. Wraps to two lines on narrow maps. */
.toast {
  position: absolute; z-index: 6; left: 50%; top: calc(var(--gap) * 2 + var(--pill-h) + var(--safe-t));
  display: flex; align-items: center; gap: 7px; width: max-content; max-width: min(460px, calc(100% - 24px));
  transform: translate(-50%, -8px) scale(.92); opacity: 0;
  padding: 7px 16px 7px 12px; border-radius: 18px; background: var(--glass-strong); color: var(--text);
  font-weight: 700; font-size: 15px; line-height: 1.2; pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  border: 2px solid var(--glass-line); box-shadow: 0 3px 0 rgba(0,0,0,.22), 0 10px 24px rgba(0,0,0,.25);
}
.toast:empty { display: none; }
/* Clearing scenery: a bubble over a tapped tree or rock. */
.clear-tip {
  position: absolute; z-index: 7; display: grid; gap: 4px; min-width: 168px; padding: 9px 11px 10px;
  transform: translate(-50%, calc(-100% - 6px)) scale(.9); opacity: 0; pointer-events: none;
  border-radius: 16px; background: var(--glass-strong); color: var(--text); border: 2px solid var(--glass-line);
  box-shadow: 0 3px 0 rgba(0,0,0,.22), 0 10px 24px rgba(0,0,0,.28); transition: opacity .12s ease, transform .12s ease;
}
.clear-tip::after { content: ''; position: absolute; left: 50%; bottom: -8px; width: 14px; height: 14px; transform: translateX(-50%) rotate(45deg);
  background: inherit; border-right: 2px solid var(--glass-line); border-bottom: 2px solid var(--glass-line); }
.clear-tip.show { opacity: 1; pointer-events: auto; transform: translate(-50%, calc(-100% - 6px)) scale(1); transition: opacity .12s ease, transform .28s var(--spring); }
.clear-tip > b { font-size: 15px; line-height: 1.1; }
.clear-tip > small { font-size: 11.5px; opacity: .8; }
.clear-tip .ct-row { display: flex; gap: 6px; margin-top: 3px; }
.clear-tip button { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 34px; border-radius: 11px; font-weight: 800; font-size: 14px; cursor: pointer; }
.clear-tip .ct-go { flex: 1; padding: 0 12px; color: #fff; background: linear-gradient(#7cc456, #3f8a2a); border: 2px solid rgba(255,255,255,.3); box-shadow: 0 2px 0 #24521a; }
.clear-tip .ct-go.short { background: linear-gradient(#b0a090, #7a6a5a); box-shadow: 0 2px 0 #4a3e32; }
.clear-tip .ct-price { display: inline-flex; align-items: center; gap: 2px; color: #fff3c4; }
.clear-tip .ct-price svg, .clear-tip .ct-no svg { width: 15px; height: 15px; }
.clear-tip .ct-no { width: 34px; padding: 0; color: var(--text); background: rgba(0,0,0,.18); border: 2px solid var(--glass-line); }
.toast .t-ico { flex: none; width: 18px; height: 18px; }
.toast .t-ico:empty { display: none; }
.toast .t-ico svg { width: 100%; height: 100%; }
.toast .t-msg { min-width: 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); transition: opacity .12s ease, transform .32s var(--spring); }
.toast.bad { background: rgba(160,48,28,.97); color: #fff; border-color: rgba(255,255,255,.22); }
.toast.good { background: rgba(38,100,27,.97); color: #fff; border-color: rgba(255,255,255,.22); }
.toast.bad.show { animation: toast-shake .32s ease; }
@keyframes toast-shake { 25% { margin-left: -5px; } 50% { margin-left: 4px; } 75% { margin-left: -2px; } }

/* Round banner: "Round 7" sweeps across the map as a round starts or clears. */
.banner {
  position: absolute; z-index: 5; left: var(--safe-l); right: 0; top: 40%; pointer-events: none;
  display: grid; justify-items: center; gap: 3px; padding: 10px 16px 12px;
  background: linear-gradient(90deg, rgba(var(--band), 0) 0%, rgba(var(--band), .84) 22%, rgba(var(--band), .84) 78%, rgba(var(--band), 0) 100%);
  color: var(--text); text-align: center; opacity: 0; transform: translateY(-50%);
}
.banner.show { animation: banner 1.9s var(--ease-out) both; }
.banner small { font-size: 12px; font-weight: 700; letter-spacing: 3px; text-transform: uppercase; color: var(--text-soft); }
.banner b { font-size: 38px; line-height: 1; font-weight: 700; letter-spacing: .5px; text-shadow: var(--text-shadow); }
.banner.show b { animation: banner-text 1.9s var(--ease-out) both; }
.banner b i { font-style: normal; font-size: .5em; opacity: .7; }
.banner b .seeds { display: inline-flex; align-items: center; gap: 2px; margin-left: 10px; color: var(--gold-text); font-size: .7em; vertical-align: .12em; }
.banner b .seeds svg { width: .95em; height: .95em; color: var(--seed); }
.banner em { font-style: normal; display: inline-flex; align-items: center; gap: 5px; margin-top: 3px; padding: 3px 11px; border-radius: 999px;
  font-size: 13px; font-weight: 700; color: #fff; background: #b8402a; box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.banner em.boss { background: linear-gradient(#a8304f, #7c2150); }
.banner em.hidden { background: #4c467a; }
.banner em.final { background: linear-gradient(#ffd666, #e2a52c); color: #3a2a08; }
.banner em svg { width: 14px; height: 14px; }
.banner.clear b { color: var(--good-text); }
.banner.trail-title.show, .banner.trail-title.show b { animation-duration: 2.5s; }
.banner.trail-title em { background: linear-gradient(var(--go-a), var(--go-b)); }
@keyframes banner {
  0% { opacity: 0; transform: translateY(-50%) scaleY(.2); }
  10% { opacity: 1; transform: translateY(-50%) scaleY(1); }
  82% { opacity: 1; transform: translateY(-50%); }
  100% { opacity: 0; transform: translateY(calc(-50% - 14px)); }
}
@keyframes banner-text { 0%, 6% { transform: scale(.6); opacity: 0; } 18% { transform: scale(1.08); opacity: 1; } 26% { transform: scale(1); } }

/* ---- Rail: title, shop + go button ----------------------------------- */
.rail {
  --bark: clamp(6px, 1.3vh, 12px);
  position: relative; min-height: 0; z-index: 7; /* above the HUD so path details can float over the map */
  display: flex; flex-direction: column; gap: 8px;
  /* The home-bar inset already includes breathing room: don't stack 8px on top. */
  padding: calc(8px + var(--safe-t)) calc(8px + var(--rail-safe-r)) max(8px, var(--safe-b)) calc(var(--bark) + 6px);
  background: radial-gradient(130% 28% at 50% 0%, rgba(96,150,84,.2), rgba(96,150,84,0) 70%), linear-gradient(180deg, var(--rail-top) 0%, var(--rail-bot) 100%);
  box-shadow: -6px 0 18px rgba(0,0,0,.3);
}
/* The bark edge between the map and the rail. */
.rail::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: var(--bark); pointer-events: none;
  background: linear-gradient(90deg, #2b170a 0%, #8f5d33 28%, #6b3f1d 58%, var(--rail-edge) 78%, #2e1a0b 100%);
  box-shadow: 1px 0 0 var(--rail-glow);
}
/* The painted Twig & Talon logo (assets/ui/hud-title.webp, cut from the HUD mockup). */
.rail-title { flex: none; height: clamp(28px, 9vh, 80px); margin: -3px -4px -1px; background: url('assets/ui/hud-title.webp') center / contain no-repeat; }

.shop {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-content: start;
  scrollbar-width: none; padding: 4px 4px 6px;
  animation: shop-in .24s var(--ease-out); /* replays whenever the shop comes back */
}
.shop::-webkit-scrollbar { display: none; }
@keyframes shop-in { from { opacity: 0; transform: translateX(-14px); } }
/* Scroll cues: the edge fades when more is hidden that way (classes set by the HUD). */
.shop.fade-b { -webkit-mask-image: linear-gradient(#000 calc(100% - 22px), transparent); mask-image: linear-gradient(#000 calc(100% - 22px), transparent); }
.shop.fade-t { -webkit-mask-image: linear-gradient(transparent, #000 22px); mask-image: linear-gradient(transparent, #000 22px); }
.shop.fade-t.fade-b { -webkit-mask-image: linear-gradient(transparent, #000 22px, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(transparent, #000 22px, #000 calc(100% - 22px), transparent); }
/* The pages don't dissolve: the animal panel darkens its scrolled edge instead. */
.tower-panel.fade-t { --tp-ft: inset 0 20px 14px -14px rgba(3,12,7,.6); }
.tower-panel.fade-b { --tp-fb: inset 0 -20px 14px -14px rgba(3,12,7,.6); }

/* ---- Woodland pages: the animal panel and its field notes ---------------
   The selected animal's panel docks beside the roster (--tp-w is its width)
   in the rail's own materials: translucent pine under a moss glow, cards with
   the roster's moss ring, cream ink and gold accents. A bark spine
   (.tp-spiral) runs down its left edge. The i button unfolds the field notes
   (.tp-info) out of the spine: each note sits beside its button with an index
   tab pointing at it, and the two pages scroll together (TD.UpgradeUI lines
   them up). */
.rail {
  --tp-w: clamp(200px, 21vw, 270px);
  --tp-pw: min(var(--tp-w), calc(100vw - var(--rail-w) - var(--rail-safe-r) - var(--safe-l) - 44px)); /* the panel's real width */
  --nb-spine: 7px;    /* the bark spine between the pages */
  --nb-ink: #fff4dc; --nb-ink-soft: #cdd5b1; --nb-moss: #c4e07e; --nb-gold: #f3cb76;
  --nb-line: rgba(166,196,102,.45);  /* the roster cards' moss ring */
  /* Translucent pine, darker than the rail so the battle still shows through without fighting the ink. */
  --nb-page: radial-gradient(130% 18% at 50% 0%, rgba(118,170,92,.24), rgba(118,170,92,0) 70%),
    linear-gradient(180deg, rgba(27,62,41,.8) 0%, rgba(15,44,28,.76) 48%, rgba(9,33,22,.84) 100%);
  --nb-well: rgba(5,18,10,.36);
  /* Section rules: a moss line that fades out, like light through the canopy. */
  --nb-rule: linear-gradient(90deg, rgba(196,224,126,.6), rgba(196,224,126,0));
  /* A small HUD leaf ahead of each section heading. */
  --nb-leaf: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><defs><linearGradient id='l' x1='0' y1='0' x2='0' y2='1'><stop offset='0' stop-color='%23c3ea5a'/><stop offset='.55' stop-color='%2377b733'/><stop offset='1' stop-color='%233d7a20'/></linearGradient></defs><path d='M1.4 10.6C1.4 5 5 1.4 10.6 1.4 10.6 7 7 10.6 1.4 10.6Z' fill='url(%23l)' stroke='%2315300f' stroke-width='1.1' stroke-linejoin='round'/><path d='M2.4 9.6L7.6 4.4' stroke='%232c661a' stroke-width='1' stroke-linecap='round'/></svg>");
  /* A fern in the undergrowth: a faint watermark low on the field notes. */
  --nb-pressed: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 120'><g fill='%23b5d873' fill-opacity='.07' stroke='%23b5d873' stroke-opacity='.13' stroke-width='.8'><path d='M40 118C38 90 41 50 52 6' fill='none' stroke-width='1.6'/><ellipse cx='-11' cy='0' rx='12' ry='4.4' transform='translate(39.5 104) rotate(-24)'/><ellipse cx='11' cy='0' rx='12' ry='4.4' transform='translate(39.5 100) rotate(22)'/><ellipse cx='-10' cy='0' rx='11' ry='4.1' transform='translate(39.6 90) rotate(-26)'/><ellipse cx='10' cy='0' rx='11' ry='4.1' transform='translate(39.7 86) rotate(20)'/><ellipse cx='-9' cy='0' rx='10' ry='3.8' transform='translate(40 76) rotate(-28)'/><ellipse cx='9' cy='0' rx='10' ry='3.8' transform='translate(40.3 72) rotate(18)'/><ellipse cx='-8' cy='0' rx='9' ry='3.5' transform='translate(41 62) rotate(-30)'/><ellipse cx='8' cy='0' rx='9' ry='3.5' transform='translate(41.4 58) rotate(16)'/><ellipse cx='-7' cy='0' rx='7.6' ry='3.1' transform='translate(42.6 48) rotate(-32)'/><ellipse cx='7' cy='0' rx='7.6' ry='3.1' transform='translate(43.2 44) rotate(14)'/><ellipse cx='-5.6' cy='0' rx='6' ry='2.7' transform='translate(45 34) rotate(-34)'/><ellipse cx='5.6' cy='0' rx='6' ry='2.7' transform='translate(45.8 30) rotate(12)'/><ellipse cx='-4.2' cy='0' rx='4.6' ry='2.2' transform='translate(48 21) rotate(-36)'/><ellipse cx='4.2' cy='0' rx='4.6' ry='2.2' transform='translate(48.8 17) rotate(10)'/><ellipse cx='0' cy='0' rx='2.2' ry='4' transform='translate(51.6 8) rotate(14)'/></g></svg>");
}

/* On narrow screens share the available map width between the two pages;
   neither page ever turns over the upgrade controls. */
.rail.notebook-open {
  --tp-pw: min(var(--tp-w), calc((100vw - var(--rail-w) - var(--rail-safe-r) - var(--safe-l) - 12px) / 2));
}

/* Translucent pine leaves the battle visible without blurring it; the cards
   carry their own near-solid fills so the ink always reads. The palette is the
   rail's (style.css :root), with wells and cards tuned for glass. */
.tower-panel {
  position: absolute; right: 100%; top: 0; bottom: 0;
  width: var(--tp-pw); max-width: calc(100vw - var(--rail-w) - var(--rail-safe-r) - var(--safe-l) - 44px);
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  scrollbar-width: thin; scrollbar-color: rgba(166,196,102,.5) transparent;
  padding: calc(10px + var(--safe-t)) 10px max(10px, var(--safe-b)) calc(var(--nb-spine) / 2 + 10px);
  border: 0; border-radius: 0;
  background: var(--nb-page);
  box-shadow: var(--tp-ft, 0 0 #0000), var(--tp-fb, 0 0 #0000), inset 0 1px 0 rgba(224,239,154,.1), -10px 0 22px rgba(0,0,0,.26);
  color: var(--text);
  --text-shadow: 0 1px 0 rgba(0,0,0,.45);
  --well: var(--nb-well); --well-line: rgba(166,196,102,.24);
  --ghost: rgba(245,224,180,.1); --ghost-hover: rgba(245,224,180,.18);
  --card-a: rgba(66,94,56,.92); --card-b: rgba(23,50,32,.94); --card-line: var(--nb-line); --card-drop: rgba(3,12,7,.6);
  --card-off-a: rgba(54,64,47,.9); --card-off-b: rgba(33,43,31,.92); --card-off-drop: rgba(3,12,7,.5);
  --card-max-a: rgba(80,114,58,.94); --card-max-b: rgba(42,76,40,.94); --card-max-drop: rgba(3,12,7,.6);
  --pip-off: rgba(246,231,193,.22); --track: rgba(3,12,7,.45);
}
.tower-panel::-webkit-scrollbar { width: 3px; }
.tp-info-btn.on { border-color: #fff0b8; color: #3a2608; text-shadow: none; background: radial-gradient(circle at 50% 30%, #fff1b8, #f2c14e 55%, #c98a26); box-shadow: 0 0 0 1px var(--hud-bark), 0 0 12px rgba(242,193,78,.6); }
.tp-info-btn:focus-visible, .tp-info button:focus-visible, .tp button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Page controls in the HUD's own style: pine inside a gold ring, bark hairline, white glyph. */
.ti-x, .tower-panel .tp-back {
  border: 2px solid transparent; color: #fff;
  background: radial-gradient(circle at 50% 28%, #33502f 0%, #183020 55%, #0b1b10 100%) padding-box, var(--hud-ring) border-box;
  box-shadow: 0 0 0 1px var(--hud-bark), 0 2px 0 1px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.12);
}
.ti-x svg, .tower-panel .tp-back svg { filter: drop-shadow(0 1.5px 0 rgba(0,0,0,.5)); }
.tower-panel .tp-back:active { box-shadow: 0 0 0 1px var(--hud-bark), inset 0 2px 3px rgba(0,0,0,.4); }
@media (hover: hover) and (pointer: fine) {
  .tower-panel .tp-back:hover, .ti-x:hover { background: radial-gradient(circle at 50% 28%, #3f6139 0%, #1f3b27 55%, #10241a 100%) padding-box, var(--hud-ring) border-box; }
}
/* Names in the roster's outlined white. */
.tower-panel .tp-id b { color: #fff; text-shadow: var(--hud-ink); }
.tower-panel .tp-id { padding: 3px 0; }
/* Rows grown to match their note keep their content centred. */
.tower-panel .ti-grown { align-content: center; }

/* Empty page after the shorter one keeps both scroll ranges identical. */
.tower-panel::after, .tp-info::after { content: ''; display: var(--ti-tail-display, none); flex: none; height: var(--ti-tail, 0px); pointer-events: none; }

/* The spine: a strip of the rail's bark edge down the panel's left edge, above both pages. */
.tp-spiral {
  position: absolute; z-index: 3; top: 0; bottom: 0; width: var(--nb-spine);
  right: calc(100% + var(--tp-pw) - var(--nb-spine) / 2);
  pointer-events: none;
  background: linear-gradient(90deg, #2b170a 0%, #8f5d33 30%, #6b3f1d 62%, var(--rail-edge) 80%, #2e1a0b 100%);
  box-shadow: -1px 0 0 var(--rail-glow), 1px 0 0 var(--rail-glow), 0 0 8px rgba(0,0,0,.35);
  animation: tp-in .22s var(--ease-out);
}
.tower-panel[hidden] ~ .tp-spiral { display: none; }
/* Sprigs tucked into the spine at the top and bottom, like the HUD bars' leaves. */
.tp-spiral::before, .tp-spiral::after {
  content: ''; position: absolute; left: 50%; width: 46px; height: 24px; margin-left: -23px;
  background: url('assets/ui/hud-sprig.svg') left bottom / 50% 100% no-repeat, url('assets/ui/hud-sprig-r.svg') right bottom / 50% 100% no-repeat;
  filter: drop-shadow(0 2px 1px rgba(0,0,0,.4));
}
.tp-spiral::before { top: calc(var(--safe-t) + 2px); }
.tp-spiral::after { bottom: max(2px, var(--safe-b)); transform: scaleY(-1); }

/* Left-hand page: the field notes, flush against the panel at the spine. */
.tp-info {
  position: absolute; z-index: 1; right: calc(100% + var(--tp-pw)); top: 0; bottom: 0;
  width: var(--ti-w, clamp(200px, 23vw, 300px)); max-width: calc(100vw - var(--rail-w) - var(--rail-safe-r) - var(--tp-pw) - var(--safe-l) - 14px);
  display: flex; flex-direction: column; gap: 8px; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(166,196,102,.5) transparent;
  padding: calc(12px + var(--safe-t)) calc(var(--nb-spine) / 2 + 12px) max(12px, var(--safe-b)) 13px;
  color: var(--nb-ink);
  border-radius: 14px 0 0 14px;
  background: var(--nb-pressed) 8px calc(100% - 6px) / 78px auto no-repeat, var(--nb-page);
  /* The outer edge in the HUD's frame (gold ring, bark hairline), then the pages' shadow on the map. */
  box-shadow: inset 0 1px 0 rgba(224,239,154,.1), -2px 0 0 #d99c45, -3.5px 0 0 var(--hud-bark), -12px 6px 22px rgba(0,0,0,.26);
  transform-origin: 100% 50%;
  animation: ti-unfold .34s cubic-bezier(.2, .85, .25, 1);
}
.tp-info[hidden] { display: none; }
.tp-info.is-closing { animation: ti-fold .18s cubic-bezier(.5, 0, .9, .5) forwards; pointer-events: none; }
.tp-info { container: ti / inline-size; }
.tp-info > * { flex-shrink: 0; }
.tp-info::-webkit-scrollbar { width: 3px; }
/* The page swings out of the spine toward you and settles flat (and back). */
@keyframes ti-unfold { from { transform: perspective(1100px) rotateY(34deg) scaleX(.92); filter: brightness(.8); opacity: .3; } }
@keyframes ti-fold { to { transform: perspective(1100px) rotateY(72deg) scaleX(.9); filter: brightness(.78); opacity: 0; } }
.tp-info button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* Header: the animal on a roster card, its name in outlined white, a close button. */
.ti-head { display: grid; grid-template-columns: 50px minmax(0, 1fr) 32px; align-items: center; gap: 10px; padding: 2px 0 10px;
  background: var(--nb-rule) left bottom / 100% 1.5px no-repeat; }
.ti-pic { display: grid; place-items: center; width: 50px; height: 50px; border-radius: 12px; border: 2px solid transparent;
  background:
    radial-gradient(62% 50% at 50% 40%, rgba(222,240,160,.26), rgba(222,240,160,0) 72%) padding-box,
    linear-gradient(180deg, #4b643d 0%, #2a452a 45%, #0e2718 100%) padding-box,
    linear-gradient(180deg, #e0ef9a 0%, #a6c466 40%, #5f833b 100%) border-box;
  box-shadow: 0 0 0 1.5px #0a1c10, 0 2px 0 1.5px rgba(0,0,0,.4); }
.ti-pic svg { width: 42px; height: 42px; filter: drop-shadow(0 1.5px 0 rgba(0,0,0,.35)); }
.ti-id { display: grid; min-width: 0; line-height: 1.1; }
.ti-id small { font: 600 17px/1 'Caveat', 'Segoe Print', cursive; color: var(--nb-gold); }
.ti-id b { font-size: 20px; color: #fff; text-shadow: var(--hud-ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-id em { font: 600 16px/1.05 'Caveat', 'Segoe Print', cursive; color: var(--nb-moss); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-x { position: relative; width: 32px; height: 32px; padding: 0; display: grid; place-items: center; align-self: start; border-radius: 50%;
  transition: transform .18s var(--spring); }
.ti-x::after { content: ''; position: absolute; inset: -6px; }
.ti-x svg { width: 14px; height: 14px; }
.ti-x:active { transform: scale(.9); transition-duration: .05s; }

/* Sections sit in shaded wells with a faint moss ring, so fine print reads over the moving map. */
.tp-info .ti-sec, .tp-info .ti-tags {
  padding: 6px 8px; border-radius: 10px; background: var(--nb-well); box-shadow: inset 0 0 0 1px rgba(166,196,102,.16);
}

/* Section headings: a HUD leaf, gold lettering and a fading moss rule. */
.ti-h { margin: 0; padding: 0 0 4px; font-size: 10.5px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--nb-gold);
  text-shadow: 0 1px 0 rgba(0,0,0,.5); background: var(--nb-rule) left bottom / 88px 1.5px no-repeat; }
.ti-h::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: 5px; vertical-align: -2px; background: var(--nb-leaf) center / contain no-repeat; }
.ti-sec { display: grid; gap: 3px; }

/* Ledgers (service record, stats): icon, label, dotted leader, value. */
.ti-ledger { margin: 0; display: grid; column-gap: 16px; }
.ti-ledger > div { display: grid; grid-template-columns: 18px minmax(0, max-content) minmax(8px, 1fr) auto; align-items: center; column-gap: 6px; min-width: 0; min-height: 23px; }
.ti-ledger > div > * { grid-row: 1; }
.ti-ledger > div::after { content: ''; grid-column: 3; grid-row: 1; align-self: end; height: 0; margin-bottom: 7px; border-bottom: 2px dotted rgba(214,230,170,.22); }
.ti-ledger i { grid-column: 1; display: grid; width: 18px; height: 18px; }
.ti-ledger i svg { width: 100%; height: 100%; filter: drop-shadow(0 1px 0 rgba(0,0,0,.4)); }
.ti-ledger i.seed { color: var(--seed); }
.ti-ledger dt { grid-column: 2; min-width: 0; font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--nb-ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-ledger dd { grid-column: 4; margin: 0; max-width: 13ch; font-size: 14px; font-weight: 700; line-height: 1.1; text-align: right; color: var(--nb-ink); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-ledger dd.up { color: var(--good-text); }
/* Wide pages keep the service record to two short columns. */
@container ti (min-width: 300px) { .ti-rec .ti-ledger { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Traits: small outlined badges. */
.ti-tags { gap: 6px; }
.ti-tags .uu-tag { padding: 2px 8px; border-radius: 999px; background: rgba(243,203,118,.1); color: var(--nb-gold);
  box-shadow: inset 0 0 0 1px rgba(243,203,118,.45); font-size: 10px; letter-spacing: .7px; text-transform: uppercase; }
.ti-tags .uu-tag.good { background: rgba(196,224,126,.1); color: var(--nb-moss); box-shadow: inset 0 0 0 1px rgba(196,224,126,.45); }

/* No room above the first path: the notes go first, beside their buttons. */
.tp-info.notes-first .ti-notes { order: 1; }
.tp-info.notes-first :is(.ti-sec, .ti-tags) { order: 2; }
.tp-info.notes-first .ti-blurb { order: 3; }

/* Notes: one card per path, in the roster's pine and moss, with the path's colour down the left edge. */
.ti-notes { display: flex; flex-direction: column; gap: 6px; }
.ti-note { --pc: #c98a26; position: relative; padding: 6px 10px 7px 13px; border-radius: 4px 10px 10px 4px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--pc) 18%, rgba(30,60,38,.92)), rgba(22,48,31,.9) 70%);
  box-shadow: inset 0 0 0 1px var(--nb-line), 0 2px 0 rgba(3,12,7,.55); }
.ti-note::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; border-radius: 4px 0 0 4px;
  background: linear-gradient(var(--pc), color-mix(in srgb, var(--pc) 78%, #3a2a10)); }
/* Lined up with its button: an index tab in the path's colour points at it across the spine. */
.ti-note.is-aligned::after { content: ''; position: absolute; right: -12px; top: var(--ay, 50%); width: 12px; height: 20px; margin-top: -10px; border-radius: 0 5px 5px 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--pc) 72%, #2a1c08), var(--pc) 45%, color-mix(in srgb, var(--pc) 70%, #fff) 100%);
  box-shadow: 1px 1px 0 rgba(0,0,0,.35); }
.ti-note small { display: block; font-size: 9.5px; font-weight: 700; letter-spacing: .9px; text-transform: uppercase; color: color-mix(in srgb, var(--pc) 55%, #fff4dc); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ti-note h4 { margin: 1px 0 2px; font-size: 15px; line-height: 1.15; color: color-mix(in srgb, var(--pc) 28%, #fff4dc); text-shadow: 0 1px 0 rgba(0,0,0,.45); }
.ti-note p { margin: 0; font-size: 12.5px; line-height: 1.3; color: var(--nb-ink-soft); }
.ti-note p.ab { margin-top: 4px; font-size: 11.5px; color: var(--nb-gold); }
.ti-note p.ab em { font-style: normal; color: var(--nb-ink-soft); }
.ti-note.max h4 { color: var(--gold-text); }
.ti-note.ab { --pc: #d39a2a; }
.ti-note.ab h4 { color: var(--gold-text); }
.ti-note.para { --pc: #9a5ac8; }
.ti-note.para h4 { color: #dcc2f4; }
.ti-note.hero { --pc: #e2a52c; }
.ti-note.locked { opacity: .8; }
.ti-note.locked h4 { color: var(--nb-ink-soft); }

/* The animal's story: a handwritten aside under a moss rule. */
.ti-blurb { margin: 2px 0 0; padding: 9px 2px 0; font: italic 600 17px/1.12 'Caveat', 'Segoe Print', cursive; color: var(--nb-moss);
  background: var(--nb-rule) left top / 100% 1.5px no-repeat; }

/* Phones in landscape: a slimmer spine and tighter pages; the notes come first,
   beside their buttons (the animal panel hides its numbers here); the numbers follow. */
@media (max-height: 560px) {
  .rail { --tp-w: clamp(184px, 22vw, 208px); --ti-w: clamp(184px, 22vw, 214px); --nb-spine: 6px; }
  .tower-panel { padding: calc(6px + var(--safe-t)) 8px max(6px, var(--safe-b)) calc(var(--nb-spine) / 2 + 8px); }
  .tp-info { gap: 5px; padding: calc(6px + var(--safe-t)) calc(var(--nb-spine) / 2 + 10px) max(6px, var(--safe-b)) 10px; border-radius: 10px 0 0 10px; }
  .ti-head { grid-template-columns: 36px minmax(0, 1fr) 28px; gap: 8px; padding: 2px 0 6px; }
  .ti-pic { width: 36px; height: 36px; border-radius: 9px; }
  .ti-pic svg { width: 30px; height: 30px; }
  .ti-id small { font-size: 14px; }
  .ti-id b { font-size: 15px; }
  .ti-id em, .ti-blurb { display: none; }
  .ti-x { width: 28px; height: 28px; }
  .ti-x svg { width: 12px; height: 12px; }
  .tp-info .ti-sec, .tp-info .ti-tags { padding: 4px 6px; border-radius: 8px; }
  .ti-h { font-size: 9px; letter-spacing: 1.2px; padding-bottom: 3px; background-size: 70px 1.5px; }
  .ti-h::before { width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; }
  .tp-spiral::before, .tp-spiral::after { width: 34px; height: 18px; margin-left: -17px; }
  .ti-notes { gap: 5px; }
  .ti-note { padding: 4px 8px 5px 11px; border-radius: 4px 8px 8px 4px; }
  .ti-note.is-aligned::after { right: -10px; width: 10px; height: 16px; margin-top: -8px; }
  .ti-note small { display: none; }
  .ti-note h4, .ti-note p { display: inline; }
  .ti-note h4 { font-size: 12.5px; }
  .ti-note h4::after { content: ' · '; color: rgba(214,230,170,.5); }
  .ti-note p { font-size: 11.5px; line-height: 1.25; }
  .ti-note p.ab { display: block; font-size: 11px; margin-top: 2px; }
  .ti-note p.ab span { display: none; }
  .ti-ledger dd { font-size: 12.5px; }
  .ti-ledger > div { min-height: 20px; }
  .ti-ledger > div::after { margin-bottom: 6px; }
}
@media (max-width: 600px) and (orientation: landscape) {
  .rail { --tp-w: 184px; }
}

/* XP on shop tiles: a gold dot when an upgrade can be unlocked, "+XP" after a round. */
.tile .xp-dot {
  position: absolute; top: 4px; right: 4px; width: 16px; height: 16px; border-radius: 50%;
  background: linear-gradient(#ffd666, #e2a52c); box-shadow: 0 1px 0 #9a6c12, 0 0 0 2px var(--card-a);
  display: grid; place-items: center; color: #3a2a08; pointer-events: none;
}
.tile .xp-dot svg { width: 10px; height: 10px; }
.tile .xp-pop {
  position: absolute; left: 50%; top: 30%; z-index: 2; pointer-events: none; white-space: nowrap;
  font-size: 12.5px; font-weight: 700; color: #3a2a08; padding: 1px 7px; border-radius: 999px;
  background: linear-gradient(#ffd666, #e2a52c); box-shadow: 0 2px 0 #9a6c12;
  animation: xp-pop 1.5s ease-out forwards;
}
@keyframes xp-pop {
  0% { transform: translate(-50%, 6px) scale(.7); opacity: 0; }
  15% { transform: translate(-50%, 0) scale(1.08); opacity: 1; }
  70% { transform: translate(-50%, -10px); opacity: 1; }
  100% { transform: translate(-50%, -22px); opacity: 0; }
}
/* Animal cards: the painted animal over a soft glow, its price in a dark pill
   along the bottom, a moss-green ring and a leaf sprig at each lower corner.
   Sized by the rail (square-ish), so text scales with the card (cqw). */
.tile {
  position: relative; display: block; aspect-ratio: 1; min-width: 0; padding: 0; cursor: pointer;
  border-radius: 14px; border: 3px solid transparent; color: #fff; container-type: inline-size;
  background:
    radial-gradient(62% 50% at 50% 40%, rgba(222,240,160,.26), rgba(222,240,160,0) 72%) padding-box,
    linear-gradient(180deg, #4b643d 0%, #3a5533 25%, #2a452a 45%, #173320 70%, #0e2718 100%) padding-box,
    linear-gradient(180deg, #e0ef9a 0%, #a6c466 40%, #5f833b 100%) border-box;
  box-shadow: 0 0 0 1.5px #0a1c10, 0 3px 0 1.5px rgba(0,0,0,.42), inset 0 0 0 1.5px rgba(8,26,14,.55);
  touch-action: none; transition: transform .2s var(--spring), box-shadow .12s, filter .15s, opacity .15s;
}
.tile::before {
  content: ''; position: absolute; z-index: 1; left: -2%; right: -2%; bottom: -2%; height: 26%; pointer-events: none;
  background: url('assets/ui/hud-sprig.svg') left bottom / auto 100% no-repeat, url('assets/ui/hud-sprig-r.svg') right bottom / auto 100% no-repeat;
}
.tile:active { transform: translateY(2px) scale(.97); transition-duration: .05s; }
/* Just became affordable: a quick hop and a golden glint. */
.tile.afford { animation: afford .55s var(--spring); }
.tile.afford::after { content: ''; position: absolute; inset: -3px; border-radius: inherit; pointer-events: none;
  box-shadow: 0 0 0 3px rgba(242,193,78,.85); animation: afford-ring .6s ease-out forwards; }
@keyframes afford { 35% { transform: translateY(-3px) scale(1.05); } }
@keyframes afford-ring { from { opacity: 1; } to { opacity: 0; } }
.tile-icon {
  position: absolute; left: 6%; right: 6%; top: 3%; bottom: 25%; display: grid; place-items: center;
  pointer-events: none; transition: transform .2s var(--spring);
}
.tile-icon canvas, .tile-icon img, .tile-icon svg { display: block; width: 100%; height: 100%; object-fit: contain; }
.tile.active .tile-icon { transform: scale(1.08) translateY(-1px); }
/* Phones show just the animal (its name is in the details bubble); taller screens add the name. */
.tile-name { display: none; font-size: 12.5px; font-weight: 700; line-height: 1.1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-height: 561px) {
  .tile:not(.hero-tile) .tile-icon { bottom: 36%; }
  .tile:not(.hero-tile) .tile-name {
    display: block; position: absolute; z-index: 2; left: 5%; right: 5%; bottom: 31%; text-align: center;
    font-size: clamp(11px, 9.5cqw, 15px); color: #fff; text-shadow: var(--hud-ink);
  }
}
.tile-cost {
  position: absolute; z-index: 2; left: 9%; right: 9%; bottom: 5%; height: 24%;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  border-radius: 999px; background: linear-gradient(#10281a, #06140b);
  box-shadow: inset 0 0 0 1.5px rgba(170,200,120,.3), 0 2px 0 rgba(0,0,0,.4);
  font-size: 15px; font-size: clamp(11px, 17cqw, 22px); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums;
  color: #fff; text-shadow: var(--hud-ink); white-space: nowrap;
}
.tile-cost svg { width: 1em; height: 1em; flex: none; color: var(--seed); filter: drop-shadow(0 1px 0 rgba(0,0,0,.5)); }
.tile kbd { position: absolute; z-index: 3; top: 4px; left: 5px; opacity: .7; display: none; }
/* Can't afford: the animal fades, the price stays readable in red. */
.tile.poor .tile-icon { filter: saturate(.25); opacity: .6; transition: opacity .2s, filter .2s; }
.tile.poor .tile-cost { color: var(--bad-text); }
.tile.poor .tile-cost svg { color: inherit; }
/* Picked (placing it now): the ring turns gold and glows. */
.tile.active {
  background:
    radial-gradient(70% 58% at 50% 40%, rgba(255,236,150,.4), rgba(255,236,150,0) 72%) padding-box,
    linear-gradient(180deg, #5a7440 0%, #3a5a34 55%, #213f24 100%) padding-box,
    var(--hud-ring) border-box;
  box-shadow: 0 0 0 1.5px var(--hud-bark), 0 0 0 4.5px rgba(255,210,100,.5), 0 3px 0 1.5px rgba(0,0,0,.42);
}
.tile:disabled { opacity: .5; cursor: default; }
.tile:focus-visible, .go-btn:focus-visible, .hud-btn:focus-visible, .mbtn:focus-visible, .sbtn:focus-visible, .chip-btn:focus-visible, .sheet-close:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.rail-foot { position: relative; display: grid; gap: 10px; }
/* Leaves curl out from under the Start button's lower right corner. */
.rail-foot::after {
  content: ''; position: absolute; z-index: 1; right: -6px; bottom: -6px; width: calc(var(--go-h) * .55); height: calc(var(--go-h) * .4);
  background: url('assets/ui/hud-sprig-r.svg') center / contain no-repeat; transform: scaleY(-1); pointer-events: none;
}
/* Start: a glossy green slab in a gold ring, leaves at its top left and a flower at its top right. */
.go-btn {
  position: relative; height: var(--go-h); border: 3px solid transparent; border-radius: calc(var(--go-h) * .3); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: calc(var(--go-h) * .42); font-weight: 700; color: #fff; letter-spacing: .3px; text-shadow: var(--go-ink);
  background:
    radial-gradient(90% 55% at 50% 0%, rgba(255,255,255,.42), rgba(255,255,255,0) 70%) padding-box,
    linear-gradient(180deg, #86dc5c 0%, #4cb43e 42%, #24903a 72%, #0f6c28 100%) padding-box,
    var(--hud-ring) border-box;
  box-shadow: 0 0 0 1.5px var(--hud-bark), 0 4px 0 1.5px rgba(0,0,0,.4), inset 0 -3px 0 rgba(0,50,15,.35);
  transition: transform .2s var(--spring), filter .15s;
}
.go-btn::before {
  content: ''; position: absolute; z-index: 1; left: -9px; right: -6px; top: -7px; height: calc(var(--go-h) * .4); pointer-events: none;
  background: url('assets/ui/hud-sprig.svg') left top / auto 100% no-repeat, url('assets/ui/hud-flower.svg') right top / auto 72% no-repeat;
}
.go-btn svg { width: calc(var(--go-h) * .48); height: calc(var(--go-h) * .48); filter: drop-shadow(0 2px 0 rgba(0,0,0,.25)); }
.go-btn svg path { stroke: #0b3a15; stroke-width: 1.8; stroke-linejoin: round; paint-order: stroke; }
.go-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 1.5px var(--hud-bark), 0 1px 0 1.5px rgba(0,0,0,.4), inset 0 -3px 0 rgba(0,50,15,.35); transition-duration: .05s; }
/* "Ready" glow: a ring on its own layer that only fades in and out (no repaints). */
.go-btn::after { content: ''; position: absolute; inset: -3px; border-radius: inherit; pointer-events: none; opacity: 0;
  box-shadow: 0 0 0 6px rgba(114,214,76,.42), 0 0 18px 4px rgba(114,214,76,.35); }
.go-btn.ready::after { animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 50% { opacity: 1; } }
.go-btn.swap > * { animation: go-swap .34s var(--spring); }
@keyframes go-swap { from { transform: scale(.55); opacity: 0; } }
/* While a round runs it is the speed toggle: pine at 1x, gold when sped up. */
.go-btn.ff { background: var(--hud-fill) padding-box, var(--hud-ring) border-box; }
.go-btn.ff.on { background: radial-gradient(90% 55% at 50% 0%, rgba(255,255,255,.45), rgba(255,255,255,0) 70%) padding-box, linear-gradient(#ffe48a, #f2b53c 55%, #c98418) padding-box, var(--hud-ring) border-box;
  color: #3a2a08; text-shadow: 0 1px 0 rgba(255,255,255,.4); }
.go-btn.ff.on svg path { stroke: none; }
.go-btn:disabled { background: linear-gradient(#56634b, #3a4634) padding-box, linear-gradient(#aaa482, #6b6650) border-box; color: var(--btn-off-text); cursor: default; text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.go-btn:disabled svg path { stroke: none; }
.go-btn .go-sub { align-self: center; font-size: calc(var(--go-h) * .2); font-weight: 700; color: rgba(255,255,255,.92); }

/* The main menu lives in src/ui/menu.css. A gentle bob shared with the heroes sheet. */
@keyframes spot-bob { 50% { transform: translateY(-4px); } }

/* ---- Quests & Awards sheets (previews until the systems land). */
.qa-group { margin: 0 0 12px; text-align: left; }
.qa-group > h3 { display: flex; align-items: center; justify-content: space-between; margin: 0 0 6px; font-size: 12px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--sheet-soft); }
.qa-group > h3 small { font-size: 11px; letter-spacing: 0; text-transform: none; font-weight: 500; }
.qa-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 0 12px; align-items: start; }
.qa-list { display: grid; gap: 6px; list-style: none; margin: 0; padding: 0; }
.quest {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 14px; background: var(--sheet-2); box-shadow: 0 3px 0 var(--sheet-drop);
}
.quest-ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--sheet-3); }
.quest-ico svg { width: 82%; height: 82%; }
.quest b { display: block; font-size: 15px; line-height: 1.2; }
.quest small { display: block; font-size: 12px; color: var(--sheet-soft); line-height: 1.25; }
.quest-bar { position: relative; height: 12px; margin-top: 4px; border-radius: 999px; background: var(--track); overflow: hidden; }
.quest-bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: inherit; background: linear-gradient(#c3cc85, #728c4e); }
.quest-bar em { position: relative; display: block; font-style: normal; font-size: 9.5px; font-weight: 700; line-height: 12px; text-align: center; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.7); }
.reward {
  display: inline-flex; align-items: center; gap: 3px; padding: 4px 10px 4px 5px; border-radius: 999px; font-size: 13px; font-weight: 700; white-space: nowrap;
  color: #fff; background: radial-gradient(circle at 40% 30%, #6fc8ec, #2a7aa8); box-shadow: 0 2px 0 #1d4f6e;
}
.reward svg { width: 16px; height: 16px; }
.awards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-bottom: 14px; text-align: left; }
.award { display: grid; grid-template-columns: 44px minmax(0, 1fr); align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px; background: var(--sheet-2); box-shadow: 0 3px 0 var(--sheet-drop); }
.award .medal { width: 44px; height: 44px; filter: grayscale(1) opacity(.45); }
.award .medal svg { width: 100%; height: 100%; }
.award b { display: block; font-size: 14px; line-height: 1.15; }
.award small { display: block; font-size: 11.5px; color: var(--sheet-soft); line-height: 1.25; }
.preview-tag { display: inline-block; margin-left: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .4px; vertical-align: middle; background: var(--tag); color: var(--accent); }
/* ---- Sheets (overlay) ------------------------------------------------- */
.overlay {
  position: absolute; inset: 0; z-index: 30; display: none; place-items: center;
  grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  background: var(--dim); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.overlay.show { display: grid; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; } }
/* Closing: fade the backdrop and drop the sheet, then the HUD clears it. */
.overlay.closing { pointer-events: none; animation: fade-out .16s ease forwards; }
.overlay.closing > * { animation: sink .16s ease-in forwards; }
@keyframes fade-out { to { opacity: 0; } }
@keyframes sink { to { transform: translateY(10px) scale(.97); opacity: 0; } }
/* The menu's demo map keeps playing behind its sheets: skip the costly blur on phones. */
@media (pointer: coarse) {
  .app[data-screen="menu"] .overlay { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
.sheet, .overlay > .card, .tile-tip, .tp-tip {
  --good-text: #38602d; --bad-text: #a03f2b; --gold-text: #80581e; --seed: #91651f;
  --tag: #d8c8a2; --tag-text: #4c513b; --tag-good: #d5dfb8; --tag-good-text: #385532;
  --well: rgba(89,76,45,.08); --well-line: rgba(103,84,47,.18); --focus: #9b4d2c;
}
.sheet, .overlay > .card {
  position: relative; width: min(460px, 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain;
  background: url('assets/icons/woodland-sprig.svg') right bottom / 150px 117px no-repeat, radial-gradient(ellipse at 15% 0, #fff5dc, transparent 65%), var(--sheet);
  color: var(--sheet-text); border-radius: 22px; padding: 20px 22px;
  border: 3px solid var(--sheet-edge); box-shadow: inset 0 0 0 2px #fff4d6, 0 6px 0 #53432c, 0 24px 60px rgba(15,29,20,.5);
  scrollbar-color: #a18a5d transparent; scrollbar-width: thin;
  text-align: center; animation: rise .26s cubic-bezier(.2,.9,.3,1.2);
}
.sheet.wide { width: min(680px, 100%); }
@keyframes rise { from { transform: translateY(14px) scale(.97); opacity: 0; } }
.sheet .eyebrow { color: var(--accent); line-height: 1.35; }
.sheet .eyebrow svg { display: inline-block; width: 1em; height: 1em; vertical-align: -.15em; }
.sheet > .eyebrow, .sheet > .title { padding-right: 34px; }
.sheet button:focus-visible, .sheet summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sbtn:disabled { cursor: default; opacity: .55; transform: none; box-shadow: none; }
.sheet .title { margin: 2px 0 6px; font-size: 34px; line-height: 1.05; font-weight: 700; letter-spacing: -.4px; color: var(--forest); }
.sheet .lede { margin: 0 auto 14px; color: var(--sheet-soft); max-width: 44ch; }
.music-credit a { color: inherit; text-underline-offset: 2px; }
.sheet-close {
  z-index: 5; flex: none;
  position: absolute; top: 10px; right: 10px; width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--sheet-2); color: var(--sheet-soft); display: grid; place-items: center;
  transition: transform .2s var(--spring);
}
.sheet-close::after { content: ''; position: absolute; inset: -6px; border-radius: 50%; }
.sheet-close:active { transform: scale(.88); transition-duration: .05s; }
.sheet-close svg { width: 20px; height: 20px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .full { grid-column: 1 / -1; }
.sbtn {
  height: 50px; border: 0; border-radius: 14px; cursor: pointer; padding: 0 14px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 17px; font-weight: 700; color: var(--sheet-text);
  background: var(--sheet-2); box-shadow: 0 4px 0 var(--sheet-drop); transition: transform .2s var(--spring);
}
.sbtn svg { width: 20px; height: 20px; flex: none; }
.sbtn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--sheet-drop); transition-duration: .05s; }
.sbtn.primary { background: linear-gradient(var(--go-a), var(--go-b)); color: #fff; box-shadow: 0 4px 0 var(--go-deep); text-shadow: 0 2px 0 rgba(0,0,0,.3); }
.sbtn.primary:active { box-shadow: 0 1px 0 var(--go-deep); }
.sbtn.danger { background: linear-gradient(#d9653b, #b94d2b); color: #fff; box-shadow: 0 4px 0 #7f2f18; text-shadow: 0 2px 0 rgba(0,0,0,.25); }
.sbtn.danger:active { box-shadow: 0 1px 0 #7f2f18; }
.sbtn.big { height: 58px; font-size: 21px; }

.stat-row { display: flex; justify-content: center; gap: 8px; margin: 0 0 16px; flex-wrap: wrap; }
.stat-row div { background: var(--sheet-2); border-radius: 12px; padding: 6px 14px; min-width: 88px; }
.stat-row dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--sheet-soft); }
.stat-row dd { margin: 0; font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sheet.won .eyebrow { color: var(--accent-good); }
.result-badge { width: 74px; height: 74px; margin: -4px auto 6px; animation: badge-in .7s var(--spring) .1s both; }
.result-badge svg { width: 100%; height: 100%; }
@keyframes badge-in { from { transform: scale(.2) rotate(-25deg); opacity: 0; } }
.sheet.won .result-badge svg { filter: drop-shadow(0 0 14px rgba(242,193,78,.6)); }
.stat-row dd { font-variant-numeric: tabular-nums; }
/* Victory confetti (pieces made by the HUD; transform/opacity only). */
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.overlay > .sheet { z-index: 1; }
.confetti i { position: absolute; top: -16px; width: 9px; height: 14px; border-radius: 2px; opacity: 0;
  animation: confetti var(--d, 2.6s) cubic-bezier(.3,.6,.5,1) var(--w, 0s) forwards; }
@keyframes confetti {
  0% { opacity: 1; transform: translate3d(0, 0, 0) rotate(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--x, 0), 105vh, 0) rotate(var(--r, 540deg)); }
}
.xp-row { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 6px; margin: -6px 0 14px; }
.xp-row > small { width: 100%; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--sheet-soft); }
.xp-row span { display: inline-flex; align-items: center; gap: 2px; padding: 2px 9px 2px 2px; border-radius: 999px; background: #f8e3a6; font-weight: 700; font-size: 14px; color: #6a4708; }
.xp-row span svg { width: 26px; height: 26px; }
.xp-row em { font-style: normal; font-size: 11.5px; margin-left: 4px; padding: 1px 6px; border-radius: 999px; background: rgba(106,71,8,.14); }
.xp-row em.lvup { color: #fff; background: linear-gradient(var(--go-a), var(--go-b)); box-shadow: 0 1px 0 var(--go-deep); }
.actions .unlocks { background: linear-gradient(#ffd666, #e2a52c); color: #3a2a08; box-shadow: 0 4px 0 #9a6c12; }
.actions .unlocks:active { box-shadow: 0 1px 0 #9a6c12; }
.reset-row { margin: -6px 0 14px; text-align: left; }
.reset-row button { height: 40px; font-size: 14px; }

.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0 16px; text-align: left; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--sheet-2); border: 1px solid rgba(119,94,50,.12); border-radius: 14px; padding: 9px 12px; min-height: 54px; cursor: pointer;
}
.setting-row b { display: block; font-size: 16px; }
.setting-row small { display: block; color: var(--sheet-soft); font-size: 12.5px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 52px; height: 30px; border-radius: 999px; background: var(--sheet-3); position: relative; transition: background .15s;
}
.switch::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch:checked { background: var(--go); }
.sheet .switch { color-scheme: normal; box-shadow: inset 0 0 0 1px rgba(55,68,40,.15); }
.switch:checked::after { transform: translateX(22px); }
.switch:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.slider { width: 140px; accent-color: var(--go-b); flex: none; }
.slider:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 4px; }

.steps { list-style: none; margin: 4px 0 16px; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; text-align: left; }
.steps li { background: var(--sheet-2); border-radius: 14px; padding: 10px 12px; display: grid; gap: 4px; align-content: start; }
.steps .step-ico { width: 44px; height: 44px; }
.steps .step-ico svg { width: 100%; height: 100%; }
/* Centred, not padded: percentage padding follows the column width and can squash the glyph to nothing. */
.steps .go-ico { border-radius: 50%; background: linear-gradient(var(--go-a), var(--go-b)); color: #fff; display: grid; place-items: center; box-shadow: 0 3px 0 var(--go-deep); }
.steps .go-ico svg { width: 56%; height: 56%; margin-left: 6%; }
.steps b { font-size: 16px; }
.steps span { font-size: 13.5px; color: var(--sheet-soft); line-height: 1.3; }
.keys { font-size: 12.5px; color: var(--sheet-soft); margin: -6px 0 14px; line-height: 2; }

.coop-art { display: flex; justify-content: center; align-items: center; gap: 6px; margin: 4px 0 8px; }
.coop-art span { width: 58px; height: 58px; }
.coop-art span svg { width: 100%; height: 100%; }
.coop-art i { font-style: normal; font-size: 26px; color: var(--accent); font-weight: 700; }
.coop-list { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 6px; text-align: left; }
.coop-list li { background: var(--sheet-2); border-radius: 12px; padding: 8px 12px; font-size: 14px; color: var(--sheet-soft); }
.coop-list b { color: var(--sheet-text); }

/* ---- Trail picker ------------------------------------------------------ */
.sheet.trails-sheet { width: min(1120px, 100%); padding-bottom: 14px; }
.trails {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(184px, 1fr); gap: 12px;
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; padding: 6px 4px 10px; margin: 4px -4px 0; text-align: left;
}
.trail-tabs { display: flex; gap: 6px; margin: 2px 0 6px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.trail-tabs::-webkit-scrollbar { display: none; }
.trail-tab {
  flex: 1 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border: 0; border-radius: 12px; font: inherit; cursor: pointer; color: var(--sheet-soft); background: var(--sheet-2); box-shadow: 0 2px 0 var(--sheet-drop);
}
.trail-tab b { font-size: 13.5px; }
.trail-tab small { font-size: 11px; font-weight: 700; opacity: .75; }
.trail-tab svg { width: 13px; height: 13px; }
.trail-tab.on { color: #fff; background: linear-gradient(135deg, #7cc456, #3f8a2a); box-shadow: 0 2px 0 #24521a; }
.trail-tab.d3.on { background: linear-gradient(135deg, #f2bf4a, #c47a14); box-shadow: 0 2px 0 #7a4a0a; }
.trail-tab.d4.on { background: linear-gradient(135deg, #f39a5a, #c4502a); box-shadow: 0 2px 0 #7a2e14; }
.trail-tab.d5.on { background: linear-gradient(135deg, #e86a7a, #9a2438); box-shadow: 0 2px 0 #5a1220; }
.trail-tab.locked:not(.on) { opacity: .7; }
.trail[hidden] { display: none; }
.trail-lanes { position: absolute; right: 8px; top: 8px; padding: 2px 8px; border-radius: 999px; font-style: normal; font-weight: 800; font-size: 11.5px; color: #fff; background: rgba(20,30,16,.72); }
.trail {
  position: relative; display: flex; flex-direction: column; padding: 0; border: 0; border-radius: 18px; overflow: hidden; cursor: pointer;
  font: inherit; text-align: left; color: var(--sheet-text); background: var(--sheet-2); box-shadow: 0 4px 0 var(--sheet-drop);
  scroll-snap-align: start; transition: transform .2s var(--spring); animation: rise .34s var(--ease-out) both;
}
.trail:nth-child(2) { animation-delay: .04s; } .trail:nth-child(3) { animation-delay: .08s; }
.trail:nth-child(4) { animation-delay: .12s; } .trail:nth-child(5) { animation-delay: .16s; }
.trail:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--sheet-drop); transition-duration: .05s; }
.trail:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.trail.last::after { content: ''; position: absolute; inset: 0; border-radius: inherit; box-shadow: inset 0 0 0 3px var(--gold); pointer-events: none; }
.trail-art { position: relative; display: block; aspect-ratio: 3 / 2; overflow: hidden; background: linear-gradient(135deg, var(--t1), var(--t2)); }
.trail-art img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .6s var(--ease-out); animation: fade .4s ease; }
.trail-art::after { content: ''; position: absolute; inset: 0; background: linear-gradient(transparent 60%, rgba(0,0,0,.28)); pointer-events: none; }
.trail-num {
  position: absolute; left: 8px; top: 8px; z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-style: normal; font-weight: 700; font-size: 15px; color: #fff; background: rgba(0,0,0,.55); box-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.trail.last .trail-num { background: var(--gold); color: #3a2a08; }
.trail-body { display: grid; gap: 5px; align-content: start; padding: 9px 12px 12px; flex: 1; }
.trail-body > b { font-size: 17px; line-height: 1.1; }
.trail-diff { display: flex; align-items: center; gap: 3px; }
.trail-diff i { width: 11px; height: 11px; border-radius: 2px 11px; background: var(--pip-off); }
.trail-diff i.on { background: linear-gradient(135deg, #9be07a, #3f8a2a); }
.trail-diff.d3 i.on { background: linear-gradient(135deg, #ffd666, #d28a1c); }
.trail-diff.d4 i.on { background: linear-gradient(135deg, #ffb070, #d4643a); }
.trail-diff.d5 i.on { background: linear-gradient(135deg, #ff8a8a, #b0303f); }
.trail-diff small { margin-left: 6px; font-size: 11.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--sheet-soft); }
.trail-tag { font-size: 12.5px; line-height: 1.3; color: var(--sheet-soft); }
.trail-feats { display: flex; flex-wrap: wrap; gap: 4px; }
.trail-feats span { padding: 2px 7px; border-radius: 999px; font-size: 11px; background: var(--tag); color: var(--tag-text); }
.trail-best { display: flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 12px; font-weight: 700; color: var(--sheet-soft); }
.trail-best.won { color: var(--gold-text); }
.trail-best svg { width: 15px; height: 15px; flex: none; }

/* ---- Rotate prompt (portrait phones) --------------------------------- */
.rotate {
  position: fixed; inset: 0; z-index: 100; display: none; place-items: center; align-content: center; gap: 22px;
  background: radial-gradient(600px 400px at 50% 30%, var(--rail-top), var(--bg)); text-align: center; padding: 24px;
}
.rotate p { margin: 0; color: var(--text-soft); font-size: 15px; }
.rotate b { display: block; color: var(--text); font-size: 22px; margin-bottom: 4px; }
.rotate-phone {
  width: 58px; height: 98px; border: 5px solid var(--text); border-radius: 14px; position: relative;
  animation: turn 2.2s ease-in-out infinite;
}
.rotate-phone::after { content: ''; position: absolute; left: 50%; bottom: 6px; width: 14px; height: 4px; margin-left: -7px; border-radius: 2px; background: var(--text); }
@keyframes turn { 0%, 20% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (pointer: coarse) and (max-width: 900px) {
  .rotate { display: grid; }
  /* The Upgrades, Animals and Heroes pages have portrait layouts of their own. */
  .app[data-page="upgrades"] .rotate, .app[data-page="animals"] .rotate, .app[data-page="heroes"] .rotate { display: none; }
}

/* Reads env() itself (not the inherited --safe-*), so a fresh style for it is a
   fresh read of the insets (menu-scene.js re-reads it after the phone turns). */
.safe-probe {
  position: fixed; top: 0; left: 0; width: 0; height: 0; visibility: hidden; pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}
/* Holds the HUD icon gradients (index.html); kept rendered (not display: none) so Safari resolves them. */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }

/* ---- Precise pointers: hotkeys and hover help ------------------------- */
@media (hover: hover) and (pointer: fine) {
  .sheet-close:hover { filter: brightness(1.08); }
  .trail:hover { filter: brightness(1.05); }
  .trail:hover .trail-art img { transform: scale(1.07); }
  .tile kbd { display: block; }
  .tile:hover:not(:disabled) { filter: brightness(1.08); }
  .go-btn:hover:not(:disabled) { filter: brightness(1.07); }
  .hud-btn:hover { filter: brightness(1.15); }
  .sbtn:hover { filter: brightness(1.04); }
}

/* ---- Short screens: phones in landscape ------------------------------ */
@media (max-height: 560px) {
  :root {
    /* A slim rail on phones: two narrow columns of cards leave the map room. */
    --rail-w: clamp(144px, 16.5vw, 160px);
    --gap: 8px;
    --pill-h: 36px;
    --pill-font: 17px;
    --hud-btn: 40px;
    --tile-icon: 40px;
    --go-h: 52px;
  }
  .xp-row { margin-bottom: 10px; }
  .xp-row span svg { width: 22px; height: 22px; }
  .pill { padding: 0 11px 0 7px; gap: 5px; }
  .round-badge { padding: 0 12px 0 14px; }
  .shop { gap: 6px; padding: 3px 3px 5px; }
  .tile { border-radius: 11px; border-width: 2.5px; }
  .go-btn { border-radius: 15px; }
  .go-btn .go-sub { display: none; }
  .pb-icon { width: 34px; height: 34px; }
  .pb-btn { width: 42px; height: 42px; }
  .pb-text b { font-size: 14px; }
  .pb-text small { font-size: 12px; }
  .toast { font-size: 14px; padding: 6px 14px 6px 10px; }
  .banner { padding: 7px 12px 9px; }
  .banner b { font-size: 30px; }
  .banner small { font-size: 11px; }
  .banner em { font-size: 12px; padding: 2px 10px; }

  .quest { padding: 5px 8px; gap: 8px; grid-template-columns: 34px minmax(0, 1fr) auto; }
  .quest-ico { width: 34px; height: 34px; border-radius: 10px; }
  .quest b { font-size: 14px; }
  .quest small { font-size: 11.5px; }
  .qa-group { margin-bottom: 8px; }
  .award { padding: 6px 8px; grid-template-columns: 36px minmax(0, 1fr); }
  .award .medal { width: 36px; height: 36px; }
  .awards { gap: 6px; margin-bottom: 10px; }
  .qa-group > h3 { margin-bottom: 4px; }
  .qa-list { gap: 5px; }

  .sheet, .overlay > .card { padding: 14px 16px; border-radius: 18px; }
  .sheet .title { font-size: 26px; }
  .sheet .lede { font-size: 14px; margin-bottom: 10px; }
  .sbtn { height: 44px; font-size: 16px; }
  .sbtn.big { height: 48px; font-size: 18px; }
  .stat-row { margin-bottom: 10px; }
  .stat-row div { padding: 4px 10px; }
  .stat-row dd { font-size: 18px; }
  .settings { gap: 6px; margin: 4px 0 10px; }
  .setting-row { min-height: 46px; padding: 6px 12px; }
  .steps { gap: 8px; margin-bottom: 10px; }
  .steps li { padding: 8px 10px; }
  .steps .step-ico { width: 34px; height: 34px; }
  .keys { display: none; }
  .steps span { font-size: 12.5px; }
  .result-badge { width: 52px; height: 52px; margin-bottom: 2px; }
  .trails { grid-auto-columns: minmax(158px, 1fr); gap: 9px; padding-bottom: 6px; }
  .trail-art { aspect-ratio: 2 / 1; }
  .trail-body { gap: 3px; padding: 6px 10px 9px; }
  .trail-body > b { font-size: 15px; }
  .trail-tag { font-size: 11.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .trail-feats { display: none; }
  .coop-art span { width: 44px; height: 44px; }
}
@media (max-height: 400px) { .tower-panel { padding-bottom: 0; } }
@media (max-height: 380px) {
  :root { --tile-icon: 36px; --go-h: 46px; --pill-h: 34px; }
}
/* Narrow windows (desktop, tablets in split view). */
@media (max-width: 600px) {
  .steps, .settings { grid-template-columns: 1fr; }
}
@media (max-width: 760px) and (min-height: 561px) {
  :root { --rail-w: 176px; }
}

/* ---- v1.0: account, market, events ------------------------------------ */

/* Menu: online dot and flash messages. */
.menu-online { flex: none; display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.7); pointer-events: none; }
.menu-online i { width: 8px; height: 8px; border-radius: 50%; background: #e2a52c; }
.menu-online.on i { background: #58bf3c; box-shadow: 0 0 8px #58bf3c; }
.menu-flash {
  position: absolute; z-index: 40; left: 50%; top: calc(14px + var(--safe-t)); max-width: min(520px, calc(100% - 24px)); transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  padding: 8px 16px; border-radius: 16px; font-weight: 700; font-size: 15px; color: #fff; background: rgba(38,100,27,.97); border: 2px solid rgba(255,255,255,.22);
  box-shadow: 0 3px 0 rgba(0,0,0,.22), 0 10px 24px rgba(0,0,0,.3); transition: opacity .15s, transform .25s var(--spring);
}
.menu-flash.show { opacity: 1; transform: translate(-50%, 0); }
.menu-flash.bad { background: rgba(160,48,28,.97); }

/* Trail picker: locked trails. */
.trail.locked { filter: saturate(.3) brightness(.8); }
.trail.locked .trail-best svg { width: 14px; height: 14px; }

/* HUD: mode label, powers button, send-next. */
.round-badge small { max-width: 24vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-btn.powers { color: #f2c14e; }
.hud-btn.powers .mi { width: calc(var(--hud-btn) * .52); height: calc(var(--hud-btn) * .52); display: grid; }
.hud-btn.powers .mi svg { width: 100%; height: 100%; }
.hud-btn.powers em { position: absolute; right: -4px; top: -4px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px; font-style: normal; font-size: 11px; font-weight: 700;
  line-height: 18px; text-align: center; color: #fff; background: #c8402a; box-shadow: 0 0 0 2px var(--glass-strong); }
.hud-btn.powers em:empty { display: none; }
.next-btn {
  height: 40px; border: 0; border-radius: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 700;
  color: #3a2a08; background: linear-gradient(#ffe08a, #e9b43e); box-shadow: 0 3px 0 #9a6c12; animation: up-in .25s var(--spring);
}
.next-btn svg { width: 18px; height: 18px; }
.next-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #9a6c12; }
@keyframes up-in { from { transform: scale(.8); opacity: 0; } }

/* Shop: level-locked tiles. */
.tile.locked .tile-icon { filter: grayscale(1) brightness(.7); opacity: .55; }
.tile.locked .tile-name { opacity: .6; }
.tile.locked .tile-cost { color: var(--text-soft); font-size: 12.5px; font-size: clamp(10px, 13cqw, 17px); }
.tile.locked .tile-cost svg { color: inherit; width: .9em; height: .9em; transform: none; }

/* The animal details bubble beside the rail (hover / press and hold). */
.tile-tip {
  position: absolute; z-index: 8; right: 8px; width: 248px; max-width: 46%; pointer-events: none; text-align: left;
  background: var(--sheet); color: var(--sheet-text); border-radius: 14px; border: 3px solid var(--sheet-edge); padding: 8px 10px 9px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25), 0 14px 30px rgba(0,0,0,.4);
}
.tile-tip.in { animation: tip-in .16s ease-out; }
@keyframes tip-in { from { opacity: 0; transform: translateX(8px); } }
.tile-tip::after { content: ''; position: absolute; right: -11px; top: var(--ay, 24px); margin-top: -7px; border: 7px solid transparent; border-left-color: var(--sheet-edge); }
.tt-head { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 7px; align-items: center; }
.tt-ico svg { width: 34px; height: 34px; }
.tt-head b { display: block; font-size: 15px; line-height: 1.1; }
.tt-head small { font-size: 11px; color: var(--sheet-soft); }
.tt-head small i { font-style: normal; font-weight: 700; }
.tt-price { display: inline-flex; align-items: center; gap: 2px; font-weight: 700; font-size: 14px; }
.tt-price svg { width: 13px; height: 13px; color: var(--seed); }
.tt-role { margin: 5px 0 5px; font-size: 12px; line-height: 1.3; color: var(--sheet-soft); }
.tt-role b { color: var(--sheet-text); }
.tt-facts, .pb-info { display: flex; flex-wrap: wrap; gap: 3px; }
.tt-facts i, .pb-info i { font-style: normal; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--tag); color: var(--tag-text); white-space: nowrap; }
.tt-facts i.g, .pb-info i.g { background: var(--tag-good); color: var(--tag-good-text); }
.tt-facts i.b, .pb-info i.b { background: rgba(200,64,42,.18); color: var(--bad-text); }
.tt-lock, .tt-note { margin: 6px 0 0; font-size: 11.5px; line-height: 1.3; color: var(--sheet-soft); }
.tt-lock { color: var(--accent); font-weight: 700; }
.tt-lock svg { width: 12px; height: 12px; vertical-align: -1px; margin-right: 3px; }

/* Placement bar: what the animal does, in plain facts. */
.place-bar { border-radius: 20px; align-items: center; }
.pb-text b { display: flex; align-items: center; gap: 6px; }
.pb-price { display: inline-flex; align-items: center; gap: 2px; color: var(--gold-text); }
.pb-price svg { width: 13px; height: 13px; color: var(--seed); }
.pb-role { font-size: 12px; font-weight: 700; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; }
.pb-insta { font-style: normal; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; color: #3a2a08; background: linear-gradient(#ffe08a, #e9b43e); }
.pb-info { margin: 2px 0 1px; max-width: min(420px, 60vw); }
.pb-info:empty { display: none; }

/* Level up ribbon (in a match). */
.lvup {
  position: absolute; z-index: 6; left: 50%; top: calc(var(--gap) * 2 + var(--pill-h) + var(--safe-t) + 40px); transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: min(560px, calc(100% - 24px)); padding: 6px 14px 6px 6px; border-radius: 999px;
  color: #3a2a08; background: linear-gradient(#fff3c8, #f6d77c); border: 2px solid #fff6d6; box-shadow: 0 3px 0 #b8862a, 0 10px 24px rgba(0,0,0,.3);
}
.lvup.show { animation: lvup 3.4s var(--ease-out) both; }
@keyframes lvup { 0% { opacity: 0; transform: translate(-50%, -12px) scale(.8); } 8% { opacity: 1; transform: translate(-50%, 0) scale(1.05); } 14% { transform: translate(-50%, 0) scale(1); } 88% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; transform: translate(-50%, -8px); } }
.lvup > b { display: grid; place-items: center; min-width: 48px; height: 48px; padding: 0 6px; border-radius: 50%; font-size: 22px; line-height: 1; color: #fff;
  background: radial-gradient(circle at 50% 30%, #ffe28a, #e2a52c 65%, #9a6c12); text-shadow: 0 2px 0 #7a4a08; }
.lvup > b small { font-size: 8px; letter-spacing: 1px; text-transform: uppercase; text-shadow: none; }
.lvup span { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; font-size: 14px; }
.lvup span svg { width: 20px; height: 20px; }
.lvup span.new { padding: 2px 10px 2px 3px; border-radius: 999px; background: rgba(255,255,255,.6); }
.lvup span.new svg { width: 26px; height: 26px; }

/* Results: rewards and level. */
.reward-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: -6px 0 10px; }
.reward-row .rw { display: inline-flex; align-items: center; gap: 4px; padding: 3px 12px 3px 6px; border-radius: 999px; font-size: 14px; font-weight: 700; background: var(--sheet-2); box-shadow: 0 2px 0 var(--sheet-drop); }
.reward-row .rw svg { width: 20px; height: 20px; }
.reward-row .rw i { font-style: normal; font-size: 10.5px; padding: 1px 6px; margin-left: 2px; border-radius: 999px; color: #fff; background: #d4643a; }
.reward-row .rw.ac { color: #3a2a08; background: linear-gradient(#ffe08a, #e9b43e); box-shadow: 0 2px 0 #9a6c12; }
.reward-row .rw.medal.new { color: #fff; background: linear-gradient(var(--go-a), var(--go-b)); box-shadow: 0 2px 0 var(--go-deep); animation: badge-in .7s var(--spring) .3s both; }
.reward-row .rw.lv { color: #fff; background: linear-gradient(#a98be0, #6a4ac0); box-shadow: 0 2px 0 #3a2470; }
.reward-row .rw.xp svg { color: var(--gold); }
.res-level { display: flex; align-items: center; gap: 8px; max-width: 360px; margin: 0 auto 12px; }
.res-level b { flex: none; font-size: 14px; }
.res-level .m-lvbar { flex: 1; height: 18px; }
.res-level .m-lvbar em { line-height: 18px; font-size: 11.5px; color: #fff; }
.actions .continue .acorn-cost { display: inline-flex; align-items: center; gap: 2px; }
.actions .continue .acorn-cost svg { width: 20px; height: 20px; }

/* Settings: more actions, backup codes. */
.settings-more { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; margin: 0 0 12px; }
.settings-more .sbtn { height: 44px; font-size: 14.5px; }
.backup-code { width: 100%; margin: 0 0 12px; padding: 10px; border-radius: 12px; border: 2px solid var(--sheet-3); background: var(--sheet-2); color: var(--sheet-text);
  font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace; word-break: break-all; resize: vertical; }
.backup-status { margin: 8px 0 0; font-weight: 700; color: var(--good-text); min-height: 1em; }

@media (max-height: 560px) {
  .next-btn { height: 34px; font-size: 12.5px; }
  .tile-tip { width: 220px; padding: 6px 8px 7px; }
  .tt-role { font-size: 11.5px; }
  .pb-info i { font-size: 10.5px; padding: 0 6px; }
  .pb-role { display: none; }
  .lvup { top: calc(var(--gap) * 2 + var(--pill-h) + var(--safe-t) + 30px); padding: 4px 12px 4px 4px; }
  .lvup > b { min-width: 40px; height: 40px; font-size: 18px; }
  .lvup span { font-size: 12.5px; }
  .reward-row { margin: -4px 0 8px; }
  .reward-row .rw { font-size: 12.5px; }
  .res-level { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .tp-info { animation: ti-fade .12s ease-out !important; }
}
@keyframes ti-fade { from { opacity: 0; } }
