:root {
    --primary: #f7931a;
    --bg-dark: #0f111a;
    --surface: #141722;
    --card-bg: rgba(var(--fg), 0.03);
    --card-border: rgba(var(--fg), 0.08);
    --text-main: #e0e0e0;
    --text-dim: #a0a0a0;
    --text-muted: #6f7380;
    --accent: #00ccff;
    --grid: rgba(var(--fg), 0.06);
    --ink: #fff;                 /* strongest text */
    --fg: 255, 255, 255;         /* rgb of faint lines and washes */
    --bg-rgb: 15, 17, 26;        /* rgb of the page background, for frosted bars */

    /* Domain lanes: validated categorical order (dark), "Other" is neutral */
    --lane-0: #3987e5;
    --lane-1: #d95926;
    --lane-2: #199e70;
    --lane-3: #c98500;
    --lane-4: #d55181;
    --lane-5: #008300;
    --lane-6: #9085e9;
    --lane-7: #e66767;
    --lane-8: #8a8f98;

    --frontier: #f7931a;
    --reg-us: #3987e5;
    --reg-cn: #e66767;
    --reg-other: #199e70;
}

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

html, body { width: 100%; margin: 0; padding: 0; }

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Figtree', sans-serif;
    line-height: 1.6;
    font-weight: 300;
    overflow-x: hidden;
    background: radial-gradient(circle at 50% -20%, #1e2130, #0f111a);
    min-height: 100vh;
}

.top-nav {
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(var(--bg-rgb), 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--card-border);
    position: sticky;
    top: 0;
    z-index: 1000;
}
.logo-link { display: flex; align-items: center; text-decoration: none; color: var(--text-main); gap: 12px; transition: transform 0.2s ease; }
.logo-link:hover { transform: scale(1.02); }
.nav-logo { height: 32px; width: auto; }
.nav-date { font-size: 0.85rem; color: var(--text-dim); letter-spacing: 1px; }

/* min-width: 0 because the footer script makes <body> a flex column; without it wide tables stretch the page */
.container { max-width: 1480px; margin: 0 auto; padding: 40px 20px; min-width: 0; width: 100%; }

header { text-align: center; margin-bottom: 40px; animation: fadeInDown 0.8s ease-out; }

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    letter-spacing: 2px;
    color: var(--primary);
    border: 1px solid rgba(247, 147, 26, 0.3);
    background: rgba(247, 147, 26, 0.07);
    padding: 6px 16px;
    border-radius: 20px;
    margin-bottom: 16px;
}

