:root {
    --bg: #0a1826;
    --surface: #12283f;
    --surface-raised: #1a3550;
    --border: #274963;
    --text: #edf2f6;
    --text-muted: #8fa6bd;
    --accent: #3f9d70;
    --accent-strong: #57b986;
    --good: #4ade80;
    --bad: #f87171;
    --favorite: #f5b942;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

header {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}

.search-bar {
    position: relative;
}

#search-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
}

#search-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
}

a:focus-visible,
button:focus-visible,
.search-result:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 60vh;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.search-result {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    touch-action: manipulation;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result:hover,
.search-result:focus {
    background: var(--surface-raised);
}

.search-result .name {
    font-weight: 600;
}

.search-result .code {
    color: var(--text-muted);
    font-size: 0.85rem;
}

main {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

h2 {
    font-size: 1.15rem;
    margin: 8px 0 12px;
}

h3 {
    font-size: 0.95rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 24px 0 8px;
}

.hidden {
    display: none !important;
}

.empty-state {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.back-button {
    background: none;
    border: none;
    color: var(--accent-strong);
    font-size: 0.95rem;
    padding: 10px 4px;
    margin: -10px 0 0 -4px;
    cursor: pointer;
    touch-action: manipulation;
}

.stop-code {
    color: var(--text-muted);
    margin-top: -8px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.route-badge {
    flex-shrink: 0;
    min-width: 40px;
    height: 28px;
    padding: 0 8px;
    border-radius: 6px;
    background: var(--surface-raised);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
}

.route-info {
    flex: 1;
    min-width: 0;
}

.route-headsign {
    font-size: 0.9rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.departure-time {
    text-align: right;
    font-size: 0.9rem;
    white-space: nowrap;
}

.departure-time .clock {
    font-weight: 600;
}

.delay-on-time {
    color: var(--good);
}

.delay-late {
    color: var(--bad);
}

.delay-scheduled {
    color: var(--text-muted);
}

.star-button {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    touch-action: manipulation;
}

.star-button.favorited {
    color: var(--favorite);
}

.favorite-card {
    cursor: pointer;
    touch-action: manipulation;
}

.stale-banner {
    font-size: 0.8rem;
    color: var(--bad);
    margin: 4px 0 12px;
}
