/* ------------------------------------------------------------------
   base.css — structure, layout and motion.
   Every colour, radius, shadow and face is a token set by themes.css,
   so the whole art direction swaps without touching this file.
   ------------------------------------------------------------------ */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--app-bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  display: flex;
  justify-content: center;
}

/* ── stage ────────────────────────────────────────────────────────── */

.stage {
  width: 100%;
  max-width: 470px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--stage-bg);
  position: relative;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

/* Ground. The vehicles and the crowd are lit 3D renders; without a surface
   with any grain or falloff under them they read as stickers on a wall.
   This is the paving they stand on, plus a vignette so the middle of the
   board sits forward of its edges. */
.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: var(--ground-tiles), var(--ground-vignette);
  background-size: var(--tile) var(--tile), 100% 100%;
  opacity: var(--ground-strength, 1);
}
.stage > * { position: relative; z-index: 1; }

/* ── top bar ──────────────────────────────────────────────────────── */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--bar-bg);
  border-bottom: var(--bar-edge);
}

.chip {
  box-shadow: var(--chip-lift);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: var(--chip-border);
  border-radius: var(--r-chip);
  background: var(--chip-bg);
  color: var(--chip-ink);
  font: 700 13px/1 var(--font-ui);
  letter-spacing: .02em;
  cursor: pointer;
}
.chip--ghost { padding: 0 10px; font-size: 15px; }
.chip--coin { cursor: default; }

.coin {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--coin);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.18);
  display: inline-block; flex: 0 0 auto;
}

.level-chip { text-align: center; line-height: 1; }
.level-chip__tier {
  display: block;
  font: 800 9px/1 var(--font-ui);
  letter-spacing: .16em;
  color: var(--tier-ink);
  margin-bottom: 4px;
}
.level-chip__no {
  font: 700 12px/1 var(--font-ui);
  letter-spacing: .1em;
  color: var(--muted);
}
.level-chip__no b { color: var(--ink); font-weight: 800; }

/* ── zone 1 : queue ───────────────────────────────────────────────── */

