/* ============================================================
   Bulwark — Tower Defense
   ============================================================ */

:root {
  --bg:        #0b0e14;
  --bg-2:      #10141d;
  --panel:     #161b26;
  --panel-2:   #1c2231;
  --line:      #2a3244;
  --line-2:    #384259;
  --text:      #e7ecf5;
  --text-dim:  #97a3b8;
  --text-mute: #6b7689;
  --gold:      #ffd76a;
  --gold-dim:  #b99a3f;
  --red:       #ff6b6b;
  --green:     #63d66b;
  --blue:      #5fa8ff;
  --purple:    #b98cff;
  --radius:    10px;
  --shadow:    0 10px 30px rgba(0, 0, 0, 0.45);
  --font:      "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 700px at 20% -10%, rgba(95, 168, 255, 0.10), transparent 60%),
    radial-gradient(900px 600px at 110% 110%, rgba(185, 140, 255, 0.10), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
}
button:disabled { cursor: default; }

kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--panel-2);
  font: 600 11px/1.5 var(--font);
  text-align: center;
  color: var(--text);
}

.coin {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 3px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--gold) 55%, #c99a2e);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
  vertical-align: -1px;
}

.hidden { display: none !important; }
.muted { color: var(--text-dim); }

/* ============================================================
   Layout
   ============================================================ */

#game-root {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 336px;
  grid-template-rows: 54px 1fr;
  grid-template-areas:
    "topbar topbar"
    "board  sidebar";
  height: 100%;
  gap: 10px;
  padding: 10px;
}

#game-root.menu-mode { visibility: hidden; }

/* ---------------------------- Top bar ---------------------------- */

#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  padding: 0 14px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 20px; color: var(--gold); }
.brand-name { font-weight: 800; letter-spacing: 2px; font-size: 14px; color: var(--text); }

.stats { display: flex; gap: 8px; margin-left: auto; }

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 86px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.stat-chip .lbl {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.2px;
  color: var(--text-mute);
}
.stat-chip.gold  { color: var(--gold); }
.stat-chip.lives { color: var(--red); position: relative; }
.stat-chip.lives .heart { font-size: 13px; }
.stat-chip.lives .bar {
  position: absolute;
  left: 8px; right: 8px; bottom: 3px;
  height: 2px;
  background: rgba(255, 107, 107, 0.2);
  border-radius: 2px;
  overflow: hidden;
}
.stat-chip.lives .bar > span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--red);
  transition: width 0.3s;
}
.stat-chip.wave  { color: var(--blue); }
.stat-chip.score { color: var(--text-dim); }

.controls { display: flex; align-items: center; gap: 8px; }

.speed-group {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.speed-group button {
  padding: 6px 11px;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-mute);
  transition: background 0.15s, color 0.15s;
}
.speed-group button:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.speed-group button.active { background: var(--blue); color: #06121f; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-dim);
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line-2); }

.fps {
  font-size: 10px;
  color: var(--text-mute);
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
}

/* ---------------------------- Board ---------------------------- */

#board {
  grid-area: board;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

#canvasWrap {
  position: relative;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 1px var(--line);
  line-height: 0;
}

/* Pixel size is assigned by Game._fitCanvas so the aspect ratio never skews. */
#game {
  display: block;
  max-width: 100%;
  cursor: crosshair;
}

#waveBanner {
  position: absolute;
  top: 16%;
  left: 50%;
  transform: translate(-50%, -10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 34px;
  background: rgba(8, 11, 18, 0.78);
  border: 1px solid var(--line-2);
  border-radius: 12px;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  line-height: 1.3;
}
#waveBanner b {
  font-size: 26px;
  letter-spacing: 5px;
  font-weight: 800;
  color: var(--text);
}
#waveBanner b.boss { color: var(--red); text-shadow: 0 0 18px rgba(255, 80, 80, 0.6); }
#waveBanner span { font-size: 12px; color: var(--text-dim); letter-spacing: 1px; }
#waveBanner.show { animation: banner 2.6s ease-out forwards; }

