/* Colour tokens follow the validated dataviz reference palette.
   Carrier colours are listed in stack order (bottom to top), which is the
   reference slot order reversed; adjacent pairs pass the CVD and
   normal-vision checks in both modes. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;

  /* Technology colours. Checked on all pairs with the dataviz palette validator
     (2026-09-24): distinct hue families for coal (warm grey), gas (orange) and
     storage (magenta); the two winds are two shades of teal. */
  --c-coal: #5f564c;
  --c-nuclear: #4a3aa7;
  --c-onwind: #3fc49a;
  --c-storage: #d9489a;
  --c-solar: #eda100;
  --c-offwind: #00866f;
  --c-gas: #e0592a;
  --c-hydro: #2a78d6;
  --c-other_re: #6aa9f2;
  --c-other: #c9c7bf;
  /* Unserved demand: neutral ink, not a status colour, so it never reads as a series status. */
  --c-unserved: #2b2a28;

  /* Categorical palette for charts of sectors, fuels and branches (dataviz reference
     palette, 8 slots). Each chart's stacking order was checked with the palette
     validator in light and dark (2026-09-25): adjacent CVD dE >= 8, normal >= 15. */
  --k-1: #2a78d6; --k-2: #eb6834; --k-3: #1baf7a; --k-4: #eda100;
  --k-5: #e87ba4; --k-6: #008300; --k-7: #4a3aa7; --k-8: #e34948;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;

  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --c-coal: #b9b0a4;
    --c-nuclear: #9686dd;
    --c-onwind: #37ac81;
    --c-storage: #c5439c;
    --c-solar: #c6a01f;
    --c-offwind: #176f66;
    --c-gas: #da5700;
    --c-hydro: #1161de;
    --c-other_re: #6db8f0;
    --c-other: #44423f;
    --c-unserved: #ecebe4;
    --k-1: #3987e5; --k-2: #d95926; --k-3: #199e70; --k-4: #c98500;
    --k-5: #d55181; --k-6: #008300; --k-7: #9085e9; --k-8: #e66767;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --wash: rgba(255, 255, 255, 0.05);
  --accent: #3987e5;
  --c-coal: #b9b0a4;
  --c-nuclear: #9686dd;
  --c-onwind: #37ac81;
  --c-storage: #c5439c;
  --c-solar: #c6a01f;
  --c-offwind: #176f66;
  --c-gas: #da5700;
  --c-hydro: #1161de;
  --c-other_re: #6db8f0;
  --c-other: #44423f;
  --c-unserved: #ecebe4;
  --k-1: #3987e5; --k-2: #d95926; --k-3: #199e70; --k-4: #c98500;
  --k-5: #d55181; --k-6: #008300; --k-7: #9085e9; --k-8: #e66767;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 120px; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 var(--font);
}

a { color: var(--accent); }

.shell { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--page);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; }
.eyebrow { color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
h1 { margin: 2px 0 0; font-size: 22px; line-height: 1.25; }
h2 { margin: 0 0 12px; font-size: 19px; }
h3 { margin: 0; font-size: 15px; }

.toolbar { display: flex; align-items: center; gap: 8px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button, .ghost {
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  padding: 5px 10px;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--wash); color: var(--ink); font-weight: 600; }
.ghost { border: 1px solid var(--border); border-radius: 8px; }
.ghost:hover, .segmented button:hover { background: var(--wash); }

.tabs { display: flex; gap: 18px; overflow-x: auto; padding-top: 10px; }
.tabs a { color: var(--ink-2); text-decoration: none; padding: 4px 0 9px; font-size: 14px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }

.case-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 20px 0 10px; }
.case-bar label { font-weight: 600; font-size: 14px; }
select {
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  max-width: 100%;
}
.muted { color: var(--muted); font-size: 13px; }
.sub { margin: 2px 0 10px; color: var(--ink-2); font-size: 13px; }
.note { margin: 10px 0 4px; color: var(--ink-2); font-size: 13px; line-height: 1.55; }

