/* willitrun — ratatui-style full-screen TUI theme */

:root {
  --bg: #0a0e13;
  --panel: #0d1319;
  --sel: #101b28;
  --border: #223041;
  --border-hi: #33475e;
  --text: #c8d3dd;
  --dim: #708499; /* keeps ≥4.5:1 (WCAG AA) on both --bg and --panel */
  --green: #54f08a;
  --amber: #ffb45e;
  --red: #ff5f56;
  --cyan: #5fd7ff;
  --magenta: #ff6ac1;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --chrome: #111a24; /* top/key bar background */
  color-scheme: dark;
}

/* light: paper-terminal palette (all pairs keep ≥4.5:1 on --bg/--panel) */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f2e8;
    --panel: #eee9dc;
    --sel: #e8e2d2;
    --border: #ccc3ae;
    --border-hi: #a89d82;
    --text: #35393f;
    --dim: #5c6470;
    --green: #14803c;
    --amber: #96660a;
    --red: #c22f26;
    --cyan: #0b6e8f;
    --magenta: #a5309f;
    --chrome: #ebe5d6;
    color-scheme: light;
  }
  .crt { opacity: 0.1; }
}

/* ---------- explicit themes (data-theme beats the auto media query) ---------- */

:root[data-theme="dark"] {
  --bg: #0a0e13; --panel: #0d1319; --sel: #101b28;
  --border: #223041; --border-hi: #33475e;
  --text: #c8d3dd; --dim: #708499;
  --green: #54f08a; --amber: #ffb45e; --red: #ff5f56;
  --cyan: #5fd7ff; --magenta: #ff6ac1;
  --chrome: #111a24;
  color-scheme: dark;
}
:root[data-theme="dark"] .crt { opacity: 0.3; }

:root[data-theme="light"] {
  --bg: #f6f2e8; --panel: #eee9dc; --sel: #e8e2d2;
  --border: #ccc3ae; --border-hi: #a89d82;
  --text: #35393f; --dim: #5c6470;
  --green: #14803c; --amber: #96660a; --red: #c22f26;
  --cyan: #0b6e8f; --magenta: #a5309f;
  --chrome: #ebe5d6;
  color-scheme: light;
}
:root[data-theme="light"] .crt { opacity: 0.1; }

/* green phosphor CRT — verdict red/amber kept for readability */
:root[data-theme="phosphor"] {
  --bg: #030a04; --panel: #07140a; --sel: #0b2211;
  --border: #155c28; --border-hi: #1f7a37;
  --text: #6dffa1; --dim: #3fae66;
  --green: #6dffa1; --amber: #ffd35e; --red: #ff6a5e;
  --cyan: #8affc0; --magenta: #d1ffdf;
  --chrome: #061107;
  color-scheme: dark;
}
:root[data-theme="phosphor"] .crt { opacity: 0.55; }

/* amber phosphor CRT */
:root[data-theme="amber"] {
  --bg: #0d0800; --panel: #161003; --sel: #241a06;
  --border: #4a3810; --border-hi: #63501d;
  --text: #ffb000; --dim: #b07c22;
  --green: #7ce38b; --amber: #ffd75e; --red: #ff6a5e;
  --cyan: #ffd075; --magenta: #ff9d45;
  --chrome: #120c02;
  color-scheme: dark;
}
:root[data-theme="amber"] .crt { opacity: 0.5; }

:root[data-theme="gruvbox"] {
  --bg: #1d2021; --panel: #282828; --sel: #32302f;
  --border: #504945; --border-hi: #665c54;
  --text: #ebdbb2; --dim: #a89984;
  --green: #b8bb26; --amber: #fabd2f; --red: #fb4934;
  --cyan: #83a598; --magenta: #d3869b;
  --chrome: #242627;
  color-scheme: dark;
}
:root[data-theme="gruvbox"] .crt { opacity: 0.25; }

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.32;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

::selection { background: var(--cyan); color: var(--bg); }

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }
.lorg { color: var(--magenta); font-weight: 600; } /* the maker pops */
.lslash { color: var(--dim); }
.lname { color: var(--cyan); }

/* subtle CRT scanlines */
.crt {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.13) 0 1px, transparent 1px 3px);
  opacity: 0.3;
}

