:root {
  --glass: rgba(16, 18, 22, 0.82);
  --line: rgba(255, 255, 255, 0.10);
  --ink: #f2f4f7;
  --dim: #9aa3ad;
  --blue: #2f7bff;
  --red: #ff3b30;
  --green: #31d158;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0d10; color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent; user-select: none; }
#map { position: fixed; inset: 0; }
.cesium-viewer-bottom { bottom: calc(86px + var(--safe-b)) !important; left: 8px !important; opacity: .75; }
.hidden { display: none !important; }

.card { position: fixed; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 8px 30px rgba(0,0,0,.35); z-index: 10; }

/* Speed */
.speed { top: calc(14px + var(--safe-t)); left: 14px; padding: 10px 16px; text-align: center; min-width: 96px; }
#speed { font-size: 44px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.unit { font-size: 12px; color: var(--dim); }
.gear { margin-top: 6px; font-weight: 700; font-size: 14px; letter-spacing: .1em; color: var(--dim); }
.gear.rev { color: var(--red); }

/* Next turn */
.turn { top: calc(14px + var(--safe-t)); left: 124px; display: flex; gap: 12px; align-items: center; padding: 12px 18px 12px 12px; max-width: min(460px, calc(100vw - 250px)); }
.turn-icon { width: 54px; height: 54px; border-radius: 12px; background: var(--blue); display: grid; place-items: center; flex: none; }
.turn-icon svg { width: 36px; height: 36px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.turn-dist { font-size: 26px; font-weight: 600; line-height: 1.1; white-space: nowrap; }
.turn-text { font-size: 15px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Top right */
.top-right { position: fixed; top: calc(14px + var(--safe-t)); right: 14px; display: flex; gap: 8px; z-index: 10; align-items: center; }
.icon-btn { width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass); color: var(--ink); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg, .dock-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ind { width: 40px; height: 40px; display: grid; place-items: center; font-size: 22px; color: rgba(255,255,255,.18); }
.ind.on { color: var(--green); animation: blink .7s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }

/* Trip */
.trip { right: 14px; bottom: calc(92px + var(--safe-b)); display: flex; align-items: center; gap: 16px; padding: 12px 12px 12px 18px; max-width: calc(100vw - 28px); }
.trip-main { display: flex; flex-direction: column; min-width: 0; }
#tripEta { font-size: 22px; font-weight: 600; }
#tripDest { color: var(--dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.trip-stats { display: flex; flex-direction: column; font-size: 15px; color: var(--dim); white-space: nowrap; }
.end { border: 0; background: #e5383b; color: #fff; font-weight: 600; border-radius: 12px; padding: 12px 16px; font-size: 15px; cursor: pointer; }

/* Dock */
.dock { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b)); display: flex; gap: 4px; padding: 6px;
  background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 20px; z-index: 10; }
.dock-btn { min-width: 68px; height: 58px; border: 0; border-radius: 14px; background: transparent; color: var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; cursor: pointer; }
.dock-btn:active, .dock-btn.active { background: rgba(255,255,255,.10); }
.dock-btn.active { color: var(--blue); }
.dock-btn span { max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill { border: 1px solid var(--line); background: rgba(255,255,255,.08); color: var(--ink); border-radius: 999px; padding: 12px 18px; font-size: 15px; cursor: pointer; min-height: 44px; }
.pill.primary { background: var(--blue); border-color: var(--blue); font-weight: 600; }
.pill.wide { width: 100%; margin-top: 10px; }
.recenter { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); z-index: 11; background: var(--blue); border-color: var(--blue); font-weight: 600; }

/* Panels */
.panel { position: fixed; z-index: 30; top: calc(12px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 110px - var(--safe-b)); overflow: auto; background: rgba(16,18,22,.94); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line); border-radius: 22px; padding: 16px; user-select: text; }
.wide-panel { width: min(820px, calc(100vw - 24px)); }
.panel h1 { margin: 6px 0 4px; font-size: 32px; }
.panel h2 { margin: 0; font-size: 20px; flex: 1; }
.panel h3 { margin: 16px 0 8px; font-size: 15px; color: var(--dim); font-weight: 500; }
.panel-head { display: flex; gap: 8px; align-items: center; }
.close { width: 44px; height: 44px; border-radius: 12px; border: 0; background: rgba(255,255,255,.08); color: var(--ink); font-size: 18px; cursor: pointer; flex: none; }
#searchInput, .field input[type=text], .field select { width: 100%; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #0b0d10; color: var(--ink); }
.results { list-style: none; margin: 10px 0 0; padding: 0; }
.results li { padding: 12px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.results li b { display: block; }
.results li small { color: var(--dim); }
.field { display: block; margin-top: 14px; color: var(--dim); font-size: 14px; }
.field input, .field select { margin-top: 6px; }
.field input[type=range] { width: 100%; }
.check { display: flex; gap: 10px; align-items: center; margin-top: 14px; }
.check input { width: 22px; height: 22px; }
.test-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 14px; color: var(--dim); font-size: 14px; }
.hint { color: var(--dim); font-size: 13px; }
.welcome { top: 50%; transform: translate(-50%, -50%); text-align: center; }

/* Car picker */
.car-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.car-card { border: 2px solid transparent; background: rgba(255,255,255,.05); border-radius: 16px; padding: 10px; color: var(--ink); text-align: left; cursor: pointer; }
.car-card.sel { border-color: var(--blue); background: rgba(47,123,255,.12); }
.car-card svg { width: 100%; height: 64px; display: block; }
.car-card b { display: block; margin-top: 6px; font-size: 15px; }
.car-card small { color: var(--dim); font-size: 12px; }
.color-row { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { display: flex; align-items: center; gap: 8px; border: 2px solid transparent; border-radius: 999px; padding: 6px 12px 6px 6px; background: rgba(255,255,255,.05); color: var(--ink); cursor: pointer; font-size: 13px; min-height: 44px; }
.swatch i { width: 28px; height: 28px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3); }
.swatch.sel { border-color: var(--blue); }

/* Cameras */
.cam { position: fixed; z-index: 20; background: #000; overflow: hidden; }
.cam img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam img.mirror { transform: scaleX(-1); }
.cam-rear { inset: 0; }
.cam-side { bottom: calc(90px + var(--safe-b)); width: min(46vw, 560px); aspect-ratio: 4 / 3; border-radius: 18px; border: 2px solid rgba(255,255,255,.25); box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.cam-side.left { left: 14px; }
.cam-side.right { right: 14px; }
.cam-label { position: absolute; z-index: 3; top: 12px; left: 12px; background: rgba(0,0,0,.6); padding: 6px 12px; border-radius: 10px; font-weight: 600; font-size: 14px; letter-spacing: .04em; }
.cam-rear .cam-label { top: calc(16px + var(--safe-t)); left: 50%; transform: translateX(-50%); }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font-size: 18px; background: #111; text-align: center; padding: 20px; }
.guides { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; pointer-events: none; }
.guides path { fill: none; stroke-width: .8; vector-effect: non-scaling-stroke; stroke-width: 4; }
.g-red { stroke: #ff3b30; } .g-yel { stroke: #ffd60a; } .g-grn { stroke: #31d158; }

.toast { position: fixed; left: 50%; top: calc(90px + var(--safe-t)); transform: translateX(-50%); z-index: 40; background: rgba(16,18,22,.95); border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 14px; max-width: calc(100vw - 32px); font-size: 15px; text-align: center; }

@media (max-width: 640px) {
  .turn { left: 14px; top: calc(110px + var(--safe-t)); max-width: calc(100vw - 28px); }
  .dock-btn { min-width: 56px; font-size: 11px; }
  .trip { left: 14px; right: 14px; justify-content: space-between; }
  .cam-side { width: calc(100vw - 28px); left: 14px !important; right: 14px !important; width: auto; top: calc(110px + var(--safe-t)); bottom: auto; }
  #speed { font-size: 36px; }
}
@media (prefers-reduced-motion: reduce) { .ind.on { animation: none; } }
