
:root {
  color-scheme: light dark;
  --bg: #f3f5f7;
  --card: rgba(255,255,255,.92);
  --card-solid: #ffffff;
  --text: #111318;
  --muted: #707680;
  --border: rgba(20,25,35,.08);
  --shadow: 0 12px 36px rgba(25,30,40,.08);
  --accent: #1578ff;
  --green: #23a455;
  --green-bg: rgba(35,164,85,.12);
  --amber: #a96f00;
  --amber-bg: rgba(210,145,0,.14);
  --red: #c84444;
  --red-bg: rgba(200,68,68,.12);
  --chip: #edf0f4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f11;
    --card: rgba(26,29,32,.94);
    --card-solid: #191c1f;
    --text: #f5f7f9;
    --muted: #a5abb4;
    --border: rgba(255,255,255,.08);
    --shadow: 0 14px 40px rgba(0,0,0,.28);
    --green-bg: rgba(35,164,85,.18);
    --amber-bg: rgba(210,145,0,.18);
    --red-bg: rgba(200,68,68,.18);
    --chip: #24282d;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { cursor: pointer; }

.app-shell {
  max-width: 760px;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px calc(26px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 13px;
  background: linear-gradient(var(--bg) 72%, rgba(0,0,0,0));
}

.brand { display:flex; align-items:center; gap:10px; }
.brand-icon {
  width: 42px; height: 42px; border-radius: 13px;
  display:grid; place-items:center; font-size:23px;
  background: linear-gradient(145deg, rgba(21,120,255,.18), rgba(203,0,124,.15));
  border: 1px solid var(--border);
}
.brand-title { font-weight: 850; font-size: 18px; letter-spacing: -.015em; }
.brand-subtitle { margin-top:2px; color:var(--muted); font-size:11px; font-weight:650; }
.icon-btn, .close-btn {
  border: 1px solid var(--border); color: var(--text);
  background: var(--card); box-shadow: var(--shadow);
  width: 42px; height: 42px; border-radius: 14px;
  font-size: 23px; display:grid; place-items:center;
}

.card {
  border: 1px solid var(--border);
  background: var(--card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-radius: 24px;
}

.hero {
  padding: 20px;
  margin-bottom: 12px;
}
.hero-top {
  display:flex; justify-content:space-between; align-items:flex-start; gap:12px;
}
.eyebrow {
  font-size: 10px; font-weight: 850; color: var(--muted);
  letter-spacing: .095em; text-transform: uppercase;
}
.hero-title {
  margin: 7px 0 0;
  font-size: clamp(27px, 7.4vw, 38px);
  line-height: 1.04; letter-spacing: -.035em; font-weight: 900;
}
.hero-meta {
  margin-top: 10px; color: var(--muted); font-size: 15px; font-weight: 650;
}
.status-pill {
  flex: 0 0 auto;
  padding: 8px 11px; border-radius: 999px;
  font-size: 11px; font-weight: 850; white-space: nowrap;
}
.status-live { color: var(--green); background: var(--green-bg); }
.status-theoretical { color: var(--amber); background: var(--amber-bg); }
.status-offline { color: var(--muted); background: var(--chip); }

.routes { display:grid; gap:10px; }

.route-card {
  --line:#687078;
  position:relative; overflow:hidden;
  padding: 16px;
  border:1px solid var(--border);
  background:var(--card);
  box-shadow:var(--shadow);
  border-radius:22px;
}
.route-card::before {
  content:""; position:absolute; left:0; top:0; bottom:0; width:5px; background:var(--line);
}
.route-head { display:flex; align-items:center; gap:10px; margin-bottom:13px; }
.line-badge {
  min-width: 36px; height: 36px; padding:0 10px; border-radius:11px;
  display:grid; place-items:center; font-size:20px; font-weight:900;
}
.direction {
  min-width:0; font-size:18px; line-height:1.13; font-weight:850;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.direction .arrow { color:var(--muted); margin-right:6px; font-weight:500; }

.passages {
  display:grid; grid-template-columns:repeat(3, minmax(0, 1fr)); gap:7px;
}
.passage {
  min-width:0; min-height: 88px;
  border:1px solid var(--border); border-radius:15px;
  background:var(--card-solid); padding:9px;
}
.passage.target {
  border-color: color-mix(in srgb, var(--line) 65%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--line) 18%, transparent);
}
.passage.tight { opacity:.50; }
.micro {
  display:inline-block; margin-bottom:6px; border-radius:7px;
  padding:3px 6px; font-size:8px; font-weight:900;
  letter-spacing:.04em; text-transform:uppercase;
}
.micro.target-badge {
  color:var(--line); background:color-mix(in srgb, var(--line) 13%, transparent);
}
.micro.tight-badge { color:var(--muted); background:var(--chip); }
.relative { font-size:15px; line-height:1.1; font-weight:900; white-space:nowrap; }
.absolute { margin-top:5px; color:var(--muted); font-size:12px; font-weight:700; }
.delay {
  display:inline-block; margin-top:6px; border-radius:6px; padding:3px 5px;
  font-size:9px; font-weight:850;
}
.delay.late { color:var(--red); background:var(--red-bg); }
.delay.early { color:var(--green); background:var(--green-bg); }

.nearby-section { margin:14px 0 4px; }
.section-label {
  margin:0 4px 8px; color:var(--muted); font-size:10px; font-weight:850;
  letter-spacing:.085em; text-transform:uppercase;
}
.nearby-chips { display:flex; gap:7px; overflow-x:auto; padding:1px 1px 5px; }
.nearby-chip {
  flex:0 0 auto; border:1px solid var(--border); background:var(--card);
  color:var(--text); border-radius:14px; padding:9px 11px; box-shadow:var(--shadow);
  text-align:left;
}
.nearby-chip strong { display:block; font-size:12px; }
.nearby-chip small { display:block; margin-top:3px; color:var(--muted); font-size:10px; }

.footer { margin-top:12px; padding:15px; }
.source-line { display:flex; align-items:center; gap:8px; font-size:12px; font-weight:800; }
.status-dot { width:9px; height:9px; border-radius:50%; background:var(--muted); }
.source-line.live .status-dot { background:var(--green); box-shadow:0 0 0 5px var(--green-bg); }
.source-line.theoretical .status-dot { background:var(--amber); box-shadow:0 0 0 5px var(--amber-bg); }
.updated-line { margin-top:5px; color:var(--muted); font-size:10px; }
.footer-actions { display:grid; grid-template-columns:1fr 1fr; gap:8px; margin-top:12px; }
.btn {
  border:0; border-radius:14px; padding:12px 10px; font-size:13px; font-weight:850;
}
.btn.primary { color:#fff; background:var(--accent); }
.btn.secondary { color:var(--text); background:var(--chip); }
.warning {
  margin-top:10px; padding:9px 10px; border-radius:11px;
  background:var(--amber-bg); color:var(--amber); font-size:10px; font-weight:750;
}

.overlay {
  position:fixed; inset:0; z-index:100;
  display:none; align-items:flex-end;
  background:rgba(0,0,0,.48);
  backdrop-filter:blur(10px); -webkit-backdrop-filter:blur(10px);
}
.overlay.open { display:flex; }
.sheet {
  width:100%; max-height:90vh; overflow:hidden;
  background:var(--card-solid);
  border-radius:26px 26px 0 0;
  padding: 10px 14px calc(16px + env(safe-area-inset-bottom));
  box-shadow:0 -18px 60px rgba(0,0,0,.28);
}
.grabber {
  width:44px; height:5px; border-radius:99px;
  background:rgba(130,135,145,.35); margin:2px auto 12px;
}
.sheet-head { display:flex; justify-content:space-between; gap:12px; align-items:center; }
.sheet-title { font-size:21px; font-weight:900; }
.sheet-subtitle { margin-top:2px; color:var(--muted); font-size:11px; }
.close-btn { width:36px; height:36px; font-size:19px; box-shadow:none; }
.search-wrap { position:relative; margin-top:12px; }
.search-icon { position:absolute; left:12px; top:50%; transform:translateY(-50%); color:var(--muted); }
#stationSearch {
  width:100%; border:1px solid var(--border); background:var(--chip); color:var(--text);
  border-radius:13px; outline:none; padding:12px 12px 12px 35px; font-size:16px;
}
.quick-stations { display:flex; gap:7px; overflow-x:auto; padding:10px 0 4px; }
.quick-btn {
  flex:0 0 auto; border:1px solid var(--border); border-radius:999px;
  padding:8px 10px; background:var(--card); color:var(--text);
  font-size:11px; font-weight:800;
}
.station-list { overflow:auto; max-height:58vh; margin-top:5px; }
.station-row {
  width:100%; border:0; border-bottom:1px solid var(--border);
  background:transparent; color:var(--text);
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:13px 3px; text-align:left;
}
.station-row:last-child { border-bottom:0; }
.station-name { font-size:14px; font-weight:830; }
.station-lines { margin-top:3px; color:var(--muted); font-size:10px; }
.station-arrow { color:var(--muted); font-size:19px; }
.empty-search { color:var(--muted); text-align:center; padding:26px 8px; }

.toast {
  position:fixed; left:50%; bottom:calc(18px + env(safe-area-inset-bottom));
  transform:translate(-50%, 20px); z-index:150;
  background:rgba(20,22,25,.92); color:#fff;
  border-radius:999px; padding:10px 14px; font-size:11px; font-weight:750;
  opacity:0; pointer-events:none; transition:.22s ease;
}
.toast.show { opacity:1; transform:translate(-50%,0); }

.loading-card, .empty-card {
  padding:18px; border:1px solid var(--border); background:var(--card);
  border-radius:22px; box-shadow:var(--shadow);
}
.loading-title { font-size:16px; font-weight:850; }
.loading-sub { color:var(--muted); font-size:11px; margin-top:5px; }
.spinner {
  width:28px; height:28px; border-radius:50%;
  border:3px solid var(--chip); border-top-color:var(--accent);
  animation:spin .75s linear infinite; margin-bottom:10px;
}
@keyframes spin { to { transform:rotate(360deg); } }

.skeleton {
  border-radius:8px;
  background:linear-gradient(90deg,var(--chip),rgba(140,145,155,.12),var(--chip));
  background-size:200% 100%; animation:shimmer 1.25s infinite;
}
.skeleton-title { width:70%; height:32px; }
.skeleton-sub { width:42%; height:15px; margin-top:12px; }
@keyframes shimmer { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

.hidden { display:none !important; }

@media (max-width:390px) {
  .app-shell { padding-left:11px; padding-right:11px; }
  .hero { padding:17px; }
  .hero-title { font-size:26px; }
  .direction { font-size:16px; }
  .passage { padding:8px 6px; min-height:82px; }
  .relative { font-size:13px; }
  .absolute { font-size:11px; }
}