/* ---------- top bar ---------- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  background: var(--chrome);
  border-bottom: 1px solid var(--border);
  padding: 0 0.6ch 0 0;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  min-height: 24px;
}
.topbar::-webkit-scrollbar { display: none; }

.tlogo {
  flex: none;
  background: var(--green);
  color: var(--bg);
  font-weight: 700;
  padding: 0.15rem 1ch;
  margin-right: 1ch;
}

.tsegs { display: flex; align-items: stretch; min-width: 0; align-self: stretch; }
.tseg {
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 0 1.1ch;
  border-right: 1px solid var(--border);
}
.tseg .sk { color: var(--cyan); }
.tseg .sk::after { content: ":"; color: var(--dim); }
.tseg .sv { color: var(--text); }
.tseg .sv.dim { color: var(--dim); }
.tseg .sv.ok { color: var(--green); }
.tright {
  margin-left: auto;
  align-self: stretch;
  border-right: 0;
  border-left: 1px solid var(--border);
  background: color-mix(in srgb, var(--green) 12%, transparent);
}

.tbtn {
  flex: none;
  align-self: stretch;
  background: transparent;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  color: var(--dim);
  font-size: 0.78rem;
  font-weight: 400;
  padding: 0 1.1ch;
  min-height: 0;
  cursor: pointer;
}
.tbtn::before, .tbtn::after { content: none; }
.tbtn:hover:not(:disabled) { background: var(--sel); color: var(--text); }

/* ---------- workspace: fixed OS-like pane grid ---------- */

.workspace {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 14px 8px 8px; /* extra top room: the ┤ TITLE ├ labels stick up ~0.7em above panel borders */
  display: grid;
  grid-template-columns: minmax(0, 6fr) minmax(0, 5fr) minmax(220px, 280px);
  /* row 1: check + specs · row 2: verdict + what-would-run-it · row 3: hub.
     row 2 can shrink below its content (panels scroll inside) so a short
     window squeezes it instead of pushing HUB off-screen */
  grid-template-rows: auto minmax(0, max-content) minmax(140px, 1fr);
  gap: 8px;
}
.panel-check { grid-column: 1 / 3; grid-row: 1; }
.panel-specs { grid-column: 3 / 4; grid-row: 1; }
.panel-runson { grid-column: 2 / 4; grid-row: 2; }

/* the main action card pops: green frame, green title block */
.panel-check {
  border-color: color-mix(in srgb, var(--green) 55%, var(--border));
}
.panel-check .panel-title { background: var(--green); }
.panel-verdict { grid-column: 1 / 2; grid-row: 2; }
.panel-trending { grid-column: 1 / -1; grid-row: 3; }

/* ---------- specs card ---------- */

.panel-specs { border-color: var(--border-hi); }
.specs { display: flex; flex-direction: column; gap: 0.06rem; }
.spec-hero { font-size: 0.82rem; font-weight: 700; margin-bottom: 0.1rem; }
.spec-hero .plat { color: var(--cyan); }
.spec { display: grid; grid-template-columns: 6ch minmax(0, 1fr); gap: 1ch; align-items: baseline; font-size: 0.72rem; }
.spec .k { color: var(--dim); font-weight: 400; font-size: 0.62rem; }
.spec .v { font-weight: 700; color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.spec .vsub { color: var(--dim); font-weight: 400; font-size: 0.62rem; }
.spec .v.ok { color: var(--green); }
.spec .v.warn { color: var(--amber); }
.spec-usable { margin-top: 0.15rem; padding-top: 0.18rem; border-top: 1px dashed var(--border); }
.spec-usable .v { font-size: 0.9rem; }
/* limited height: typical 6-quant verdicts fit without scrolling; long GGUF
   lists and short windows scroll internally instead of growing the panel */
.panel-verdict .pscroll, .panel-runson .pscroll { max-height: min(45dvh, 300px); }

.panel {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.6rem 0.55rem 0.45rem;
  background: var(--panel); /* flat contrast against the page background */
  /* keep scrollIntoView targets clear of the sticky topbar (mobile) */
  scroll-margin-top: 72px;
}
/* panels themselves must not clip — the ┤ TITLE ├ straddles the border.
   scrolling lives on an inner wrapper instead. */
.panel-verdict, .panel-trending, .panel-runson {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pscroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hi) transparent;
}

/* inverse-video title blocks, tmux-tab style: accent bg, page-dark text,
   flush with the panel's left border edge */
.panel-title {
  position: absolute;
  top: -0.85em;
  left: -1px;
  margin: 0;
  padding: 0.05rem 1ch;
  background: var(--cyan);
  color: var(--bg);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
}
.panel-specs .panel-title { background: var(--cyan); }
.panel-verdict .panel-title { background: var(--amber); }
.panel-runson .panel-title { background: var(--magenta); }
.panel-trending .panel-title { background: var(--text); }

/* ---------- inputs & controls ---------- */

select,
input[type="text"] {
  max-width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg); /* fields sit deeper than the card */
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0.14rem 0.4rem;
  min-height: 24px;
}
select:focus-visible,
input[type="text"]:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 1px solid var(--cyan);
  outline-offset: 1px;
}