@keyframes banner {
  0%   { opacity: 0; transform: translate(-50%, 14px) scale(0.94); }
  12%  { opacity: 1; transform: translate(-50%, 0) scale(1); }
  78%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -14px) scale(1.02); }
}

#dmgFlash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  box-shadow: inset 0 0 90px rgba(255, 40, 40, 0.85);
}
#dmgFlash.show { animation: dmgflash 0.5s ease-out; }
@keyframes dmgflash {
  0% { opacity: 0.95; }
  100% { opacity: 0; }
}

/* ---------------------------- Sidebar ---------------------------- */

#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.panel-box {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 9px;
  box-shadow: var(--shadow);
  flex: none;
}
.panel-box.grow { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.box-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 6px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-mute);
}
.box-title .hint {
  font-size: 9px;
  letter-spacing: 1px;
  color: var(--line-2);
}

/* Shop */

.shop-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.card:hover { border-color: var(--line-2); background: rgba(255, 255, 255, 0.05); transform: translateY(-1px); }
.card.selected {
  border-color: var(--gold);
  background: rgba(255, 215, 106, 0.10);
  box-shadow: 0 0 0 1px rgba(255, 215, 106, 0.35), 0 4px 14px rgba(255, 215, 106, 0.12);
}
.card.poor { opacity: 0.42; }
.card.poor .card-cost { color: var(--red); }

.card-key {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-mute);
}
.card-icon { display: grid; place-items: center; flex: none; }
.card-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.card-name {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-cost { font-size: 11px; font-weight: 700; color: var(--gold); }

/* Inspector */

.inspect {
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
  min-height: 0;
  flex: 1 1 auto;
}
.inspect.empty { justify-content: center; }

/* Stats area scrolls; .ins-actions below it never does. */
.ins-scroll {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 3px;
}
.ins-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: none;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

/* Keep the scrollbar visible so it's obvious the panel scrolls when a long
   upgrade path pushes the sell button below the fold. */
.ins-scroll { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.ins-scroll::-webkit-scrollbar { width: 6px; }
.ins-scroll::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); border-radius: 4px; }
.ins-scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.ins-scroll::-webkit-scrollbar-thumb:hover { background: #4a5670; }

.inspect-hint {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 14px 10px;
  text-align: center;
  color: var(--text-mute);
}
.inspect-hint b { color: var(--text-dim); font-size: 12px; }
.inspect-hint span { font-size: 11px; line-height: 1.5; }

.ins-head { display: flex; align-items: center; gap: 9px; }
.ins-icon { flex: none; display: grid; place-items: center; }
.ins-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.ins-title b { font-size: 13px; }
.ins-sub { font-size: 10px; color: var(--text-dim); }

.lvl-pips { display: flex; gap: 2px; }
.lvl-pips i {
  width: 5px; height: 12px;
  border-radius: 2px;
  background: var(--line);
}
.lvl-pips i.on { background: var(--gold); }

.warn, .buffed {
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 10.5px;
  font-weight: 600;
}
.warn   { background: rgba(255, 90, 90, 0.14);  color: #ff9d9d; }
.buffed { background: rgba(255, 215, 106, 0.12); color: var(--gold); }

.ins-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.ins-stats .stat {
  display: flex;
  flex-direction: column;
  padding: 4px 6px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.035);
}
.ins-stats .stat span { font-size: 9px; letter-spacing: 0.6px; color: var(--text-mute); text-transform: uppercase; }
.ins-stats .stat b { font-size: 13px; font-variant-numeric: tabular-nums; }
.ins-stats .stat i { font-size: 9px; color: var(--text-mute); font-style: normal; }

.ins-perf {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-mute);
  padding: 0 2px;
}
.ins-perf b { color: var(--text-dim); }

