/* The Chromatic Star — self-contained dark theme. No external fonts or assets. */
:root {
  --bg: #0c0e12;
  --bg-raise: #141821;
  --bg-inset: #0a0c10;
  --stroke: #2a3140;
  --stroke-soft: #1e2430;
  --text: #e7e3d8;
  --muted: #a8b0bc;
  --faint: #7d8694;
  --gold: #e0b45a;
  --gold-dim: #8a7034;
  --blue: #7eafd4;
  --blue-dim: #3d5f7a;
  --green: #8fbf9a;
  --danger: #d9897a;
  --focus: #f0d48a;
  --cell-fill: #1b2030;
  --cell-stroke: #3c4658;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --serif: Palatino, "Palatino Linotype", "Iowan Old Style", "Times New Roman", serif;
  --sans: "Avenir Next", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", "Consolas", ui-monospace, monospace;
  --radius: 10px;
  --max: 1180px;
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(224, 180, 90, 0.07), transparent 50%),
    radial-gradient(900px 500px at -10% 20%, rgba(126, 175, 212, 0.06), transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 1.05rem;
  line-height: 1.6;
}

img, svg { max-width: 100%; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--gold); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: #f3d48a; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem; top: 0;
  transform: translateY(-120%);
  background: var(--gold);
  color: #1a1408;
  padding: 0.4rem 0.8rem;
  z-index: 20;
  border-radius: 0 0 6px 6px;
}
.skip-link:focus { transform: none; }

.site-header {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.15rem 1.4rem 0.55rem;
  display: grid;
  gap: 0.35rem;
}
.site-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 0;
}
.site-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.15;
  margin: 0;
  letter-spacing: -0.02em;
}
.site-sub {
  margin: 0.2rem 0 0;
  color: var(--muted);
  max-width: 46rem;
}
.site-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: baseline;
  color: var(--faint);
  font-size: 0.92rem;
  margin-top: 0.6rem;
}
#course-progress {
  color: var(--blue);
}

.tabs {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.6rem 1.4rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  border-bottom: 1px solid var(--stroke);
}
.tabs [role="tab"] {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 0.7rem 0.85rem 0.65rem;
  margin-bottom: -1px;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.tabs [role="tab"].is-active,
.tabs [role="tab"][aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--gold);
}
.tabs [role="tab"]:hover { color: var(--text); }

