:root {
    color-scheme: light;
    --page: #f9f9f7;
    --surface: #fcfcfb;
    --ink: #0b0b0b;
    --ink-2: #52514e;
    --muted: #898781;
    --grid: #e1e0d9;
    --axis: #c3c2b7;
    --border: rgba(11, 11, 11, 0.10);
    --wash: rgba(11, 11, 11, 0.05);
    --warning: #fab219;
    --series-1: #2a78d6;
    --series-2: #eb6834;
    --series-3: #1baf7a;
    --series-4: #eda100;
    --series-5: #e87ba4;
    --series-6: #008300;
    --series-7: #4a3aa7;
    --series-8: #e34948;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --page: #0d0d0d;
        --surface: #1a1a19;
        --ink: #ffffff;
        --ink-2: #c3c2b7;
        --muted: #898781;
        --grid: #2c2c2a;
        --axis: #383835;
        --border: rgba(255, 255, 255, 0.10);
        --wash: rgba(255, 255, 255, 0.06);
        --series-1: #3987e5;
        --series-2: #d95926;
        --series-3: #199e70;
        --series-4: #c98500;
        --series-5: #d55181;
        --series-6: #008300;
        --series-7: #9085e9;
        --series-8: #e66767;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--page);
    color: var(--ink);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 48px;
}

button, input, select {
    font: inherit;
    color: inherit;
}

/* Header and current values */

.top {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 16px;
    margin-bottom: 16px;
}

h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
}

.updated {
    margin: 0;
    color: var(--ink-2);
}

.stale::before {
    content: "▲";
    color: var(--warning);
    margin-right: 6px;
    font-size: 12px;
}

.notice {
    margin: 0 0 16px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink-2);
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.tile-label {
    color: var(--ink-2);
    font-size: 13px;
}

.tile-value {
    font-size: 26px;
    font-weight: 600;
}

/* Tabs and filters */

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.tabs button {
    padding: 8px 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: none;
    color: var(--ink-2);
    cursor: pointer;
}

.tabs button[aria-selected="true"] {
    color: var(--ink);
    border-bottom-color: var(--ink);
    font-weight: 600;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
    margin-bottom: 16px;
}

.seg {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
}

.seg button, .stepper button {
    padding: 5px 11px;
    border: 0;
    border-radius: 6px;
    background: none;
    cursor: pointer;
}

.seg button:hover, .stepper button:hover:not(:disabled) {
    background: var(--wash);
}

.seg button[aria-pressed="true"] {
    background: var(--ink);
    color: var(--surface);
}

.stepper {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.stepper button {
    border: 1px solid var(--border);
    background: var(--surface);
}

.stepper button:disabled {
    color: var(--muted);
    cursor: default;
}

.range-label {
    min-width: 13em;
    padding: 0 8px;
    text-align: center;
    color: var(--ink-2);
    font-variant-numeric: tabular-nums;
}

.check, .field {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ink-2);
}

.field input, .field select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}

/* Charts */

.charts {
    display: grid;
    gap: 12px;
    transition: opacity 0.15s;
}

.loading {
    opacity: 0.5;
}

.card {
    margin: 0 0 12px;
    padding: 14px 16px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.charts .card {
    margin: 0;
}

figcaption {
    margin-bottom: 6px;
}

.card-title {
    font-weight: 600;
}

.card-sub {
    color: var(--muted);
    font-size: 13px;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin-bottom: 6px;
    color: var(--ink-2);
    font-size: 13px;
}

.key {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.key i {
    display: inline-block;
    width: 16px;
    height: 2px;
    border-radius: 1px;
}

button.key {
    padding: 2px 4px;
    border: 0;
    background: none;
    cursor: pointer;
}

button.key[aria-pressed="false"] {
    opacity: 0.4;
}

.plot {
    position: relative;
}

/* Vertical swipes scroll the page; sideways swipes and pinches go to the chart */
.plot canvas {
    touch-action: pan-y !important;
    cursor: grab;
}

.plot canvas:active {
    cursor: grabbing;
}

.hint {
    margin: -6px 0 12px;
    color: var(--muted);
    font-size: 13px;
}

.card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.small-button {
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font-size: 13px;
    cursor: pointer;
}

.small-button:hover {
    background: var(--wash);
}

.plot-s { height: 140px; }
.plot-m { height: 190px; }
.plot-l { height: 240px; }
.plot-xl { height: 340px; }

/* Tables */

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

th, td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--grid);
    text-align: right;
    white-space: nowrap;
}

th {
    color: var(--ink-2);
    font-weight: 500;
    font-size: 13px;
}

th:first-child, td:first-child {
    text-align: left;
}

td small {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

td.none {
    color: var(--muted);
    text-align: left;
}

.stats {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    border-collapse: separate;
    border-spacing: 0;
}

.stats tr:last-child td {
    border-bottom: 0;
}

.year-key {
    display: inline-block;
    width: 16px;
    height: 2px;
    margin-right: 8px;
    vertical-align: middle;
    border-radius: 1px;
}

.warn::before {
    content: "▲";
    color: var(--warning);
    margin-right: 4px;
    font-size: 11px;
}

.data-table {
    margin-top: 16px;
}

.data-table summary {
    color: var(--ink-2);
    cursor: pointer;
}

.data-table .table-wrap {
    max-height: 420px;
    margin-top: 8px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.data-table th {
    position: sticky;
    top: 0;
    background: var(--surface);
}

.footnote {
    color: var(--muted);
    font-size: 13px;
}

.error {
    color: var(--series-8);
}

@media (max-width: 600px) {
    .tile-value {
        font-size: 22px;
    }

    .range-label {
        min-width: 0;
        flex: 1;
    }

    .stepper {
        width: 100%;
    }

    .plot-l { height: 210px; }
    .plot-xl { height: 280px; }
}
