/* ==========================================================================
   Heartwood — low-poly tower defense
   Warm parchment HUD over a sunlit floating diorama.
   ========================================================================== */

:root {
  --ink: #22352c;
  --ink-soft: #50625a;
  --ink-faint: #75857b;
  --cream: #f6efdf;
  --cream-strong: #fff9ec;
  --cream-deep: #e9dfc8;
  --panel: rgba(250, 245, 233, 0.94);
  --panel-solid: #faf5e9;
  --panel-edge: rgba(74, 91, 70, 0.22);
  --gold: #d7a240;
  --gold-deep: #a97522;
  --gold-soft: #f1d69a;
  --teal: #2f6f60;
  --teal-bright: #3d8d79;
  --teal-soft: #dcebe2;
  --danger: #b9513c;
  --danger-soft: #f4d8ce;
  --arcane: #7163c7;
  --frost: #6ea9c7;
  --shadow-lg: 0 26px 60px -24px rgba(19, 38, 31, 0.55), 0 2px 0 rgba(255, 255, 255, 0.62) inset;
  --shadow-md: 0 14px 30px -18px rgba(19, 38, 31, 0.5), 0 1px 0 rgba(255, 255, 255, 0.5) inset;
  --shadow-sm: 0 6px 14px -8px rgba(19, 38, 31, 0.5), 0 1px 0 rgba(255, 255, 255, 0.45) inset;
  --display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --hud-ink: #f7f2e4;
  --screen-scrim: rgba(10, 25, 21, 0.46);
  --focus: #f0c264;
}

:root[data-theme="dark"] {
  --ink: #f1ebdb;
  --ink-soft: #c0cabb;
  --ink-faint: #93a094;
  --cream: #25322d;
  --cream-strong: #2d3c35;
  --cream-deep: #1d2924;
  --panel: rgba(30, 43, 37, 0.94);
  --panel-solid: #1e2c27;
  --panel-edge: rgba(226, 209, 167, 0.2);
  --gold: #e2b25a;
  --gold-deep: #c18c34;
  --gold-soft: #6d5423;
  --teal: #4b9b86;
  --teal-bright: #5cb49b;
  --teal-soft: #263e36;
  --danger: #e08770;
  --danger-soft: #4a2d28;
  --frost: #8cc6df;
  --shadow-lg: 0 28px 60px -24px rgba(0, 0, 0, 0.75), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
  --shadow-md: 0 16px 32px -18px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  --shadow-sm: 0 8px 16px -10px rgba(0, 0, 0, 0.6), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  --screen-scrim: rgba(4, 12, 10, 0.62);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: #b9dce8;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; color: inherit; }

button { -webkit-tap-highlight-color: transparent; }

::selection { background: var(--gold-soft); color: var(--ink); }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(100% 70% at 80% 0%, rgba(255, 245, 205, 0.85) 0%, rgba(255, 245, 205, 0) 52%),
    linear-gradient(178deg, #a9d5e6 0%, #c8e5ea 36%, #efe6cc 78%, #f6e7c7 100%);
}
:root[data-theme="dark"] .app {
  background:
    radial-gradient(90% 65% at 78% 0%, rgba(210, 222, 172, 0.26) 0%, rgba(210, 222, 172, 0) 55%),
    linear-gradient(178deg, #0f2029 0%, #172d32 42%, #2a3930 76%, #3a4130 100%);
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 1;
  touch-action: none;
  cursor: grab;
}
#scene.is-dragging { cursor: grabbing; }

.sky-glow {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background:
    radial-gradient(42% 30% at 76% 8%, rgba(255, 245, 202, 0.55), transparent 70%),
    radial-gradient(120% 90% at 50% 42%, transparent 55%, rgba(15, 37, 31, 0.22) 100%);
  mix-blend-mode: soft-light;
}
:root[data-theme="dark"] .sky-glow {
  background:
    radial-gradient(40% 28% at 76% 8%, rgba(244, 226, 177, 0.18), transparent 70%),
    radial-gradient(120% 90% at 50% 42%, transparent 48%, rgba(0, 0, 0, 0.38) 100%);
}
.sky-grain {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.55'/%3E%3C/svg%3E");
}

/* ------------------------------------------------------------------ HUD */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px 40px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(16, 34, 28, 0.2), rgba(16, 34, 28, 0));
}
.hud > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 5px;
  color: var(--hud-ink);
  filter: drop-shadow(0 2px 8px rgba(10, 25, 20, 0.45));
}
.brand__mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #f3e5bd;
  background: linear-gradient(160deg, rgba(38, 79, 65, 0.92), rgba(24, 54, 45, 0.92));
  border: 1px solid rgba(240, 214, 154, 0.45);
  box-shadow: 0 6px 18px -8px rgba(8, 24, 18, 0.8);
}
.brand__text { display: flex; flex-direction: column; line-height: 1.02; }
.brand__name {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.01em;
}
.brand__sub {
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  opacity: 0.72;
  margin-top: 4px;
}

