:root {
  --bg: #0f1417;
  --surface: #171e22;
  --surface-high: #1f282d;
  --surface-top: #2a353b;
  --on: #e3e9ec;
  --muted: #9aa8b0;
  --primary: #8fcdff;
  --on-primary: #00344f;
  --at: #9fe0a7;
  --at-bg: #12301a;
  --between: #ffd28a;
  --between-bg: #33270f;
  --danger: #ffb4ab;
  --radius: 28px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--on);
  font: 16px/1.4 "Google Sans", Roboto, system-ui, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 6px;
}

.top h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  flex: 1;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-high);
  color: var(--primary);
  font-size: 13px;
  white-space: nowrap;
}

.chip.off { color: var(--between); }

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-high);
  color: var(--on);
  font-size: 22px;
}

main {
  display: grid;
  gap: 12px;
  padding: 8px 14px 24px;
  max-width: 640px;
  margin: 0 auto;
}

.hero {
  border-radius: var(--radius);
  padding: 22px 20px 20px;
  background: var(--surface-high);
  transition: background .3s;
}

.hero[data-state="at"] { background: var(--at-bg); }
.hero[data-state="between"] { background: var(--between-bg); }

.hero-label {
  font-size: 14px;
  letter-spacing: .4px;
  text-transform: uppercase;
  color: var(--muted);
}

.hero[data-state="at"] .hero-label { color: var(--at); }
.hero[data-state="between"] .hero-label { color: var(--between); }

.hero-name {
  margin: 6px 0 4px;
  font-size: clamp(30px, 9vw, 44px);
  font-weight: 700;
  line-height: 1.1;
  word-break: break-word;
}

.hero-meta {
  color: var(--muted);
  font-size: 17px;
  min-height: 1.4em;
}

.hero #gpsBtn { margin-top: 14px; }

.track {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
}

.track-end {
  display: grid;
  font-size: 14px;
  min-width: 0;
}

.track-end span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.track-end small { color: var(--muted); }
.track-end.right { text-align: right; }

.track-bar {
  position: relative;
  height: 8px;
  border-radius: 4px;
  background: var(--surface-top);
}

.track-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 4px;
  background: var(--primary);
  transition: width .6s;
}

.track-dot {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--bg);
  transform: translate(-50%, -50%);
  transition: left .6s;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat {
  display: grid;
  padding: 12px 14px;
  border-radius: 20px;
  background: var(--surface);
}

.stat small { color: var(--muted); font-size: 12px; }
.stat b { font-size: 18px; font-weight: 600; }

.card {
  border-radius: var(--radius);
  padding: 16px 8px 8px;
  background: var(--surface);
}

.card h2 {
  margin: 0 12px 8px;
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
}

.nearby {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nearby li {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 18px;
}

.nearby li.current { background: var(--at-bg); }

.nearby .arrow {
  display: inline-block;
  text-align: center;
  color: var(--primary);
  font-size: 18px;
  transition: transform .4s;
}

.nearby .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nearby .type {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-top);
  color: var(--muted);
}

.nearby .type.station { color: var(--primary); }
.nearby .dist { font-variant-numeric: tabular-nums; color: var(--muted); }

dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: 0;
  border-radius: var(--radius);
  padding: 22px;
  background: var(--surface-high);
  color: var(--on);
}

dialog::backdrop { background: #000a; }

dialog h2 { margin: 0 0 14px; font-size: 22px; font-weight: 600; }
dialog h3 { margin: 18px 0 10px; font-size: 15px; color: var(--muted); font-weight: 500; }

.field {
  display: grid;
  gap: 6px;
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--surface-top);
  border-radius: 14px;
  background: var(--surface);
  color: var(--on);
  font: inherit;
  font-size: 16px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.switch input { width: 20px; height: 20px; accent-color: var(--primary); }

.row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.row.end { justify-content: flex-end; margin-top: 14px; }
.row .btn { margin-bottom: 12px; }
.row.end .btn { margin-bottom: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 20px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

.btn:disabled { opacity: .5; }
.btn.filled { background: var(--primary); color: var(--on-primary); }
.btn.tonal { background: #24485f; color: #cbe6ff; }
.btn.outline { background: transparent; color: var(--primary); border: 1px solid var(--surface-top); }
.btn.text { background: transparent; color: var(--primary); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid #5c2b27; }

.hint { color: var(--muted); font-size: 14px; min-height: 1.4em; margin: 4px 0 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 140%);
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--surface-top);
  color: var(--on);
  font-size: 14px;
  opacity: 0;
  transition: transform .3s, opacity .3s;
  pointer-events: none;
}

.toast.show { transform: translate(-50%, 0); opacity: 1; }