.status-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14px;
}
.status .icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.status.good .icon { background: var(--good); }
.status.warning .icon { background: var(--warning); color: #0b0b0b; }
.status.critical .icon { background: var(--critical); }
.status b { font-weight: 600; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 26px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.tile .unit { font-size: 14px; font-weight: 400; color: var(--ink-2); margin-left: 3px; }
.tile .note { color: var(--muted); font-size: 12px; }

.section { margin-bottom: 34px; }
.grid { display: grid; gap: 14px; margin-bottom: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.section > .panel { margin-bottom: 14px; }
.chart { width: 100%; height: 320px; }
.chart.tall { height: 420px; }

details { margin-top: 8px; font-size: 13px; }
summary { cursor: pointer; color: var(--ink-2); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td:first-child { white-space: nowrap; }
#table-potential th, #table-cmp-params th { white-space: normal; }
#table-cmp-params td:last-child { color: var(--ink-2); min-width: 180px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--wash); }
tr.current { background: var(--wash); box-shadow: inset 3px 0 0 var(--accent); }
tr.selected { background: var(--wash); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.badge { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; }

.findings { margin: 0; padding-left: 18px; }
.findings li { margin-bottom: 8px; }

.footer { color: var(--muted); font-size: 12px; padding-bottom: 28px; }

@media (max-width: 760px) {
  .grid.two { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  .chart { height: 280px; }
  .chart.tall { height: 340px; }
}

/* (i) icon with a tooltip: opens on hover, keyboard focus, or tap (focus). */
.info {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  margin-left: 4px;
  border: 1px solid var(--axis);
  border-radius: 50%;
  color: var(--ink-2);
  font: italic 600 11px/1 Georgia, "Times New Roman", serif;
  vertical-align: 1px;
  cursor: help;
}
.info:hover, .info:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.info-tip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: -12px;
  width: max-content;
  max-width: min(360px, 80vw);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
  color: var(--ink);
  font: 400 13px/1.55 var(--font);
  text-align: left;
  white-space: normal;
  transition: opacity 0.12s ease;
}
.info-tip > span { display: block; }
.info-tip .tip-muted { margin-top: 8px; color: var(--ink-2); font-size: 12px; }
.info:hover .info-tip, .info:focus .info-tip, .info:focus-within .info-tip { visibility: visible; opacity: 1; }

/* Taiwan energy data page */
.intro { max-width: 860px; margin-top: 18px; font-size: 14px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; margin-bottom: 8px; }
.filters label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.filters .grow { flex: 1 1 220px; }
input[type="search"] {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; width: 100%;
}
.chip {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); font-size: 12px; color: var(--ink);
}
.chip-icon { font-weight: 700; font-size: 11px; }
.chip.good .chip-icon { color: var(--good); }
.chip.warning { border-color: var(--warning); }
.chip.warning .chip-icon { color: var(--ink); background: var(--warning); border-radius: 50%; width: 14px; height: 14px; display: inline-grid; place-items: center; font-size: 10px; }
.chip.neutral .chip-icon { color: var(--muted); }
.chip.use-used { border-color: var(--accent); }
.link-mark { margin-left: 4px; font-size: 11px; font-weight: 700; cursor: help; }
.link-mark.ok { color: var(--good); }
.link-mark.bad { color: var(--muted); }
td.note-cell { min-width: 220px; max-width: 420px; color: var(--ink-2); }

.download { align-self: end; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; text-decoration: none; }
.download:hover { background: var(--wash); }

.setup { margin-bottom: 22px; }
.setup summary { font-size: 14px; }
.setup .note { margin-top: 10px; }

/* Source line under a chart */
.sources { margin-top: 8px; font-size: 12px; color: var(--ink-2); }
.sources-label { font-weight: 600; margin-right: 4px; }
.sources ul { list-style: none; margin: 2px 0 0; padding: 0; }
.sources li { margin: 3px 0; line-height: 1.5; }
.sources .chip { font-size: 11px; padding: 0 6px; }

/* Sandbox */
.sandbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; margin-bottom: 26px; }
.levers { position: sticky; top: 112px; max-height: calc(100vh - 130px); overflow-y: auto; }
.levers h2 { margin: 0 0 4px; font-size: 18px; }
.lever-group { border: 0; border-top: 1px solid var(--border); margin: 10px 0 0; padding: 10px 0 0; }
.lever-group legend { font-weight: 600; font-size: 13px; padding: 0 6px 0 0; }
.lever { margin: 8px 0 12px; }
.lever-label { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--ink-2); }
.lever-label output { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lever input[type=range] { width: 100%; accent-color: var(--accent); min-height: 24px; }
.lever .check { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 4px 0; min-height: 24px; }
.lever-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.sb-main { min-width: 0; }
.match { margin-bottom: 12px; font-size: 14px; }
.match .note { margin: 6px 0 0; color: var(--ink-2); font-size: 13px; }
@media (max-width: 900px) {
  .sandbox { grid-template-columns: 1fr; }
  .levers { position: static; max-height: none; }
}

/* Uncertainty range under a sandbox number: the band spans the range, the dot is the central case. */
.range-bar { position: relative; height: 8px; margin: 6px 2px 2px; }
.range-fill { position: absolute; inset: 2px 0; border-radius: 4px; background: var(--grid); }
.range-dot { position: absolute; top: 0; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%;
             background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.unc-note { grid-column: 1 / -1; margin: 0; }

/* ---------- Text pages: home, challenges, about, request ---------- */
/* Bilingual text: both languages are in the HTML, the page language picks one. */
html:not([lang="zh-Hant"]) .t-zh { display: none; }
html[lang="zh-Hant"] .t-en { display: none; }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }

.hero { padding: 36px 0 24px; max-width: 820px; }
.hero-kicker { color: var(--accent); font-weight: 600; font-size: 14px; margin: 0 0 8px; }
.hero-title { font-size: 30px; line-height: 1.25; margin: 0 0 14px; }
.hero-lead { font-size: 17px; line-height: 1.6; color: var(--ink-2); margin: 0 0 20px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.button { display: inline-flex; align-items: center; min-height: 40px; padding: 8px 16px; border-radius: 8px;
          border: 1px solid var(--border); background: var(--surface); color: var(--ink); font: inherit;
          font-size: 15px; text-decoration: none; cursor: pointer; }
.button:hover { background: var(--wash); }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.button.primary:hover { filter: brightness(1.08); }
.button:disabled { opacity: 0.6; cursor: default; }
.source-line { margin: -14px 0 26px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
        color: var(--ink); text-decoration: none; }
.card:hover, .card:focus-visible { border-color: var(--accent); }
.card h3 { margin: 0 0 6px; font-size: 16px; color: var(--accent); }
.card p { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.55; }

.prose { max-width: 860px; padding-top: 24px; padding-bottom: 12px; }
.prose p, .prose li { line-height: 1.65; font-size: 15px; }
.prose h2 { margin-top: 28px; }
.lead { font-size: 17px; color: var(--ink-2); }
.challenge { border-top: 1px solid var(--border); padding: 18px 0 6px; }
.challenge h2 { display: flex; align-items: baseline; gap: 10px; margin: 0 0 8px; }
.challenge .num { display: inline-grid; place-items: center; min-width: 28px; height: 28px; border-radius: 50%;
                  background: var(--wash); color: var(--ink-2); font-size: 14px; }
.finding { background: var(--wash); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0; padding: 10px 12px; }
.src { color: var(--muted); font-size: 13px; }

.author { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 8px; }
.author h2 { margin: 0 0 4px; }
.author .role { margin: 0; font-weight: 600; }
.author .avatar { border-radius: 50%; flex: none; }
@media (max-width: 560px) { .author { flex-direction: column; } .hero-title { font-size: 24px; } }

.request-form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 600; }
.field-row .field { flex: 1 1 220px; }
.field input, .field textarea { font: inherit; font-weight: 400; color: var(--ink); background: var(--page);
                                border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; min-height: 40px; }
.field textarea { resize: vertical; }
.field input:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.field-row { display: flex; flex-wrap: wrap; gap: 14px; }
.request-form .check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.request-form .check input { margin-top: 4px; }
.scenario-box { background: var(--wash); border-radius: 8px; padding: 10px 14px; }
.scenario-box .label { margin: 0; font-weight: 600; font-size: 14px; }
.scenario-box ul { margin: 6px 0; padding-left: 18px; font-size: 14px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.lever-today { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }

/* Sandbox: the settings are not a computed scenario */
.match.inexact { border: 2px solid var(--critical); background: color-mix(in srgb, var(--critical) 8%, var(--surface)); }
.match-head { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
.match-head .icon { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
                    background: var(--critical); color: #fff; font-weight: 700; flex: none; }

/* Energy security: one radio option per line. */
#sec-controls .check { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; line-height: 1.35; }
#sec-controls .check input { margin-top: 2px; flex: none; }
#sec-table td:first-child { white-space: normal; min-width: 180px; }

/* Numbered source list (sector page) */
ol.refs { padding-left: 1.4em; }
ol.refs li { margin: 0 0 10px; overflow-wrap: anywhere; }
ol.refs .chip { margin-left: 4px; }

/* Model data page */
.tabs.inline { padding-top: 4px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.filters input[type=range] { width: 220px; accent-color: var(--accent); min-height: 24px; }
.filters input[type=search] { font: inherit; color: var(--ink); background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; min-height: 34px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--ink-2); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (max-width: 640px) { dl.kv { grid-template-columns: 1fr; } .filters input[type=range] { width: 100%; } }
#md-plant-table { max-height: 560px; overflow: auto; }
#md-plant-table thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
#md-cmp-table table + table { margin-top: 18px; }
#md-cmp-table td:first-child, #md-cost-table td:first-child { white-space: normal; min-width: 240px; max-width: 340px; }
#md-cmp-table td:last-child { min-width: 200px; }
#md-cmp-table th { white-space: normal; min-width: 70px; }
#md-plant-table td:last-child { min-width: 240px; }

/* Data origin tags: PyPSA-Earth default / Taiwan data / added in this fork (text always shown) */
.origin { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 12px; line-height: 1.4;
  color: var(--ink-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; margin: 1px 2px 1px 0; }
.origin::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.origin.o-pypsa-earth::before { background: var(--k-1); }
.origin.o-taiwan::before { background: var(--k-3); }
.origin.o-fork::before { background: var(--k-4); }
.origin-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin: 6px 0 10px; font-size: 13px; color: var(--ink-2); }
.origin-head { font-size: 0; vertical-align: middle; margin-left: 6px; }
.origin-head .origin { font-weight: 400; }