.ledger {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 9px 18px 10px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(10px) saturate(1.04);
  -webkit-backdrop-filter: blur(10px) saturate(1.04);
  margin-top: 0;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 16px;
}
.stat { display: flex; align-items: center; gap: 9px; min-width: 82px; }
.stat__icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  color: var(--ink-soft);
  background: rgba(84, 104, 86, 0.1);
}
.stat__icon--gold { color: var(--gold-deep); background: rgba(215, 162, 64, 0.16); }
.stat__icon--lives { color: var(--danger); background: rgba(185, 81, 60, 0.14); }
.stat--wave .stat__icon { color: var(--teal); background: rgba(47, 111, 96, 0.13); }
.stat__copy { display: flex; flex-direction: column; line-height: 1; }
.stat__label {
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 3px;
}
.stat__value {
  font-family: var(--display);
  font-size: 25px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1;
  white-space: nowrap;
}
.stat__value small { font-size: 14px; color: var(--ink-faint); font-weight: 500; }
.stat__value.is-bump { animation: bump 0.42s ease; }
.ledger__rule { width: 1px; height: 28px; background: var(--panel-edge); }

.hud__controls { display: flex; align-items: center; gap: 9px; }
.speed {
  display: flex;
  padding: 3px;
  gap: 2px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow-sm);
}
.speed__btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 9px;
  padding: 6px 11px;
  min-width: 40px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}
