/* Dark "chalkboard" theme. Every colour is a token; colour roles are semantic across the site:
   blue = given/original (the user's text, labels), orange = derived (model inferences),
   aqua = a third series, yellow = what the student manipulates, red = adversary/attack/errors.
   Series hues validated with the dataviz palette validator against --surface (#1c2129). */
:root {
  color-scheme: dark;
  --bg: #12151b;
  --surface: #1c2129;
  --surface-2: #242a34;
  --surface-3: #2d3441;
  --ink: #f2efe6;
  --ink-2: #c9c6bb;
  --muted: #979389;
  --grid: #2b313b;
  --axis: #454c59;
  --border: rgba(255, 255, 255, 0.1);
  --dot-dim: #3a414d;

  --c-given: #3987e5;
  --c-derived: #d95926;
  --c-third: #199e70;
  --c-student: #e0a91c;
  --c-attack: #e66767;
  --c-neutral: #7d8491;
  --t-given: #8dbcf6;
  --t-derived: #f5a37c;
  --t-third: #6fd4ab;
  --t-student: #f2c75c;
  --t-attack: #f49c9c;

  /* ordinal ramp for hardness 1..5 (brighter = harder) */
  --h1: #1c5cab;
  --h2: #2a78d6;
  --h3: #5598e7;
  --h4: #86b6ef;
  --h5: #b7d3f6;

  --ok: #4cc26d;
  --bad: #f07a7a;
  --warn: #f2c75c;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--axis) var(--surface);
  background: radial-gradient(circle at 20% -10%, #1b2230 0, transparent 900px) no-repeat, var(--bg);
}
body {
  margin: 0;
  color: var(--ink-2);
  font: 17px/1.6 var(--sans);
  overflow-x: hidden;
}
.page { max-width: 920px; margin: 0 auto; padding: 32px 16px 80px; }
h1, h2, h3 { font-family: var(--serif); color: var(--ink); font-weight: 600; line-height: 1.2; }
h1 { font-size: clamp(2rem, 5vw, 3.1rem); margin: 0.2em 0 0.3em; letter-spacing: -0.01em; }
h2 { font-size: 1.6rem; margin: 0 0 0.6em; }
h3 { font-size: 1.2rem; margin: 0 0 0.4em; }
a { color: var(--t-given); }
strong { color: var(--ink); }
code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--c-student); outline-offset: 2px; border-radius: 4px; }
.small { font-size: 0.88rem; }
.muted { color: var(--muted); }
.error { color: var(--bad); }

/* semantic text colours */
.t-given { color: var(--t-given); }
.t-derived { color: var(--t-derived); }
.t-third { color: var(--t-third); }
.t-student { color: var(--t-student); }
.t-attack { color: var(--t-attack); }
.ok { color: var(--ok); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }

/* MathML */
math { font-size: 1.08em; color: var(--ink); }
math[display="block"] { margin: 0.9em 0; overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 4px 0; }
.m-given { color: var(--t-given); }
.m-derived { color: var(--t-derived); }
.m-attack { color: var(--t-attack); }

/* ---------- home ---------- */
.hero { padding: 24px 0 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.78rem; color: var(--muted); margin: 0; }
.lede { font-size: 1.15rem; color: var(--ink-2); max-width: 40em; }
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.flow-grid { display: grid; gap: 10px; margin: 14px 0; }
.chip { display: inline-block; padding: 5px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--ink); font-size: 0.9rem; }
.chip.given { border-color: var(--c-given); color: var(--t-given); }
.chip.derived { border-color: var(--c-derived); color: var(--t-derived); }
.chip.attack { border-color: var(--c-attack); color: var(--t-attack); }
.arrow { color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 28px 0; }
.card {
  display: flex; flex-direction: column; gap: 6px; padding: 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-2); text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}
