/* Local Model Explorer. Colour carries meaning: teal = GPU memory, amber = system RAM,
   violet = MoE experts kept in RAM, red = over capacity. */
:root {
  --ground: #eef2f5;
  --surface: #fbfcfd;
  --sunk: #e4e9ee;
  --ink: #16202b;
  --muted: #56616f;
  --line: #d3dae2;
  --gpu: #0c7c86;
  --gpu-soft: #cfe9eb;
  --ram: #a8680f;
  --ram-soft: #f1e2c8;
  --exp: #6c55c4;
  --no: #b42318;
  --ok: #17703a;
  --focus: #1d5fd1;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0d1217; --surface: #141b22; --sunk: #1b242d; --ink: #e3e9ef; --muted: #95a2af; --line: #26313c;
    --gpu: #36b3be; --gpu-soft: #12353a; --ram: #e0a445; --ram-soft: #3a2c14; --exp: #a390ec;
    --no: #f07b6f; --ok: #5cc486; --focus: #7aa7ff;
  }
}
:root[data-theme="dark"] {
  --ground: #0d1217; --surface: #141b22; --sunk: #1b242d; --ink: #e3e9ef; --muted: #95a2af; --line: #26313c;
  --gpu: #36b3be; --gpu-soft: #12353a; --ram: #e0a445; --ram-soft: #3a2c14; --exp: #a390ec;
  --no: #f07b6f; --ok: #5cc486; --focus: #7aa7ff;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: inherit; text-underline-offset: 3px; }
a:hover { color: var(--gpu); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
code, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
code { font-size: .88em; background: var(--sunk); padding: .05em .35em; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--surface); padding: 6px 10px; z-index: 10; }
[hidden] { display: none !important; }
.shell { max-width: 1240px; margin: 0 auto; padding-inline: 20px; }

/* header */
.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; letter-spacing: -.01em; }
.brand-mark { width: 32px; height: 20px; }
.fill-gpu { fill: var(--gpu); } .fill-ram { fill: var(--ram); }
.top nav { display: flex; gap: 18px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.top nav a { text-decoration: none; }

/* layout */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 28px; padding-block: 24px 40px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: minmax(0, 1fr); } }

