:root {
    --primary-1: #310086;
    --primary-2: #f2a400;
    --secondary-1: #2489c8;
    --secondary-2: #456fbb;
    --secondary-3: #f4ae26;
    --secondary-4: #f5bc5b;
    --ink: #0f1021;
    --heading: #1f2d4f;
    --paper: #f8f9ff;
    --panel: rgba(255, 255, 255, 0.86);
    --card: #ffffff;
    --ink-soft: #3f4b64;
    --surface-border: rgba(38, 52, 77, 0.08);
    --white: #ffffff;
    --success: #087f5b;
    --danger: #b42318;
}

html[data-theme='dark'] {
    --ink: #e8edff;
    --heading: #dce7ff;
    --paper: #0d1324;
    --panel: rgba(20, 29, 52, 0.88);
    --card: #1a2542;
    --ink-soft: #b8c6e8;
    --surface-border: rgba(162, 182, 228, 0.2);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) {
        --ink: #e8edff;
        --heading: #dce7ff;
        --paper: #0d1324;
        --panel: rgba(20, 29, 52, 0.88);
        --card: #1a2542;
        --ink-soft: #b8c6e8;
        --surface-border: rgba(162, 182, 228, 0.2);
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    font-family: 'Montserrat', sans-serif;
    background: linear-gradient(165deg, #f5f8ff 0%, #eef4ff 54%, #e8f1ff 100%);
    color: var(--ink);
    min-height: 100vh;
}

html[data-theme='dark'] body {
    background: linear-gradient(164deg, #0c1327 0%, #121a31 52%, #182342 100%);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) body {
        background: linear-gradient(164deg, #0c1327 0%, #121a31 52%, #182342 100%);
    }
}

h1,
h2,
h3,
h4,
label,
button,
select {
    font-family: 'Montserrat', sans-serif;
}

.loader-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #1f004f, #310086);
    z-index: 1000;
    transition: opacity 0.4s ease;
}

.loader-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-card {
    width: min(360px, 92vw);
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    padding: 1.5rem;
    color: #fff;
    text-align: center;
    backdrop-filter: blur(6px);
}

.loader-bus {
    width: 84px;
    height: 38px;
    margin: 0 auto 0.9rem;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--primary-2), var(--secondary-3));
    position: relative;
    animation: drive 1s ease-in-out infinite alternate;
}

.loader-bus::before,
.loader-bus::after {
    content: '';
    position: absolute;
    bottom: -8px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #1c1c1c;
}

.loader-bus::before {
    left: 10px;
}

.loader-bus::after {
    right: 10px;
}

@keyframes drive {
    from { transform: translateX(-8px); }
    to { transform: translateX(8px); }
}

.topbar {
    width: min(1240px, 94vw);
    margin: 1rem auto;
    border-radius: 22px;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--surface-border);
    padding: 1rem 1.2rem;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    box-shadow: 0 10px 26px rgba(42, 55, 90, 0.12);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.brand-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--primary-2);
    box-shadow: 0 0 0 8px rgba(242, 164, 0, 0.2);
}

.brand-wrap h1 {
    margin: 0;
    font-size: clamp(1.1rem, 2vw, 1.8rem);
    line-height: 1;
}

.brand-wrap p {
    margin: 0.2rem 0 0;
    font-size: 0.84rem;
    color: var(--ink-soft);
}

.actions {
    display: flex;
    gap: 0.7rem;
}

.btn {
    border: 0;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.95rem;
    padding: 0.62rem 1rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
    transform: translateY(-2px);
}

.btn-primary {
    background: linear-gradient(120deg, var(--primary-2), var(--secondary-3));
    color: #1f1f1f;
}

.btn-secondary {
    background: rgba(36, 137, 200, 0.12);
    color: var(--ink);
    border: 1px solid rgba(36, 137, 200, 0.35);
}

.theme-toggle {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid rgba(36, 137, 200, 0.35);
    background: rgba(36, 137, 200, 0.12);
    color: var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.theme-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 18px rgba(33, 67, 116, 0.22);
}

.theme-icon {
    display: none;
    line-height: 0;
}

.theme-toggle .moon {
    display: inline-flex;
}

.theme-toggle.is-dark .moon {
    display: none;
}