.card:hover { border-color: var(--c-given); transform: translateY(-2px); }
.card h3 { margin: 0; }
.card p { margin: 0; flex: 1; }
.card-num { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.card-pct { font-size: 0.82rem; color: var(--muted); }
.progress { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; background: var(--c-student); border-radius: 3px; }
.source { border-top: 1px solid var(--border); padding-top: 18px; font-size: 0.9rem; color: var(--muted); }
.link-btn { background: none; border: 0; padding: 0; color: var(--t-given); font: inherit; text-decoration: underline; cursor: pointer; }

/* ---------- lesson ---------- */
.lesson-head { margin-bottom: 20px; }
.back { font-size: 0.92rem; text-decoration: none; }
.mode { font-size: 0.9rem; }
.step {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 26px 26px 22px; margin: 22px 0; scroll-margin-top: 16px;
}
.step.new { animation: rise 0.35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.prose p, .prose li { max-width: 44em; }
.prose.after { margin-top: 12px; }
.compact li { margin: 4px 0; }
.scale { list-style: none; padding-left: 0; }
.scale li { margin: 4px 0; }
blockquote { margin: 14px 0; padding: 10px 16px; border-left: 3px solid var(--muted); background: var(--surface-2); border-radius: 0 8px 8px 0; color: var(--ink); font-style: italic; }
blockquote.comment, p.comment { font-style: normal; border-left-color: var(--c-given); }
.keyidea { border: 1px solid var(--c-student); background: rgba(224, 169, 28, 0.08); color: var(--ink); padding: 12px 16px; border-radius: 10px; font-weight: 500; }
.keyidea::before { content: "Key idea · "; color: var(--t-student); font-weight: 700; }
.think { border: 1px dashed var(--muted); padding: 12px 16px; border-radius: 10px; }
.think::before { content: "Think about it · "; color: var(--ink); font-weight: 700; }
.callout-inline { border-left: 3px solid var(--c-student); padding: 6px 12px; background: rgba(224, 169, 28, 0.07); font-size: 0.88rem; }

.lesson-foot { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 28px 0; text-align: center; }
.hint, .step-count { margin: 0; color: var(--muted); font-size: 0.9rem; }
.complete h2 { margin-bottom: 12px; }

/* buttons */
.btn {
  display: inline-block; font: 600 0.95rem var(--sans); color: #15181e; background: var(--ink);
  border: 1px solid transparent; border-radius: 999px; padding: 9px 18px; cursor: pointer; text-decoration: none;
}
.btn:hover:not(:disabled) { background: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--axis); }
.btn.ghost:hover:not(:disabled) { border-color: var(--ink-2); background: var(--surface-2); }
.btn.continue { font-size: 1.05rem; padding: 12px 34px; }

/* quiz */
.quiz { margin-top: 18px; padding: 18px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.quiz-q { color: var(--ink); font-weight: 600; margin: 0 0 12px; }
.quiz-tag { display: inline-block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--t-student); margin-right: 10px; }
.quiz-options { display: grid; gap: 8px; }
.quiz-option {
  text-align: left; font: inherit; font-size: 0.97rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 8px; padding: 10px 14px; cursor: pointer;
}
.quiz-option:hover:not(:disabled) { border-color: var(--c-student); }
.quiz-option:disabled { cursor: default; }
.quiz-option.wrong { border-color: var(--bad); color: var(--bad); background: rgba(230, 103, 103, 0.08); }
.quiz-option.right { border-color: var(--ok); background: rgba(76, 194, 109, 0.12); color: var(--ink); }
.quiz-option.right::after { content: "  ✓"; color: var(--ok); font-weight: 700; }
.quiz-explain { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.quiz-explain.show { display: block; }
.quiz-reveal { margin-top: 10px; font-size: 0.9rem; }
.shake { animation: shake 0.35s; }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* ---------- widgets ---------- */
.widget { margin: 16px 0; padding: 18px; border-radius: 10px; background: #171b22; border: 1px solid var(--border); }
.widget-title { margin: 0 0 12px; color: var(--ink); font-weight: 600; font-family: var(--serif); font-size: 1.1rem; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; margin: 12px 0; }
.two-col.wide-left { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.two-col.chat-layout { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.stats.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 14px; border-top: 3px solid var(--axis); display: flex; flex-direction: column; gap: 2px; }
.stat.given { border-top-color: var(--c-given); }
.stat.derived { border-top-color: var(--c-derived); }
.stat span { font-size: 0.8rem; color: var(--muted); }
.stat small { font-size: 0.78rem; color: var(--muted); }
.stat-value { font-size: 1.55rem; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.tag { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--axis); color: var(--ink-2); }
.tag.given { border-color: var(--c-given); color: var(--t-given); }
.tag.derived { border-color: var(--c-derived); color: var(--t-derived); }
.tag.attack { border-color: var(--c-attack); color: var(--t-attack); }

/* sliders & segmented controls */
.slider { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) 72px; gap: 12px; align-items: center; margin: 8px 0; font-size: 0.92rem; }
.slider output { font-variant-numeric: tabular-nums; color: var(--t-student); font-weight: 600; text-align: right; }
input[type="range"] { width: 100%; accent-color: var(--c-student); }
input[type="checkbox"] { accent-color: var(--c-student); }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 18px; margin: 4px 0; }
.segmented button { font: inherit; font-size: 0.86rem; color: var(--ink-2); background: transparent; border: 0; border-radius: 999px; padding: 6px 12px; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--c-student); color: #1a1406; font-weight: 600; }
.toggle { font: inherit; font-size: 0.9rem; display: inline-flex; flex-direction: column; align-items: flex-start; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--axis); background: var(--surface-2); color: var(--ink); cursor: pointer; }
.toggle small { color: var(--muted); font-size: 0.75rem; }
.toggle[aria-pressed="true"] { border-color: var(--c-student); background: rgba(224, 169, 28, 0.14); }
.input { width: 100%; font: inherit; font-size: 0.95rem; color: var(--ink); background: var(--surface-2); border: 1px solid var(--axis); border-radius: 8px; padding: 8px 10px; }
textarea.input { resize: vertical; }
.block-label { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.block-label .tag { align-self: flex-start; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; }
fieldset.side { border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px 12px; margin: 0; min-width: 0; }
fieldset.side legend { padding: 0 6px; font-weight: 600; }
fieldset.side .slider { grid-template-columns: 48px minmax(0, 1fr) 36px; }
fieldset.side.given { border-top: 3px solid var(--c-given); }
fieldset.side.given legend { color: var(--t-given); }
fieldset.side.derived { border-top: 3px solid var(--c-derived); }
fieldset.side.derived legend { color: var(--t-derived); }
.verdict { margin-top: 10px; }
.verdict p { margin: 6px 0; }

.meter { position: relative; height: 12px; background: var(--surface-3); border-radius: 6px; margin: 10px 0; }
.meter-fill { position: absolute; inset: 0 auto 0 0; background: var(--c-derived); border-radius: 6px; transition: width 0.15s; }
.meter-mark { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); }

/* canvas + charts */
canvas.stage { display: block; width: 100%; }
canvas.stage.draggable { touch-action: none; }
.chart { margin: 8px 0 0; }
.chart figcaption { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.plot { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.85rem; color: var(--ink-2); margin-bottom: 6px; min-height: 0; }
.legend .key, .tooltip span { display: inline-flex; align-items: center; gap: 6px; }
.legend i, .tooltip i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.tooltip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity 0.1s; z-index: 2;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
  font-size: 0.82rem; color: var(--ink); display: flex; flex-direction: column; gap: 2px; min-width: 120px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.tooltip.show { opacity: 1; }
.data-table { font-size: 0.85rem; margin-top: 6px; }
.data-table summary { cursor: pointer; color: var(--muted); }
.table-scroll { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 10px; border-bottom: 1px solid var(--grid); text-align: left; }
th { color: var(--ink); font-weight: 600; }
table.compare { width: 100%; margin: 10px 0; }
table.compare td, table.compare th { vertical-align: top; }
table.heat td { text-align: center; background: rgba(57, 135, 229, var(--a, 0)); color: var(--ink); min-width: 52px; }
table.delta-row { margin-top: 8px; }
table.delta-row td { color: var(--t-derived); }

/* profiler */
.comments .comment { margin: 8px 0; padding: 8px 12px; background: var(--surface-2); border-radius: 8px; border-left: 3px solid var(--c-given); color: var(--ink); }
.clue-span { border-bottom: 2px dotted var(--muted); cursor: pointer; }
.clue-span:hover { border-bottom-color: var(--c-student); }
.clue-span.found { background: rgba(217, 89, 38, 0.25); border-bottom-color: var(--c-derived); border-radius: 3px; }
.clue-notes { padding-left: 20px; font-size: 0.9rem; }
.clue-note { margin: 6px 0; }
.profile-card { background: var(--surface-2); border-radius: 12px; padding: 14px; border: 1px solid var(--border); }
.profile-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--c-given); display: inline-block; }
.profile-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--grid); }
.profile-row .k { color: var(--muted); }
.profile-row .v { color: var(--muted); font-weight: 600; }
.profile-row.known .v { color: var(--t-derived); }