/* rig panel */
.rig { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; position: sticky; top: 12px; }
@media (max-width: 860px) { .rig { position: static; } }
.rig h2 { font-size: 13px; text-transform: none; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field label, .seg legend { font-size: 13px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
select, input[type="number"], input[type="search"], textarea {
  font: inherit; color: var(--ink); background: var(--ground); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 9px; width: 100%; min-width: 0;
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }
select:hover, input:hover, textarea:hover { border-color: var(--muted); }
.seg { border: 0; padding: 0; margin: 0 0 12px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; }
.seg legend { margin-bottom: 4px; grid-column: 1 / -1; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: block; text-align: center; padding: 7px 4px; font-size: 13px; border: 1px solid var(--line); background: var(--ground); cursor: pointer; }
.seg label:first-of-type span { border-radius: 7px 0 0 7px; }
.seg label:last-of-type span { border-radius: 0 7px 7px 0; }
.seg label + label span { border-left: 0; }
.seg input:checked + span { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; cursor: pointer; }
.hint { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.capacity { display: flex; gap: 6px; margin: 2px 0 14px; font-size: 12.5px; }
.capacity .pool { flex: 1; border-radius: 7px; padding: 6px 8px; }
.capacity .pool b { display: block; font-family: var(--mono); font-size: 15px; }
.capacity .gpu { background: var(--gpu-soft); color: var(--gpu); }
.capacity .ram { background: var(--ram-soft); color: var(--ram); }

/* intro + filters */
.intro h1 { font-size: clamp(26px, 3.4vw, 38px); line-height: 1.1; letter-spacing: -.025em; margin: 0 0 8px; font-weight: 750; }
.intro p { color: var(--muted); max-width: 64ch; margin: 0 0 16px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters .field { margin: 0; }
.filters .grow { flex: 1 1 260px; }
.toggles { display: flex; gap: 14px; padding-left: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); margin: 14px 0 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 8px; border-radius: 2px; display: inline-block; }
.sw.gpu { background: var(--gpu); } .sw.exp { background: var(--exp); } .sw.ram { background: var(--ram); } .sw.over { background: var(--no); }
.notice { background: var(--ram-soft); color: var(--ink); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
.count { color: var(--muted); font-size: 13.5px; margin: 6px 0 10px; }

/* results */
.results { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.result { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 16px; }
.result:hover { border-color: var(--muted); }
.r-name { font-weight: 650; font-size: 16px; overflow-wrap: anywhere; }
.r-name button { all: unset; cursor: pointer; }
.r-name button:hover { color: var(--gpu); }
.r-name button:focus-visible { outline: 2px solid var(--focus); }
.r-meta { color: var(--muted); font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.tag { font-size: 11.5px; border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; color: var(--muted); }
.r-best { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center; }
.r-choice { font-size: 13.5px; overflow-wrap: anywhere; }
.r-choice .num { font-size: 13px; }
.fit { font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.fit.t-gpu, .fit.t-unified { background: var(--gpu-soft); color: var(--gpu); }
.fit.t-gpu_moe { background: color-mix(in srgb, var(--exp) 18%, transparent); color: var(--exp); }
.fit.t-partial, .fit.t-unified_tight { background: var(--ram-soft); color: var(--ram); }
.fit.t-cpu { background: var(--sunk); color: var(--muted); }
.fit.t-no, .fit.t-no_vram { background: color-mix(in srgb, var(--no) 14%, transparent); color: var(--no); }
.fit.t-est { font-weight: 500; }
.r-side { text-align: right; font-size: 13px; color: var(--muted); }
.r-side .score { font-family: var(--mono); font-size: 20px; color: var(--ink); line-height: 1; }

/* memory rail: two pools sized to the hardware, filled with what the quant needs */
.rail { display: flex; gap: 4px; height: 10px; margin-top: 2px; grid-column: 1 / -1; }
.pool { position: relative; background: var(--sunk); border-radius: 3px; overflow: hidden; min-width: 18px; }
.pool i { position: absolute; top: 0; bottom: 0; left: 0; }
.pool .gpu { background: var(--gpu); }
.pool .exp { background: var(--exp); }
.pool .ram { background: var(--ram); }
.pool .over { background: var(--no); right: 0; left: auto; }
.rail-cap { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); font-family: var(--mono); }

.more { text-align: center; margin-top: 14px; }
.btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn:disabled { opacity: .55; cursor: default; }
.score-why { margin: 0 0 14px; font-size: 14px; }
.score-why summary { cursor: pointer; color: var(--muted); }
.score-why ul { margin: 8px 0 4px; padding-left: 20px; }
.btn.small { font-size: 13px; padding: 4px 10px; margin-bottom: 12px; }
.icon-btn { font-size: 26px; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 8px; }

/* detail dialog */
dialog { width: min(1040px, calc(100vw - 24px)); max-height: calc(100vh - 24px); border: 1px solid var(--line);
  border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); }
dialog::backdrop { background: rgb(8 12 16 / .55); }
.d-head { position: sticky; top: 0; background: var(--surface); display: flex; justify-content: space-between; gap: 12px;
  padding: 16px 20px 12px; border-bottom: 1px solid var(--line); z-index: 2; }
.d-head h2 { margin: 0; font-size: 22px; letter-spacing: -.015em; overflow-wrap: anywhere; }
.d-kicker { margin: 0; font-size: 12.5px; color: var(--muted); }
.d-facts { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.d-body { padding: 16px 20px 24px; }
.d-body h3 { font-size: 15px; margin: 22px 0 8px; }
.d-body h3:first-child { margin-top: 0; }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 12.5px; background: var(--ground); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--ground); }
tbody tr[aria-selected="true"] { background: color-mix(in srgb, var(--gpu) 10%, transparent); }
td.num, th.num { text-align: right; }
td .rail { width: 160px; height: 8px; }
.cmd { background: var(--ink); color: var(--surface); border-radius: var(--radius); padding: 12px 14px; font-family: var(--mono);
  font-size: 13px; overflow-x: auto; white-space: pre; margin: 0; }
.cmd-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { font: inherit; font-size: 13px; background: none; border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--ink); }
.kv-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.kv-strip span { background: var(--ground); border: 1px solid var(--line); border-radius: 7px; padding: 3px 8px; font-size: 12.5px; }
.kv-strip b { font-family: var(--mono); font-weight: 600; }
.formats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.format { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 13.5px; }
.format h4 { margin: 0 0 4px; font-size: 14px; }
.format ul { margin: 4px 0 0; padding-left: 18px; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.panel .field { margin-bottom: 10px; }
.status { font-size: 13.5px; margin: 8px 0 0; }
.status.ok { color: var(--ok); } .status.err { color: var(--no); }
.muted { color: var(--muted); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 20px; color: var(--muted); }

/* about + footer */
.about { padding-block: 10px 30px; }
.about h2 { font-size: 20px; margin: 0 0 12px; }
.about-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 22px; }
.about h3 { font-size: 15px; margin: 0 0 6px; }
.about p { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.foot { border-top: 1px solid var(--line); padding-block: 16px 30px; font-size: 13px; color: var(--muted); display: flex; gap: 18px; flex-wrap: wrap; }

/* stats page */
.stats-hero { padding-block: 28px 12px; }
.stats-hero h1 { font-size: clamp(26px, 3.4vw, 36px); letter-spacing: -.02em; margin: 0 0 8px; }
.stats-hero p { color: var(--muted); max-width: 70ch; }
.totals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.total { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.total b { display: block; font-family: var(--mono); font-size: 24px; }
.total span { color: var(--muted); font-size: 13px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; padding-bottom: 30px; }
.chart { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.chart h2 { font-size: 15px; margin: 0 0 10px; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 13px; }
.bar .k { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .track { background: var(--sunk); height: 8px; border-radius: 3px; overflow: hidden; }
.bar .fill { background: var(--gpu); height: 100%; }
.bar .n { font-family: var(--mono); color: var(--muted); font-size: 12px; }
.scale-note { color: var(--muted); font-size: 13px; }

@media (prefers-reduced-motion: no-preference) {
  .pool i { transition: width .25s ease; }
}
@media (max-width: 520px) {
  .shell { padding-inline: 16px; }
  .result { grid-template-columns: minmax(0, 1fr); }
  .r-side { text-align: left; display: flex; gap: 12px; align-items: baseline; }
  .r-best { grid-template-columns: minmax(0, 1fr); }
  .d-body, .d-head { padding-inline: 14px; }
}
.about-grid code { white-space: nowrap; }
