/* TrailMaps — warm paper, forest ink, terracotta accent. */

:root {
  --tm-paper: #f3efe4;
  --tm-surface: #fffdf8;
  --tm-glass: rgba(252, 250, 244, 0.86);
  --tm-ink: #1f2a24;
  --tm-ink-2: #3b4640;
  --tm-muted: #6b756f;
  --tm-faint: #9aa29d;
  --tm-line: rgba(31, 42, 36, 0.09);
  --tm-line-2: rgba(31, 42, 36, 0.14);
  --tm-forest: #2f5d46;
  --tm-forest-2: #3d7559;
  --tm-forest-soft: rgba(47, 93, 70, 0.1);
  --tm-accent: #d4683c;
  --tm-accent-soft: rgba(212, 104, 60, 0.12);
  --tm-danger: #b9442f;
  --tm-blue: #2f7fd8;
  --tm-pin: #a3482a;
  --tm-pin-soft: rgba(163, 72, 42, 0.12);
  --tm-radius: 18px;
  --tm-shadow: 0 1px 0 rgba(255, 255, 255, 0.75) inset, 0 12px 32px -10px rgba(31, 42, 36, 0.32), 0 2px 8px rgba(31, 42, 36, 0.08);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --dock-h: 64px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--tm-paper); color: var(--tm-ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
button:disabled { opacity: 0.45; cursor: default; }
:focus-visible { outline: 2px solid var(--tm-accent); outline-offset: 2px; }
.ic { display: block; flex: none; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; } /* long-press drops a point, not a callout */

.glass {
  background: var(--tm-glass);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--tm-shadow);
}

/* ---- Top bar ---------------------------------------------------------------- */

.topbar {
  position: fixed; z-index: 5;
  top: calc(var(--safe-t) + 10px); left: calc(var(--safe-l) + 12px);
  pointer-events: none;
}
.brand {
  pointer-events: auto;
  display: flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 8px 0 10px; border-radius: 14px;
}
.brand-mark { width: 26px; height: 26px; }
.brand-name { font-weight: 720; font-size: 16px; letter-spacing: -0.02em; }
.net {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px 0 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; color: var(--tm-forest);
  background: var(--tm-forest-soft);
}
.net i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.net b { font-weight: 600; }
.net[data-state="offline"] { color: #8a5a12; background: rgba(217, 154, 43, 0.16); }

/* ---- Floating buttons --------------------------------------------------------- */

.fabs {
  position: fixed; z-index: 5;
  top: calc(var(--safe-t) + 10px); right: calc(var(--safe-r) + 12px);
  display: flex; flex-direction: column; gap: 10px;
}
.fab {
  width: 46px; height: 46px; border-radius: 14px;
  display: grid; place-items: center; color: var(--tm-ink-2);
  transition: transform 0.15s var(--ease), color 0.2s;
}
.fab:active { transform: scale(0.94); }
.fab.on { color: var(--tm-blue); }
.fab.follow { color: #fff; background: var(--tm-blue); border-color: transparent; }
.fab.waiting .ic { animation: pulse 1.4s ease-in-out infinite; }
#btn-north .ic { transition: transform 0.1s linear; color: var(--tm-accent); }

@keyframes pulse { 50% { opacity: 0.35; } }

/* Scale bar sits under the brand pill */
.maplibregl-ctrl-top-left { top: calc(var(--safe-t) + 58px); left: calc(var(--safe-l) + 4px); }
.maplibregl-ctrl-scale {
  background: rgba(252, 250, 244, 0.7); border-color: var(--tm-ink-2); color: var(--tm-ink-2);
  font-size: 10px; font-weight: 600; border-radius: 0 0 3px 3px;
}
.maplibregl-ctrl-bottom-right { bottom: calc(var(--safe-b) + var(--dock-h) + 18px); }
.maplibregl-ctrl-attrib.maplibregl-compact { background: rgba(252, 250, 244, 0.8); }

/* ---- Dock --------------------------------------------------------------------- */

.dock {
  position: fixed; z-index: 11; /* stays above an open sheet, like an iOS tab bar */
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + 10px);
  width: min(440px, calc(100% - 24px));
  height: var(--dock-h); border-radius: 22px; padding: 6px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
}
.dock button {
  border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--tm-muted); letter-spacing: 0.01em;
  transition: background 0.2s, color 0.2s;
}
.dock button.active { color: var(--tm-forest); background: var(--tm-forest-soft); }
.dock-ic .ic { width: 22px; height: 22px; }

