/* Palette tokens are the validated reference instance — see README.
   Series slots 1-6 in this exact order cleared the CVD, normal-vision and
   band checks in both modes. The stack order in app.js matches; changing
   either without re-running the validator breaks the guarantee. */

:root {
  color-scheme: light;

  --surface:        #fcfcfb;
  --plane:          #f9f9f7;
  --ink:            #0b0b0b;
  --ink-2:          #52514e;
  --ink-muted:      #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --hairline:       rgba(11, 11, 11, 0.10);

  --hydro:          #2a78d6;
  --fossil:         #eb6834;
  --wind:           #1baf7a;
  --solar:          #eda100;
  --pumped:         #e87ba4;
  --biomass:        #008300;
  --other:          #898781;
  --nuclear:        #4a3aa7;

  --import:         #e34948;
  --export:         #2a78d6;

  --radius:         10px;
  --gap:            2px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface:     #1a1a19;
    --plane:       #0d0d0d;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --ink-muted:   #898781;
    --grid:        #2c2c2a;
    --axis:        #383835;
    --hairline:    rgba(255, 255, 255, 0.10);

    --hydro:       #3987e5;
    --fossil:      #d95926;
    --wind:        #199e70;
    --solar:       #c98500;
    --pumped:      #d55181;
    --biomass:     #008300;
    --other:       #898781;
    --nuclear:     #9085e9;

    --import:      #e66767;
    --export:      #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface:     #1a1a19;
  --plane:       #0d0d0d;
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --ink-muted:   #898781;
  --grid:        #2c2c2a;
  --axis:        #383835;
  --hairline:    rgba(255, 255, 255, 0.10);

  --hydro:       #3987e5;
  --fossil:      #d95926;
  --wind:        #199e70;
  --solar:       #c98500;
  --pumped:      #d55181;
  --biomass:     #008300;
  --other:       #898781;
  --nuclear:     #9085e9;

  --import:      #e66767;
  --export:      #3987e5;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 400 16px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

/* ── header ─────────────────────────────────────────────────────────── */

header { margin-bottom: 28px; }

.topline {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

h1 {
  font-size: clamp(26px, 4.2vw, 40px);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
  font-weight: 650;
}

.sub {
  color: var(--ink-2);
  font-size: 15px;
  margin: 0;
  max-width: 62ch;
}

.controls { display: flex; gap: 6px; flex-shrink: 0; }

.controls button {
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}

.controls button[aria-pressed="true"] {
  color: var(--ink);
  border-color: var(--axis);
  font-weight: 600;
}

.stamp {
  margin-top: 14px;
  font-size: 13px;
  color: var(--ink-muted);
}

/* Inline rather than a flex item, so a wrapping stamp does not orphan the
   dot on a line of its own. */
.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--biomass);
  margin-right: 8px;
  vertical-align: middle;
}

/* ── cards ──────────────────────────────────────────────────────────── */

section {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
}

h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 600;
  margin: 0 0 18px;
}

.note {
  color: var(--ink-2);
  font-size: 14px;
  margin: 16px 0 0;
  max-width: 68ch;
}

/* ── stat tiles ─────────────────────────────────────────────────────── */

/* Separators are borders on the tiles, not grid gaps over a tinted
   container — an incomplete last row then reads as plain surface instead of
   an odd empty cell. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}

.tile {
  padding: 18px 20px;
  border-right: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
}

.tile .k {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
  font-weight: 600;
}

.tile .v {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-top: 4px;
  line-height: 1.1;
}

.tile .v small { font-size: 15px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .d { font-size: 13px; color: var(--ink-2); margin-top: 3px; }

.estimate-dot { background: var(--solar); }

/* ── share bar ──────────────────────────────────────────────────────── */

.sharebar {
  display: flex;
  width: 100%;
  height: 46px;
  gap: var(--gap);
  margin-bottom: 18px;
}

.sharebar span {
  height: 100%;
  border-radius: 3px;
  min-width: 2px;
  transition: opacity .15s;
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
  gap: 2px 30px;
}

.legend .row {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-size: 14px;
  padding: 4px 0;
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
}

#dayLegend .row { border-bottom: none; }

.legend .sw {
  width: 11px; height: 11px;
  border-radius: 3px;
  flex-shrink: 0;
  transform: translateY(1px);
}

/* Imported shares reuse the source colours, so the swatch has to carry the
   same hatch the donut does. Rows set background-color only; the stripes come
   from here. */
.legend .sw.imported {
  background-image: repeating-linear-gradient(45deg,
    transparent 0 2px, var(--surface) 2px 3.5px);
}

.legend .nm { color: var(--ink); }
.legend .mw { margin-left: auto; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend .pc { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 46px; text-align: right; }

/* ── the mix donut ──────────────────────────────────────────────────── */

.mixlayout {
  display: grid;
  grid-template-columns: minmax(240px, 340px) minmax(0, 1fr);
  gap: 26px 34px;
  align-items: center;
}

.donutwrap { max-width: 340px; width: 100%; }
.donutwrap svg { overflow: visible; }

/* Qualified with `.chart` so these win over the shared `.chart text` rule,
   which is otherwise more specific and would render both at 11px muted. */
.chart text.donutv { font: 600 30px system-ui, -apple-system, sans-serif; fill: var(--ink); letter-spacing: -.02em; }
.chart text.donutk { font: 500 12px system-ui, -apple-system, sans-serif; fill: var(--ink-muted); letter-spacing: .04em; }

.donutsplit {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--ink-2);
}

.donutsplit i {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 7px;
}

.mixlegends .subhead.first { margin-top: 0; }
.mixlegends .subhead { margin: 20px 0 8px; }

/* ── charts ─────────────────────────────────────────────────────────── */

