/* Budżet Polski 2026 — Terra Cracovianum
   Light data-viz aesthetic. Categorical palette, tabular figures. */

:root {
  --bg: #FBFAF7;
  --surface: #FFFFFF;
  --ink: #1A1714;
  --ink-soft: #5A534B;
  --ink-faint: #8C857B;
  --line: rgba(26, 23, 20, 0.10);
  --line-strong: rgba(26, 23, 20, 0.18);
  --accent: #7C5C3E;            /* TC brown, used sparingly */
  --danger: #A32D2D;
  --radius: 10px;
  --radius-sm: 6px;
  --maxw: 1120px;

  /* motion — strong custom curves (built-in CSS easings are too weak) */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --dur-press: 140ms;
  --dur-ui: 200ms;
  --dur-enter: 320ms;

  /* warm-tinted elevation (paper aesthetic, not neutral black) */
  --shadow-sm: 0 1px 2px rgba(60, 50, 40, 0.04), 0 8px 24px -14px rgba(60, 50, 40, 0.10);
  --shadow-pop: 0 4px 18px rgba(60, 50, 40, 0.18);

  /* categorical ramp — grouped by spend theme */
  --c-social: #B5D4F4;  --c-social-ink: #0C447C;  --c-social-line: #378ADD;
  --c-transfer: #9FE1CB; --c-transfer-ink: #085041; --c-transfer-line: #1D9E75;
  --c-defense: #F5C4B3;  --c-defense-ink: #712B13;  --c-defense-line: #D85A30;
  --c-debt: #FAC775;     --c-debt-ink: #633806;     --c-debt-line: #EF9F27;
  --c-health: #F4C0D1;   --c-health-ink: #72243E;   --c-health-line: #D4537E;
  --c-edu: #C0DD97;      --c-edu-ink: #27500A;      --c-edu-line: #639922;
  --c-admin: #CECBF6;    --c-admin-ink: #3C3489;    --c-admin-line: #7F77DD;
  --c-infra: #D3D1C7;    --c-infra-ink: #444441;    --c-infra-line: #888780;
  --c-other: #E4E0D7;    --c-other-ink: #5A534B;    --c-other-line: #B4B2A9;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

/* ---------- Mobile bar list (treemap replacement) ---------- */
#tree-rest { display: none; }
.mbar {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "head head" "track pct";
  gap: 6px 10px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  margin: 0 0 8px;
  font: inherit;
  color: var(--ink);
  cursor: default;
}
button.mbar { cursor: pointer;
  transition: border-color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out); }