.upgrade-btn {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1px 8px;
  align-items: center;
  padding: 7px 10px;
  background: linear-gradient(180deg, rgba(99, 214, 107, 0.16), rgba(99, 214, 107, 0.07));
  border: 1px solid rgba(99, 214, 107, 0.4);
  border-radius: 8px;
  text-align: left;
  transition: all 0.14s;
}
.upgrade-btn:hover { background: rgba(99, 214, 107, 0.24); transform: translateY(-1px); }
.upgrade-btn .up-main { font-size: 12px; font-weight: 700; color: #a9f0ad; }
.upgrade-btn .up-note { grid-column: 1; font-size: 10px; color: var(--text-dim); }
.upgrade-btn .up-cost {
  grid-row: 1 / span 2;
  grid-column: 2;
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
  white-space: nowrap;
}
.upgrade-btn.poor, .branch-btn.poor { opacity: 0.5; border-color: var(--line); }
.upgrade-btn.poor .up-cost, .branch-btn.poor { color: var(--red); }

.maxed {
  padding: 8px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--gold);
  background: rgba(255, 215, 106, 0.1);
  border: 1px dashed rgba(255, 215, 106, 0.35);
  border-radius: 8px;
}

.branch-title { font-size: 11px; font-weight: 700; color: var(--text-dim); }
.branch-grid { display: grid; gap: 5px; }
.branch-btn {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 9px;
  background: rgba(95, 168, 255, 0.10);
  border: 1px solid rgba(95, 168, 255, 0.35);
  border-radius: 8px;
  text-align: left;
  transition: all 0.14s;
}
.branch-btn:hover { background: rgba(95, 168, 255, 0.2); transform: translateY(-1px); }
.branch-btn b { font-size: 12px; color: #a9d3ff; }
.branch-btn span { font-size: 10px; line-height: 1.45; color: var(--text-dim); }

.target-row { display: flex; flex-direction: column; gap: 4px; }
.tr-label { font-size: 9px; letter-spacing: 1px; text-transform: uppercase; color: var(--text-mute); }
.tr-modes { display: flex; gap: 3px; flex-wrap: wrap; }
.tmode {
  flex: 1;
  padding: 4px 2px;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--text-mute);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 5px;
  transition: all 0.12s;
}
.tmode:hover { color: var(--text); border-color: var(--line-2); }
.tmode.active { background: var(--blue); border-color: var(--blue); color: #06121f; }

.sell-btn {
  padding: 6px;
  font-size: 11px;
  font-weight: 700;
  color: #ffb3b3;
  background: rgba(255, 107, 107, 0.1);
  border: 1px solid rgba(255, 107, 107, 0.3);
  border-radius: 8px;
  transition: all 0.14s;
}
.sell-btn:hover { background: rgba(255, 107, 107, 0.22); }

/* Abilities */

.ability-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.ability {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 7px 4px 6px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.14s;
}
.ability .ab-cd {
  position: absolute;
  left: 0; bottom: 0;
  width: 100%;
  height: 0;
  background: rgba(0, 0, 0, 0.6);
  transition: height 0.2s linear;
}
.ability .ab-name { font-size: 10.5px; font-weight: 700; position: relative; }
.ability .ab-key { font-size: 8.5px; color: var(--text-mute); position: relative; }
.ability .ab-timer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 800;
  color: var(--text);
  text-shadow: 0 1px 4px #000;
}
.ability.ready { border-color: var(--purple); color: #ddc9ff; }
.ability.ready:hover { background: rgba(185, 140, 255, 0.18); transform: translateY(-1px); }
.ability.aiming {
  border-color: var(--gold);
  background: rgba(255, 215, 106, 0.16);
  animation: pulseGlow 1s ease-in-out infinite;
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 215, 106, 0.4); }
  50%      { box-shadow: 0 0 0 5px rgba(255, 215, 106, 0); }
}

/* Wave box */

