  :root {
    --bg-0: #0a0e14;
    --bg-1: #10151d;
    --bg-2: #161c26;
    --bg-3: #1e2630;
    --border: #2a3340;
    --text: #d8e0ea;
    --text-dim: #7c8794;
    --accent: #4fd1ff;

    --c-wind: #45c4a0;
    --c-solar: #f2c94c;
    --c-gas: #e3654b;
    --c-nuclear: #b085f5;
    --c-biomass: #a3823a;
    --c-imports: #6c8ebf;
    --c-coal: #858f9d;
    --c-hydro: #51a6c8;
    --c-intensity: #ffffff;
    --c-freq: #4fd1ff;
    --c-balance: #f2994a;

    --very-low: #1fae7a;
    --low: #63c15f;
    --moderate: #e0c23c;
    --high: #e3813f;
    --very-high: #e2503f;
  }

  * { box-sizing: border-box; }

  html, body {
    margin: 0;
    padding: 0;
    background: var(--bg-0);
    color: var(--text);
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
    font-size: 13px;
  }

  #app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  header.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 10px;
  }

  header.top-bar h1 {
    font-size: 15px;
    margin: 0;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
    font-weight: 600;
  }

  header.top-bar h1 span { color: var(--accent); }

  /* Header link buttons (main site + data source) */
  .header-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .header-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-2);
    color: var(--text-dim);
    font-size: 12px;
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
  }

  .header-link-btn:hover { color: var(--text); border-color: var(--accent); }

  .header-link-btn img, .header-link-btn svg { width: 14px; height: 14px; flex: 0 0 auto; }

  .header-link-btn img { border-radius: 2px; }

  .header-link-btn svg { fill: currentColor; }

  /* Data outage / staleness notice */
  .outage-banner {
    display: none;
    align-items: flex-start;
    gap: 10px;
    background: rgba(217, 119, 6, 0.12);
    border: 1px solid rgba(217, 119, 6, 0.45);
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 12.5px;
    color: #f0b429;
    line-height: 1.4;
  }

  .outage-banner.visible {
    display: flex;
  }

  .outage-banner .icon {
    flex: 0 0 auto;
    font-size: 15px;
    line-height: 1.4;
  }

  .outage-banner strong {
    color: #ffcf5c;
  }

  .outage-banner .detail {
    color: var(--text-dim);
    font-weight: 400;
  }

  /* Metrics bar */
  .metrics-bar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }

  .metric-chip {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 12px;
    min-width: 128px;
  }

  .metric-chip .label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
  }

  .metric-chip .value {
    font-size: 18px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    line-height: 1.3;
  }

  .metric-chip .value .unit {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 400;
    margin-left: 3px;
  }

  #metric-intensity .value { color: var(--c-intensity); }
  #metric-demand .value { color: var(--c-imports); }
  #metric-frequency .value { color: var(--c-freq); }
  #metric-price .value { color: var(--c-balance); }
  #metric-generation .value { color: var(--c-wind); }
  #metric-transfers .value { color: var(--c-imports); }
  #metric-time .value { color: var(--accent); }

  /* Page-level tabs (Overview vs Carbon & Fuel Mix System) */
  nav.page-nav {
    display: flex;
    gap: 4px;
    padding: 10px 16px 0;
    background: var(--bg-1);
  }

  nav.page-nav button,
  nav.page-nav a {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid var(--border);
    border-bottom: none;
    color: var(--text-dim);
    padding: 8px 16px;
    border-radius: 6px 6px 0 0;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
  }

  nav.page-nav button:hover,
  nav.page-nav a:hover { color: var(--text); }

  nav.page-nav button.active,
  nav.page-nav a.active {
    background: var(--bg-2);
    color: var(--accent);
    border-color: var(--border);
  }

  .app-page { display: none; }
  .app-page.active { display: block; }

  /* Nav bar */
  nav.history-nav {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }

  nav.history-nav button,
  nav.history-nav a {
    display: inline-flex;
    align-items: center;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 14px;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
  }

  nav.history-nav button:hover,
  nav.history-nav a:hover {
    color: var(--text);
    border-color: var(--accent);
  }

  nav.history-nav button.active,
  nav.history-nav a.active {
    background: var(--accent);
    color: #062028;
    border-color: var(--accent);
    font-weight: 600;
  }

  nav.history-nav .nav-status {
    margin-left: auto;
    align-self: center;
    font-size: 11px;
    color: var(--text-dim);
  }

  /* Chart viewport */
  main.viewport {
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 12px 16px;
  }

  .chart-panel {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px 12px;
  }

  .chart-panel .panel-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
  }

  /* Height is auto so uPlot's legend (rendered below the canvas) has room to
     breathe instead of overlapping the next chart panel. */
  .chart-holder { width: 100%; }

  .server-chart { margin: 0; width: 100%; }

  .interactive-chart-host { width: 100%; }

  .chart-svg[hidden] { display: none; }

  .chart-legend[hidden] { display: none; }

  .chart-svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
  }

  .chart-gridline { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; }

  .chart-axis-label {
    fill: var(--text-dim);
    font-family: inherit;
    font-size: 11px;
  }

  .chart-line {
    fill: none;
    stroke-width: 1.8;
    vector-effect: non-scaling-stroke;
  }

  .server-chart figcaption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin-top: 6px;
  }

  .chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 14px;
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .chart-legend li {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--text-dim);
    font-size: 10px;
  }

  .chart-key {
    display: inline-block;
    width: 12px;
    height: 3px;
    background: var(--series-color);
    flex: 0 0 auto;
  }

  .chart-range,
  .chart-empty,
  .chart-interaction-hint {
    color: var(--text-dim);
    font-size: 11px;
  }

  .chart-interaction-hint { margin-left: auto; }

  .chart-empty { margin: 10px 0; }

  .u-legend { font-size: 11px !important; }
  .u-legend th { font-variant-numeric: tabular-nums; }

  /* Regional section */
  section.regional {
    padding: 4px 16px 20px;
  }

  section.regional h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin: 10px 0 8px;
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .legend-swatches {
    display: flex;
    gap: 10px;
    font-size: 10px;
    text-transform: none;
    letter-spacing: 0;
  }

  .legend-swatches span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-dim);
  }

  .legend-swatches i {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    display: inline-block;
  }

  .region-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
  }

  .region-card {
    position: relative;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    cursor: default;
    transition: transform 0.1s, box-shadow 0.1s;
  }

  .region-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
    z-index: 2;
  }

  .region-card .name {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
  }

  .region-card .intensity {
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }

  .region-card .intensity .unit {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 400;
  }

  .region-card .meta {
    display: flex;
    justify-content: space-between;
    font-size: 10.5px;
    color: var(--text-dim);
    margin-top: 4px;
    text-transform: capitalize;
  }

  /* Regional 24h intensity and primary-fuel heatmap strips */
  .regional > .legend-swatches {
    flex-wrap: wrap;
    margin-bottom: 8px;
  }

  .regional h2.region-fuel-heading { margin-top: 40px; }

  .region-history-nav {
    display: flex;
    gap: 6px;
    margin: 10px 0 14px;
  }

  .region-history-nav a {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 11px;
  }

  .region-history-nav a:hover,
  .region-history-nav a.active {
    color: var(--accent);
    border-color: var(--accent);
  }

  .region-history {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-x: auto;
  }

  .region-history-row {
    display: grid;
    grid-template-columns: 150px 1fr;
    align-items: center;
    gap: 8px;
  }

  .region-history-row .name {
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .region-history-cells {
    display: flex;
    gap: 1px;
    min-width: 480px;
  }

  .region-history-cells .cell {
    flex: 1 1 auto;
    height: 20px;
    border-radius: 2px;
    cursor: default;
  }

  .region-history-axis {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 8px;
    margin-top: 2px;
  }

  .region-history-axis .labels {
    display: flex;
    justify-content: space-between;
    font-size: 9.5px;
    color: var(--text-dim);
    min-width: 480px;
  }

  footer {
    margin-top: auto;
    padding: 8px 16px;
    font-size: 10.5px;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
  }

  footer p { margin: 4px 0; line-height: 1.5; }

  footer a {
    color: var(--accent);
    text-decoration: none;
  }

  footer a:hover { text-decoration: underline; }

  /* Detailed fuel & transfer breakdown */
  section.detail {
    padding: 4px 16px 6px;
  }

  section.detail h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin: 10px 0 8px;
  }

  .detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 10px;
  }

  .detail-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
  }

  .detail-card h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin: 0 0 6px;
  }

  .detail-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--border);
  }

  .detail-row:last-child { border-bottom: none; }

  .detail-row .name {
    flex: 1 1 auto;
    font-size: 12px;
    color: var(--text);
  }

  .detail-row .val {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .detail-row .pct {
    font-size: 11px;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    min-width: 46px;
    text-align: right;
    white-space: nowrap;
  }

  /* Changelog page */
  section.changelog {
    padding: 16px 16px 24px;
    max-width: 760px;
  }

  section.changelog h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    margin: 0 0 6px;
  }

  .changelog-note {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
    margin: 0 0 16px;
  }

  .changelog-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .changelog-entry {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
  }

  .changelog-entry .changelog-date {
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
  }

  .changelog-entry h3 {
    font-size: 13px;
    color: var(--text);
    margin: 0 0 6px;
  }

  .changelog-entry ul {
    margin: 0;
    padding-left: 18px;
  }

  .changelog-entry li {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.5;
    margin: 2px 0;
  }

  /* Documentation page */
  .documentation-page {
    width: min(100%, 900px);
    padding: 16px 16px 28px;
    margin: 0 auto;
  }

  .documentation-page > h2 {
    margin: 0 0 6px;
    color: var(--text);
    font-size: 20px;
  }

  .documentation-intro {
    margin: 0 0 18px;
    color: var(--text-dim);
    line-height: 1.6;
  }

  .documentation-section {
    margin: 0 0 12px;
    padding: 14px 16px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
  }

  .documentation-section h3 {
    margin: 0 0 8px;
    color: var(--accent);
    font-size: 14px;
  }

  .documentation-section p,
  .documentation-section li {
    color: var(--text-dim);
    font-size: 12.5px;
    line-height: 1.65;
  }

  .documentation-section p { margin: 8px 0 0; }
  .documentation-section ul { margin: 8px 0 0; padding-left: 20px; }
  .documentation-section li + li { margin-top: 5px; }

  .documentation-section a {
    color: var(--accent);
    text-decoration: none;
  }

  .documentation-section a:hover { text-decoration: underline; }

  .documentation-section code {
    padding: 1px 4px;
    background: var(--bg-3);
    border-radius: 3px;
    color: var(--text);
  }

  /* Grid Decarbonisation + Grid Operations summary cards */
  section.summary {
    padding: 4px 16px 0;
  }

  .summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 10px;
  }

  .summary-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
  }

  .summary-card h3 {
    margin: 0 0 10px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
  }

  .decarb-body {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .gauge-wrap {
    position: relative;
    width: 100px;
    height: 100px;
    flex: 0 0 auto;
  }

  .gauge-svg { width: 100%; height: 100%; transform: rotate(-90deg); }

  .gauge-track { fill: none; stroke: var(--bg-3); stroke-width: 10; }

  .gauge-progress {
    fill: none;
    stroke: var(--very-low);
    stroke-width: 10;
    stroke-linecap: round;
    stroke-dasharray: 314.159;
    stroke-dashoffset: 314.159;
    transition: stroke-dashoffset 0.4s ease, stroke 0.4s ease;
  }

  .gauge-label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .gauge-label .pct {
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
  }

  .gauge-label .caption {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-dim);
  }

  .decarb-submetrics {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .submetric-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 12px;
  }

  .submetric-row .name { color: var(--text-dim); }
  .submetric-row .val { font-weight: 600; font-variant-numeric: tabular-nums; cursor: default; }
  .submetric-row.low-carbon .val { color: var(--very-low); }
  .submetric-row.fossil .val { color: var(--c-gas); }

  .sparkline-holder {
    position: relative;
    width: 100%;
    min-height: 70px;
    margin-top: 12px;
  }

  .sparkline-holder .server-chart figcaption { display: none; }

  .sparkline-holder .chart-svg { max-height: 70px; }

  .sparkline-holder .interactive-chart-host { height: 100px; }

  .sparkline-holder .u-legend {
    position: absolute;
    top: 2px;
    left: 4px;
    background: rgba(10, 14, 20, 0.85);
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
    font-size: 10px !important;
    z-index: 2;
  }

  .ops-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .freq-display { display: flex; align-items: baseline; gap: 10px; }

  .freq-value {
    font-size: 28px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--c-freq);
    cursor: default;
  }

  .freq-delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    cursor: default;
  }

  .freq-delta.rising { color: var(--low); }
  .freq-delta.falling { color: var(--very-high); }
  .freq-delta.flat { color: var(--text-dim); }

  .net-transfer-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    width: fit-content;
    cursor: default;
  }

  .net-transfer-badge .label {
    font-weight: 400;
    color: var(--text-dim);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .net-transfer-badge.importing {
    background: rgba(108, 142, 191, 0.18);
    color: var(--c-imports);
    border: 1px solid var(--c-imports);
  }

  .net-transfer-badge.exporting {
    background: rgba(31, 174, 122, 0.18);
    color: var(--very-low);
    border: 1px solid var(--very-low);
  }

  /* Info icon + explainer modal */
  .info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    border-radius: 50%;
    border: 1px solid var(--text-dim);
    background: transparent;
    color: var(--text-dim);
    font-size: 10px;
    font-weight: 700;
    font-style: italic;
    font-family: Georgia, "Times New Roman", serif;
    line-height: 1;
    cursor: pointer;
    flex: 0 0 auto;
    padding: 0;
  }

  .info-icon:hover {
    color: var(--accent);
    border-color: var(--accent);
  }

  .summary-card h3, section.detail h2, section.regional h2 {
    display: flex;
    align-items: center;
  }

  .info-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
  }

  .info-modal-overlay.open { display: flex; }

  .info-modal {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    max-width: 440px;
    width: 100%;
    padding: 16px 18px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  }

  .info-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
  }

  .info-modal-header h4 {
    margin: 0;
    font-size: 13px;
    color: var(--text);
  }

  .info-modal-close {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
  }

  .info-modal-close:hover { color: var(--text); }

  .info-modal-body {
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--text-dim);
  }

  .info-modal-body code {
    background: var(--bg-3);
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--text);
  }
