:root {
  --blue: #3e6ae1;
}
#screen[data-theme="dark"] {
  --panel: #16171a;
  --card: rgba(36, 37, 41, 0.94);
  --card-line: rgba(255, 255, 255, 0.06);
  --text: #f2f3f5;
  --muted: #8d9097;
  --dock: #0d0d0f;
  --btn: rgba(44, 45, 50, 0.92);
}
#screen[data-theme="light"] {
  --panel: #e9eaec;
  --card: rgba(255, 255, 255, 0.96);
  --card-line: rgba(0, 0, 0, 0.06);
  --text: #17181a;
  --muted: #6b6e74;
  --dock: #f7f7f8;
  --btn: rgba(255, 255, 255, 0.94);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #050506; color: #ddd; font-family: -apple-system, "SF Pro Text", "Helvetica Neue", Arial, sans-serif; }
button { font: inherit; color: inherit; }

#stage { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; gap: 10px; }
.hint { margin: 0; font-size: 12px; color: #6d7076; }

#screen {
  position: relative;
  width: min(100%, calc((100vh - 64px) * 1.6));
  aspect-ratio: 16 / 10;
  border-radius: 1.4em;
  overflow: hidden;
  background: var(--panel);
  color: var(--text);
  display: grid;
  grid-template-columns: 36% 64%;
  transition: grid-template-columns .45s cubic-bezier(.3, .7, .2, 1);
  grid-template-rows: 1fr 8.5%;
  box-shadow: 0 0 0 0.6em #111, 0 0 0 0.7em #2a2a2d, 0 30px 80px rgba(0,0,0,.6);
  user-select: none;
}
#screen[data-layout="map"] { grid-template-columns: 0% 100%; }
#vis { cursor: pointer; }
/* fixed-width layer pinned to the right edge, so collapsing the panel slides it left instead of squashing it */
.visinner { position: absolute; top: 0; bottom: 0; right: 0; width: calc(var(--sw, 1440px) * .36); }
/* tab on the map's left edge that slides the driving view back in */
.vistab { position: absolute; left: 0; top: 50%; transform: translate(-100%, -50%); width: 1.6em; height: 4.6em; border: 1px solid var(--card-line); border-left: 0; border-radius: 0 .8em .8em 0; background: var(--btn); color: var(--text); display: grid; place-items: center; cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,.25); transition: transform .35s ease .15s; z-index: 4; }
.vistab svg { width: 1.1em; height: 1.1em; stroke-width: 2.4; }
#screen[data-layout="map"] .vistab { transform: translate(0, -50%); }

