:root {
    --bg: #f1f2f6;
    --panel: #ffffff;
    --panel2: #eef0f6;
    --line: #dde1ea;
    --navy: #2d2b70;
    --orange: #f26924;
    --orange-dim: #f7b78e;
    --red: #ff2800;
    --text: #22233d;
    --muted: #666a85;
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Poppins', system-ui, sans-serif;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    min-height: 100%;
}

.wrap {
    max-width: 760px;
    margin: 0 auto;
    padding: 20px 16px 48px;
}

header {
    margin-bottom: 18px;
}

h1 {
    font-size: 1.5rem;
    margin: 0 0 4px;
    letter-spacing: .2px;
    color: var(--navy);
    font-weight: 700;
}

.sub {
    color: var(--muted);
    font-size: .9rem;
    margin: 0;
}

.tabs {
    display: flex;
    gap: 8px;
    margin: 18px 0 14px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px;
}

.tab {
    flex: 1;
    text-align: center;
    padding: 10px 6px;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 600;
    font-size: .92rem;
    color: var(--muted);
    user-select: none;
    transition: background .15s, color .15s;
}

.tab.active {
    background: var(--navy);
    color: #ffffff;
}

.controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: end;
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: .75rem;
    color: var(--muted);
    margin-bottom: 6px;
}

select {
    width: 100%;
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 11px 10px;
    font-family: inherit;
    font-size: .95rem;
    font-weight: 600;
}

.swap {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--orange);
    align-self: end;
    margin-bottom: 1px;
}

.swap:active {
    transform: scale(.94);
}

.clock-note {
    font-size: .78rem;
    color: var(--muted);
    margin: -6px 0 16px;
}

#next-card {
    background: linear-gradient(135deg, var(--navy), #3d3a8f);
    border: 1px solid var(--navy);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 18px;
    position: relative;
    overflow: hidden;
}

#next-card .eyebrow {
    font-size: .72rem;
    color: var(--orange-dim);
    font-weight: 700;
    margin-bottom: 6px;
}

#next-card .row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 14px;
}

#next-card .dep-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2.2rem;
    font-weight: 700;
    color: #ffffff;
    line-height: 1;
}

#next-card .meta {
    color: #c7c9ea;
    font-size: .85rem;
}

#next-card .arr {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    color: #ffffff;
}

#next-card .empty {
    color: #c7c9ea;
}

#next-card .badge {
    display: inline-block;
    background: var(--orange);
    color: #2a1400;
    font-size: .7rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 20px;
    margin-top: 8px;
}

#next-card .badge.urgent {
    background: var(--red);
    color: #ffffff;
}

.list-title {
    font-size: .8rem;
    color: var(--muted);
    margin: 0 0 8px;
    font-weight: 600;
}

.trains {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.train-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.train-row:last-child {
    border-bottom: none;
}

.train-row.past {
    opacity: .4;
}

.train-row.next {
    background: var(--panel2);
    box-shadow: inset 3px 0 0 var(--orange);
}

.t-dep,
.t-arr {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--navy);
}

.t-arr {
    color: var(--muted);
    font-weight: 600;
}

.arrow {
    color: var(--muted);
    font-size: .85rem;
}

.dur {
    font-size: .72rem;
    color: var(--muted);
    text-align: right;
    white-space: nowrap;
}

.dur strong {
    display: block;
    color: var(--text);
    font-size: .85rem;
    font-family: 'JetBrains Mono', monospace;
}

.empty {
    padding: 22px 14px;
    text-align: center;
    color: var(--muted);
    font-size: .9rem;
}

footer {
    margin-top: 26px;
    color: var(--muted);
    font-size: .76rem;
    text-align: center;
}

@media (max-width:420px) {
    .controls {
        grid-template-columns: 1fr auto 1fr;
    }

    #next-card .dep-time {
        font-size: 1.8rem;
    }

    .train-row {
        grid-template-columns: 1fr auto 1fr auto;
        padding: 11px 10px;
        gap: 6px;
    }

    .t-dep,
    .t-arr {
        font-size: .92rem;
    }
}