:root {
  --paper: #F8F2E8;
  --paper-2: #FFFBF4;
  --ink: #2A211C;
  --muted: #76675B;
  --line: #E4D8C5;
  --accent: #B4472B;
  --accent-soft: #F3DFD3;
  --on-accent: #FFF9F2;
  --done: #8C9A84;
  --me: #2F6FDE;
  --shadow: 0 6px 24px rgba(42, 33, 28, .16), 0 1px 3px rgba(42, 33, 28, .12);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --peek: 210px;
  --sheet-h: min(88dvh, calc(100dvh - 64px));
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1F1A17;
    --paper-2: #27211D;
    --ink: #F3EADD;
    --muted: #AC9D8E;
    --line: #3B312B;
    --accent: #E27552;
    --accent-soft: #4A2B21;
    --on-accent: #1F1A17;
    --done: #7E8C77;
    --shadow: 0 6px 24px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  background: var(--paper); color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#map { position: fixed; inset: 0; background: #f8f4f0; }
.maplibregl-ctrl-top-right { top: calc(var(--sat) + 58px); }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; z-index: 5; left: 0; right: 0; top: 0;
  padding: calc(var(--sat) + 10px) 12px 0;
  display: flex; justify-content: space-between; gap: 8px; pointer-events: none;
}
.pill {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 14px; border-radius: 22px;
  background: var(--paper-2); box-shadow: var(--shadow);
  font-weight: 600; font-size: 15px; white-space: nowrap;
}
.pill svg { width: 20px; height: 20px; flex: none; }
.pill b {
  font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums;
  background: var(--accent-soft); color: var(--accent);
  padding: 2px 8px; border-radius: 10px;
}
.pill:active, .fab:active { transform: scale(.96); }

/* ---------- floating buttons ---------- */
.fabs {
  position: fixed; z-index: 4; right: 12px;
  bottom: calc(var(--peek) + 14px);
  display: flex; flex-direction: column; gap: 10px;
  transition: opacity .2s;
}
body.sheet-full .fabs { opacity: 0; pointer-events: none; }
.fab {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--paper-2); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.fab svg { width: 22px; height: 22px; }
#btnLocate .ico-compass { display: none; fill: currentColor; stroke: none; }
#btnLocate.follow { color: var(--me); }
#btnLocate.compass { background: var(--me); color: #fff; }
#btnLocate.compass .ico-locate { display: none; }
#btnLocate.compass .ico-compass { display: block; }

/* ---------- stop pins ---------- */
.pin {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--ink); color: var(--paper-2);
  border: 2px solid var(--paper-2);
  font: 700 13px/1 var(--sans); font-variant-numeric: tabular-nums;
  display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(42, 33, 28, .35);
  transition: width .15s, height .15s, background .15s;
}
.pin svg { width: 15px; height: 15px; stroke-width: 2.4; }
.pin.done { background: var(--done); }
.pin.cur {
  width: 40px; height: 40px; font-size: 16px;
  background: var(--accent); color: #FFF9F2; z-index: 3;
  box-shadow: 0 0 0 6px rgba(180, 71, 43, .22), 0 3px 10px rgba(42, 33, 28, .4);
}

