/* ============================================================ tokens ===== */
:root {
  color-scheme: light;
  --bg:        #f4f6f9;
  --bg-raise:  #ffffff;
  --bg-high:   #eaeef4;
  --line:      #d2d9e3;
  --line-soft: #e5eaf1;
  --ink:       #14171c;
  --ink-dim:   #545d6b;
  --ink-faint: #828c9b;
  --accent:    #2563eb;
  --accent-2:  #ea580c;
  --good:      #15803d;
  --warn:      #b45309;
  --bad:       #dc2626;
  --on-accent: #ffffff;
  --shadow:    rgba(15, 23, 42, .10);
  --shadow-up: rgba(15, 23, 42, .16);
  --radius:    16px;
  --tap:       44px;
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-t:    env(safe-area-inset-top, 0px);
  --topbar-h:  56px;
  --tabbar-h:  58px;
}

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

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }

/* ============================================================ gate ======= */
.gate {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 0%, #ffffff 0%, var(--bg) 62%);
}
.gate-inner { width: min(420px, 100%); text-align: center; }
.gate-mark { font-size: 52px; line-height: 1; }
.gate h1 { margin: 14px 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.gate-sub { margin: 0 0 26px; color: var(--ink-dim); }
.gate-choices { display: grid; gap: 12px; }
.gate-choice {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 17px; font-weight: 600;
  transition: transform .12s ease, border-color .12s ease;
}
.gate-choice:active { transform: scale(.97); border-color: var(--accent); }
.gate-fine { margin-top: 22px; font-size: 12.5px; color: var(--ink-faint); }

.lock-input {
  width: 100%; min-height: var(--tap);
  padding: 12px 14px; margin-bottom: 12px;
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: 12px; color: var(--ink); font: inherit; font-size: 17px;
  text-align: center; letter-spacing: .06em;
}
.lock-input:focus { outline: none; border-color: var(--accent); }
.lock-go { min-height: var(--tap); }
.lock-err { margin-top: 14px; font-size: 13px; color: var(--bad); }

/* ============================================================ chrome ===== */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; gap: 12px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(150%) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title strong { font-size: 16px; letter-spacing: -.01em; }
.topbar-sub { font-size: 11.5px; color: var(--ink-faint); }

.profile-chip { padding: 0; border-radius: 999px; }
.avatar {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 800; font-size: 14px;
}

.sync-dot {
  width: 9px; height: 9px; border-radius: 999px;
  background: var(--line); transition: background .2s ease;
}
.sync-dot.is-saving { background: var(--warn); }
.sync-dot.is-saved  { background: var(--good); }
.sync-dot.is-error  { background: var(--bad); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(150%) blur(14px);
  border-top: 1px solid var(--line-soft);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 10.5px; font-weight: 600; color: var(--ink-faint);
  transition: color .12s ease;
}
.tab span { font-size: 19px; line-height: 1; }
.tab.is-on { color: var(--accent); }

main {
  padding-top: calc(var(--topbar-h) + var(--safe-t));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
  min-height: 100%;
}
.view { padding: 14px 14px 24px; }
.view-map { padding: 0; height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - var(--safe-t) - var(--safe-b)); }

/* ============================================================ route ====== */
.day-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 18px 2px 12px;
}
.day-head:first-child { margin-top: 2px; }
.day-head h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.day-meta { font-size: 12px; color: var(--ink-faint); }

.stop {
  position: relative;
  display: grid; grid-template-columns: 30px 1fr; gap: 12px;
  padding-bottom: 4px;
}
/* the connecting spine */
.stop::before {
  content: ""; position: absolute; left: 14px; top: 30px; bottom: -6px;
  width: 2px; background: var(--line-soft);
}
.stop:last-child::before { display: none; }

.stop-num {
  z-index: 1;
  width: 30px; height: 30px; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--bg-high); border: 1px solid var(--line);
  font-size: 13px; font-weight: 700; color: var(--ink-dim);
}
.stop-card {
  background: var(--bg-raise); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 12px;
  box-shadow: 0 1px 2px var(--shadow);
}
.stop-time {
  font-size: 12px; font-weight: 700; color: var(--accent);
  letter-spacing: .02em; text-transform: uppercase;
}
.stop-addr { margin: 3px 0 2px; font-size: 16px; font-weight: 650; letter-spacing: -.01em; }
.stop-sub { font-size: 12.5px; color: var(--ink-dim); }
.stop-facts { margin-top: 6px; font-size: 12.5px; color: var(--ink-dim); }
.stop-actions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }

