:root {
  --bg: #F2F2F7;
  --card: #FFFFFF;
  --well: #F2F2F7;
  --ink: #111114;
  --muted: #6B6D76;
  --faint: #8A8C94;
  --line: #E3E3E8;
  --glass: rgba(255, 255, 255, 0.78);
  --glass-edge: rgba(255, 255, 255, 0.9);
  --shadow: 0 1px 2px rgba(16, 20, 30, 0.06), 0 10px 30px rgba(16, 20, 30, 0.12);
  --blue: #007AFF;
  --red: #D92B34;
  --over: #D70015;
  --over-bg: rgba(255, 59, 48, 0.12);
  --law-fg: #9A5200; --law-bg: #FDF0DC;
  --sign-fg: #146B33; --sign-bg: #E3F5E9;
  --unk-fg: #62656E; --unk-bg: #ECEBE7;
  --button: #1C1C1E; --button-ink: #FFFFFF;
  --spring: cubic-bezier(0.2, 0.9, 0.25, 1.15);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #1C1C1E; --well: #2C2C2E; --ink: #FFFFFF; --muted: #98989D; --faint: #8A8A8E; --line: #2C2C2E;
    --glass: rgba(30, 30, 32, 0.72); --glass-edge: rgba(255, 255, 255, 0.08);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.5);
    --blue: #0A84FF;
    --over: #FF453A; --over-bg: rgba(255, 69, 58, 0.18);
    --law-fg: #FF9F0A; --law-bg: rgba(255, 159, 10, 0.16);
    --sign-fg: #30D158; --sign-bg: rgba(48, 209, 88, 0.16);
    --unk-fg: #98989D; --unk-bg: #2C2C2E;
    --button: #3A3A3C; --button-ink: #FFFFFF;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #1C1C1E; --well: #2C2C2E; --ink: #FFFFFF; --muted: #98989D; --faint: #8A8A8E; --line: #2C2C2E;
  --glass: rgba(30, 30, 32, 0.72); --glass-edge: rgba(255, 255, 255, 0.08);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px rgba(0, 0, 0, 0.5);
  --blue: #0A84FF;
  --over: #FF453A; --over-bg: rgba(255, 69, 58, 0.18);
  --law-fg: #FF9F0A; --law-bg: rgba(255, 159, 10, 0.16);
  --sign-fg: #30D158; --sign-bg: rgba(48, 209, 88, 0.16);
  --unk-fg: #98989D; --unk-bg: #2C2C2E;
  --button: #3A3A3C; --button-ink: #FFFFFF;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

.primary {
  font-size: 18px; font-weight: 700; color: #fff; background: var(--blue);
  border: 0; border-radius: 16px; padding: 16px; min-height: 56px;
  transition: transform 0.2s var(--spring);
}
.primary:active { transform: scale(0.97); }

/* ---------- the one screen: a map of where the car is, parked or driving ---------- */

.app { position: fixed; inset: 0; overflow: hidden; background: var(--bg); }
.scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
/* The page never zooms or scrolls; the road view handles its own fingers. */
.app { touch-action: none; }

