:root {
    --bg-top: #0a1118;
    --bg-bottom: #0f1923;
    --surface: #1e2d3d;
    --surface-hover: #283a4d;
    --text: #e8edf2;
    --text-dim: #a0b3c6;
    --text-muted: #6b8099;
    --dry: #2dd4a8;
    --drizzle: #f5c542;
    --wet: #ff6b6b;
    --accent: #3b82f6;
    --dest: #a78bfa;
    --radius: 12px;
    --radius-sm: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
    background-attachment: fixed;
    color: var(--text);
    font-size: 16px;
    line-height: 1.4;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
.header {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-top);
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.header h1 { font-size: 16px; font-weight: 600; color: var(--text-dim); }
.header-right { display: flex; align-items: center; gap: 8px; }
.staleness { font-size: 11px; color: var(--text-muted); }
.staleness.stale { color: var(--drizzle); }
.gear-btn {
    background: none; border: none; color: var(--text-muted);
    font-size: 18px; cursor: pointer; padding: 4px;
    transition: color 0.2s;
}
.gear-btn:hover { color: var(--text); }

/* ===== CONTAINER ===== */
.container { max-width: 480px; margin: 0 auto; padding: 0 12px 80px; }

/* ===== ROUTE PILL ===== */
.route-pill {
    display: none; align-items: center; justify-content: space-between;
    padding: 8px 14px; margin-bottom: 8px;
    background: var(--surface); border-radius: var(--radius);
    font-size: 13px; color: var(--text-dim);
}
.route-pill.visible { display: flex; }
.pill-label { flex: 1; cursor: pointer; }
.pill-label:hover { color: var(--text); }
.pill-actions { display: flex; gap: 4px; }
.pill-btn {
    background: none; border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-muted); width: 30px; height: 30px;
    border-radius: 6px; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.pill-btn:hover { color: var(--text); border-color: var(--accent); }

/* ===== ROUTE FORM ===== */
.route-form { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }
.route-form.collapsed { display: none; }

.input-group { position: relative; }
.input-group input {
    width: 100%; padding: 12px 44px 12px 14px;
    background: var(--surface); border: 1px solid rgba(255,255,255,0.06);
    border-radius: var(--radius); color: var(--text); font-size: 16px;
    outline: none; transition: border-color 0.2s;
}
.input-group input:focus { border-color: var(--accent); }
.input-group input::placeholder { color: var(--text-muted); }
.gps-btn {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-muted);
    width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
    font-size: 18px; display: flex; align-items: center; justify-content: center;
    transition: color 0.2s; z-index: 1;
}
.gps-btn:hover { color: var(--accent); }
.gps-btn.locating { color: var(--drizzle); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:0.4 } }

.autocomplete-dropdown {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    background: var(--surface); border: 1px solid rgba(255,255,255,0.08);
    border-radius: 0 0 var(--radius) var(--radius); z-index: 50;
    max-height: 200px; overflow-y: auto;
}
.autocomplete-dropdown.open { display: block; }
.autocomplete-item {
    padding: 10px 14px; cursor: pointer; font-size: 14px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.autocomplete-item:hover, .autocomplete-item.active { background: var(--surface-hover); }

.swap-row { display: flex; justify-content: center; }
.swap-btn {
    background: none; border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-muted); width: 32px; height: 32px;
    border-radius: 50%; cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.swap-btn:hover { color: var(--text); border-color: var(--accent); }

.time-picker-row {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; background: var(--surface); border-radius: var(--radius);
}
.time-picker-label { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.datetime-input {
    flex: 1; background: transparent; border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px; color: var(--text); padding: 6px 8px;
    font-size: 14px; font-family: inherit; outline: none; color-scheme: dark;
}
.time-clear-btn {
    background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-muted); padding: 6px 10px; border-radius: 6px;
    cursor: pointer; font-size: 13px; font-family: inherit;
}
.time-clear-btn:hover { color: var(--text); }

.search-btn {
    width: 100%; padding: 14px; background: var(--accent); color: white;
    border: none; border-radius: var(--radius); font-size: 16px;
    font-weight: 600; cursor: pointer; transition: opacity 0.2s;
}
.search-btn:hover { opacity: 0.9; }
.search-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== WEATHER STRIP ===== */
.weather-strip {
    display: none; padding: 6px 0 2px; margin-bottom: 4px;
}
.weather-strip.visible { display: block; }
.strip-wrap {
    position: relative; height: 48px;
    background: var(--surface); border-radius: var(--radius-sm);
    overflow: hidden; padding: 0 2px;
}
.strip-svg { width: 100%; height: 36px; display: block; }
.strip-labels {
    display: flex; justify-content: space-between;
    padding: 0 8px; font-size: 10px; color: var(--text-muted);
}
.strip-legend {
    display: flex; gap: 12px; padding: 2px 8px 0; font-size: 10px; color: var(--text-muted);
}
.strip-legend-dot {
    display: inline-block; width: 6px; height: 6px; border-radius: 50%;
    margin-right: 3px; vertical-align: middle;
}
.strip-now {
    position: absolute; left: 0; top: 4px;
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--accent);
    animation: breathe 2s ease-in-out infinite;
}
@keyframes breathe { 0%,100% { opacity:1;transform:scale(1) } 50% { opacity:0.5;transform:scale(0.7) } }
.strip-dep-marker {
    position: absolute; bottom: 12px;
    width: 0; height: 0;
    border-left: 3px solid transparent; border-right: 3px solid transparent;
    border-bottom: 5px solid var(--text-muted);
}

