:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --mast: #1c2b3a;
  --mast-ink: #f4f3ef;
  --mast-muted: #a9b4bf;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7a7873;
  --grid: #e7e6e0;
  --axis: #c3c2b7;
  --rule: rgba(11, 11, 11, 0.10);
  --focus: #1c5cab;
  --col: #c9c8c0;
  --col-active: #2b2b29;
  --up: #006300;
  --down: #b42727;
  --hover: rgba(11, 11, 11, 0.04);

  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s-other: #b5b3ab;

  --font: "IBM Plex Sans", "Noto Sans Khmer", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-kh: "Noto Sans Khmer", "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --mast: #0d1620;
    --mast-ink: #f0efec;
    --mast-muted: #8d99a6;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #96948d;
    --grid: #2c2c2a;
    --axis: #45453f;
    --rule: rgba(255, 255, 255, 0.10);
    --focus: #6da7ec;
    --col: #45453f;
    --col-active: #e6e5e0;
    --up: #3fbf3f;
    --down: #f07a7a;
    --hover: rgba(255, 255, 255, 0.05);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s-other: #5c5b57;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --mast: #0d1620;
  --mast-ink: #f0efec;
  --mast-muted: #8d99a6;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #96948d;
  --grid: #2c2c2a;
  --axis: #45453f;
  --rule: rgba(255, 255, 255, 0.10);
  --focus: #6da7ec;
  --col: #45453f;
  --col-active: #e6e5e0;
  --up: #3fbf3f;
  --down: #f07a7a;
  --hover: rgba(255, 255, 255, 0.05);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s-other: #5c5b57;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.kh, [lang="km"] { font-family: var(--font-kh); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* Masthead */
.masthead { background: var(--mast); color: var(--mast-ink); }
.masthead-inner {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 24px;
  padding-top: 36px; padding-bottom: 28px;
}
.eyebrow {
  font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--mast-muted); margin-bottom: 10px; font-weight: 500;
}
.masthead h1 { font-size: 30px; line-height: 1.15; font-weight: 600; letter-spacing: -0.01em; }
.lede { color: var(--mast-muted); margin-top: 8px; font-size: 15px; }
.link-btn {
  display: inline-block; white-space: nowrap; text-decoration: none;
  font-size: 13px; font-weight: 500; padding: 8px 14px; border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.28); color: var(--mast-ink);
}
.link-btn:hover { background: rgba(255, 255, 255, 0.08); }

/* Toolbar */
.toolbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--rule);
}
.toolbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px 28px;
  flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px;
}
.control { display: flex; align-items: center; gap: 10px; min-width: 0; }
.control-group { display: flex; gap: 24px; flex-wrap: wrap; }
.control-label { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; }

.year-tabs { display: flex; gap: 2px; }
.year-tabs button {
  border: 0; background: none; cursor: pointer;
  padding: 6px 9px; border-radius: 4px; font-size: 13px;
  font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.year-tabs button:hover { background: var(--hover); color: var(--ink); }
.year-tabs button[aria-selected="true"] { background: var(--col-active); color: var(--surface); font-weight: 600; }
.year-select-mobile { display: none; }

.segmented {
  display: inline-flex; border: 1px solid var(--rule); border-radius: 5px; padding: 2px; gap: 2px;
  background: var(--surface);
}
.segmented button {
  border: 0; background: none; cursor: pointer; font-size: 12.5px;
  padding: 4px 10px; border-radius: 3px; color: var(--ink-2); line-height: 1.4;
}
.segmented button:hover { color: var(--ink); background: var(--hover); }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }

.select, .search {
  border: 1px solid var(--rule); background: var(--surface); border-radius: 5px;
  padding: 6px 10px; font-size: 13.5px; min-width: 0; max-width: 100%;
}
.select { padding-right: 28px; }
.search { width: 260px; }

/* Layout */
main.wrap { padding-top: 24px; padding-bottom: 48px; }
.grid { display: grid; gap: 20px; margin-bottom: 20px; }
.grid > .panel { margin-bottom: 0; }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-1-1 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }

