:root {
  --bg: #14161d;
  --panel: #1e212b;
  --panel-2: #282c39;
  --text: #f3efe6;
  --muted: #9aa0ad;
  --accent: #ff5a36;
  --accent-2: #ffc93c;
  --good: #5ad17a;
  --bad: #ff7b6b;
  --radius: 14px;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
}

kbd {
  font-family: inherit;
  font-size: 0.8em;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  padding: 1px 6px;
}

/* ---- Header ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 16px;
}
.logo {
  font-family: Bungee, Impact, sans-serif;
  font-size: 28px;
  color: var(--accent);
  letter-spacing: 1px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.logo span { color: var(--text); margin-left: 6px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.next { color: var(--muted); font-size: 14px; }
.pill {
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  color: var(--text);
  background: var(--panel);
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.pill:hover { background: var(--panel-2); }
.pill.icon { width: 36px; padding: 8px 0; text-align: center; }
code { background: rgba(255, 255, 255, 0.08); border-radius: 5px; padding: 1px 5px; font-size: 0.9em; }
a { color: var(--accent-2); }
#next-countdown { color: var(--text); font-weight: 800; font-variant-numeric: tabular-nums; }

/* ---- Layout ---- */
.layout {
  display: flex;
  justify-content: center;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 16px 24px;
}
.content { flex: 1; max-width: 1000px; min-width: 0; }

/* ---- Home ---- */
.hero { text-align: center; padding: 28px 0 18px; }
.hero h1 {
  font-family: Bungee, Impact, sans-serif;
  font-weight: 400;
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.1;
  margin: 10px 0;
}
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); margin: 18px 0 10px; }
.home-tracks { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.track-card {
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}
.track-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.track-card canvas { display: block; width: 100%; height: auto; aspect-ratio: 1000 / 650; }
.track-card-info { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.track-card-text { flex: 1; min-width: 0; }
.track-card-name { font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-card-best { text-align: right; font-size: 13px; font-weight: 800; white-space: nowrap; }
.home-cta { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-top: 16px; }
.btn.big { font-size: 18px; padding: 16px; margin-top: 0; }
.home-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 18px; }
.card h3 { margin: 0 0 6px; }
.card p { margin: 6px 0; }
.mode-card {
  font: inherit;
  color: var(--text);
  text-align: left;
  border: 2px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform 0.12s, border-color 0.12s;
}
.mode-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.mode-card canvas { display: block; width: 100%; height: auto; aspect-ratio: 1000 / 650; border-radius: 10px; }
.garage-card {
  font: inherit;
  color: var(--text);
  text-align: left;
  border: 2px solid transparent;
  cursor: pointer;
  display: flex;
  gap: 14px;
  align-items: center;
}
.garage-card:hover { border-color: var(--accent); }
.garage-card canvas { width: 150px; height: 60px; border-radius: 10px; flex: none; }

/* ---- Garage pop-up ---- */
.garage-big { display: block; width: 100%; height: auto; border-radius: 12px; margin-top: 10px; }
.garage-caption { margin: 10px 0 2px; font-size: 18px; }
.style-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.style-card {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  cursor: pointer;
}
.style-card canvas { width: 100%; height: auto; border-radius: 8px; }
.style-card.active { border-color: var(--accent); }
.style-card:disabled { cursor: not-allowed; }
.style-name { font-weight: 800; font-size: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--panel);
  box-shadow: 0 0 0 2px var(--panel-2);
  cursor: pointer;
}
.swatch.active { box-shadow: 0 0 0 3px var(--accent); }
.unlock {
  margin: 10px 0;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 201, 60, 0.15);
  color: var(--accent-2);
  font-weight: 600;
}
.unlock .btn { margin-top: 8px; }
@media (max-width: 520px) { .style-grid { grid-template-columns: repeat(2, 1fr); } }
.badge {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #1a0e0a;
  background: var(--accent-2);
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}

/* ---- Race screen ---- */
.play-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.play-title { font-weight: 800; color: var(--muted); text-align: center; flex: 1; }

