:root {
  color-scheme: light;
  --paper: #fbf8f3;
  --surface: #ffffff;
  --ink: #20292c;
  --muted: #66716f;
  --line: #e4ddd2;
  --accent: #b84a2b;
  --accent-ink: #ffffff;
  --accent-soft: #f7e6df;
  --warn-bg: #fdf3d7;
  --warn-ink: #6a4d00;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#map { flex: 0 0 38dvh; z-index: 0; background: #e8e4dc; }
.map-3d-control button {
  width: 48px;
  height: 48px;
  padding: 0;
  font: 700 15px/1 system-ui, sans-serif;
  color: var(--ink);
}
.map-3d-control button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}
.map-3d-control button:disabled { opacity: 0.45; cursor: default; }

.sheet {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  margin-top: -14px;
  z-index: 1;
  background: var(--paper);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -2px 12px rgb(0 0 0 / 0.12);
}

h1 { font-size: 1.4rem; line-height: 1.2; margin: 0 0 14px; }
h2 { font-size: 0.95rem; margin: 0 0 8px; }

.muted, .hint { color: var(--muted); font-weight: 400; }
.hint { font-size: 0.85rem; margin: 8px 0 0; }
.field { margin-bottom: 18px; }

button, .button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 12px;
  min-height: 48px;
  padding: 12px 16px;
  cursor: pointer;
}

.primary {
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  background: var(--accent);
  color: var(--accent-ink);
}
.primary:disabled { background: #d9d3c9; color: #80786c; cursor: not-allowed; }

.secondary {
  width: 100%;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.link {
  background: none;
  color: var(--accent);
  padding: 0;
  min-height: 40px;
}

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 500;
}
.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 14px;
}
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

.status { min-height: 1.4em; margin: 12px 0 0; font-size: 0.9rem; color: var(--muted); }
.status.error { color: #a4262c; }

.warnings { list-style: none; padding: 0; margin: 0 0 12px; }
.warnings li {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.875rem;
  margin-bottom: 6px;
}

.stops { list-style: none; margin: 0 0 18px; padding: 0; }

.leg { color: var(--muted); font-size: 0.85rem; padding: 6px 0 6px 40px; }

.stop { display: flex; gap: 12px; }

.badge {
  flex: 0 0 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.stop-body {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.stop-body h3 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.stop-meta { color: var(--muted); font-size: 0.85rem; margin: 2px 0 0; }
.stop-links { display: flex; gap: 14px; font-size: 0.85rem; margin-top: 6px; }
.stop-links a { color: var(--accent); }

.map-pin {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font: 700 13px/1 system-ui, sans-serif;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.4);
}
.map-pin.start { background: #1f6f8b; }

@media (min-width: 800px) {
  body { flex-direction: row-reverse; }
  #map { flex: 1; }
  .sheet { flex: 0 0 400px; margin: 0; border-radius: 0; }
}

[hidden] { display: none !important; }

.link-out {
  display: block;
  text-align: center;
  color: var(--accent);
  padding: 14px 0 4px;
  font-size: 0.9rem;
}

#install { margin-top: 12px; }

#result .primary + .link-out { margin-top: 2px; }

/* Guidance screen */
body.navigating { flex-direction: column; }
body.navigating .sheet { display: none; }
body.navigating #map { flex: 1; min-height: 0; }

#nav-banner {
  background: var(--accent);
  color: var(--accent-ink);
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}

.nav-maneuver { display: flex; align-items: center; gap: 14px; }
#nav-arrow { font-size: 2.6rem; line-height: 1; font-weight: 700; min-width: 44px; text-align: center; }
#nav-distance { margin: 0; font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
#nav-instruction { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }

#nav-alert {
  margin: 10px 0 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.875rem;
}

#nav-panel {
  background: var(--paper);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 12px rgb(0 0 0 / 0.12);
  z-index: 1;
}

#nav-target-name, #nav-arrival-name { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
#nav-target-meta, #nav-arrival-meta { margin: 0 0 10px; font-size: 0.9rem; }
#nav-continue { margin-bottom: 10px; }

.nav-actions { display: flex; gap: 8px; }
.nav-actions button { flex: 1; width: auto; padding: 10px 8px; }
.nav-orientation { display: flex; gap: 8px; }
.nav-orientation button { flex: 1; width: auto; padding: 10px 8px; }
.nav-orientation button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
#nav-camera-status { margin: 6px 0 10px; }

.nav-user {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #1f6f8b;
  border: 3px solid #fff;
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.45);
  display: grid;
  place-items: center;
}
.nav-user span {
  width: 18px;
  height: 20px;
  background: #fff;
  clip-path: polygon(50% 0, 100% 100%, 50% 78%, 0 100%);
}

/* Duration slider */
.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}
.slider-head label { font-size: 0.95rem; font-weight: 700; }
#duration-value { font-size: 1.3rem; font-weight: 700; color: var(--accent); }

#duration {
  --thumb: 30px;
  --fill: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--ratio, 0));
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 44px;
  margin: 0;
  background: none;
  cursor: pointer;
}

#duration::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--line) var(--fill));
}
#duration::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--line) var(--fill));
}

#duration::-webkit-slider-thumb {
  -webkit-appearance: none;
  box-sizing: border-box;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: -12px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgb(0 0 0 / 0.35);
}
#duration::-moz-range-thumb {
  box-sizing: border-box;
  width: var(--thumb);
  height: var(--thumb);
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 1px 5px rgb(0 0 0 / 0.35);
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  height: 12px;
  margin-top: -8px;
  padding: 0 14px;
}
.slider-ticks span { width: 2px; height: 6px; background: var(--line); }
.slider-ticks span.major { height: 11px; }
.slider-ticks span.passed { background: var(--accent); }

.slider-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 0.8rem;
  color: var(--muted);
}