.panel {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px;
  padding: 20px 22px 22px; margin-bottom: 20px; min-width: 0;
}
.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px 16px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.panel-head > div:first-child { min-width: 0; flex: 1 1 260px; }
.panel h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.panel-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.footnote { font-size: 12.5px; color: var(--muted); margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--grid); }

/* KPIs */
.kpis {
  display: grid; grid-template-columns: 1.35fr 1fr 1fr 1fr;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px;
  margin-bottom: 20px;
}
.kpi { padding: 18px 22px 20px; border-left: 1px solid var(--grid); min-width: 0; }
.kpi:first-child { border-left: 0; }
.kpi-label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 6px; letter-spacing: -0.015em; }
.kpi:first-child .kpi-value { font-size: 40px; }
.kpi-value .unit { font-size: 0.55em; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.kpi-meta { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.kpi-name { font-size: 17px; font-weight: 600; line-height: 1.3; margin-top: 8px; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

/* Charts */
.chart { position: relative; width: 100%; }
.panel.fill { display: flex; flex-direction: column; }
.panel.fill > .chart { flex: 1 1 auto; min-height: 232px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: var(--font); fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .value-label { fill: var(--ink); font-weight: 600; font-size: 12px; }
.chart .crosshair { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:focus { outline: none; }
.chart .hit:focus-visible { stroke: var(--focus); stroke-width: 2; }
.chart .col { transition: fill 120ms ease; }
.chart .seg-group { transition: opacity 120ms ease; }
.chart.dim-others .seg-group:not(.on) { opacity: 0.35; }

.legend { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.legend li { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); }
.legend-label { max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

/* Movers */
.movers-group + .movers-group { margin-top: 18px; }
.movers-title { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.06em; }
.mover {
  display: grid; grid-template-columns: minmax(0, 1fr) 72px; gap: 4px 12px; align-items: center;
  padding: 6px 0; border-top: 1px solid var(--grid); cursor: pointer;
  background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left;
}
.mover:hover .mover-name { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--axis); }
.mover-name { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 7px; }
.mover-name span:last-child { overflow: hidden; text-overflow: ellipsis; }
.mover-val { font-size: 13px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.mover-bar { grid-column: 1 / -1; height: 4px; background: var(--surface-2); border-radius: 2px; position: relative; }
.mover-bar i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 2px; }
.empty { font-size: 13px; color: var(--muted); padding: 8px 0; }

/* Ranking */
.ranking { list-style: none; margin: 0; padding: 0; }
.rank-row {
  display: grid; grid-template-columns: 24px minmax(0, 190px) minmax(0, 1fr) 64px; gap: 10px; align-items: center;
  width: 100%; padding: 4px 6px; margin: 0 -6px; border: 0; background: none; cursor: pointer; text-align: left;
  border-radius: 4px; width: calc(100% + 12px);
}
.rank-row:hover { background: var(--hover); }
.rank-row[aria-current="true"] { background: var(--surface-2); }
.rank-row[aria-current="true"] .rank-name { color: var(--ink); font-weight: 600; }
.rank-n { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.rank-name { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-track { height: 14px; position: relative; }
.rank-track i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 3px 3px 0; min-width: 2px; }
.rank-val { font-size: 12.5px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* Profile */
.profile-head { margin-bottom: 12px; }
.profile-code { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.profile-name { font-size: 17px; font-weight: 600; line-height: 1.35; margin-top: 2px; }
.profile-full { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.profile-stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 16px 0 0; padding-top: 14px;
  border-top: 1px solid var(--grid);
}
.profile-stats div { min-width: 0; }
.profile-stats dt { font-size: 12px; color: var(--muted); }
.profile-stats dd { margin: 2px 0 0; font-size: 16px; font-weight: 600; }

/* Table */
.table-scroll { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap; user-select: none;
}
.data-table th[data-sort] { cursor: pointer; }
.data-table th[data-sort]:hover { color: var(--ink); }
.data-table th[aria-sort]::after { content: ""; display: inline-block; margin-left: 5px; border: 4px solid transparent; vertical-align: middle; }
.data-table th[aria-sort="descending"]::after { border-top-color: currentColor; border-bottom: 0; }
.data-table th[aria-sort="ascending"]::after { border-bottom-color: currentColor; border-top: 0; }
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover td { background: var(--hover); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .code { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); }
.data-table .name-cell { min-width: 220px; }
.data-table .name-main { display: flex; align-items: center; gap: 8px; }
.data-table .name-full { font-size: 12px; color: var(--muted); margin-top: 2px; }
.data-table .na { color: var(--muted); }
.spark { display: block; }

/* Notes */
.notes { padding: 8px 2px 0; color: var(--ink-2); font-size: 13px; }
.notes h2 { font-size: 13px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.notes ul { margin: 0; padding-left: 18px; }
.notes li + li { margin-top: 3px; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 160px; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--rule);
  border-radius: 6px; padding: 10px 12px; font-size: 12.5px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
}
.tt-title { font-weight: 600; margin-bottom: 6px; line-height: 1.35; }
.tt-sub { color: var(--muted); font-size: 11.5px; margin-top: -4px; margin-bottom: 6px; }
.tt-row { display: grid; grid-template-columns: 12px auto minmax(0, 1fr); gap: 8px; align-items: center; padding: 1px 0; }
.tt-row .k { width: 12px; height: 2px; border-radius: 1px; }
.tt-row .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: left; }
.tt-row .l { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tt-line { color: var(--ink-2); }
.tt-line strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* Responsive */
@media (max-width: 1080px) {
  .year-tabs { display: none; }
  .year-select-mobile { display: block; }
}
@media (max-width: 960px) {
  .grid-2-1, .grid-1-1 { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--grid); }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .wrap { padding: 0 16px; }
  .masthead-inner { flex-direction: column; align-items: flex-start; padding-top: 24px; padding-bottom: 20px; gap: 16px; }
  .masthead h1 { font-size: 23px; }
  .lede { font-size: 14px; }
  .toolbar-inner { gap: 10px 16px; padding-top: 8px; padding-bottom: 8px; }
  .control-group { gap: 12px 16px; }
  .control-label { display: none; }
  main.wrap { padding-top: 16px; }
  .segmented button { padding: 4px 8px; }
  .toolbar-inner { flex-wrap: nowrap; }
  .control-group { flex-wrap: nowrap; gap: 8px; }
  .year-select-mobile { padding: 5px 24px 5px 8px; }
  .grid { gap: 14px; margin-bottom: 14px; }
  .panel { padding: 16px; margin-bottom: 14px; }
  .kpis { margin-bottom: 14px; }
  .kpi { padding: 14px 16px; }
  .kpi-value { font-size: 22px; }
  .kpi:first-child .kpi-value { font-size: 30px; }
  .kpi-name { font-size: 15px; }
  .rank-row { grid-template-columns: 20px minmax(0, 1fr) 58px; grid-template-rows: auto auto; row-gap: 3px; padding: 6px; }
  .rank-n { grid-row: 1; }
  .rank-name { grid-column: 2; grid-row: 1; }
  .rank-val { grid-column: 3; grid-row: 1; }
  .rank-track { grid-column: 2 / 4; grid-row: 2; height: 6px; }
  .profile-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search { width: 100%; }
  .table-scroll { margin: 0 -16px; padding: 0 16px; }
  .data-table .col-share, .data-table .col-years, .data-table .col-trend, .data-table .col-code { display: none; }
  .data-table th, .data-table td { padding-left: 6px; padding-right: 6px; }
  .data-table .name-cell { min-width: 0; }
  .data-table .name-full { display: none; }
}
@media (max-width: 400px) {
  .toolbar-inner { flex-wrap: wrap; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .kpi { border-left: 0 !important; }
  .kpi + .kpi { border-top: 1px solid var(--grid); }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