.ad-slot {
  border: 1px dashed #3a3f4d;
  border-radius: 10px;
  color: #5b6170;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.ad-side { width: 160px; height: 600px; flex: none; position: sticky; top: 16px; }
.ad-banner { height: 90px; max-width: 728px; margin: 16px auto 0; }
@media (max-width: 1399px) { .ad-side { display: none; } }

/* ---- Track tabs ---- */
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; }
.tab {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-areas: "num name dots" "num best best";
  column-gap: 10px;
  align-items: center;
  min-width: 0;
}
.tab:hover:not(:disabled) { background: var(--panel-2); }
.tab.active { border-color: var(--accent); }
.tab:disabled { cursor: default; opacity: 0.6; }
.tab-num {
  grid-area: num;
  font-family: Bungee, Impact, sans-serif;
  font-size: 26px;
  color: var(--accent);
}
.tab-name { grid-area: name; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-best { grid-area: best; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.tab-dots { grid-area: dots; color: var(--accent-2); letter-spacing: 2px; font-size: 12px; }

/* ---- Stage ---- */
.stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
#game { display: block; width: 100%; height: auto; aspect-ratio: 1000 / 650; }

.hud { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel); }
.hud-box {
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
}
.hud-box + .hud-box { border-left: 1px solid rgba(255, 255, 255, 0.06); }
.hud-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.hud-box span:last-child { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }

.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  font-family: Bungee, Impact, sans-serif;
  font-size: clamp(48px, 12vw, 120px);
  color: var(--accent-2);
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
}

/* ---- Overlay panels ---- */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(12, 14, 20, 0.55);
  backdrop-filter: blur(2px);
}
.overlay.show { display: flex; }
.panel {
  width: 100%;
  max-width: 420px;
  max-height: 100%;
  overflow: auto;
  background: var(--panel);
  border-radius: 18px;
  padding: 22px 26px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.panel h2 { font-family: Bungee, Impact, sans-serif; font-weight: 400; font-size: 28px; margin: 4px 0 12px; }
.kicker { color: var(--accent); font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.targets { display: flex; justify-content: center; gap: 16px; font-weight: 800; font-variant-numeric: tabular-nums; }
.big-time { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 10px 0 4px; }
.delta { font-weight: 800; margin-bottom: 14px; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }

.btn {
  font: inherit;
  font-weight: 800;
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  color: var(--text);
  background: var(--panel-2);
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { background: var(--accent); color: #1a0e0a; }
.btn.primary kbd { background: rgba(0, 0, 0, 0.15); }

.summary { width: 100%; border-collapse: collapse; margin: 8px 0 12px; text-align: left; }
.summary td { padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.summary .num { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.summary .total td { border-bottom: 0; font-weight: 800; }

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 9, 13, 0.7);
  backdrop-filter: blur(3px);
}
.modal-panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--panel);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-panel h2 { font-family: Bungee, Impact, sans-serif; font-weight: 400; margin: 0 0 6px; padding-right: 30px; }
.modal-panel h3 { margin: 18px 0 8px; }
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}

.form { display: grid; gap: 10px; margin-top: 14px; }
.form input {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 2px solid var(--panel-2);
  border-radius: 12px;
  padding: 12px 14px;
}
.form input:focus { outline: none; border-color: var(--accent); }
.form .btn { margin-top: 0; }
.form-msg { min-height: 1em; font-weight: 600; }
.form-msg:empty { display: none; }
.link-btn {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-2);
  background: none;
  border: 0;
  padding: 8px 0 0;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 6px 0 4px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--panel-2); }
.form-msg.good { color: var(--good); }
.form-msg.bad { color: var(--bad); }

.segs { display: flex; gap: 6px; flex-wrap: wrap; margin: 14px 0; }
.seg {
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  color: var(--muted);
  background: var(--panel-2);
  border: 0;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
}
.seg.active { background: var(--accent); color: #1a0e0a; }
.mode-segs { margin-bottom: 4px; }
.mode-segs .seg { font-size: 14px; padding: 9px 14px; }
.mode-segs .seg.active { background: var(--text); }

.board { list-style: none; margin: 0; padding: 0; }
.board li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.board li.me { background: rgba(255, 90, 54, 0.15); border-radius: 8px; }
.board .rank { color: var(--muted); font-weight: 800; }
.board .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-weight: 800; font-variant-numeric: tabular-nums; }
.board-me { margin-top: 10px; padding: 10px; border-radius: 10px; background: var(--panel-2); font-weight: 800; text-align: center; }

