:root {
  --ink: #1c1915;
  --ink-soft: #4a433a;
  --paper: #f7f3eb;
  --paper-2: #efe8dc;
  --line: rgba(28, 25, 21, 0.14);
  --clay: #9a4318;
  --gold: #a9782e;
  --vein: #e1b15a;
  --malachite: #1d6b45;
  --iron: #8d342c;
  --lapis: #1d4e78;
  --ground: #efe4d2;
  --shadow: 10px 10px 0 rgba(28, 25, 21, 0.06);
  --serif: "Fraunces", "Iowan Old Style", Palatino, Georgia, serif;
  --sans: "Outfit", "Avenir Next", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}
body[data-depth="0"] { --ground: #f3e7d2; }
body[data-depth="1"] { --ground: #f0e0cc; }
body[data-depth="2"] { --ground: #edd8c4; }
body[data-depth="3"] { --ground: #e7ddd0; }
body[data-depth="4"] { --ground: #e5d9d4; }
body[data-depth="5"] { --ground: #ddd8d2; }
body[data-depth="6"] { --ground: #d8d4ce; }
body[data-depth="7"] { --ground: #d4d0cb; }
body[data-depth="8"] { --ground: #cfcbc6; }
body[data-depth="9"] { --ground: #c8c4bf; }

body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  opacity: 0.22;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.55'/></svg>");
  z-index: 0;
}

::selection { background: #efd3a4; color: var(--ink); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 3px;
}
.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 12px;
  z-index: 20;
}
.skip:focus { top: 12px; }

.noscript {
  max-width: 40rem;
  margin: 4rem auto;
  font-family: var(--serif);
}

/* Rail */
.rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: 108px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: #141210;
  border-right: 1px solid rgba(225, 177, 90, 0.35);
}
.band {
  flex: 1;
  border: 0;
  margin: 0;
  padding: 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
  background: var(--pigment);
  color: var(--band-ink);
  opacity: 0.45;
  transition: opacity 160ms ease, filter 160ms ease;
}
.band:hover, .band:focus-visible { opacity: 1; filter: saturate(1.08); }
.band.is-current { opacity: 1; box-shadow: inset -6px 0 0 var(--vein); }
.band.is-current::after,
.band.is-done::before {
  content: "";
  position: absolute;
  background: var(--vein);
}
.band.is-current::after {
  inset: 5px;
  border: 1.5px solid var(--vein);
  pointer-events: none;
}
.band.is-done { opacity: 0.92; }
.band.is-done::before {
  width: 7px;
  top: 0;
  bottom: 0;
  left: 0;
}
.band .vert {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  white-space: nowrap;
}
.band .short { display: none; font-family: var(--mono); font-size: 11px; font-weight: 500; }
.seam-rail {
  position: absolute;
  left: 50%;
  top: 8px;
  bottom: 8px;
  width: 2px;
  transform: translateX(-50%) scaleY(var(--p));
  transform-origin: top;
  background: linear-gradient(var(--vein), transparent);
  pointer-events: none;
  opacity: 0.85;
}

.shell {
  position: relative;
  z-index: 1;
  margin-left: 108px;
  padding: 22px 28px 88px;
}
.topbar {
  max-width: 880px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.brand strong {
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.brand span, .quiet-meta {
  color: var(--ink-soft);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}
.top-actions { display: flex; gap: 8px; align-items: center; }

.sheet {
  max-width: 880px;
  margin: 0 auto;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: clamp(22px, 4vw, 48px);
}

.kicker {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--clay);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 560; letter-spacing: -0.03em; }
h1 { font-size: clamp(2.4rem, 5vw, 4.2rem); line-height: 0.96; margin: 0 0 12px; }
h1:focus { outline: none; }
.deck {
  font-family: var(--serif);
  font-weight: 480;
  font-style: italic;
  font-size: 1.28rem;
  line-height: 1.35;
  color: var(--ink-soft);
  margin: 0 0 8px;
}
.minutes { margin: 0; color: var(--ink-soft); font-size: 0.88rem; }
.lesson-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin: 0 0 22px;
}
.listen { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.listen-rate { display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: 0.82rem; }
.listen-rate input { width: 92px; }
.listen-state { color: var(--ink-soft); font-size: 0.82rem; }
[data-action="read-block"] { cursor: pointer; border-radius: 2px; }
[data-action="read-block"]:hover,
[data-action="read-block"]:focus-visible {
  background: rgba(225, 177, 90, 0.12);
  box-shadow: inset 3px 0 0 rgba(225, 177, 90, 0.7);
  outline: none;
}
[data-say].is-speaking {
  background: rgba(225, 177, 90, 0.2);
  box-shadow: inset 3px 0 0 var(--gold);
}

.prose { max-width: 66ch; }
.illus {
  margin: 1.6rem 0 1.8rem;
  padding: 18px 18px 14px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.illus figcaption {
  margin-top: 10px;
  font-family: var(--sans);
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.illus figcaption code { font-family: var(--mono); font-size: 0.84em; }
.ill { display: block; width: 100%; height: auto; overflow: visible; }
.ill text { fill: var(--ink); }
.ill .ill-t { font: 400 13px var(--sans); }
.ill .ill-h { font: 600 13.5px var(--sans); }
.ill .ill-s { font: 400 11.5px var(--sans); fill: var(--ink-soft); }
.ill .ill-m { font: 500 11.5px var(--mono); }
.ill .ill-n { font: 600 11px var(--sans); fill: var(--paper); }
.ill-box { fill: #fbf8f2; stroke: var(--ink); stroke-width: 1.2; }
.ill-line { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.ill-dash { stroke-dasharray: 4 4; }
.ill-faint { stroke: rgba(28, 25, 21, 0.3); }
.ill-text { stroke-width: 5; stroke-linecap: round; stroke: rgba(28, 25, 21, 0.12); }
.ill-head { fill: var(--ink); }
.ill-dot { fill: var(--ink); }
.ill-bar { fill: rgba(29, 78, 120, 0.35); stroke: var(--lapis); stroke-width: 1; }
.ill-bar.is-top { fill: var(--lapis); }
.ill .f-paper { fill: #fbf8f2; }
.ill .f-gold { fill: #f3e2bd; }
.ill .f-clay { fill: #efd3bf; }
.ill .f-mal { fill: #d5e6da; }
.ill .f-lapis { fill: #d6e2ee; }
.ill .f-iron { fill: #f1d6d1; }
.ill .f-off { fill: rgba(28, 25, 21, 0.04); stroke: rgba(28, 25, 21, 0.4); }
.prose h3 { font-size: 1.45rem; margin: 1.6rem 0 0.4rem; }
.prose p, .prose li {
  font-family: var(--serif);
  font-size: 1.16rem;
  font-weight: 460;
  line-height: 1.55;
}
.prose ul { padding-left: 1.2rem; }
.prose li { margin: 0.35rem 0; }
.prose code, .note code, .feedback code, .why code {
  font-family: var(--mono);
  font-size: 0.84em;
  background: rgba(28, 25, 21, 0.06);
  padding: 0.05em 0.3em;
}
.note {
  max-width: 66ch;
  margin: 1.2rem 0;
  padding: 0.9rem 1rem 0.9rem 1rem;
  border-left: 3px solid var(--gold);
  background: rgba(225, 177, 90, 0.14);
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.45;
}

.codeblock {
  margin: 1.1rem 0 1.3rem;
  background: #1a1816;
  color: #f3ecdf;
  border-radius: 2px;
  overflow: hidden;
}
.codeblock header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  color: #c8bba6;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(243, 236, 223, 0.12);
}
.codeblock pre {
  margin: 0;
  padding: 14px 16px 16px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.55;
}
.codeblock .btn { color: #f3ecdf; border-color: rgba(243, 236, 223, 0.3); }

.exercise, .check {
  margin-top: 2rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--line);
}
.exercise h2, .check h2 { font-size: 1.7rem; margin: 0 0 0.4rem; }
.lead-in {
  max-width: 66ch;
  color: var(--ink-soft);
  margin: 0 0 1rem;
}

.btn {
  border: 1px solid var(--ink);
  background: transparent;
  padding: 0.55rem 0.9rem;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 500;
}
.btn:hover { background: rgba(28, 25, 21, 0.05); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: #322c26; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; }
.btn.danger { border-color: var(--iron); color: var(--iron); }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 1.6rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.specimen-list, .scenario-list, .sieve-list, .toggle-list { display: grid; gap: 10px; }
.specimen, .scenario, .sieve-item, .toggle-item, .q-card, .piece, .policy-card {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.35);
  padding: 12px 14px;
}
.specimen, .sieve-item, .toggle-item {
  display: grid;
  grid-template-columns: 1fr minmax(180px, 240px);
  gap: 12px;
  align-items: center;
}
.specimen p, .sieve-item p, .toggle-item p, .scenario p { margin: 0; }
.scenario h3, .q-card h3, .piece h3 { font-family: var(--sans); font-size: 1rem; letter-spacing: 0; margin: 0 0 4px; font-weight: 600; }
select, textarea, input[type="text"], input[type="number"] {
  width: 100%;
  background: #fffdf8;
  border: 1px solid var(--line);
  padding: 8px 10px;
  border-radius: 2px;
}
textarea { min-height: 88px; resize: vertical; font-family: var(--serif); font-size: 1.02rem; }
.choice-list { display: grid; gap: 6px; margin-top: 8px; }
.choice {
  text-align: left;
  background: #fffdf8;
  border: 1px solid var(--line);
  padding: 8px 10px;
  border-radius: 2px;
}
.choice.is-on, .piece.is-on, .layer.is-on { border-color: var(--ink); background: #fff; }
.choice.is-right, .mark.is-right { border-color: var(--malachite); background: rgba(29, 107, 69, 0.08); }
.choice.is-wrong, .mark.is-wrong { border-color: var(--iron); background: rgba(141, 52, 44, 0.08); }
.why { margin: 8px 0 0; color: var(--ink-soft); font-size: 0.92rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip {
  border: 1px dashed var(--ink-soft);
  background: transparent;
  border-radius: 999px;
  padding: 6px 10px;
}
.chip:disabled { opacity: 0.35; }
.slots { display: grid; gap: 6px; margin: 10px 0 12px; }
.slot {
  min-height: 42px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: rgba(255,255,255,0.4);
}
.slot b { font-family: var(--mono); font-size: 0.78rem; color: var(--clay); }

.composer-grid, .split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field span { font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.banner {
  padding: 8px 10px;
  background: rgba(29, 78, 120, 0.1);
  border: 1px solid rgba(29, 78, 120, 0.25);
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.token-row { display: flex; gap: 6px; align-items: flex-end; height: 92px; margin: 8px 0 12px; }
.token {
  flex: 1;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 6px;
  font-family: var(--mono);
  font-size: 0.72rem;
  min-height: 8px;
}
.slider-line { width: 100%; accent-color: var(--clay); }

.layers { display: grid; gap: 8px; }
.layer {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  background: #fffdf8;
}
.prompt-out {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.82rem;
  background: #1a1816;
  color: #f3ecdf;
  padding: 14px;
  min-height: 180px;
  margin: 0;
}
.rubric { list-style: none; padding: 0; margin: 10px 0 0; }
.rubric li { padding: 4px 0 4px 1.2rem; position: relative; }
.rubric li::before { position: absolute; left: 0; }
.rubric li.met::before { content: "●"; color: var(--malachite); }
.rubric li.unmet::before { content: "○"; color: var(--ink-soft); }

.diagram {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.piece { text-align: left; width: 100%; }
.piece small { display: block; color: var(--ink-soft); font-size: 0.82rem; margin-top: 4px; }
.piece.is-trap.is-on { border-color: var(--iron); }

.meter {
  height: 10px;
  background: rgba(28, 25, 21, 0.08);
  margin: 8px 0 14px;
  position: relative;
}
.meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--iron), var(--gold), var(--malachite));
  width: var(--w);
}

.feedback {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--paper-2);
  border-left: 3px solid var(--ink);
  font-size: 0.95rem;
}
.feedback.good { border-color: var(--malachite); }
.feedback.bad { border-color: var(--iron); }

.q-card { margin-bottom: 12px; }
.q-card p { font-family: var(--serif); font-size: 1.08rem; margin: 0 0 8px; }

/* Trail */
.trail { max-width: 1120px; margin: 0 auto; position: relative; z-index: 1; padding: 28px 28px 80px; }
.mast {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(220px, 280px);
  gap: 48px;
  align-items: center;
  margin-bottom: 36px;
  min-height: calc(100vh - 72px);
}
.mast h1 {
  font-size: clamp(3.4rem, 8vw, 6.6rem);
  font-weight: 560;
  letter-spacing: -0.045em;
  line-height: 0.9;
}
.lede {
  font-family: var(--serif);
  font-size: 1.35rem;
  line-height: 1.4;
  max-width: 38ch;
}
.mast-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 18px; }
.core-hero svg { width: 100%; height: auto; display: block; filter: drop-shadow(8px 10px 0 rgba(28, 25, 21, 0.08)); }
.core-hero { margin: 0; }

.how {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 10px 0 26px;
}
.how article {
  background: rgba(247, 243, 235, 0.72);
  border: 1px solid var(--line);
  padding: 12px 14px;
}
.how strong { display: block; font-family: var(--serif); font-size: 1.15rem; font-weight: 560; }
.how p { margin: 4px 0 0; color: var(--ink-soft); font-size: 0.92rem; }

.map { display: grid; gap: 8px; }
.map-item {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 18px 72px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: rgba(247, 243, 235, 0.8);
  border: 1px solid var(--line);
}
.map-item:hover { background: #fffdf8; }
.swatch { width: 18px; height: 36px; background: var(--pigment); }
.map-item .depth { font-family: var(--mono); font-size: 0.78rem; color: var(--clay); }
.map-item .map-title {
  display: block;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 560;
  letter-spacing: -0.03em;
}
.piece .piece-title { font-weight: 600; display: block; }
.map-item p { margin: 2px 0 0; color: var(--ink-soft); }
.seal-flag {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--malachite);
  font-weight: 600;
}
.sources {
  margin-top: 22px;
  color: var(--ink-soft);
  font-size: 0.85rem;
}
.sources a { color: var(--lapis); }

.drawer-back {
  position: fixed;
  inset: 0;
  background: rgba(20, 18, 16, 0.35);
  z-index: 8;
}
.drawer {
  position: fixed;
  z-index: 9;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100%);
  background: var(--paper);
  border-left: 1px solid var(--line);
  padding: 22px;
  overflow: auto;
}
.drawer h2 { margin-top: 0; }
.note-item { border-top: 1px solid var(--line); padding: 10px 0; }
.note-item strong { font-family: var(--serif); }

.certificate {
  max-width: 720px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  padding: 32px 20px 80px;
}
.cert-card {
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: clamp(22px, 5vw, 48px);
  box-shadow: var(--shadow);
}
.cert-card h1 { font-size: clamp(2.6rem, 6vw, 4.4rem); }
.corebar { display: flex; height: 28px; width: 100%; margin: 16px 0; }
.corebar i { display: block; flex: 1; background: var(--pigment); }
.cert-name {
  font-family: var(--serif);
  font-size: 2rem;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  border-radius: 0;
  padding: 4px 0;
  width: min(100%, 420px);
}

@media (max-width: 860px) {
  .rail {
    position: sticky;
    top: 0;
    width: 100%;
    height: 58px;
    flex-direction: row;
    border-right: 0;
    border-bottom: 1px solid rgba(225, 177, 90, 0.35);
  }
  .seam-rail { display: none; }
  .band .vert { display: none; }
  .band .short { display: block; }
  .shell { margin-left: 0; padding: 16px 14px 72px; }
  .mast, .composer-grid, .split, .how, .diagram { grid-template-columns: 1fr; }
  .illus { padding: 12px; overflow-x: auto; }
  .ill { min-width: 560px; }
  .mast { min-height: 0; }
  .specimen, .sieve-item, .toggle-item, .map-item { grid-template-columns: 1fr; }
  .map-item { grid-template-columns: 18px 1fr; }
  .map-item .depth { grid-column: 2; }
  .trail { padding: 18px 14px 64px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .band { transition: none; }
}