/* ---------- my position ---------- */
.me { width: 22px; height: 22px; pointer-events: none; z-index: 4; }
.me .dot {
  position: absolute; inset: 2px; border-radius: 50%;
  background: var(--me); border: 3px solid #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .35);
}
.me::before {
  content: ""; position: absolute; inset: -9px; border-radius: 50%;
  background: rgba(47, 111, 222, .25); animation: pulse 2.2s ease-out infinite;
}
.me .cone {
  position: absolute; left: 50%; bottom: 50%; width: 0; height: 0;
  margin-left: -17px;
  border-left: 17px solid transparent; border-right: 17px solid transparent;
  border-bottom: 34px solid rgba(47, 111, 222, .38);
  border-radius: 50% 50% 0 0;
  transform-origin: 50% 100%; display: none;
  -webkit-mask-image: linear-gradient(to top, #000 30%, transparent);
  mask-image: linear-gradient(to top, #000 30%, transparent);
}
.me.has-heading .cone { display: block; }
@keyframes pulse { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }

/* ---------- bottom sheet ---------- */
.sheet {
  position: fixed; z-index: 6; left: 0; right: 0; bottom: 0;
  height: var(--sheet-h);
  background: var(--paper); border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 28px rgba(42, 33, 28, .2);
  display: flex; flex-direction: column;
  transform: translateY(calc(var(--sheet-h) - var(--peek)));
  transition: transform .32s cubic-bezier(.2, .8, .2, 1);
  will-change: transform;
}
.sheet.full { transform: translateY(0); }
.sheet.dragging { transition: none; }
.sheet-head { flex: none; padding: 6px 16px calc(12px + var(--sab)); touch-action: none; user-select: none; -webkit-user-select: none; }
.sheet.full .sheet-head { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }

.stop-row { display: flex; align-items: center; gap: 12px; }
.badge {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  font: 700 18px/1 var(--sans); font-variant-numeric: tabular-nums;
  display: grid; place-items: center;
}
.badge svg { width: 20px; height: 20px; stroke-width: 2.2; }
.badge.done { background: var(--done); }
.stop-titles { min-width: 0; }
.stop-titles h1 {
  margin: 0; font: 700 20px/1.2 var(--serif); letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.stop-titles p { margin: 2px 0 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav {
  width: 100%; margin-top: 12px; padding: 10px 12px;
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 14px;
  min-height: 62px;
}
.nav-arrow {
  flex: none; width: 40px; height: 40px; border-radius: 12px;
  background: var(--ink); color: var(--paper);
  display: grid; place-items: center;
}
.nav-arrow svg { width: 24px; height: 24px; stroke-width: 2.6; transition: transform .25s; }
.nav.arrived .nav-arrow { background: var(--done); }
.nav.idle .nav-arrow { background: var(--me); color: #fff; }
.nav-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.nav-main { font-weight: 700; font-size: 17px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-sub { font-size: 13px; color: var(--muted); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dial { flex: none; width: 44px; height: 44px; color: var(--accent); }
.dial[hidden] { display: none; }
.dial svg { width: 44px; height: 44px; transition: transform .2s linear; }
.dial circle { stroke: var(--line); stroke-width: 2; }
.dial path { fill: currentColor; stroke: none; }

.actions { display: flex; gap: 8px; margin-top: 10px; }
.btn {
  height: 48px; padding: 0 16px; border-radius: 14px;
  background: var(--paper-2); border: 1px solid var(--line);
  font-weight: 600; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  flex: 1; white-space: nowrap;
}
.btn svg { width: 20px; height: 20px; }
.btn.ghost { flex: none; width: 48px; padding: 0; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .35; }
.btn.pulse { animation: glow 1.4s ease-in-out 3; }
@keyframes glow { 50% { box-shadow: 0 0 0 6px var(--accent-soft); } }

.sheet-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 calc(28px + var(--sab));
}
.sheet:not(.full) .sheet-body { overflow: hidden; }
.photo { margin: 0; background: var(--line); }
.photo img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; }
.photo figcaption { font-size: 11px; color: var(--muted); padding: 4px 16px 0; text-align: right; }
.photo figcaption a { color: inherit; }
.prose { padding: 0 18px; max-width: 680px; margin: 0 auto; }
.lead { font: italic 500 20px/1.4 var(--serif); margin: 16px 0 14px; text-wrap: pretty; }
.prose p { margin: 0 0 12px; font-size: 16.5px; line-height: 1.58; text-wrap: pretty; }
.prose h3 {
  margin: 22px 0 8px; font: 700 12px/1 var(--sans);
  text-transform: uppercase; letter-spacing: .08em; color: var(--accent);
}
.look { list-style: none; margin: 0; padding: 0; }
.look li {
  position: relative; padding: 10px 0 10px 26px; font-size: 15.5px; line-height: 1.5;
  border-top: 1px solid var(--line); text-wrap: pretty;
}
.look li::before {
  content: ""; position: absolute; left: 4px; top: 18px;
  width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--accent);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 4px; }
.chip { font-size: 13px; padding: 4px 10px; border-radius: 12px; background: var(--paper-2); border: 1px solid var(--line); color: var(--muted); }
.next-card {
  margin: 22px 0 0; padding: 14px; width: 100%; text-align: left;
  border-radius: 16px; background: var(--accent-soft); display: flex; align-items: center; gap: 12px;
}
.next-card small { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--accent); font-weight: 700; }
.next-card b { display: block; font: 700 17px/1.25 var(--serif); margin-top: 2px; }
.next-card span { font-size: 13px; color: var(--muted); }
.next-card svg { flex: none; width: 22px; height: 22px; color: var(--accent); margin-left: auto; }
.ext { display: inline-block; margin-top: 14px; font-size: 14px; color: var(--muted); }

/* ---------- panels ---------- */
.panel {
  position: fixed; z-index: 10; inset: 0; background: var(--paper);
  display: flex; flex-direction: column;
  animation: rise .28s cubic-bezier(.2, .8, .2, 1);
}
.panel[hidden], .intro[hidden] { display: none; }
@keyframes rise { from { transform: translateY(6%); opacity: 0; } }
.panel-head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 14px) 18px 12px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { margin: 0; font: 700 24px/1.2 var(--serif); }
.close { width: 44px; height: 44px; border-radius: 50%; background: var(--paper-2); border: 1px solid var(--line); display: grid; place-items: center; }
.close svg { width: 20px; height: 20px; }
.panel-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 18px calc(32px + var(--sab)); }
.panel-body > * { max-width: 680px; margin-left: auto; margin-right: auto; }

.summary { font-size: 14px; color: var(--muted); margin: 10px auto 6px; }
.stops { list-style: none; margin: 0 auto; padding: 0; }
.stops li button { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; padding: 8px 0; }
.stops .n {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  background: var(--paper-2); border: 1.5px solid var(--ink);
  font: 700 14px/1 var(--sans); display: grid; place-items: center; font-variant-numeric: tabular-nums;
}
.stops .n svg { width: 16px; height: 16px; }
.stops li.done .n { background: var(--done); border-color: var(--done); color: #fff; }
.stops li.cur .n { background: var(--accent); border-color: var(--accent); color: #FFF9F2; }
.stops .t { min-width: 0; }
.stops .t b { display: block; font: 700 16.5px/1.25 var(--serif); }
.stops .t span { font-size: 13px; color: var(--muted); }
.stops .leg {
  margin-left: 16px; padding: 3px 0 3px 28px; border-left: 2px dotted var(--line);
  font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.reset { margin: 20px auto 0; display: block; font-size: 14px; color: var(--muted); text-decoration: underline; }

.timeline { list-style: none; margin: 8px auto 0; padding: 0 0 0 4px; }
.timeline li { position: relative; padding: 0 0 20px 24px; border-left: 2px solid var(--line); }
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: ""; position: absolute; left: -7px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%; background: var(--paper); border: 3px solid var(--accent);
}
.timeline .y { font: 700 13px/1.3 var(--sans); color: var(--accent); letter-spacing: .03em; font-variant-numeric: tabular-nums; }
.timeline h3 { margin: 2px 0 4px; font: 700 18px/1.25 var(--serif); }
.timeline p { margin: 0; font-size: 15.5px; line-height: 1.55; text-wrap: pretty; }
.hist-intro { font: italic 500 18px/1.45 var(--serif); margin: 12px auto 18px; text-wrap: pretty; }

/* ---------- intro ---------- */
.intro {
  position: fixed; z-index: 20; inset: 0;
  background: rgba(42, 33, 28, .45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
}
.intro-card {
  width: 100%; max-width: 520px; background: var(--paper);
  border-radius: 24px 24px 0 0; padding: 26px 22px calc(22px + var(--sab));
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}
.kicker { margin: 0; font: 700 12px/1 var(--sans); text-transform: uppercase; letter-spacing: .1em; color: var(--accent); }
.intro-card h2 { margin: 8px 0 10px; font: 700 30px/1.12 var(--serif); letter-spacing: -.015em; text-wrap: balance; }
.intro-meta { margin: 0 0 12px; font-size: 15px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.intro-meta b { color: var(--ink); font-size: 17px; }
.intro-meta i { width: 4px; height: 4px; border-radius: 50%; background: var(--line); }
.intro-card p { margin: 0 0 10px; font-size: 15.5px; line-height: 1.5; text-wrap: pretty; }
.intro-note { color: var(--muted); font-size: 14px !important; }
.btn.big { width: 100%; height: 54px; font-size: 17px; margin-top: 8px; }
.btn.link { width: 100%; border: 0; background: none; color: var(--muted); height: 44px; font-weight: 500; }

/* ---------- toast ---------- */
.toast {
  position: fixed; z-index: 30; left: 50%; top: calc(var(--sat) + 66px);
  transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 14px;
  background: var(--ink); color: var(--paper); font-size: 14.5px; font-weight: 600; text-align: center;
  box-shadow: var(--shadow); transition: transform .25s, opacity .25s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (min-width: 760px) {
  .sheet { left: 16px; right: auto; width: 420px; border-radius: 20px 20px 0 0; }
  .fabs { bottom: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
