/* Forest stage theme: pine-dark panels, stage-board yellow, livery stripes. */
:root {
  --forest-0: #0b1410;
  --forest-1: #122019;
  --forest-2: #1a2d23;
  --forest-3: #24392d;
  --line: #2e4738;
  --paper: #e6e9d6;
  --paper-ink: #1c241d;
  --paper-muted: #5f6b55;
  --ink: #eef1e6;
  --muted: #93a495;
  --accent: #ffc20e;      /* stage-board yellow */
  --accent-dim: #b8890a;
  --signal: #ff5a1f;      /* hi-vis orange */
  --sky: #2fa3e6;         /* livery blue */
  --red: #e5483c;
  --green: #6cc15f;
  --blue: #4fa3e0;
  --radius: 6px;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Barlow", system-ui, sans-serif;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --livery: linear-gradient(90deg, var(--accent) 0 52%, transparent 52% 55%, var(--signal) 55% 78%, transparent 78% 81%, var(--sky) 81%);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  min-height: 100vh;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='110' viewBox='0 0 220 110'%3E%3Cg fill='%23142a1e'%3E%3Cpolygon points='30,8 46,40 38,40 54,68 44,68 62,98 -2,98 16,68 6,68 22,40 14,40'/%3E%3Cpolygon points='92,30 104,54 98,54 110,76 102,76 116,100 68,100 82,76 74,76 86,54 80,54'/%3E%3Cpolygon points='160,0 178,36 170,36 188,66 178,66 198,100 122,100 142,66 132,66 150,36 142,36'/%3E%3Cpolygon points='212,40 222,60 217,60 227,80 220,80 230,100 194,100 204,80 197,80 207,60 202,60'/%3E%3C/g%3E%3Crect y='98' width='220' height='12' fill='%23142a1e'/%3E%3C/svg%3E") left bottom / 220px 110px repeat-x fixed,
    radial-gradient(ellipse 120% 60% at 50% -10%, #1f3d2d 0%, transparent 70%),
    var(--forest-0);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2 { font-family: var(--display); font-style: italic; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; margin: 0 0 .5rem; }
h2 { font-size: 1.35rem; color: var(--accent); }
b { font-family: var(--mono); font-weight: 600; }

/* ---------- buttons & inputs */
.btn {
  font: italic 700 15px var(--display);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--forest-3);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: .6rem 1rem;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent-dim); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary, .btn.on { background: var(--accent); color: #141006; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: .35rem .7rem; font-size: 13px; }
.btn.wide { width: 100%; margin-top: .75rem; font-size: 19px; padding: .8rem; }
input:not([type=checkbox]) {
  font: 16px var(--mono);
  background: var(--forest-0);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: .6rem .75rem;
}
input[aria-invalid] { border-color: var(--red); box-shadow: 0 0 0 3px rgba(229,72,60,.25); }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; }
input:focus-visible, .btn:focus-visible, .car-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.error { color: var(--red); min-height: 1.4em; margin: .75rem 0 0; }

.panel {
  background: var(--forest-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

/* ---------- lobby */
#lobby { max-width: 900px; margin: 0 auto; padding: 2rem 16px 9rem; }
.brand { text-align: center; margin: 1rem 0 2rem; }
.brand h1 {
  font-size: clamp(3.2rem, 12vw, 6.5rem);
  font-weight: 900;
  line-height: .88;
  color: var(--ink);
  text-shadow: 3px 3px 0 #000;
}
.brand::after {
  content: "";
  display: block;
  width: min(460px, 80%);
  height: 10px;
  margin: 1rem auto 0;
  background: var(--livery);
  transform: skewX(-24deg);
}
.brand p { color: var(--accent); margin: .6rem 0 0; letter-spacing: .14em; text-transform: uppercase; font: italic 700 15px var(--display); }
.field { display: grid; gap: .35rem; margin-bottom: 1.25rem; font-weight: 600; }
.car-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; }
.car-card {
  text-align: left;
  background: var(--forest-0);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: .85rem;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  position: relative;
  overflow: hidden;
}
.car-card:hover { border-color: var(--accent-dim); }
.car-card.on { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,194,14,.18); }
.car-card.on::before {
  content: "";
  position: absolute; top: 0; right: -14px;
  width: 90px; height: 6px;
  background: var(--livery);
  transform: skewX(-24deg);
}
.car-icon { display: block; width: 100%; max-width: 168px; height: auto; margin: 0 0 .35rem; }
.car-title-icon { width: 48px; height: auto; vertical-align: middle; margin-right: .4rem; }
.car-card h3 { font: italic 800 1.6rem var(--display); text-transform: uppercase; margin: 0; }
.car-card p { color: var(--muted); font-size: 13px; margin: .2rem 0 .6rem; min-height: 2.6em; }
.lobby-actions { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between; margin-top: 1.5rem; }
.join { display: flex; gap: .5rem; }
.join input { width: 8.5rem; text-transform: uppercase; letter-spacing: .2em; }