/* ===== UMBRELLA NARRATIVE ===== */
.umbrella-narrative {
    display: none; padding: 10px 14px; margin-bottom: 8px;
    font-size: 14px; line-height: 1.5; border-radius: var(--radius);
}
.umbrella-narrative.visible { display: block; }
.umbrella-narrative.n-dry { color: var(--dry); background: rgba(45,212,168,0.06); }
.umbrella-narrative.n-drizzle { color: var(--drizzle); background: rgba(245,197,66,0.06); }
.umbrella-narrative.n-wet { color: var(--wet); background: rgba(255,107,107,0.06); }

@keyframes urgentPulse { 0%,100% { opacity:1 } 50% { opacity:0.7 } }

/* ===== CONNECTION CARDS ===== */
.compact-card {
    background: var(--surface); border-radius: var(--radius-sm);
    padding: 10px 12px; margin-bottom: 4px;
    cursor: pointer; transition: background 0.2s, border-color 0.2s;
    animation: fadeIn 0.3s ease-out;
    border-left: 3px solid transparent;
}
.compact-card:hover { background: var(--surface-hover); }
.compact-card.departed { opacity: 0.35; }
.compact-card.best { border-left-color: var(--dry); }

.compact-header {
    display: flex; align-items: center; gap: 10px;
}

.compact-left { min-width: 100px; }
.compact-times { font-size: 14px; font-weight: 600; white-space: nowrap; }
.compact-times .arrow { color: var(--text-muted); font-size: 12px; margin: 0 2px; }
.compact-leave { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.compact-ribbon { flex: 1; height: 24px; min-width: 60px; overflow: hidden; transition: height 0.25s ease; }

.compact-right { text-align: right; min-width: 60px; }
.compact-status { font-size: 13px; font-weight: 500; }
.compact-meta { font-size: 11px; color: var(--text); }

.compact-details {
    max-height: 0; overflow: hidden; opacity: 0;
    transition: max-height 0.25s ease, opacity 0.2s ease, margin 0.25s ease;
}
.compact-card.expanded {
    background: var(--surface-hover);
}
.compact-card.expanded .compact-ribbon { height: 40px; }
.compact-card.expanded .compact-details {
    max-height: 120px; opacity: 1; margin-top: 10px;
    padding-top: 8px; border-top: 1px solid rgba(255,255,255,0.08);
}
.compact-expand-leave {
    font-size: 22px; font-weight: 700; letter-spacing: -0.5px;
    color: var(--accent); margin-bottom: 6px;
}
.compact-expand-leave.urgent { color: var(--drizzle); animation: urgentPulse 2s ease-in-out infinite; }
.compact-expand-leave.now { color: var(--wet); animation: urgentPulse 1.5s ease-in-out infinite; }
.compact-expand-leave.passed { color: var(--text-muted); font-size: 16px; font-weight: 400; animation: none; }
.compact-summary { font-size: 13px; color: var(--text-dim); }
.compact-delay { font-size: 12px; color: var(--drizzle); margin-top: 2px; }

.status-dry { color: var(--dry); }
.status-drizzle { color: var(--drizzle); }
.status-wet { color: var(--wet); }
.status-unknown { color: var(--text-muted); }

/* ===== RIBBON SVG ===== */
.ribbon-svg { width: 100%; display: block; }
.ribbon-zone-walk { opacity: 1; }
.ribbon-zone-train { opacity: 0.2; }
.ribbon-divider { stroke: rgba(255,255,255,0.1); stroke-width: 1; stroke-dasharray: 2,2; }

@keyframes fadeIn { from { opacity:0; transform:translateY(4px) } to { opacity:1; transform:translateY(0) } }

/* ===== TRAIN LIST ===== */
#compactSection {
    max-height: 370px;
    overflow-y: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}