button.mbar:active { border-color: var(--line-strong); background: var(--bg); transform: scale(0.985); }
@media (hover: hover) and (pointer: fine) {
  button.mbar:hover { border-color: var(--line-strong); background: var(--bg); }
}
.mbar.is-drill .mbar-name { color: var(--ink); }
.mbar-head { grid-area: head; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.mbar-name { font-size: 14px; font-weight: 500; line-height: 1.3; }
.mbar-name i { font-size: 14px; color: var(--ink-faint); vertical-align: -1px; }
.mbar-amt { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mbar-track { grid-area: track; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; align-self: center; }
.mbar-fill { display: block; height: 100%; border-radius: 4px; }
.mbar-pct { grid-area: pct; font-size: 12px; color: var(--ink-faint); font-variant-numeric: tabular-nums; align-self: center; min-width: 40px; text-align: right; }
.mbar-rest { background: var(--bg); border-style: dashed; }
.mbar-tail { background: var(--bg); }

/* ---------- Header ---------- */
.masthead {
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.masthead .wrap {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; padding-top: 18px; padding-bottom: 18px; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-logo {
  height: 56px; width: auto; display: block; max-width: min(72vw, 360px);
}
@media (max-width: 760px) { .brand-logo { height: 44px; } }
.masthead-meta { font-size: 13px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* ---------- Hero ---------- */
.hero { padding: 56px 0 32px; position: relative; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(110% 75% at 12% -10%, rgba(124, 92, 62, 0.07), transparent 58%),
    radial-gradient(90% 70% at 100% 0%, rgba(55, 138, 221, 0.05), transparent 60%);
}
.hero .wrap { max-width: var(--maxw); position: relative; z-index: 1; }
.eyebrow {
  font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--accent); font-weight: 500; margin: 0 0 16px;
}
.hero h1 {
  font-size: clamp(34px, 6vw, 62px);
  line-height: 1.04; font-weight: 600; letter-spacing: -0.02em;
  margin: 0 0 20px; max-width: 16ch;
}
.hero h1 .amt { color: var(--accent); font-variant-numeric: tabular-nums; white-space: nowrap; }
.hero-lead { font-size: 18px; color: var(--ink-soft); max-width: 60ch; margin: 0; }

/* ---------- Stat band ---------- */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; margin: 40px 0 8px;
  box-shadow: var(--shadow-sm);
}
.stat { background: var(--surface); padding: 20px 22px; }
.stat-label { font-size: 13px; color: var(--ink-faint); margin: 0 0 8px; }
.stat-value {
  font-size: clamp(24px, 3.4vw, 34px); font-weight: 600; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums; line-height: 1; margin: 0;
}
.stat-value .unit { font-size: 14px; font-weight: 400; color: var(--ink-faint); margin-left: 4px; }
.stat-value.is-danger { color: var(--danger); }
.stat-foot { font-size: 12px; color: var(--ink-faint); margin: 8px 0 0; }

/* ---------- Controls ---------- */
.controls {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin: 44px 0 18px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 4px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 4px; box-shadow: var(--shadow-sm); }
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 14px; color: var(--ink-soft);
  padding: 8px 16px; border-radius: var(--radius-sm); display: flex; align-items: center; gap: 7px;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.tab:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .tab:hover { color: var(--ink); } }
.tab[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.tab i { font-size: 16px; }

.control-right { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.axis-toggle { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-soft); flex-wrap: wrap; }

/* ---------- Prominent year bar ---------- */
.year-bar-section { margin-top: 8px; }
.year-bar {
  display: flex; align-items: flex-start; gap: 16px; padding: 18px 22px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.year-bar-label { font-size: 15px; font-weight: 500; color: var(--ink); padding-top: 8px; white-space: nowrap; }
.year-bar-buttons { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.year-bar-buttons button {
  appearance: none; border: 1.5px solid var(--line-strong); background: var(--bg); cursor: pointer;
  font: inherit; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--ink-soft); padding: 8px 14px; border-radius: var(--radius-sm);
  transition: border-color var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out),
    background var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
  letter-spacing: -0.01em;
}
.year-bar-buttons button:active { transform: scale(0.96); }
@media (hover: hover) and (pointer: fine) {
  .year-bar-buttons button:hover { border-color: var(--accent); color: var(--ink); }
}
.year-bar-buttons button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
@media (max-width: 760px) {
  .year-bar { gap: 8px; flex-direction: column; align-items: stretch; }
  .year-bar-label { padding-top: 0; }
  .year-bar-buttons { gap: 5px; width: 100%; }
  .year-bar-buttons button { padding: 9px 0; font-size: 14px; flex: 1 1 calc(16.666% - 5px); min-width: 46px; }
}
.axis-toggle .seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.axis-toggle button {
  appearance: none; border: 0; background: var(--surface); cursor: pointer; font: inherit;
  font-size: 13px; color: var(--ink-soft); padding: 8px 14px;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.axis-toggle button:active { transform: scale(0.97); }
.axis-toggle button + button { border-left: 1px solid var(--line); }
.axis-toggle button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ---------- View panels ---------- */
.panel { display: none; }
.panel.is-active { display: block; }

/* breadcrumb */
.crumbs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 14px; color: var(--ink-soft); margin: 0 0 16px; min-height: 24px; }
.crumb { background: none; border: 0; padding: 0; font: inherit; color: var(--accent);
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: transform var(--dur-press) var(--ease-out); }
.crumb:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .crumb:hover { text-decoration: underline; } }
.crumb.is-current { color: var(--ink); cursor: default; }
.crumb.is-current:hover { text-decoration: none; }
.crumb-sep { color: var(--line-strong); font-size: 12px; }

/* treemap */
#treemap-wrap { position: relative; width: 100%; }
#treemap { width: 100%; display: block; }
.tile { cursor: pointer; transition: opacity var(--dur-ui) var(--ease-out); }
.tile rect { transition: stroke-width var(--dur-ui) var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
  .tile:hover { opacity: 1; }
  .tile:hover rect { stroke-width: 2.5; }
}
.tile-label { font-size: 13px; font-weight: 400; pointer-events: none; }
.tile-value { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; pointer-events: none; }
.tile-sub { font-size: 11px; pointer-events: none; }

/* tooltip */
.tt {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 12px; border-radius: 8px;
  font-size: 13px; line-height: 1.45; max-width: 280px; opacity: 0; transition: opacity 0.12s var(--ease-out);
  box-shadow: var(--shadow-pop);
}
.tt strong { font-weight: 600; }
.tt .tt-val { font-variant-numeric: tabular-nums; }
.tt .tt-share { color: #C9B79F; }

/* sankey */
#sankey-wrap { width: 100%; overflow: hidden; }
#sankey { width: 100%; display: block; }
.snode rect { cursor: default; }
.slabel { font-size: 12px; fill: var(--ink); }
.svalue { font-size: 11px; fill: var(--ink-faint); font-variant-numeric: tabular-nums; }
.slink { fill: none; transition: stroke-opacity var(--dur-ui) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .slink:hover { stroke-opacity: 0.55 !important; } }

/* type-breakdown bars */
.types { display: grid; gap: 14px; margin-top: 8px; }
.type-row { display: grid; grid-template-columns: 220px 1fr auto; align-items: center; gap: 16px; }
.type-name { font-size: 14px; color: var(--ink-soft); }
.type-bar-track { height: 22px; background: var(--c-other); border-radius: 4px; overflow: hidden; }
.type-bar-fill { height: 100%; border-radius: 4px; }
.type-amt { font-size: 14px; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 120px; text-align: right; }

/* legend */
.legend { display: flex; flex-wrap: wrap; gap: 12px 18px; margin: 18px 0 0; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-soft); }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

.hint { font-size: 13px; color: var(--ink-faint); margin: 14px 0 0; display: flex; align-items: center; gap: 7px; }
.hint i { font-size: 16px; }

/* ---------- Trends dashboard ---------- */
.trend-kpis { margin: 0 0 30px; }
.trend-section { margin: 0 0 34px; }
.trend-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin: 0 0 10px; }
.trend-h { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 10px; color: var(--ink); }
.trend-section-head .trend-h { margin: 0; }
.trend-legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0 0 12px; }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap svg { width: 100%; display: block; overflow: visible; touch-action: pan-y; }

