:root {
  color-scheme: light;
  --bg: #efeae2;
  --ink: #142033;
  --muted: #5c6b7a;
  --card: rgba(255, 252, 247, 0.96);
  --card-solid: #fffdf8;
  --accent: #0f6e64;
  --accent-ink: #f7fffd;
  --line: rgba(20, 32, 51, 0.12);
  --warn: #7a4e00;
  --warn-bg: #fff4df;
  --danger: #8d2f2f;
  --shadow: 0 12px 40px rgba(20, 32, 51, 0.16);
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}
html.dark {
  color-scheme: dark;
  --bg: #0e141b;
  --ink: #e7eef6;
  --muted: #b7c3d0;
  --card: rgba(22, 32, 42, 0.96);
  --card-solid: #18222c;
  --line: rgba(231, 238, 246, 0.12);
  --warn: #e6b15a;
  --warn-bg: #3a2c16;
  --danger: #ffb4b4;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
}
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: 0.01em; }
.brand svg { width: 28px; height: 28px; }
.page-body { min-height: 100vh; }
.auth, .sub { width: min(440px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 48px; }
.card, .sub {
  background: transparent;
}
.auth h1, .sub h1 { font-size: 1.8rem; margin: 18px 0 8px; }
.sub h2, .auth h2 { font-size: 1.05rem; margin: 22px 0 8px; }
.lede { font-size: 1.05rem; }
.fine, .links { color: var(--muted); font-size: 0.92rem; }
.links { display: flex; flex-wrap: wrap; gap: 14px; }
.subhead {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) 16px 0;
  width: min(440px, calc(100% - 32px));
  margin: 0 auto;
}
.back { text-decoration: none; font-weight: 650; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field input, .field select, .pw input, .sheet input, .sheet select {
  display: block; width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card-solid); padding: 12px 14px; font-size: 16px;
}
.sheet label { display: block; font-weight: 650; margin: 4px 0 8px; }
.sheet .field { margin-top: 0; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pw { display: flex; gap: 8px; align-items: center; }
.pw input { flex: 1; }
.check { display: flex; gap: 8px; align-items: flex-start; margin: 10px 0; }
.check input { margin-top: 4px; }
.choices { border: 0; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.choices label, .permit, .route {
  border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; background: var(--card-solid);
}
.choices span { display: block; color: var(--muted); font-size: 0.9rem; margin-top: 4px; }
.choices.miles { grid-template-columns: 1fr 1fr; }
.primary, .secondary, .danger, a.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; border-radius: 999px; padding: 0 16px; border: 0; text-decoration: none;
  margin-top: 8px; cursor: pointer;
}
.primary, a.primary { background: var(--accent); color: var(--accent-ink); width: 100%; font-weight: 650; }
.secondary { background: transparent; border: 1px solid var(--line); }
.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.textish { background: none; border: 0; color: var(--accent); padding: 8px 0; cursor: pointer; }
.banner { border-radius: 12px; padding: 12px 14px; background: var(--warn-bg); color: var(--warn); }
.banner.error { background: #fde8e8; color: var(--danger); }
html.dark .banner.error { background: #3a1d1d; }
.banner.ok { background: #e5f4f1; color: var(--accent); }
html.dark .banner.ok { background: #14312d; }
.field-error { color: var(--danger); margin: 4px 0 0; font-size: 0.9rem; }
.permit { margin: 12px 0; padding: 16px; }
.permit-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.permit h2 { margin: 0; font-size: 1.05rem; line-height: 1.3; }
.permit .meta { margin: 4px 0 0; color: var(--muted); }
.permit.is-off { opacity: 0.72; }
.permit details { margin-top: 8px; }
.permit summary { min-height: 44px; display: flex; align-items: center; font-weight: 650; cursor: pointer; }
.pill {
  display: inline-flex; align-items: center; flex: none;
  min-height: 28px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); font-size: 0.78rem; font-weight: 650;
}
.pill-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.form-card { border: 1px solid var(--line); border-radius: 18px; padding: 4px 16px 16px; background: var(--card-solid); }
.empty { color: var(--muted); }
.choices.segment { grid-template-columns: 1fr 1fr; }
.choices.segment label { display: flex; align-items: center; gap: 10px; min-height: 48px; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-actions form { margin: 0; }
.row-actions .secondary, .row-actions .danger { margin-top: 0; min-height: 40px; }
.plain { padding-left: 18px; }
.inline-form { margin-top: 12px; }

.map-body { position: relative; height: 100vh; height: 100dvh; overflow: hidden; background: #d5dde4; }
.map, .map.maplibregl-map { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-fallback { margin: 80px 20px; }
.top, .maneuver, .warning, .eta, .sheet, .devflag, .fab { position: absolute; z-index: 2; }
.top {
  top: max(12px, env(safe-area-inset-top));
  left: 12px; right: 12px;
  display: flex; gap: 10px;
}
.where, .acct {
  border: 0; background: var(--card); box-shadow: var(--shadow); color: var(--ink);
}
.where {
  flex: 1; min-height: 56px; border-radius: 999px; text-align: left; padding: 0 20px; font-size: 1.05rem;
}
.acct {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; text-decoration: none; font-weight: 700;
}
.acct.wide { width: auto; border-radius: 999px; padding: 0 16px; }
.fab {
  right: 12px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: 48px; height: 48px; padding: 0; border: 0; border-radius: 50%;
  background: var(--card); color: var(--accent); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.fab svg { width: 22px; height: 22px; }
.fab.recenter { bottom: calc(112px + env(safe-area-inset-bottom)); }
.maneuver, .warning, .eta, .sheet { left: 0; right: 0; }
.maneuver {
  top: 0; display: flex; align-items: center; gap: 12px;
  background: #0c3f3a; color: #f7fffd;
  border-radius: 0 0 18px 18px;
  padding: max(14px, env(safe-area-inset-top)) 8px 14px 16px;
  box-shadow: var(--shadow);
}
#maneuver-body { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.turn-icon { width: 44px; height: 44px; flex: none; }
.maneuver strong { display: block; font-size: 1.65rem; line-height: 1.1; font-weight: 700; }
.maneuver .road { display: block; font-size: 1.02rem; line-height: 1.25; }
.maneuver #mute {
  flex: none; border: 0; background: transparent; color: #f7fffd;
  min-height: 44px; min-width: 64px; font-weight: 650;
}
.eta {
  bottom: 0;
  background: var(--card); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.eta div { flex: 1; min-width: 0; }
.eta strong { display: block; font-size: 1.35rem; line-height: 1.15; }
.eta span, .devflag { color: var(--muted); font-size: 0.85rem; }
.eta #end-nav {
  flex: none; border: 0; background: transparent; color: var(--danger);
  font-weight: 700; min-height: 44px; min-width: 64px;
}
.warning button { border: 0; background: transparent; color: var(--warn); font-weight: 650; min-height: 40px; }
.warning {
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 12px; right: 12px;
  background: var(--warn-bg); color: var(--warn); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow);
}
.warning p { margin: 0 0 4px; }
.warning .actions { display: flex; flex-wrap: nowrap; gap: 4px; overflow-x: auto; }
.warning button { white-space: nowrap; flex: none; padding: 0 6px; }
.sheet .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sheet {
  bottom: 0; max-height: min(78dvh, 680px); overflow: auto;
  background: var(--card); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
}
.route-actions { display: flex; align-items: center; gap: 8px; }
.route-actions .primary { width: auto; flex: 1; margin-top: 0; }
.route-actions .textish { min-height: 48px; margin: 0; }
.handle { width: 42px; height: 4px; border-radius: 99px; background: var(--line); margin: 6px auto 10px; }
.sheet h2 { font-size: 1.35rem; margin: 4px 0 8px; }
.sheet h3 { margin: 0; font-size: 0.92rem; font-weight: 650; color: var(--muted); letter-spacing: 0.01em; }
.sheet .route {
  border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 12px 0; background: var(--card-solid);
}
.roster { list-style: none; margin: 8px 0 12px; padding: 0; }
.roster li {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.scrim { position: absolute; inset: 0; background: rgba(8, 12, 18, 0.28); z-index: 1; }
.result, .route, .stop {
  width: 100%; text-align: left; background: transparent; color: inherit;
  border: 0; border-bottom: 1px solid var(--line); padding: 12px 0; display: block;
}
.result { min-height: 48px; }
.result small, .route .via { color: var(--muted); }
.time { font-size: 1.35rem; font-weight: 700; margin: 4px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { border-radius: 999px; border: 1px solid var(--line); background: transparent; padding: 6px 10px; }
.devflag { left: 12px; right: 72px; bottom: max(12px, env(safe-area-inset-bottom)); margin: 0; pointer-events: none; line-height: 1.3; }
body.navigating .top, body.navigating .devflag, body.navigating #locate-btn { display: none; }
body.navigating .maplibregl-ctrl-top-right { display: none; }
.result { cursor: pointer; }
.you {
  width: 18px; height: 18px; border-radius: 50%; background: #1a73e8;
  border: 3px solid white; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
body.navigating .you {
  width: 0; height: 0; border: none; border-radius: 0; background: transparent; box-shadow: none;
}
body.navigating .you::before {
  content: "";
  position: absolute;
  left: 0; top: 0;
  width: 22px; height: 28px;
  transform: translate(-50%, -78%);
  background: #1a73e8;
  clip-path: polygon(50% 0, 100% 100%, 50% 76%, 0 100%);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}
.maplibregl-ctrl-top-right { top: calc(max(12px, env(safe-area-inset-top)) + 68px); }
.maplibregl-ctrl-attrib { font-size: 11px; }
body.navigating .maplibregl-ctrl-bottom-left,
body.navigating .maplibregl-ctrl-bottom-right { bottom: 96px; }
@media (max-width: 420px) {
  .split { grid-template-columns: 1fr; }
}
@media (min-width: 800px) {
  .sheet { left: 50%; width: min(440px, calc(100% - 32px)); transform: translateX(-50%); bottom: 16px; border-radius: 22px; }
  .top { left: 50%; width: min(440px, calc(100% - 32px)); transform: translateX(-50%); }
  .warning { left: 50%; width: min(440px, calc(100% - 32px)); transform: translateX(-50%); }
}