.btn {
  min-height: 38px; padding: 0 14px; border-radius: 10px;
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 650;
  background: var(--bg-high); border: 1px solid var(--line);
  transition: transform .1s ease, background .12s ease;
}
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-ghost { background: transparent; }
.btn-wide { width: 100%; justify-content: center; }

.leg {
  display: flex; align-items: center; gap: 7px;
  margin: -4px 0 12px 42px;
  font-size: 12px; color: var(--ink-faint);
}

.score-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  background: var(--bg-high); border: 1px solid var(--line);
  font-size: 12px; font-weight: 700;
}

.depart, .arrive {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 13px; margin-bottom: 12px;
  background: var(--bg-raise); border: 1px dashed var(--line);
  border-radius: 12px; font-size: 13px; color: var(--ink-dim);
}
.arrive { margin: 2px 0 4px 42px; }
.arrive.is-tight { border-color: var(--warn); color: var(--warn); }

/* ============================================================ cards ====== */
.card-rail {
  display: flex; gap: 12px;
  overflow-x: auto; scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  margin: 0 -14px; padding: 0 14px 10px;
}
.card-rail::-webkit-scrollbar { display: none; }

.card {
  flex: 0 0 100%; scroll-snap-align: center; scroll-snap-stop: always;
  background: var(--bg-raise); border: 1px solid var(--line-soft);
  border-radius: 20px; overflow: hidden;
  box-shadow: 0 1px 3px var(--shadow);
}
.card-head { padding: 14px 16px 12px; border-bottom: 1px solid var(--line-soft); }
.card-eyebrow {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--accent);
}
.card-addr { margin: 6px 0 2px; font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.card-sub { font-size: 12.5px; color: var(--ink-dim); }

.total-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--bg-high);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 2;
}
.total-num { font-size: 28px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.total-max { font-size: 13px; color: var(--ink-faint); font-weight: 600; }
.total-meter { flex: 1; height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.total-meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--good)); transition: width .25s ease; }
.total-done { font-size: 11.5px; color: var(--ink-faint); }

.cats { padding: 6px 10px 4px; }
.cat { padding: 9px 6px; border-bottom: 1px solid var(--line-soft); }
.cat:last-child { border-bottom: 0; }
.cat-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.cat-icon { font-size: 15px; }
.cat-label { font-size: 14px; font-weight: 650; flex: 1; letter-spacing: -.01em; }
.cat-val { font-size: 14px; font-weight: 800; color: var(--ink-faint); min-width: 20px; text-align: right; }
.cat-val.is-set { color: var(--accent); }

.dots { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.dot {
  height: 34px; border-radius: 8px;
  background: var(--bg-high); border: 1px solid transparent;
  font-size: 12px; font-weight: 700; color: var(--ink-faint);
  transition: background .1s ease, color .1s ease, transform .1s ease;
}
.dot:active { transform: scale(.9); }
.dot.is-filled { background: color-mix(in srgb, var(--accent) 22%, var(--bg-high)); color: var(--ink); }
.dot.is-pick {
  background: var(--accent); color: var(--on-accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent);
}

.card-foot { padding: 12px 16px 16px; display: grid; gap: 10px; }
.note-box {
  width: 100%; min-height: 76px; resize: vertical;
  padding: 11px 12px; border-radius: 12px;
  background: var(--bg-high); border: 1px solid var(--line);
  color: var(--ink); font: inherit; font-size: 14px;
}
.note-box::placeholder { color: var(--ink-faint); }
.note-box:focus { outline: none; border-color: var(--accent); }

.shots { display: flex; gap: 8px; flex-wrap: wrap; }
.shot { position: relative; width: 62px; height: 62px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot-x {
  position: absolute; top: 2px; right: 2px;
  width: 20px; height: 20px; border-radius: 999px;
  background: rgba(0,0,0,.65); font-size: 12px; line-height: 20px; text-align: center;
}
.shot-add {
  width: 62px; height: 62px; border-radius: 10px;
  border: 1px dashed var(--line); display: grid; place-items: center;
  font-size: 20px; color: var(--ink-faint);
}

.rail-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 6px; }
.rail-btn {
  width: var(--tap); height: 34px; border-radius: 10px;
  background: var(--bg-raise); border: 1px solid var(--line);
  font-size: 20px; line-height: 1; color: var(--ink-dim);
}
.rail-dots { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; max-width: 60%; }
.rail-dots i {
  width: 6px; height: 6px; border-radius: 999px; background: var(--line);
  transition: background .15s ease, transform .15s ease;
}
.rail-dots i.is-on { background: var(--accent); transform: scale(1.45); }

/* ============================================================ compare ==== */
.compare-toolbar { margin-bottom: 12px; }
.seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: 11px; padding: 3px; gap: 3px;
}
.seg-btn {
  min-height: 32px; border-radius: 8px; font-size: 13px; font-weight: 650;
  color: var(--ink-dim);
}
.seg-btn.is-on { background: var(--bg-high); color: var(--ink); }

