/* Shared look for the gada.space web-project demos.
 * Fonts match the site (Inter for UI and data, Newsreader for titles); chart
 * colors are the validated ramps from the data-viz palette (see each ramp's
 * comment). Demos load this first, then their own stylesheet. */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400..700&family=Newsreader:opsz,wght@6..72,400..600&display=swap');

:root {
    color-scheme: light;
    --surface: #ffffff;
    --plane: #f9f9f9;
    --ink: #191919;
    --ink-2: #666666;
    --grid: #e7e7e7;
    --axis: #c2c2c2;
    --ring: rgba(11, 11, 11, 0.1);
    --focus: #257de0;

    /* Sequential blue, steps 250-650 (validated: ordinal, light surface) */
    --seq-1: #84b9f3;
    --seq-2: #519ced;
    --seq-3: #257de0;
    --seq-4: #1b64be;
    --seq-5: #0f4a96;

    /* Diverging blue <-> red with a gray midpoint (each arm validated) */
    --div-neg-2: #257de0;
    --div-neg-1: #84b9f3;
    --div-mid: #d4d4d4;
    --div-pos-1: #fc9272;
    --div-pos-2: #fb6a4a;
    --div-pos-3: #ef3b2c;
    --div-pos-4: #cb181d;
    --div-pos-5: #99000d;

    /* Sequential green for vegetation, 5 steps (validated: ordinal, light surface) */
    --green-1: #74c476;
    --green-2: #41ab5d;
    --green-3: #238b45;
    --green-4: #006d2c;
    --green-5: #00441b;

    --no-data: #f2f2f2;
    --no-data-line: #cfcfcf;

    --sans: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
    --serif: Newsreader, Georgia, serif;
}

/* Dark theme, chosen by shared/theme.js (data-theme), with the system setting
 * as the no-JavaScript fallback. Surface and text match gada.space's dark
 * mode. Sequential ramps flip their anchor: low values sit near the dark
 * surface and high values are brightest; the diverging arms grow brighter
 * away from a dark gray midpoint. Every ramp is validated on #171717
 * (ordinal: monotone lightness, visible steps, nearest step >= 2:1). */
:root[data-theme='dark'] {
    color-scheme: dark;
    --surface: #171717;
    --plane: #1f1f1f;
    --ink: #f2f1ec;
    --ink-2: #a3a3a3;
    --grid: #2e2e2e;
    --axis: #4a4a4a;
    --ring: rgba(255, 255, 255, 0.14);
    --focus: #6aabf1;

    --seq-1: #1757ac;
    --seq-2: #2370cd;
    --seq-3: #338ced;
    --seq-4: #6aabf1;
    --seq-5: #9dc8f7;

    --div-neg-2: #6aabf1;
    --div-neg-1: #1757ac;
    --div-mid: #383838;
    --div-pos-1: #a3302a;
    --div-pos-2: #cb3a33;
    --div-pos-3: #ef5a47;
    --div-pos-4: #f88a70;
    --div-pos-5: #fcbba1;

    --green-1: #238b45;
    --green-2: #41ab5d;
    --green-3: #74c476;
    --green-4: #a1d99b;
    --green-5: #c7e9c0;

    --no-data: #242424;
    --no-data-line: #3a3a3a;
}
@media (prefers-color-scheme: dark) {
    :root:where(:not([data-theme='light'])) {
        color-scheme: dark;
        --surface: #171717; --plane: #1f1f1f; --ink: #f2f1ec; --ink-2: #a3a3a3; --grid: #2e2e2e; --axis: #4a4a4a;
        --ring: rgba(255, 255, 255, 0.14); --focus: #6aabf1;
        --seq-1: #1757ac; --seq-2: #2370cd; --seq-3: #338ced; --seq-4: #6aabf1; --seq-5: #9dc8f7;
        --div-neg-2: #6aabf1; --div-neg-1: #1757ac; --div-mid: #383838;
        --div-pos-1: #a3302a; --div-pos-2: #cb3a33; --div-pos-3: #ef5a47; --div-pos-4: #f88a70; --div-pos-5: #fcbba1;
        --green-1: #238b45; --green-2: #41ab5d; --green-3: #74c476; --green-4: #a1d99b; --green-5: #c7e9c0;
        --no-data: #242424; --no-data-line: #3a3a3a;
    }
}
/* The "← gada.space" link carries light inline styles; restyle it in dark. */
:root[data-theme='dark'] a[title='About this project on gada.space'] {
    color: #f2f1ec !important;
    background: rgba(23, 23, 23, 0.92) !important;
    border-color: #f2f1ec !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5) !important;
}

* { box-sizing: border-box; }
/* Components set their own display, which would otherwise override [hidden]. */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--surface);
    color: var(--ink);
    font: 400 15px/1.5 var(--sans);
    -webkit-font-smoothing: antialiased;
}

.demo { max-width: 1100px; margin: 0 auto; padding: 20px 20px 72px; }
.demo h1 { font: 500 clamp(1.4rem, 3vw, 2rem)/1.15 var(--serif); margin: 0 0 4px; letter-spacing: -0.01em; }
.demo .subtitle { color: var(--ink-2); margin: 0 0 16px; font-size: 14px; }
.demo .source { color: var(--ink-2); font-size: 12px; margin-top: 12px; }
.demo .source a { color: inherit; }

/* Controls: one row above the chart, wrapping on narrow screens */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 0 0 12px; }

.btn {
    font: 500 13px/1 var(--sans);
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--ink);
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover { background: var(--plane); }
.btn[aria-pressed='true'], .btn.is-primary { background: var(--ink); color: var(--surface); }

.segmented { display: inline-flex; border: 1px solid var(--ink); border-radius: 999px; padding: 2px; gap: 2px; }
.segmented button {
    font: 500 13px/1 var(--sans);
    border: 0;
    background: transparent;
    color: var(--ink);
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
}
.segmented button[aria-checked='true'] { background: var(--ink); color: var(--surface); }

.year-control { display: flex; align-items: center; gap: 10px; flex: 1 1 260px; min-width: 220px; }
.year-control output { font: 600 22px/1 var(--sans); font-variant-numeric: tabular-nums; min-width: 3.2em; }
input[type='range'] { flex: 1; accent-color: var(--ink); min-width: 120px; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Tooltip: value leads, label follows */
.tooltip {
    position: fixed;
    pointer-events: none;
    z-index: 10;
    background: var(--surface);
    border: 1px solid var(--ring);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.35;
    max-width: 240px;
    opacity: 0;
    transition: opacity 0.08s;
}
.tooltip.is-visible { opacity: 1; }
.tooltip .value { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.tooltip .label { color: var(--ink-2); }

/* Binned legend */
.legend { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 2px; font-size: 12px; color: var(--ink-2); margin: 8px 0 0; }
.legend .item { display: flex; flex-direction: column; gap: 4px; min-width: 56px; }
.legend .swatch { height: 12px; border-radius: 2px; }
.legend .gap { width: 12px; }
.legend .title { width: 100%; color: var(--ink); font-weight: 500; margin-bottom: 4px; }

.no-data-swatch { background: repeating-linear-gradient(45deg, var(--no-data) 0 3px, var(--no-data-line) 3px 4px); }

/* Table view, for every value without hovering */
details.table-view { margin-top: 16px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--ink-2); }
details.table-view table { border-collapse: collapse; margin-top: 8px; width: 100%; max-width: 480px; }
details.table-view th, details.table-view td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--grid); }
details.table-view td.num, details.table-view th.num { text-align: right; font-variant-numeric: tabular-nums; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) { .tooltip { transition: none; } }