.speed__btn:hover { background: rgba(47, 111, 96, 0.1); color: var(--ink); }
.speed__btn[aria-pressed="true"] {
  background: linear-gradient(180deg, var(--teal-bright), var(--teal));
  color: #fdf8ea;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 3px 8px -4px rgba(26, 63, 52, 0.7);
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.16s ease, background 0.16s ease, opacity 0.16s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.btn--quiet {
  background: var(--panel);
  border-color: var(--panel-edge);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.btn--quiet:hover { background: var(--cream-strong); transform: translateY(-1px); }
.btn--quiet[aria-pressed="true"] { color: var(--gold-deep); border-color: rgba(215, 162, 64, 0.5); }
.pause-btn { padding: 9px 13px; gap: 6px; }
.pause-btn svg { opacity: 0.8; }

.btn--primary {
  color: #fff8e8;
  background: linear-gradient(180deg, #4a9b84 0%, #347c69 52%, #2b6c5b 100%);
  border-color: #245b4c;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 -2px 0 rgba(15, 45, 36, 0.32) inset, 0 12px 24px -14px rgba(18, 58, 47, 0.85);
}
.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.32) inset, 0 -2px 0 rgba(15, 45, 36, 0.32) inset, 0 18px 30px -16px rgba(18, 58, 47, 0.9); }
.btn--primary:active { transform: translateY(1px); }
.btn--wave {
  width: 100%;
  margin-top: 10px;
  justify-content: space-between;
  padding: 12px 14px;
  color: #32260f;
  background: linear-gradient(180deg, #f4ce7e 0%, #e3b257 55%, #ce9839 100%);
  border-color: #b07d26;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.55) inset, 0 -2px 0 rgba(126, 84, 18, 0.32) inset, 0 12px 22px -14px rgba(95, 63, 12, 0.8);
}
.btn--wave:hover:not(:disabled) { transform: translateY(-1px); }
.btn--wave:disabled { opacity: 0.58; cursor: not-allowed; transform: none; }
.btn--wave kbd {
  background: rgba(255, 251, 235, 0.5);
  border-color: rgba(87, 60, 14, 0.26);
  color: rgba(57, 41, 12, 0.78);
  box-shadow: none;
}
.btn--lg { padding: 15px 22px; font-size: 15px; border-radius: 14px; }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 3px 7px;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.03em;
  line-height: 1.2;
  color: var(--ink-soft);
  background: rgba(255, 253, 246, 0.72);
  border: 1px solid rgba(64, 83, 70, 0.2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 1px 2px rgba(20, 40, 32, 0.12);
}
:root[data-theme="dark"] kbd {
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

/* ----------------------------------------------------------- wave card */

.wave-card {
  position: absolute;
  top: 88px;
  right: 22px;
  z-index: 26;
  width: 286px;
  padding: 15px 16px 14px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px) saturate(1.04);
  -webkit-backdrop-filter: blur(12px) saturate(1.04);
}
.wave-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--panel-edge);
}
.eyebrow {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.eyebrow--gold { color: var(--gold-deep); }
.wave-card__num {
  font-family: var(--display);
  font-size: 14px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.wave-comp {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 11px 0 4px;
  min-height: 30px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px 5px 7px;
  border-radius: 999px;
  background: rgba(84, 104, 86, 0.08);
  border: 1px solid rgba(84, 104, 86, 0.12);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chip__dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.06) inset; }
.chip--runner .chip__dot { background: #e28455; }
.chip--soldier .chip__dot { background: #6e95b4; }
.chip--brute .chip__dot { background: #a06a86; }
.chip--boss .chip__dot { background: #d9a441; }
.chip b { color: var(--ink); font-weight: 750; }
.chip--elite { border-color: rgba(160, 106, 134, 0.3); }
.wave-comp--note { font-size: 11px; color: var(--ink-faint); padding-top: 6px; width: 100%; }
.live-line { display: flex; align-items: baseline; gap: 7px; width: 100%; }
.live-line strong { font-family: var(--display); font-size: 27px; color: var(--ink); font-variant-numeric: tabular-nums; }
.live-line span { font-size: 11px; color: var(--ink-faint); letter-spacing: 0.08em; text-transform: uppercase; }
.wave-progress { width: 100%; height: 4px; border-radius: 4px; background: rgba(84, 104, 86, 0.14); overflow: hidden; margin-top: 2px; }
.wave-progress > i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal), var(--gold)); border-radius: 4px; transition: width 0.2s linear; }

/* -------------------------------------------------------------- boss bar */

.boss {
  position: absolute;
  top: 92px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  width: min(440px, 40vw);
  padding: 11px 16px 13px;
  border-radius: 14px;
  color: #f7edd8;
  background: linear-gradient(180deg, rgba(39, 27, 38, 0.94), rgba(25, 18, 27, 0.94));
  border: 1px solid rgba(215, 162, 64, 0.4);
  box-shadow: 0 16px 36px -18px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
  backdrop-filter: blur(10px);
}
.boss__top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.boss__name { font-family: var(--display); font-size: 16px; letter-spacing: 0.02em; }
.boss__tag { font-size: 9px; letter-spacing: 0.06em; color: rgba(247, 237, 216, 0.62); text-align: right; }
.boss__track { height: 9px; border-radius: 6px; background: rgba(255, 255, 255, 0.11); overflow: hidden; }
.boss__fill { height: 100%; width: 100%; border-radius: 6px; background: linear-gradient(90deg, #d96a4d, #e2a94d); transition: width 0.15s linear; }

/* --------------------------------------------------------------- palette */

.palette {
  position: absolute;
  left: 22px;
  bottom: 20px;
  z-index: 24;
  width: 530px;
  max-width: calc(100vw - 380px);
}
.palette__head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px 7px; }
.palette__head .eyebrow { color: var(--hud-ink); opacity: 0.78; text-shadow: 0 1px 6px rgba(8, 22, 17, 0.6); }
.palette__hint { font-size: 10px; color: var(--hud-ink); opacity: 0.62; text-shadow: 0 1px 6px rgba(8, 22, 17, 0.6); }
.palette__cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.tower-card {
  position: relative;
  appearance: none;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 9px;
  row-gap: 2px;
  text-align: left;
  padding: 11px 12px 10px;
  border-radius: 15px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink);
}
.tower-card:hover { transform: translateY(-2px); border-color: rgba(215, 162, 64, 0.5); }
.tower-card:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.tower-card[aria-pressed="true"] {
  border-color: var(--gold);
  background: linear-gradient(180deg, var(--panel), rgba(247, 226, 173, 0.5));
  box-shadow: 0 0 0 2px rgba(215, 162, 64, 0.28), var(--shadow-sm);
}
:root[data-theme="dark"] .tower-card[aria-pressed="true"] { background: linear-gradient(180deg, var(--panel), rgba(109, 84, 35, 0.5)); }
.tower-card.is-poor { opacity: 0.62; }
.tower-card.is-poor .tower-card__cost { color: var(--danger); }
.tower-card__icon {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid rgba(47, 111, 96, 0.16);
}
.tower-card__icon--arrow { color: #3d7a5f; background: rgba(88, 148, 112, 0.16); }
.tower-card__icon--cannon { color: #a4693a; background: rgba(184, 122, 70, 0.17); }
.tower-card__icon--frost { color: #4a86a4; background: rgba(110, 169, 199, 0.19); }
.tower-card__body { display: flex; flex-direction: column; min-width: 0; }
.tower-card__name { font-family: var(--display); font-size: 16px; font-weight: 600; line-height: 1.05; }
.tower-card__role { font-size: 9.5px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tower-card__cost {
  grid-column: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 750;
  color: var(--gold-deep);
  font-variant-numeric: tabular-nums;
}
.coin-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 1px rgba(121, 84, 24, 0.4);
}
.tower-card__key {
  position: absolute;
  top: 7px;
  right: 8px;
  opacity: 0.5;
  min-width: 16px;
  padding: 1px 4px;
  font-size: 8.5px;
  box-shadow: none;
  background: transparent;
  border-color: rgba(64, 83, 70, 0.16);
}
:root[data-theme="dark"] .tower-card__key { border-color: rgba(255, 255, 255, 0.14); }

/* ------------------------------------------------------------- inspector */

.inspector {
  position: absolute;
  right: 22px;
  bottom: 20px;
  z-index: 24;
  width: 300px;
  padding: 14px 15px 15px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px) saturate(1.04);
  -webkit-backdrop-filter: blur(12px) saturate(1.04);
}
.inspector[hidden] { display: none; }
.inspector__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.inspector__title { font-family: var(--display); font-size: 19px; line-height: 1.08; margin: 2px 0 0; letter-spacing: -0.01em; }
.inspector__sub { font-size: 10px; color: var(--ink-faint); margin-top: 3px; letter-spacing: 0.03em; }
.inspector__close {
  appearance: none;
  border: 1px solid var(--panel-edge);
  background: transparent;
  color: var(--ink-faint);
  width: 24px; height: 24px;
  border-radius: 8px;
  display: grid; place-items: center;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  flex: none;
}
.inspector__close:hover { color: var(--ink); background: rgba(84, 104, 86, 0.08); }
.inspector__close:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.build-list { display: flex; flex-direction: column; gap: 6px; margin-top: 11px; }
.build-option {
  appearance: none;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  border-radius: 11px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 253, 246, 0.55);
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.14s ease;
  color: var(--ink);
}
:root[data-theme="dark"] .build-option { background: rgba(255, 255, 255, 0.035); }
.build-option:hover:not(:disabled) { border-color: var(--gold); transform: translateX(1px); }
.build-option:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.build-option:disabled { opacity: 0.45; cursor: not-allowed; }
.build-option__icon {
  width: 30px; height: 30px; border-radius: 9px;
  display: grid; place-items: center;
  font-family: var(--display); font-size: 14px; font-weight: 700;
}
.build-option__icon--arrow { background: rgba(88, 148, 112, 0.18); color: #3d7a5f; }
.build-option__icon--cannon { background: rgba(184, 122, 70, 0.19); color: #9c6134; }
.build-option__icon--frost { background: rgba(110, 169, 199, 0.2); color: #3f7d9b; }
.build-option__name { display: block; font-size: 12.5px; font-weight: 700; }
.build-option__role { display: block; font-size: 9.5px; color: var(--ink-faint); margin-top: 1px; }
.build-option__cost {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 750; color: var(--gold-deep);
  font-variant-numeric: tabular-nums;
}
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 12px; margin-top: 10px; }
.stat-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; font-size: 10.5px; }
.stat-row span { color: var(--ink-faint); }
.stat-row b { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-row--wide { grid-column: 1 / -1; }
.tier-pips { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.tier-pips i { width: 5px; height: 5px; border-radius: 50%; background: rgba(84, 104, 86, 0.2); }
.tier-pips i.on { background: var(--gold); }
.next-tier {
  margin-top: 9px;
  padding: 8px 9px;
  border-radius: 9px;
  background: rgba(47, 111, 96, 0.07);
  border: 1px dashed rgba(47, 111, 96, 0.24);
  font-size: 10px;
  color: var(--ink-soft);
  line-height: 1.4;
}
.next-tier b { color: var(--ink); }
.action-row { display: flex; gap: 6px; margin-top: 10px; }
.action-row .btn { flex: 1; padding: 9px 8px; font-size: 11.5px; }
.btn--sell { background: transparent; border-color: rgba(185, 81, 60, 0.32); color: var(--danger); box-shadow: none; }
.btn--sell:hover:not(:disabled) { background: var(--danger-soft); }
.btn--upgrade {
  color: #3a2b10;
  background: linear-gradient(180deg, #f1cd82, #dfae52);
  border-color: #bb8630;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset;
}
.btn--upgrade:hover:not(:disabled) { transform: translateY(-1px); }
.btn--upgrade:disabled, .btn--sell:disabled { opacity: 0.45; cursor: not-allowed; }
.inspector__hint { font-size: 11px; line-height: 1.5; color: var(--ink-soft); margin: 9px 0 0; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; margin-top: 9px; }
.legend__row { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--ink-soft); }
.legend__dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.legend__dot--runner { background: #e28455; }
.legend__dot--soldier { background: #6e95b4; }
.legend__dot--brute { background: #a06a86; }
.legend__dot--boss { background: #d9a441; }
.inspector__foot { margin-top: 9px; font-size: 9.5px; color: var(--ink-faint); border-top: 1px solid var(--panel-edge); padding-top: 7px; display: flex; justify-content: space-between; }

/* -------------------------------------------------------------- tile layer */

.tile-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}
.tile-hit {
  position: absolute;
  left: 0; top: 0;
  width: 88px; height: 58px;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 14px;
  cursor: pointer;
  color: transparent;
  font-size: 0;
  padding: 0;
  transition: border-color 0.14s ease, background 0.14s ease;
}
.tile-hit:hover { border-color: rgba(255, 246, 213, 0.28); background: rgba(255, 246, 213, 0.05); }
.tile-hit:focus-visible {
  outline: none;
  border: 2px dashed var(--focus);
  background: rgba(255, 240, 194, 0.08);
  box-shadow: 0 0 0 4px rgba(240, 194, 100, 0.16);
}
.tile-hit.is-under-hud { pointer-events: none; }

/* --------------------------------------------------------------- tooltip */

.tooltip {
  position: absolute;
  z-index: 40;
  max-width: 220px;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(24, 37, 31, 0.94);
  color: #f8f0df;
  font-size: 11px;
  line-height: 1.35;
  box-shadow: 0 10px 22px -12px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 10px));
}
.tooltip b { font-weight: 700; }
.tooltip span { opacity: 0.7; }

/* ---------------------------------------------------------------- toasts */

.toast-stack {
  position: absolute;
  left: 50%;
  bottom: 172px;
  transform: translateX(-50%);
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  width: max-content;
  max-width: min(520px, 88vw);
}
.toast {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(25, 39, 33, 0.93);
  color: #f8f1e1;
  border: 1px solid rgba(240, 214, 154, 0.22);
  font-size: 11.5px;
  font-weight: 550;
  letter-spacing: 0.01em;
  box-shadow: 0 12px 26px -14px rgba(0, 0, 0, 0.6);
  animation: toast-in 0.22s ease both;
}
.toast--warn { border-color: rgba(231, 152, 120, 0.5); }
.toast--good { border-color: rgba(126, 195, 158, 0.45); }
.toast.is-out { animation: toast-out 0.25s ease both; }

.pop-layer { position: absolute; inset: 0; z-index: 18; pointer-events: none; overflow: hidden; }
.gold-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  color: #ffe6a6;
  text-shadow: 0 0 2px rgba(80, 50, 8, 0.6), 0 2px 10px rgba(70, 42, 4, 0.5);
  animation: gold-rise 1.15s cubic-bezier(0.2, 0.75, 0.25, 1) both;
  white-space: nowrap;
}
.gold-pop small { font-family: var(--sans); font-size: 10px; font-weight: 600; color: #f6dfae; opacity: 0.9; margin-left: 2px; }

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

.screen {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 28px;
}
.screen[hidden] { display: none; }

.screen--start {
  background:
    linear-gradient(90deg, rgba(9, 26, 21, 0.77) 0%, rgba(9, 26, 21, 0.56) 38%, rgba(9, 26, 21, 0.1) 72%, rgba(9, 26, 21, 0.02) 100%),
    radial-gradient(100% 90% at 10% 100%, rgba(7, 23, 18, 0.4), transparent 58%);
  justify-content: flex-start;
  padding-left: clamp(26px, 5.5vw, 92px);
  padding-right: clamp(26px, 5vw, 60px);
  backdrop-filter: blur(1.5px);
  -webkit-backdrop-filter: blur(1.5px);
  animation: screen-in 0.5s ease both;
}
.start-inner { width: 100%; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.start-card {
  width: min(640px, 100%);
  padding: clamp(24px, 3.4vw, 40px) clamp(24px, 3.6vw, 42px) clamp(22px, 2.6vw, 30px);
  border-radius: 26px;
  background: linear-gradient(165deg, rgba(250, 246, 235, 0.97), rgba(245, 237, 219, 0.94));
  border: 1px solid rgba(255, 255, 255, 0.62);
  box-shadow: 0 40px 90px -40px rgba(2, 15, 11, 0.8), 0 2px 0 rgba(255, 255, 255, 0.7) inset;
  position: relative;
  overflow: hidden;
}
.start-card::after {
  content: "";
  position: absolute;
  right: -120px; top: -140px;
  width: 260px; height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(215, 162, 64, 0.18), transparent 68%);
  pointer-events: none;
}
:root[data-theme="dark"] .start-card {
  background: linear-gradient(165deg, rgba(32, 46, 39, 0.97), rgba(25, 37, 32, 0.95));
  border-color: rgba(226, 209, 167, 0.16);
  box-shadow: 0 40px 90px -40px rgba(0, 0, 0, 0.9), 0 2px 0 rgba(255, 255, 255, 0.05) inset;
}
.title {
  font-family: var(--display);
  font-size: clamp(58px, 7.2vw, 92px);
  line-height: 0.86;
  letter-spacing: -0.045em;
  margin: 10px 0 16px;
  color: var(--ink);
  font-weight: 600;
}
.title span { color: var(--gold-deep); font-style: italic; }
.lede {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 46ch;
  margin: 0 0 16px;
}
.goal {
  margin: 0 0 18px;
  padding: 10px 0 10px 15px;
  border-left: 3px solid var(--gold);
  font-family: var(--display);
  font-size: clamp(19px, 2vw, 23px);
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 18px;
  padding: 14px 0 4px;
  border-top: 1px solid var(--panel-edge);
  margin-bottom: 18px;
}
.controls__item { display: flex; align-items: center; gap: 8px; min-width: 0; }
.controls__item > span:last-child { font-size: 10.5px; color: var(--ink-soft); line-height: 1.3; }
.keys { display: inline-flex; gap: 3px; flex: none; }
.keys kbd { font-size: 9px; min-width: 20px; padding: 3px 5px; }
.start-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.best {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 12px;
  border-radius: 11px;
  background: rgba(47, 111, 96, 0.08);
  border: 1px solid rgba(47, 111, 96, 0.16);
  min-width: 126px;
}
.best__label { font-size: 8.5px; letter-spacing: 0.17em; text-transform: uppercase; color: var(--ink-faint); }
.best strong { font-family: var(--display); font-size: 16px; font-weight: 600; color: var(--ink); }
.start-note { margin: 14px 0 0; font-size: 9.5px; color: var(--ink-faint); letter-spacing: 0.03em; }
.start-credit {
  margin: 0 0 4px 4px;
  color: rgba(246, 240, 224, 0.72);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-shadow: 0 1px 8px rgba(6, 20, 15, 0.5);
}

.screen--pause, .screen--end {
  background: radial-gradient(80% 60% at 50% 45%, rgba(10, 27, 22, 0.44), rgba(6, 18, 14, 0.7));
  backdrop-filter: blur(4px) saturate(0.85);
  -webkit-backdrop-filter: blur(4px) saturate(0.85);
  animation: screen-in 0.25s ease both;
}
.pause-card, .end-card {
  width: min(560px, 100%);
  padding: 30px 32px 28px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow-lg);
  text-align: left;
}
.pause-title, .end-title {
  font-family: var(--display);
  font-size: clamp(38px, 5vw, 54px);
  line-height: 0.95;
  margin: 8px 0 12px;
  letter-spacing: -0.035em;
  color: var(--ink);
}
.pause-copy, .end-copy { font-size: 13px; line-height: 1.55; color: var(--ink-soft); margin: 0 0 20px; max-width: 48ch; }
.pause-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.pause-hint { font-size: 10px; color: var(--ink-faint); display: inline-flex; align-items: center; gap: 5px; }
.end-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 4px 0 22px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel-edge);
  border: 1px solid var(--panel-edge);
}
.end-stat { background: var(--panel-solid); padding: 11px 13px 12px; display: flex; flex-direction: column; gap: 5px; }
.end-stat__label { font-size: 8.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint); }
.end-stat strong { font-family: var(--display); font-size: 23px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1; }
.end-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.end-card[data-outcome="victory"] .eyebrow { color: var(--gold-deep); }
.end-card[data-outcome="defeat"] .eyebrow { color: var(--danger); }

.fatal {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: rgba(9, 26, 21, 0.72);
  padding: 24px;
}
.fatal[hidden] { display: none; }
.fatal__card {
  max-width: 420px;
  padding: 26px 28px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  box-shadow: var(--shadow-lg);
}
.fatal__card h2 { font-family: var(--display); font-size: 30px; margin: 0 0 8px; }
.fatal__card p { font-size: 13px; line-height: 1.55; color: var(--ink-soft); margin: 0; }

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

/* Hide the game HUD during title and end screens. */
body.is-start .hud,
body.is-start .wave-card,
body.is-start .palette,
body.is-start .inspector,
body.is-start .tile-layer,
body.is-start .boss,
body.is-over .hud,
body.is-over .wave-card,
body.is-over .palette,
body.is-over .inspector,
body.is-over .tile-layer,
body.is-over .boss {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
body.is-start .hud, body.is-over .hud { transform: translateY(-6px); }
body.is-start .tile-layer, body.is-over .tile-layer { visibility: hidden; }
.gold-pop--hurt { color: #ffa088; text-shadow: 0 0 2px rgba(90, 25, 10, 0.7), 0 2px 10px rgba(70, 18, 8, 0.5); }
body.is-paused .hud, body.is-paused .wave-card, body.is-paused .palette, body.is-paused .inspector { filter: saturate(0.7); }

/* ------------------------------------------------------------- keyframes */

@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.14); } 100% { transform: scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-4px); } }
@keyframes gold-rise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.85); }
  18% { opacity: 1; transform: translate(-50%, -70%) scale(1); }
  72% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(0.96); }
}
@keyframes screen-in { from { opacity: 0; } to { opacity: 1; } }