/* ---------- stat bars */
.stats { display: grid; gap: .3rem; }
.stat { display: grid; grid-template-columns: 6.5rem 1fr 1.6rem; align-items: center; gap: .5rem; font-size: 13px; }
.stat .pips { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; }
.stat .pips i { height: 8px; background: var(--forest-3); transform: skewX(-20deg); }
.stat .pips i.f { background: var(--accent); }
.stat b { text-align: right; }

/* ---------- race layout */
.topbar {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  padding: .6rem 16px .75rem;
  background: var(--livery) left bottom / 100% 4px no-repeat, #08100c;
  position: sticky; top: 0; z-index: 5;
}
.logo { font: italic 900 1.7rem var(--display); color: var(--ink); text-transform: uppercase; margin-right: .5rem; }
.pill { font-size: 13px; color: var(--muted); background: var(--forest-2); border: 1px solid var(--line); border-radius: 3px; padding: .2rem .65rem; }
.pill b { color: var(--accent); }
.turn-banner { margin-left: auto; font: italic 700 17px var(--display); text-transform: uppercase; letter-spacing: .03em; }
.turn-banner.mine { color: #141006; background: var(--accent); padding: .2rem .9rem; transform: skewX(-12deg); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; padding: 16px 16px 8rem; align-items: start; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }
.side { display: grid; gap: 12px; }

.map-wrap { position: sticky; top: 64px; display: grid; gap: .5rem; }
@media (max-width: 1000px) { .map-wrap { position: relative; top: auto; } }
/* Map paper with faint topo contours */
#map {
  width: 100%; height: auto; display: block;
  border-radius: var(--radius);
  border: 3px solid #0a130e;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='320' height='240' viewBox='0 0 320 240'%3E%3Cg fill='none' stroke='%23c8d0b3' stroke-width='1.2'%3E%3Cpath d='M0 40 C60 10 110 70 170 44 S280 20 320 40'/%3E%3Cpath d='M0 120 C50 96 120 150 190 118 S280 96 320 120'/%3E%3Cpath d='M0 200 C70 176 130 228 200 200 S290 182 320 200'/%3E%3Cellipse cx='240' cy='160' rx='34' ry='18'/%3E%3Cellipse cx='240' cy='160' rx='18' ry='9'/%3E%3Cellipse cx='70' cy='78' rx='28' ry='14'/%3E%3C/g%3E%3C/svg%3E") 0 0 / 320px 240px,
    var(--paper);
}
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; font-size: 12px; color: var(--muted); }
.lg { display: inline-block; width: 20px; height: 4px; margin-right: 5px; vertical-align: middle; border-radius: 2px; }
.lg.highway { background: #3b3f3c; }
.lg.twisty { background: #d9480f; }
.lg.gravel { background: repeating-linear-gradient(90deg, #9a6b33 0 4px, transparent 4px 7px); }
.lg.city { background: #56607a; }
.wait { margin-top: .5rem; }
.wait .btn + .btn { margin-left: .5rem; }

/* map svg styling */
/* weather labels, roads and legend items on the map, with a hover/focus tooltip */
.wx-label { cursor: help; outline: none; }
.wx-pill { fill: rgba(255,255,255,.55); stroke: rgba(28,36,29,.25); }
.wx-label:hover .wx-pill, .wx-label:focus-visible .wx-pill { fill: #fff; stroke: var(--paper-ink); }
.map-tip {
  position: absolute; z-index: 4;
  max-width: 260px;
  padding: .6rem .75rem;
  background: var(--forest-0);
  color: var(--ink);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-size: 13px;
  pointer-events: none;
}
.map-tip b { display: block; font: italic 800 16px var(--display); text-transform: uppercase; color: var(--accent); }
.map-tip small { color: var(--muted); }
.map-tip ul { margin: .3rem 0 0; padding-left: 1.1rem; display: grid; gap: .2rem; }
.region-label { pointer-events: none; font: italic 800 14px var(--display); text-transform: uppercase; letter-spacing: .06em; fill: #4d5b45; }
.road { fill: none; stroke-linecap: round; }
.road-hit { stroke: transparent; stroke-width: 16; stroke-linecap: round; }
.road-group { cursor: help; }
.road-group.pick { cursor: pointer; }
.road-group:hover .road { filter: drop-shadow(0 0 3px rgba(0,0,0,.55)); }
.road-miles { pointer-events: none; }
.lg-item { cursor: help; border-bottom: 1px dotted var(--muted); }
.lg-item:hover, .lg-item:focus-visible { color: var(--ink); outline: none; }
.road.highway { stroke: #3b3f3c; }
.road.twisty { stroke: #d9480f; }
.road.gravel { stroke: #9a6b33; stroke-dasharray: 6 5; }
.road.city { stroke: #56607a; }
.road.option { stroke: var(--accent); filter: drop-shadow(0 0 3px rgba(0,0,0,.6)); cursor: pointer; }
.road.option.chosen { stroke: var(--sky); }
.road-miles { font: 10px var(--mono); fill: #4d5b45; }
.town circle { fill: #fbfcf4; stroke: var(--paper-ink); stroke-width: 2; }
.town.detour circle { stroke-dasharray: 3 2; }
.town text { font: 600 11px var(--sans); fill: var(--paper-ink); paint-order: stroke; stroke: var(--paper); stroke-width: 3px; }
.town .icon { font-size: 12px; stroke: none; }
.car-dot { stroke: #111; stroke-width: 2; }
.car-dot.me { stroke: #fff; stroke-width: 3; }
.car-label { font: 700 10px var(--mono); fill: #fff; pointer-events: none; }

/* gauges */
.gauges { display: grid; gap: .4rem; margin: .8rem 0 .6rem; }
.gauge { display: grid; grid-template-columns: 3rem 1fr 5.5rem; gap: .5rem; align-items: center; font-size: 13px; }
.gauge b { text-align: right; }
.bar { height: 10px; background: var(--forest-3); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); transition: width .3s; }
.bar.heat i { background: var(--blue); }
.bar.heat i.hot { background: var(--red); }
.kv { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: 13px; color: var(--muted); }
.kv b { color: var(--ink); }

/* chance card: a pace-note card */
.chance {
  border-radius: var(--radius);
  padding: 1rem 1rem .9rem;
  background: var(--paper);
  color: var(--paper-ink);
  border-left: 8px solid var(--muted);
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.chance.good { border-left-color: var(--green); }
.chance.bad { border-left-color: var(--red); }
.chance.neutral { border-left-color: var(--accent-dim); }
.chance small { text-transform: uppercase; letter-spacing: .12em; font-size: 11px; color: var(--paper-muted); }
.chance h3 { font: italic 800 1.8rem var(--display); text-transform: uppercase; margin: .1rem 0 .2rem; }
.chance p { margin: 0; }
.chance .note { margin-top: .5rem; font-weight: 600; }

/* drive panel */
.drive .push { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin: .5rem 0 .3rem; }
.choice { display: grid; gap: .35rem; margin: .4rem 0 .6rem; }
.choice .label { font-size: 13px; color: var(--muted); }
.choice .btn { text-align: left; font: 400 14px var(--sans); text-transform: none; letter-spacing: 0; }
.choice .btn b { font-weight: 600; }
.check { display: flex; gap: .5rem; align-items: center; font-size: 14px; margin-top: .45rem; }

/* garage */
.shop { display: grid; gap: .4rem; }
.part { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; align-items: center; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 3px; background: var(--forest-0); }
.part h4 { margin: 0; font-size: 15px; }
.part .mods { font: 12px var(--mono); color: var(--muted); grid-column: 1; }
.part .mods .up { color: var(--green); }
.part .mods .down { color: var(--red); }
.part .btn { grid-row: 1 / span 2; grid-column: 2; }
.part.rare { border-color: var(--accent-dim); }

/* start-line garage popup */
.garage-modal {
  width: min(940px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
}
.garage-modal[open] { animation: result-in .22s ease-out; }
.garage-modal::backdrop { background: rgba(4,9,6,.75); }
.garage-modal .btn.wide { margin-top: .75rem; }
.drive .open-garage { width: 100%; margin-top: .75rem; }
#garage.featured {
  border: 2px solid var(--accent);
  background: var(--livery) left top / 100% 5px no-repeat, var(--forest-1);
  padding: 1.2rem 1.2rem 1.1rem;
}
#garage.featured h2 { font-size: 2.1rem; font-weight: 900; color: var(--ink); margin-top: .2rem; }
#garage.featured .shop { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .5rem; }
.garage-intro { display: grid; gap: .5rem; margin: 0 0 1rem; color: var(--muted); }
.garage-stats { display: flex; flex-wrap: wrap; gap: .5rem 1.5rem; color: var(--ink); font: italic 700 17px var(--display); text-transform: uppercase; }
.garage-stats b { font: italic 900 1.6rem var(--display); color: var(--accent); margin-left: .2rem; }
.tag { font: 11px var(--mono); color: var(--accent); margin-left: .3rem; }

/* standings + log */
.standings { margin: 0; padding-left: 1.4rem; display: grid; gap: .3rem; font-size: 15px; }
.standings ::marker { font: italic 800 16px var(--display); color: var(--accent); }
.standings .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .4rem; vertical-align: middle; }
.standings .meta { color: var(--muted); font-size: 12px; }
.log { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; font-size: 13px; display: grid; gap: .3rem; }
.log li { color: var(--muted); }
.log li.me { color: var(--ink); }
.log li span { font-family: var(--mono); color: var(--accent-dim); margin-right: .35rem; }
/* roll explanation: what you scored vs what you needed */
.roll-explain { display: grid; gap: .4rem; margin: 0 0 .9rem; font-size: 14px; }
.roll-sum { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
.roll-sum > b { font-size: 15px; margin-left: .15rem; }
.roll-label { width: 6.2rem; color: var(--muted); font-size: 13px; }
.chip { background: var(--forest-3); border: 1px solid var(--line); border-radius: 3px; padding: .05rem .45rem; white-space: nowrap; }
.chip.die { background: var(--accent); color: #141006; border-color: var(--accent); font-weight: 600; }
.roll-verdict { margin: .2rem 0 0; font-weight: 600; }
.roll-verdict.pass { color: var(--green); }
.roll-verdict.slow { color: var(--accent); }
.roll-verdict.crash { color: var(--red); }

/* chance card modal */
.card-modal {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
.card-modal[open] { animation: card-in .35s cubic-bezier(.2, .9, .3, 1.2); }
.card-modal::backdrop { background: rgba(4,9,6,.75); }
.card-modal .chance { padding: 1.4rem 1.4rem 1.2rem; border-left-width: 12px; font-size: 17px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.card-modal .chance h3 { font-size: 2.6rem; line-height: 1; margin: .3rem 0 .5rem; }
.card-modal .chance .note { margin-top: .8rem; padding-top: .6rem; border-top: 1px dashed #b9bea5; }
.card-modal .btn.wide { margin-top: .9rem; }
@keyframes card-in { from { opacity: 0; transform: translateY(-30px) rotate(-4deg) scale(.95); } }

/* turn result modal */
.result-modal {
  width: min(440px, calc(100vw - 32px));
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-top: 8px solid var(--muted);
  border-radius: var(--radius);
  background: var(--forest-1);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.result-modal[open] { animation: result-in .22s ease-out; }
.result-modal::backdrop { background: rgba(4,9,6,.75); }
.result-modal.pass { border-top-color: var(--green); }
.result-modal.slow { border-top-color: var(--accent); }
.result-modal.crash { border-top-color: var(--red); }
.result-head small { text-transform: uppercase; letter-spacing: .1em; font-size: 12px; color: var(--muted); }
.result-head h2 { font-size: 2.6rem; font-weight: 900; line-height: 1; margin: .2rem 0 .3rem; }
.result-modal.pass h2 { color: var(--green); }
.result-modal.crash h2 { color: var(--red); }
.result-head p { margin: 0; color: var(--muted); }
.result-miles { margin: .9rem 0 .1rem; font: italic 800 1.4rem var(--display); text-transform: uppercase; }
.result-miles b { font: italic 900 3.4rem var(--display); color: var(--ink); }
.result-where { margin: 0 0 .9rem; font-weight: 600; }
.result-grid { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; margin: 0; padding: .75rem 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 14px; }
.result-grid dt { color: var(--muted); }
.result-grid dd { margin: 0; }
.result-grid dd.bad b { color: var(--red); }
.result-notes { margin: .75rem 0 0; padding-left: 1.2rem; display: grid; gap: .25rem; }
@keyframes result-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }

.toast {
  visibility: hidden;
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(150%);
  background: var(--red); color: #fff; padding: .7rem 1.1rem; border-radius: 3px;
  font-weight: 600; transition: transform .25s; max-width: calc(100vw - 32px);
}
.toast.show { visibility: visible; transform: translateX(-50%) translateY(0); }

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