:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d2327;
  --muted: #5f676d;
  --border: #dcd8ce;
  --accent: #2f5d3a;
  --accent-text: #ffffff;
  --done: #2e8b3e;
  --warn-bg: #fff4d6;
  --warn-text: #6b4e00;
  --danger: #b3261e;
  --shadow: 0 4px 18px rgba(20, 24, 28, .16);
  --radius: 12px;
  --gutter: 16px;
  --tap: 44px;
  --topbar-h: 52px;
  --sidebar-w: 360px;
  --card-w: 390px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16191d;
    --surface: #1f2328;
    --surface-2: #2a2f35;
    --text: #e8e6e1;
    --muted: #a0a7ad;
    --border: #3a4047;
    --accent: #7cc48a;
    --accent-text: #0f1a12;
    --done: #6cd17d;
    --warn-bg: #3a3112;
    --warn-text: #f2d98c;
    --danger: #ff8a80;
    --shadow: 0 4px 18px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Top bar ---------- */
#topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1100;
}
.brand {
  display: flex; align-items: center; gap: 8px;
  font-size: 17px; margin: 0; font-weight: 650; white-space: nowrap;
  flex: 1 1 auto; min-width: 0;
}
.brand svg { width: 22px; height: 22px; fill: var(--accent); stroke: none; }
.pill {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: 6px 12px; min-height: 36px; font-weight: 600;
  white-space: nowrap;
}
.icon-btn {
  width: var(--tap); height: var(--tap); display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: 10px; padding: 0; flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.account-btn {
  display: flex; align-items: center; gap: 8px; min-height: 40px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 4px 12px; font-weight: 600; white-space: nowrap; max-width: 46vw;
}
.account-btn.signed-in { padding: 3px; border-color: transparent; }
.account-btn img, .avatar {
  width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-text); font-weight: 700;
}

/* ---------- Layout ---------- */
#layout { position: relative; flex: 1 1 auto; min-height: 0; display: flex; }
#map-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.sheet { background: var(--surface); color: var(--text); }
#sidebar {
  width: var(--sidebar-w); flex: 0 0 auto; overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 12px var(--gutter) 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.mobile-only { display: none !important; }