section { position: relative; overflow: hidden; min-width: 0; }
canvas { display: block; width: 100%; height: 100%; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Visualization panel ---------- */
#vis { background: var(--panel); }
.vis-top { position: absolute; top: 1em; left: 1.4em; right: 1.4em; display: flex; justify-content: space-between; font-size: 1.05em; letter-spacing: .12em; }
.prnd span { color: var(--muted); margin-right: .35em; }
.prnd b { color: var(--text); }
.battery { display: flex; align-items: center; gap: .5em; letter-spacing: 0; color: var(--text); }
.batt { width: 2.2em; height: 1em; border: 1.5px solid var(--muted); border-radius: .25em; padding: 1.5px; display: inline-block; }
.batt i { display: block; height: 100%; background: var(--text); border-radius: .1em; }
.speed { position: absolute; top: 2.8em; left: 1.3em; line-height: 1; }
.speed .num { font-size: 5.4em; font-weight: 300; letter-spacing: -.03em; }
.speed .unit { font-size: .95em; color: var(--muted); letter-spacing: .1em; margin-top: .3em; padding-left: .2em; }
.limit { position: absolute; top: 3.7em; right: 1.5em; width: 3.1em; padding: .3em 0 .2em; background: #fff; color: #111; border: 2px solid #111; border-radius: .35em; text-align: center; box-shadow: 0 0 0 1.5px #fff; }
.limit span { display: block; font-size: .48em; font-weight: 700; line-height: 1.1; }
.limit b { font-size: 1.55em; line-height: 1; }
.fsd { position: absolute; top: 10.2em; left: 1.6em; width: 2.2em; height: 2.2em; color: var(--blue); }
.fsd svg { width: 100%; height: 100%; stroke-width: 2; }

/* ---------- Map panel ---------- */
#map { background: var(--panel); }
#labels { position: absolute; inset: 0; pointer-events: none; }
.lbl { position: absolute; transform: translate(-50%, -100%); padding: .25em .6em; border-radius: .5em; background: var(--card); color: var(--text); font-size: .82em; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.lbl.dest { background: var(--blue); color: #fff; }
.lbl::after { content: ""; position: absolute; left: 50%; bottom: -.35em; width: .7em; height: .7em; background: inherit; transform: translateX(-50%) rotate(45deg); z-index: -1; }

.status { position: absolute; top: 0; left: 0; right: 0; height: 2.8em; display: flex; align-items: center; gap: 1em; padding: 0 1.4em; font-size: 1em; font-weight: 500; background: linear-gradient(var(--panel), transparent); }
.status .ico { width: 1.1em; height: 1.1em; }
.status .lte { font-size: .75em; color: var(--muted); }
.spacer { flex: 1; }
.netbadge { font-size: .78em; font-weight: 600; color: #fff; background: #d9442c; padding: .2em .6em; border-radius: .5em; }

.turncard { min-width: 19em; max-width: 26em; display: flex; align-items: center; gap: 1em; padding: .9em 1.3em .9em 1em; background: var(--card); border-radius: .9em; box-shadow: 0 6px 24px rgba(0,0,0,.28); border: 1px solid var(--card-line); }
.turncard .arrow { width: 3.4em; height: 3.4em; flex: none; }
.turncard .arrow svg { width: 100%; height: 100%; stroke-width: 2.2; }
.turncard .dist { font-size: 2em; font-weight: 600; line-height: 1.05; }
.turncard .road { font-size: 1.15em; color: var(--muted); margin-top: .15em; }
.then { align-self: flex-start; display: flex; align-items: center; gap: .5em; padding: .45em .9em; background: var(--card); border-radius: .7em; font-size: .92em; color: var(--muted); border: 1px solid var(--card-line); }
.then svg { width: 1.3em; height: 1.3em; color: var(--text); stroke-width: 2.4; }
.then #thenRoad { color: var(--text); font-weight: 500; }

.tripcard { position: absolute; left: 1.2em; bottom: 1.2em; width: 22em; padding: .9em 1.2em .8em; background: var(--card); border-radius: .9em; box-shadow: 0 6px 24px rgba(0,0,0,.25); border: 1px solid var(--card-line); }
.trip-row { display: flex; justify-content: space-between; }
.trip-row b { display: block; font-size: 1.35em; font-weight: 600; }
.trip-row small { color: var(--muted); font-size: .78em; }
.trip-bar { height: .25em; background: var(--card-line); border-radius: 1em; margin: .7em 0 .5em; overflow: hidden; }
.trip-bar i { display: block; height: 100%; width: 0; background: var(--blue); }
.trip-dest { font-size: .85em; color: var(--muted); }

.mapctl { position: absolute; right: 1.2em; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: .6em; }
.mapctl button { width: 3.1em; height: 3.1em; border: 1px solid var(--card-line); border-radius: .8em; background: var(--btn); display: grid; place-items: center; cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,.2); }
.mapctl button svg { width: 1.5em; height: 1.5em; }
.mapctl button.on { color: var(--blue); }
#btnPlay .play, #btnPlay.paused .pause { display: none; }
#btnPlay.paused .play { display: block; }

.navstack { position: absolute; top: 3.2em; left: 1.2em; width: 30em; display: flex; flex-direction: column; gap: .5em; z-index: 5; }
.navrow { display: flex; gap: .5em; }
.navrow .navbar { flex: 1; min-width: 0; }
.tourbtn { flex: none; display: flex; align-items: center; gap: .45em; height: 3.1em; padding: 0 1em; border: 1px solid var(--card-line); border-radius: .8em; background: var(--blue); color: #fff; font-weight: 600; font-size: .95em; cursor: pointer; box-shadow: 0 6px 24px rgba(0,0,0,.25); white-space: nowrap; }
.tourbtn svg { width: 1.15em; height: 1.15em; stroke-width: 2.2; }
.tourbtn:disabled { opacity: .6; cursor: progress; }
.explorebtn { flex: none; display: flex; align-items: center; gap: .45em; height: 3.1em; padding: 0 1em; border: 1px solid var(--card-line); border-radius: .8em; background: var(--card); color: var(--text); font-weight: 600; font-size: .95em; cursor: pointer; box-shadow: 0 6px 24px rgba(0,0,0,.25); white-space: nowrap; }
.explorebtn svg { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.explore { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; background: rgba(10, 12, 16, .38); backdrop-filter: blur(3px); }
.explore[hidden] { display: none; }
.excard { width: min(44em, 92%); max-height: 86%; display: flex; flex-direction: column; gap: .9em; padding: 1.3em 1.3em 1.1em; background: var(--card); color: var(--text); border: 1px solid var(--card-line); border-radius: 1.1em; box-shadow: 0 24px 70px rgba(0,0,0,.4); }
.exhead { display: flex; justify-content: space-between; align-items: flex-start; gap: 1em; }
.exhead b { display: block; font-size: 1.35em; letter-spacing: -.01em; }
.exhead span { display: block; margin-top: .2em; color: var(--muted); font-size: .9em; }
.exclose { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: .2em; }
.exclose svg { width: 1.4em; height: 1.4em; fill: none; stroke: currentColor; stroke-width: 2; }
.exsurprise { display: flex; align-items: center; gap: .6em; padding: .85em 1em; border: 0; border-radius: .8em; background: var(--blue); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-align: left; }
.exsurprise svg { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.exsurprise small { margin-left: auto; font-weight: 500; opacity: .85; }
.exlist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .55em; overflow-y: auto; }
.exlist li { min-width: 0; display: flex; gap: .75em; align-items: center; padding: .75em .85em; border: 1px solid var(--card-line); border-radius: .8em; cursor: pointer; transition: border-color .15s, transform .15s; }
.exlist li:hover { border-color: var(--blue); transform: translateY(-1px); }
.exlist li.next { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.exlist li.done { opacity: .6; }
.exlist i { flex: none; width: 2em; height: 2em; border-radius: 50%; display: grid; place-items: center; background: var(--card-line); font-style: normal; font-weight: 700; font-size: .85em; }
.exlist li.next i { background: var(--blue); color: #fff; }
.exlist div { min-width: 0; }
.exlist b { display: block; font-size: .95em; }
.exlist small { display: block; color: var(--muted); font-size: .78em; margin-top: .15em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exlist em { display: block; font-style: normal; color: var(--muted); font-size: .72em; margin-top: .2em; }
.navbar { display: flex; align-items: center; gap: .7em; padding: 0 .6em 0 1em; height: 3.1em; background: var(--card); border-radius: .8em; border: 1px solid var(--card-line); box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.navbar > svg { width: 1.3em; height: 1.3em; color: var(--muted); flex: none; stroke-width: 2.2; }
.navbar input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--text); font: inherit; font-size: 1.15em; font-weight: 500; }
.navbar input::placeholder { color: var(--text); opacity: .85; }
.navbar button { border: 0; background: transparent; color: var(--muted); padding: .3em; cursor: pointer; display: grid; }
.navbar button svg { width: 1.1em; height: 1.1em; }
.suggest { margin: 0; padding: .35em; list-style: none; background: var(--card); border: 1px solid var(--card-line); border-radius: .8em; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-height: 18em; overflow: auto; }
.suggest li { display: flex; gap: .8em; align-items: center; padding: .55em .7em; border-radius: .55em; cursor: pointer; }
.suggest li:hover { background: var(--card-line); }
.suggest li .pin { width: 1.3em; height: 1.3em; flex: none; color: var(--muted); }
.suggest b { display: block; font-weight: 600; font-size: .95em; }
.suggest small { color: var(--muted); font-size: .78em; }
.tripsheet { padding: 1em 1.1em .8em; background: var(--card); border-radius: .9em; border: 1px solid var(--card-line); box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.stop { display: flex; align-items: flex-start; gap: .9em; }
.stop .pin { width: 1.6em; height: 1.6em; flex: none; margin-top: .1em; fill: var(--text); stroke: var(--card); stroke-width: 1.2; }
.stoptext { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1em; }
.stoptext b { font-size: 1.1em; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stoptext > span { font-size: .9em; color: var(--text); opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stop time { font-size: .95em; color: var(--text); opacity: .85; white-space: nowrap; }
.tsbatt { display: flex; align-items: center; gap: .4em; font-size: .82em !important; opacity: .7 !important; }
.mini-batt { display: inline-block; width: 1.7em; height: .8em; border: 1.5px solid currentColor; border-radius: .2em; padding: 1px; }
.mini-batt i { display: block; height: 100%; background: #3fbf5a; border-radius: .1em; }
.tsdots { height: 1.6em; margin: .25em 0 .25em .78em; border-left: 2px dotted var(--muted); }
.tsfoot { display: flex; align-items: center; gap: .8em; margin-top: .8em; }
.tsfoot #navStatus { flex: 1; font-size: .82em; color: var(--muted); }
.tsfoot button { border: 0; border-radius: .6em; padding: .6em 1.8em; background: var(--blue); color: #fff; font-weight: 600; cursor: pointer; }
.tsfoot button:disabled { opacity: .5; cursor: default; }
.navcredit { display: block; margin-top: .6em; font-size: .62em; color: var(--muted); }
.pedals { position: absolute; right: 1.2em; bottom: 1.2em; display: flex; flex-direction: column; gap: .6em; touch-action: none; }
.pedals button { width: 4em; height: 4em; border: 1px solid var(--card-line); border-radius: 1em; background: var(--btn); display: grid; place-items: center; cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,.25); }
.pedals button svg { width: 1.8em; height: 1.8em; stroke-width: 2.6; }
.pedals button.held { background: var(--blue); color: #fff; }
.fsd.off { color: var(--muted); opacity: .5; }
.settings { position: absolute; right: 5.3em; top: 50%; transform: translateY(-50%); width: 18em; padding: 1em 1.2em 1.2em; background: var(--card); border-radius: 1em; box-shadow: 0 10px 40px rgba(0,0,0,.35); border: 1px solid var(--card-line); font-size: .9em; }
.settings h3 { margin: 0 0 .6em; font-size: 1.05em; }
.settings label { display: block; margin: .7em 0; color: var(--muted); }
.settings output { float: right; color: var(--text); font-variant-numeric: tabular-nums; }
.settings input[type=range] { width: 100%; margin-top: .4em; accent-color: var(--blue); }
.settings label.check { display: flex; align-items: center; gap: .6em; color: var(--text); cursor: pointer; }
.settings label.check input { accent-color: var(--blue); width: 1.1em; height: 1.1em; }
.seg { display: flex; background: var(--card-line); border-radius: .6em; padding: .2em; margin: 1em 0 .7em; }
.seg button { flex: 1; border: 0; background: transparent; padding: .45em; border-radius: .45em; cursor: pointer; }
.seg button.on { background: var(--blue); color: #fff; }
.settings .note { margin: 0 0 .7em; font-size: .85em; color: var(--muted); }
.settings .wide { width: 100%; padding: .6em; border: 1px solid var(--card-line); background: var(--btn); border-radius: .6em; cursor: pointer; }

.arrived { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); padding: 1.2em 2em; background: var(--card); border-radius: 1em; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
.arrived b { display: block; font-size: 1.5em; }
.arrived span { color: var(--muted); }
.attrib { position: absolute; right: .8em; bottom: .5em; font-size: .62em; color: var(--muted); opacity: .8; }

/* ---------- Dock ---------- */
#dock { grid-column: 1 / -1; display: flex; align-items: center; gap: 2.2em; padding: 0 2.2em; background: var(--dock); border-top: 1px solid var(--card-line); }
#dock .ico { width: 1.7em; height: 1.7em; color: var(--text); }
#dock .ico.car { width: 2.6em; }
.climate { display: flex; align-items: center; gap: .8em; font-size: 1.1em; }
.climate b { font-size: 1.5em; font-weight: 400; }
.climate span { color: var(--muted); }
.app { width: 2.3em; height: 2.3em; border-radius: .6em; background: var(--c); display: grid; place-items: center; color: #fff; }
.app svg { width: 1.3em; height: 1.3em; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; background: var(--panel); font-size: 1.2em; color: var(--muted); z-index: 10; }
.loading.gone { display: none; }
.bootfail { display: grid; gap: 12px; justify-items: center; text-align: center; max-width: 34em; }
.bootfail b { color: var(--text, #111); font-weight: 600; }
.bootfail span { font-size: .8em; }
.bootfail button { font: inherit; font-size: .8em; padding: 8px 22px; border-radius: 999px; border: 0; background: #3e6ae1; color: #fff; cursor: pointer; }
[hidden] { display: none !important; }

/* ?capture: fill a 16:9 frame with the screen, no hint line */
body.capture .hint { display: none; }
body.capture #stage { padding: 28px; }
body.capture #screen { width: min(100%, calc((100vh - 56px) * 1.6)); }

/* engine sound toggle */
.dockbtn { border: 0; background: transparent; padding: 0; cursor: pointer; display: grid; color: var(--text); }
.dockbtn .mute { display: none; }
.dockbtn.muted .waves { display: none; }
.dockbtn.muted .mute { display: inline; }

/* sonic boom: white shock flash rippling from the centre, plus a short camera shake */
#map::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 55%, rgba(255,255,255,.95) 0%, rgba(255,255,255,.55) 18%, rgba(255,255,255,0) 55%); }
#map.boom::after { animation: boomflash .7s ease-out; }
#map.boom #mapCanvas { animation: boomshake .5s cubic-bezier(.36,.07,.19,.97); }
@keyframes boomflash { 0% { opacity: 0; transform: scale(.6); } 8% { opacity: 1; } 100% { opacity: 0; transform: scale(1.6); } }
@keyframes boomshake {
  10%, 90% { transform: translate(-2px, 1px); } 20%, 80% { transform: translate(4px, -3px); }
  30%, 50%, 70% { transform: translate(-7px, 4px); } 40%, 60% { transform: translate(7px, -4px); }
}


.settings .setlabel { margin: .9em 0 -.5em; color: var(--muted); }