/* prompt builder */
.picks { display: grid; gap: 6px; }
.pick { display: flex; gap: 8px; align-items: flex-start; font-size: 0.9rem; color: var(--ink); }
.pick input { margin-top: 5px; }
pre.prompt { scrollbar-color: var(--axis) #0f1217; white-space: pre-wrap; word-break: break-word; font: 0.8rem/1.5 var(--mono); background: #0f1217; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0; max-height: 420px; overflow: auto; }
.seg { display: block; border-left: 3px solid var(--axis); padding-left: 8px; margin: 4px 0; }
.seg-label { display: block; font: 600 0.68rem var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.seg.sys { border-left-color: var(--c-attack); color: var(--ink-2); }
.seg.fix { border-left-color: var(--c-attack); color: var(--t-attack); }
.seg.ft { border-left-color: var(--c-given); color: var(--t-given); }
.model-out .tuple { background: var(--surface-2); border-left: 3px solid var(--c-derived); border-radius: 6px; padding: 8px 10px; margin: 8px 0; }
.model-out code { color: var(--t-derived); background: none; padding: 0; }
.model-out p { margin: 4px 0 0; }

/* chat replay */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 560px; overflow-y: auto; padding-right: 4px; }
.bubble { max-width: 88%; padding: 8px 12px; border-radius: 12px; font-size: 0.9rem; }
.bubble p { margin: 2px 0 0; color: var(--ink); }
.bubble.user { align-self: flex-start; background: rgba(57, 135, 229, 0.16); border: 1px solid rgba(57, 135, 229, 0.45); }
.bubble.bot { align-self: flex-end; background: var(--surface-2); border: 1px solid var(--border); }
.bubble-tag { display: block; font-size: 0.76rem; color: var(--muted); }
.hidden-note { align-self: stretch; border: 1px dashed var(--c-attack); background: rgba(230, 103, 103, 0.07); border-radius: 10px; padding: 8px 12px; font-size: 0.84rem; }
.hidden-note .bubble-tag { color: var(--t-attack); }
.hidden-note p { margin: 4px 0; }
.belief { background: var(--surface-2); border-radius: 10px; padding: 12px; position: sticky; top: 12px; }
.belief-table { width: 100%; font-size: 0.84rem; }
.belief-table td { vertical-align: top; }

/* hardness rater */
.rater blockquote { font-size: 0.95rem; }
.levels .level-btn { width: 46px; height: 46px; font: 600 1.1rem var(--sans); border-radius: 10px; border: 1px solid var(--axis); background: var(--surface-2); color: var(--ink); cursor: pointer; }
.levels .level-btn:hover:not(:disabled) { border-color: var(--c-student); }
.levels .level-btn.right { border-color: var(--ok); background: rgba(76, 194, 109, 0.18); }
.levels .level-btn.close { border-color: var(--warn); background: rgba(242, 199, 92, 0.14); }
.levels .level-btn.wrong { border-color: var(--bad); background: rgba(230, 103, 103, 0.12); }
.rater-feedback p { margin: 8px 0; }

/* anonymizer */
.anon-text { line-height: 2.1; }
.word { font: inherit; font-size: 0.95rem; color: var(--ink); background: none; border: 0; border-radius: 4px; padding: 1px 2px; cursor: pointer; }
.word:hover { background: rgba(224, 169, 28, 0.2); }
.word.redacted { color: var(--muted); background: var(--surface-3); letter-spacing: 0.02em; }
.clue-list { list-style: none; padding: 0; margin: 0; font-size: 0.9rem; }
.clue-list li { padding: 4px 0; }
.clue-list li.alive.explicit { color: var(--t-given); }
.clue-list li.alive.context { color: var(--t-attack); }
.clue-list li.dead { color: var(--muted); text-decoration: line-through; }

/* cheat sheet */
.cheatsheet { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.cheatsheet section { background: var(--surface-2); border-radius: 10px; padding: 14px 16px; font-size: 0.92rem; }
.cheatsheet section p { margin: 6px 0; }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .page { padding: 20px 16px 60px; }
  .cards, .two-col, .two-col.wide-left, .two-col.chat-layout, .cheatsheet, .stats.three { grid-template-columns: minmax(0, 1fr); }
  .stats.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step { padding: 18px 14px; }
  .widget { padding: 12px; }
  .slider { grid-template-columns: minmax(0, 1fr) 64px; }
  .slider .slider-label { grid-column: 1 / -1; }
  .belief { position: static; }
  .bubble { max-width: 96%; }
}

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