:root {
  --bg: #1b232d;
  --panel: #26313d;
  --panel-2: #303c4a;
  --line: #3b4858;
  --text: #e9edf1;
  --muted: #9aa7b5;
  --accent: #7fe0d0;
  --accent-ink: #12302c;
  --warm: #ffd27a;
  --danger: #e86a5f;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(6, 10, 16, 0.35), 0 2px 6px rgba(6, 10, 16, 0.25);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; }
svg { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; }

/* ---------- Layout ---------- */
#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  background: radial-gradient(120% 80% at 50% 0%, #243140 0%, var(--bg) 70%);
}
#app.mode-menu .hud { display: none; }
#app.mode-menu #stage { grid-row: 1 / -1; grid-column: 1 / -1; visibility: hidden; }

.hud { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
#hud-top { justify-content: space-between; }
.level-name { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.level-name span { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.level-name strong { font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }

#hud-stats { justify-content: center; gap: 10px; padding-top: 0; flex-wrap: wrap; }
.stat {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border-radius: 12px;
  padding: 8px 14px;
  min-height: 44px;
  box-shadow: 0 2px 8px rgba(6, 10, 16, 0.25);
}
.stat b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.stat .of { color: var(--muted); font-weight: 600; }
.stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-icon { color: var(--warm); }
.stat-houses { position: relative; padding-bottom: 12px; min-width: 120px; justify-content: center; }
.meter { position: absolute; left: 12px; right: 12px; bottom: 6px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--warm); border-radius: 2px; transition: width 0.35s ease; }
.stat-houses.done .meter div { background: var(--accent); }
.stat-houses.violated { box-shadow: 0 2px 8px rgba(6, 10, 16, 0.25), inset 0 0 0 1.5px var(--danger); }
.bump { animation: bump 0.35s; }
@keyframes bump { 30% { transform: translateX(-4px); } 60% { transform: translateX(4px); } }

#stage { position: relative; min-height: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#hud-bottom { justify-content: center; gap: 0; padding-bottom: 14px; }
#hud-bottom .tools { display: flex; gap: 12px; }

/* ---------- Tower tray ---------- */
.tray {
  position: relative;
  display: flex; gap: 10px;
  padding: 6px;
  border-radius: 16px;
  background: rgba(38, 49, 61, 0.6);
  border: 1px solid var(--line);
  transition: background 0.15s, border-color 0.15s;
}
.tray.drop { border: 2px dashed var(--accent); padding: 5px; background: rgba(127, 224, 208, 0.08); }
.tray-note {
  position: absolute; left: 50%; bottom: calc(100% + 8px);
  transform: translateX(-50%);
  display: none; place-items: center;
  padding: 5px 12px; border-radius: 999px;
  background: rgba(38, 49, 61, 0.94);
  box-shadow: var(--shadow);
  white-space: nowrap;
  color: var(--accent); font-size: 0.9rem; font-weight: 700;
  pointer-events: none; z-index: 2;
}
.tray.removing .tray-note { display: grid; }
.tray.removing .chip { opacity: 0.35; }
.tray-divider { width: 1px; height: 40px; background: var(--line); margin: 0 12px; flex: none; }
.chip {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  width: 76px; height: 64px;
  padding: 4px 4px 0;
  border: none; border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(6, 10, 16, 0.25);
  cursor: grab;
  touch-action: none;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.chip:hover { background: var(--panel-2); }
.chip.selected { background: var(--panel-2); box-shadow: 0 2px 8px rgba(6, 10, 16, 0.25), inset 0 0 0 2px var(--accent); }
.chip.pressed, .chip:active { transform: scale(0.96); }
.chip-icon { width: 36px; height: 36px; pointer-events: none; }
.chip-label { font-size: 0.75rem; font-weight: 600; color: var(--text); line-height: 1.3; pointer-events: none; }
.chip-badge {
  position: absolute; top: -6px; right: -4px;
  min-width: 30px; height: 22px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--accent); color: var(--accent-ink);
  font-size: 0.8rem; font-weight: 700; font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.chip-badge.pop { animation: badge-pop 0.2s ease-out; }
@keyframes badge-pop { 50% { transform: scale(1.2); } }
.chip.holding .chip-icon { opacity: 0.5; }
.chip.empty { cursor: default; }
.chip.empty .chip-icon { opacity: 0.35; }
.chip.empty .chip-label { color: var(--muted); opacity: 0.7; }
.chip.empty .chip-badge { background: var(--line); color: var(--muted); }
.chip.callout-ring { box-shadow: 0 0 0 2px var(--accent), 0 0 14px rgba(127, 224, 208, 0.45); animation: ring-pulse 1.2s ease-in-out infinite; }
@keyframes ring-pulse { 50% { box-shadow: 0 0 0 4px rgba(127, 224, 208, 0.5), 0 0 18px rgba(127, 224, 208, 0.3); } }

#drag-layer { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 8; }

.callout {
  position: fixed; z-index: 9;
  max-width: 240px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(38, 49, 61, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.85rem; line-height: 1.35;
  pointer-events: none;
  animation: toast-in 0.25s ease-out;
}
.callout::after {
  content: ""; position: absolute; left: var(--caret, 50%); bottom: -8px;
  width: 0; height: 0; margin-left: -8px;
  border: 8px solid transparent; border-bottom: 0; border-top-color: rgba(38, 49, 61, 0.94);
}
.callout.side { max-width: none; text-align: center; }
.callout.side::after { display: none; }
.callout.below::after { bottom: auto; top: -8px; border: 8px solid transparent; border-top: 0; border-bottom-color: rgba(38, 49, 61, 0.94); }
.tool-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 76px; min-height: 56px;
  padding: 8px 12px;
  border: none; border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(6, 10, 16, 0.25);
  font-size: 0.78rem; font-weight: 600; color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.tool-btn svg { width: 22px; height: 22px; color: var(--text); }
.tool-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.tool-btn:active:not(:disabled) { transform: scale(0.96); }
.tool-btn:disabled { opacity: 0.4; cursor: default; }

.icon-btn {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  border: none; border-radius: 12px;
  background: var(--panel);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(6, 10, 16, 0.25);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--panel-2); }

button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toast {
  position: absolute; left: 50%; top: 8px;
  transform: translateX(-50%);
  max-width: min(92%, 440px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(38, 49, 61, 0.94);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  text-align: center;
  pointer-events: none;
  animation: toast-in 0.25s ease-out;
}
.toast.warm { color: var(--warm); }
.toast.side { transform: none; max-width: none; border-radius: 14px; font-size: 0.82rem; padding: 8px 12px; z-index: 3; animation: fade 0.25s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -6px); } }

/* ---------- Screens ---------- */
.screen {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  overflow-y: auto;
  z-index: 10;
  animation: fade 0.2s ease-out;
}
.screen.dim { background: rgba(14, 19, 26, 0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
@keyframes fade { from { opacity: 0; } }

.panel {
  width: 100%;
  background: rgba(38, 49, 61, 0.97);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease-out;
}
@keyframes rise { from { transform: translateY(10px); opacity: 0; } }
.small-panel { max-width: 360px; }
.panel h2 { margin: 0; font-size: 1.4rem; text-align: center; }
.panel-head { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; margin-bottom: 18px; min-width: 44px; }

.menu { display: flex; flex-direction: column; gap: 10px; }
.menu.row { flex-direction: row; justify-content: center; margin-top: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 48px;
  padding: 12px 20px;
  border: none; border-radius: var(--radius);
  background: var(--panel-2);
  font-weight: 650; font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(6, 10, 16, 0.25);
  transition: background 0.15s, transform 0.1s, filter 0.15s;
}
.btn:hover { background: #394757; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.grow { flex: 1; }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: 0.9rem; }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1.5px var(--danger); }
.btn.danger.confirm { background: var(--danger); color: #2a0f0c; }

/* ---------- Title (start screen) ---------- */
.title-screen { display: block; padding: 0; overflow-x: hidden; }
.title-sound { position: absolute; top: calc(12px + var(--safe-t)); right: 16px; z-index: 2; }
.title-col {
  min-height: 100%;
  max-width: 400px; margin: 0 auto;
  padding: var(--safe-t) 24px calc(24px + var(--safe-b));
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.title-hero { display: block; width: min(88vw, 360px); height: auto; aspect-ratio: 320 / 220; margin-top: clamp(24px, 7vh, 72px); user-select: none; -webkit-user-drag: none; }
/* The hero's own sky is a flat rectangle; fade its edges into the page
   gradient so it reads as part of the screen, not a picture on it. */
.title-hero {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 16%, #000 84%, transparent), linear-gradient(to bottom, transparent, #000 14%, #000);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to right, transparent, #000 16%, #000 84%, transparent), linear-gradient(to bottom, transparent, #000 14%, #000);
  mask-composite: intersect;
}
.title-text { display: flex; flex-direction: column; align-items: center; width: 100%; }
.title-eyebrow { margin: 20px 0 0; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.16em; color: var(--accent); }
.title-word { margin: 6px 0 8px; font-size: 2.75rem; font-weight: 800; letter-spacing: -0.015em; line-height: 1.05; }
.title-word .accent { color: var(--accent); }
.title-tagline { margin: 0; font-size: 1rem; font-weight: 500; color: var(--muted); }
.title-primary {
  margin-top: clamp(20px, 5vh, 56px);
  width: 100%; max-width: 320px; height: 68px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: none; border-radius: 18px;
  background: var(--accent); color: var(--accent-ink);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(127, 224, 208, 0.22);
  animation: glow 2.4s ease-in-out infinite alternate;
  transition: filter 0.12s, transform 0.12s;
}
.title-primary #title-play-label { font-size: 1.25rem; font-weight: 800; }
.title-primary .sub { font-size: 0.82rem; font-weight: 600; opacity: 0.75; max-width: 92%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes glow { to { box-shadow: 0 6px 20px rgba(127, 224, 208, 0.38); } }
.title-secondary { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; max-width: 320px; }
.title-btn {
  height: 56px; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: none; border-radius: 16px; background: var(--panel-2);
  font-size: 1rem; font-weight: 700; color: var(--text); cursor: pointer;
  transition: background 0.15s, transform 0.08s;
}
.title-btn svg { width: 22px; height: 22px; }
@media (hover: hover) {
  .title-primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
  .title-btn:hover { background: #394757; }
}
.title-primary:active, .title-btn:active { transform: scale(0.97); transition-duration: 0.08s; }
.title-primary:focus-visible, .title-btn:focus-visible, .title-screen .icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.title-progress { margin-top: 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.tp-row { display: flex; align-items: center; font-size: 0.875rem; }
.tp-row svg { width: 16px; height: 16px; color: var(--warm); margin-right: 6px; }
.tp-stars { color: var(--warm); font-weight: 700; font-variant-numeric: tabular-nums; }
.tp-div { width: 1px; height: 12px; background: var(--line); margin: 0 12px; }
.tp-levels { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.tp-meter { width: 160px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.tp-meter div { height: 100%; width: 0; background: var(--warm); border-radius: 2px; }
/* Entrance: the first title display after page load only. */
.title-screen.enter .title-hero, .title-screen.enter .title-eyebrow, .title-screen.enter .title-word,
.title-screen.enter .title-tagline, .title-screen.enter .title-primary, .title-screen.enter .title-secondary,
.title-screen.enter .title-progress { animation: enter 450ms cubic-bezier(.2, .8, .2, 1) backwards; }
.title-screen.enter .title-eyebrow, .title-screen.enter .title-word { animation-delay: 120ms; }
.title-screen.enter .title-tagline { animation-delay: 180ms; }
.title-screen.enter .title-primary { animation: enter 450ms cubic-bezier(.2, .8, .2, 1) 240ms backwards, glow 2.4s ease-in-out 700ms infinite alternate; }
.title-screen.enter .title-secondary { animation-delay: 300ms; }
.title-screen.enter .title-progress { animation-delay: 360ms; }
@keyframes enter { from { opacity: 0; transform: translateY(12px); } }
@media (max-height: 700px) and (orientation: portrait) {
  .title-hero { width: min(70vw, 280px); }
  .title-word { font-size: 2.25rem; }
  .title-primary { height: 60px; }
}
@media (min-width: 900px) and (min-height: 600px) {
  .title-col { max-width: 440px; justify-content: center; }
  .title-hero { width: 440px; margin-top: 0; }
  .title-word { font-size: 3.5rem; }
  .title-primary { max-width: 340px; }
  .title-secondary { max-width: 340px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .title-col {
    max-width: none; min-height: 100%;
    display: grid; grid-template-columns: 1fr 1fr; gap: 32px; align-items: center; justify-items: center;
    padding: calc(16px + var(--safe-t)) calc(24px + env(safe-area-inset-right, 0px)) calc(16px + var(--safe-b)) calc(24px + env(safe-area-inset-left, 0px));
  }
  .title-hero { height: min(calc(100vh - 48px), 300px); width: auto; margin: 0; justify-self: end; }
  .title-text { max-width: 340px; justify-self: start; }
  .title-eyebrow { margin-top: 0; font-size: 11px; }
  .title-word { font-size: 2.25rem; }
  .title-tagline { font-size: 0.9rem; }
  .title-primary { height: 60px; border-radius: 16px; margin-top: 20px; }
  .title-btn { height: 48px; border-radius: 14px; }
  .title-progress { margin-top: 16px; }
}

/* ---------- Level map (road path) ---------- */
.map-screen { display: flex; flex-direction: column; align-items: stretch; padding: 0; overflow: hidden; }
.map-bar {
  flex: none; position: relative; z-index: 3;
  display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px;
  height: calc(60px + var(--safe-t)); padding: var(--safe-t) 16px 0;
  background: rgba(27, 35, 45, 0.88);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent; transition: border-color 0.15s;
}
.map-bar.scrolled { border-bottom-color: var(--line); }
.map-bar h2 { margin: 0; font-size: 1.15rem; font-weight: 700; text-align: center; }
.star-pill {
  display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--panel); color: var(--warm); font-size: 0.875rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.star-pill svg { width: 16px; height: 16px; }
.map-scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; position: relative; overscroll-behavior: contain; }
.map-track { position: relative; margin: 0 auto; }
.map-road { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.map-road .shadow { stroke: rgba(6, 10, 16, 0.35); stroke-width: 18; transform: translateY(3px); }
.map-road .bed { stroke: #26313d; stroke-width: 18; }
.map-road .dots { stroke: #4a5868; stroke-width: 4; stroke-dasharray: 0 12; }
.map-road .glow { stroke: rgba(127, 224, 208, 0.18); stroke-width: 16; }
.map-road .line { stroke: #7fe0d0; stroke-width: 8; }
.map-road > path, .map-road .travelled path { fill: none; stroke-linecap: round; }
.map-road .scenery.locked { opacity: 0.5; }
.map-packet { position: absolute; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: rgba(127, 224, 208, 0.4); pointer-events: none; z-index: 2; }
.map-packet::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: #d8fff9; }

.map-node {
  position: absolute; z-index: 1;
  display: grid; place-items: center;
  padding: 0; border-radius: 50%; border: none;
  font: inherit; font-weight: 800; font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform 0.12s;
}
.map-node.locked { background: #26313d; box-shadow: inset 0 0 0 2px #3b4858, 0 3px 0 rgba(6, 10, 16, 0.3); color: #9aa7b5; cursor: default; }
.map-node.locked svg { width: 20px; height: 20px; opacity: 0.85; }
.map-node.current { background: #7fe0d0; color: #12302c; font-size: 1.5rem; box-shadow: 0 6px 16px rgba(127, 224, 208, 0.30); }
.map-node.beaten, .map-node.open { background: #303c4a; color: #e9edf1; font-size: 1.25rem; box-shadow: inset 0 0 0 3px #7fe0d0; }
.map-node.perfect { box-shadow: inset 0 0 0 3px #ffd27a; }
.map-node.open { box-shadow: inset 0 0 0 2px #7fe0d0; }
@media (hover: hover) { .map-node:hover { transform: scale(1.06); } }
.map-node:active { transform: scale(0.94); transition-duration: 0.08s; }
.map-node:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.map-node .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid #7fe0d0; opacity: 0; pointer-events: none; animation: pulse 1.8s ease-out infinite; }
.map-node .ring + .ring { animation-delay: 0.9s; }
@keyframes pulse { from { transform: scale(1); opacity: 0.6; } to { transform: scale(1.6); opacity: 0; } }
.map-node .pill {
  position: absolute; left: 50%; width: 54px; height: 18px; margin-left: -27px;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  border-radius: 9px; background: #1b232d; box-shadow: inset 0 0 0 1px #3b4858;
}
.map-node .pill svg { width: 12px; height: 12px; }
.map-node .pill svg.on { fill: #ffd27a; }
.map-node .pill svg.off { fill: none; stroke: #6b7787; stroke-width: 3.2; }
.map-label {
  position: absolute; z-index: 2; height: 48px; padding: 0 12px; border-radius: 12px;
  display: flex; flex-direction: column; justify-content: center; text-align: left;
  background: rgba(38, 49, 61, 0.96); box-shadow: var(--shadow);
  pointer-events: none; opacity: 0; transition: opacity 0.15s;
}
.map-label::before { content: ""; position: absolute; top: 50%; margin-top: -7px; border: 7px solid transparent; }
.map-label.right::before { left: -14px; border-right-color: rgba(38, 49, 61, 0.96); }
.map-label.left::before { right: -14px; border-left-color: rgba(38, 49, 61, 0.96); }
.map-label .k { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.map-label .n { font-size: 14px; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-label.show { opacity: 1; }
.map-node:hover + .map-label, .map-node:focus-visible + .map-label { opacity: 1; transition-delay: 150ms; }
/* After a win the map lands on the next circle: a ring round it and its name shown. */
.map-node.arrive { outline: 3px solid var(--accent); outline-offset: 5px; }
.map-node.arrive + .map-label { opacity: 1; }
.map-banner {
  position: absolute; z-index: 1; height: 64px; padding: 0 16px 0 12px; border-radius: 16px;
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); box-shadow: 0 4px 0 rgba(6, 10, 16, 0.35);
}
.map-banner .disc { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #303c4a; color: var(--warm); flex: none; transition: background 0.2s, color 0.2s; }
.map-banner .disc svg { width: 22px; height: 22px; }
.map-banner .t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.map-banner .k { font-size: 10.5px; line-height: 1.25; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-banner .n { font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-banner .s { display: flex; align-items: center; gap: 5px; color: var(--warm); font-size: 0.875rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.map-banner .s svg { width: 16px; height: 16px; }
.map-banner.locked .disc { background: #1b232d; color: var(--muted); }
.map-banner.locked .n { opacity: 0.6; }
.map-banner.locked .s { color: var(--muted); }
.map-banner.locked .s svg { width: 18px; height: 18px; }
.map-cta {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex; justify-content: center;
  padding: 48px 16px calc(16px + var(--safe-b));
  background: linear-gradient(to bottom, rgba(27, 35, 45, 0), var(--bg) 48px);
  pointer-events: none;
}
.map-cta .btn { pointer-events: auto; width: min(var(--col, 340px), 340px); height: 56px; border-radius: 16px; font-size: 1.05rem; font-weight: 700; }
.map-toast { position: absolute; top: calc(70px + var(--safe-t)); z-index: 4; }
/* Road animation */
.map-node.ack { animation: ack 280ms ease-out; }
@keyframes ack { 50% { transform: scale(1.12); } }
.map-node.unlocking { animation: unlock-pop 360ms cubic-bezier(.2, 1.6, .4, 1), unlock-fill 200ms ease-out; }
.map-node.unlocking .num { animation: fade-in 150ms ease-out 80ms backwards; }
.map-node .burst { position: absolute; inset: 0; border-radius: 50%; border: 2px solid #7fe0d0; pointer-events: none; animation: burst 600ms ease-out forwards; }
.map-node .lock-out { position: absolute; inset: 0; display: grid; place-items: center; color: #9aa7b5; animation: lock-out 150ms ease-in forwards; }
.map-node .lock-out svg { width: 20px; height: 20px; }
@keyframes unlock-pop { from { transform: scale(var(--from, 0.833)); } }
@keyframes unlock-fill { from { background: #26313d; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes burst { from { transform: scale(1); opacity: 0.7; } to { transform: scale(2); opacity: 0; } }
@keyframes lock-out { to { opacity: 0; transform: scale(0); } }
.map-label.label-in { animation: label-in 200ms ease-out; }
@keyframes label-in { from { opacity: 0; transform: translateY(4px); } }
.map-banner.opening { animation: banner-pop 240ms ease-out; }
.map-banner.opening .k, .map-banner.opening .s { animation: fade-in 200ms ease-out; }
@keyframes banner-pop { 50% { transform: scale(1.03); } }
.map-track.crossfade { animation: fade 200ms ease-out; }
.map-node .ring.still { animation: none; opacity: 0.45; }
@media (max-height: 560px) and (orientation: landscape) {
  .map-bar { height: calc(56px + var(--safe-t)); }
  .map-cta { padding-top: 32px; padding-bottom: calc(10px + var(--safe-b)); }
  .map-cta .btn { height: 48px; }
}

/* Settings */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 2px; border-bottom: 1px solid var(--line); font-weight: 600; }
.setting.inline { border: none; padding: 8px 4px 0; }
.fine { color: var(--muted); font-size: 0.85rem; margin: 14px 0 0; }
.switch {
  appearance: none; -webkit-appearance: none;
  position: relative; width: 50px; height: 30px; margin: 0;
  border-radius: 999px; background: var(--line);
  cursor: pointer; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* Pause */
#screen-pause h2 { margin-bottom: 18px; }

/* Win */
.win-panel { text-align: center; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.win-stars { display: flex; justify-content: center; align-items: flex-end; gap: 6px; margin: 18px 0 8px; }
.win-stars .star { width: 54px; height: 54px; color: var(--line); transform: scale(0.85); }
.win-stars .star.big { width: 70px; height: 70px; }
.win-stars .star.on { color: var(--warm); animation: star-pop 0.4s cubic-bezier(.2, 1.6, .4, 1) forwards; filter: drop-shadow(0 0 10px rgba(255, 210, 122, 0.45)); }
@keyframes star-pop { 0% { transform: scale(0.3); } 100% { transform: scale(1); } }
.win-detail { color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.win-detail b { color: var(--text); }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .panel { padding: 18px; }
  .hud { padding: 8px 12px; }
  #hud-stats { gap: 6px; }
  .stat { padding: 6px 10px; gap: 6px; }
  .stat-label { font-size: 0.65rem; }
  .stat-houses { min-width: 96px; }
  .tool-btn { min-width: 0; flex: 1; max-width: 120px; }
  #hud-bottom { flex-direction: column; align-items: stretch; gap: 8px; padding: 6px 16px 12px; }
  .tray { width: 100%; }
  .chip { flex: 1; width: auto; }
  .tray-divider { display: none; }
  #hud-bottom .tools { justify-content: center; gap: 10px; }
  #hud-bottom .tool-btn { min-height: 52px; padding: 5px 12px; }
}
@media (max-height: 560px) and (orientation: landscape) {
  #app { grid-template-columns: 1fr auto; grid-template-rows: auto 1fr auto; }
  #hud-top { grid-column: 1 / -1; padding-block: 6px; }
  #stage { grid-column: 1; grid-row: 2 / 4; }
  #hud-stats { grid-column: 2; grid-row: 2; flex-direction: column; align-items: stretch; justify-content: center; flex-wrap: nowrap; padding-top: 0; }
  #hud-stats { padding-bottom: 6px; gap: 6px; justify-content: flex-end !important; }
  #hud-bottom { grid-column: 2; grid-row: 3; flex-direction: column; align-items: stretch; gap: 12px; padding: 0 12px 8px; }
  .stat { min-height: 38px; padding: 4px 12px; justify-content: space-between; }
  .tray { width: 100%; }
  .chip { flex: 1; width: 84px; }
  .tray-divider { display: none; }
  #hud-bottom .tools { gap: 8px; }
  .tool-btn { min-width: 0; flex: 1; min-height: 48px; padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