.panels {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1.4rem 3rem;
}
[role="tabpanel"] { animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel-intro h2 {
  font-family: var(--serif);
  font-size: clamp(1.4rem, 3vw, 1.9rem);
  margin: 0 0 0.4rem;
}
.panel-intro p { margin: 0 0 1rem; color: var(--muted); }

.lesson {
  display: grid;
  gap: 1.4rem;
}
.lesson-copy {
  background: var(--bg-raise);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem 1.3rem;
  box-shadow: var(--shadow);
}
.lesson-copy h3 {
  font-family: var(--serif);
  font-size: 1.2rem;
  margin: 1.1rem 0 0.35rem;
}
.lesson-copy h3:first-child { margin-top: 0; }
.lesson-copy p, .lesson-copy li { color: var(--text); }
.lesson-copy .muted, .note { color: var(--muted); }
.lesson-copy ul { padding-left: 1.2rem; }
.figure-note, .source-note, .interpret-note {
  font-size: 0.92rem;
  color: var(--muted);
  border-left: 2px solid var(--gold-dim);
  padding-left: 0.85rem;
}
.interpret-note { border-left-color: var(--blue-dim); }

.torus-diagram {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}
.torus-card {
  background: var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 0.7rem 0.8rem 0.9rem;
}
.torus-card h3 { font-family: var(--serif); font-size: 1.05rem; margin: 0.2rem 0 0.4rem; }
.torus-card svg { width: 100%; height: auto; display: block; }

/* Laboratory */
.lab { display: block; }
.lab-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.9fr);
  gap: 1rem;
  align-items: stretch;
}
.lab-svg-wrap {
  background:
    radial-gradient(circle at 50% 50%, rgba(224, 180, 90, 0.05), transparent 55%),
    var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lab-svg {
  width: 100%;
  height: auto;
  display: block;
  aspect-ratio: 1 / 1;
  max-height: min(72vh, 46rem);
}
.lab-side {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.lab-toolbar, .lab-toggles, .lab-actions, .lab-info {
  background: var(--bg-raise);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius);
  padding: 0.8rem;
}
.lab-toolbar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem 0.7rem;
}
.lab-field { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.82rem; color: var(--muted); }
.lab-field-label { letter-spacing: 0.04em; text-transform: uppercase; font-size: 0.72rem; }
.lab-field select, .lab-field input[type="range"] {
  background: var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: 6px;
  padding: 0.35rem 0.45rem;
}
.lab-field input[type="range"] { padding: 0.2rem 0; width: 100%; }
.lab-range-val { color: var(--gold); font-variant-numeric: tabular-nums; margin-left: 0.35rem; }
.lab-toggles { display: grid; gap: 0.35rem; }
.lab-check { display: flex; gap: 0.5rem; align-items: flex-start; font-size: 0.92rem; cursor: pointer; }
.lab-check input { margin-top: 0.3rem; accent-color: var(--gold); }
.lab-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.lab-btn {
  appearance: none;
  background: #1c2230;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 0.32rem 0.75rem;
  cursor: pointer;
  color: var(--text);
}
.lab-btn:hover { border-color: var(--gold-dim); background: #232a3a; }
.lab-info { font-size: 0.95rem; overflow: auto; max-height: 22rem; }
.lab-info h3 { font-family: var(--serif); margin: 0 0 0.4rem; font-size: 1.2rem; }
.lab-info p { margin: 0 0 0.65rem; }
.lab-facts { padding-left: 1.1rem; margin: 0; }
.lab-facts .k { color: var(--gold); }
.lab-hint { color: var(--muted); font-size: 0.9rem; }
.lab-shape-notes { font-family: var(--serif); font-size: 1.15rem; color: var(--gold); }

/* SVG cells */
.lab-centre { fill: none; stroke: var(--gold-dim); stroke-width: 0.05; }
.lab-axis { stroke: rgba(231, 227, 216, 0.75); stroke-width: 0.06; stroke-dasharray: 0.18 0.14; }
.lab-ray { stroke-width: 0.045; }
.lab-ray--fifths { stroke: var(--gold); stroke-opacity: 0.85; }
.lab-ray--fourths { stroke: var(--blue); stroke-opacity: 0.85; }
.lab-ray--mother { stroke: rgba(168, 176, 188, 0.35); }
.lab-ray--odd { stroke: rgba(224, 180, 90, 0.4); }
.lab-ray--even { stroke: rgba(126, 175, 212, 0.35); }
.lab-cell polygon {
  fill: var(--cell-fill);
  stroke: var(--cell-stroke);
  stroke-width: 0.06;
  transition: fill 0.15s ease, stroke 0.15s ease, filter 0.15s ease;
}
.lab-cell--ring1 polygon { stroke: #5a6578; stroke-width: 0.07; }
.lab-cell-label {
  fill: var(--text);
  font-family: var(--sans);
  font-weight: 600;
  pointer-events: none;
}
.lab-cell:focus { outline: none; }
.lab-cell:focus-visible polygon {
  stroke: var(--focus);
  stroke-width: 0.11;
  filter: drop-shadow(0 0 0.12px #f0d48a);
}
.lab-cell:hover polygon { fill: #252b3d; }
.lab-cell--axis polygon { stroke: #efe6d0; stroke-width: 0.09; }
.lab-cell--fifths polygon { stroke: var(--gold); fill: #3a3018; }
.lab-cell--fourths polygon { stroke: var(--blue); fill: #173044; }
.lab-cell--wt-tips polygon { fill: #3a3018; stroke: var(--gold); }
.lab-cell--wt-joints polygon { fill: #173044; stroke: var(--blue); }
.lab-cell--root-pc .lab-cell-label { fill: var(--gold); }
.lab-cell.is-highlighted polygon {
  fill: #5a3f12;
  stroke: var(--gold);
  stroke-width: 0.1;
}
.lab-cell.is-highlighted .lab-cell-label { fill: #fff6e0; }
.lab-cell.is-selected polygon {
  fill: #6d4a14;
  stroke: #f3d48a;
  stroke-width: 0.12;
}
.lab-cell.is-dimmed polygon { fill: #141824; stroke: #2a3140; }
.lab-cell.is-dimmed .lab-cell-label { fill: #6e7684; }

.lab--compact .lab-svg { max-height: min(58vh, 34rem); }
.lab--compact .lab-info { max-height: 16rem; }

/* Quiz */
.quiz {
  background: var(--bg-raise);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.quiz h3 { font-family: var(--serif); margin: 0 0 0.3rem; }
.quiz-item { margin: 1rem 0 0; padding-top: 0.8rem; border-top: 1px solid var(--stroke-soft); }
.quiz-item > p { margin: 0 0 0.5rem; }
.quiz-choices { display: flex; flex-direction: column; align-items: flex-start; gap: 0.35rem; }
.quiz-choices button {
  appearance: none;
  background: var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.quiz-choices button:hover:not(:disabled) { border-color: var(--gold-dim); }
.quiz-choices button.is-right { border-color: var(--green); background: #16301c; }
.quiz-choices button.is-picked-wrong { border-color: var(--danger); background: #3a1c18; }
.quiz-feedback { margin: 0.55rem 0 0; color: var(--muted); font-size: 0.95rem; }
.quiz-item.is-correct > p::after { content: "  ✓"; color: var(--green); }
.quiz-item.is-wrong > p::after { content: "  ✗"; color: var(--danger); }
.progress-pill {
  display: inline-block;
  margin-left: 0.5rem;
  color: var(--blue);
  font-size: 0.9rem;
}

.preset-row { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.2rem 0 0.8rem; }

.site-footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.4rem 2.5rem;
  border-top: 1px solid var(--stroke);
  color: var(--muted);
  font-size: 0.92rem;
}
.site-footer p { margin: 0.4rem 0; }
.disclaimer { color: var(--faint); }

@media (max-width: 860px) {
  .lab-stage { grid-template-columns: 1fr; }
  .lab-svg { max-height: min(70vh, 32rem); }
  .lab-info { max-height: none; }
  .lab-toolbar { grid-template-columns: 1fr; }
  body { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  [role="tabpanel"], .lab-cell polygon { animation: none; transition: none; }
}