.cmp {
  background: var(--bg-raise); border: 1px solid var(--line-soft);
  border-radius: var(--radius); padding: 13px 14px; margin-bottom: 10px;
  box-shadow: 0 1px 2px var(--shadow);
}
.cmp-top { display: flex; align-items: baseline; gap: 10px; }
.cmp-rank { font-size: 12px; font-weight: 800; color: var(--ink-faint); }
.cmp-addr { flex: 1; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.cmp-sum { font-size: 17px; font-weight: 800; }
.cmp-bars { margin-top: 10px; display: grid; gap: 7px; }
.cmp-row { display: grid; grid-template-columns: 54px 1fr 34px; align-items: center; gap: 9px; font-size: 12px; }
.cmp-name { color: var(--ink-dim); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.cmp-bar i { display: block; height: 100%; border-radius: 999px; transition: width .3s ease; }
.cmp-n { text-align: right; font-weight: 700; }
.cmp-gap { margin-top: 9px; font-size: 12px; color: var(--warn); }
.cmp-empty { font-size: 12px; color: var(--ink-faint); margin-top: 8px; }

.compare-breakdown { margin-top: 22px; }
.bd-title { font-size: 13px; font-weight: 700; color: var(--ink-dim); margin: 0 2px 10px; }
.bd-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.bd-table th, .bd-table td { padding: 7px 6px; border-bottom: 1px solid var(--line-soft); text-align: right; }
.bd-table th:first-child, .bd-table td:first-child { text-align: left; color: var(--ink-dim); font-weight: 600; }
.bd-table thead th { color: var(--ink-faint); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.bd-wrap { overflow-x: auto; }
.bd-diff-up { color: var(--good); }
.bd-diff-dn { color: var(--bad); }

/* ============================================================ map ======== */
#map { width: 100%; height: 100%; background: var(--bg-raise); }
.map-recenter {
  position: absolute; right: 10px; top: 10px; z-index: 500;
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; font-size: 17px;
  background: color-mix(in srgb, var(--bg-raise) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line); color: var(--ink-dim);
  box-shadow: 0 2px 10px var(--shadow);
}
.map-recenter:active { transform: scale(.94); }
.leaflet-container { background: var(--bg-high); font: inherit; }
.map-legend {
  position: absolute; left: 10px; bottom: 10px; z-index: 500;
  background: color-mix(in srgb, var(--bg-raise) 92%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 11px; font-size: 11.5px; line-height: 1.6;
}
.map-legend b { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; }
.legend-credit {
  display: block; margin-top: 6px; padding-top: 5px;
  border-top: 1px solid var(--line-soft);
  font-size: 9.5px; color: var(--ink-faint); letter-spacing: .01em;
}
.map-legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }
.pin {
  width: 26px; height: 26px; border-radius: 999px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 1px 5px var(--shadow-up);
}
.leaflet-popup-content-wrapper { background: var(--bg-high); color: var(--ink); border-radius: 12px; }
.leaflet-popup-tip { background: var(--bg-high); }
.leaflet-popup-content { margin: 11px 13px; font-size: 13px; }
.leaflet-popup-content a { color: var(--accent); }

/* ============================================================ misc ======= */
.empty {
  text-align: center; color: var(--ink-faint); font-size: 13.5px;
  padding: 48px 20px; line-height: 1.6;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 80;
  background: var(--bg-high); border: 1px solid var(--line);
  border-radius: 999px; padding: 9px 16px; font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 24px var(--shadow-up);
  animation: toast-in .18s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .card-rail { scroll-behavior: auto; }
}

/* roomier on tablets/desktop, still the same layout */
@media (min-width: 720px) {
  .view { max-width: 680px; margin: 0 auto; }
  .card { flex-basis: 100%; }
}