#compactSection::-webkit-scrollbar { width: 4px; }
#compactSection::-webkit-scrollbar-track { background: transparent; }
#compactSection::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

/* ===== TRAIN NAV ===== */
.train-nav-top, .train-nav-bottom { display: none; padding: 4px 0; }
.train-nav-top.visible, .train-nav-bottom.visible { display: block; }
.nav-btn {
    width: 100%; padding: 8px; background: transparent;
    border: 1px dashed rgba(255,255,255,0.1); border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 13px; cursor: pointer; font-family: inherit;
    transition: all 0.2s;
}
.nav-btn:hover { border-color: var(--accent); color: var(--accent); }
.nav-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.nav-btn.loading { color: var(--drizzle); border-color: var(--drizzle); }

/* ===== RETURN TRIP ===== */
.return-section { padding: 8px 0; }
.return-header { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.return-card {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface); border-radius: var(--radius-sm);
    padding: 10px 12px; border-left: 3px solid rgba(59,130,246,0.3);
}
.return-info { font-size: 13px; }
.return-times { font-weight: 500; }
.return-status { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.return-switch {
    font-size: 12px; color: var(--accent); background: none;
    border: 1px solid rgba(59,130,246,0.3); border-radius: 6px;
    padding: 4px 10px; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.return-switch:hover { background: rgba(59,130,246,0.1); }

/* ===== SAVED ROUTES ===== */
.saved-routes { padding: 12px 0; }
.saved-routes-label { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.saved-chips { display: flex; flex-direction: column; gap: 4px; }
.saved-chip {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; background: var(--surface); border-radius: var(--radius-sm);
    cursor: pointer; font-size: 14px; transition: background 0.2s;
}
.saved-chip:hover { background: var(--surface-hover); }
.chip-delete {
    color: var(--text-muted); background: none; border: none;
    cursor: pointer; font-size: 16px; padding: 0 0 0 8px;
}

/* ===== SETTINGS DRAWER ===== */
.drawer-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 200;
}
.drawer-overlay.open { display: block; }
.settings-drawer {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface); border-radius: 16px 16px 0 0;
    max-height: 70vh; overflow-y: auto; z-index: 201;
    transform: translateY(100%); transition: transform 0.25s ease-out;
}
.settings-drawer.open { transform: translateY(0); }
.drawer-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 20px; border-bottom: 1px solid rgba(255,255,255,0.06);
    font-size: 16px; font-weight: 600;
}
.drawer-done {
    background: none; border: none; color: var(--accent);
    font-size: 15px; font-weight: 500; cursor: pointer; font-family: inherit;
}
.drawer-body { padding: 12px 20px 32px; }
.setting-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.setting-row label { font-size: 14px; color: var(--text-dim); }
.setting-select {
    background: var(--bg-bottom); border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px; color: var(--text); padding: 6px 8px;
    font-size: 13px; font-family: inherit; outline: none; color-scheme: dark;
}
.setting-section { padding-top: 12px; }
.setting-section-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.walk-time-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 0; font-size: 13px; color: var(--text-dim);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.walk-time-item .wt-station { flex: 1; }
.walk-time-item .wt-value { color: var(--text); font-weight: 500; }

/* ===== LOADING / ERROR ===== */
.results-loading { text-align: center; padding: 40px 0; color: var(--text-muted); }
.error-msg {
    text-align: center; padding: 16px; color: var(--wet);
    font-size: 14px; background: rgba(255,107,107,0.08); border-radius: var(--radius);
}
