/* style.css */
:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0e12;
  --bg-2: #12141b;
  --fg: #e8eadf;
  --muted: #9aa193;
  --accent: #5ac4b0;
  --accent-2: #e2b15a;
  --card: #16181f;
  --line: rgba(232, 234, 223, 0.1);
  --danger: #e07a6a;
  --ok: #7dce8a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "IBM Plex Sans", sans-serif;
  --serif: ui-serif, Georgia, "Times New Roman", "Fraunces", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "IBM Plex Mono", monospace;
  --radius: 16px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4efe4;
  --bg-2: #ece4d4;
  --fg: #1c1a16;
  --muted: #5f5a50;
  --accent: #0f7f72;
  --accent-2: #b4741e;
  --card: #fffaf1;
  --line: rgba(28, 26, 22, 0.12);
  --danger: #c45b4c;
  --ok: #2f8a48;
  --shadow: 0 12px 32px rgba(80, 60, 20, 0.12);
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]):not([data-theme="light"]) {
    color-scheme: light;
    --bg: #f4efe4;
    --bg-2: #ece4d4;
    --fg: #1c1a16;
    --muted: #5f5a50;
    --accent: #0f7f72;
    --accent-2: #b4741e;
    --card: #fffaf1;
    --line: rgba(28, 26, 22, 0.12);
    --danger: #c45b4c;
    --ok: #2f8a48;
    --shadow: 0 12px 32px rgba(80, 60, 20, 0.12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(90, 196, 176, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(226, 177, 90, 0.07), transparent 45%),
    var(--bg);
  color: var(--fg);
  line-height: 1.55;
  min-height: 100dvh;
}

.skip {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--accent);
  color: #0c0e12;
  padding: 8px 12px;
  z-index: 9;
}
.skip:focus { left: 8px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 8px;
  max-width: 1080px;
  margin: 0 auto;
}
.brand { display: flex; gap: 12px; align-items: center; }
.mark {
  width: 42px; height: 42px; border-radius: 12px;
  background:
    linear-gradient(135deg, var(--accent), transparent 60%),
    repeating-linear-gradient(90deg, var(--accent-2) 0 3px, transparent 3px 7px);
  box-shadow: inset 0 0 0 1px var(--line);
  flex: 0 0 auto;
}
.kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 10px;
  color: var(--muted);
}
h1 {
  font-family: var(--serif);
  font-size: 1.15rem;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.top-actions { display: flex; gap: 8px; }

.icon-btn, .btn, .chip, .choice {
  min-height: 44px;
  min-width: 44px;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  color: var(--fg);
}
.icon-btn {
  display: grid;
  place-items: center;
  background: var(--card);
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.icon-btn img { display: block; filter: invert(0.92); }
html[data-theme="light"] .icon-btn img { filter: none; }
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .icon-btn img { filter: none; }
}
.icon-btn.is-off { opacity: 0.45; }

.theme-glyph {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: inset -5px -3px 0 0 var(--fg);
  display: block;
}
html[data-theme="light"] .theme-glyph,
html[data-theme="light"] #btn-theme.is-light .theme-glyph {
  box-shadow: none;
  background:
    radial-gradient(circle at 32% 32%, #fff6d2 0 28%, var(--accent-2) 29% 100%);
}
@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) .theme-glyph {
    box-shadow: none;
    background:
      radial-gradient(circle at 32% 32%, #fff6d2 0 28%, var(--accent-2) 29% 100%);
  }
}

.chapters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 16px 12px;
  max-width: 1080px;
  margin: 0 auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.chip {
  flex: 0 0 auto;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 0.92rem;
  font-weight: 600;
}
.chip.is-active {
  background: var(--accent);
  color: #0c0e12;
  box-shadow: none;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 16px 48px;
}
.panel { animation: in 0.35s ease; }
@keyframes in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 11px;
  color: var(--accent);
  margin: 8px 0 0;
  font-weight: 600;
}
h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.6rem, 4vw, 2.35rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 6px 0 12px;
}
.lede { font-size: 1.05rem; color: var(--fg); max-width: 62ch; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

.hero-art {
  margin: 0 0 16px;
  border-radius: var(--radius);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(90,196,176,0.12), transparent),
    var(--bg-2);
  min-height: 120px;
  box-shadow: var(--shadow);
}
.hero-art img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 280px;
  object-fit: cover;
}