.theme-toggle.is-dark .sun {
    display: inline-flex;
}

.layout {
    width: min(1240px, 94vw);
    margin: 1.2rem auto 2rem;
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(12, 1fr);
}

.panel {
    grid-column: span 12;
    background: var(--panel);
    border: 1px solid var(--surface-border);
    border-radius: 22px;
    padding: 1rem;
    backdrop-filter: blur(5px);
    box-shadow: 0 14px 40px rgba(45, 58, 92, 0.08);
}

.hero {
    grid-column: span 12;
}

.hero h2 {
    margin-top: 0;
    margin-bottom: 0.2rem;
    font-size: clamp(1.35rem, 3vw, 2rem);
    color: var(--heading);
}

.hero p {
    margin-top: 0;
    color: var(--ink-soft);
}

.control-row {
    display: flex;
    gap: 1rem;
    align-items: end;
    justify-content: space-between;
    flex-wrap: wrap;
}

.field-group {
    min-width: 270px;
    flex: 1;
}

.field-group label {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--heading);
    font-weight: 600;
}

select {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(69, 111, 187, 0.35);
    padding: 0.72rem 0.8rem;
    font-size: 0.98rem;
    background: var(--card);
    color: var(--ink);
}

.status-stack {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    font-size: 0.82rem;
    padding: 0.3rem 0.7rem;
    background: #edf2ff;
    color: #21385f;
}

.badge-online {
    background: #dbf6ec;
    color: var(--success);
}

.badge-offline {
    background: #fde9e9;
    color: var(--danger);
}

.sync-hint {
    margin-top: 0.8rem;
    border-radius: 12px;
    padding: 0.6rem 0.8rem;
    border: 1px solid rgba(36, 137, 200, 0.28);
    background: rgba(36, 137, 200, 0.14);
    color: var(--ink);
    line-height: 1.4;
}

.sync-hint a {
    color: var(--heading);
    font-weight: 700;
}

.proximity-hint {
    margin-top: 0.5rem;
    border-radius: 12px;
    padding: 0.6rem 0.8rem;
    background: rgba(242, 164, 0, 0.18);
    color: #5e3e00;
    font-weight: 600;
}

html[data-theme='dark'] .proximity-hint {
    background: rgba(64, 222, 255, 0.2);
    border: 1px solid rgba(64, 222, 255, 0.42);
    color: #e3fbff;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) .proximity-hint {
        background: rgba(64, 222, 255, 0.2);
        border: 1px solid rgba(64, 222, 255, 0.42);
        color: #e3fbff;
    }
}

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 0.8rem;
}

.section-head h3 {
    margin: 0;
    color: var(--heading);
}

.departures-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(300px, 1fr));
    gap: 1rem;
}

.departure-card {
    border-radius: 16px;
    padding: 1.1rem;
    border: 1px solid rgba(69, 111, 187, 0.22);
    background: linear-gradient(180deg, var(--card), rgba(220, 236, 255, 0.75));
    box-shadow: 0 8px 24px rgba(35, 65, 120, 0.08);
}

.departure-header {
    display: flex;
    justify-content: flex-start;
    gap: 0.5rem;
}

.departure-header h4 {
    margin: 0;
    font-size: 1.08rem;
    line-height: 1.25;
}

.direction-card .departure-header h4 {
    color: var(--heading);
}

.departure-pairs {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.75rem;
}

.departure-pair-row {
    display: grid;
    grid-template-columns: 56px 1fr auto;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid rgba(69, 111, 187, 0.22);
    border-radius: 12px;
    padding: 0.55rem 0.65rem;
    background: rgba(255, 255, 255, 0.58);
}

.pair-label {
    font-weight: 700;
    color: var(--heading);
    font-size: 0.84rem;
}

.pair-time {
    font-size: clamp(1.15rem, 2.3vw, 1.45rem);
    font-weight: 700;
    color: var(--heading);
}

html[data-theme='dark'] .pair-time {
    color: #64d5ff;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) .pair-time {
        color: #64d5ff;
    }
}

.wait-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.24rem 0.55rem;
    font-size: 0.8rem;
    background: rgba(36, 137, 200, 0.15);
    color: #0d4b70;
    font-weight: 600;
    white-space: nowrap;
}

