:root {
  --blue: #0b57d0;
  --blue-dark: #0842a0;
  --accent: #007b8b;
  --tonal: #d4f6ff;
  --text: #202124;
  --muted: #5f6368;
  --line: #e8eaed;
  --card: #ffffff;
  --hover: #f1f3f4;
  --field: #ffffff;
  --border: #dadce0;
  --chip: #e8f0fe;
  --ground: #f2f1ec;
  --shadow: 0 1px 2px rgba(60,64,67,.3), 0 2px 6px 2px rgba(60,64,67,.15);
  --radius: 8px;
  --panel-w: 400px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
:root[data-theme="dark"] {
  --blue: #8ab4f8;
  --blue-dark: #aecbfa;
  --accent: #4dd0e1;
  --tonal: #1f3b40;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --line: #3c4043;
  --card: #202124;
  --hover: #303134;
  --field: #303134;
  --border: #5f6368;
  --chip: #394457;
  --ground: #242f3e;
  --shadow: 0 1px 3px rgba(0,0,0,.5), 0 4px 8px 3px rgba(0,0,0,.3);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 Roboto, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--ground); overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
#map { position: absolute; inset: 0; }
svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- panel ---------- */
.panel {
  position: absolute; top: calc(8px + var(--sat)); left: 8px; width: var(--panel-w);
  max-width: calc(100% - 16px); z-index: 5; display: flex; flex-direction: column; gap: 8px;
  max-height: calc(100% - 16px - var(--sat) - var(--sab)); pointer-events: none;
}
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); pointer-events: auto; }
.search { padding: 4px; border-radius: 24px; }
.search .row { display: flex; align-items: center; gap: 2px; }
.search input {
  flex: 1; min-width: 0; height: 40px; border: 0; outline: 0; background: none; font-size: 16px; padding: 0 6px;
}
.search input::-webkit-search-cancel-button { display: none; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.blue { color: var(--accent); }

.suggest { list-style: none; margin: 4px 4px 0; padding: 6px 0 4px; border-top: 1px solid var(--line); max-height: 50vh; overflow: auto; }
.suggest li { display: flex; align-items: center; gap: 12px; padding: 8px 10px; cursor: pointer; border-radius: 6px; }
.suggest li:hover, .suggest li.active { background: var(--hover); }
.suggest .ico { width: 24px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--muted); flex: none; }
.suggest .ico svg { width: 20px; height: 20px; }
.suggest .txt { min-width: 0; }
.suggest .t1 { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest .t1 b { font-weight: 700; }
.suggest .t2 { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest .dist { margin-left: auto; color: var(--muted); font-size: 12px; flex: none; }

/* ---------- place ---------- */
.place { padding: 14px 16px 12px; overflow: auto; }
.place-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.place h2 { margin: 2px 0 2px; font-size: 22px; font-weight: 500; line-height: 28px; }
.actions { display: flex; gap: 8px; margin: 12px 0 4px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 10px; border-radius: 18px;
  border: 0; color: #00363d; font-weight: 500; background: var(--tonal);
}
:root[data-theme="dark"] .pill { color: #b2ebf2; }
.pill { height: 40px; border-radius: 20px; }
.pill svg { width: 18px; height: 18px; }
.pill:hover { background: var(--hover); }
.pill.primary { background: var(--blue); color: #fff; }
:root[data-theme="dark"] .pill.primary { color: #062e6f; }
.pill.primary:hover { filter: brightness(1.08); }
.pill.white { box-shadow: var(--shadow); border: 0; color: var(--text); text-decoration: none; }
.place-extra { font-size: 13px; color: var(--muted); }
.place-extra .dep { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); color: var(--text); }
.place-extra .dep .time { width: 52px; font-variant-numeric: tabular-nums; }
.place-extra .dep .rt { color: #188038; font-size: 12px; }

/* ---------- directions ---------- */
.dir { display: flex; flex-direction: column; overflow: hidden; max-height: 100%; }
.modes { display: flex; align-items: center; gap: 2px; padding: 6px 8px 0; }
.mode { width: 48px; height: 40px; border-radius: 20px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.mode.active { background: var(--chip); color: var(--blue); }
.spacer { flex: 1; }
.endpoints { display: flex; align-items: stretch; gap: 8px; padding: 8px 8px 4px 16px; }
.dots { display: flex; flex-direction: column; align-items: center; padding: 14px 0; }
.dots .dot { width: 10px; height: 10px; border-radius: 50%; border: 2.5px solid var(--muted); background: var(--card); }
.dots .dot.to { border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border-color: #ea4335; background: #ea4335; width: 11px; height: 11px; }
.dots .line { flex: 1; border-left: 2px dotted #bdc1c6; margin: 4px 0; }
.inputs { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.inputs input { height: 40px; border: 1px solid var(--border); border-radius: 4px; padding: 0 12px; font-size: 15px; outline: 0; width: 100%; background: var(--field); }
.inputs input:focus { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.when { display: flex; gap: 8px; padding: 4px 16px 8px; align-items: center; }
.when select, .when input { height: 34px; border: 1px solid var(--border); border-radius: 17px; padding: 0 12px; background: var(--field); outline: 0; color: var(--text); }
.results { overflow: auto; border-top: 1px solid var(--line); }
.results:empty { border: 0; }
.itin { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.itin:hover, .itin.active { background: var(--hover); }
.itin.active { box-shadow: inset 4px 0 0 var(--blue); }
.itin .big { font-size: 26px; font-weight: 500; color: #188038; line-height: 1.2; }
:root[data-theme="dark"] .itin .big { color: #81c995; }
.itin .line2 { font-size: 14px; color: var(--text); margin-top: 2px; }
.itin .top { display: flex; justify-content: space-between; align-items: baseline; }
.itin .times { font-size: 16px; font-weight: 500; }
.itin .dur { font-size: 16px; font-weight: 500; }
.itin .chain { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin-top: 6px; color: var(--muted); }
.itin .chain svg { width: 18px; height: 18px; }
.itin .chain .arrow { font-size: 11px; }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: 4px; font-size: 12px; font-weight: 700; color: #fff; background: #5f6368; }
.itin .sub { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.status { padding: 16px; color: var(--muted); text-align: center; }
.detail { padding: 8px 0 12px; }
.detail .back { display: flex; align-items: center; gap: 4px; color: var(--blue); padding: 6px 12px; font-weight: 500; }
.detail .back svg { width: 20px; height: 20px; }
.detail .summary { padding: 4px 16px 10px; font-size: 15px; font-weight: 500; border-bottom: 1px solid var(--line); }
.leg { display: grid; grid-template-columns: 52px 22px 1fr; gap: 0 8px; padding: 0 12px; }
.leg .t { font-size: 13px; color: var(--muted); padding-top: 8px; font-variant-numeric: tabular-nums; text-align: right; }
.leg .bar { position: relative; }
.leg .bar::before { content: ""; position: absolute; left: 9px; top: 12px; bottom: -12px; width: 4px; border-radius: 2px; background: var(--c, #bdc1c6); }
.leg.walk .bar::before { width: 0; border-left: 4px dotted #9aa0a6; background: none; }
.leg .bar .pt { position: absolute; left: 4px; top: 8px; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 3px solid var(--c, #5f6368); }
.leg .body { padding: 6px 0 14px; }
.leg .body .name { font-size: 15px; font-weight: 500; }
.leg .body .info { color: var(--muted); font-size: 13px; }
.leg .body .steps { margin: 6px 0 0; padding-left: 16px; color: var(--muted); font-size: 13px; }
.leg .body .stops { margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.leg.end .bar::before { display: none; }

/* ---------- timeline ---------- */
.tl { display: flex; flex-direction: column; overflow: hidden; max-height: 100%; }
.tl-head { display: flex; align-items: center; gap: 2px; padding: 6px 8px; }
.tl-head input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.tl-date-btn { flex: 1; text-align: center; font-size: 18px; font-weight: 500; height: 40px; border-radius: 20px; }
.tl-date-btn:hover { background: var(--hover); }
.tl-stats { display: flex; justify-content: center; gap: 28px; padding: 6px 16px 12px; font-size: 14px; color: var(--text); }
.tl-stats span { display: inline-flex; align-items: center; gap: 6px; }
.tl-stats svg { width: 20px; height: 20px; color: var(--muted); }
.tl-list { overflow: auto; border-top: 1px solid var(--line); }
.tl-list:empty { border: 0; }
.tl-row { display: grid; grid-template-columns: 40px 1fr 24px; gap: 0 12px; padding: 0 12px; cursor: pointer; }
.tl-row:hover { background: var(--hover); }
.tl-row .bar { position: relative; }
.tl-row .bar::before { content: ""; position: absolute; left: 19px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.tl-row.visit .bar .pt { position: absolute; left: 0; top: 14px; width: 40px; height: 40px; border-radius: 50%; background: #78909c; color: #fff; display: flex; align-items: center; justify-content: center; }
.tl-row.visit .bar .pt svg { width: 22px; height: 22px; }
.tl-row.visit .bar.saved .pt { background: #4286f5; }
.tl-row.move .bar .pt { position: absolute; left: 0; top: 12px; width: 40px; height: 40px; border-radius: 50%; background: var(--card); border: 2px solid #3c4043; display: flex; align-items: center; justify-content: center; color: var(--text); }
:root[data-theme="dark"] .tl-row.move .bar .pt { border-color: var(--muted); }
.tl-row.move .bar .pt svg { width: 22px; height: 22px; }
.tl-row .body { padding: 14px 0 16px; min-width: 0; }
.tl-row .name { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-row .info { font-size: 14px; color: var(--muted); }
.tl-row .when { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-row .more { align-self: start; margin-top: 18px; width: 24px; height: 24px; color: var(--muted); border-radius: 50%; }
.tl-row .more:hover { background: var(--hover); }
.tl-empty { padding: 24px 16px; color: var(--muted); text-align: center; }

/* ---------- login ---------- */
.login { position: absolute; inset: 0; z-index: 20; background: var(--ground); display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; padding: 28px 24px 24px; display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login-logo { width: 56px; height: 56px; border-radius: 50%; background: var(--blue); color: #fff; display: flex; align-items: center; justify-content: center; margin: 0 auto 4px; }
.login-logo svg { width: 32px; height: 32px; }
.login-card h1 { margin: 0; font-size: 22px; font-weight: 500; }
.login-card p { margin: 0 0 8px; }
.login-card input { height: 44px; border: 1px solid var(--border); border-radius: 4px; padding: 0 12px; font-size: 15px; outline: 0; background: var(--field); }
.login-card input:focus { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.login-card .pill { justify-content: center; height: 40px; margin-top: 6px; }
.login-err { color: #d93025; font-size: 13px; }

/* ---------- navigation ---------- */
body.navigating .panel, body.navigating .topright, body.navigating .maplibregl-ctrl-top-right, body.navigating .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group { display: none; }
.nav { position: absolute; inset: 0; z-index: 8; pointer-events: none; }
.nav > * { pointer-events: auto; }
.nav-top { position: absolute; top: calc(8px + var(--sat)); left: 8px; right: 8px; background: #188038; color: #fff; border-radius: 12px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 14px; padding: 14px 16px; max-width: 520px; }
.nav-top.transit { background: var(--blue); }
.nav-icon { width: 56px; height: 56px; flex: none; display: flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 52px; height: 52px; fill: #fff; }
.nav-main { min-width: 0; }
.nav-dist { font-size: 30px; font-weight: 500; line-height: 1.1; }
.nav-text { font-size: 17px; opacity: .95; margin-top: 2px; }
.nav-then { position: absolute; top: calc(108px + var(--sat)); left: 8px; background: #0d652d; color: #fff; border-radius: 0 0 10px 10px; padding: 6px 14px; font-size: 14px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 6px; }
.nav-then svg { width: 18px; height: 18px; fill: #fff; }
.nav-recenter { position: absolute; bottom: calc(96px + var(--sab)); left: 50%; transform: translateX(-50%); background: var(--card); color: var(--blue); border-radius: 20px; height: 40px; padding: 0 16px 0 10px; box-shadow: var(--shadow); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.nav-recenter svg { width: 20px; height: 20px; }
.nav-bottom { position: absolute; left: 8px; right: 8px; bottom: calc(8px + var(--sab)); background: var(--card); border-radius: 12px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 4px; max-width: 520px; }
.nav-eta { flex: 1; text-align: center; }
.nav-eta-time { font-size: 20px; font-weight: 500; color: #188038; }
:root[data-theme="dark"] .nav-eta-time { color: #81c995; }
.nav-eta-sub { font-size: 13px; color: var(--muted); }
.nav-exit { background: #d93025; color: #fff; border-color: #d93025; }
#nav-mute.off { color: #bdc1c6; }
.marker-nav { width: 44px; height: 44px; }
.detail .summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.detail .summary .pill { height: 34px; }

/* ---------- misc ---------- */
.topright { position: absolute; top: calc(10px + var(--sat)); right: 10px; z-index: 5; }
.toast { position: absolute; bottom: calc(24px + var(--sab)); left: 50%; transform: translateX(-50%); background: #202124; color: #fff; padding: 10px 16px; border-radius: 4px; z-index: 9; font-size: 14px; box-shadow: var(--shadow); }
.maplibregl-ctrl-group { box-shadow: var(--shadow) !important; border-radius: 8px !important; }
.maplibregl-ctrl-bottom-right { bottom: var(--sab); }
.maplibregl-ctrl-attrib { font-size: 10px; }
.marker-pin { width: 26px; height: 36px; }
.marker-dot { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 2.5px solid #3c4043; }

@media (max-width: 600px) {
  :root { --panel-w: 100%; }
  .panel { left: 0; right: 0; top: 0; bottom: 0; width: auto; max-height: none; padding: calc(8px + var(--sat)) 8px 0; }
  /* Google mobile: search pill stays on top, everything else is a bottom sheet */
  .place, .dir, .tl { margin-top: auto; border-radius: 28px 28px 0 0; margin-left: -8px; margin-right: -8px; padding-bottom: var(--sab); max-height: 62vh; }
  .place::before, .dir::before, .tl::before { content: ""; display: block; width: 32px; height: 4px; border-radius: 2px; background: #c4c7c5; margin: 8px auto 4px; }
  .place { padding-top: 0; }
  .dir .modes, .tl-head { padding-top: 0; }
  .topright { display: none; }
  .search input { font-size: 16px; }
  .suggest { max-height: 40vh; }
  .results { max-height: 40vh; }
  .panel.dir-open .search { display: none; }
  .tl-list { max-height: 42vh; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group:has(.maplibregl-ctrl-zoom-in) { display: none; }
  .place { max-height: 50vh; }
}

:root[data-theme="dark"] .maplibregl-ctrl-group { background: var(--card); }
:root[data-theme="dark"] .maplibregl-ctrl-group button + button { border-top-color: var(--line); }
:root[data-theme="dark"] .maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1) hue-rotate(180deg); }
:root[data-theme="dark"] .maplibregl-ctrl-attrib { background: rgba(32,33,36,.8); color: var(--muted); }
:root[data-theme="dark"] .maplibregl-ctrl-attrib a { color: var(--muted); }