h1 {
    font-size: 3.2rem;
    font-weight: 300;
    background: linear-gradient(135deg, var(--primary), #ffc107);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
    letter-spacing: -1px;
}

.subheader { font-size: 1.1rem; color: var(--text-dim); max-width: 700px; margin: 0 auto; }
.subheader strong { color: var(--text-main); font-weight: 400; }

.kpis { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; margin-top: 28px; }
.kpi {
    min-width: 170px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 14px 20px;
}
.kpi-num { font-size: 2.2rem; font-weight: 600; color: var(--ink); line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 0.75rem; letter-spacing: 1px; text-transform: uppercase; color: var(--text-dim); }

.quick-nav {
    position: sticky;
    top: 72px;
    z-index: 900;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    padding: 12px 16px;
    margin-bottom: 36px;
    background: rgba(var(--bg-rgb), 0.85);
    backdrop-filter: blur(10px);
    border: 1px solid var(--card-border);
    border-radius: 30px;
}
.quick-nav a {
    font-size: 0.78rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-dim);
    text-decoration: none;
    padding: 7px 16px;
    border: 1px solid var(--card-border);
    border-radius: 20px;
    transition: all 0.25s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.quick-nav a:hover { color: var(--accent); border-color: var(--accent); background: rgba(0, 204, 255, 0.07); }

.era-switch { display: inline-flex; padding: 5px; margin: 6px 0 18px; border-radius: 40px; border: 1px solid rgba(247, 147, 26, 0.45); background: rgba(247, 147, 26, 0.05); }
.era-switch button {
    font-family: inherit;
    font-size: 1.05rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--text-dim);
    background: transparent;
    border: none;
    border-radius: 34px;
    padding: 12px 30px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.25s ease;
}
.era-switch button:hover { color: var(--text-main); }
.era-switch + .kind-switch { margin-left: 12px; }
.era-switch button.on { background: var(--primary); color: #0f111a; font-weight: 600; }

.section { margin-bottom: 60px; scroll-margin-top: 150px; }
.section-title { font-size: 1.7rem; font-weight: 300; color: var(--accent); letter-spacing: 1px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.section-title.gold { color: var(--primary); }
.section-desc { color: var(--text-dim); font-size: 0.95rem; margin-bottom: 24px; max-width: 860px; }
.section-desc strong { color: var(--text-main); font-weight: 400; }

.count-badge { margin-left: auto; font-size: 0.75rem; border: 1px solid currentColor; border-radius: 14px; padding: 2px 10px; opacity: 0.85; }

.river-card, .chart-card {
    background: var(--surface);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 20px 22px;
}

/* River */
.river-head { display: flex; align-items: baseline; gap: 18px; margin-bottom: 10px; flex-wrap: wrap; }
.river-year {
    font-size: 3rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    min-width: 3.2em;
}
.river-count { color: var(--text-dim); font-size: 1rem; }
.river-count span { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.river-controls { margin-left: auto; display: flex; gap: 8px; }
.ctl-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(247, 147, 26, 0.45);
    background: rgba(247, 147, 26, 0.08);
    color: var(--primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}
.ctl-btn:hover { background: rgba(247, 147, 26, 0.2); transform: scale(1.06); }
.river-wrap { position: relative; width: 100%; }
.river-wrap canvas { display: block; width: 100%; cursor: crosshair; }
.scrubber { width: 100%; margin-top: 10px; accent-color: var(--primary); cursor: pointer; }

.ticker { display: flex; gap: 10px; flex-wrap: wrap; min-height: 40px; margin-top: 10px; }
.tick {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 18px;
    background: rgba(247, 147, 26, 0.08);
    border: 1px solid rgba(247, 147, 26, 0.3);
    color: var(--text-main);
    text-decoration: none;
    animation: tickIn 0.45s cubic-bezier(.2, 1.4, .4, 1) both;
}
.tick b { color: var(--ink); font-weight: 600; }
.tick small { color: var(--text-dim); }
.tick i { color: var(--primary); }
@keyframes tickIn { from { opacity: 0; transform: translateY(10px) scale(0.85); } to { opacity: 1; transform: none; } }

/* Charts */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 14px; font-size: 0.82rem; color: var(--text-dim); }
.lg-item { display: inline-flex; align-items: center; gap: 6px; }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chart-svg { width: 100%; position: relative; }
.chart-svg svg { display: block; width: 100%; height: auto; overflow: visible; }
.axis text { fill: var(--text-muted); font-size: 11px; font-family: 'Figtree', sans-serif; }
.axis line, .axis path { stroke: var(--grid); }
.grid line { stroke: var(--grid); }
.direct-label { fill: var(--text-main); font-size: 12px; font-family: 'Figtree', sans-serif; font-weight: 600; }
.direct-label.dim { fill: var(--text-dim); font-weight: 400; }
.anno-line { stroke: rgba(var(--fg), 0.25); stroke-dasharray: 3 3; }

.bar-seg { transform-box: fill-box; transform-origin: bottom; transform: scaleY(0); transition: transform 0.7s cubic-bezier(.2, .9, .3, 1); }
.in .bar-seg { transform: scaleY(1); }
.bar-hit { fill: transparent; cursor: pointer; }
.bar-hit:hover { fill: rgba(var(--fg), 0.05); }

.cdot { opacity: 0; transform-box: fill-box; transform-origin: center; transform: scale(0); transition: opacity 0.4s ease, transform 0.5s cubic-bezier(.2, 1.6, .4, 1); cursor: pointer; }
.in .cdot { opacity: 1; transform: scale(1); }
.cdot:hover { stroke: var(--ink); stroke-width: 2; }
.c-label { opacity: 0; transition: opacity 0.6s ease; }
.in .c-label { opacity: 1; }
.trend-line { stroke: var(--frontier); stroke-width: 2; stroke-dasharray: 6 5; fill: none; opacity: 0; transition: opacity 0.8s ease 2.4s; }
.in .trend-line { opacity: 0.8; }
.lg-line { width: 16px; height: 2px; background: var(--frontier); display: inline-block; border-radius: 1px; }
.record-line { stroke: var(--frontier); stroke-width: 2; fill: none; stroke-dasharray: var(--len); stroke-dashoffset: var(--len); transition: stroke-dashoffset 2.4s ease-in-out; }
.in .record-line { stroke-dashoffset: 0; }

/* Race */
.race-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.race-head .legend { margin-bottom: 0; }
.race { position: relative; margin-top: 14px; }
.race-date {
    position: absolute;
    right: 6px;
    bottom: 4px;
    font-size: 4rem;
    font-weight: 700;
    color: rgba(var(--fg), 0.12);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}
.race-row {
    position: absolute;
    left: 0;
    right: 0;
    height: 34px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: transform 0.45s ease, opacity 0.45s ease;
}
.race-name { width: 170px; flex: none; text-align: right; font-size: 0.88rem; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.race-track { flex: 1; position: relative; height: 24px; }
.race-bar { height: 100%; border-radius: 0 4px 4px 0; transition: width 0.45s linear; min-width: 2px; }
.race-val { position: absolute; top: 2px; font-size: 0.82rem; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; padding-left: 8px; transition: left 0.45s linear; }

/* All models */
.filters { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 16px; }
#search {
    width: 100%;
    max-width: 420px;
    padding: 10px 16px;
    border-radius: 22px;
    border: 1px solid var(--card-border);
    background: rgba(var(--fg), 0.04);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
}
#search:focus { outline: none; border-color: var(--accent); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.f-chip {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 5px 12px;
    border-radius: 16px;
    border: 1px solid var(--card-border);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}
.f-chip:hover { color: var(--text-main); border-color: rgba(var(--fg), 0.25); }
.f-chip.on { color: var(--ink); border-color: var(--primary); background: rgba(247, 147, 26, 0.12); }
.f-chip.off { opacity: 0.4; }

.decades { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.decades a { font-size: 0.78rem; color: var(--text-dim); text-decoration: none; padding: 3px 10px; border-radius: 12px; border: 1px solid var(--card-border); }
.decades a:hover { color: var(--accent); border-color: var(--accent); }

.year-block { display: grid; grid-template-columns: 110px 1fr; gap: 16px; padding: 14px 0; border-top: 1px solid var(--card-border); scroll-margin-top: 150px; }
.year-side { position: sticky; top: 150px; align-self: start; }
.year-num { font-size: 1.6rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.year-n { font-size: 0.78rem; color: var(--text-dim); }
.year-bar { height: 4px; border-radius: 2px; background: var(--primary); margin-top: 6px; transform-origin: left; transform: scaleX(0); transition: transform 0.9s cubic-bezier(.2, .9, .3, 1); }
.year-block.in .year-bar { transform: scaleX(1); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.month-strip { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; height: 26px; margin-top: 10px; align-items: end; }
.ms-cell { height: 100%; display: flex; align-items: flex-end; border-radius: 2px; background: rgba(var(--fg), 0.04); }
.ms-cell span { width: 100%; background: var(--accent); border-radius: 2px 2px 0 0; transform-origin: bottom; transform: scaleY(0); transition: transform 0.6s cubic-bezier(.2, .9, .3, 1) 0.2s; }
.year-block.in .ms-cell span { transform: scaleY(1); }
.ms-cell:hover span { background: var(--ink); }
.month-letters { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; margin-top: 2px; font-size: 0.6rem; color: var(--text-muted); text-align: center; line-height: 1.2; }
.months { position: relative; display: flex; flex-direction: column; gap: 8px; padding-left: 18px; border-left: 1px solid var(--card-border); }
.month-row { position: relative; display: grid; grid-template-columns: 56px 1fr; gap: 10px; align-items: start; scroll-margin-top: 150px; }
.month-row::before { content: ''; position: absolute; left: -22px; top: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--bg-dark); }
.month-label { font-size: 0.78rem; letter-spacing: 1px; text-transform: uppercase; color: var(--text-main); padding-top: 3px; display: flex; gap: 6px; align-items: baseline; }
.month-label span { color: var(--text-muted); font-size: 0.72rem; letter-spacing: 0; }
.m-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px 3px 8px;
    border-radius: 14px;
    background: rgba(var(--fg), 0.035);
    border: 1px solid rgba(var(--fg), 0.06);
    font-size: 0.8rem;
    color: var(--text-main);
    text-decoration: none;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.35s ease, transform 0.35s ease, background 0.2s ease;
}
.year-block.in .m-chip { opacity: 1; transform: none; }
.m-chip:hover { background: rgba(0, 204, 255, 0.1); border-color: rgba(0, 204, 255, 0.4); }
.m-chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.m-chip small { color: var(--text-muted); }
.m-chip.frontier { border-color: rgba(247, 147, 26, 0.55); background: rgba(247, 147, 26, 0.08); }
.m-chip.frontier::after { content: '\2605'; color: var(--primary); font-size: 0.75rem; }
.empty { color: var(--text-dim); padding: 30px 0; text-align: center; }

.source-note { color: var(--text-muted); font-size: 0.8rem; text-align: center; margin-top: 10px; }
.source-note a { color: var(--text-dim); }

.viz-tip {
    position: fixed;
    z-index: 2000;
    pointer-events: none;
    max-width: 300px;
    background: rgba(20, 23, 34, 0.97);
    border: 1px solid rgba(var(--fg), 0.15);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 0.82rem;
    color: var(--text-dim);
    line-height: 1.45;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.viz-tip b { color: var(--ink); font-weight: 600; }
.viz-tip .tip-row { display: flex; align-items: center; gap: 6px; }

@keyframes fadeInDown { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

@media (prefers-reduced-motion: reduce) {
    .bar-seg, .cdot, .c-label, .trend-line, .record-line, .m-chip, .year-bar, .race-row, .race-bar, .race-val { transition: none !important; }
    .tick { animation: none; }
}

@media (max-width: 768px) {
    .top-nav { padding: 14px 16px; }
    .container { padding: 24px 16px; }
    h1 { font-size: 2.3rem; }
    .kpi { min-width: 0; flex: 1 1 40%; padding: 10px 12px; }
    .kpi-num { font-size: 1.6rem; }
    .quick-nav { top: 62px; border-radius: 18px; padding: 8px; gap: 6px; }
    .quick-nav a { padding: 5px 10px; font-size: 0.7rem; }
    .era-switch { max-width: 100%; }
    .era-switch button { font-size: 0.78rem; padding: 9px 12px; letter-spacing: 0.5px; white-space: normal; }
    .era-switch { margin-bottom: 8px; }
    .era-switch + .kind-switch { margin-left: 0; margin-bottom: 18px; }
    .river-card, .chart-card { padding: 14px 12px; }
    .river-year { font-size: 2.2rem; }
    .race-name { width: 96px; font-size: 0.78rem; }
    .race-date { font-size: 2.6rem; }
    .year-block { grid-template-columns: 1fr; gap: 8px; }
    .year-side { position: static; display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
    .year-bar { flex: 1; }
    .month-strip, .month-letters { flex-basis: 100%; margin-top: 0; }
    .month-letters { margin-top: -8px; }
    .months { padding-left: 14px; }
    .month-row { grid-template-columns: 1fr; gap: 4px; }
    .month-row::before { left: -18px; }
}

/* Provider logos (provider-icons.js): brand-colour images, one-colour logos as white masks */
.pico { display: inline-block; width: 1em; height: 1em; flex: none; vertical-align: -0.14em; margin-right: 0.35em; }
.pico.mono { background: var(--ink); -webkit-mask: var(--pico) center / contain no-repeat; mask: var(--pico) center / contain no-repeat; }

/* Bright skin */
:root[data-theme="light"] {
    --primary: #b45f06;
    --frontier: #e8850c;
    --bg-dark: #f4f6fa;
    --surface: #ffffff;
    --text-main: #1a1d29;
    --text-dim: #4a5068;
    --text-muted: #6b7186;
    --accent: #0277b5;
    --ink: #0b0d14;
    --fg: 20, 24, 40;
    --bg-rgb: 255, 255, 255;
    --green: #047857;
    --orange: #b45309;
    --red: #dc2626;
    --card-border: rgba(var(--fg), 0.11);
    --grid: rgba(var(--fg), 0.08);
}
:root[data-theme="light"] body { background: radial-gradient(circle at 50% -20%, #ffffff, #eef1f6); }
:root[data-theme="light"] h1 { background: linear-gradient(135deg, #c2410c, #e88a00); -webkit-background-clip: text; background-clip: text; }
:root[data-theme="light"] .era-switch button.on,
:root[data-theme="light"] .sort-btn.on,
:root[data-theme="light"] .scen button.on,
:root[data-theme="light"] .country-cur { background: #f7931a; border-color: #f7931a; color: #1a1d29; }
:root[data-theme="light"] .river-card,
:root[data-theme="light"] .chart-card,
:root[data-theme="light"] .kpi { box-shadow: 0 1px 3px rgba(20, 24, 40, 0.06); }
:root[data-theme="light"] .kpi { background: #fff; }
:root[data-theme="light"] .quick-nav a:hover { background: rgba(2, 119, 181, 0.07); }
:root[data-theme="light"] .m-chip:hover { background: rgba(2, 119, 181, 0.08); border-color: rgba(2, 119, 181, 0.4); }
:root[data-theme="light"] .viz-tip { background: rgba(255, 255, 255, 0.98); box-shadow: 0 12px 32px rgba(20, 24, 40, 0.16); }