.grid-2, .grid-3 {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}
@media (min-width: 720px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.card h3 { margin: 0 0 8px; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); }
.callout { margin: 12px 0 16px; border-left: 3px solid var(--accent); }

.facts, .steps { margin: 0; padding-left: 18px; color: var(--muted); }
.facts li, .steps li { margin: 0 0 8px; }
.facts strong, .steps strong { color: var(--fg); }

.lab {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}
@media (min-width: 860px) {
  .lab { grid-template-columns: 1fr 1.15fr; align-items: start; }
}
.lab-controls, .lab-out {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 12px; font-size: 0.92rem; }
.field span { color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
textarea, select, input[type="range"] {
  width: 100%;
  font: inherit;
  color: var(--fg);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
textarea, select {
  padding: 12px;
  min-height: 44px;
  resize: vertical;
}
input[type="range"] { min-height: 44px; accent-color: var(--accent); }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border-radius: 12px;
  background: var(--bg-2);
  box-shadow: inset 0 0 0 1px var(--line);
  font-weight: 600;
}
.btn img { display: block; }
.btn.primary { background: var(--accent); color: #0c0e12; box-shadow: none; }
.btn.ghost { background: transparent; }
.stream {
  min-height: 3.2em;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}
.formula { color: var(--muted); font-size: 0.85rem; }

.bars { display: flex; flex-direction: column; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(64px, 28%) 1fr 52px; gap: 8px; align-items: center; }
.bar-lab { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; }
.bar-pct { font-size: 11px; color: var(--muted); text-align: right; }

.token-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tok {
  font-family: var(--mono);
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--bg);
}
.tok.c0 { background: rgba(90,196,176,0.22); }
.tok.c1 { background: rgba(226,177,90,0.22); }
.tok.c2 { background: rgba(120,160,220,0.22); }
.tok.c3 { background: rgba(200,120,160,0.2); }
.tok.c4 { background: rgba(125,206,138,0.2); }
.tok.c5 { background: rgba(232,234,223,0.12); }

.attn-wrap, .notes { margin: 12px 0 18px; }
.attn-grid-wrap {
  overflow-x: auto;
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
}
#attn-canvas, #wave-canvas, #vid-canvas, #c3d {
  width: 100%;
  display: block;
  border-radius: 10px;
}
#vid-canvas {
  background: #000;
  image-rendering: pixelated;
  max-width: 480px;
  aspect-ratio: 16 / 9;
}
.stage3d {
  min-height: 260px;
}
#c3d { height: min(42vw, 380px); min-height: 240px; background: radial-gradient(circle at 40% 30%, rgba(90,196,176,0.12), transparent 55%), var(--bg); }

.choices { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.choice {
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg-2);
  box-shadow: inset 0 0 0 1px var(--line);
  font-size: 0.98rem;
}
.choice.is-right { box-shadow: inset 0 0 0 2px var(--ok); }
.choice.is-wrong { box-shadow: inset 0 0 0 2px var(--danger); }
.explain { color: var(--muted); }

.notes {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.note { margin: 12px 0; padding-top: 12px; border-top: 1px solid var(--line); }
.note h4 { margin: 0 0 6px; }
.note a { color: var(--accent); }
.foot {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 16px 32px;
  color: var(--muted);
  font-size: 0.88rem;
}

@media (max-width: 420px) {
  h1 { font-size: 1rem; }
  .bar-row { grid-template-columns: 72px 1fr; }
  .bar-pct { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .panel { animation: none; }
}