/* ----------------------------------------------------------- responsive */

@media (max-width: 1180px) {
  .palette { width: 480px; max-width: calc(100vw - 350px); }
  .inspector { width: 280px; }
  .wave-card { width: 264px; }
}

@media (max-width: 1020px) {
  .brand__text { display: none; }
  .palette { width: 440px; max-width: calc(100vw - 330px); }
  .tower-card { padding: 9px 10px; }
  .tower-card__role { display: none; }
  .inspector { width: 262px; }
  .wave-card { width: 244px; padding: 13px; }
  .ledger { gap: 11px; padding: 8px 13px 9px; }
  .stat { min-width: 70px; }
  .stat__value { font-size: 22px; }
  .brand { padding-top: 2px; }
}

@media (max-width: 880px) {
  .hud { padding: 12px 14px 36px; }
  .brand { display: none; }
  .ledger { left: 14px; transform: none; top: 12px; }
  .hud__controls { margin-left: auto; }
  .wave-card { top: 82px; right: 14px; width: 226px; }
  .palette { left: 14px; bottom: 14px; width: min(420px, calc(100vw - 300px)); }
  .inspector { right: 14px; bottom: 14px; width: 250px; }
  .toast-stack { bottom: 158px; }
  .palette__hint { display: none; }
  .boss { top: 78px; width: 300px; }
  .boss__tag { display: none; }
}

