:root {
  --ink: #16130f;
  --panel: #221d17;
  --panel-2: #2d261e;
  --line: #4a4034;
  --cream: #fff6dc;
  --muted: #cfc3a4;
  --yellow: #ffc61a;
  --yellow-deep: #e0a800;
  --green: #35c97b;
  --red: #ff6a5e;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

#game,
#fx {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}
#fx { pointer-events: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

/* ---------- buttons ---------- */

.btn {
  min-height: 48px;
  padding: 12px 22px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: transform 0.12s ease, background-color 0.12s ease;
}
.btn:active { transform: translateY(2px); }
.btn-primary {
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--yellow-deep);
}
.btn-primary:hover { background: #ffd447; }
.btn-primary:active { box-shadow: 0 2px 0 var(--yellow-deep); }
.btn-big {
  width: 100%;
  min-height: 60px;
  font-size: 1.25rem;
  text-transform: uppercase;
  font-style: italic;
  font-weight: 900;
}
.btn-quiet {
  background: transparent;
  border-color: var(--line);
  color: var(--cream);
}
.btn-quiet:hover { background: var(--panel-2); }

.icon-btn {
  width: 48px;
  height: 48px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid rgba(255, 246, 220, 0.25);
  background: rgba(22, 19, 15, 0.82);
}
.icon-btn:hover { background: var(--panel-2); }

/* ---------- in-game HUD ---------- */

.hud {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(100%, 720px);
  padding: calc(10px + env(safe-area-inset-top)) 12px 0;
  pointer-events: none;
  display: grid;
  gap: 8px;
}
.hud > * { pointer-events: auto; }
.hud-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.hud-row-2 { flex-wrap: wrap; }

.stat, .health {
  background: rgba(22, 19, 15, 0.82);
  border-radius: var(--radius);
  padding: 6px 12px 8px;
  min-width: 0;
}
.stat { flex: none; min-width: 112px; }
.health { flex: 1; }
.stat-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  display: block;
  font-size: 1.375rem;
  font-weight: 900;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  color: var(--yellow);
}
.bar {
  height: 14px;
  margin-top: 5px;
  border-radius: 999px;
  background: #3a322a;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 0.2s ease, background-color 0.2s ease;
}
.bar-fill.warn { background: var(--yellow); }
.bar-fill.danger { background: var(--red); }

