/* Day: high-contrast for sunlight. Night: amber instrument lighting, easy on dark-adapted eyes. */
:root {
  --panel: #E6E9EC;
  --face: #F7F8F9;
  --accent: #A85F00;
  --accent-soft: rgb(168 95 0 / 0.16);
  --text: #15181B;
  --muted: #5B6570;
  --tick: #A9B1B9;
  --good: #2E7D4F;
  --warn: #A85F00;
  --bad: #B3261E;
  --digits: system-ui, -apple-system, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --panel: #1A1612;
    --face: #231E18;
    --accent: #FFB000;
    --accent-soft: rgb(255 176 0 / 0.14);
    --text: #F4E7CF;
    --muted: #A08F76;
    --tick: #4D4236;
    --good: #8FC98A;
    --warn: #FFB000;
    --bad: #FF7A66;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--panel); -webkit-text-size-adjust: 100%; }
body {
  color: var(--text);
  font: 400 16px/1.4 var(--digits);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }

.app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 8px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 12px) max(16px, env(safe-area-inset-left));
  transition: transform 0.3s;
}

/* Top bar */
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 48px; }
.bar-actions { display: flex; gap: 8px; align-items: center; }
.gps { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--tick); }
.gps[data-state="good"] .dot { background: var(--good); }
.gps[data-state="weak"] .dot { background: var(--warn); }
.gps[data-state="lost"] .dot, .gps[data-state="error"] .dot { background: var(--bad); }
.gps[data-state="search"] .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }

.pill {
  min-height: 40px;
  padding: 0 16px;
  border: 1.5px solid var(--tick);
  border-radius: 20px;
  background: none;
  font-weight: 600;
  font-size: 15px;
}
.pill[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1.5px solid var(--tick);
  border-radius: 50%;
  background: none;
}

/* Speed dial */
.gauge { position: relative; width: min(100%, 420px); margin: 4px auto 0; }
#dial { display: block; width: 100%; height: auto; overflow: visible; }
.track { fill: none; stroke: var(--tick); stroke-width: 3; }
.sweep { fill: none; stroke: var(--accent); stroke-width: 9; stroke-linecap: round; }
.tip { fill: var(--accent); stroke: var(--panel); stroke-width: 3; }
.top-mark { stroke: var(--text); stroke-width: 3; stroke-linecap: round; opacity: 0.55; }
.tick { stroke: var(--tick); stroke-width: 1.5; }
.tick.major { stroke: var(--muted); stroke-width: 2.5; }
.tick-label { fill: var(--muted); font: 600 13px var(--digits); text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; }

.readout {
  position: absolute;
  left: 0; right: 0;
  top: 25%;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}
#speed {
  font: 200 clamp(96px, 32vw, 168px)/0.9 var(--digits);
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
#speed-unit { margin-top: 6px; color: var(--muted); font-size: 17px; font-weight: 600; }

/* Heading */
.heading { margin-top: 8px; text-align: center; }
.tape {
  position: relative;
  height: 56px;
  overflow: hidden;
  border-radius: 12px;
  background: var(--face);
  -webkit-mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent);
  mask-image: linear-gradient(to right, transparent, #000 18%, #000 82%, transparent);
}
.strip { position: absolute; left: 0; top: 0; height: 56px; will-change: transform; }
.strip .t { stroke: var(--tick); stroke-width: 1.5; }
.strip .t.mid { stroke: var(--muted); }
.strip .t.card { stroke: var(--text); stroke-width: 2.5; }
.strip text { fill: var(--muted); font: 600 13px var(--digits); text-anchor: middle; }
.strip text.card { fill: var(--text); font-size: 17px; font-weight: 700; }
.strip text.north { fill: var(--accent); }
/* Stops above the labels so the one it points at stays readable */
.pointer {
  position: absolute;
  left: 50%; top: 0;
  height: 24px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 0 0 2px 2px;
  background: var(--accent);
}
.pointer::before {
  content: "";
  position: absolute;
  left: 50%; top: 0;
  margin-left: -7px;
  border: 7px solid transparent;
  border-top-color: var(--accent);
  border-bottom-width: 0;
}
.heading-read { display: flex; justify-content: center; align-items: baseline; gap: 12px; margin-top: 10px; }
.cardinal { font: 700 44px/1 var(--digits); letter-spacing: -0.01em; min-width: 2ch; }
.degrees { font: 300 34px/1 var(--digits); color: var(--muted); font-variant-numeric: tabular-nums; }
.source { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.link-btn { margin-top: 6px; border: 0; background: none; color: var(--accent); font-weight: 700; min-height: 40px; }
.link-btn[hidden] { display: none; }

/* Trip */
.trip { margin-top: auto; padding-top: 18px; }
.trip dl {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 8px;
  margin: 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--face);
}
.trip dt { color: var(--muted); font-size: 13px; font-weight: 600; }
.trip dd { margin: 2px 0 0; font: 500 22px/1.15 var(--digits); font-variant-numeric: tabular-nums; }
.trip dd small { font-size: 13px; color: var(--muted); font-weight: 600; margin-left: 3px; }
.trip-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.note { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

/* Start screen */
.start {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: end center;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 16px) max(16px, env(safe-area-inset-left));
  background: rgb(0 0 0 / 0.35);
  z-index: 5;
}
.start[hidden] { display: none; }
.start-card { width: min(100%, 520px); padding: 22px; border-radius: 20px; background: var(--face); box-shadow: 0 12px 40px rgb(0 0 0 / 0.35); }
.start-card h1 { margin: 0 0 8px; font: 700 30px/1.1 var(--digits); }
.start-card p { margin: 0 0 12px; }
.big-btn {
  width: 100%;
  min-height: 54px;
  margin-top: 6px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: var(--panel);
  font-size: 18px;
  font-weight: 700;
}
.error { color: var(--bad); margin-top: 12px !important; }

/* Windshield (HUD) mode: flip top-to-bottom so the reflection in the glass reads correctly */
.hud .app { transform: scaleY(-1); }
.hud .trip, .hud .bar-actions .pill, .hud #compass-btn, .hud .source { visibility: hidden; }
.hud #speed { color: var(--accent); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  transform: translateX(-50%);
  width: min(100vw - 32px, 520px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 12px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--panel);
  z-index: 10;
}
.toast[hidden] { display: none; }
.toast span { flex: 1; }
.toast .pill { border-color: currentColor; }

/* Landscape on a dash mount: dial on the left, direction and trip on the right */
@media (orientation: landscape) and (max-height: 560px) {
  .app {
    max-width: none;
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
    column-gap: 24px;
  }
  .bar { grid-column: 1 / -1; }
  .gauge { grid-column: 1; grid-row: 2 / 4; align-self: center; width: min(100%, calc(100dvh - 90px) * 1.2); }
  .heading { grid-column: 2; grid-row: 2; align-self: center; margin-top: 0; }
  .trip { grid-column: 2; grid-row: 3; padding-top: 8px; }
  .note { display: none; }
  #speed { font-size: clamp(72px, 22vh, 140px); }
  .bar { min-height: 44px; }
  .tape { height: 48px; }
  .heading-read { margin-top: 6px; }
  .cardinal { font-size: 34px; }
  .degrees { font-size: 26px; }
  .source { margin-top: 2px; font-size: 13px; }
  .link-btn { min-height: 32px; margin-top: 0; }
  .trip dl { gap: 6px 8px; padding: 10px 14px; }
  .trip dd { font-size: 18px; }
  .trip-actions { margin-top: 8px; }
  .pill { min-height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  .app { transition: none; }
  .gps[data-state="search"] .dot { animation: none; }
}
