/* Thai AI Leaderboard. One 1180px column: compact masthead, a sticky section bar, an at-a-glance grid,
   then one card per task (title, one-line subtitle, tabs, chart, table on demand, caveats, method).
   Colours are tokens; dark mode is its own set of steps, not an automatic flip. */
:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --ink: #111827;
  --ink-2: #444c5a;
  --muted: #6b7280;
  --line: #e2e5eb;
  --grid: #eceef2;
  --axis: #c7ccd5;
  --accent: #2452c8;
  --accent-soft: #e8eefc;
  --open: #2a78d6;            /* categorical slot 1: open weights */
  --api: #eb6834;             /* categorical slot 2: hosted API */
  --ci: #111827;
  --good: #0a7d0a;
  --bad: #b42318;
  --heat-0: #f4f8fe; --heat-1: #cde2fb; --heat-2: #9ec5f4; --heat-3: #6da7ec; --heat-4: #3987e5; --heat-5: #256abf; --heat-6: #184f95;
  --heat-ink-low: #111827; --heat-ink-high: #ffffff;
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 12px;
  --step--1: 0.8125rem; --step-0: 0.9375rem; --step-1: 1.125rem; --step-2: 1.4rem; --step-3: 2.1rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c0f14; --surface: #141920; --surface-2: #1b212b; --ink: #eef1f5; --ink-2: #c2c8d2; --muted: #8d95a3;
    --line: #273040; --grid: #1f2733; --axis: #3a4558; --accent: #8fb0ff; --accent-soft: #1d2a48;
    --open: #3987e5; --api: #d95926; --ci: #eef1f5; --good: #4cc24c; --bad: #ff8a7a;
    --heat-0: #17202d; --heat-1: #1a2a42; --heat-2: #183a66; --heat-3: #1c5cab; --heat-4: #3a8be8; --heat-5: #6da7ec; --heat-6: #b7d3f6;
    --heat-ink-low: #eef1f5; --heat-ink-high: #0b0f14;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0f14; --surface: #141920; --surface-2: #1b212b; --ink: #eef1f5; --ink-2: #c2c8d2; --muted: #8d95a3;
  --line: #273040; --grid: #1f2733; --axis: #3a4558; --accent: #8fb0ff; --accent-soft: #1d2a48;
  --open: #3987e5; --api: #d95926; --ci: #eef1f5; --good: #4cc24c; --bad: #ff8a7a;
  --heat-0: #17202d; --heat-1: #1a2a42; --heat-2: #183a66; --heat-3: #1c5cab; --heat-4: #3a8be8; --heat-5: #6da7ec; --heat-6: #b7d3f6;
  --heat-ink-low: #eef1f5; --heat-ink-high: #0b0f14;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 64px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: var(--step-0); line-height: 1.55; }
a { color: var(--accent); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: 1180px; margin: 0 auto; padding-left: 16px; padding-right: 16px; }

