/* ============================================================
   looptrace — sage mist + ink + crimson tick.
   Crimson marks ONLY the currently-executing thing, so the eye
   follows execution. Light default; dark via data-theme or OS.
   ============================================================ */

:root {
  --bg:      #E3EAE0;   /* sage mist */
  --panel:   #F4F7F2;
  --panel2:  #EAEFE7;
  --ink:     #16171A;
  --muted:   #445747;   /* deep sage, AA on bg */
  --line:    #C2CEC0;
  --accent:  #C42847;   /* crimson (cooled from cherry) */
  --accent-ink: #FFFFFF;
  --accent-dim: rgba(196, 40, 71, 0.12);
  --ok:      #2F6C46;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --wrap: 1180px;
  --shadow: 0 14px 34px -22px rgba(22, 23, 26, 0.35);
}

:root[data-theme="dark"] {
  --bg:      #101211;   /* ink ground */
  --panel:   #191E1B;
  --panel2:  #141816;
  --ink:     #D9E4D6;   /* pale sage */
  --muted:   #9DB2A0;
  --line:    #2C342E;
  --accent:  #E8506B;   /* raspberry-crimson, lifted for dark */
  --accent-ink: #16171A;
  --accent-dim: rgba(232, 80, 107, 0.16);
  --ok:      #6FBE8C;
  --shadow: 0 14px 34px -22px rgba(0, 0, 0, 0.8);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg:      #101211;
    --panel:   #191E1B;
    --panel2:  #141816;
    --ink:     #D9E4D6;
    --muted:   #9DB2A0;
    --line:    #2C342E;
    --accent:  #E8506B;
    --accent-ink: #16171A;
    --accent-dim: rgba(232, 80, 107, 0.16);
    --ok:      #6FBE8C;
    --shadow: 0 14px 34px -22px rgba(0, 0, 0, 0.8);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.015em; line-height: 1.15; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--panel2); padding: 0.08em 0.35em; border-radius: 5px; }
a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent); }

.wrap { max-width: var(--wrap); margin: 0 auto; padding: 0 20px; }

/* ---------- a11y ---------- */
.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0; z-index: 50;
}
.skip-link:focus { left: 0; }

button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- hero ---------- */
.hero { padding: 26px 0 34px; border-bottom: 1px solid var(--line); }
.hero__top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 26px; }
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand__mark { width: 34px; height: 34px; color: var(--ink); }
.brand__dot { fill: var(--accent); }
.brand__name { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; }
.hero h1 { font-size: clamp(26px, 4.4vw, 44px); max-width: 21ch; }
.lede { margin-top: 16px; max-width: 68ch; color: var(--muted); font-size: 17px; }
.lede strong { color: var(--ink); }
.hero__badges { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 9px; }
.pill {
  border: 1px solid var(--line); background: var(--panel);
  padding: 5px 13px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted);
}

/* ---------- player layout ---------- */
.player {
  display: grid; grid-template-columns: 280px 1fr; gap: 22px;
  padding: 30px 0 10px;
}
@media (max-width: 900px) { .player { grid-template-columns: 1fr; } }

.panel-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.panel-sub { font-weight: 500; text-transform: none; letter-spacing: 0; opacity: 0.85; }
.mini-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 8px; }

/* picker */
.picker { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.picker__filters { display: flex; flex-wrap: wrap; gap: 6px; }
.filter {
  font: inherit; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 4px 11px; cursor: pointer;
}
.filter[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.picker__list { display: flex; flex-direction: column; gap: 4px; max-height: 560px; overflow-y: auto; padding-right: 4px; }
.snip {
  font: inherit; text-align: left; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--ink);
  border-radius: var(--radius-sm); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.snip:hover { background: var(--panel); }
.snip[aria-current="true"] { background: var(--panel); border-color: var(--line); box-shadow: inset 3px 0 0 var(--accent); }
.snip__title { font-weight: 600; font-size: 14px; line-height: 1.3; }
.snip__meta { font-size: 12px; color: var(--muted); font-family: var(--mono); }

/* stage */
.stage { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.stage__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.stage__title { font-size: 22px; }
.stage__meta { color: var(--muted); font-size: 13.5px; margin-top: 3px; font-family: var(--mono); }

/* ---------- the racetrack dial (motif) ---------- */
.dial { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px 6px; box-shadow: var(--shadow); }
.dial__svg { width: 100%; max-width: 560px; display: block; margin: 0 auto; }
.dial__track { fill: none; stroke: var(--ink); stroke-width: 3; opacity: 0.85; }
.dial__station circle { fill: var(--bg); stroke: var(--ink); stroke-width: 2.5; }
.dial__station text { font-family: var(--mono); font-size: 15px; fill: var(--muted); }
.dial__station.active circle { fill: var(--accent); stroke: var(--accent); }
.dial__station.active text { fill: var(--ink); font-weight: 700; }
.dial__dot { fill: var(--accent); stroke: var(--bg); stroke-width: 3; transition: cx 0.35s ease, cy 0.35s ease; }
.dial__dot.idle { opacity: 0.35; }
.dial__label { text-align: center; font-family: var(--mono); font-size: 13px; color: var(--muted); padding: 6px 0 8px; }

/* ---------- code box ---------- */
.codebox { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--panel); box-shadow: var(--shadow); }
.codebox__bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel2);
}
.codebox__lang { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.verified { font-size: 12px; color: var(--ok); font-weight: 600; }
.verified a { color: inherit; }
.codebox__pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  font-family: var(--mono); font-size: 13.5px; line-height: 1.6;
}
.codebox__pre code { background: none; padding: 0; font-size: inherit; }