.board {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.queue {
  flex: 0 0 auto;
  min-height: 104px;
  z-index: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 4px 6px 0;
}
#queueSvg { width: 100%; height: 100%; display: block; overflow: visible; }

.track-rail { stroke: var(--rail); stroke-width: 64; stroke-linecap: round; stroke-linejoin: round; }
.track-face { stroke: var(--track); stroke-width: 56; stroke-linecap: round; stroke-linejoin: round; }

.pax { transition: transform var(--t-pax) cubic-bezier(.34,.9,.3,1); }
.pax image { image-rendering: auto; }
.pax circle { r: 5.4; }
.pax text {
  font: 800 6px/1 var(--font-ui);
  fill: var(--pax-glyph);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  opacity: 0;
}
html[data-shapes="on"] .pax text { opacity: .85; }

/* the walk to the door, then aboard */
.pax--boarding { transition: transform .2s cubic-bezier(.4,0,.5,1); }
.pax--aboard { transition: transform .26s cubic-bezier(.5,0,.85,.4), opacity .26s ease-in; opacity: 0; }
.pax--leaving { opacity: 0; transform: scale(.4); transition: all .28s ease-in; }

.queue__count {
  position: absolute;
  top: -2px; right: 14px;
  font: 700 11px/1 var(--font-ui);
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
}
.queue__count b { color: var(--ink); }

/* ── zone 2 : platform + bays ─────────────────────────────────────── */

.platform { flex: 0 0 auto; padding: 0 10px; position: relative; z-index: 2; margin-bottom: -6px; }

.platform__deck {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 12px 10px 14px;
  border-radius: var(--r-deck);
  background-color: var(--deck);
  background-image: var(--deck-sheen);
  box-shadow: var(--deck-shadow);
}

/* The painted line along the platform edge, as on any real bus stand. It
   also does the job of tying the deck to the lot below it. */
.platform__deck::after {
  content: "";
  position: absolute;
  left: 14px; right: 14px; bottom: 5px;
  height: 3px;
  border-radius: 2px;
  background: var(--safety-line);
  opacity: .75;
}

.bays {
  flex: 1 1 auto;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 6px;
}

.bay {
  position: relative;
  aspect-ratio: 1 / 1.42;
  border-radius: var(--r-bay);
  background: var(--bay-bg);
  border: var(--bay-border);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.bay--locked {
  border: var(--bay-locked-border);
  background: transparent;
  cursor: pointer;
}
.bay--locked::after {
  content: "＋";
  font: 700 20px/1 var(--font-ui);
  color: var(--accent);
}

.bay--vip {
  flex: 0 0 46px;
  aspect-ratio: auto;
  border: var(--vip-border);
  background: var(--vip-bg);
  cursor: pointer;
}
.bay--vip .bay__tag {
  font: 800 10px/1 var(--font-ui);
  letter-spacing: .12em;
  color: var(--vip-ink);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.bay--vip[data-locked="true"] { opacity: .45; }
.bay--vip.is-armed { box-shadow: 0 0 0 2px var(--accent); }
.bay--vip .dock { position: absolute; inset: 6px; }

.bay.is-target { box-shadow: inset 0 0 0 2px var(--accent); }

/* a bus sitting in a bay */
.dock {
  position: absolute;
  inset: 4% 8%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  animation: dockIn .34s cubic-bezier(.2,1.3,.5,1) backwards;
  cursor: pointer;
}
.dock .veh__art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: none;
  pointer-events: none;
}
.dock__glyph {
  position: absolute;
  top: 3px; left: 4px;
  font: 800 9px/1 var(--font-ui);
  color: var(--on-bus);
  opacity: 0;
}
html[data-shapes="on"] .dock__glyph { opacity: .9; }

.seatbadge {
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  min-width: 26px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--busColor);
  color: var(--on-bus);
  border: 2px solid var(--deck);
  font: 800 11px/16px var(--font-ui);
  text-align: center;
  z-index: 2;
}
.seatbadge.is-pulse { animation: pulse .3s ease; }

/* ── zone 3 : the lot ─────────────────────────────────────────────── */

.lot {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 10px 6px;
}

.lot__floor {
  position: relative;
  border-radius: var(--r-lot);
  background-color: var(--lot-bg);
  background-image: var(--lot-bays), var(--lot-sheen);
  background-size: var(--cell) var(--cell), 100% 100%;
  box-shadow: var(--lot-shadow);
  isolation: isolate;
}

/* The kerb. A painted edge reads as a surface with a boundary; a plain
   rounded rectangle reads as a card. */
.lot__floor::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: var(--kerb);
  pointer-events: none;
  z-index: 3;
}

.veh {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .16s ease, filter .16s ease;
  will-change: transform;
}

/* The body is drawn nose-up and turned to face its direction, so the
   art keeps its own aspect ratio no matter which way the vehicle sits
   on the grid. */
.veh__art {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--aw);
  height: var(--ah);
  transform-origin: 50% 50%;
  pointer-events: none;
}
.veh[data-dir="U"] .veh__art { transform: translate(-50%, -50%) rotate(0deg); }
.veh[data-dir="D"] .veh__art { transform: translate(-50%, -50%) rotate(180deg); }
.veh[data-dir="R"] .veh__art { transform: translate(-50%, -50%) rotate(90deg); }
.veh[data-dir="L"] .veh__art { transform: translate(-50%, -50%) rotate(270deg); }

.veh__arrow {
  position: relative;
  z-index: 2;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
  font: 700 var(--arrow-size)/1 var(--font-ui);
  color: var(--on-bus);
  opacity: .95;
  pointer-events: none;
}
.veh__glyph {
  position: absolute;
  top: 2px; left: 3px;
  z-index: 2;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
  font: 800 9px/1 var(--font-ui);
  color: var(--on-bus);
  opacity: 0;
}
html[data-shapes="on"] .veh__glyph { opacity: .95; }
html[data-shapes="on"] .veh__arrow { opacity: .8; }

