:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0f1ed;
  --border: #dcded8;
  --grid: #e6e7e2;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #6b6a66;
  --brand: #0f6b46;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1ea;
  --focus: #2a78d6;
  --best: #2a78d6;
  --usual: #eb6834;
  --other: #c9cbc4;
  --range: #52514e;
  --mix-1: #eb6834; /* coal */
  --mix-2: #6250d6; /* gas & oil */
  --mix-3: #e87ba4; /* other fuels */
  --mix-4: #2a78d6; /* nuclear & hydro */
  --mix-5: #1baf7a; /* wind & solar */
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #353532;
    --grid: #2c2c2a;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #a3a29a;
    --brand: #3fb27f;
    --brand-ink: #0b1a12;
    --brand-soft: #1d3329;
    --focus: #6da7ec;
    --best: #3987e5;
    --usual: #d95926;
    --other: #4a4a46;
    --range: #c3c2b7;
    --mix-1: #d95926;
    --mix-2: #9085e9;
    --mix-3: #d55181;
    --mix-4: #3987e5;
    --mix-5: #199e70;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #353532; --grid: #2c2c2a;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #a3a29a; --brand: #3fb27f; --brand-ink: #0b1a12; --brand-soft: #1d3329;
  --focus: #6da7ec; --best: #3987e5; --usual: #d95926; --other: #4a4a46; --range: #c3c2b7;
  --mix-1: #d95926; --mix-2: #9085e9; --mix-3: #d55181; --mix-4: #3987e5; --mix-5: #199e70; --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--brand); }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { padding-top: 16px; padding-bottom: 16px; }
.brand { display: flex; gap: 12px; align-items: flex-start; }
.brand img { flex: none; margin-top: 2px; }
.brand h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.tagline { margin: 2px 0 0; color: var(--text-2); font-size: 15px; }

.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; padding-top: 20px; padding-bottom: 20px; align-items: start; }
@media (max-width: 900px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.results { display: grid; gap: 20px; min-width: 0; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.panel-title { font-size: 17px; margin: 0 0 4px; line-height: 1.3; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.panel h3 { font-size: 15px; margin: 20px 0 6px; }
.hint { color: var(--text-2); font-size: 14px; margin: 4px 0 0; }

.controls { position: sticky; top: 16px; }
@media (max-width: 900px) { .controls { position: static; } }
.field { margin: 14px 0 0; border: 0; padding: 0; min-width: 0; }
fieldset.field { margin-top: 16px; }
.field > label, legend { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; padding: 0; }
.unit { font-weight: 400; color: var(--text-3); }
select, input[type="number"] {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 40px;
}
select:hover, input[type="number"]:hover { border-color: var(--text-3); }
input:invalid { border-color: #d03b3b; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row2 .field { margin-top: 14px; }
.custom-window { margin-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; cursor: pointer; min-height: 36px;
}
.chip:hover { border-color: var(--text-3); }
.chip[aria-checked="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }

.seg { display: flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { flex: 1 1 auto; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 7px 8px; font-size: 14px; border-right: 1px solid var(--border); cursor: pointer; }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--brand-soft); color: var(--text); font-weight: 600; box-shadow: inset 0 -2px 0 var(--brand); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

.finder { margin-top: 8px; font-size: 14px; }
.finder summary { cursor: pointer; color: var(--brand); }
.finder select { margin-top: 8px; }
.state-out { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.state-out p { margin: 0; width: 100%; color: var(--text-2); }

.hero { border-color: var(--brand); border-width: 1px; }
.hero:focus { outline: none; }
.eyebrow { margin: 0; font-size: 14px; color: var(--text-2); font-weight: 600; }
.hero-time { margin: 2px 0 0; font-size: 52px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; }
.hero-sub { margin: 6px 0 0; color: var(--text-2); }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
@media (max-width: 620px) { .tiles { grid-template-columns: minmax(0, 1fr); } .hero-time { font-size: 44px; } }
.tile { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.tile-label { margin: 0; font-size: 13px; color: var(--text-2); font-weight: 600; }
.tile-value { margin: 2px 0 0; font-size: 24px; font-weight: 650; line-height: 1.2; }
.tile-note { margin: 4px 0 0; font-size: 13px; color: var(--text-2); }
.summary { margin: 16px 0 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.btn {
  font: inherit; font-size: 15px; border-radius: 8px; padding: 9px 14px; cursor: pointer; min-height: 40px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.status { font-size: 14px; color: var(--text-2); }
.link-btn { font: inherit; font-size: 14px; background: none; border: 0; color: var(--brand); cursor: pointer; padding: 4px 0; text-decoration: underline; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 12px 0 4px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.key-best { background: var(--best); }
.key-usual { background: var(--usual); }
.key-other { background: var(--other); }
.key-range { width: 2px; height: 14px; border-radius: 0; background: var(--range); }

.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text, .chart .lbl { fill: var(--text-3); font-size: 11px; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .bar { transition: opacity .15s; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.col:hover .bar { opacity: .8; }
.chart .whisker { stroke: var(--range); stroke-width: 1.5; }
.chart .annot { fill: var(--text); font-size: 12px; font-weight: 600; }

.tooltip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  max-width: 240px;
}
.tooltip strong { font-size: 15px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-key { width: 10px; height: 2px; display: inline-block; }

.table-scroll { overflow-x: auto; margin-top: 10px; }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th { color: var(--text-2); font-weight: 600; font-size: 13px; }
table.data tr.current td { background: var(--brand-soft); font-weight: 600; }
#hour-table-wrap, #mix-table-wrap { overflow-x: auto; margin-top: 10px; }

.method .steps, .method ul { padding-left: 20px; margin: 8px 0 0; }
.method li { margin: 6px 0; }
.method .limits li, .method .assumptions li, .method .provenance li { font-size: 15px; }
.provenance code { font-size: 13px; word-break: break-all; }

.foot { color: var(--text-2); font-size: 13px; padding-bottom: 32px; }
.foot p { margin: 0; max-width: 820px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .controls, .actions, .link-btn { display: none; } .layout { display: block; } }