/* ---------- predict-first ---------- */
.predict { border: 1px dashed var(--accent); border-radius: var(--radius); padding: 16px; background: var(--accent-dim); }
.predict__hint { color: var(--muted); font-size: 14px; margin-top: 6px; }
.predict__cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 14px; }
@media (max-width: 640px) { .predict__cols { grid-template-columns: 1fr; } }
.predict__pool { display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; }
.chip {
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--radius-sm); padding: 6px 10px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip:disabled { opacity: 0.35; cursor: default; }
.predict__choice { margin: 0; padding: 0 0 0 22px; display: flex; flex-direction: column; gap: 6px; min-height: 40px; }
.predict__choice li { font-family: var(--mono); font-size: 13px; }
.predict__choice .chip { margin-left: 4px; }
.predict__actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.predict__streak { font-size: 13.5px; font-weight: 600; color: var(--muted); }
/* Solid panel behind the verdict: the tinted predict background drops
   accent/ok text below 4.5:1 (3.83 light / 4.37 dark measured) — the
   verdict must sit on --panel, where both pass AA. */
.predict__result {
  margin-top: 10px; font-weight: 600;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 12px;
}
.predict__result:empty { display: none; }
.predict__result.good { color: var(--ok); }
.predict__result.bad { color: var(--accent); }

/* ---------- caption + panels ---------- */
.caption {
  min-height: 48px; padding: 12px 16px;
  border-left: 4px solid var(--accent);
  background: var(--panel); border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 15px;
}
.panels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 980px) { .panels { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .panels { grid-template-columns: 1fr; } }

.panel {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); padding: 12px; min-height: 190px;
  display: flex; flex-direction: column; gap: 10px;
}
.stack, .queue, .console { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.stack { flex-direction: column; justify-content: flex-end; flex: 1; }
.stack li, .queue li, .console li {
  font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 6px 9px; background: var(--panel2);
  overflow-wrap: anywhere;
}
.stack li.running {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 700;
}
.console li { border-style: dotted; }
.empty { color: var(--muted); font-family: var(--mono); font-size: 12px; border: none; background: none; padding: 6px 2px; }

/* ---------- controls ---------- */
.controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.btn {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 16px;
}
.btn:hover { border-color: var(--muted); }
.btn--accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--accent:hover { filter: brightness(0.94); border-color: var(--accent); }
.btn--ghost { background: transparent; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.controls__count { font-family: var(--mono); font-size: 13.5px; font-variant-numeric: tabular-nums; color: var(--muted); }
.controls__hint { font-size: 12.5px; color: var(--muted); }

.rulebox {
  font-size: 14.5px; color: var(--muted);
  border-top: 1px solid var(--line); padding-top: 12px;
}
.rulebox strong { color: var(--ink); }

.exports { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.exports__status { font-size: 13px; color: var(--ok); font-weight: 600; }
.exports__fallback textarea {
  width: 100%; font-family: var(--mono); font-size: 12px;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px;
}

/* ---------- prose sections ---------- */
.prose { padding: 38px 0 6px; max-width: 900px; }
.prose h2 { font-size: 24px; margin-bottom: 14px; }
.prose h3 { font-size: 16px; margin: 14px 0 8px; }
.prose ul { margin: 0; padding-left: 20px; color: var(--muted); }
.prose li { margin: 6px 0; }
.prose li strong, .prose p strong { color: var(--ink); }
.prose p { color: var(--muted); margin: 8px 0; }
.prose__cols { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
@media (max-width: 720px) { .prose__cols { grid-template-columns: 1fr; } }

.aside { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 22px 24px; margin-top: 30px; }
.aside__tag {
  display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--accent); border: 1px solid var(--accent); border-radius: 999px; padding: 3px 10px; margin-bottom: 10px;
}

.faq { margin: 0; }
.faq dt { font-weight: 700; margin-top: 16px; }
.faq dd { margin: 6px 0 0; color: var(--muted); }

/* ---------- footer ---------- */
.footer { border-top: 1px solid var(--line); margin-top: 44px; padding: 26px 0 40px; }
.footer p { color: var(--muted); font-size: 13.5px; max-width: 88ch; }
.footer strong { color: var(--ink); }
.footer__links { margin-top: 10px; }

/* ---------- print ---------- */
.printout { display: none; }
@media print {
  body * { visibility: hidden; }
  .printout, .printout * { visibility: visible; }
  .printout {
    display: block; position: absolute; inset: 0; padding: 10mm;
    color: #000; background: #fff; font-size: 11pt;
  }
  .printout pre { font-family: var(--mono); font-size: 9.5pt; white-space: pre-wrap; border: 1px solid #999; padding: 8px; }
  .printout table { border-collapse: collapse; width: 100%; font-size: 9pt; }
  .printout th, .printout td { border: 1px solid #999; padding: 3px 6px; text-align: left; font-family: var(--mono); }
  .printout h2 { font-size: 14pt; }
  .printout .printout__foot { margin-top: 10px; font-size: 8.5pt; color: #333; }
}