.wave-box { display: flex; flex-direction: column; gap: 6px; }
.wave-head { display: flex; align-items: baseline; justify-content: space-between; }
#nextWaveNum { font-size: 13px; font-weight: 800; letter-spacing: 0.5px; }
#nextWaveNum.boss { color: var(--red); }
.prep-timer { font-size: 10.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

.prep-track {
  height: 4px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 3px;
  overflow: hidden;
}
.prep-track > span {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--blue), #9fd0ff);
  transition: width 0.15s linear;
}
.prep-track > span.active { background: linear-gradient(90deg, var(--red), #ff9d5c); }

.wave-comp { display: flex; flex-wrap: wrap; gap: 4px; min-height: 20px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.chip i {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c, #888);
}
.chip.boss { border-color: rgba(255, 107, 107, 0.5); color: #ffb0b0; }

.next-wave-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: #06121f;
  background: linear-gradient(180deg, #ffe08a, var(--gold));
  border-radius: 8px;
  transition: all 0.14s;
}
.next-wave-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.next-wave-btn .nw-bonus {
  padding: 1px 7px;
  font-size: 11px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 20px;
}
.next-wave-btn .nw-bonus:empty { display: none; }

/* ============================================================
   Overlays / panels
   ============================================================ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 7, 12, 0.82);
  backdrop-filter: blur(7px);
  overflow-y: auto;
}

.panel {
  width: min(980px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 26px 30px;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease-out;
}
.panel.small { width: min(440px, 100%); }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.panel h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: 0.5px; }
.panel h3 {
  margin: 0 0 9px;
  font-size: 10px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--text-mute);
}
.panel h4 { margin: 16px 0 5px; font-size: 12.5px; color: var(--gold); }
.panel h4:first-child { margin-top: 0; }
.panel p { margin: 0 0 8px; font-size: 12px; line-height: 1.62; color: var(--text-dim); }

.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }

.primary, .ghost, .danger {
  padding: 11px 18px;
  font-size: 13px;
  font-weight: 700;
  border-radius: 9px;
  transition: all 0.15s;
  border: 1px solid transparent;
}
.primary {
  background: linear-gradient(180deg, #ffe08a, var(--gold));
  color: #101418;
}
.primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line-2);
  color: var(--text);
}
.ghost:hover { background: rgba(255, 255, 255, 0.1); }
.danger {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.4);
  color: #ffb3b3;
}
.danger:hover { background: rgba(255, 107, 107, 0.24); }
.big { padding: 14px 20px; font-size: 15px; }
.small-btn { padding: 8px 14px; font-size: 11.5px; }

/* Menu */

.menu-hero { text-align: center; margin-bottom: 22px; }
.menu-hero h1 {
  margin: 0;
  font-size: 46px;
  font-weight: 900;
  letter-spacing: 12px;
  background: linear-gradient(180deg, #fff6d8, var(--gold) 55%, #b0842a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.menu-hero p { max-width: 560px; margin: 6px auto 0; font-size: 12.5px; }

.menu-cols { display: grid; grid-template-columns: 1fr 300px; gap: 22px; }
.menu-col { min-width: 0; }
.menu-col.narrow h3:not(:first-child) { margin-top: 18px; }

.map-list { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.map-card {
  display: flex;
  gap: 10px;
  padding: 9px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: left;
  transition: all 0.15s;
}
.map-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.map-card.active { border-color: var(--gold); background: rgba(255, 215, 106, 0.08); }
.map-thumb {
  flex: none;
  width: 84px; height: 58px;
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  line-height: 0;
}
.map-thumb svg { width: 100%; height: 100%; }
.map-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.map-meta b { font-size: 12.5px; }
.map-diff { font-size: 9.5px; letter-spacing: 1px; text-transform: uppercase; color: var(--gold-dim); }
.map-desc { font-size: 10.5px; line-height: 1.45; color: var(--text-mute); }

.diff-list { display: grid; gap: 6px; }
.diff-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 11px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
  transition: all 0.15s;
}
.diff-card:hover { border-color: var(--line-2); }
.diff-card.active { border-color: var(--gold); background: rgba(255, 215, 106, 0.08); }
.diff-card b { font-size: 12.5px; }
.diff-card span { font-size: 10.5px; color: var(--text-mute); }
.diff-stats { font-size: 10px !important; color: var(--text-dim) !important; }

.score-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 3px; }
.score-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.24);
  border-radius: 6px;
  font-size: 11px;
}
.score-list li.empty { justify-content: center; color: var(--text-mute); font-size: 10.5px; }
.score-list .rank { width: 14px; color: var(--text-mute); font-weight: 700; }
.sc-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.sc-main b { color: var(--gold); font-variant-numeric: tabular-nums; }
.sc-main i {
  font-style: normal;
  font-size: 9.5px;
  color: var(--text-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sc-wave { font-size: 10px; color: var(--text-dim); white-space: nowrap; }

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: center;
  margin-top: 24px;
}
.menu-actions .big { min-width: 190px; }

/* End screen */

.end-title { font-size: 27px; }
.end-title.win  { color: var(--gold); }
.end-title.lose { color: var(--red); }
.end-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 14px; }
.end-stat {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 6px;
  font-size: 11.5px;
}
.end-stat span { color: var(--text-mute); }
.end-stat b { font-variant-numeric: tabular-nums; }

/* Settings */

.settings { display: grid; gap: 6px; margin-top: 12px; }
.settings .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 11px;
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}
.settings input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--gold); cursor: pointer; }
.settings input[type="range"] { width: 140px; accent-color: var(--gold); cursor: pointer; }
.settings select {
  padding: 4px 8px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  font-family: inherit;
  cursor: pointer;
}