.veh--mystery .veh__arrow { color: var(--mystery-ink); }

.veh:active { transform: scale(.94); }
.veh.is-blocked { animation: nudge .3s cubic-bezier(.36,.07,.19,.97); }
.veh.is-leaving { transition: transform .38s cubic-bezier(.5,0,.85,.4), opacity .38s ease-in; opacity: 0; }
.veh.is-culprit { animation: culprit .45s ease 2; }
.veh.is-hint { animation: hint 1s ease infinite; }

/* ── boosters ─────────────────────────────────────────────────────── */

.boosters {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 10px 10px 12px;
  background: var(--bar-bg);
  border-top: var(--bar-edge);
}

.booster {
  position: relative;
  min-height: 56px;
  padding: 7px 2px 6px;
  border: var(--chip-border);
  border-radius: var(--r-chip);
  background: var(--chip-bg);
  color: var(--chip-ink);
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.booster { box-shadow: var(--chip-lift); }
.booster:active { transform: translateY(1px) scale(.98); box-shadow: none; }
.booster:disabled { opacity: .38; cursor: default; }
.booster__ico { font-size: 16px; line-height: 1; }
.booster__lbl { font-size: 9px; font-weight: 700; letter-spacing: 0; white-space: nowrap; }
.booster__cost {
  display: inline-flex; align-items: center; gap: 2px;
  font-size: 8.5px; font-weight: 800; letter-spacing: .04em;
  color: var(--muted);
}
.booster__cost .coin { width: 9px; height: 9px; }
.booster__cost--free { color: var(--accent); }
.booster.is-armed { box-shadow: 0 0 0 2px var(--accent); }

/* ── toast ────────────────────────────────────────────────────────── */

.toast {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: var(--r-chip);
  background: var(--toast-bg);
  color: var(--toast-ink);
  font: 700 12px/1 var(--font-ui);
  letter-spacing: .02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 40;
  white-space: nowrap;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ── sheets ───────────────────────────────────────────────────────── */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--scrim);
}
.sheet[hidden] { display: none; }
.sheet.is-in { animation: fade .18s ease backwards; }
.sheet.is-in .sheet__card { animation: pop .26s cubic-bezier(.2,1.2,.4,1) backwards; }

.sheet__card {
  width: 100%;
  max-width: 380px;
  max-height: 86dvh;
  overflow-y: auto;
  padding: 26px 22px 20px;
  border-radius: var(--r-card);
  background: var(--card-bg);
  border: var(--card-border);
  box-shadow: var(--card-shadow);
  text-align: center;
}
.sheet__card--menu { text-align: left; }

.sheet__art { font-size: 42px; line-height: 1; margin-bottom: 10px; }
.sheet__title {
  margin: 0 0 6px;
  font: 800 24px/1.1 var(--font-display);
  letter-spacing: var(--display-tracking);
  color: var(--ink);
}
.sheet__body { margin: 0 0 18px; font-size: 13.5px; line-height: 1.5; color: var(--muted); }
.sheet__actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }

.btn {
  height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--r-chip);
  font: 800 14px/1 var(--font-ui);
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .12s ease;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--ghost { background: var(--chip-bg); color: var(--chip-ink); border: var(--chip-border); }

.menu__group { margin: 18px 0; }
.menu__label {
  display: block;
  font: 800 9px/1 var(--font-ui);
  letter-spacing: .16em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 9px;
}

