:root {
  --bg: #ffffff;
  --fg: #14171a;
  --muted: #5f6b76;
  --line: #e2e6ea;
  --accent: #1f6feb;
  --danger: #d1242f;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  --radius: 16px;
  --accent-soft: rgba(31, 111, 235, 0.12);   /* behind a switched-on control */
  --press: rgba(0, 0, 0, 0.06);              /* under a finger or a hovering mouse */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}
body.night {
  --bg: #1b1f24;
  --fg: #eef1f4;
  --muted: #9aa5b1;
  --line: #2d333b;
  --accent: #4c9aff;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  --accent-soft: rgba(76, 154, 255, 0.18);
  --press: rgba(255, 255, 255, 0.07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Georgian", sans-serif;
  font-size: 18px;
  color: var(--fg);
  background: #111418;
  -webkit-tap-highlight-color: transparent;
}
#map { position: absolute; inset: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

.card {
  position: absolute;
  background: var(--bg);
  color: var(--fg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 5;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Line icons, drawn in the text colour of their button */
.i {
  width: 24px; height: 24px; flex: none; display: block;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.i .fill { fill: currentColor; stroke: none; }

/* Top bar: search, with Home / Work beside it */
.topbar {
  /* above the controls: on a phone the open result list runs over them */
  position: absolute; top: 16px; left: 16px; right: 96px; z-index: 6;
  display: flex; align-items: flex-start; gap: 10px;
  pointer-events: none;   /* the empty stretch to the right leaves the map draggable */
}
.topbar > * { pointer-events: auto; }
.search { position: relative; flex: 0 1 460px; min-width: 0; }
.search input {
  width: 100%;
  height: 64px;
  padding: 0 56px 0 20px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font-size: 20px;
  outline: none;
}
.search input::-webkit-search-cancel-button { display: none; }
.icon-btn {
  border: 0; background: transparent; width: 48px; height: 48px;
  border-radius: 12px; color: var(--muted);
  display: grid; place-items: center;
  transition: background-color 150ms ease;
}
.icon-btn .i { width: 22px; height: 22px; }
.search .icon-btn { position: absolute; right: 8px; top: 8px; }
.results { list-style: none; margin: 0; padding: 4px 0 8px; border-top: 1px solid var(--line); max-height: 60vh; overflow: auto; }
.results li { padding: 14px 20px; cursor: pointer; }
.results li:hover, .results li:focus { background: var(--line); }
.results .r-name { font-weight: 600; }
.results .r-sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.results li.shortcut { display: flex; align-items: center; gap: 14px; }
.r-icon { color: var(--muted); }
.r-icon .i { width: 22px; height: 22px; }

/* Home / Work, the same height as the search box */
.places { display: flex; gap: 10px; flex: none; }
.place-chip {
  height: 64px; padding: 0 20px 0 16px; border: 0; border-radius: var(--radius);
  background: var(--bg); color: var(--fg); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 600; white-space: nowrap;
  transition: transform 160ms var(--ease-out);
}
.place-chip .i { color: var(--accent); }
/* Not saved yet: greyed, and a tap explains how to set it */
.place-chip.unset { color: var(--muted); font-weight: 500; }
.place-chip.unset .i { color: var(--muted); }

/* Map controls: one column, each switch lights up in the accent colour when on */
.controls {
  position: absolute; top: 16px; right: 16px; z-index: 5;
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px; box-shadow: var(--shadow); overflow: hidden;
}
.ctrl-btn {
  width: 64px; height: 64px; border: 0; background: transparent; color: var(--fg);
  display: grid; place-items: center;
  transition: background-color 150ms ease, color 150ms ease;
}
.ctrl-btn + .ctrl-btn { border-top: 1px solid var(--line); }
.ctrl-btn .i { width: 26px; height: 26px; transition: transform 160ms var(--ease-out); }
.ctrl-btn.active { color: var(--accent); background: var(--accent-soft); }
.ctrl-3d { font-size: 19px; font-weight: 700; letter-spacing: -0.5px; transition: transform 160ms var(--ease-out); }
#voiceBtn .off, #voiceBtn.muted .on { display: none; }
#voiceBtn.muted .off { display: block; }

/* Press feedback: the button shrinks a touch under the finger, so the tap is felt */
.ctrl-btn:active { background: var(--press); }
.ctrl-btn:active .i, .ctrl-btn:active .ctrl-3d { transform: scale(0.88); }
.place-chip:active, .btn:active { transform: scale(0.97); }
.icon-btn:active { background: var(--press); }
@media (hover: hover) and (pointer: fine) {
  .ctrl-btn:hover:not(.active), .icon-btn:hover, .btn:not(.primary):not(.danger):hover { background: var(--press); }
}
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.ctrl-btn:focus-visible { outline-offset: -4px; }   /* the column clips anything outside */
@media (prefers-reduced-motion: reduce) {
  .ctrl-btn:active .i, .ctrl-btn:active .ctrl-3d, .place-chip:active, .btn:active { transform: none; }
}

/* Start-up error */
.boot-error {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100vw - 48px)); z-index: 30;
  background: var(--bg); color: var(--fg); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; text-align: center;
}
.boot-error-title { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
.boot-error-detail { color: var(--danger); word-break: break-word; margin-bottom: 10px; }

/* Brand and credits badge, tucked into the bottom-right corner */
.brand {
  position: absolute; right: 8px; bottom: 8px; z-index: 4;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px 6px 6px; border: 0; border-radius: 22px;
  background: var(--bg); box-shadow: var(--shadow);
  white-space: nowrap; text-align: left;
}
.brand-more { display: none; }
.brand[aria-expanded="true"] .brand-more { display: block; }
.brand .logo { width: 32px; height: 32px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand b { color: var(--fg); font-weight: 700; font-size: 13px; letter-spacing: -0.1px; }
.brand-sub { color: var(--muted); font-size: 11px; }

/* Send-from-phone panel */
.phone {
  top: 16px; right: 96px; width: min(340px, calc(100vw - 112px)); padding: 16px;
  display: flex; flex-direction: column; gap: 6px;
}
.phone header { display: flex; align-items: center; justify-content: space-between; }
.phone h2 { margin: 0; font-size: 20px; }
.paircode {
  font-size: 44px; font-weight: 800; letter-spacing: 10px; text-align: center;
  padding: 10px 0 6px; color: var(--accent);
}
#pairQr { align-self: center; width: 170px; height: 170px; border-radius: 10px; background: #fff; padding: 8px; image-rendering: pixelated; }

/* Toast */
.toast {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(20, 23, 26, 0.92); color: #fff; padding: 12px 20px;
  border-radius: 12px; z-index: 20; font-size: 16px; max-width: 90vw;
}

/* Route panel */
.route { left: 16px; bottom: 16px; width: min(460px, calc(100vw - 32px)); padding: 16px; max-height: 70vh; display: flex; flex-direction: column; }
.next {
  display: flex; gap: 16px; align-items: center; width: 100%;
  background: transparent; border: 0; padding: 0; text-align: left; color: inherit;
}
.chev {
  margin-left: auto; flex: none; width: 26px; height: 26px; color: var(--muted);
  border-right: 3px solid currentColor; border-bottom: 3px solid currentColor;
  transform: rotate(45deg) scale(0.55); transform-origin: center;
}
.route.collapsed .chev { transform: rotate(-135deg) scale(0.55); }

/* Collapsed: just the next turn. Tap it for the rest. */
.route.collapsed { padding: 10px 14px; width: min(430px, calc(100vw - 32px)); }
.route.collapsed .next-arrow { width: 58px; height: 58px; border-radius: 13px; }
.route.collapsed .next-arrow svg { width: 40px; height: 40px; }
.route.collapsed .next-dist { font-size: 25px; }
.route.collapsed .next-instr { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.route.collapsed .next-text { min-width: 0; }
.route.collapsed .then,
.route.collapsed .progress,
.route.collapsed .route-actions,
.route.collapsed .steps { display: none !important; }
.route.collapsed .route-meta { margin: 6px 0 0; font-size: 14px; gap: 14px; }
.next-arrow {
  flex: none; width: 76px; height: 76px; border-radius: 16px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.next-arrow svg { width: 52px; height: 52px; }

/* "then …" secondary instruction */
.then {
  display: flex; align-items: center; gap: 8px;
  margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
  font-size: 16px; color: var(--fg);
}
.then-arrow { display: inline-grid; place-items: center; width: 24px; height: 24px; color: var(--muted); }
.then-arrow svg { width: 22px; height: 22px; }
.then-instr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* trip progress */
.progress { height: 6px; border-radius: 3px; background: var(--line); margin: 14px 0 10px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.6s linear; }
.next-dist { font-size: 30px; font-weight: 700; line-height: 1.1; }
.next-instr { font-size: 19px; margin-top: 4px; }
.route-meta { display: flex; gap: 18px; margin: 0 0 12px; color: var(--muted); font-size: 17px; }
.route-meta span:first-child { color: #1a7f37; font-weight: 700; }
body.night .route-meta span:first-child { color: #3fb950; }
.route-actions { display: flex; gap: 10px; }
/* Before you press Start the panel shows Start / Cancel, after it shows Steps / End */
.route .preview-only { display: none; }
.route.preview .preview-only { display: block; }
.route.preview .drive-only { display: none; }
.route.preview .next-dist { font-size: 26px; }
.save-row { gap: 10px; margin-top: 10px; }
.route.preview .save-row { display: flex; }
.btn.small {
  height: 42px; font-size: 15px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.small .i { width: 18px; height: 18px; color: var(--accent); }
.btn {
  flex: 1; height: 52px; border-radius: 12px; border: 1px solid var(--line);
  background: transparent; font-weight: 600;
  transition: transform 160ms var(--ease-out), background-color 150ms ease;
}
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.steps { margin: 12px 0 0; padding: 0 0 0 4px; list-style: none; overflow: auto; border-top: 1px solid var(--line); }
.steps li { display: flex; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 16px; }
.steps li.current { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 8px; }
.steps .s-arrow { flex: none; display: inline-grid; place-items: center; width: 26px; height: 26px; color: var(--muted); }
.steps .s-arrow svg { width: 24px; height: 24px; }
.steps .s-text { overflow: hidden; }
.steps .s-dist { margin-left: auto; color: var(--muted); white-space: nowrap; }

/* Updates panel */
.updates { top: 16px; right: 96px; bottom: 16px; width: min(400px, calc(100vw - 112px)); padding: 16px; display: flex; flex-direction: column; }
.updates header { display: flex; align-items: center; justify-content: space-between; }
.updates h2 { margin: 0; font-size: 22px; }
.updates-list { list-style: none; margin: 8px 0; padding: 0; overflow: auto; flex: 1; }
.updates-list li { padding: 12px 8px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 12px; }
.updates-list li:hover { background: var(--line); border-radius: 8px; }
.u-dot { flex: none; width: 14px; height: 14px; border-radius: 50%; margin-top: 5px; }
.u-title { font-weight: 600; }
.u-desc { font-size: 15px; color: var(--muted); margin-top: 2px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: #bf8700; color: #fff; margin-left: 6px; vertical-align: middle; }

/* Map popups */
.maplibregl-popup-content { font-size: 16px; border-radius: 12px; padding: 14px 16px; color: #14171a; }
.popup-title { font-weight: 700; margin-bottom: 4px; }
.popup-btn { margin-top: 10px; width: 100%; height: 44px; border: 0; border-radius: 10px; background: #1f6feb; color: #fff; font-weight: 600; }

/* My-location marker: the car from above. Black with a white rim on the day map,
   white on the night map, so it stands out from the roads either way. */
.me { position: relative; width: 30px; height: 54px; }
.me-car { display: block; width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.45)); }
.car-body { fill: #17191c; stroke: rgba(255, 255, 255, 0.9); stroke-width: 1; stroke-linejoin: round; }
.car-glass { fill: #4b535d; }
.car-lamp { fill: none; stroke: #e6ecf2; stroke-width: 1.5; stroke-linecap: round; }
.car-tail { fill: none; stroke: #e5313d; stroke-width: 1.5; stroke-linecap: round; }
body.night .car-body { fill: #f4f6f8; stroke: rgba(0, 0, 0, 0.35); }
body.night .car-glass { fill: #1e242b; }
body.night .car-lamp { stroke: #2b323a; }

/* Phones: the search row takes the full width and the controls start below it.
   Home / Work shrink to their icons, and step aside while you type. */
@media (max-width: 640px) {
  body { font-size: 16px; }
  .topbar { right: 16px; gap: 8px; }
  .topbar:focus-within .places { display: none; }
  .search { flex: 1 1 auto; }
  /* 52 px keeps the column clear of the route preview panel on a phone */
  .search input { height: 52px; font-size: 17px; padding: 0 44px 0 16px; }
  .search .icon-btn { top: 2px; right: 2px; }
  .places { gap: 8px; }
  .place-chip { width: 52px; height: 52px; padding: 0; justify-content: center; }
  .place-chip span { display: none; }
  .controls { top: 78px; border-radius: 18px; }
  .ctrl-btn { width: 52px; height: 52px; }
  .ctrl-btn .i { width: 24px; height: 24px; }
  .ctrl-3d { font-size: 17px; }
  .phone { top: 78px; left: 16px; right: 80px; width: auto; }
  .updates { right: 16px; left: 16px; width: auto; top: 78px; }
}

/* Portrait car screens — the 17" display in a Model S or X is 1200 x 1920.
   The landscape layout is untouched; here the panels span the width and the
   turn card sits along the bottom, near where the driver is already looking,
   instead of being marooned in the corner of a very tall screen. */
@media (orientation: portrait) and (min-width: 700px) {
  body { font-size: 20px; }

  .topbar { right: 104px; gap: 12px; }
  .search { flex: 1 1 auto; }
  .search input { height: 72px; font-size: 22px; }
  .search .icon-btn { top: 12px; }
  .results li { padding: 16px 20px; }
  .place-chip { height: 72px; font-size: 20px; padding: 0 24px 0 20px; }
  .place-chip .i { width: 28px; height: 28px; }

  .controls { border-radius: 22px; }
  .ctrl-btn { width: 72px; height: 72px; }
  .ctrl-btn .i { width: 30px; height: 30px; }
  .ctrl-3d { font-size: 22px; }

  .route { left: 16px; right: 16px; width: auto; max-height: 46vh; padding: 18px; }
  .route.collapsed { width: auto; padding: 14px 18px; }
  .route.collapsed .next-arrow { width: 74px; height: 74px; }
  .route.collapsed .next-arrow svg { width: 52px; height: 52px; }
  .route.collapsed .next-dist { font-size: 34px; }
  .route.collapsed .next-instr { font-size: 22px; }
  .route.collapsed .route-meta { font-size: 17px; }
  .next-arrow { width: 92px; height: 92px; border-radius: 18px; }
  .next-arrow svg { width: 64px; height: 64px; }
  .next-dist { font-size: 38px; }
  .next-instr { font-size: 24px; }
  .then { font-size: 19px; }
  .route-meta { font-size: 20px; }
  .btn { height: 60px; }
  .btn.small { height: 52px; font-size: 18px; }
  .btn.small .i { width: 22px; height: 22px; }
  .steps li { font-size: 18px; padding: 13px 4px; }

  .phone { left: 16px; right: 104px; width: auto; top: 100px; }
  #pairQr { width: 220px; height: 220px; }
  .paircode { font-size: 54px; }
  .updates { left: 16px; right: 104px; width: auto; top: 100px; bottom: 16px; }

  .toast { font-size: 19px; bottom: 32px; }
}
