:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #5b6472;
  --paper: #f5f1e8;
  --paper-2: #fffaf0;
  --line: #d6cdbb;
  --accent: #b45309;
  --accent-2: #0f766e;
  --class-i: #334155;
  --class-ii: #2563eb;
  --class-iii: #b45309;
  --class-iv: #7c3aed;
  --shadow: 0 18px 55px rgba(39, 31, 20, 0.14);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(180, 83, 9, 0.14), transparent 32rem),
    linear-gradient(180deg, #fff7e6 0%, var(--paper) 38%, #ede6d9 100%);
  color: var(--ink);
}
.hero, main, footer { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.hero { padding: 64px 0 34px; }
.kicker, .eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}
h1 { margin: 0; font-size: clamp(3.1rem, 9vw, 7.4rem); line-height: 0.9; letter-spacing: -0.08em; }
h2 { margin: 0 0 12px; font-size: clamp(1.8rem, 3vw, 3rem); letter-spacing: -0.04em; }
.lede { max-width: 760px; margin: 18px 0; font-size: clamp(1.2rem, 2vw, 1.65rem); line-height: 1.25; }
.explainer { max-width: 900px; color: var(--muted); font-size: 1.02rem; line-height: 1.65; }
code { background: rgba(17, 24, 39, 0.08); padding: 0.12em 0.32em; border-radius: 0.35em; }
.explorer {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(420px, 1.18fr);
  gap: 24px;
  align-items: stretch;
  margin: 18px 0 54px;
}
.panel-copy, .canvas-wrap, .section-head, footer {
  background: rgba(255, 250, 240, 0.82);
  border: 1px solid rgba(214, 205, 187, 0.85);
  border-radius: 26px;
  box-shadow: var(--shadow);
}
.panel-copy { padding: 24px; }
.bits { min-height: 1.8em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); }
.class-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: -4px 0 10px; color: var(--muted); line-height: 1.45; }
.class-badge { display: inline-flex; align-items: center; width: fit-content; border-radius: 999px; padding: 3px 9px; color: white; font-size: 0.72rem; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.class-i { background: var(--class-i); }
.class-ii { background: var(--class-ii); }
.class-iii { background: var(--class-iii); }
.class-iv { background: var(--class-iv); }
.permalink { color: var(--accent-2); font-weight: 800; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.controls { display: grid; gap: 12px; margin: 22px 0; }
label { display: grid; gap: 5px; font-size: 0.88rem; font-weight: 700; color: #374151; }
input, select, button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 10px 12px;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
}
button { cursor: pointer; font-weight: 800; transition: transform 120ms ease, border-color 120ms ease, background 120ms ease; }
button:hover, button:focus-visible { transform: translateY(-1px); border-color: var(--accent); outline: none; }
#reroll { background: #0f766e; color: white; border-color: #0f766e; }
.seed-wrap { margin-top: 18px; color: var(--muted); font-size: 0.91rem; }
#seedCanvas, #caCanvas {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--paper);
  image-rendering: pixelated;
}
#seedCanvas { height: 32px; border-radius: 11px; cursor: crosshair; }
.canvas-wrap { padding: 12px; min-width: 0; }
#caCanvas { height: auto; border-radius: 18px; }
.section-head { padding: 24px; margin-bottom: 18px; }
.section-head p { max-width: 760px; color: var(--muted); line-height: 1.55; }
.section-head p:last-child { margin-bottom: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 18px; }
.filter-chip { width: auto; display: inline-flex; gap: 7px; align-items: center; border-radius: 999px; padding: 9px 13px; background: rgba(255, 253, 248, .86); }
.filter-chip span { color: var(--muted); font-weight: 800; }
.filter-chip.active { background: var(--ink); border-color: var(--ink); color: #fffdf8; }
.filter-chip.active span { color: rgba(255, 253, 248, .72); }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(138px, 1fr));
  gap: 12px;
  padding-bottom: 48px;
}
.rule-card {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255, 250, 240, 0.76);
  border: 1px solid rgba(214, 205, 187, 0.9);
  box-shadow: 0 10px 28px rgba(39, 31, 20, 0.08);
  text-align: left;
}
.rule-card.active { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18); }
.rule-card img { width: 100%; height: auto; border-radius: 10px; border: 1px solid rgba(17, 24, 39, 0.08); background: var(--paper); }
.card-title { padding: 0 2px; font-weight: 850; }
.rule-card .class-badge { margin: 0 2px 2px; font-size: .66rem; }
.rule-card[hidden] { display: none; }
footer { margin-bottom: 34px; padding: 18px 22px; color: var(--muted); }
footer p { margin: 0; }
@media (max-width: 860px) {
  .explorer { grid-template-columns: 1fr; }
  .hero { padding-top: 38px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); }
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.pill-link {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(17, 24, 39, .16);
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255, 250, 240, .78);
  color: var(--ink);
  font-weight: 850;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(39, 31, 20, 0.08);
}
.pill-link:hover, .pill-link:focus-visible { border-color: var(--accent); outline: none; }
#exportGif { background: var(--accent); color: white; border-color: var(--accent); }
#compareCurrent { background: var(--ink); color: #fffdf8; border-color: var(--ink); }
button:disabled { opacity: .62; cursor: wait; transform: none; }
.export-status { margin: -8px 0 12px; color: var(--muted); font-size: .9rem; line-height: 1.45; }
.compare-section { margin: 0 0 54px; }
.compare-section .section-head { margin-bottom: 14px; }
.compare-controls { grid-template-columns: repeat(4, minmax(140px, 1fr)); align-items: end; }
.compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.compare-card {
  min-width: 0;
  padding: 14px;
  background: rgba(255, 250, 240, 0.82);
  border: 1px solid rgba(214, 205, 187, 0.9);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.compare-card-head { display: grid; grid-template-columns: minmax(130px, 180px) 1fr; gap: 8px 14px; align-items: end; margin-bottom: 12px; }
.compare-card h3 { margin: 0; font-size: clamp(1.4rem, 3vw, 2.2rem); letter-spacing: -.04em; }
.compare-card .class-line { grid-column: 1 / -1; margin: 0; }
.compare-card canvas { display: block; width: 100%; height: auto; border-radius: 18px; border: 1px solid var(--line); background: var(--paper); image-rendering: pixelated; }
body:not(.compare-mode) .compare-section { display: none; }
body.compare-mode .explorer, body.compare-mode .gallery-section { display: none; }
body.compare-mode .hero { padding-bottom: 24px; }
@media (max-width: 860px) {
  .compare-controls, .compare-grid, .compare-card-head { grid-template-columns: 1fr; }
}

.lab-section { margin: 0 0 54px; }
.lab-head { margin-bottom: 16px; }
.lab-controls { grid-template-columns: repeat(6, minmax(120px, 1fr)); align-items: end; }
#labReroll { background: var(--accent-2); color: white; border-color: var(--accent-2); }
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.metric-card, .lab-copy-grid article, .sensitivity-card, .atlas-section {
  background: rgba(255, 250, 240, 0.82);
  border: 1px solid rgba(214, 205, 187, 0.9);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.metric-card { padding: 16px; display: grid; gap: 8px; }
.metric-card span { color: var(--muted); font-size: .78rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.metric-card strong { font-size: clamp(1.65rem, 4vw, 2.7rem); line-height: 1; letter-spacing: -.04em; }
.metric-card p { margin: 0; color: var(--muted); font-size: .91rem; line-height: 1.45; }
.metric-card canvas { width: 100%; height: 54px; border: 1px solid var(--line); border-radius: 12px; image-rendering: auto; }
.metric-card.active-lens { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(15,118,110,.16), var(--shadow); }
.lab-lens {
  display: grid;
  grid-template-columns: minmax(240px, .6fr) minmax(320px, .75fr) minmax(320px, 1fr);
  gap: 14px;
  align-items: stretch;
  margin: 0 0 16px;
  padding: 18px;
  background: rgba(255, 250, 240, 0.82);
  border: 1px solid rgba(214, 205, 187, 0.9);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.lab-lens h3, .lab-lens-card h4 { margin: 0 0 8px; letter-spacing: -.035em; }
.lab-lens h3 { font-size: clamp(1.35rem, 3vw, 2.1rem); }
.lab-lens-copy p, .lab-lens-card p { margin: 0; color: var(--muted); line-height: 1.55; }
.lab-lens-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid rgba(214, 205, 187, .9);
  border-radius: 18px;
  background: rgba(255,253,248,.68);
}
.lab-lens-controls legend { padding: 0 6px; color: var(--muted); font-size: .76rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.lab-lens-controls label { display: inline-flex; width: auto; grid-template-columns: none; gap: 7px; align-items: center; font-size: .88rem; color: var(--ink); }
.lab-lens-controls input { width: auto; accent-color: var(--accent-2); }
.lab-lens-card { padding: 14px 16px; border: 1px solid rgba(15,118,110,.28); border-radius: 18px; background: rgba(15,118,110,.07); }
.lab-lens-card h4 { font-size: 1.15rem; color: var(--accent-2); }
.lab-lens-card ul { margin: 10px 0 0; padding-left: 1.15rem; color: var(--muted); line-height: 1.45; }
.lab-lens-card li + li { margin-top: 5px; }
.atlas-section { display: grid; grid-template-columns: minmax(260px, .62fr) minmax(360px, 1fr); gap: 16px; padding: 18px; margin: 0 0 16px; align-items: start; }
.atlas-copy { display: grid; gap: 10px; }
.atlas-copy h3 { margin: 0; font-size: clamp(1.45rem, 3vw, 2.35rem); letter-spacing: -.04em; }
.atlas-copy p { margin: 0; color: var(--muted); line-height: 1.55; }
#atlasPlot { display: block; width: 100%; height: auto; min-height: 260px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); cursor: crosshair; }
.atlas-table-wrap { grid-column: 1 / -1; max-height: 340px; overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,253,248,.78); }
#atlasTable { width: 100%; border-collapse: collapse; font-size: .92rem; }
#atlasTable caption { text-align: left; padding: 10px 12px; color: var(--muted); font-weight: 800; }
#atlasTable th, #atlasTable td { padding: 8px 10px; border-top: 1px solid rgba(214,205,187,.72); text-align: left; white-space: nowrap; }
#atlasTable th { position: sticky; top: 0; background: #fffaf0; z-index: 1; color: #374151; }
#atlasTable tr.active { background: rgba(15,118,110,.12); }
#atlasTable button { width: auto; padding: 6px 9px; border-radius: 999px; background: var(--ink); color: #fffdf8; border-color: var(--ink); font-size: .86rem; }
.lab-copy-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 0 0 16px; }
.lab-copy-grid article { padding: 20px; }
.lab-copy-grid h3, .sensitivity-card h3 { margin: 0 0 8px; font-size: 1.25rem; letter-spacing: -.02em; }
.lab-copy-grid p, .delta-note { margin: 0; color: var(--muted); line-height: 1.55; }
.sensitivity-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.sensitivity-card { min-width: 0; padding: 14px; }
.sensitivity-wide { grid-column: 1 / -1; }
.sensitivity-card canvas { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); image-rendering: pixelated; }
.lab-section[data-lens=entropy] #entropySpark,
.lab-section[data-lens=density] #densitySpark,
.lab-section[data-lens=sensitivity] #sensitivitySpark,
.lab-section[data-lens=sensitivity] #labDelta,
.lab-section[data-lens=correlation] #labOriginal,
.lab-section[data-lens=block] #labOriginal,
.lab-section[data-lens=lambda] #labOriginal,
.lab-section[data-lens=density] #labOriginal,
.lab-section[data-lens=entropy] #labOriginal {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(15,118,110,.18);
}
.delta-note { margin-bottom: 12px; }