/* segmented zł / % toggle (matches axis-toggle) */
.trend-toggle .seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.trend-toggle button {
  appearance: none; border: 0; background: var(--surface); cursor: pointer; font: inherit;
  font-size: 13px; color: var(--ink-soft); padding: 7px 13px;
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.trend-toggle button:active { transform: scale(0.97); }
.trend-toggle button + button { border-left: 1px solid var(--line); }
.trend-toggle button[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* category picker */
.cat-pick { font-size: 13px; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 8px; }
.cat-pick select {
  font: inherit; font-size: 13px; color: var(--ink); background-color: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 7px 32px 7px 11px;
  cursor: pointer; max-width: 230px; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238C857B' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
  transition: border-color var(--dur-ui) var(--ease-out);
}
.cat-pick select:hover { border-color: var(--accent); }

/* chart primitives */
.axis-label { font-size: 11px; fill: var(--ink-faint); font-variant-numeric: tabular-nums; }
.grid { stroke: var(--line); stroke-width: 1; }
.year-marker { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; opacity: 0.5; }
.focus-line { stroke: var(--ink-faint); stroke-width: 1; pointer-events: none; }
.tdot { pointer-events: none; }
.tseg { transition: opacity var(--dur-ui) var(--ease-out); }
.col-current { fill: none; stroke: var(--accent); stroke-width: 1.5; rx: 3; pointer-events: none; }

/* line-chart focus tooltip rows */
.tt-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.tt-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }

@media (max-width: 760px) {
  .trend-section-head { align-items: stretch; }
  .cat-pick { justify-content: space-between; width: 100%; }
  .cat-pick select { max-width: none; width: 100%; min-width: 0; flex: 1 1 auto; }
}

/* ---------- Trends toolbar (zł/% + ceny bieżące/stałe) ---------- */
.trend-toolbar { display: flex; flex-wrap: wrap; gap: 10px 14px; margin: 0 0 26px; }

/* ---------- Movers + tax bar lists (shared compact bar rows) ---------- */
.movers-pick { font-size: 13px; color: var(--ink-soft); display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.movers-pick select {
  font: inherit; font-size: 13px; color: var(--ink); background-color: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 6px 28px 6px 10px;
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238C857B' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat; background-position: right 8px center;
}
.cat-pick input[type="number"] {
  font: inherit; font-size: 13px; width: 130px; padding: 7px 11px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums; transition: border-color var(--dur-ui) var(--ease-out);
}
.cat-pick input[type="number"]:focus { outline: none; border-color: var(--accent); }

.movers { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 30px; }
.movers-h { font-size: 13px; font-weight: 600; letter-spacing: 0.01em; margin: 0 0 8px; }
.movers-h.is-up { color: var(--c-edu-ink); }
.movers-h.is-down { color: var(--danger); }
.mv-empty { color: var(--ink-faint); font-size: 13px; margin: 0; }

.taxbar, .mv-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 120px auto; align-items: center;
  gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line);
}
.taxbar:last-child, .mv-row:last-child { border-bottom: 0; }
.taxbar-name, .mv-name { font-size: 13px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.taxbar-track, .mv-track { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.taxbar-fill, .mv-fill { display: block; height: 100%; border-radius: 4px; transform-origin: left center; }
.taxbar-amt, .mv-amt { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.mv-pct { color: var(--ink-faint); font-weight: 400; }

@media (max-width: 760px) {
  .movers { grid-template-columns: 1fr; gap: 18px; }
  .taxbar, .mv-row {
    grid-template-columns: 1fr auto; grid-template-areas: "name amt" "track track"; gap: 4px 10px;
  }
  .taxbar-name, .mv-name { grid-area: name; }
  .taxbar-amt, .mv-amt { grid-area: amt; }
  .taxbar-track, .mv-track { grid-area: track; }
  .cat-pick input[type="number"] { width: 100%; flex: 1 1 auto; }
}

/* ---------- Plan vs wykonanie ---------- */
#exec-kpis { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { #exec-kpis { grid-template-columns: 1fr; } }
.exec-notice {
  color: var(--ink-soft); font-size: 14px; line-height: 1.55; margin: 8px 0 0;
  padding: 18px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.exec-pct.is-over { color: var(--c-edu-ink); }
.exec-pct.is-low { color: var(--danger); }

.exec-summary {
  margin: 6px 0 26px; padding: 16px 18px; font-size: 15px; line-height: 1.6; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--radius);
}
.exec-summary strong { font-weight: 600; }
.exec-delta { font-size: 12px; margin: 5px 0 0; color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.exec-delta.is-good { color: var(--c-edu-ink); }
.exec-delta.is-bad { color: var(--danger); }

/* paired plan vs wykonanie bars */
.planbars { display: grid; gap: 16px; }
.planbar-group { display: grid; gap: 4px; }
.planbar-label { font-size: 13px; font-weight: 500; color: var(--ink); }
.planbar-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; }
.planbar-track { height: 12px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.planbar-fill { display: block; height: 100%; border-radius: 4px; }
.planbar-fill.is-plan { background: var(--line-strong); }
.planbar-val { font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 104px; text-align: right; }

/* ---------- Dział detail (beta, 2025) — focus mode ---------- */
/* When a dział is open, hide the page chrome so the numbers take focus (logo stays). */
body.dzial-open .hero,
body.dzial-open .year-bar-section,
body.dzial-open .controls,
body.dzial-open #treemap-wrap,
body.dzial-open #legend,
body.dzial-open #tree-hint,
body.dzial-open #crumbs { display: none; }
body.dzial-open #panel-tree { padding-top: 8px; }

.dzial-detail { max-width: 760px; }
.dd-back {
  background: none; border: 0; padding: 8px 10px 8px 0; font: inherit; font-size: 14px; font-weight: 500;
  color: var(--accent); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: transform var(--dur-press) var(--ease-out), opacity var(--dur-ui) var(--ease-out);
}
.dd-back:active { transform: scale(0.97); }
.dd-back i { font-size: 17px; }
@media (hover: hover) and (pointer: fine) { .dd-back:hover { opacity: 0.7; } }

/* header — focused hero for the dział */
.dd-header { position: relative; padding: 14px 0 18px 18px; margin: 8px 0 26px; }
.dd-accent { position: absolute; left: 0; top: 4px; bottom: 4px; width: 4px; border-radius: 4px; }
.dd-eyebrow { font-size: 12px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--accent); font-weight: 500; margin: 0 0 8px; }
.dd-title { font-size: clamp(24px, 5vw, 36px); font-weight: 600; letter-spacing: -0.02em; line-height: 1.08; margin: 0 0 12px; max-width: 18ch; }
.dd-amount { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin: 0 0 6px; }
.dd-amount-num { font-size: clamp(26px, 5vw, 34px); font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.dd-amount-num .unit { font-size: 0.5em; font-weight: 400; color: var(--ink-faint); }
.dd-share {
  font-size: 13px; font-weight: 500; color: var(--accent); background: rgba(124, 92, 62, 0.09);
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.dd-meta { font-size: 13px; color: var(--ink-faint); margin: 0; font-variant-numeric: tabular-nums; }

.dd-h { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 4px; }
.dd-sub { font-size: 13px; color: var(--ink-soft); margin: 0 0 16px; max-width: 60ch; }

.dd-parts { margin: 0 0 18px; }
.dd-part { border-bottom: 1px solid var(--line); opacity: 0; animation: ddRowIn var(--dur-enter) var(--ease-out) forwards; animation-delay: calc(var(--i, 0) * 38ms); }
.dd-part:first-child { border-top: 1px solid var(--line); }
.dd-part > summary {
  list-style: none; cursor: pointer; padding: 12px 24px 12px 0; display: grid; gap: 7px; position: relative;
  transition: background var(--dur-ui) var(--ease-out);
}
.dd-part > summary::-webkit-details-marker { display: none; }
.dd-part > summary::after {
  content: "\203A"; position: absolute; right: 4px; top: 10px; font-size: 19px; color: var(--ink-faint);
  transition: transform var(--dur-ui) var(--ease-out);
}
.dd-part[open] > summary::after { transform: rotate(90deg); color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .dd-part > summary:hover { background: var(--bg); } }
.dd-part-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.dd-part-name { font-size: 14px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; }
.dd-code { color: var(--ink-faint); font-weight: 400; font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dd-part-amt { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dd-part-pct { color: var(--ink-faint); font-weight: 400; font-size: 12px; }
.dd-track { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.dd-fill { display: block; height: 100%; border-radius: 4px; transform-origin: left center; }
.dd-fill.dd-grow { animation: ddBarGrow var(--dur-enter) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 38ms + 80ms); }
.dd-roz-list { padding: 4px 0 14px 14px; margin: 2px 0 6px 1px; border-left: 2px solid var(--line); }
.dd-roz { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 13px; color: var(--ink-soft); }
.dd-roz-name { min-width: 0; }
.dd-roz-amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.dd-roz-pct { color: var(--ink-faint); margin-left: 4px; }
.dd-empty { color: var(--ink-faint); font-size: 13px; margin: 4px 0; }
.dd-note { margin-top: 18px; }

@keyframes ddRowIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ddBarGrow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

@media (prefers-reduced-motion: reduce) {
  .dd-part { opacity: 1; animation: none; }
  .dd-fill.dd-grow { animation: none; }
}
@media (max-width: 760px) {
  .dd-title { max-width: none; }
  .dd-header { padding-left: 14px; }
}

/* ---------- Footer ---------- */
.foot { border-top: 1px solid var(--line); margin-top: 64px; padding: 28px 0 56px; }
.foot .wrap { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-size: 13px; color: var(--ink-faint); }
.foot a { color: var(--accent); text-decoration: none; display: inline-block; padding: 4px 2px; font-weight: 500; }
@media (hover: hover) and (pointer: fine) { .foot a:hover { text-decoration: underline; } }

/* ---------- Loading / error ---------- */
.state { padding: 80px 0; text-align: center; color: var(--ink-faint); }
.state .spinner { width: 28px; height: 28px; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 16px;
  animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .controls { flex-direction: column; align-items: stretch; }
  .tabs { justify-content: center; flex-wrap: wrap; }
  .tab { flex: 1 1 auto; justify-content: center; }
  .axis-toggle { justify-content: space-between; }
  .type-row { grid-template-columns: 1fr; gap: 6px; }
  .type-amt { text-align: left; }
  .hero { padding: 36px 0 24px; }
  .hint { margin-top: 18px; }
  .tab { padding: 8px 12px; font-size: 13px; }
}

/* ---------- Entrance motion (first load) ---------- */
/* Elements tagged .anim-in start offset+transparent; .is-loaded on <body> releases
   them with a staggered delay. Only transform+opacity — GPU-friendly. */
.anim-in {
  opacity: 0;
  transform: translateY(10px);
}
body.is-loaded .anim-in {
  opacity: 1;
  transform: none;
  transition: opacity var(--dur-enter) var(--ease-out), transform var(--dur-enter) var(--ease-out);
  transition-delay: var(--anim-delay, 0ms);
}

/* Tab/view panel fade-in on activation */
.panel.fade-in { animation: panelIn var(--dur-ui) var(--ease-out) both; }
@keyframes panelIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* Year-change crossfade: blur masks the imperfect data swap */
.chart-swap { transition: opacity 150ms var(--ease-out), filter 150ms var(--ease-out); will-change: opacity, filter; }
.chart-swap.is-swapping { opacity: 0; filter: blur(2px); }

/* Mobile/type bar fills grow in from the left, staggered by row */
.mbar-fill, .type-bar-fill { transform-origin: left center; }
.mbar-fill.grow-in, .type-bar-fill.grow-in {
  animation: barGrow var(--dur-enter) var(--ease-out) both;
  animation-delay: var(--anim-delay, 0ms);
}
@keyframes barGrow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

@media (prefers-reduced-motion: reduce) {
  /* Reduced ≠ zero: keep opacity/color fades, drop movement and infinite motion. */
  *, *::before, *::after {
    animation-iteration-count: 1 !important;
  }
  .anim-in { transform: none !important; }
  body.is-loaded .anim-in { transition: opacity var(--dur-ui) var(--ease-out); }
  .panel.fade-in { animation: none !important; }
  .mbar-fill.grow-in, .type-bar-fill.grow-in { animation: none !important; }
  .chart-swap { transition: opacity 120ms var(--ease-out); }
  .chart-swap.is-swapping { filter: none; }
  .tab:active, .year-bar-buttons button:active, .axis-toggle button:active,
  .crumb:active, button.mbar:active { transform: none !important; }
  .spinner { animation: spin 1.2s linear infinite !important; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Tutorial: masthead button + video dialog ---------- */
.masthead-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.tut-btn {
  appearance: none; cursor: pointer; font: inherit; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px; border-radius: var(--radius-sm);
  color: var(--ink-soft); background: transparent; border: 1px solid var(--line-strong);
  transition: background var(--dur-ui) var(--ease-out), color var(--dur-ui) var(--ease-out),
              border-color var(--dur-ui) var(--ease-out), transform var(--dur-press) var(--ease-out);
}
.tut-btn i { font-size: 16px; color: var(--accent); }
.tut-btn:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) {
  .tut-btn:hover { color: var(--ink); border-color: var(--accent); background: var(--bg); }
}
@media (max-width: 560px) { .tut-btn-label { display: none; } .tut-btn { padding: 7px 9px; } }

.tut-dialog { border: 0; padding: 0; background: transparent; max-width: min(760px, 92vw); width: 100%; color: var(--ink); }
.tut-dialog::backdrop { background: rgba(26, 23, 20, 0.44); }
.tut-panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); padding: 22px 22px 18px; }
.tut-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.tut-title { font-size: 19px; font-weight: 600; margin: 0; line-height: 1.3; }
.tut-close { appearance: none; border: 0; background: transparent; cursor: pointer; color: var(--ink-faint);
  font-size: 20px; line-height: 1; padding: 4px; border-radius: var(--radius-sm); flex: none; display: inline-flex;
  transition: color var(--dur-ui) var(--ease-out), background var(--dur-ui) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .tut-close:hover { color: var(--ink); background: var(--bg); } }
.tut-lead { color: var(--ink-soft); font-size: 14px; margin: 0 0 14px; max-width: 62ch; }

/* 16:9 video area (poster or iframe) */
.tut-video { position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius-sm); overflow: hidden; }
@supports not (aspect-ratio: 16 / 9) { .tut-video { height: 0; padding-top: 56.25%; } }
.tut-iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* click-to-play poster */
.tut-play { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; background: #000; cursor: pointer; display: block; }
.tut-poster { width: 100%; height: 100%; object-fit: cover; display: block; }
.tut-play-icon { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 66px; height: 66px; border-radius: 50%; background: rgba(26, 23, 20, 0.72); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  transition: background var(--dur-ui) var(--ease-out), transform var(--dur-ui) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .tut-play:hover .tut-play-icon { background: var(--accent); transform: translate(-50%, -50%) scale(1.06); } }
.tut-play:active .tut-play-icon { transform: translate(-50%, -50%) scale(0.96); }

.tut-foot { margin: 12px 0 0; font-size: 13px; color: var(--ink-faint); }
.tut-yt-link { color: var(--accent); text-decoration: none; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.tut-yt-link i { font-size: 14px; }
@media (hover: hover) and (pointer: fine) { .tut-yt-link:hover { text-decoration: underline; } }

/* entrance */
.tut-dialog[open] .tut-panel { animation: tutIn var(--dur-enter) var(--ease-out) both; }
.tut-dialog[open]::backdrop { animation: tutBackdrop var(--dur-ui) var(--ease-out) both; }
@keyframes tutIn { from { opacity: 0; transform: translateY(12px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes tutBackdrop { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .tut-dialog[open] .tut-panel, .tut-dialog[open]::backdrop { animation: none !important; }
  .tut-btn:active { transform: none !important; }
}