/* ---------- site bar + masthead */
.sitebar { background: var(--surface); border-bottom: 1px solid var(--line); font-size: var(--step--1); }
.sitebar .wrap { display: flex; align-items: center; gap: 16px; padding-block: 8px; flex-wrap: wrap; }
.sitebar .brand { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
.sitebar .brand img { width: 26px; height: 26px; }
.sitebar nav { display: flex; gap: 14px; flex-wrap: wrap; }
.sitebar nav a { color: var(--ink-2); text-decoration: none; }
.sitebar nav a:hover { color: var(--accent); }
.sitebar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.theme-btn { font: inherit; font-size: var(--step--1); color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; cursor: pointer; }

.masthead { background: var(--surface); border-bottom: 1px solid var(--line); }
.masthead .wrap { padding-block: 22px 24px; display: grid; gap: 12px; }
.maintainers { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; color: var(--muted); font-size: var(--step--1); }
.maintainers .by { letter-spacing: 0.06em; text-transform: uppercase; font-size: 0.7rem; }
.maintainers b { color: var(--ink-2); font-weight: 600; }
.pill { font-size: 0.74rem; border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; color: var(--ink-2); background: var(--surface-2); white-space: nowrap; }
h1 { font-weight: 600; font-size: var(--step-3); line-height: 1.15; letter-spacing: -0.01em; }
h1 .th { display: block; font-size: var(--step-1); font-weight: 500; color: var(--muted); letter-spacing: 0; margin-top: 4px; }
.lede { color: var(--ink-2); max-width: 62rem; }
.disclosure { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; border: 1px solid var(--line); border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 10px; padding: 10px 14px; font-size: var(--step--1); color: var(--ink-2); max-width: 62rem; }
.disclosure strong { color: var(--ink); }
.disclosure .ico { font-weight: 700; color: var(--accent); }

/* ---------- sticky section bar */
.viewbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.viewbar .wrap { padding-block: 8px; display: flex; gap: 6px 16px; align-items: center; overflow-x: auto; scrollbar-width: thin; }
.viewbar a { color: var(--ink-2); text-decoration: none; font-size: var(--step--1); white-space: nowrap; }
.viewbar a:hover, .viewbar a.on { color: var(--accent); }

/* ---------- layout */
main .wrap { padding-block: 22px 56px; display: grid; gap: 22px; }
.group { display: grid; gap: 14px; scroll-margin-top: 56px; }
.group-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.group-head h2 { font-size: var(--step-1); font-weight: 600; }
.group-head .th { color: var(--muted); font-size: var(--step--1); }
.group-head .rule { flex: 1; height: 1px; background: var(--line); min-width: 40px; }

/* ---------- at a glance */
.glance { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 12px; }
.tile { display: grid; gap: 6px; align-content: start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; color: inherit; text-decoration: none; min-width: 0; }
.tile:hover { border-color: var(--accent); }
.tile .k { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.tile .t { font-weight: 600; line-height: 1.3; }
.tile .lead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: var(--step--1); color: var(--ink-2); }
.tile .lead b { color: var(--ink); font-weight: 600; font-size: 1.15rem; }
.tile .m { font-size: 0.78rem; color: var(--muted); }

/* ---------- cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: grid; gap: 12px; min-width: 0; scroll-margin-top: 56px; }
.card-head { display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: space-between; align-items: flex-start; }
.card-head > div:first-child { display: grid; gap: 3px; min-width: 0; flex: 1 1 340px; }
.card h3 { font-size: var(--step-2); font-weight: 600; line-height: 1.25; }
.card h3 .th { display: block; font-size: var(--step--1); font-weight: 500; color: var(--muted); margin-top: 2px; }
.sub { color: var(--muted); font-size: var(--step--1); }
.dir { display: inline-block; border-radius: 999px; padding: 0 8px; font-size: 0.74rem; font-weight: 600; border: 1px solid var(--line); color: var(--ink); background: var(--surface-2); white-space: nowrap; }
.sources { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 100%; }
.chip { font-size: 0.75rem; color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; text-decoration: none; white-space: nowrap; background: var(--surface); }
.chip:hover { color: var(--accent); border-color: var(--accent); }
.controls { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tab { font: inherit; font-size: var(--step--1); color: var(--ink-2); background: var(--surface-2); border: 1px solid transparent; border-radius: 999px; padding: 3px 12px; cursor: pointer; }
.tab:hover { border-color: var(--line); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--surface); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); font-size: var(--step--1); }
.seg span { padding: 3px 10px; color: var(--muted); border-right: 1px solid var(--line); }
.seg button { font: inherit; color: var(--ink-2); background: none; border: 0; border-left: 1px solid var(--line); padding: 3px 10px; cursor: pointer; }
.seg span + button { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: var(--step--1); color: var(--ink-2); align-items: center; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.sw.open { background: var(--open); }
.sw.api { background: var(--api); }
.sw.ci { width: 16px; height: 2px; background: var(--ci); position: relative; }
.badge { display: inline-block; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.03em; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); border-radius: 4px; padding: 0 5px; vertical-align: 1px; white-space: nowrap; }
.card-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; }
.btn-link { font: inherit; font-size: 0.78rem; color: var(--accent); background: none; border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; cursor: pointer; white-space: nowrap; }
.note { color: var(--muted); font-size: 0.8rem; }
.caveats { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 0.82rem; display: grid; gap: 3px; }
.caveats li::marker { color: var(--muted); }

/* ---------- bar chart (HTML) */
.bars { --name-w: 36%; position: relative; display: grid; gap: 2px; padding-bottom: 22px; }
.bars .gridlayer { position: absolute; top: 0; bottom: 22px; left: calc(var(--name-w) + 12px); right: 56px; pointer-events: none; }
.bars .gridlayer i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--grid); }
.bars .gridlayer i.zero { background: var(--axis); }
.bars .gridlayer b { position: absolute; bottom: -20px; transform: translateX(-50%); font-size: 11px; font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-row { display: grid; grid-template-columns: var(--name-w) 1fr; gap: 12px; align-items: center; min-height: 34px; border-radius: 6px; padding-right: 56px; position: relative; cursor: default; }
.bar-row:hover, .bar-row:focus-visible { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.bar-name { min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; padding: 4px 0 4px 6px; font-size: var(--step--1); line-height: 1.3; }
.bar-name a { color: var(--ink); text-decoration: none; }
.bar-name a:hover { color: var(--accent); text-decoration: underline; }
.bar-name .ours a { font-weight: 600; }
.bar-name .meta { color: var(--muted); font-size: 0.74rem; }
.bar-track { position: relative; height: 16px; }
.bar-fill { position: absolute; left: 0; top: 1px; height: 14px; border-radius: 0 4px 4px 0; background: var(--open); }
.bar-fill.api { background: var(--api); }
.bar-ci { position: absolute; top: 7px; height: 2px; background: var(--ci); opacity: 0.75; }
.bar-ci::before, .bar-ci::after { content: ""; position: absolute; top: -4px; width: 2px; height: 10px; background: var(--ci); }
.bar-ci::before { left: 0; } .bar-ci::after { right: 0; }
.bar-val { position: absolute; top: -2px; padding-left: 6px; font-size: 12px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-val.na { color: var(--muted); font-weight: 400; }
@media (max-width: 640px) {
  .bars { --name-w: 0px; }
  .bars .gridlayer { left: 0; }
  .bar-row { grid-template-columns: 1fr; gap: 0; padding: 4px 56px 6px 0; }
  .bar-name { padding-left: 0; }
}

/* ---------- tables */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 0.84rem; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
thead th { background: var(--surface-2); color: var(--ink-2); font-weight: 600; position: sticky; top: 0; vertical-align: bottom; }
thead th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
thead th[aria-sort="descending"] button::after { content: " ▾"; color: var(--accent); }
thead th[aria-sort="ascending"] button::after { content: " ▴"; color: var(--accent); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
thead th:first-child { background: var(--surface-2); z-index: 2; }
td.num { font-variant-numeric: tabular-nums; }
td .ci-txt { display: block; color: var(--muted); font-size: 0.7rem; font-weight: 400; }
td.best { font-weight: 700; }
td.hl { background: color-mix(in srgb, var(--accent-soft) 55%, transparent); }
th .colsub { display: block; font-weight: 400; color: var(--muted); font-size: 0.7rem; }
table.heat td.cell { color: var(--heat-ink-low); }
table.heat td.cell.light { color: var(--heat-ink-high); }
.heat-legend { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; color: var(--muted); }
.heat-legend .ramp { display: inline-flex; border-radius: 3px; overflow: hidden; }
.heat-legend .ramp i { width: 18px; height: 10px; display: block; }

/* verdicts carry an icon and a word, never colour alone */
.verdict { font-weight: 600; white-space: nowrap; }
.verdict.lead { color: var(--good); }
.verdict.loss { color: var(--bad); }
.verdict.tie { color: var(--ink-2); }

/* ---------- method + details */
details.method { border-top: 1px solid var(--line); padding-top: 10px; }
details.method summary { cursor: pointer; font-size: var(--step--1); color: var(--ink-2); font-weight: 600; }
details.method .body { display: grid; gap: 10px; padding-top: 10px; font-size: 0.84rem; color: var(--ink-2); }
details.method ul { margin: 0; padding-left: 18px; }
.faq { display: grid; gap: 8px; }
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details > *:not(summary) { margin-top: 8px; color: var(--ink-2); font-size: 0.9rem; }
.faq ul { margin: 8px 0 0; padding-left: 18px; }
.sec-title { font-size: var(--step-1); font-weight: 600; }

/* ---------- tooltip */
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,0.12); padding: 8px 10px; font-size: 0.8rem; max-width: 280px; }
.tip .v { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tip .s { color: var(--muted); }

footer { border-top: 1px solid var(--line); background: var(--surface); }
footer .wrap { padding-block: 22px 32px; display: grid; gap: 8px; font-size: var(--step--1); color: var(--muted); }
.loading { color: var(--muted); font-size: var(--step--1); }
.bar-name .rownote { flex-basis: 100%; color: var(--muted); font-size: 0.72rem; line-height: 1.3; }

/* grids must not grow to fit a wide table: the table scrolls inside .tbl-wrap instead */
main .wrap, .group, #sections, .card, .view, details.method .body { grid-template-columns: minmax(0, 1fr); }
.chip { white-space: normal; max-width: 100%; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .card { padding: 14px 14px; }
  .sources { justify-content: flex-start; }
  h1 { font-size: 1.7rem; }
}

/* ---------- head-to-head forest plot */
:root { --h2h-lead: #2a78d6; --h2h-loss: #e34948; --h2h-tie: #b9bec8; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --h2h-lead: #3987e5; --h2h-loss: #e66767; --h2h-tie: #556070; } }
:root[data-theme="dark"] { --h2h-lead: #3987e5; --h2h-loss: #e66767; --h2h-tie: #556070; }
.h2h { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.h2h-group { --name-w: 32%; display: grid; gap: 0; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 6px; }
.h2h-title { font-size: 0.85rem; font-weight: 600; color: var(--ink); padding: 2px 0 4px; }
.h2h-row { display: grid; grid-template-columns: var(--name-w) minmax(0, 1fr) 11.5rem; gap: 12px; align-items: center; min-height: 28px; border-radius: 6px; }
.h2h-row:not(.h2h-axis):hover, .h2h-row:focus-visible { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.h2h-name { font-size: var(--step--1); line-height: 1.3; padding-left: 4px; display: flex; flex-wrap: wrap; gap: 2px 6px; align-items: baseline; }
.h2h-name.ours { font-weight: 600; }
.h2h-track { position: relative; height: 16px; }
.h2h-zero { position: absolute; left: 50%; top: -6px; bottom: -6px; width: 1px; background: var(--axis); }
.h2h-bar { position: absolute; top: 3px; height: 10px; border-radius: 3px; background: var(--h2h-tie); }
.h2h-bar.lead { background: var(--h2h-lead); }
.h2h-bar.loss { background: var(--h2h-loss); }
.h2h-ci { top: 7px; }
.h2h-val { font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); }
.h2h-axis { min-height: 18px; }
.h2h-axis .h2h-track { height: 14px; }
.h2h-ax { position: absolute; top: 0; font-size: 11px; color: var(--muted); white-space: nowrap; }
.h2h-ax.l { left: 0; } .h2h-ax.r { right: 0; } .h2h-ax.c { left: 50%; transform: translateX(-50%); }
@media (max-width: 640px) {
  .h2h-row { grid-template-columns: minmax(0, 1fr) 8.2rem; grid-template-areas: "name name" "track val"; row-gap: 2px; column-gap: 8px; padding: 3px 0; }
  .h2h-val { white-space: normal; }
  .h2h-name { grid-area: name; padding-left: 0; }
  .h2h-row .h2h-track { grid-area: track; }
  .h2h-val { grid-area: val; }
  .h2h-axis { grid-template-areas: "track track"; }
  .h2h-axis > span:first-child, .h2h-axis > span:last-child { display: none; }
}

/* ---------- at a glance: scoreboard */
.glance { display: grid; grid-template-columns: minmax(0, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 0; }
.g-row { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1.25fr) minmax(0, 1fr) 1.5rem; gap: 16px; align-items: center; padding: 9px 16px; color: inherit; text-decoration: none; border-top: 1px solid var(--grid); }
a.g-row:hover, a.g-row:focus-visible { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.g-head { border-top: 0; padding-top: 6px; padding-bottom: 6px; font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.g-group { padding: 12px 16px 4px; font-size: 0.72rem; font-weight: 700; color: var(--accent); letter-spacing: 0.05em; text-transform: uppercase; border-top: 1px solid var(--line); }
.g-task { font-weight: 600; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.g-dir { font-weight: 400; font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.g-top { display: flex; align-items: baseline; gap: 6px; min-width: 0; font-size: var(--step--1); }
.g-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.g-name.ours { font-weight: 600; }
.g-val { margin-left: auto; font-size: 1rem; font-variant-numeric: tabular-nums; }
.g-none { color: var(--muted); font-style: italic; }
.g-wtl { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; }
.g-bar { display: flex; gap: 2px; width: 72px; height: 8px; flex: none; }
.g-bar i { display: block; height: 100%; border-radius: 4px; }
.g-bar i.lead { background: var(--h2h-lead); } .g-bar i.tie { background: var(--h2h-tie); } .g-bar i.loss { background: var(--h2h-loss); }
.g-n { white-space: nowrap; font-variant-numeric: tabular-nums; }
.g-go { color: var(--muted); text-align: right; }
@media (max-width: 720px) {
  .g-head { display: none; }
  .g-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "task go" "top top" "wtl wtl"; gap: 4px 8px; }
  .g-task { grid-area: task; } .g-top { grid-area: top; } .g-wtl { grid-area: wtl; } .g-go { grid-area: go; }
  .g-val { margin-left: 8px; }
}