/* Everything that hangs from the top: where the car is, then any notice. */
.top {
  position: absolute; left: 12px; right: 12px; top: calc(env(safe-area-inset-top) + 10px);
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
.top > * { pointer-events: auto; }
.road-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px 13px 18px; border-radius: 24px;
  background: var(--glass); border: 0.5px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow);
}
.rc-text { flex: 1; min-width: 0; }
.road-name {
  font-size: 25px; font-weight: 800; letter-spacing: -0.025em; line-height: 1.12;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.road-meta { margin-top: 3px; font-size: 14px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.road-meta .t { font-weight: 700; }
.t.law { color: var(--law-fg); } .t.sign { color: var(--sign-fg); } .t.unk { color: var(--unk-fg); } .t.rep { color: var(--rep-fg); }
.swap-in { animation: swap-in 0.5s var(--spring) both; }
@keyframes swap-in { from { transform: translateY(10px); opacity: 0; filter: blur(4px); } to { transform: none; opacity: 1; filter: none; } }
/* Parked, the limit where the car stands, in small. Driving, the badge has it. */
.here { --s: 46px; transition: transform 0.45s var(--spring), opacity 0.3s ease; }
.road-card.driving .here { transform: scale(0.3); opacity: 0; }

.install {
  display: flex; align-items: center; gap: 12px; padding: 11px 11px 11px 12px; border-radius: 20px;
  background: var(--glass); border: 0.5px solid var(--glass-edge); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
}
.install:not([hidden]) { animation: swap-in 0.5s var(--spring) both; }
.install .ic { flex: none; width: 38px; height: 38px; border-radius: 11px; background: var(--blue); color: #fff; display: grid; place-items: center; }
.install > div { flex: 1; min-width: 0; }
.install b { display: block; font-size: 15px; font-weight: 800; }
.install small { display: block; margin-top: 1px; font-size: 12.5px; line-height: 1.35; color: var(--muted); font-weight: 500; }
.install .x { flex: none; width: 28px; height: 28px; border: 0; border-radius: 50%; background: var(--well); color: var(--muted); display: grid; place-items: center; }

/* A demo drive, played like a video: how fast, and a bar along its route to jump about in,
   with the flyovers marked. */
.demo-bar {
  align-self: stretch; margin: 0 26px; display: flex; flex-direction: column; gap: 6px;
  padding: 7px 7px 8px 14px; border-radius: 18px;
  background: var(--glass); border: 0.5px solid var(--glass-edge); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
}
.demo-bar:not([hidden]) { animation: swap-in 0.5s var(--spring) both; }
.db-row { display: flex; align-items: center; gap: 10px; }
.db-label { font-size: 11.5px; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.db-km { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.db-rate {
  display: inline-flex; align-items: center; gap: 5px; min-width: 62px; justify-content: center;
  border: 0; border-radius: 999px; padding: 6px 12px 6px 10px;
  background: var(--well); color: var(--ink); font-size: 14.5px; font-weight: 800; font-variant-numeric: tabular-nums;
  transition: transform 0.25s var(--spring), background-color 0.25s ease, color 0.25s ease;
}
.db-rate:active { transform: scale(0.9); }
.db-rate.fast { background: var(--blue); color: #fff; }
.db-rate span { display: inline-block; }
.db-rate span.tick { animation: rate-in 0.4s var(--spring) both; }
@keyframes rate-in { from { transform: translateY(70%); opacity: 0; } to { transform: none; opacity: 1; } }
.db-track { position: relative; height: 22px; margin-right: 7px; touch-action: none; cursor: pointer; }
.db-track::before { content: ''; position: absolute; left: 0; right: 0; top: 9px; height: 4px; border-radius: 2px; background: var(--line); }
.db-fill { position: absolute; left: 0; top: 9px; height: 4px; width: 0; border-radius: 2px; background: var(--blue); }
.db-mark {
  position: absolute; top: 6px; width: 10px; height: 10px; margin-left: -5px; box-sizing: border-box;
  border-radius: 2.5px; background: var(--card); border: 2px solid var(--faint);
  transform: rotate(45deg); transition: transform 0.3s var(--spring), border-color 0.2s ease;
}
.db-mark.on { border-color: var(--blue); transform: rotate(45deg) scale(1.4); }
.db-knob {
  position: absolute; top: 2px; width: 18px; height: 18px; margin-left: -9px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28), 0 0 0 0.5px rgba(0, 0, 0, 0.08);
  transition: transform 0.25s var(--spring);
}
.db-track.dragging .db-knob { transform: scale(1.3); }
.db-km.scrub { color: var(--ink); font-weight: 800; overflow: hidden; text-overflow: ellipsis; }
.demo-bar.scrubbing .db-label { display: none; }
.pill {
  align-self: center; display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border: 0; border-radius: 999px;
  background: rgba(28, 28, 30, 0.86); color: #fff; font-size: 14px; font-weight: 600; white-space: nowrap;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.pill:not([hidden]) { animation: pill-in 0.35s var(--spring) both; }
@keyframes pill-in { from { transform: translateY(8px) scale(0.9); opacity: 0; } to { transform: none; opacity: 1; } }
/* Driving with the voice still locked: the one tap it needs, asked for where it is seen. */
.voice-pill { background: var(--blue); font-size: 15px; font-weight: 700; padding: 11px 18px; box-shadow: 0 8px 24px -8px rgba(0, 90, 200, 0.6); }
.voice-pill:not([hidden]) { animation: pill-in 0.45s var(--spring) both, breathe 2.2s ease-in-out 0.6s infinite; }
.voice-pill.done { background: rgba(28, 28, 30, 0.86); box-shadow: none; animation: none; }
@keyframes breathe { 50% { transform: scale(1.045); } }

/* ---------- the panel: home parked, gauge driving ---------- */

.dock {
  position: absolute; left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
}
.panel {
  position: relative; align-self: stretch; overflow: hidden;
  padding: 16px 16px 14px; border-radius: 32px;
  background: var(--card); box-shadow: var(--shadow);
  transition: background-color 0.4s ease;
}
.panel.over { background: color-mix(in srgb, var(--card) 88%, var(--over)); }
/* The side leaving stays where it was while it fades, so the panel sizes to what is coming. */
.body.leaving { position: absolute; left: 16px; right: 16px; top: 16px; pointer-events: none; }
.home-body { display: flex; flex-direction: column; gap: 12px; }

.greet { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; padding: 2px 4px 0; }
.tiles { display: flex; gap: 10px; }
/* Picking the vehicle is starting the drive. The one driven last is filled. */
.tile {
  position: relative; flex: 1; min-width: 0; height: 92px; border: 0; border-radius: 22px; padding: 12px 14px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; text-align: left;
  background: var(--unk-bg); color: var(--ink);
  transition: transform 0.25s var(--spring), background-color 0.35s ease, color 0.35s ease, box-shadow 0.35s ease;
}
.tile:active { transform: scale(0.95); }
.tile.last { background: var(--blue); color: #fff; box-shadow: 0 10px 22px -10px rgba(0, 100, 230, 0.7); }
.tile .tg svg { width: 32px; height: 32px; display: block; }
.tile .was { position: absolute; top: 12px; right: 11px; font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.22); }
.tile .tl { display: block; width: 100%; }
.tile b { display: block; font-size: 19px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile small { display: block; margin-top: 2px; font-size: 12.5px; font-weight: 600; opacity: 0.75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.more-tile { flex: none; width: 58px; padding: 0; align-items: center; justify-content: center; }

.gauge { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.speed { display: flex; flex-direction: column; padding-left: 4px; }
/* Current speed is the biggest thing on the screen: it is what the driver acts on. */
.speed-num {
  font-size: 92px; font-weight: 800; line-height: 0.86; letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums; transition: color 0.3s ease;
}
.speed-num.over { color: var(--over); }
.speed-num.none { color: var(--faint); font-weight: 500; }
.speed-unit { font-size: 16px; color: var(--muted); font-weight: 600; margin-top: 8px; }

.badge { display: flex; flex-direction: column; align-items: center; gap: 9px; }
/* The sign is always the real sign: white face, red rim, black number. Confidence lives
   in the label underneath, never in the sign itself. The rim is a background under the
   face, not a border: when a new number lands, Safari repaints the text's box with the
   backgrounds but not the border, and the corners of that box showed through the rim. */
.sign {
  --rim: var(--red); --face: #fff;
  position: relative; width: 108px; height: 108px; border-radius: 50%;
  border: 13px solid transparent; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(var(--face), var(--face)) padding-box, linear-gradient(var(--rim), var(--rim)) border-box;
  box-shadow: 0 2px 6px rgba(16, 20, 30, 0.1), 0 10px 24px rgba(16, 20, 30, 0.14);
}
.sign .num {
  grid-area: 1 / 1; font-size: 40px; font-weight: 800; color: #15161A; letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.sign.unknown { --rim: #C9C7C1; --face: #FAF9F7; }
.sign.unknown .num { color: #A9A7A1; }

.tier {
  font-size: 13px; font-weight: 700; padding: 5px 12px; border-radius: 999px;
  background: var(--unk-bg); color: var(--unk-fg); white-space: nowrap;
}
.tier.law { background: var(--law-bg); color: var(--law-fg); }
.tier.sign-tier { background: var(--sign-bg); color: var(--sign-fg); }

.actions { margin-top: 14px; display: flex; gap: 10px; }
/* Neutral, not red: red on this screen means over the limit and nothing else. */
/* One centred line: the small hint shares the word's baseline, and the pair sits in the
   middle of the button. */
.wrong {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 58px; border: 0; border-radius: 18px;
  background: var(--button); color: var(--button-ink);
  font-size: 21px; font-weight: 800; letter-spacing: 0.01em;
  transition: transform 0.25s var(--spring);
}
.wrong span { line-height: 1; }
.wrong small { margin-left: 10px; font-size: 13px; font-weight: 500; opacity: 0.7; letter-spacing: 0; }
.wrong:active, .wrong.flash { transform: scale(0.96); }
.more {
  width: 58px; min-height: 58px; border: 0; border-radius: 18px;
  background: var(--unk-bg); color: var(--ink); display: grid; place-items: center;
  transition: transform 0.25s var(--spring);
}
.more:active { transform: scale(0.92); }

/* A sign on its way somewhere: from the shoulder or the card into the badge, and back. */
.ghost-sign {
  position: absolute; z-index: 5; border-radius: 50%; background: #fff; border: 13px solid var(--red);
  display: grid; place-items: center; pointer-events: none;
  font-size: 40px; font-weight: 800; color: #15161A; letter-spacing: -0.04em; font-variant-numeric: tabular-nums;
}
.ghost-sign.unknown { border-color: #C9C7C1; background: #FAF9F7; color: #A9A7A1; }

/* Shown only while the view has been moved by hand, which only happens standing still. */
.recenter {
  height: 42px; padding: 0 16px 0 13px;
  display: flex; align-items: center; gap: 7px; border: 0.5px solid var(--glass-edge); border-radius: 999px;
  background: var(--glass); color: var(--blue); font-size: 15px; font-weight: 700;
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow);
}
.recenter:not([hidden]) { animation: pill-in 0.45s var(--spring) both; }
.recenter:active { transform: scale(0.95); }

/* ---------- sheets ---------- */

.sheet-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.2); opacity: 0; pointer-events: none; transition: opacity 0.3s ease; }
.sheet-scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88%; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 18px);
  border-radius: 30px 30px 0 0; background: var(--card); box-shadow: var(--shadow);
  transform: translateY(105%); transition: transform 0.5s var(--spring);
}
.sheet.open { transform: none; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 4px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.sheet h4 { margin: 0 0 14px; font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.sheet .group + h3 { margin-top: 20px; }
.sheet h3 + .group { margin-top: 7px; }
.sheet .zone { font-size: 17px; font-weight: 700; }
.sheet .reason { margin-top: 3px; font-size: 14px; color: var(--muted); line-height: 1.4; }
.rows { margin-top: 16px; border-radius: 14px; background: var(--bg); overflow: hidden; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 13px 14px; font-size: 15px; }
.row + .row { border-top: 0.5px solid var(--line); }
.row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.sheet-actions { margin-top: 16px; display: flex; gap: 10px; }
.sheet-actions button {
  flex: 1; min-height: 50px; border: 0; border-radius: 14px; font-size: 16px; font-weight: 700;
  background: var(--bg); color: var(--blue);
}
.sheet-actions .stop { color: var(--ink); }
.group { border-radius: 14px; background: var(--bg); overflow: hidden; }
.cell { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 9px 14px; border: 0; background: none; text-align: left; }
.cell + .cell { border-top: 0.5px solid var(--line); }
.cell:active { background: var(--line); }
.cell .grow { flex: 1; min-width: 0; }
.cell b { display: block; font-size: 16px; font-weight: 600; }
.cell small { display: block; margin-top: 1px; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell .val { flex: none; font-size: 14px; color: var(--muted); }
.cell .act-blue { font-size: 16px; font-weight: 600; color: var(--blue); }
.cell > svg { flex: none; color: var(--faint); }
/* The signs this phone has been taught. A row slides left over its Xoá, the way iOS lists
   do, and opens to show on a map how far its number reaches. */
.group-note { margin: 7px 14px 0; font-size: 12.5px; line-height: 1.4; color: var(--muted); }
.sheet .group-note + h3 { margin-top: 20px; }
.tsign { position: relative; overflow: hidden; }
.tsign + .tsign { border-top: 0.5px solid var(--line); }
.t-del {
  position: absolute; top: 0; right: 0; bottom: 0; width: 100%; padding-right: 22px; border: 0;
  display: flex; align-items: center; justify-content: flex-end;
  background: #FF3B30; color: #fff; font-size: 16px; font-weight: 600;
}
.t-face { position: relative; background: var(--bg); touch-action: pan-y; will-change: transform; }
.t-face.snap { transition: transform 0.45s var(--spring); }
.t-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 10px 14px; border: 0; background: none; text-align: left; color: inherit; }
.t-row .mini-sign { --s: 38px; }
.t-row .grow { flex: 1; min-width: 0; }
.t-row b { display: block; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-row small { display: block; margin-top: 1px; font-size: 13px; color: var(--muted); line-height: 1.35; }
.t-row small + small { color: var(--faint); font-size: 12px; }
.t-row .chev { flex: none; color: var(--faint); transition: transform 0.45s var(--spring); }
.tsign.open .t-row .chev { transform: rotate(90deg); }
.t-map { overflow: hidden; height: 0; transition: height 0.5s var(--spring); }
.t-map > div { margin: 0 14px 12px; border-radius: 12px; overflow: hidden; aspect-ratio: 360 / 150; background: var(--map-bg); }
.t-map svg { display: block; width: 100%; height: 100%; }
.t-map .reach { fill: none; stroke: var(--rep-fg); stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.t-map .reach-end { fill: var(--card); stroke: var(--rep-fg); stroke-width: 3; }
.tsign.open .t-map .reach { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 0.8s cubic-bezier(0.4, 0, 0.2, 1) 0.2s forwards; }
.tsign.open .t-map .reach-end { transform-box: fill-box; transform-origin: center; animation: pop 0.45s var(--spring) 0.9s both; }
.t-empty { padding: 14px; font-size: 14px; line-height: 1.45; color: var(--muted); }
.attrib { margin-top: 12px; font-size: 11px; color: var(--faint); text-align: center; }

/* Landscape on a dashboard mount: the road gets the wide side, the numbers a column. */
@media (orientation: landscape) and (max-height: 520px) {
  .top { right: auto; width: calc(58% - 18px); left: calc(env(safe-area-inset-left) + 10px); }
  .road-card { padding: 10px 14px 10px 16px; }
  .road-name { font-size: 21px; }
  .dock { left: auto; top: 10px; bottom: 10px; right: calc(env(safe-area-inset-right) + 10px); width: 40%; }
  .panel { flex: 1; display: flex; flex-direction: column; justify-content: space-between; }
  .gauge { flex: 1; }
  .speed-num { font-size: 84px; }
  /* The panel is full height here, so the way back sits beside it, over the map. */
  .recenter { position: absolute; bottom: 4px; right: calc(100% + 10px); white-space: nowrap; }
}