.themes { display: grid; gap: 7px; }
.swatch {
  display: grid;
  grid-template-columns: 34px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 11px;
  padding: 9px 11px;
  border: var(--chip-border);
  border-radius: var(--r-chip);
  background: var(--chip-bg);
  color: var(--chip-ink);
  text-align: left;
  cursor: pointer;
  font-family: var(--font-ui);
}
.swatch i {
  grid-row: 1 / 3;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--sw, #888);
}
.swatch b { font-size: 13px; font-weight: 800; }
.swatch small { font-size: 10.5px; color: var(--muted); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.swatch[data-set="transit"] { --sw: linear-gradient(135deg,#E4002B 0 33%,#F0AB00 33% 66%,#0057B8 66%); }
.swatch[data-set="neon"]    { --sw: linear-gradient(135deg,#FF2E63 0 33%,#FFC53D 33% 66%,#29B6FF 66%); }
.swatch[data-set="paper"]   { --sw: linear-gradient(135deg,#D8695A 0 33%,#E5B45C 33% 66%,#6E92B0 66%); }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span {
  width: 38px; height: 22px;
  border-radius: 11px;
  background: var(--field);
  border: var(--chip-border);
  position: relative;
  flex: 0 0 auto;
  transition: background .16s ease;
}
.toggle span::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--knob);
  transition: transform .16s ease;
}
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(16px); background: var(--on-accent); }

.jump { display: flex; gap: 8px; }
.jump input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--r-chip);
  border: var(--chip-border);
  background: var(--field);
  color: var(--ink);
  font: 700 15px/1 var(--font-ui);
}
.jump .btn { flex: 0 0 74px; }

/* ── motion ───────────────────────────────────────────────────────── */

@keyframes nudge {
  10%,90% { transform: translate(var(--nx,-2px), var(--ny,0)); }
  30%,70% { transform: translate(calc(var(--nx,-2px)*-2.4), calc(var(--ny,0)*-2.4)); }
  50%     { transform: translate(calc(var(--nx,-2px)*3), calc(var(--ny,0)*3)); }
}
@keyframes culprit {
  0%,100% { filter: none; }
  50% { filter: brightness(1.5) saturate(1.4); }
}
@keyframes hint {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes dockIn {
  from { transform: translateY(46px) scale(.8); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
@keyframes pulse {
  50% { transform: translateX(-50%) scale(1.32); }
}
@keyframes pop {
  from { transform: translateY(14px) scale(.94); opacity: 0; }
}
@keyframes fade { from { opacity: 0; } }

html[data-motion="reduced"] *,
html[data-motion="reduced"] *::before,
html[data-motion="reduced"] *::after {
  animation-duration: .01ms !important;
  transition-duration: .01ms !important;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* short phones: give the lot the space back */
@media (max-height: 700px) {
  .queue { min-height: 88px; }
  .booster { min-height: 50px; }
  .bay--vip { flex-basis: 40px; }
  .platform__deck { padding: 8px; }
}

/* ── tunnels ──────────────────────────────────────────────────────── */

/* A fixed block in the lot that feeds hidden-colour cars out of its
   mouth whenever the cell in front of it clears. */
.tunnel {
  position: absolute;
  border-radius: var(--r-veh);
  background: var(--tunnel-bg);
  box-shadow: var(--tunnel-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.tunnel__mouth {
  position: absolute;
  inset: 26% 20% 8%;
  border-radius: 50% 50% 3px 3px;
  background: var(--tunnel-mouth);
}
.tunnel[data-dir="D"] .tunnel__mouth { inset: 8% 20% 26%; border-radius: 3px 3px 50% 50%; }
.tunnel[data-dir="L"] .tunnel__mouth { inset: 20% 26% 20% 8%; border-radius: 3px 50% 50% 3px; }
.tunnel[data-dir="R"] .tunnel__mouth { inset: 20% 8% 20% 26%; border-radius: 50% 3px 3px 50%; }

.tunnel__arrow {
  position: absolute;
  top: 3px; left: 4px;
  font: 700 9px/1 var(--font-ui);
  color: var(--tunnel-ink);
  z-index: 1;
}
.tunnel__count {
  position: absolute;
  right: -4px; bottom: -4px;
  min-width: 17px; height: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--coin);
  color: #20160A;
  border: 2px solid var(--lot-bg);
  font: 800 10px/13px var(--font-ui);
  text-align: center;
  z-index: 2;
}
.tunnel.is-empty { opacity: .45; }
.tunnel.is-empty .tunnel__count { display: none; }

.veh.is-fresh { animation: fedOut .34s cubic-bezier(.2,1.25,.5,1) both; }
@keyframes fedOut {
  from { transform: scale(.4); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* A baked 3D body fills its cell footprint directly; the render already
   carries its own lighting and shadow, so nothing is rotated in CSS. */
.veh__art--3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: none !important;
  object-fit: fill;
  pointer-events: none;
  image-rendering: auto;
}
.dock .veh__art--3d { inset: 0; }

/* ── emergency callouts ───────────────────────────────────────────── */

.hud { display: flex; align-items: center; gap: 7px; }

.objective {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px 0 8px;
  border-radius: var(--r-chip);
  background: var(--chip-bg);
  border: var(--chip-border);
  color: var(--chip-ink);
  font: 800 13px/1 var(--font-ui);
}
.objective[hidden] { display: none; }
.objective__ico {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--siren);
  color: #fff;
  font: 900 12px/18px var(--font-ui);
  text-align: center;
}
.objective.is-urgent { box-shadow: 0 0 0 2px var(--siren); }
.objective.is-urgent .objective__ico { animation: siren 1s ease-in-out infinite; }

/* the move budget painted on the roof of a callout */
.callout {
  position: absolute;
  right: -5px; top: -5px;
  min-width: 19px; height: 19px;
  padding: 0 4px;
  border-radius: 10px;
  background: var(--siren);
  color: #fff;
  border: 2px solid var(--lot-bg);
  font: 800 11px/15px var(--font-ui);
  text-align: center;
  z-index: 3;
  pointer-events: none;
}
.callout.is-urgent { animation: siren .8s ease-in-out infinite; }

.veh--rescue { z-index: 2; }

@keyframes siren {
  0%, 100% { transform: scale(1); filter: none; }
  50% { transform: scale(1.16); filter: brightness(1.35); }
}


/* a reshuffled lot drops back in rather than teleporting */
.veh.is-relaid { animation: relaid .34s cubic-bezier(.2,1.2,.5,1) backwards; }
@keyframes relaid {
  from { transform: scale(.55); opacity: 0; }
  to   { transform: none; opacity: 1; }
}


/* the bus being sent away, and the lot highlighting what can be picked */
.veh.is-cleared { animation: cleared .34s ease-in forwards; pointer-events: none; }
@keyframes cleared {
  to { transform: scale(1.35); opacity: 0; filter: brightness(1.5); }
}
.lot.is-picking .veh:not(.veh--rescue) { cursor: crosshair; }
.lot.is-picking .veh--rescue { opacity: .45; }
.lot.is-picking .lot__floor { box-shadow: var(--lot-shadow), 0 0 0 2px var(--accent); }

/* the level clock on a timed callout */
.objective__clock {
  font: 800 13px/1 var(--font-ui);
  font-variant-numeric: tabular-nums;
  padding-left: 7px;
  margin-left: 1px;
  border-left: 1px solid var(--chip-border-col, rgba(128,128,128,.35));
}
.objective__clock[hidden] { display: none; }
.objective.is-urgent .objective__clock { color: var(--siren); }

/* Neon only: the platform edge is a lit strip rather than paint, and the
   lot glows faintly at its kerb. Everything else the theme tokens handle. */
html[data-theme="neon"] .platform__deck::after {
  box-shadow: 0 0 10px 1px var(--safety-line);
  opacity: .9;
}
html[data-theme="neon"] .lot__floor::after {
  box-shadow: inset 0 0 24px rgba(41,182,255,.07);
}
