:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #fcfcfa;
  --surface-2: #eef0ec;
  --border: #dfe2dc;
  --ink: #131614;
  --ink-2: #4f5651;
  --ink-3: #6f7671;
  --accent: #1f6f8b;
  --accent-ink: #ffffff;
  --accent-soft: #dcecf1;
  --error: #b42318;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 10px rgba(0, 0, 0, .04);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --map-water: #cfe0e8;
  --map-land: #f3f1ea;
  --map-urban: #e6e1d6;
  --map-river: #a9c8d8;
  --map-road: #d8cdb8;
  --map-border: #9aa39d;
  --map-state: #c3c8c1;
  --map-label: #2b302d;
  --map-halo: #fbfaf6;
  --map-point: rgba(31, 111, 139, .55);
  --map-place: #1f6f8b;
  --map-home: #c2410c;
  --m-walk: #15803d;
  --m-cycle: #65a30d;
  --m-car: #2563eb;
  --m-transit: #9333ea;
  --m-flight: #db2777;
  --m-boat: #0891b2;
  --m-other: #78716c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1211;
    --surface: #171b19;
    --surface-2: #212623;
    --border: #2f3531;
    --ink: #eef1ee;
    --ink-2: #bcc3be;
    --ink-3: #939a95;
    --accent: #5fb3cf;
    --accent-ink: #06171d;
    --accent-soft: #15303a;
    --error: #ff8a80;
    --shadow: none;
    --map-water: #0e1b22;
    --map-land: #1d2320;
    --map-urban: #2a302c;
    --map-river: #1d3a48;
    --map-road: #3b3f37;
    --map-border: #5d6761;
    --map-state: #343b37;
    --map-label: #dfe5e0;
    --map-halo: #121614;
    --map-point: rgba(95, 179, 207, .6);
    --map-place: #5fb3cf;
    --map-home: #fb923c;
    --m-walk: #4ade80;
    --m-cycle: #a3e635;
    --m-car: #60a5fa;
    --m-transit: #c084fc;
    --m-flight: #f472b6;
    --m-boat: #22d3ee;
    --m-other: #a8a29e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1211;
  --surface: #171b19;
  --surface-2: #212623;
  --border: #2f3531;
  --ink: #eef1ee;
  --ink-2: #bcc3be;
  --ink-3: #939a95;
  --accent: #5fb3cf;
  --accent-ink: #06171d;
  --accent-soft: #15303a;
  --error: #ff8a80;
  --shadow: none;
  --map-water: #0e1b22;
  --map-land: #1d2320;
  --map-urban: #2a302c;
  --map-river: #1d3a48;
  --map-road: #3b3f37;
  --map-border: #5d6761;
  --map-state: #343b37;
  --map-label: #dfe5e0;
  --map-halo: #121614;
  --map-point: rgba(95, 179, 207, .6);
  --map-place: #5fb3cf;
  --map-home: #fb923c;
  --m-walk: #4ade80;
  --m-cycle: #a3e635;
  --m-car: #60a5fa;
  --m-transit: #c084fc;
  --m-flight: #f472b6;
  --m-boat: #22d3ee;
  --m-other: #a8a29e;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
code { font: 0.92em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 6px 10px; border-radius: 8px; z-index: 10; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; max-width: 1280px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 16px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.back { color: var(--ink-2); text-decoration: none; font-size: 14px; padding: 6px 8px; }
.back:hover { color: var(--ink); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); font: 600 14px var(--font); cursor: pointer; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-within, canvas:focus-visible, .drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); cursor: pointer; font: 600 18px var(--font); }
.icon-btn:hover { border-color: var(--ink-3); }

main { max-width: 1280px; margin: 0 auto; padding: 0 20px 40px; }
.intro { max-width: 860px; margin: 0 auto; }
.hero { text-align: center; padding: 28px 0 18px; }
.hero h1 { font-size: clamp(28px, 4.6vw, 42px); line-height: 1.12; margin: 0 0 12px; letter-spacing: -0.02em; }
.lede { font-size: 17px; color: var(--ink-2); margin: 0 auto 14px; max-width: 640px; }
.privacy { display: inline-flex; align-items: flex-start; gap: 8px; text-align: left; background: var(--accent-soft); color: var(--ink); padding: 10px 14px; border-radius: 12px; margin: 0; font-size: 14px; max-width: 640px; }
.privacy svg { color: var(--accent); flex: none; margin-top: 2px; }

