/* One-screen layout: the page itself never scrolls. Header and summary take
   their natural height; the board (code | details) fills what is left. */
:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #17202e;
  --muted: #5d6879;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --accent-text: #ffffff;
  --code-bg: #f7f8fa;
  --error-bg: #fdecec;
  --error-border: #f0a8a8;
  --ok: #16a34a;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --code-size: 13px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b22;
    --surface-2: #1e232c;
    --border: #2a313c;
    --text: #e6eaf0;
    --muted: #97a3b6;
    --accent: #6b9cff;
    --accent-soft: #1c2a47;
    --accent-text: #0b1020;
    --code-bg: #12161c;
    --error-bg: #33191b;
    --error-border: #7c3238;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 14.5px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ---------- header ---------- */
.topbar {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 14px;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 240px; }
.brand h1 { font-size: 16.5px; line-height: 1.3; margin: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status-dot[data-status="done"] { background: var(--ok); }
.status-dot[data-status="error"] { background: #e5484d; }
.status-dot[data-status="running"] { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.pagebar { display: flex; gap: 5px; flex: none; }
.chip {
  display: inline-block; padding: 0 8px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 12px; line-height: 1.7;
}
.actions { display: flex; align-items: center; gap: 6px; }
.status-text { color: var(--muted); font-size: 12.5px; margin-right: 4px; white-space: nowrap; }
button {
  font: inherit; font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .5; cursor: default; }

.steps { flex: none; list-style: none; display: flex; gap: 6px; margin: 0; padding: 8px 14px 0; font-size: 12px; color: var(--muted); }
.steps li { flex: 1; text-align: center; padding-top: 5px; border-top: 3px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.steps li.done { border-color: var(--ok); }
.steps li.active { border-color: var(--accent); color: var(--text); font-weight: 600; }

/* ---------- layout ---------- */
main { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 10px 14px 12px; }
.board { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); gap: 10px; }
.side { min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px 12px; min-width: 0; }
.card > h2 {
  margin: 0 0 6px; font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--accent);
}
.code-card { display: flex; flex-direction: column; min-height: 0; }
.code-card .body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.card.error { flex: none; background: var(--error-bg); border-color: var(--error-border); }
.card.error > h2 { font-size: 15px; letter-spacing: 0; text-transform: none; color: var(--text); margin: 0; }
.card.error pre { margin: 8px 0 0; max-height: 40vh; overflow: auto; }
.card.pending .body { display: grid; gap: 9px; align-content: start; }
.skeleton { height: 11px; border-radius: 6px; background: var(--border); animation: pulse 1.4s ease-in-out infinite; }
.skeleton:nth-child(2) { width: 85%; } .skeleton:nth-child(3) { width: 60%; }

/* ---------- audio mode ---------- */
.card.audio { flex: none; }
.card.gate { flex: none; max-width: 360px; margin: 40px auto; }
.gate-row { display: flex; gap: 8px; }
.gate-row input { flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.gate-error { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.audio-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.audio-icon { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.audio-icon.speaking { background: var(--accent); animation: pulse .9s ease-in-out infinite; }
.audio-text { flex: 1 1 200px; font-weight: 600; }
.audio-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

/* ---------- summary strip ---------- */
.summary {
  flex: none; display: grid; gap: 8px;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  border-radius: 10px; padding: 10px 12px;
}
.stats { display: grid; gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; min-width: 0; }
.stat-label { display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.stat-value { display: block; font-size: 14.5px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.stat-value.mono { font-family: var(--mono); font-size: 13.5px; }
.insight { margin: 0; font-size: 14px; }
.insight .md, .insight .md p { display: inline; margin: 0; }

/* ---------- details ---------- */
ol.steps-list { list-style: none; counter-reset: step; padding: 0; margin: 0; display: grid; gap: 5px; }
ol.steps-list > li { counter-increment: step; display: grid; grid-template-columns: 20px 1fr; gap: 8px; align-items: start; }
ol.steps-list > li::before {
  content: counter(step); display: grid; place-items: center; width: 19px; height: 19px; margin-top: 1px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700;
}
ul.tidy { margin: 0; padding-left: 18px; display: grid; gap: 2px; }
ul.tests { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
ul.tests li { border-left: 3px solid var(--border); padding-left: 8px; font-family: var(--mono); font-size: 12px; line-height: 1.45; overflow-wrap: anywhere; }
ul.tests .arrow { color: var(--accent); font-weight: 700; }
ul.tests .note { display: block; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--muted); font-size: 11.5px; }

.md p, .md ul, .md ol { margin: 0; }
a { color: var(--accent); text-decoration: none; }
code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
pre { margin: 0; font: var(--code-size)/1.45 var(--mono); tab-size: 4; }
pre.wrap { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12.5px; }
/* highlight.js makes the code element a scroll box; keep it inline so it can flow across columns. */
pre code, pre code.hljs { display: inline; overflow: visible; background: transparent; padding: 0; font-size: inherit; }

/* ---------- code ---------- */
.code-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--code-bg); }
.code-head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 3px 6px 3px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.code-lang { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.code-head button { padding: 1px 9px; font-size: 12px; }
.code-scroll { flex: 1; min-height: 0; overflow: auto; }
.code-scroll pre.code { padding: 8px 12px; white-space: pre; width: max-content; min-width: 100%; }
.code-scroll.wrap pre.code { white-space: pre-wrap; overflow-wrap: anywhere; width: auto; }
/* Long solutions: two newspaper-style columns (extra columns would overflow sideways, which fitCode detects). */
.code-scroll.cols pre.code {
  width: 100%; min-width: 0; column-count: 2; column-gap: 24px; column-fill: auto;
  column-rule: 1px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* Long solutions: code across the full width, compact details in a row underneath. */
.board.wide { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.board.wide .code-card { padding: 8px; }
.board.wide .code-card > h2 { display: none; }  /* the language bar already labels it */
.board.wide pre.code { line-height: 1.35; }
.board.wide .side { flex-direction: row; overflow: visible; font-size: 12.5px; line-height: 1.38; }
.board.wide .side > .card { flex: 1 1 0; padding: 7px 11px 9px; }
.board.wide .side > .card > h2 { margin-bottom: 4px; }
.board.wide ol.steps-list { gap: 3px; }
.board.wide ul.tests { gap: 4px; }
/* Keep the expected value visible; a long input is cut to one line (full text on hover). */
.board.wide ul.tests .in { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board.wide ul.tests .out { display: block; }
.board.wide ul.tests .note { display: none; }

/* ---------- non-coding answers: two columns of cards ---------- */
.panels { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 10px; }
.panels .col { min-height: 0; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.panels.dense { font-size: 13.5px; line-height: 1.4; }
.panels.dense .col { gap: 8px; }
.panels.dense .card { padding: 8px 12px 10px; }
.panels.denser { font-size: 12.5px; line-height: 1.35; }
dl.pairs { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0; }
dl.pairs dt { font-weight: 700; }
dl.pairs dd { margin: 0; }
.sublabel { display: block; margin: 6px 0 2px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.body > .sublabel:first-child { margin-top: 0; }
pre.example { background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Narrow or very short windows cannot hold two columns: stack and allow scrolling. */
@media (max-width: 680px), (max-height: 520px) {
  body { overflow: auto; height: auto; }
  main { flex: none; }
  .board, .board.wide, .panels { grid-template-columns: 1fr; grid-template-rows: auto; }
  .panels .col { overflow: visible; }
  .side, .board.wide .side { flex-direction: column; overflow: visible; }
  .stats { grid-template-columns: 1fr 1fr !important; }
  .status-text { display: none; }
}
