:root {
  --bg: #ffffff;
  --fg: #1f1f1f;
  --muted: #5f6368;
  --line: #e3e3e3;
  --accent: #1a73e8;
  --accent-fg: #ffffff;
  --ok: #188038;
  --bad: #d93025;
  --nav: #0b6b3a;
  --shadow: 0 2px 12px rgba(0, 0, 0, .18);
  --chip: #f1f3f4;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #202124; --fg: #e8eaed; --muted: #9aa0a6; --line: #3c4043;
    --chip: #303134; --accent: #8ab4f8; --accent-fg: #202124; --ok: #81c995; --bad: #f28b82;
    --shadow: 0 2px 12px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --bg: #202124; --fg: #e8eaed; --muted: #9aa0a6; --line: #3c4043;
  --chip: #303134; --accent: #8ab4f8; --accent-fg: #202124; --ok: #81c995; --bad: #f28b82;
  --shadow: 0 2px 12px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; cursor: pointer; }
#map { position: fixed; inset: 0; }

#topbar { position: fixed; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 5;
  max-width: 640px; margin: 0 auto; }
#ask { display: flex; gap: 6px; background: var(--bg); border-radius: 28px; box-shadow: var(--shadow); padding: 6px; }
#q { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--fg); font-size: 16px; padding: 8px 12px; }
#ask button { border: 0; border-radius: 50%; width: 42px; height: 42px; flex: none; background: var(--chip); color: var(--fg); font-size: 18px; }
#ask #go { background: var(--accent); color: var(--accent-fg); }
#mic.listening { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
#ask.busy #go { animation: pulse .8s infinite; }

#chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 2px; scrollbar-width: none; }
#chips::-webkit-scrollbar { display: none; }
#chips button { flex: none; border: 0; border-radius: 18px; padding: 6px 12px; background: var(--bg); color: var(--fg); box-shadow: var(--shadow); white-space: nowrap; }

#routebadge { display: inline-flex; align-items: center; gap: 8px; background: var(--accent); color: var(--accent-fg);
  border-radius: 16px; padding: 4px 6px 4px 12px; font-size: 13px; box-shadow: var(--shadow); max-width: 100%; }
#routebadge span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#routebadge button { border: 0; background: rgba(255,255,255,.25); color: inherit; border-radius: 50%; width: 22px; height: 22px; padding: 0; }

#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; max-height: 55vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0; box-shadow: var(--shadow); max-width: 680px; margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom); }
.grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 8px auto 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 8px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
#closeSheet { border: 0; background: var(--chip); color: var(--fg); border-radius: 50%; width: 32px; height: 32px; flex: none; }
#results { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#results li { padding: 12px 16px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
#results li.active { background: var(--chip); }
.r-name { font-weight: 600; }
.r-num { display: inline-block; min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent); color: var(--accent-fg);
  font-size: 12px; text-align: center; line-height: 20px; margin-right: 6px; }
.r-meta { color: var(--muted); font-size: 13px; grid-column: 1; }
.r-time { text-align: right; font-weight: 600; white-space: nowrap; }
.r-time small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.open { color: var(--ok); } .closed { color: var(--bad); }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 8px; background: var(--chip); margin-right: 4px; }
.tag.hw { background: #1967d2; color: #fff; }
.r-actions { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.r-actions button, .r-actions a { border: 1px solid var(--line); background: var(--bg); color: var(--accent); border-radius: 18px;
  padding: 6px 14px; font-size: 14px; text-decoration: none; }
.r-actions .primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

#nav { position: fixed; left: 12px; right: 12px; top: max(12px, env(safe-area-inset-top)); z-index: 7; max-width: 640px; margin: 0 auto; }
#navNext { display: flex; gap: 14px; align-items: center; background: var(--nav); color: #fff; border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
#navIcon { font-size: 34px; width: 44px; text-align: center; flex: none; }
#navDist { font-size: 26px; font-weight: 700; }
#navText { font-size: 16px; }
#navFoot { position: fixed; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: 14px; box-shadow: var(--shadow); padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
#navEta { font-weight: 600; }
.navBtns { display: flex; gap: 6px; }
.navBtns button, .navBtns a { border: 1px solid var(--line); background: var(--bg); color: var(--fg); border-radius: 18px; padding: 6px 12px; text-decoration: none; font-size: 14px; }
#navStop { background: var(--bad); color: #fff; border-color: var(--bad); }

#recenter { position: fixed; right: 12px; bottom: calc(55vh + 12px); z-index: 4; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--bg); color: var(--accent); box-shadow: var(--shadow); font-size: 22px; }
body:not(.sheet-open) #recenter { bottom: 24px; }
body.navigating #recenter { bottom: 90px; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 30px; z-index: 9; background: #323232; color: #fff;
  padding: 10px 16px; border-radius: 8px; max-width: calc(100% - 32px); box-shadow: var(--shadow); }

#setup { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.setup-card { max-width: 520px; }
.setup-card pre { background: var(--chip); padding: 10px; border-radius: 8px; overflow-x: auto; }

.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }
.pin { min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px; background: #ea4335; color: #fff; font: 600 13px/26px system-ui, sans-serif;
  text-align: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.pin.best { background: #188038; }
.pin.sel { transform: scale(1.3); }