html[data-theme='dark'] .wait-chip {
    background: rgba(100, 150, 220, 0.25);
    color: #90d5ff;
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) .wait-chip {
        background: rgba(100, 150, 220, 0.25);
        color: #90d5ff;
    }
}

html[data-theme='dark'] .departure-card {
    background: linear-gradient(180deg, rgba(31, 45, 78, 0.9), rgba(24, 36, 63, 0.95));
    border-color: rgba(137, 165, 229, 0.26);
}

html[data-theme='dark'] .departure-pair-row {
    background: rgba(17, 27, 49, 0.85);
    border-color: rgba(137, 165, 229, 0.26);
}

html[data-theme='dark'] .topbar {
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--surface-border);
}

html[data-theme='dark'] .site-footer {
    color: var(--ink-soft);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) .topbar {
        background: var(--panel);
        color: var(--ink);
        border: 1px solid var(--surface-border);
    }

    html:not([data-theme='light']) .site-footer {
        color: var(--ink-soft);
    }
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) .departure-card {
        background: linear-gradient(180deg, rgba(31, 45, 78, 0.9), rgba(24, 36, 63, 0.95));
        border-color: rgba(137, 165, 229, 0.26);
    }

    html:not([data-theme='light']) .departure-pair-row {
        background: rgba(17, 27, 49, 0.85);
        border-color: rgba(137, 165, 229, 0.26);
    }
}

.departure-time {
    margin: 0.7rem 0 0.2rem;
    font-size: clamp(1.8rem, 2.8vw, 2.25rem);
    color: var(--heading);
    font-weight: 700;
}

.departure-detail {
    margin: 0;
    color: var(--ink-soft);
    font-size: 0.9rem;
}

.map-panel {
    grid-column: span 12;
}

.map-canvas {
    width: 100%;
    height: 420px;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(75, 98, 145, 0.25);
}

.route-legend {
    margin-top: 0.7rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.legend-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    padding: 0.35rem 0.65rem;
    background: rgba(215, 228, 255, 0.55);
    border: 1px solid rgba(69, 111, 187, 0.36);
    font-size: 0.8rem;
}

html[data-theme='dark'] .legend-chip {
    background: rgba(50, 80, 140, 0.5);
    border-color: rgba(100, 150, 220, 0.4);
}

@media (prefers-color-scheme: dark) {
    html:not([data-theme='light']) .legend-chip {
        background: rgba(50, 80, 140, 0.5);
        border-color: rgba(100, 150, 220, 0.4);
    }
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.feature-list {
    margin: 0;
    padding-left: 1rem;
    color: var(--ink-soft);
    line-height: 1.65;
}

.toast {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(27, 34, 57, 0.95);
    color: #fff;
    padding: 0.6rem 0.85rem;
    border-radius: 999px;
    font-size: 0.85rem;
    z-index: 999;
}

.site-footer {
    width: min(1240px, 94vw);
    margin: 0 auto 1.5rem;
    text-align: center;
    color: var(--ink-soft);
    font-size: 0.95rem;
}

.site-footer a {
    color: var(--heading);
    font-weight: 700;
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

.noscript {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #2b1f4e;
    color: #fff;
    text-align: center;
    padding: 0.7rem;
}

.reveal {
    opacity: 0;
    transform: translateY(12px);
    animation: revealUp 0.6s ease forwards;
}

.reveal:nth-child(2) { animation-delay: 0.08s; }
.reveal:nth-child(3) { animation-delay: 0.16s; }
.reveal:nth-child(4) { animation-delay: 0.24s; }

@keyframes revealUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hidden {
    display: none !important;
}

@media (max-width: 860px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .actions {
        justify-content: space-between;
        align-items: center;
    }

    .departures-grid {
        grid-template-columns: 1fr;
    }

    .map-canvas {
        height: 360px;
    }
}

@media (max-width: 620px) {
    .layout,
    .topbar {
        width: 95vw;
    }

    .panel {
        padding: 0.86rem;
    }

    .actions {
        flex-wrap: wrap;
    }

    .actions .btn {
        flex: 1 1 170px;
    }

    .theme-toggle {
        width: 42px;
        min-width: 42px;
    }

    .map-canvas {
        height: 320px;
    }
}
