:root {
    color-scheme: light;
    --page: #f6f6f3;
    --surface: #fcfcfb;
    --card: #ffffff;
    --text: #0b0b0b;
    --text-2: #52514e;
    --muted: #898781;
    --grid: #e9e8e2;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.09);
    --accent: #2a78d6;
    --accent-soft: rgba(42, 120, 214, 0.10);

    /* chart palette (categorical slots, diverging poles, year ramp, ordinal ramp) */
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --warm: #d03b3b;
    --cool: #2a78d6;
    --neutral: #f0efec;
    --seq-old: #cde2fb;
    --seq-new: #104281;
    --ramp-1: #86b6ef;
    --ramp-2: #3987e5;
    --ramp-3: #1c5cab;
    --ramp-4: #0d366b;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --card: #151514;
        --text: #f0efec;
        --text-2: #c3c2b7;
        --muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.09);
        --accent: #3987e5;
        --accent-soft: rgba(57, 135, 229, 0.16);
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --series-4: #c98500;
        --warm: #e66767;
        --cool: #3987e5;
        --neutral: #383835;
        --seq-old: #184f95;
        --seq-new: #cde2fb;
        --ramp-1: #184f95;
        --ramp-2: #2a78d6;
        --ramp-3: #6da7ec;
        --ramp-4: #b7d3f6;
    }
}

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

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--page);
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    min-height: 100vh;
}

/* ---- sidebar ---- */

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 20px 12px;
    border-right: 1px solid var(--border);
    background: var(--card);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px 18px;
    font-weight: 650;
    font-size: 15px;
}

.brand svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: var(--accent);
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-group {
    margin: 14px 10px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.nav-item {
    display: block;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--text-2);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.nav-item:hover { background: var(--accent-soft); color: var(--text); }

.nav-item[aria-current="page"] {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* ---- main ---- */

main {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px 28px 40px;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px 24px;
    flex-wrap: wrap;
}

.title-block { max-width: 680px; }

h1 {
    font-size: 22px;
    font-weight: 650;
    letter-spacing: -0.01em;
}

#view-desc {
    margin-top: 4px;
    color: var(--text-2);
}

.global-controls,
.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 14px;
}

.controls:empty { display: none; }

.controls {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--card);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field > span {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

select,
input[type="number"] {
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

select { min-width: 140px; padding-right: 28px; }
#station { min-width: 220px; }
input[type="number"] { width: 92px; font-variant-numeric: tabular-nums; }

select:focus-visible,
input:focus-visible,
button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

select:disabled,
input:disabled { opacity: 0.45; }

.toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 34px;
    color: var(--text-2);
    cursor: pointer;
    user-select: none;
}

.toggle input { accent-color: var(--accent); width: 16px; height: 16px; }

.button {
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}

.button:hover,
.button[aria-expanded="true"] { border-color: var(--accent); }

.city-settings { flex-direction: column; align-items: stretch; }
.city-settings[hidden] { display: none; }
.city-settings-note { color: var(--text-2); max-width: 760px; }
.city-settings-fields { display: flex; flex-wrap: wrap; gap: 12px 14px; }
.city-settings .button { align-self: flex-start; }

/* ---- chart ---- */

.card {
    position: relative;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.chart-card {
    padding: 8px;
    min-height: 480px;
}

#chart { min-height: 460px; }

.loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--muted);
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    border-radius: 12px;
}

.loading[hidden] { display: none; }

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--grid);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty {
    padding: 80px 20px;
    text-align: center;
    color: var(--muted);
}

.summary {
    color: var(--text-2);
    max-width: 900px;
}

.summary b { color: var(--text); font-weight: 600; }

/* ---- small screens: sidebar becomes a scrolling tab strip ---- */

@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; }

    .sidebar {
        position: sticky;
        z-index: 10;
        height: auto;
        padding: 10px 16px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .brand { padding: 0 0 8px; }

    #view-nav {
        display: flex;
        gap: 4px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .nav-group { display: none; }
    .nav-item { width: auto; white-space: nowrap; }

    main { padding: 16px 16px 32px; }
    #station { min-width: 0; width: 100%; }
    .global-controls .field { flex: 1 1 200px; }
}