@media (max-width: 760px) {
  .hud { padding: 10px 12px 34px; flex-wrap: wrap; }
  .ledger { position: static; transform: none; order: 1; margin-right: auto; }
  .hud__controls { order: 2; }
  .stat { min-width: 58px; gap: 7px; }
  .stat__icon { width: 26px; height: 26px; }
  .stat__value { font-size: 20px; }
  .ledger__rule { height: 24px; }
  .pause-btn span { display: none; }
  .speed__btn { min-width: 34px; padding: 5px 8px; }
  .wave-card { top: auto; bottom: 88px; right: 10px; width: 212px; padding: 11px 12px; border-radius: 15px; }
  .wave-comp { padding: 8px 0 2px; gap: 4px; }
  .chip { font-size: 10px; padding: 4px 7px; }
  .btn--wave { padding: 9px 11px; font-size: 12px; }
  .palette { left: 10px; right: 10px; bottom: 10px; width: auto; max-width: none; }
  .palette__head { padding-bottom: 5px; }
  .palette__cards { gap: 6px; }
  .tower-card { grid-template-columns: auto 1fr; padding: 8px 9px; border-radius: 12px; }
  .tower-card__icon { width: 32px; height: 32px; border-radius: 9px; }
  .tower-card__name { font-size: 14px; }
  .tower-card__cost { font-size: 10px; }
  .tower-card__role { display: none; }
  .inspector {
    left: 10px; right: 10px; bottom: 84px;
    width: auto; max-height: 52vh; overflow-y: auto;
    padding: 13px 14px;
    z-index: 30;
  }
  .toast-stack { bottom: 150px; }
  .screen--start { justify-content: center; padding: 18px; }
  .start-card { padding: 22px 20px 20px; border-radius: 20px; max-height: calc(100vh - 36px); overflow-y: auto; }
  .title { font-size: clamp(48px, 12vw, 64px); }
  .lede { font-size: 13px; }
  .controls { grid-template-columns: 1fr; gap: 7px; }
  .start-foot { align-items: stretch; }
  .start-foot .btn { width: 100%; }
  .start-credit { text-align: center; }
  .pause-card, .end-card { padding: 24px 22px; border-radius: 20px; }
  .end-stats { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .wave-card { left: 10px; right: 10px; width: auto; bottom: 82px; }
  .palette { bottom: 10px; }
  .tower-card { grid-template-columns: 1fr; justify-items: center; text-align: center; row-gap: 3px; }
  .tower-card__icon { grid-row: auto; width: 28px; height: 28px; border: 0; background: transparent; }
  .tower-card__name { font-size: 12.5px; }
  .tower-card__cost { grid-column: auto; }
  .tower-card__role { display: none; }
  .tower-card__key { display: none; }
  .inspector { bottom: 118px; }
  .toast-stack { bottom: 170px; }
  .boss { top: 70px; left: 12px; right: 12px; width: auto; transform: none; }
  .screen--start { padding: 0; }
  .start-card { border-radius: 0; min-height: 100%; max-height: none; display: flex; flex-direction: column; justify-content: center; }
}

@media (max-height: 660px) and (min-width: 761px) {
  .title { font-size: clamp(48px, 6vw, 66px); }
  .start-card { padding: 22px 28px 20px; }
  .lede { margin-bottom: 10px; }
  .goal { margin-bottom: 12px; }
  .controls { padding-top: 10px; margin-bottom: 12px; gap: 6px 16px; }
  .start-note { display: none; }
  .palette { bottom: 12px; }
  .inspector { bottom: 12px; }
  .wave-card { top: 80px; }
}

/* Reduced motion: remove decorative movement, keep state changes instant. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .gold-pop { animation: none; opacity: 1; }
}
.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}
.reduce-motion .gold-pop { animation: none; opacity: 1; }

/* Screen-reader-only utility. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
