:root {
  --forest: #123b2b;
  --forest-deep: #09271c;
  --moss: #276a49;
  --fern: #90b894;
  --paper: #f2ead8;
  --paper-light: #fffaf0;
  --paper-dark: #ddd0b7;
  --ink: #17211b;
  --muted: #67675d;
  --ochre: #e9b742;
  --signal: #c94b32;
  --blue: #426d79;
  --good: #d9edcf;
  --warn: #f7dfad;
  --line: #24372d;
  --shadow: 8px 8px 0 var(--ink);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent 49px, rgba(201, 75, 50, .16) 50px, transparent 51px),
    repeating-linear-gradient(0deg, rgba(18, 59, 43, .055) 0 1px, transparent 1px 31px),
    var(--paper);
  font-family: "Courier New", Courier, monospace;
}

button,
input { font: inherit; }

button,
a { touch-action: manipulation; }

button:focus-visible,
a:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 4px solid var(--ochre);
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  z-index: 30;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  color: #fff;
  background: var(--forest-deep);
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.page-shell {
  width: min(1200px, calc(100% - 36px));
  margin: 0 auto;
  padding: 24px 0 70px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--ink);
}

.topbar a,
.page-footer a,
.source-ledger a {
  color: inherit;
  font-weight: 800;
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}

.brand {
  letter-spacing: .06em;
  text-transform: uppercase;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, .85fr);
  gap: clamp(28px, 6vw, 84px);
  align-items: center;
  min-height: 650px;
  padding: 70px 0 60px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 13px;
  font-size: .76rem;
  font-weight: 900;
  letter-spacing: .13em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4 {
  margin-top: 0;
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  margin-bottom: 26px;
  font-size: clamp(4rem, 10vw, 8.2rem);
  line-height: .75;
  letter-spacing: -.075em;
}

h1 em {
  color: var(--signal);
  font-weight: 400;
}

.hero-lead {
  max-width: 680px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.15rem, 2.2vw, 1.55rem);
  line-height: 1.55;
}

.start-action,
.next-button {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 26px;
  margin-top: 20px;
  padding: 14px 18px;
  border: 2px solid var(--ink);
  color: #fff;
  background: var(--signal);
  box-shadow: 5px 5px 0 var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.start-action:hover,
.next-button:hover { transform: translate(-2px, -2px); }

.hero-board {
  position: relative;
  padding: 30px 26px 22px;
  border: 2px solid var(--ink);
  background: var(--forest);
  box-shadow: var(--shadow);
  color: #fff;
  transform: rotate(1.25deg);
}

.hero-board svg { display: block; width: 100%; }
.hero-edge { fill: none; stroke: #8bb49a; stroke-width: 5; }
.hero-path { fill: none; stroke: var(--ochre); stroke-width: 9; stroke-linecap: round; }
.hero-node circle { fill: var(--paper-light); stroke: var(--forest-deep); stroke-width: 5; }
.hero-node text { fill: var(--forest-deep); font-size: 24px; font-weight: 900; text-anchor: middle; }
.hero-node.path circle { fill: var(--ochre); }
.hero-board p { max-width: calc(100% - 125px); margin: 0; line-height: 1.5; }

.case-stamp {
  position: absolute;
  right: 12px;
  bottom: -30px;
  display: grid;
  width: 112px;
  height: 112px;
  place-items: center;
  border: 4px double var(--signal);
  border-radius: 50%;
  color: var(--signal);
  background: var(--paper);
  font-size: .78rem;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
  transform: rotate(-12deg);
}

.wobble-strip {
  display: grid;
  grid-template-columns: .72fr 2fr;
  gap: 28px;
  margin: 0 0 90px;
  padding: 28px;
  border: 2px solid var(--ink);
  background: var(--ochre);
  box-shadow: var(--shadow);
}

.section-number {
  display: inline-block;
  min-width: 42px;
  margin-right: 12px;
  padding: 4px 7px;
  border: 2px solid;
  font-weight: 900;
}

.wobble-strip h2 { margin: 12px 0 0; font-size: clamp(1.7rem, 3vw, 2.6rem); }
.wobble-strip ul { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.wobble-strip li { display: grid; grid-template-columns: minmax(180px, .7fr) 1fr; gap: 18px; padding-bottom: 11px; border-bottom: 2px dashed rgba(23, 33, 27, .45); line-height: 1.45; }
.wobble-strip li:last-child { padding-bottom: 0; border-bottom: 0; }

.module-section,
.control-deck,
.training,
.source-ledger { margin: 90px 0; }

.section-heading,
.control-heading,
.training-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}

.section-heading h2,
.control-heading h2,
.training-heading h2,
.source-ledger h2 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 5vw, 4.5rem);
  line-height: .95;
  letter-spacing: -.045em;
}