.tour-section { margin: 0 0 54px; }
.tour-head { margin-bottom: 16px; }
.tour-controls { display: grid; grid-template-columns: minmax(120px, 160px) minmax(180px, 1fr) minmax(120px, 160px); gap: 12px; align-items: end; margin-top: 18px; }
#tourPrev, #tourNext { background: var(--ink); color: #fffdf8; border-color: var(--ink); }
.tour-stops { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 12px; }
.tour-stops button { width: auto; border-radius: 999px; padding: 9px 13px; background: rgba(255, 253, 248, .86); }
.tour-stops button.active { background: var(--accent-2); border-color: var(--accent-2); color: #fffdf8; }
.annotation-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 14px 0 0;
  padding: 10px 12px;
  border: 1px solid rgba(214, 205, 187, .9);
  border-radius: 16px;
  background: rgba(255, 253, 248, .62);
}
.annotation-controls legend { padding: 0 6px; color: var(--muted); font-size: .76rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.annotation-controls label { display: inline-flex; width: auto; grid-template-columns: none; gap: 7px; align-items: center; color: var(--ink); font-size: .86rem; }
.annotation-controls input { width: auto; accent-color: var(--accent-2); }
.tour-grid { display: grid; grid-template-columns: minmax(280px, .72fr) minmax(420px, 1.28fr); gap: 16px; align-items: stretch; }
.tour-copy, .tour-canvas-card { background: rgba(255, 250, 240, 0.82); border: 1px solid rgba(214, 205, 187, 0.9); border-radius: 24px; box-shadow: var(--shadow); }
.tour-copy { padding: 22px; }
.tour-copy h3 { margin: 0 0 12px; font-size: clamp(1.55rem, 3vw, 2.45rem); line-height: 1; letter-spacing: -.04em; }
.tour-observation { color: var(--ink); font-size: 1.08rem; line-height: 1.55; }
.tour-prompt { color: var(--ink); line-height: 1.55; border-left: 4px solid var(--accent-2); padding: 10px 12px; background: rgba(15,118,110,.08); border-radius: 12px; }
.metric-cue {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  padding: 12px 13px;
  border: 1px solid rgba(124, 58, 237, .26);
  border-radius: 14px;
  background: rgba(124, 58, 237, .08);
  color: var(--ink);
  line-height: 1.45;
}
.metric-cue strong { color: var(--class-iv); }
.metric-cue span { color: var(--muted); }
.tour-links { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.tour-canvas-card { padding: 12px; min-width: 0; }
#tourCanvas { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); image-rendering: pixelated; }
.metrics-glossary {
  display: grid;
  grid-template-columns: minmax(240px, .52fr) minmax(360px, 1fr);
  gap: 16px;
  margin-top: 16px;
  padding: 18px;
  background: rgba(255, 250, 240, 0.82);
  border: 1px solid rgba(214, 205, 187, 0.9);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.metrics-glossary h3 { margin: 0 0 8px; font-size: clamp(1.35rem, 3vw, 2.1rem); letter-spacing: -.04em; }
.metrics-glossary p { margin: 0; color: var(--muted); line-height: 1.55; }
.metrics-glossary dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; }
.metrics-glossary dl > div { padding: 12px; border: 1px solid rgba(214,205,187,.8); border-radius: 16px; background: rgba(255,253,248,.7); }
.metrics-glossary dl > div.active { border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(15,118,110,.14); }
.metrics-glossary dt { margin: 0 0 5px; font-weight: 900; }
.metrics-glossary dd { margin: 0; color: var(--muted); line-height: 1.45; font-size: .93rem; }
.metrics-glossary a { color: var(--accent-2); font-weight: 800; }
body:not(.tour-mode) .tour-section { display: none; }
body.tour-mode .explorer, body.tour-mode .gallery-section, body.tour-mode .compare-section, body.tour-mode .lab-section { display: none; }
body.tour-mode .hero { padding-bottom: 24px; }
@media (max-width: 860px) {
  .tour-controls, .tour-grid, .metrics-glossary, .metrics-glossary dl { grid-template-columns: 1fr; }
}

body:not(.lab-mode) .lab-section { display: none; }
body.lab-mode .explorer, body.lab-mode .gallery-section, body.lab-mode .compare-section { display: none; }
body.lab-mode .hero { padding-bottom: 24px; }
/* Reading-path disclosures: layered explanations for newcomer → graduate */
.reading-path {
  max-width: 900px;
  margin: 20px 0 18px;
  background: linear-gradient(180deg, #fdf8e9 0%, #faf3dd 100%);
  border: 1.5px solid #d6c98e;
  border-left: 4px solid #b8961f;
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 0.98rem;
  box-shadow: 0 1px 3px rgba(94, 74, 18, 0.08), 0 0 0 1px rgba(184, 150, 31, 0.04);
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.12s ease;
}
.reading-path:hover {
  border-color: #b8961f;
  box-shadow: 0 2px 8px rgba(94, 74, 18, 0.14), 0 0 0 1px rgba(184, 150, 31, 0.1);
}
.reading-path[open] {
  padding-bottom: 14px;
  box-shadow: 0 2px 10px rgba(94, 74, 18, 0.16), 0 0 0 1px rgba(184, 150, 31, 0.12);
}
.reading-path summary {
  cursor: pointer;
  font-weight: 600;
  color: #5b4a1f;
  list-style: none;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.reading-path summary::-webkit-details-marker { display: none; }
.reading-path summary::before {
  content: '⊕';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #b8961f;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: transform 0.18s ease, background 0.18s ease;
}
.reading-path[open] summary::before {
  content: '⊖';
  background: #8a7536;
  transform: rotate(180deg);
}
.reading-path summary .reading-path-hint {
  margin-left: auto;
  font-size: 0.82rem;
  font-weight: 500;
  color: #8a7536;
  font-style: italic;
  letter-spacing: 0.02em;
}
.reading-path[open] summary .reading-path-hint::after { content: ' — tap to collapse'; }
.reading-path:not([open]) summary .reading-path-hint::after { content: ' — tap to expand'; }
.reading-path-body {
  padding-top: 14px;
  border-top: 1px dashed #d6c98e;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.65;
}
.reading-path-body p { margin: 0 0 14px; }
.reading-path-body p:last-child { margin-bottom: 4px; }
.reading-path-body b { color: #2a3640; }
.reading-path-body .layer-tag {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  background: #8a7536;
  padding: 2px 8px;
  border-radius: 4px;
  margin-right: 8px;
  vertical-align: 2px;
}
.reading-path-body .layer-tag.layer-1 { background: #4a7c3a; }
.reading-path-body .layer-tag.layer-2 { background: #4a6f8a; }
.reading-path-body .layer-tag.layer-3 { background: #8a4a6f; }
.reading-path-body .layer-tag.layer-4 { background: #6b4a8a; }
.reading-path-compact { font-size: 0.94rem; }
.refs-heading {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 24px 0 10px;
  font-weight: 700;
}
ol.refs {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--muted);
  margin: 0 0 18px;
  padding-left: 1.6em;
}
ol.refs li {
  margin-bottom: 10px;
  padding-left: 4px;
}
ol.refs li:last-child { margin-bottom: 0; }
ol.refs em, ol.refs cite { font-style: italic; }
ol.refs b { color: #2a3640; font-weight: 600; }
ol.refs a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.colophon {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
  margin: 22px 0 4px;
  padding-top: 14px;
  border-top: 1px solid #e6dec7;
}
.colophon a { color: inherit; text-decoration: underline; }
.note { color: var(--muted); font-size: 0.92rem; font-style: italic; margin: 6px 0 0; }

@media (max-width: 1000px) {
  .lab-controls, .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .lab-controls, .metric-grid, .lab-lens, .lab-copy-grid, .sensitivity-grid, .atlas-section { grid-template-columns: 1fr; }
  .sensitivity-wide { grid-column: auto; }
}