.table-scroll { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.history-table th { text-align: left; color: var(--muted); font-size: 12px; padding: 6px 6px; }
.history-table td { padding: 8px 6px; border-top: 1px solid rgba(255, 255, 255, 0.06); white-space: nowrap; }

.btn.danger { background: #c2361a; color: #fff; }
.btn.danger-link { background: none; color: var(--bad); font-weight: 600; font-size: 14px; }

.howto { list-style: none; margin: 14px 0; padding: 0; display: grid; gap: 12px; }
.howto li { display: flex; gap: 12px; align-items: flex-start; }
.howto-icon {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.howto p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* ---- Cookie banner ---- */
.consent {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 15; /* below pop-ups, above the game */
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  background: var(--panel-2);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.consent p { margin: 0; font-size: 14px; flex: 1; }
.consent-buttons { display: flex; gap: 8px; flex: none; }
.consent-buttons .btn { margin: 0; width: auto; padding: 10px 14px; white-space: nowrap; }
.consent-buttons .btn:not(.primary) { background: var(--panel); }
@media (max-width: 640px) {
  .consent { flex-direction: column; align-items: stretch; }
  .consent-buttons .btn { flex: 1; }
}

/* ---- Privacy page ---- */
.legal { max-width: 760px; margin: 0 auto; padding: 0 16px 48px; line-height: 1.6; }
.legal h1 { font-family: Bungee, Impact, sans-serif; font-weight: 400; }
.legal h2 { margin-top: 32px; font-size: 20px; }
.legal li { margin-bottom: 6px; }
.legal table { width: 100%; border-collapse: collapse; font-size: 14px; }
.legal th, .legal td { text-align: left; padding: 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); vertical-align: top; }
.todo { background: rgba(255, 201, 60, 0.18); color: var(--accent-2); border-radius: 4px; padding: 0 4px; }

/* ---- Touch controls ---- */
/* Holding a button must never select its text, pop up the copy/look-up menu,
   flash a tap highlight or zoom the page. The race area gets the same treatment. */
.touch, .touch *, .stage, .stage .hud {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.touch { display: none; justify-content: space-between; gap: 12px; margin-top: 12px; touch-action: none; }
.touch-group { display: flex; gap: 10px; }
.touch button {
  font: inherit;
  font-weight: 800;
  color: var(--text);
  background: var(--panel);
  border: 0;
  border-radius: 16px;
  width: 74px;
  height: 74px;
  touch-action: none;
  outline: none;
}
.touch button.gas { background: var(--accent); color: #1a0e0a; }
.touch button.held { filter: brightness(1.35); }

.help { color: var(--muted); font-size: 13px; text-align: center; margin: 12px 0 0; }
.footer { color: #5b6170; font-size: 12px; text-align: center; padding: 0 16px 24px; }
.footer a { color: inherit; }

@media (pointer: coarse) {
  .touch { display: flex; }
  .help { display: none; }
}

@media (max-width: 800px) {
  .home-tracks { grid-template-columns: 1fr; }
  .track-card { display: grid; grid-template-columns: 140px 1fr; align-items: center; }
  .home-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .logo { font-size: 22px; }
  .next { display: none; }
  .hero-line { display: block; } /* one sentence per line on phones */
  .wide-only { display: none; }
  .home-cta { grid-template-columns: 1fr; }
  .track-card { grid-template-columns: 110px 1fr; }
  .track-card-info { flex-wrap: wrap; padding: 8px 10px; }
  .track-card .tab-num { display: none; }
  .overlay { position: fixed; z-index: 10; }
  .hud-box { padding: 6px 10px; }
  .hud-box span:last-child { font-size: 15px; }
  .tab { grid-template-columns: auto 1fr; grid-template-areas: "num name" "num best"; padding: 8px; }
  .tab-dots { display: none; }
  .tab-num { font-size: 20px; }
  .tab-name { font-size: 13px; }
  .tab-best { font-size: 11px; }
}
