:root {
  color-scheme: light dark;
  --background: light-dark(#fcfcfa, #171b1a);
  --surface: light-dark(#ffffff, #222826);
  --text: light-dark(#182c28, #edf3ef);
  --muted: light-dark(#52645e, #b4c2bb);
  --line: light-dark(#d8dfd9, #42534a);
  --hover: light-dark(#edf2ec, #2e3a33);
  --capital: light-dark(#64ad83, #78b28e);
  --planning: var(--capital);
  --operating: light-dark(#c3e9a8, #d0edb5);
  --prohibited: light-dark(#efa4b1, #f1b5bf);
  --unresolved: light-dark(#c9d0d6, #aeb8b2);
  --focus: light-dark(#253e61, #b4d2ff);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--background);
}

/* Source identity is separate from the permitted-use fills.
   Light mode separates the warm and green families with neutral and wine hues;
   dark mode retains its original palette. Token names remain stable across themes. */
[data-source-color="blue"] { --source-color: light-dark(#1268d3, #53a9ff); }
[data-source-color="orange"] { --source-color: light-dark(#be5600, #ff9b45); }
[data-source-color="violet"] { --source-color: light-dark(#7836c4, #b68aff); }
[data-source-color="cyan"] { --source-color: light-dark(#007ea8, #35d2e2); }
[data-source-color="rose"] { --source-color: light-dark(#ba008a, #f879b7); }
[data-source-color="gold"] { --source-color: light-dark(#927000, #e8c45c); }
[data-source-color="teal"] { --source-color: light-dark(#176a23, #34d5ae); }
[data-source-color="coral"] { --source-color: light-dark(#26303f, #ff806c); }
[data-source-color="lime"] { --source-color: light-dark(#7f263b, #b4d85f); }
[data-source-color="lilac"] { --source-color: light-dark(#9f439e, #e7acfa); }
[data-source-color="silver"] { --source-color: light-dark(#596675, #c3cddd); }

* { box-sizing: border-box; }
:root[data-appearance="light"] { color-scheme: light; }
:root[data-appearance="dark"] { color-scheme: dark; }
body { margin: 0; }
main { max-width: 1220px; margin: 0 auto; padding: 22px 40px 30px; }
button, summary, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
button { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 9px 14px; }
button:hover { background: var(--hover); }
a { color: inherit; text-underline-offset: 3px; }
p { line-height: 1.5; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.8px; margin: 4px 0 5px; }
h2 { font-size: 22px; font-weight: 550; letter-spacing: -0.3px; }
h3 { font-size: 17px; font-weight: 600; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-bottom: 19px; border-bottom: 1px solid var(--line); }
.eyebrow { font-size: 13px; color: var(--muted); }
.text-button { background: transparent; border: 0; padding: 5px 0; text-decoration: underline; text-underline-offset: 4px; white-space: nowrap; }
.header-controls { display: grid; justify-items: end; gap: 12px; }
.appearance-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.appearance-control select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 5px; }
#breadcrumbs { display: flex; align-items: center; flex-wrap: wrap; min-height: 44px; gap: 10px; font-size: 13px; }
#breadcrumbs button { background: transparent; padding: 4px 0; border: 0; text-decoration: underline; text-underline-offset: 4px; }
#breadcrumbs .current { color: var(--muted); }
#breadcrumbs [data-source-color] { color: var(--source-color); }
.chart-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
#breadcrumbs[hidden] + .chart-heading { margin-top: 20px; }
.chart-heading[data-source-color] { border-left: 4px solid var(--source-color); padding-left: 12px; }
.chart-heading[data-source-color] h2 { color: var(--source-color); }
.amount-heading { text-align: right; white-space: nowrap; }
.amount-heading strong { font-size: 30px; font-weight: 550; letter-spacing: -0.6px; font-variant-numeric: tabular-nums; display: block; }
.amount-heading span { font-size: 12px; color: var(--muted); }
.explorer { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 26px; align-items: start; margin-top: 10px; }
figure { margin: 0; min-width: 0; }
#chart-container { width: 100%; height: min(46vw, 520px); min-height: 280px; position: relative; }
.pie-svg { display: block; width: 100%; height: 100%; overflow: visible; }
.sector { cursor: pointer; transition: opacity 120ms ease; }
.sector.is-muted { opacity: 0.28; }
.boundary-base, .boundary { fill: none; stroke-linejoin: round; pointer-events: none; }
.boundary-base { stroke: var(--background); stroke-width: 12; }
.boundary { stroke: var(--source-color); stroke-width: 8; }
.sector.is-active .boundary-base { stroke-width: 15; }
.sector.is-active .boundary { stroke-width: 11; }
.slice-number { fill: #ffffff; font-size: 13px; font-weight: 600; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.number-back { fill: light-dark(var(--source-color), #222a28); stroke: light-dark(#ffffff, var(--source-color)); stroke-width: 2.5; pointer-events: none; }
.leader { fill: none; stroke: var(--source-color); stroke-width: 1.5; pointer-events: none; }
.external-number { fill: var(--text); font-size: 13px; font-weight: 600; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.external-number[data-source-color] { fill: var(--source-color); }
.sector-label { fill: var(--text); stroke: var(--background); stroke-width: 3px; stroke-linejoin: round; paint-order: stroke; font-size: 13px; font-weight: 550; text-anchor: middle; pointer-events: none; }
.slice-panel { padding-top: 16px; }
#slice-list { margin: 0; padding: 0; list-style: none; }
#slice-list li { margin: 0; }
.slice-button { border: 0; background: transparent; border-radius: 5px; width: 100%; display: grid; grid-template-columns: 24px 1fr auto 10px; align-items: center; gap: 8px; padding: 4px 5px; text-align: left; min-height: 31px; }
.slice-button.is-active { background: var(--hover); }
.row-number { font-size: 11px; color: light-dark(#ffffff, var(--source-color)); background: light-dark(var(--source-color), transparent); border: 2px solid var(--source-color); width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.row-label { line-height: 1.2; font-size: 14px; }
.row-amount { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-arrow { color: var(--muted); }
.preview { min-height: 80px; margin-top: 13px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 13px; color: var(--muted); }
.preview:empty { visibility: hidden; }
.preview strong { color: var(--text); display: block; margin-bottom: 5px; font-weight: 600; }
.preview p { line-height: 1.4; }
.legend { border-top: 1px solid var(--line); padding-top: 20px; display: flex; gap: 12px 20px; flex-wrap: wrap; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch { flex-shrink: 0; display: inline-block; width: 22px; height: 14px; border-radius: 2px; }
.capital { background: var(--capital); }
.operating { background: var(--operating); }
.prohibited { background: var(--prohibited); }
.unresolved { background: var(--unresolved); }
.mixed-capital { background: repeating-linear-gradient(135deg, var(--capital) 0 13px, var(--prohibited) 13px 18px); }
.mixed-operating { background: repeating-linear-gradient(135deg, var(--operating) 0 13px, var(--prohibited) 13px 18px); }
.marker-key { display: flex; flex-wrap: wrap; gap: 10px 20px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.marker-key:empty { display: none; }
.marker-key strong { margin-right: 3px; color: var(--text); }
details { margin-top: 14px; font-size: 13px; }
summary { cursor: pointer; color: var(--muted); }
#dialog-content p { margin-bottom: 12px; }
#dialog-content ul { padding-left: 22px; }
#dialog-content li { margin-bottom: 9px; line-height: 1.5; }
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; max-width: 780px; width: calc(100% - 32px); padding: 26px; max-height: calc(100% - 40px); }
dialog::backdrop { background: #00000066; }
.dialog-header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; align-items: center; }
#dialog-content { font-size: 14px; line-height: 1.55; }
#dialog-content h3 { margin: 22px 0 10px; }
.source-links { padding-left: 20px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

@media (max-width: 850px) {
  main { padding: 25px 22px; }
  .explorer { grid-template-columns: minmax(0, 1fr) 270px; gap: 14px; }
  h1 { font-size: 28px; }
  .row-label { font-size: 13px; }
  .slice-button { gap: 5px; }
}

@media (max-width: 650px) {
  main { padding: 23px 17px; }
  .page-header { flex-wrap: wrap; gap: 12px; }
  .explorer { display: block; }
  .slice-panel { padding-top: 0; }
  #chart-container { max-width: 520px; margin: auto; height: auto; aspect-ratio: 1.08; }
  .chart-heading { gap: 8px; }
  h2 { font-size: 20px; }
  .amount-heading strong { font-size: 24px; }
  .row-label { font-size: 14px; }
  .slice-button { min-height: 44px; }
  .preview { min-height: 74px; }
  .legend { margin-top: 16px; gap: 12px; }
  .legend span { width: calc(50% - 6px); line-height: 1.35; }
}

@media (prefers-reduced-motion: reduce) {
  .sector { transition: none; }
}