.pill, .chip {
  background: rgba(22, 19, 15, 0.82);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.875rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pill { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.alert { background: var(--yellow); color: var(--ink); }
.pill.good { background: #0f7b4b; color: #fff; }
.chip { flex: none; color: var(--muted); }
.chip span:first-of-type, .chip #hud-seats, .chip #hud-streak { color: var(--cream); }
.chip-streak { background: var(--yellow); color: var(--ink); }
.chip-streak #hud-streak { color: var(--ink); }

.toast {
  position: fixed;
  left: 0;
  right: 0;
  margin: 0 auto;
  width: fit-content;
  top: calc(126px + env(safe-area-inset-top));
  transform: translateY(-8px);
  max-width: min(92vw, 460px);
  padding: 10px 16px;
  border-radius: 14px 14px 14px 4px;
  background: var(--cream);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.9375rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.show { opacity: 1; transform: none; }

/* ---------- touch controls ---------- */

.controls {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 720px);
  padding: 0 14px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.steer, .actions { display: flex; gap: 12px; }
.ctl {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  border: 2px solid rgba(255, 246, 220, 0.35);
  background: rgba(22, 19, 15, 0.78);
  color: var(--cream);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.ctl:active, .ctl.down { background: var(--cream); color: var(--ink); }
.ctl-brake {
  width: 112px;
  border-color: var(--red);
  color: #fff;
  background: rgba(190, 40, 32, 0.9);
  font-weight: 900;
  font-style: italic;
  font-size: 1.125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ctl-brake:active, .ctl-brake.down { background: #fff; color: #9c1c15; }
.ctl-jump {
  width: 84px;
  border-color: var(--yellow);
  color: var(--ink);
  background: rgba(255, 198, 26, 0.94);
  font-weight: 900;
  font-style: italic;
  font-size: 1.0625rem;
  text-transform: uppercase;
}
.ctl-jump:active, .ctl-jump.down { background: #fff; color: var(--ink); }

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

.screen {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(22, 19, 15, 0.9);
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}
.screen-dialog {
  display: grid;
  place-items: center;
  background: rgba(22, 19, 15, 0.78);
}

.menu {
  width: min(100%, 1040px);
  margin: 0 auto;
  display: grid;
  gap: 28px;
}
.hero { text-align: center; }
.logo { width: 150px; height: auto; display: block; margin: 0 auto -6px; }
.wordmark {
  margin: 0;
  font-size: clamp(2.75rem, 12vw, 4.25rem);
  line-height: 1;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: -0.03em;
  color: var(--yellow);
}
.wordmark span { color: var(--cream); }
.tagline {
  margin: 10px 0 20px;
  font-size: 1.0625rem;
  color: var(--muted);
}

.purse {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 0 16px;
}
.purse div, .over-stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}
dt {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
dd {
  margin: 2px 0 0;
  font-size: 1.25rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.trip { margin: 12px 0 0; font-size: 0.9375rem; color: var(--muted); }

.howto {
  margin: 22px 0 16px;
  padding: 0;
  list-style: none;
  text-align: left;
  display: grid;
  gap: 8px;
  font-size: 0.9375rem;
  color: var(--muted);
}
.howto li {
  padding-left: 14px;
  border-left: 3px solid var(--yellow);
}
.howto strong { color: var(--cream); }

.garage h2 {
  margin: 0 0 10px;
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.garage h2:not(:first-child) { margin-top: 22px; }
.cards { display: grid; gap: 10px; }

.card {
  width: 100%;
  min-height: 76px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  text-align: left;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.card:hover { background: var(--panel-2); }
.card[aria-pressed="true"] { border-color: var(--yellow); background: #2f2714; }
.card-art {
  width: 64px;
  height: 56px;
  display: grid;
  place-items: center;
}
.card-art canvas { width: 64px; height: 56px; }
.card-num {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 900;
  font-style: italic;
  font-size: 1.125rem;
}
.card.locked .card-num { background: #4a4034; color: var(--cream); }
.card.locked .card-art { opacity: 0.55; }
.card-name { display: block; font-weight: 800; font-size: 1.0625rem; }
.card-blurb { display: block; font-size: 0.875rem; color: var(--muted); }
.card-meta { display: block; margin-top: 2px; font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.card-tag {
  justify-self: end;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 800;
  white-space: nowrap;
  text-align: center;
  font-variant-numeric: tabular-nums;
  background: #3a322a;
  color: var(--cream);
}
.card[aria-pressed="true"] .card-tag { background: var(--yellow); color: var(--ink); }
.card.can-buy .card-tag { background: #0f7b4b; color: #fff; }
.card.armed { border-color: var(--green); }
.card-tag small { display: block; font-size: 0.6875rem; font-weight: 700; color: var(--muted); }

.fineprint { margin: 16px 0 0; font-size: 0.8125rem; color: var(--muted); }

/* ---------- dialogs ---------- */

.dialog {
  width: min(100%, 440px);
  padding: 26px 22px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.dialog-title {
  margin: 0;
  font-size: 2.125rem;
  line-height: 1.05;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: -0.02em;
  color: var(--yellow);
}
.dialog-sub { margin: 8px 0 18px; color: var(--muted); }
.dialog-actions { display: grid; gap: 10px; margin-top: 18px; }
.badge {
  display: inline-block;
  margin: 0 0 12px;
  padding: 5px 12px;
  border-radius: 999px;
  background: #0f7b4b;
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.over-score { margin: 0 0 14px; }
.over-score #over-takings {
  display: block;
  font-size: 3rem;
  line-height: 1.05;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--cream);
}
.over-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}
.over-stats div { padding: 8px 6px; background: var(--panel-2); }
.over-stats dd { font-size: 1.0625rem; }
.over-tip {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #12392a;
  color: #d9ffe9;
  font-weight: 700;
  font-size: 0.9375rem;
}

.noscript {
  position: fixed;
  inset: auto 16px 16px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--cream);
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}

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

@media (min-width: 900px) {
  .screen:not(.screen-dialog) { display: grid; align-items: center; padding: 32px; }
  .menu {
    grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
    gap: 56px;
    align-items: center;
  }
  .hero { text-align: left; }
  .logo { margin-left: -6px; width: 180px; }
  .garage {
    background: rgba(34, 29, 23, 0.6);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 24px;
  }
  .toast { top: 132px; }
}

@media (max-height: 520px) {
  .ctl { width: 60px; height: 60px; border-radius: 18px; }
  .ctl-brake { width: 88px; font-size: 1rem; }
  .ctl-jump { width: 72px; font-size: 0.9375rem; }
  .steer, .actions { gap: 8px; }
  .stat-value { font-size: 1.125rem; }
}

@media (max-width: 380px) {
  .stat { min-width: 98px; }
  .over-score #over-takings { font-size: 2.5rem; }
  .card { gap: 10px; padding: 12px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 480px) {
  .toast { top: calc(176px + env(safe-area-inset-top)); }
  .card.locked { grid-template-columns: auto 1fr; }
  .card.locked .card-tag { grid-column: 1 / -1; justify-self: stretch; }
  .card-tag small { display: inline; margin-left: 6px; }
}

/* Four buttons across a phone: a little smaller, still well over 44px. */
@media (max-width: 480px) {
  .ctl { width: 64px; height: 64px; border-radius: 20px; }
  .ctl-brake { width: 92px; font-size: 1rem; }
  .ctl-jump { width: 76px; font-size: 0.9375rem; }
  .steer, .actions { gap: 8px; }
}