button {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--green);
  background: transparent;
  border: 1px solid var(--green);
  border-radius: 0;
  padding: 0.14rem 0.7rem;
  min-height: 24px;
  cursor: pointer;
}
button::before { content: "[ "; color: var(--dim); }
button::after { content: " ]"; color: var(--dim); }
button:hover:not(:disabled) { background: var(--green); color: var(--bg); }
button:hover:not(:disabled)::before, button:hover:not(:disabled)::after { color: var(--bg); }
button:disabled { opacity: 0.5; cursor: wait; }

/* touch devices: bigger targets, 16px inputs so iOS doesn't zoom on focus */
@media (hover: none) and (pointer: coarse) {
  select, input[type="text"] { font-size: 16px; min-height: 44px; }
  button { min-height: 44px; }
  .tbtn { min-height: 36px; }
  .ttab { min-height: 36px; }
}

.model-row { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.model-row input { flex: 1 1 220px; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1ch;
  align-items: center;
  margin-top: 0.45rem;
}
.controls label {
  display: flex;
  align-items: center;
  gap: 0.7ch;
  color: var(--dim);
  font-size: 0.78rem;
}
.controls label + label::before { content: "│"; color: var(--border-hi); margin-right: 1ch; }

.memtest { font-size: 0.8rem; }
.memtest summary { cursor: pointer; color: var(--amber); list-style: none; }
.memtest summary::-webkit-details-marker { display: none; }
.memtest summary::before { content: "│ > "; color: var(--border-hi); }
.memtest[open] summary::before { content: "│ v "; }
.memtest button { margin: 0.35rem 0.6rem 0.15rem 0; }

.note { color: var(--dim); font-size: 0.75rem; margin: 0.3rem 0 0; overflow-wrap: anywhere; }
.dim { color: var(--dim); font-weight: 400; }
.error { color: var(--red); font-size: 0.8rem; margin: 0.3rem 0 0; overflow-wrap: anywhere; }
.error:empty { display: none; }
.error::before { content: "[!!] "; }

/* ---------- verdict: character-cell rows ---------- */

/* one ellipsized line + dashed rule, sized to mirror the runson panel's
   .phead so the quant rows in both panels line up */
.summary {
  position: sticky; /* pins while the quant rows scroll beneath it */
  top: 0;
  z-index: 1;
  background: var(--panel);
  margin: 0 0 0.3rem;
  padding-bottom: 0.32rem;
  border-bottom: 1px dashed var(--border);
  min-height: 22px;
  line-height: 22px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.summary::before { content: "[ok] "; color: var(--green); }
.help { color: var(--dim); cursor: help; }

.qrows { display: flex; flex-direction: column; }

/* one line per quant: NAME  SIZE  ████░░░░  NEED ✓ */
.qrow {
  display: grid;
  grid-template-columns: minmax(8ch, 13ch) 10ch max-content minmax(6ch, 1fr) 2ch;
  gap: 1ch;
  align-items: baseline;
  padding: 0.24rem 0.15rem;
  min-height: 27px;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}
.qrow:last-child { border-bottom: 0; }
.qrow:hover, .qrow.hl { background: var(--sel); }

.qname {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qsize { color: var(--dim); text-align: right; white-space: nowrap; }
.qwarn { color: var(--amber); }
.qneed { text-align: right; color: var(--text); white-space: nowrap; }

.cbar { letter-spacing: -0.5px; white-space: nowrap; }
.cfill.ok { color: var(--green); }
.cfill.warn { color: var(--amber); }
.cfill.over { color: var(--red); }
.cempty { color: var(--border-hi); }

.mark { font-weight: 700; text-align: center; }
.mark.ok { color: var(--green); }
.mark.warn { color: var(--amber); }
.mark.over { color: var(--red); }

/* "what would run it" hardware lines: QUANT  GPU  CLOUD↗ */
.runson { font-size: 0.76rem; }
.ron {
  display: grid;
  grid-template-columns: 11ch minmax(13ch, max-content) minmax(0, 1fr);
  gap: 1.2ch;
  align-items: baseline;
  color: var(--dim);
  padding: 0.24rem 0.15rem;
  min-height: 27px;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}
.ron:last-child { border-bottom: 0; }
.ron:hover, .ron.hl { background: var(--sel); }
.ron-q { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ron-gpu { color: var(--cyan); white-space: nowrap; }
.ron-cloud {
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: right;
}
.ron-cloud:hover { color: var(--cyan); }

/* specs sim picker */
.preset-row { margin-top: 0.3rem; padding-top: 0.25rem; border-top: 1px dashed var(--border); }
.preset-label { display: flex; align-items: center; gap: 1ch; color: var(--dim); font-size: 0.7rem; }
.preset-label select { flex: 1; min-width: 0; font-size: 11px; min-height: 22px; padding: 0.05rem 0.3rem; }
.sim-tag { font-size: 0.64rem; font-weight: 400; }

.notes { color: var(--dim); font-size: 0.64rem; line-height: 1.3; opacity: 0.85; padding-left: 0; margin: 0.5rem 0 0; list-style: none; }
.notes li { margin-bottom: 0.1rem; }
.notes li::before { content: "▸ "; color: var(--magenta); }

/* ---------- trending ---------- */

.phead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.2rem 1ch;
  margin: 0 0 0.3rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px dashed var(--border);
}
.phead .note { margin: 0; }

.ttabs { display: flex; }
.ttab {
  background: transparent;
  border: 1px solid var(--border);
  border-right: 0;
  border-radius: 0;
  color: var(--dim);
  padding: 0 1.2ch;
  min-height: 20px;
  font-size: 0.75rem;
  font-weight: 400;
  cursor: pointer;
}
.ttab:last-child { border-right: 1px solid var(--border); }
.ttab::before, .ttab::after { content: none; }
.ttab:hover:not(:disabled) { background: var(--sel); color: var(--text); }
.ttab.active, .ttab.active:hover:not(:disabled) {
  background: var(--cyan);
  border-color: var(--cyan);
  color: var(--bg);
}

.hub-search {
  min-height: 20px;
  padding: 0 0.6ch;
  font-size: 0.78rem;
  width: 24ch;
  flex: 1 1 12ch;
  max-width: 34ch;
}

.trows { display: flex; flex-direction: column; }

.trow {
  display: grid;
  grid-template-columns: 2ch minmax(0, 1fr) 6ch 8ch 12ch 2ch;
  gap: 1ch;
  align-items: center;
  width: 100%;
  padding: 0.2rem 0.15rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 400;
  color: var(--text);
  min-height: 26px;
  text-align: left;
  cursor: pointer;
}
.trow::before, .trow::after { content: none; }
.trow:last-child { border-bottom: 0; }
.trow:hover:not(:disabled) { background: var(--sel); color: var(--text); }
.trow.selected {
  background: var(--sel);
  box-shadow: inset 2px 0 0 var(--green);
}
.trow.cursor {
  background: var(--sel);
  box-shadow: inset 2px 0 0 var(--cyan);
}
.trow.selected .t-rank { color: var(--green); }
.trow:focus-visible { outline: 1px solid var(--cyan); outline-offset: -1px; }
.trow .t-rank { color: var(--dim); }
.trow .t-id { color: var(--cyan); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trow:hover:not(:disabled) .t-id { text-decoration: underline; }
.trow .t-params { color: var(--text); text-align: right; }
.trow .t-dl { color: var(--dim); text-align: right; white-space: nowrap; }
.trow .t-fit { text-align: right; white-space: nowrap; }
.trow .t-hf { color: var(--dim); text-align: center; }
.trow .t-hf:hover { color: var(--cyan); text-decoration: none; }
.trow .t-sub { grid-column: 2 / -1; color: var(--dim); font-size: 0.7rem; }
.t-fit.fit-yes { color: var(--green); }
.t-fit.fit-tight { color: var(--amber); }
.t-fit.fit-no { color: var(--red); }
.t-fit.fit-unknown { color: var(--dim); }

/* ---------- key bar (bottom) ---------- */

.keybar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 1.6ch;
  background: var(--chrome);
  border-top: 1px solid var(--border);
  padding: 0.16rem 1ch calc(0.16rem + env(safe-area-inset-bottom));
  font-size: 0.74rem;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  min-height: 22px;
}
.kb b { color: var(--amber); font-weight: 700; }
.kfill { flex: 1; }

/* ---------- narrow screens: stacked, page scroll ---------- */

@media (max-width: 760px) {
  body { height: auto; min-height: 100dvh; overflow: auto; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    flex-wrap: wrap;
    white-space: normal;
    row-gap: 0.05rem;
    padding-bottom: 0.1rem;
  }
  .tright { padding-right: max(0px, env(safe-area-inset-right)); }
  .workspace {
    padding: 14px
      max(8px, env(safe-area-inset-right))
      8px
      max(8px, env(safe-area-inset-left));
  }
  .workspace { display: flex; flex-direction: column; }
  .pscroll { overflow-y: visible; }
  .panel-verdict .pscroll { max-height: none; }
  .trow { grid-template-columns: 2ch minmax(0, 1fr) 6ch 12ch 2ch; }
  .trow .t-dl { display: none; }
  .model-row button { flex: 1 1 100%; }
  .memtest { flex-basis: 100%; }
  .memtest summary::before { content: "> "; }
  .memtest[open] summary::before { content: "v "; }
  .qrow { grid-template-columns: minmax(6ch, 9ch) 9ch max-content minmax(5ch, 1fr) 2ch; gap: 0.8ch; }
  .ron { grid-template-columns: 9ch minmax(0, 1fr); }
  .ron-cloud { grid-column: 1 / -1; text-align: left; }
  .kb { display: none; } /* keyboard hints are pointless on touch */
  .keybar { justify-content: center; }
}