/* ---- Sheet -------------------------------------------------------------------- */

.sheet {
  position: fixed; z-index: 10;
  left: 0; right: 0; bottom: 0;
  max-height: min(78dvh, 720px);
  display: flex; flex-direction: column;
  background: var(--tm-surface);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 40px -12px rgba(31, 42, 36, 0.35);
  transform: translateY(105%); visibility: hidden;
  transition: transform 0.36s var(--ease), visibility 0s linear 0.36s;
  padding-bottom: calc(var(--safe-b) + var(--dock-h) + 14px);
}
.sheet.open { transform: none; visibility: visible; transition: transform 0.36s var(--ease); }
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--tm-line-2); margin: 8px auto 0; flex: none; }
.sheet-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px 10px 20px; flex: none;
}
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 750; letter-spacing: -0.025em; flex: 1; }
.sheet-actions { display: flex; gap: 6px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 20px; overscroll-behavior: contain; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; color: var(--tm-muted);
  background: rgba(31, 42, 36, 0.06);
}
.icon-btn:active { background: rgba(31, 42, 36, 0.12); }
.icon-btn .ic { width: 18px; height: 18px; }

@media (min-width: 900px) {
  .sheet {
    left: calc(var(--safe-l) + 12px); right: auto; bottom: 12px; top: calc(var(--safe-t) + 64px);
    width: 400px; max-height: none; border-radius: 22px;
    transform: translateX(calc(-100% - 24px));
    box-shadow: var(--tm-shadow);
    padding-bottom: 0;
  }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 16px; }
}

/* ---- Buttons & fields ---------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 18px; border-radius: 14px;
  font-size: 15px; font-weight: 650; letter-spacing: -0.005em;
  transition: transform 0.12s var(--ease), background 0.2s, box-shadow 0.2s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn .ic { width: 19px; height: 19px; }
.btn.primary { background: var(--tm-forest); color: #fff; box-shadow: 0 6px 16px -6px rgba(47, 93, 70, 0.6); }
.btn.accent { background: var(--tm-accent); color: #fff; box-shadow: 0 6px 16px -6px rgba(212, 104, 60, 0.6); }
.btn.soft { background: var(--tm-forest-soft); color: var(--tm-forest); }
.btn.ghost { background: rgba(31, 42, 36, 0.06); color: var(--tm-ink-2); }
.btn.danger { background: var(--tm-danger); color: #fff; }
.btn.small { height: 36px; padding: 0 12px; font-size: 14px; border-radius: 11px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

.field {
  width: 100%; height: 46px; padding: 0 14px;
  border-radius: 13px; border: 1px solid var(--tm-line-2);
  background: #fff; color: var(--tm-ink);
  font: inherit; font-size: 16px; /* ≥16px: no iOS focus zoom */
}
.field:focus { outline: none; border-color: var(--tm-forest-2); box-shadow: 0 0 0 3px var(--tm-forest-soft); }

/* ---- Lists & cards ---------------------------------------------------------------- */