/* Help */

.help-panel { width: min(880px, 100%); }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.keys { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.keys td { padding: 4px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); color: var(--text-dim); }
.keys td:first-child { width: 130px; white-space: nowrap; }

/* ============================================================
   Toasts + tooltip
   ============================================================ */

#toasts {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  padding: 9px 18px;
  background: rgba(12, 16, 24, 0.94);
  border: 1px solid var(--line-2);
  border-left: 3px solid var(--blue);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toastIn 0.28s ease-out;
}
.toast.good { border-left-color: var(--green); color: #b6f0ba; }
.toast.bad  { border-left-color: var(--red);   color: #ffb3b3; }
.toast.out  { animation: toastOut 0.4s ease-in forwards; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

.tooltip {
  position: fixed;
  z-index: 70;
  width: 250px;
  padding: 11px 13px;
  background: rgba(10, 13, 20, 0.97);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  box-shadow: var(--shadow);
  pointer-events: none;
  font-size: 11.5px;
}
.tooltip h4 { margin: 0 0 4px; font-size: 13px; color: var(--gold); }
.tooltip p { margin: 0 0 8px; font-size: 11px; line-height: 1.5; color: var(--text-dim); }
.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.tip-row span { color: var(--text-mute); }
.tip-row b { font-variant-numeric: tabular-nums; }
.tip-foot {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 10px;
  line-height: 1.45;
  color: var(--text-mute);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 1180px) {
  #game-root { grid-template-columns: minmax(0, 1fr) 300px; }
}

/* Single column: the board sits above the controls. Every track is
   minmax(0, …) so a wide top bar can never push the grid past the viewport. */
@media (max-width: 980px) {
  html, body { overflow: auto; }
  #game-root {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "topbar" "board" "sidebar";
    height: auto;
    min-height: 100%;
    gap: 8px;
    padding: 8px;
  }
  #topbar {
    flex-wrap: wrap;
    height: auto;
    gap: 8px;
    padding: 8px 10px;
  }
  #sidebar { overflow: visible; }
  #board { height: auto; }
  .stats { margin-left: 0; flex: 1 1 auto; flex-wrap: wrap; }
  .controls { flex: 1 1 auto; justify-content: flex-end; flex-wrap: wrap; }
  .menu-cols { grid-template-columns: 1fr; }
  .help-cols { grid-template-columns: 1fr; }
  .brand-name { display: none; }
  .fps { display: none; }
  /* No hover on touch devices — tooltips would just get in the way. */
  .tooltip { display: none !important; }
}

@media (max-width: 620px) {
  .stat-chip { min-width: 56px; padding: 4px 8px; font-size: 12px; }
  .stats { gap: 5px; }
  .stat-chip.score { display: none; }
  .menu-hero h1 { font-size: 32px; letter-spacing: 6px; }
  .map-list { grid-template-columns: 1fr; }
  .panel { padding: 20px 16px; }
  .menu-actions .big { min-width: 0; flex: 1 1 140px; }
}