.chart { width: 100%; display: block; overflow: visible; }
.scroller { overflow-x: auto; }
.chart text { font: 11px system-ui, -apple-system, sans-serif; fill: var(--ink-muted); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axisline { stroke: var(--axis); stroke-width: 1; }
.chart .loadline { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.chart .cursor { stroke: var(--axis); stroke-width: 1; }

.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .16);
  min-width: 178px;
  z-index: 10;
  opacity: 0;
  transition: opacity .1s;
}

.tip.on { opacity: 1; }
.tip .t { color: var(--ink-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; }
.tip .r { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.tip .r .sw { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.tip .r .v { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }

/* Share sits in its own fixed-width column so the percentages line up
   under each other regardless of how wide the MW value is. */
.tip .r .v em {
  display: inline-block;
  width: 46px;
  text-align: right;
  margin-left: 9px;
  font-style: normal;
  color: var(--ink-muted);
}
.tip .r.tot { border-top: 1px solid var(--hairline); margin-top: 5px; padding-top: 5px; font-weight: 600; }
.tip .r.tot .v { color: var(--ink); }

.plotwrap { position: relative; }

.panelstamp { margin: -8px 0 16px; }

/* ── trade (24 h import / export) ───────────────────────────────────── */

.tradestats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 8px 26px;
  margin-bottom: 20px;
}

.tstat .k {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-muted);
  font-weight: 600;
}

.tstat .v {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.15;
  margin-top: 2px;
}

.tstat .v small { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tstat .v.imp { color: var(--import); }
.tstat .v.exp { color: var(--export); }
.tstat .d { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.tradestats.compact { margin-bottom: 0; }

.sectionhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.sectionhead h2 { margin: 0; }

.segmented {
  display: flex;
  border: 1px solid var(--hairline);
  border-radius: 7px;
  overflow: hidden;
  flex-shrink: 0;
}
.segmented button {
  border: 0;
  border-right: 1px solid var(--hairline);
  border-radius: 0;
  padding: 6px 10px;
  background: transparent;
  color: var(--ink-2);
}
.segmented button:last-child { border-right: 0; }
.segmented button.active,
.segmented button[aria-pressed="true"] { background: var(--grid); color: var(--ink); font-weight: 600; }
.segmented button:disabled { color: var(--ink-muted); cursor: not-allowed; opacity: .55; }

.comparegrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1px;
  background: var(--hairline);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  overflow: hidden;
}
.comparecard { background: var(--surface); padding: 17px 18px; }
.comparecard .k { color: var(--ink-muted); text-transform: uppercase; letter-spacing: .07em; font-size: 11px; font-weight: 600; }
.comparecard .v { font-size: 27px; font-weight: 600; margin-top: 3px; }
.comparecard .v small { font-size: 13px; color: var(--ink-2); margin-left: 3px; }
.comparecard .delta { margin-top: 6px; font-size: 13px; font-weight: 600; }
.comparecard .delta.good { color: var(--export); }
.comparecard .delta.bad { color: var(--import); }
.comparecard .base { color: var(--ink-muted); font-size: 11px; margin-top: 2px; }

.balanceeq {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.eqterm {
  min-width: 145px;
  flex: 1 1 145px;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 12px 14px;
}
.eqterm.gap { border-color: var(--pumped); }
.eqterm .k { color: var(--ink-muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.eqterm .v { font-size: 22px; font-weight: 600; margin-top: 2px; }
.eqterm .v small { font-size: 12px; color: var(--ink-2); margin-left: 3px; }
.eqop { align-self: center; font-size: 22px; color: var(--ink-muted); }
.balanceMean { width: 100%; color: var(--ink-2); font-size: 12px; }

.subhead {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-muted);
  font-weight: 600;
  margin: 26px 0 12px;
}

.sparks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px 22px;
}

.spark .sh {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 3px;
}

.spark .sh .nm { color: var(--ink); }
.spark .sh .val { margin-left: auto; color: var(--ink-2); font-variant-numeric: tabular-nums; font-weight: 600; }
.spark .sh .val.imp { color: var(--import); }
.spark .sh .val.exp { color: var(--export); }
.spark svg { width: 100%; display: block; }

.flowkey { display: flex; gap: 18px; font-size: 13px; color: var(--ink-2); margin-bottom: 14px; }
.flowkey i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }

/* ── table view ─────────────────────────────────────────────────────── */

details { margin-top: 18px; }

summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--ink-2);
  padding: 5px 0;
}

table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
caption { text-align: left; font-size: 13px; color: var(--ink-muted); padding-bottom: 8px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--hairline); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-muted); font-weight: 600; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }

/* ── footer ─────────────────────────────────────────────────────────── */

footer {
  margin-top: 34px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.7;
}

footer a { color: var(--ink-2); }
footer p { margin: 0 0 9px; max-width: 76ch; }

.err {
  background: var(--surface);
  border: 1px solid var(--export);
  border-radius: var(--radius);
  padding: 18px 20px;
  color: var(--ink);
}

@media (max-width: 820px) {
  .mixlayout { grid-template-columns: minmax(0, 1fr); justify-items: center; }
  .mixlegends { width: 100%; }
}

@media (max-width: 560px) {
  .wrap { padding: 22px 14px 48px; }
  section { padding: 17px 15px; }
  .tile .v { font-size: 25px; }
  .sectionhead { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ── traced origin (Sankey) ─────────────────────────────────────────── */

#traceChart { min-width: 460px; }
#traceChart .sankeylabel { fill: var(--ink); font-size: 12px; font-weight: 500; }
#traceChart .sankeypct {
  fill: var(--ink-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
#traceChart path { transition: fill-opacity .12s; cursor: default; }

@media (prefers-reduced-motion: reduce) {
  #traceChart path { transition: none; }
}