.section-label {
  margin: 18px 4px 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--tm-faint);
}
.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: #fff; border: 1px solid var(--tm-line); border-radius: var(--tm-radius);
  padding: 14px; box-shadow: 0 1px 2px rgba(31, 42, 36, 0.04);
}
.card.tappable { cursor: pointer; transition: transform 0.12s var(--ease), box-shadow 0.2s; }
.card.tappable:active { transform: scale(0.985); }
.card.active { border-color: rgba(47, 93, 70, 0.45); box-shadow: 0 0 0 3px var(--tm-forest-soft); }
.card-top { display: flex; align-items: flex-start; gap: 12px; }
.card-title { font-weight: 680; font-size: 16px; letter-spacing: -0.012em; line-height: 1.25; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { color: var(--tm-muted); font-size: 13px; margin-top: 2px; }
.card-main { flex: 1; min-width: 0; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.card-actions .btn { flex: 1 1 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; color: var(--tm-ink-2); font-variant-numeric: tabular-nums; }
.chips span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chips .ic { width: 14px; height: 14px; color: var(--tm-faint); }

.spark { flex: none; margin-top: 2px; }
.spark-fill { fill: rgba(47, 93, 70, 0.12); }
.spark-line { fill: none; stroke: var(--tm-forest); stroke-width: 1.6; stroke-linejoin: round; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 650; background: var(--tm-forest-soft); color: var(--tm-forest); white-space: nowrap;
}
.badge.warn { background: rgba(217, 154, 43, 0.16); color: #8a5a12; }
.badge.accent { background: var(--tm-accent-soft); color: #a3482a; }

.empty {
  text-align: center; color: var(--tm-muted); padding: 26px 18px 10px; font-size: 14px;
}
.empty .ic { margin: 0 auto 10px; color: var(--tm-faint); width: 34px; height: 34px; }
.empty b { display: block; color: var(--tm-ink); font-size: 16px; margin-bottom: 4px; }

/* Settings rows */
.rows { background: #fff; border: 1px solid var(--tm-line); border-radius: var(--tm-radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 10px 14px;
  border-top: 1px solid var(--tm-line);
}
.row:first-child { border-top: 0; }
.row-ic {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--tm-forest-soft); color: var(--tm-forest);
}
.row-ic .ic { width: 18px; height: 18px; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { font-size: 12.5px; color: var(--tm-muted); margin-top: 1px; }

/* iOS-style switch */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: rgba(31, 42, 36, 0.16);
  transition: background 0.22s var(--ease);
}
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  transition: transform 0.22s var(--ease);
}
.switch input:checked + span { background: var(--tm-forest-2); }
.switch input:checked + span::after { transform: translateX(20px); }

/* Segmented control */
.seg { display: inline-flex; background: rgba(31, 42, 36, 0.07); border-radius: 10px; padding: 2px; }
.seg button { height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--tm-muted); white-space: nowrap; }
.seg button.on { background: #fff; color: var(--tm-ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
/* Full-width variant: equal segments, label over an optional small line */
.seg-block { display: flex; width: 100%; }
.seg-block button { flex: 1 1 0; min-width: 0; padding: 0 6px; }
.seg-block button small { display: block; font-size: 11px; font-weight: 500; color: var(--tm-faint); line-height: 1.1; }
.seg-block.tall button { height: 40px; }

.slope-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 12px 4px 0; font-size: 12px; color: var(--tm-ink-2); }
.slope-legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.slope-legend i { width: 12px; height: 12px; border-radius: 3px; opacity: 0.75; }
.slope-legend[hidden] { display: none; }

/* Download: optional layers */
.dl-layers { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.dl-label { font-size: 12px; font-weight: 600; color: var(--tm-muted); margin: 0 2px 4px; }
.dl-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dl-toggle {
  display: flex; align-items: center; gap: 9px; min-width: 0; height: 46px; padding: 0 10px;
  border-radius: 10px; border: 1px solid var(--tm-line); background: #fff; text-align: left;
}
.dl-toggle .tick {
  flex: none; width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--tm-line-2);
  display: grid; place-items: center; color: transparent;
}
.dl-toggle .tick .ic { width: 12px; height: 12px; }
.dl-toggle .dl-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.dl-toggle .dl-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dl-toggle .dl-size { font-size: 11px; color: var(--tm-faint); white-space: nowrap; font-variant-numeric: tabular-nums; }
.dl-toggle.on { border-color: rgba(47, 93, 70, 0.45); box-shadow: 0 0 0 2px var(--tm-forest-soft); }
.dl-toggle.on .tick { background: var(--tm-forest); border-color: var(--tm-forest); color: #fff; }
.area-layers { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.area-layers span { font-size: 11px; font-weight: 600; color: var(--tm-muted); background: rgba(31, 42, 36, 0.06); border-radius: 6px; padding: 2px 6px; white-space: nowrap; }

/* Layer tiles */
.layer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.layer-tile {
  position: relative; text-align: left; padding: 12px; border-radius: 16px; min-height: 92px;
  background: #fff; border: 1px solid var(--tm-line);
  display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.layer-tile .swatch { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; }
.layer-tile .lt-name { font-weight: 650; font-size: 14px; }
.layer-tile .lt-sub { font-size: 12px; color: var(--tm-muted); }
.layer-tile .tick {
  position: absolute; top: 10px; right: 10px; width: 22px; height: 22px; border-radius: 50%;
  border: 1.5px solid var(--tm-line-2); display: grid; place-items: center; color: transparent;
}
.layer-tile .tick .ic { width: 13px; height: 13px; }
.layer-tile.on { border-color: rgba(47, 93, 70, 0.45); box-shadow: 0 0 0 3px var(--tm-forest-soft); }
.layer-tile.on .tick { background: var(--tm-forest); border-color: var(--tm-forest); color: #fff; }

/* Progress */
.progress { height: 8px; border-radius: 99px; background: rgba(31, 42, 36, 0.08); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--tm-forest-2), var(--tm-forest)); transition: width 0.25s linear; }

.meter { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--tm-muted); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* ---- HUD (active route) ------------------------------------------------------------ */

.hud, .drawbar {
  position: fixed; z-index: 7;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-b) + var(--dock-h) + 20px);
  width: min(560px, calc(100% - 24px));
  border-radius: 22px; padding: 12px 14px 10px;
}
body[data-mode="draw"] .dock, body[data-mode="download"] .dock { display: none; }
body[data-mode="draw"] .drawbar, body[data-mode="download"] .drawbar { bottom: calc(var(--safe-b) + 12px); }
body[data-mode="draw"] .hud, body[data-mode="download"] .hud { display: none; }
body[data-mode="draw"] .maplibregl-ctrl-bottom-right,
body[data-mode="download"] .maplibregl-ctrl-bottom-right { display: none; }
body[data-sheet] .hud { opacity: 0; pointer-events: none; }

.hud-head { display: flex; align-items: center; gap: 10px; }
.hud-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; text-align: left; font-weight: 700; font-size: 15px; letter-spacing: -0.015em; }
.hud-title span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-title .ic { color: var(--tm-faint); }
.hud-state { font-size: 12px; font-weight: 600; color: var(--tm-muted); white-space: nowrap; }
.hud-state.off { color: var(--tm-danger); }
.hud-state.on { color: var(--tm-forest); }
.hud .icon-btn { width: 32px; height: 32px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 10px 0 6px; }
.stat { min-width: 0; }
.stat-v { font-size: 21px; font-weight: 720; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; line-height: 1.1; white-space: nowrap; }
.stat-v small { font-size: 12px; font-weight: 600; color: var(--tm-muted); letter-spacing: 0; margin-left: 2px; }
.stat-k { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--tm-faint); margin-top: 2px; white-space: nowrap; }
.stat-sub { font-size: 11px; font-weight: 600; color: var(--tm-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.hud-profile { height: 118px; margin: 0 -4px; }
.hud-line { display: none; width: 100%; align-items: center; gap: 10px; margin-top: 8px; text-align: left; }
.hud-line .progress { flex: 0 0 72px; height: 6px; }
.hud-line-text { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 600; color: var(--tm-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.hud.collapsed .hud-line { display: flex; }
.hud.collapsed .stats, .hud.collapsed .hud-profile, .hud.collapsed .hud-actions, .hud.collapsed .hud-pick, .hud.collapsed .hud-next { display: none !important; }
.hud-actions, .hud-pick { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.hud-actions .btn { flex: 1 1 0; min-width: 0; white-space: nowrap; }
.hud-actions .btn .ic, .hud-pick .btn .ic { width: 16px; height: 16px; }
.hud-pick > span { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: var(--tm-ink-2); }
.hud-pick .btn { flex: none; }
.hud.picking .hud-profile { box-shadow: 0 0 0 2px var(--tm-accent-soft); border-radius: 10px; }

/* Trip sheet */
.trip-profile { height: 132px; margin: 0 -4px 4px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; font-size: 14px; font-variant-numeric: tabular-nums; }
.kv.kv3 { grid-template-columns: 1fr 88px 88px; margin-bottom: 8px; }
.kv-k { color: var(--tm-muted); min-width: 0; }
.kv-v { font-weight: 650; text-align: right; white-space: nowrap; }
.kv-h { font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--tm-faint); text-align: right; }
.trip-cta p, .trip-note { font-size: 13px; color: var(--tm-muted); margin: 8px 0 10px; }
.trip-cta .btn { width: 100%; }
.trip-end { margin-top: 12px; }
.trip-dest { margin-bottom: 8px; }

/* Draw bar */
.draw-hint { font-size: 13px; color: var(--tm-muted); display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.draw-hint b { color: var(--tm-ink); font-weight: 650; }
.draw-tools { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.draw-tools .btn.small { flex: none; }
.draw-tools .spacer { flex: 1; }
.tool { height: 40px; min-width: 40px; padding: 0 10px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: rgba(31, 42, 36, 0.06); font-size: 13px; font-weight: 650; color: var(--tm-ink-2); }
.tool .ic { width: 18px; height: 18px; }
.tool.on { background: var(--tm-accent-soft); color: #a3482a; }
.drawbar .hud-profile { height: 96px; }

/* Next saved point on the route */
.hud-next {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  margin: 0 0 6px; padding: 6px 10px; border-radius: 11px;
  background: var(--tm-pin-soft); color: var(--tm-ink-2); font-size: 13px;
}
.hud-next .ic { color: var(--tm-pin); }
.hud-next > span:first-of-type { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-next b { font-weight: 650; color: var(--tm-ink); }
.hud-next-d { white-space: nowrap; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--tm-ink-2); }

/* ---- Place card (search result / saved point) ------------------------------------- */

.place { z-index: 8; padding-bottom: 12px; }
body[data-place] .hud:not(.place) { display: none; }
body[data-sheet] .place { opacity: 0; pointer-events: none; }
body[data-mode="draw"] .place, body[data-mode="download"] .place { display: none; }
.place-head { display: flex; align-items: flex-start; gap: 10px; }
.place-head .icon-btn { width: 32px; height: 32px; }
.place-main { flex: 1; min-width: 0; padding-top: 1px; }
.place-sub { font-size: 13px; color: var(--tm-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.place .chips { margin-top: 10px; }
.place .card-actions { margin-top: 12px; flex-wrap: nowrap; }
.place .card-actions .btn[data-act="delete"] { flex: none; }

.place-ic {
  width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--tm-forest-soft); color: var(--tm-forest);
}
.place-ic.pin { background: var(--tm-pin-soft); color: var(--tm-pin); }

/* ---- Route card (a saved route selected on the map) -------------------------------- */

.routecard .place-head { align-items: center; }
.route-ic { background: color-mix(in srgb, var(--route, var(--tm-forest)) 14%, transparent); color: var(--route, var(--tm-forest)); }
.rc-name { flex: none; max-width: 100%; }
.rc-name .ic { flex: none; }
.routecard .spark { flex: none; }
.swatches { display: flex; gap: 8px; margin-top: 12px; }
.swatch-btn {
  width: 28px; height: 28px; border-radius: 50%; background: var(--c); flex: none;
  box-shadow: 0 0 0 2px var(--tm-surface) inset; border: 2px solid transparent;
}
.swatch-btn.on { border-color: var(--c); box-shadow: 0 0 0 3px var(--tm-surface) inset; }
/* Bigger touch target than the dot itself. */
.swatch-btn { position: relative; }
.swatch-btn::after { content: ''; position: absolute; inset: -6px -3px; }
.swatch-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; flex: none; }

/* ---- Route editor handles (DOM markers) ---------------------------------------------- */

/* The visible dot is small; the element is a 44 px touch target around it. */
.wp, .wp-mid { width: 44px; height: 44px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.wp i { width: 16px; height: 16px; border-radius: 50%; background: #fff; border: 3px solid var(--tm-accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); transition: transform 0.12s var(--ease); }
.wp-start i { background: var(--tm-forest); border-color: #fff; }
.wp-end i { background: #fff; border-color: var(--tm-forest); width: 18px; height: 18px; border-width: 4px; }
.wp.sel i { transform: scale(1.35); box-shadow: 0 0 0 6px var(--tm-accent-soft), 0 1px 4px rgba(0, 0, 0, 0.3); }
.wp.locked { cursor: pointer; }
.wp.locked i { border-style: dotted; }
.wp-mid i { width: 12px; height: 12px; border-radius: 50%; background: rgba(255, 255, 255, 0.85); border: 2px solid var(--tm-accent); opacity: 0.85; }
.wp-mid.dragging i { opacity: 1; transform: scale(1.3); }
.maplibregl-marker:active .wp, .wp:active { cursor: grabbing; }
.tool.danger { background: rgba(185, 68, 47, 0.1); color: var(--tm-danger); }

/* ---- Directions --------------------------------------------------------------------- */

/* Next turn on the route card: stays visible when the card is collapsed. */
.hud-cue {
  display: flex; align-items: center; gap: 8px; width: 100%; min-width: 0; text-align: left;
  margin: 10px 0 0; padding: 7px 10px; border-radius: 11px;
  background: var(--tm-forest-soft); color: var(--tm-ink); font-size: 14px;
}
.hud-cue .cue-ic { color: var(--tm-forest); }
.hud-cue .cue-when { font-weight: 720; white-space: nowrap; font-variant-numeric: tabular-nums; }
.hud-cue .cue-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--tm-ink-2); }
.hud.collapsed .hud-cue { margin-top: 8px; }

.cues { display: flex; flex-direction: column; }
.cue {
  display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start; width: 100%;
  padding: 9px 2px; border-top: 1px solid var(--tm-line); text-align: left;
}
.cue:first-child { border-top: 0; }
.cue-ic { display: grid; place-items: center; width: 26px; height: 22px; color: var(--tm-ink-2); }
.cue-main { display: flex; flex-direction: column; min-width: 0; }
.cue-title { font-size: 14.5px; line-height: 1.3; }
.cue-detail { font-size: 12.5px; color: var(--tm-muted); margin-top: 1px; }
.cue-at { display: flex; flex-direction: column; align-items: flex-end; font-size: 12.5px; color: var(--tm-muted); font-variant-numeric: tabular-nums; white-space: nowrap; padding-top: 1px; }
.cue-dist { font-size: 11.5px; color: var(--tm-faint); }
.cue.major .cue-title { font-weight: 700; color: var(--tm-ink); }
.cue.major .cue-ic { color: var(--tm-forest); }
.cue.minor { padding: 5px 2px; }
.cue.minor .cue-title { font-size: 13px; color: var(--tm-faint); }
.cue.minor .cue-ic, .cue.minor .cue-at { color: var(--tm-faint); }
.cue.minor .cue-ic .ic { width: 12px; height: 12px; }
.cue.done { opacity: 0.45; }
.cue.next { background: var(--tm-forest-soft); border-radius: 12px; border-top-color: transparent; padding-left: 8px; padding-right: 8px; margin: 2px -6px; width: calc(100% + 12px); }
.cue.next + .cue { border-top-color: transparent; }

/* Reverse direction: a quiet icon button; it pulses once when you're at the far end. */
.hud-actions .hud-rev { flex: none; width: 36px; height: 36px; border-radius: 11px; background: rgba(31, 42, 36, 0.06); color: var(--tm-ink-2); }
.hud-rev.on { background: var(--tm-forest-soft); color: var(--tm-forest); }
.hud-rev.nudge { background: var(--tm-accent-soft); color: #a3482a; animation: tm-nudge 1.6s var(--ease) 2; }
@keyframes tm-nudge { 0%, 100% { transform: none; } 30% { transform: scale(1.12); } }

/* ---- Segment splits ------------------------------------------------------------------ */

.splits { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.split { display: grid; grid-template-columns: 22px 1fr 76px 66px; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--tm-line); font-size: 14px; }
.split.head { border-top: 0; padding: 0 0 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--tm-faint); }
.split.head span:nth-child(n+3) { text-align: right; }
.split-n { font-weight: 700; color: var(--tm-muted); text-align: center; }
.split-main { display: flex; flex-direction: column; min-width: 0; }
.split-main small, .split-rate small { font-size: 11.5px; color: var(--tm-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.split-time { text-align: right; font-weight: 650; white-space: nowrap; }
.split-rate { text-align: right; font-weight: 650; display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }
.split.ahead, .split.skipped { color: var(--tm-faint); }
.split.ahead .split-time .plan { font-weight: 500; }
.split.current { background: var(--tm-forest-soft); border-radius: 10px; border-top-color: transparent; margin: 0 -6px; padding: 8px 6px; }
.split.current + .split { border-top-color: transparent; }

/* Daylight (experimental) */
.hud-sun { margin: 0 0 6px; }
.sun-line { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 11px; font-size: 13px; font-weight: 600; background: rgba(242, 178, 51, 0.16); color: #7a5410; }
.sun-line .ic { flex: none; }
.sun-line.tight { background: rgba(212, 104, 60, 0.14); color: #a3482a; }
.sun-line.dark { background: rgba(185, 68, 47, 0.12); color: var(--tm-danger); }
.sun-chip { color: #7a5410; }
.sun-chip .ic { color: #c98a14 !important; }
.sun-chip.dark { color: var(--tm-danger); }
.hud.collapsed .hud-sun { display: none !important; }

/* Trips in the History sheet */
.act-row { width: 100%; text-align: left; }
.muted { color: var(--tm-muted); font-weight: 500; }
.live { color: var(--tm-accent); font-weight: 650; }

/* ---- Search sheet ------------------------------------------------------------------ */

.search-box { position: relative; }
.search-box > .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--tm-faint); pointer-events: none; }
.search-box .field { padding-left: 40px; -webkit-appearance: none; appearance: none; }
.search-box .field::-webkit-search-decoration { -webkit-appearance: none; }
.search-note { display: flex; align-items: center; gap: 6px; }
.search-note .ic { flex: none; }
.section-label .ic { display: inline-block; vertical-align: -2px; margin-right: 5px; }
.results .rows + .section-label { margin-top: 20px; }

.result {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 9px 14px;
  border-top: 1px solid var(--tm-line); text-align: left;
}
.result:first-child { border-top: 0; }
.result:active { background: rgba(31, 42, 36, 0.04); }
.result-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.result-name { font-weight: 620; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-sub { font-size: 12.5px; color: var(--tm-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }

.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Download frame ------------------------------------------------------------------ */

#frame { position: fixed; inset: 0; z-index: 4; pointer-events: none; display: none; }
body[data-mode="download"] #frame { display: block; }
.frame-box {
  position: absolute;
  top: calc(var(--safe-t) + 112px); left: 26px; right: 26px; bottom: calc(var(--safe-b) + var(--dl-h, 238px) + 24px);
  border-radius: 18px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(212, 104, 60, 0.4), 0 0 0 200vmax rgba(24, 32, 28, 0.45), 0 0 0 1px rgba(31, 42, 36, 0.25) inset;
}
.frame-size {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: rgba(24, 32, 28, 0.72); color: #fff; font-size: 12.5px; font-weight: 650;
  padding: 5px 11px; border-radius: 99px; white-space: nowrap; font-variant-numeric: tabular-nums;
}

/* ---- Toast & dialog -------------------------------------------------------------------- */

.toast {
  position: fixed; z-index: 30; left: 50%; top: calc(var(--safe-t) + 62px);
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px);
  background: rgba(31, 42, 36, 0.92); color: #fff; font-size: 14px; font-weight: 550;
  padding: 10px 16px; border-radius: 14px; box-shadow: 0 10px 30px -8px rgba(0, 0, 0, 0.4);
  transition: opacity 0.25s, transform 0.3s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: rgba(160, 52, 34, 0.95); }
.toast[data-kind="ok"] { background: rgba(37, 82, 60, 0.95); }

.dialog-backdrop {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 24px;
  background: rgba(20, 28, 24, 0); transition: background 0.2s;
}
.dialog-backdrop.show { background: rgba(20, 28, 24, 0.4); }
.dialog {
  width: min(360px, 100%); background: var(--tm-surface); border-radius: 22px; padding: 20px;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.45);
  transform: scale(0.94); opacity: 0; transition: transform 0.22s var(--ease), opacity 0.2s;
}
.dialog-backdrop.show .dialog { transform: none; opacity: 1; }
.dialog h3 { margin: 0 0 6px; font-size: 18px; letter-spacing: -0.02em; }
.dialog p { margin: 0 0 14px; color: var(--tm-muted); font-size: 14px; }
.dialog .field { margin: 6px 0 4px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 14px; }
.dialog-actions .btn { flex: 1; }
.dialog-actions .btn { padding: 0 10px; white-space: nowrap; }

.link-btn { display: block; margin: 10px 2px 0; padding: 4px 0; font-size: 14px; font-weight: 600; color: var(--tm-forest); }

/* Stacked options (share format, join or not) and the note field */
.dialog-choices { display: grid; gap: 8px; }
.dialog-choices .btn { height: auto; min-height: 46px; padding: 8px 14px; flex-direction: column; gap: 1px; white-space: normal; text-align: center; }
.dialog-choices .btn small { font-size: 12.5px; font-weight: 500; opacity: 0.8; }
.dialog-choices + .dialog-actions { margin-top: 8px; }
.parts + .dialog-choices { margin-top: 14px; }
.dialog-field { display: grid; gap: 4px; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--tm-muted); }
.note-field { height: auto; min-height: 96px; padding: 10px 14px; line-height: 1.4; resize: vertical; }
.paste-field { height: auto; min-height: 110px; padding: 10px 14px; line-height: 1.35; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 16px; word-break: break-all; }

/* Choosing the parts of a joined route */
.parts-list { max-height: 38vh; overflow-y: auto; border: 1px solid var(--tm-line); border-radius: 13px; background: #fff; }
.part { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 12px; border-top: 1px solid var(--tm-line); font-size: 15px; }
.part:first-child { border-top: 0; }
.part input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--tm-forest); }
.part .swatch-dot { flex: none; }
.part-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.part-d { flex: none; font-size: 13px; color: var(--tm-muted); font-variant-numeric: tabular-nums; }
.parts-sum { margin-top: 8px; font-size: 13px; color: var(--tm-muted); }
.dialog-choices .btn:disabled { opacity: 0.45; }

/* A note on a card: clamped to three lines until tapped */
.note-text {
  margin: 8px 0 2px; font-size: 14px; line-height: 1.4; color: var(--tm-ink-2); white-space: pre-line;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer;
}
.note-text.open { display: block; -webkit-line-clamp: unset; max-height: 40vh; overflow-y: auto; }

/* Offline-maps offer after an import (ui/importarea.js) and its settings row */
.import-area { display: grid; gap: 8px; }
.ia-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; font-weight: 600; }
.ia-row .field, [data-buffer-wrap] .field { width: auto; min-width: 96px; height: 40px; margin: 0; padding: 0 10px; }
.ia-est { font-size: 13px; color: var(--tm-muted); }
.ia-est.bad { color: var(--tm-danger); }
.ia-check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.ia-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--tm-forest); }
.ia-check small { color: var(--tm-muted); font-size: 12.5px; }

.note { font-size: 12.5px; color: var(--tm-muted); margin: 10px 4px 0; line-height: 1.45; }
.note a { color: var(--tm-forest); }

/* Methodology page */
.doc { font-size: 14px; line-height: 1.55; color: var(--tm-ink-2); }
.doc h1 { font-size: 20px; margin: 4px 0 8px; color: var(--tm-ink); letter-spacing: -0.02em; }
.doc h2 { font-size: 16px; margin: 18px 0 6px; color: var(--tm-ink); }
.doc h3 { font-size: 14px; margin: 14px 0 4px; color: var(--tm-ink); }
.doc p, .doc ul { margin: 0 0 10px; }
.doc ul { padding-left: 20px; }
.doc code { background: rgba(31, 42, 36, 0.06); padding: 1px 5px; border-radius: 5px; font-size: 12.5px; }
.doc a { color: var(--tm-forest); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
.part.focus { background: color-mix(in srgb, var(--tm-forest) 10%, #fff); }
.part.focus .part-name { font-weight: 700; }
.routecard .alt-hint { margin-top: 6px; font-size: 13px; color: var(--tm-muted); }

/* ---- A route found by the old online search: source link, saved page ------------ */

.btn:disabled { opacity: 0.45; pointer-events: none; }
.rc-web { display: flex; align-items: center; gap: 14px; margin-top: 8px; font-size: 13px; }
.rc-web a, .rc-web button { display: inline-flex; align-items: center; gap: 5px; color: var(--tm-forest); font-weight: 600; text-decoration: none; min-width: 0; }
.rc-web a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-web .ic { flex: none; }
.saved-page .note .ic { vertical-align: -2px; }
.saved-sum { font-style: italic; }
.saved-page a { color: var(--tm-forest); word-break: break-word; }
.link-btn .ic { display: inline-block; vertical-align: -2px; margin-right: 5px; }
.saved-page .note .ic { display: inline-block; vertical-align: -2px; margin-right: 2px; }

/* ---- Routes sheet: paste, search and sort (ui/routes.js) --------------------------- */

.paste-btn { display: block; margin: 12px 2px 0; padding: 4px 0; text-align: left; color: var(--tm-forest); }
.paste-title { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; }
.paste-title .ic { flex: none; }
/* Lines up with the label, past the 16px icon and its 6px gap. */
.paste-sub { display: block; margin: 2px 0 0 22px; font-size: 12.5px; font-weight: 500; color: var(--tm-muted); }
.route-tools { display: flex; gap: 8px; margin-top: 16px; }
.route-tools[hidden] { display: none; }
.route-tools .search-box { flex: 1; min-width: 0; }
.sort-box { position: relative; flex: none; width: 128px; }
.sort-box > .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--tm-faint); pointer-events: none; }
.sort-box .field {
  padding: 0 26px 0 34px; -webkit-appearance: none; appearance: none; text-overflow: ellipsis;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%237a857e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center;
}
.card.flash { box-shadow: 0 0 0 3px var(--tm-forest-soft), 0 0 0 1px var(--tm-forest-2); transition: box-shadow 0.3s; }
.rc-nav { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--tm-ink-2); }
.routecard { touch-action: pan-y; }