/* ---------- Progress ---------- */
.progress-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.progress strong { font-size: 24px; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar span { display: block; height: 100%; width: 0; background: var(--done); transition: width .3s; }

.notice {
  background: var(--warn-bg); color: var(--warn-text); border-radius: 10px;
  padding: 10px 12px; font-size: 14px;
}
.notice button { margin-left: 4px; }
.linkish { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; font-weight: 600; }

/* ---------- Tabs + tools ---------- */
.tabs { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.tabs button {
  flex: 1; border: 0; background: transparent; border-radius: 8px; min-height: 38px; font-weight: 600;
  color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.list-tools { display: flex; gap: 8px; }
.list-tools input, .list-tools select, .field {
  min-height: var(--tap); border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); padding: 0 12px;
}
.list-tools input { flex: 1; min-width: 0; }
.list-tools select { flex: 0 0 auto; max-width: 42%; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list li { border-bottom: 1px solid var(--border); }
.list .row {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px;
  padding: 8px 4px; text-align: left; background: none; border: 0;
}
.list .row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 13px; color: var(--muted); display: block; }
.row.is-done .title { text-decoration: line-through; text-decoration-color: var(--muted); }
.list .empty { padding: 20px 4px; color: var(--muted); border: 0; }
.list .section-head { padding: 14px 4px 4px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border: 0; }
.ethel-row { display: flex; align-items: center; gap: 4px; }
.ethel-row .row { flex: 1; }
.attribution { font-size: 12px; margin: 8px 0 0; }

/* Badge used on map + lists */
.badge {
  --c: #555;
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 700; font-size: 12px;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
  letter-spacing: -.02em;
}
.badge.done { background: #8a8f94; }
.badge.done::after { content: ""; }

/* Checkboxes: big tap target */
.tick {
  position: relative; width: var(--tap); height: var(--tap); flex: 0 0 auto;
  display: grid; place-items: center; cursor: pointer;
}
.tick input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.tick span {
  width: 24px; height: 24px; border-radius: 6px; border: 2px solid var(--muted);
  display: grid; place-items: center; background: var(--surface);
}
.tick input:checked + span { background: var(--done); border-color: var(--done); }
.tick input:checked + span::after {
  content: ""; width: 6px; height: 12px; border: solid #fff; border-width: 0 3px 3px 0;
  transform: translateY(-2px) rotate(45deg);
}
.tick input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Chips (filters + legend) ---------- */
.chips {
  position: absolute; top: 60px; left: 10px; right: 64px; z-index: 900;
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding: 2px; pointer-events: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  pointer-events: auto; flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip .sw { width: 18px; height: 4px; border-radius: 2px; background: var(--c); }
.chip .sw.dash { background: repeating-linear-gradient(90deg, #8a8f94 0 5px, transparent 5px 9px); }
.chip[aria-pressed="false"] { opacity: .55; text-decoration: line-through; box-shadow: none; }
.chip-sep { flex: 0 0 6px; }

/* ---------- Card (route / drive detail) ---------- */
.card {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: var(--card-w);
  z-index: 1000; overflow-y: auto; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 0 var(--gutter) var(--gutter);
  overscroll-behavior: contain;
}
.card-head {
  position: sticky; top: 0; background: var(--surface); z-index: 2;
  display: flex; align-items: flex-start; gap: 10px; padding: 14px 0 10px;
}
.card-head h2 { font-size: 18px; margin: 2px 0 0; line-height: 1.25; }
.card-head .grow { flex: 1; min-width: 0; }
.card-head .kicker { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 17px; }
.stat small { color: var(--muted); font-size: 12px; }
.card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.card .ethel-list { list-style: none; padding: 0; margin: 0; }
.card .ethel-list li { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--border); }
.card .ethel-list li:last-child { border-bottom: 0; }
.card .ethel-list .name { flex: 1; min-width: 0; }
.card .ethel-list button.name { background: none; border: 0; text-align: left; padding: 8px 0; min-height: var(--tap); }
.card .notes { font-size: 14px; color: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 600; text-align: center;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn.done-on { background: var(--done); border-color: var(--done); color: #fff; }
.btn.wide { grid-column: 1 / -1; }
.btn[disabled] { opacity: .5; cursor: default; }

/* Elevation profile */
.profile { position: relative; margin-top: 4px; }
.profile svg { display: block; width: 100%; height: 150px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.profile .area { fill: color-mix(in srgb, var(--c) 22%, transparent); stroke: none; }
.profile .line { stroke: var(--c); stroke-width: 2; fill: none; }
.profile .grid { stroke: var(--border); stroke-width: 1; }
.profile text { fill: var(--muted); stroke: none; font-size: 11px; }
.profile .cursor { stroke: var(--text); stroke-width: 1; stroke-dasharray: 3 3; }
.profile .dot { fill: var(--c); stroke: var(--surface); stroke-width: 2; }
.profile .readout {
  position: absolute; top: 0; right: 0; font-size: 12px; font-weight: 600;
  background: var(--surface); padding: 2px 6px; border-radius: 6px; border: 1px solid var(--border);
}
.profile .summit { fill: var(--muted); stroke: none; }

.stops { list-style: none; counter-reset: stop; padding: 0; margin: 0; }
.stops li { counter-increment: stop; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); }
.stops li::before {
  content: counter(stop); width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--surface-2); font-weight: 700; font-size: 13px;
}
.stops .row { flex: 1; display: flex; flex-direction: column; align-items: flex-start; background: none; border: 0; padding: 8px 0; min-height: 52px; text-align: left; }
.stops .row .sub { font-size: 13px; color: var(--muted); }

/* ---------- Map markers ---------- */
.start-icon { background: none; border: 0; }
.start-icon .badge { width: 28px; height: 28px; font-size: 11px; }
.summit-icon { background: none; border: 0; }
.summit-icon svg { width: 100%; height: 100%; overflow: visible; }
.summit-icon path { fill: #6b3b1f; stroke: #fff; stroke-width: 1.6; }
.summit-icon.ticked path { fill: #2ea043; }
.me-dot { background: none; border: 0; }
.me-dot span { display: block; width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(26,115,232,.35), 0 1px 4px rgba(0,0,0,.4); }
.leaflet-control.locate-btn a { width: 44px; height: 44px; display: grid; place-items: center; color: #222; background: #fff; }
.leaflet-control.locate-btn a svg { width: 22px; height: 22px; }
.leaflet-control.locate-btn.active a { color: #1a73e8; }
.leaflet-touch .leaflet-bar a { width: 44px; height: 44px; line-height: 44px; }
.leaflet-touch .leaflet-control-layers-toggle { width: 44px; height: 44px; }
.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 12px 14px; min-width: 190px; }
.leaflet-popup-content .pop-title { font-weight: 700; font-size: 15px; }
.leaflet-popup-content .pop-routes { margin: 6px 0 0; padding: 0; list-style: none; }
.leaflet-popup-content .pop-routes button { background: none; border: 0; padding: 6px 0; color: #2f5d3a; text-decoration: underline; text-align: left; min-height: 32px; }
.leaflet-popup-content label.pop-tick { display: flex; align-items: center; gap: 8px; min-height: 40px; font-weight: 600; cursor: pointer; }
.leaflet-popup-content label.pop-tick input { width: 22px; height: 22px; accent-color: #2ea043; }

/* ---------- Login dialog ---------- */
dialog {
  border: 0; border-radius: var(--radius); padding: 0 var(--gutter) var(--gutter);
  width: min(420px, calc(100vw - 32px)); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog-close-row { display: flex; align-items: center; justify-content: space-between; padding-top: 8px; }
.dialog-close-row h2 { font-size: 18px; margin: 0; }
#login-body { display: flex; flex-direction: column; gap: 12px; }
#login-body .field { width: 100%; }
#login-body form { display: flex; flex-direction: column; gap: 8px; margin: 0; }
#login-body .divider { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
#login-body .divider::before, #login-body .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#login-body .msg { font-size: 14px; }
#login-body .msg.error { color: var(--danger); }
#login-body .who { display: flex; gap: 12px; align-items: center; }
#google-btn { min-height: 44px; display: flex; justify-content: center; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 3000;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mobile ---------- */
@media (max-width: 799px) {
  .mobile-only { display: inline-grid !important; }
  #topbar { gap: 4px; padding-left: 8px; }
  .brand { font-size: 16px; }
  #sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; z-index: 1200;
    max-height: 78dvh; border-right: 0; border-radius: 16px 16px 0 0; box-shadow: var(--shadow);
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateY(105%); transition: transform .25s ease; visibility: hidden;
  }
  #sidebar.open { transform: none; visibility: visible; }
  .sheet-handle {
    display: block !important; align-self: center; width: 64px; height: 24px; flex: 0 0 auto;
    border: 0; background: none; position: relative; margin: -6px 0 -4px;
  }
  .sheet-handle::after {
    content: ""; position: absolute; left: 14px; right: 14px; top: 9px; height: 5px; border-radius: 3px; background: var(--border);
  }
  .card {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto;
    max-height: 62dvh; border-radius: 16px 16px 0 0; z-index: 1150;
    padding-bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
  }
  .card.collapsed { max-height: none; overflow: hidden; }
  .card.collapsed > :not(.card-head) { display: none; }
  .card .sheet-handle { margin: 0 auto; }
  .chips { right: 60px; left: 8px; top: 56px; }
}
@media (min-width: 800px) {
  .card .sheet-handle { display: none !important; }
}

/* ---------- UKH ---------- */
.ukh-btn { font-size: 13px; padding: 6px 10px; }
.ukh-links { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; flex-wrap: wrap; }
.ukh-links a, .ukh-links button { min-height: 32px; display: inline-flex; align-items: center; }
.ukh-link { font-size: 13px; white-space: nowrap; padding: 8px 4px; min-height: var(--tap); display: inline-flex; align-items: center; }
.dialog-body { display: flex; flex-direction: column; gap: 10px; max-height: 70dvh; overflow-y: auto; }
.dialog-body h3 { font-size: 14px; margin: 8px 0 0; }
.dialog-body p { margin: 0; font-size: 14px; }
.steps { margin: 0; padding-left: 20px; font-size: 14px; display: flex; flex-direction: column; gap: 8px; }
.bookmarklet { margin-top: 6px; cursor: grab; }
.snippet { width: 100%; font: 12px/1.3 ui-monospace, Menlo, monospace; padding: 8px; resize: vertical; margin: 8px 0; word-break: break-all; }
details summary { cursor: pointer; font-weight: 600; min-height: 36px; display: flex; align-items: center; }
.import-list { list-style: none; margin: 0; padding: 0; font-size: 14px; max-height: 40dvh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.import-list li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.import-list li:last-child { border-bottom: 0; }
.import-list .tag { font-size: 12px; font-weight: 700; color: var(--done); }
.import-list .tag.old { color: var(--muted); font-weight: 600; }
.row-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 799px) { .ukh-btn { display: none; } }

/* ---------- Trip switch, cross-links, loops ---------- */
.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; margin: 0 0 12px; }
.segmented button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 8px; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.cross-links { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin: 0 0 10px; }
.cross-link { min-height: 36px; color: var(--accent); }
.list .row .sub + .sub { margin-top: 1px; }

/* ---------- Modes: Hill walks | Quick hops | Road trips ---------- */
.modebar {
  position: absolute; top: 10px; left: 10px; z-index: 950; width: min(460px, calc(100% - 20px));
  margin: 0; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border);
}
.modebar button { min-height: 40px; font-size: 14px; white-space: nowrap; padding: 0 6px; }
.modebar button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); box-shadow: none; }
.leaflet-top.leaflet-right { top: 56px; }
.chip-label { pointer-events: none; align-self: center; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface); padding: 4px 8px; border-radius: 6px; box-shadow: var(--shadow); flex: 0 0 auto; }
.badge.wide { border-radius: 14px; padding: 0 4px; }
.start-icon .badge.wide { width: auto; }
.trip-badge { border-radius: 8px; width: auto; min-width: 34px; padding: 0 5px; }
.stops li::before { background: var(--c, var(--surface-2)); color: #fff; }
.hop-row { display: flex; flex-direction: column; align-items: stretch; }
.hop-row .trip-link, .leaflet-popup-content .trip-link { align-self: flex-start; margin: -6px 0 8px 44px; font-size: 13px; min-height: 28px; color: var(--accent); }
.leaflet-popup-content .trip-link { margin: 0; color: #2f5d3a; }
.credit { font-size: 12px; margin: 10px 0 0; }
.explainer {
  position: absolute; top: 104px; left: 10px; z-index: 960; width: 340px;
  background: var(--surface); color: var(--text); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px var(--gutter);
}
.explainer h2 { font-size: 16px; margin: 0 0 8px; }
.explainer ul { margin: 0 0 8px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.explainer p { font-size: 13px; margin: 0 0 10px; }
.explainer .btn { width: 100%; }
@media (max-width: 799px) {
  .modebar { top: 8px; left: 8px; width: calc(100% - 16px); }
  .explainer { position: fixed; top: auto; left: 8px; right: 8px; width: auto; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 1100; }
}

.badge.loop { border-radius: 8px; }
.tag-loop { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; vertical-align: 1px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); text-decoration: none; }
.loop-cta {
  display: block; width: 100%; text-align: left; margin: 0 0 12px; padding: 12px 14px; min-height: var(--tap);
  border-radius: 10px; border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  color: var(--text); font-size: 14px; line-height: 1.35;
}
.loop-cta b { color: var(--accent); }

/* Sidebar list title (mode bar picks the list) */
.list-title { font-size: 16px; margin: 0; }
.walkin-note { display: block; font-size: 12px; color: var(--muted); margin: -6px 0 8px 44px; }
.walkin-note.card-note { margin: 0 0 10px; font-size: 13px; }
/* Four segments: icon + label; stack them on narrow screens so they fit 360px. */
.modebar { width: min(520px, calc(100% - 20px)); }
.modebar .mi { margin-right: 4px; }
@media (max-width: 520px) {
  .modebar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 46px; padding: 2px 2px; font-size: 11px; line-height: 1.1; }
  .modebar .mi { margin: 0; font-size: 17px; }
  .chips { top: 64px; }
  .leaflet-top.leaflet-right { top: 62px; }
}