.drop { margin: 18px 0; border: 2px dashed var(--border); border-radius: 18px; background: var(--surface); padding: 28px 20px; text-align: center; transition: border-color .15s, background .15s; }
.drop svg { color: var(--accent); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-title { font-weight: 700; font-size: 16px; margin: 8px 0 4px; }
.drop-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.progress { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; margin: 0 0 16px; }
.progress-row { display: flex; justify-content: space-between; font-weight: 600; font-size: 14px; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress p { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error { color: var(--error); background: var(--surface); border: 1px solid var(--error); border-radius: 12px; padding: 10px 14px; }

.howto h2 { font-size: 18px; margin: 26px 0 10px; }
.howto-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.howto-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.howto-card h3 { margin: 0 0 6px; font-size: 15px; }
.howto-card p { margin: 0; font-size: 14px; color: var(--ink-2); }

/* ---------- results ---------- */
.example-note { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--accent-soft); border-radius: 12px; padding: 8px 14px; margin: 4px 0 12px; font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-size: 20px; line-height: 1.2; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat span { font-size: 12.5px; color: var(--ink-3); }

.map-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.map-tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 99px; border: 1px solid var(--border); font-size: 13px; font-weight: 600; cursor: pointer; background: var(--surface-2); user-select: none; }
.chip input { accent-color: var(--accent); margin: 0; }
.zoom { display: flex; gap: 6px; align-items: center; }
.zoom .icon-btn { width: 32px; height: 32px; }
.map-wrap { position: relative; height: min(68vh, 640px); min-height: 360px; }
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map:active { cursor: grabbing; }
.attrib { position: absolute; right: 6px; bottom: 4px; font-size: 11px; color: var(--ink-3); background: color-mix(in srgb, var(--surface) 75%, transparent); padding: 1px 6px; border-radius: 6px; pointer-events: none; }
.legend { position: absolute; left: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: calc(100% - 140px); font-size: 12px; background: color-mix(in srgb, var(--surface) 85%, transparent); padding: 5px 9px; border-radius: 9px; pointer-events: none; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.popup { position: absolute; z-index: 3; min-width: 200px; max-width: 280px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); padding: 10px 12px; font-size: 13.5px; }
.popup h4 { margin: 0 0 4px; font-size: 14.5px; }
.popup dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0 0; }
.popup dt { color: var(--ink-3); }
.popup dd { margin: 0; font-variant-numeric: tabular-nums; }
.popup .close { position: absolute; right: 6px; top: 4px; border: 0; background: none; color: var(--ink-3); font-size: 18px; cursor: pointer; width: 28px; height: 28px; }

.timebar { padding: 10px 12px 12px; border-top: 1px solid var(--border); }
.time-row { display: flex; align-items: center; gap: 10px; }
.time-row.labels { justify-content: space-between; flex-wrap: wrap; margin-top: 6px; }
.range-label { font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.range2 { position: relative; flex: 1; height: 40px; }
.range-track { position: absolute; left: 8px; right: 8px; top: 4px; bottom: 4px; border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.range-fill { position: absolute; top: 0; bottom: 0; background: var(--accent-soft); }
#spark { position: absolute; inset: 0; width: 100%; height: 100%; }
.range2 input[type=range] { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 40px; margin: 0; background: none; pointer-events: none; -webkit-appearance: none; appearance: none; }
.range2 input[type=range]::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 16px; height: 36px; border-radius: 6px; background: var(--accent); border: 2px solid var(--surface); cursor: ew-resize; }
.range2 input[type=range]::-moz-range-thumb { pointer-events: auto; width: 14px; height: 34px; border-radius: 6px; background: var(--accent); border: 2px solid var(--surface); cursor: ew-resize; }
.range2 input[type=range]::-webkit-slider-runnable-track { background: none; }
.range2 input[type=range]::-moz-range-track { background: none; }
.years { display: flex; gap: 4px; flex-wrap: wrap; }
.years button { border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); border-radius: 8px; padding: 3px 9px; font: 600 12.5px var(--font); cursor: pointer; min-height: 30px; }
.years button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.play { flex: none; }

.panels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.panel h2 { font-size: 16px; margin: 0; }
.panel h3.sub { font-size: 14px; margin: 14px 0 6px; color: var(--ink-2); }
.empty { color: var(--ink-3); font-size: 14px; margin: 4px 0; }

.mode-totals { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13.5px; margin-bottom: 10px; }
.mode-totals span { white-space: nowrap; }
.mode-totals i, .year-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.year-chart svg { width: 100%; height: auto; display: block; }
.year-chart text { fill: var(--ink-2); font: 12px var(--font); }
.year-chart .val { fill: var(--ink); font-weight: 600; }

.trip-list { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow: auto; }
.trip-list li { border-top: 1px solid var(--border); }
.trip-list li:first-child { border-top: 0; }
.trip-list button { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: left; border: 0; background: none; color: var(--ink); padding: 8px 4px; cursor: pointer; font: 14px var(--font); border-radius: 8px; }
.trip-list button:hover, .trip-list button[aria-pressed="true"] { background: var(--surface-2); }
.trip-list .where { font-weight: 600; }
.trip-list .when { color: var(--ink-3); font-size: 13px; }
.trip-list .km { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12.5px; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.place-row { cursor: pointer; }
.table tr.place-row:hover td { background: var(--surface-2); }
.table .pname { font-weight: 600; }
.table .psub { color: var(--ink-3); font-size: 12.5px; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .02em; padding: 0 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; vertical-align: 1px; }
.tag.home { background: color-mix(in srgb, var(--map-home) 18%, transparent); color: var(--map-home); }

.country-list { display: flex; flex-wrap: wrap; gap: 6px; }
.country-list span { background: var(--surface-2); border-radius: 99px; padding: 3px 10px; font-size: 13px; }
.country-list b { font-variant-numeric: tabular-nums; }
.city-list { margin: 0; padding-left: 22px; font-size: 14px; columns: 2; column-gap: 24px; }
.city-list li { break-inside: avoid; padding: 1px 0; }
.city-list .muted { font-size: 12.5px; }

.export-row { display: flex; flex-wrap: wrap; gap: 8px; }
.files { margin-top: 12px; font-size: 13.5px; }
.files summary { cursor: pointer; color: var(--ink-2); font-weight: 600; }
.files ul { margin: 6px 0 0; padding-left: 20px; }

.foot { max-width: 1280px; margin: 0 auto; padding: 10px 20px 30px; color: var(--ink-3); font-size: 13px; text-align: center; }
.foot p { margin: 4px 0; }

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .panels { grid-template-columns: minmax(0, 1fr); }
  .howto-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .top { padding: 10px 16px; }
  .brand span { font-size: 15px; }
  main { padding: 0 16px 32px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .map-wrap { height: 62vh; min-height: 320px; }
  .city-list { columns: 1; }
  .legend { max-width: calc(100% - 16px); bottom: 22px; }
  .example-note { flex-direction: column; align-items: flex-start; }
  #newBtn { display: none; }
}