.module-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 19px; }

.module-card {
  min-height: 310px;
  padding: 24px;
  border: 2px solid var(--ink);
  color: inherit;
  background: var(--paper-light);
  box-shadow: 5px 5px 0 var(--ink);
  text-align: left;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease;
}

.module-card:nth-child(2) { transform: translateY(16px); }
.module-card:nth-child(3) { transform: translateY(-9px); }
.module-card:hover { background: #e6eedc; transform: translate(-3px, -3px); }
.module-card:nth-child(2):hover { transform: translate(-3px, 13px); }
.module-card:nth-child(3):hover { transform: translate(-3px, -12px); }

.module-code {
  display: inline-grid;
  width: 58px;
  height: 58px;
  place-items: center;
  margin-bottom: 38px;
  border: 2px solid;
  border-radius: 50%;
  color: #fff;
  background: var(--forest);
  font-weight: 900;
}

.module-card h3 { margin-bottom: 14px; font-size: 1.65rem; }
.module-card p { min-height: 88px; line-height: 1.5; }
.module-status { display: inline-block; padding: 6px 8px; border: 2px solid; font-size: .72rem; font-weight: 900; text-transform: uppercase; }
.module-status.is-clean { color: #fff; background: var(--moss); }

.control-deck {
  padding: 34px;
  border: 2px solid var(--ink);
  background: var(--paper-light);
  box-shadow: var(--shadow);
}

.control-heading p { max-width: 360px; margin: 0; color: var(--muted); line-height: 1.5; }
.control-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 25px; }
.control-grid fieldset { margin: 0; padding: 18px; border: 2px solid var(--line); }
.control-grid legend { padding: 0 8px; font-weight: 900; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); }
.segmented button { min-height: 48px; border: 2px solid var(--ink); border-right: 0; color: inherit; background: #fff; cursor: pointer; }
.segmented button:last-child { border-right: 2px solid; }
.segmented button[aria-pressed="true"] { color: #fff; background: var(--forest); box-shadow: inset 0 -5px 0 var(--ochre); }

.method-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(9px, 2vw, 28px);
  margin-top: 30px;
  padding-top: 25px;
  border-top: 2px dashed var(--paper-dark);
  font-weight: 900;
}

.method-strip span { display: flex; align-items: center; gap: 8px; }
.method-strip b { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 50%; color: #fff; background: var(--signal); }
.method-strip i { font-size: 1.5rem; font-style: normal; }

.training { scroll-margin-top: 18px; }
.training-score { min-width: 130px; padding: 12px 16px; border: 2px solid; background: var(--good); text-align: right; transform: rotate(2deg); }
.training-score b { display: block; font: 800 2.4rem Georgia, serif; }
.training-score span { font-size: .7rem; font-weight: 900; text-transform: uppercase; }

.case-tabs { display: flex; gap: 9px; overflow-x: auto; padding: 8px 5px 14px; scrollbar-color: var(--forest) var(--paper-dark); }
.case-tab { flex: 0 0 auto; display: grid; width: 44px; height: 44px; place-items: center; border: 2px solid; border-radius: 50%; color: inherit; background: var(--paper-light); font-weight: 900; cursor: pointer; }
.case-tab[aria-selected="true"] { color: #fff; background: var(--forest); transform: translateY(-4px); }
.case-tab.is-clean { background: var(--good); }
.case-tab.is-guided { background: var(--warn); }
.case-tab[aria-selected="true"].is-clean,
.case-tab[aria-selected="true"].is-guided { color: var(--ink); box-shadow: 0 0 0 4px var(--ochre); }

.case-file {
  border: 2px solid var(--ink);
  background: var(--paper-light);
  box-shadow: 10px 10px 0 var(--ink);
}

.case-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 25px;
  align-items: start;
  padding: 28px 30px 23px;
  border-bottom: 2px solid var(--ink);
}

.case-topic { display: inline-block; margin-bottom: 9px; color: var(--signal); font-size: .74rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.case-head h3 { margin-bottom: 9px; font-size: clamp(2rem, 4vw, 3.4rem); line-height: 1; }
.case-head p { max-width: 750px; margin: 0; line-height: 1.55; }
.case-id-block { min-width: 82px; padding: 8px 12px; border: 3px double var(--signal); color: var(--signal); text-align: center; transform: rotate(4deg); }
.case-id-block span { display: block; font-size: .65rem; font-weight: 900; }
.case-id-block b { font: 800 2.4rem Georgia, serif; }

.support-banner { margin: 20px 30px 0; padding: 12px 14px; border-left: 6px solid var(--blue); background: #e5eff0; line-height: 1.5; }

.workbench { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(310px, .85fr); min-height: 600px; }

.tree-stage {
  min-width: 0;
  padding: 18px;
  border-right: 2px solid var(--ink);
  background:
    radial-gradient(circle at 50% 90%, rgba(144, 184, 148, .17), transparent 38%),
    var(--forest-deep);
  color: #fff;
}

.stage-label { display: flex; justify-content: space-between; gap: 18px; min-height: 42px; padding: 5px 9px 10px; border-bottom: 1px solid rgba(255,255,255,.27); font-size: .73rem; font-weight: 900; text-transform: uppercase; }
.stage-label span:last-child { color: #c9dccb; text-align: right; }
#tree-svg { display: block; width: 100%; min-height: 440px; max-height: 520px; overflow: visible; }

.tree-edge { stroke: #7da88d; stroke-width: 5; stroke-linecap: round; }
.tree-edge.is-path { stroke: var(--ochre); stroke-width: 9; }
.tree-node { cursor: pointer; }
.tree-node circle { fill: #f8f0dc; stroke: #071b13; stroke-width: 5; transition: fill .15s ease, transform .15s ease; }
.tree-node text { fill: var(--forest-deep); font-size: 23px; font-weight: 900; pointer-events: none; text-anchor: middle; }
.tree-node:hover circle,
.tree-node:focus-visible circle { fill: #f7d36f; }
.tree-node.is-selected circle { fill: var(--ochre); stroke: #fff6d8; }
.tree-node.is-final circle { fill: #b9dda9; }
.tree-node.is-pivot circle { fill: #e88462; }
.tree-node-index { fill: #fff !important; font-size: 13px !important; }

.action-panel { display: flex; min-width: 0; flex-direction: column; padding: 28px; background: #f7f0e2; }
.action-panel h4 { margin-bottom: 9px; font-size: 1.55rem; }
.action-panel p { line-height: 1.5; }
.instruction-tag { display: inline-block; margin-bottom: 13px; padding: 5px 8px; color: #fff; background: var(--forest); font-size: .69rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.path-readout { min-height: 48px; margin: 16px 0; padding: 12px; border: 2px dashed var(--paper-dark); background: #fff; line-height: 1.5; }
.path-readout b { display: inline-grid; min-width: 32px; height: 32px; place-items: center; margin: 2px 3px; border: 2px solid; border-radius: 50%; }

.button-row,
.choice-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 15px; }
.choice-list { flex-direction: column; }
.panel-button,
.choice-button,
.text-button,
.sequence-token,
.next-button {
  border: 2px solid var(--ink);
  cursor: pointer;
}
.panel-button,
.choice-button { padding: 11px 13px; color: inherit; background: #fff; box-shadow: 3px 3px 0 var(--ink); text-align: left; }
.panel-button.primary { color: #fff; background: var(--signal); }
.panel-button:hover,
.choice-button:hover { transform: translateY(-2px); }
.choice-button.is-selected { background: var(--ochre); }

.sequence-instruction { margin-bottom: 13px; }
.sequence-slots,
.token-bank { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 9px; }
.sequence-slots { margin: 12px 0 18px; }
.sequence-slot { display: grid; min-height: 54px; place-items: center; padding: 5px; border: 2px dashed var(--moss); background: rgba(255,255,255,.55); color: var(--muted); text-align: center; cursor: pointer; }
.sequence-slot.is-over { background: var(--good); }
.sequence-token { width: 100%; min-height: 44px; padding: 7px; color: inherit; background: #fff; font-weight: 900; box-shadow: 2px 2px 0 var(--ink); }
.sequence-token:hover { background: var(--ochre); }
.token-bank .sequence-token.is-used { display: none; }

.feedback { display: none; margin-top: 20px; padding: 15px; border: 2px dashed; line-height: 1.55; }
.feedback.show { display: block; }
.feedback.good { border-color: var(--moss); background: var(--good); }
.feedback.try { border-color: #9c661b; background: var(--warn); }

.code-bridge { margin-top: 22px; padding-top: 20px; border-top: 3px double var(--ink); }
.bridge-label { display: inline-block; margin-bottom: 9px; padding: 5px 8px; color: #fff; background: var(--blue); font-size: .67rem; font-weight: 900; text-transform: uppercase; }
.code-bridge pre { max-width: 100%; overflow-x: auto; padding: 14px; color: #eef5e9; background: var(--forest-deep); font-size: .79rem; line-height: 1.55; }
.code-bridge p { margin-bottom: 0; font-size: .85rem; }

.help-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: auto; padding-top: 24px; }
.text-button { padding: 7px 0; border-width: 0 0 2px; color: inherit; background: transparent; font-weight: 900; }
.text-button:hover { color: var(--signal); }
#mode-indicator { color: var(--muted); font-size: .69rem; text-align: right; }
.next-button { width: 100%; margin-top: 18px; }

.case-source { display: flex; justify-content: space-between; gap: 20px; padding: 12px 30px; border-top: 2px solid var(--ink); background: var(--paper-dark); font-size: .72rem; line-height: 1.4; }

.source-ledger {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 25px;
  align-items: end;
  padding: 30px;
  border: 2px solid var(--ink);
  background: #e4ead9;
}
.source-ledger p { max-width: 760px; margin: 18px 0 0; line-height: 1.6; }

.page-footer { display: flex; justify-content: space-between; gap: 30px; align-items: flex-end; padding-top: 30px; border-top: 3px double var(--ink); }
.page-footer p { max-width: 700px; margin: 0; font-family: Georgia, serif; font-size: 1.25rem; line-height: 1.5; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

[hidden] { display: none !important; }

@media (max-width: 1020px) {
  .hero { grid-template-columns: 1fr .8fr; min-height: 590px; }
  .workbench { grid-template-columns: 1.25fr .9fr; }
  #tree-svg { min-height: 390px; }
  .module-card { min-height: 330px; }
}

@media (max-width: 820px) {
  .page-shell { width: min(100% - 26px, 720px); }
  .hero { grid-template-columns: 1fr; padding-top: 54px; }
  .hero-board { width: min(520px, 92%); margin: 0 auto; }
  .wobble-strip,
  .control-grid,
  .workbench { grid-template-columns: 1fr; }
  .wobble-strip li { grid-template-columns: 1fr; gap: 4px; }
  .module-grid { grid-template-columns: 1fr; }
  .module-card,
  .module-card:nth-child(2),
  .module-card:nth-child(3) { min-height: 0; transform: none; }
  .module-card p { min-height: 0; }
  .tree-stage { border-right: 0; border-bottom: 2px solid var(--ink); }
  .action-panel { min-height: 470px; }
  .source-ledger { grid-template-columns: auto 1fr; }
  .source-ledger a { grid-column: 2; }
}

@media (max-width: 580px) {
  .page-shell { width: min(100% - 20px, 520px); padding-top: 15px; }
  .topbar { align-items: flex-start; font-size: .68rem; }
  .source-link { text-align: right; }
  .hero { min-height: 0; padding: 50px 0 70px; }
  h1 { font-size: clamp(3.8rem, 22vw, 6.4rem); }
  .hero-board { width: calc(100% - 12px); padding: 18px 15px; }
  .hero-board p { max-width: calc(100% - 96px); }
  .wobble-strip,
  .control-deck { padding: 20px; }
  .section-heading,
  .control-heading,
  .training-heading { flex-direction: column; }
  .segmented { grid-template-columns: 1fr; }
  .segmented button { border-right: 2px solid; border-bottom: 0; }
  .segmented button:last-child { border-bottom: 2px solid; }
  .method-strip { display: grid; grid-template-columns: 1fr 1fr; }
  .method-strip i { display: none; }
  .case-head { padding: 22px 18px; }
  .case-id-block { min-width: 65px; }
  .case-head h3 { font-size: 1.9rem; }
  .support-banner { margin: 18px 18px 0; }
  .tree-stage { padding: 10px; }
  #tree-svg { min-height: 310px; }
  .stage-label { min-height: 58px; }
  .action-panel { min-height: 500px; padding: 22px 18px; }
  .case-source,
  .page-footer { flex-direction: column; align-items: flex-start; }
  .source-ledger { grid-template-columns: 1fr; }
  .source-ledger a { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
