:root {
  --paper: #f3f5f9;
  --sheet: #ffffff;
  --ink: #1d3fae;
  --ink-deep: #14275f;
  --graphite: #262a33;
  --muted: #5d6474;
  --rule: #d5dae5;
  --red: #c0312a;
  --green: #17734a;
  --hl: #ffe45c;
  --hl-new: #c5efd3;
  --hl-del: #f9d5d1;
  --hl-unit: #ffd7a3;
  --f-display: "Bricolage Grotesque", "Segoe UI Variable Display", "Segoe UI", sans-serif;
  --f-body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --f-mono: "JetBrains Mono", "Cascadia Code", Consolas, monospace;
}
* { box-sizing: border-box; }
html { font-size: 17px; }
body { margin: 0; background: var(--paper); color: var(--graphite); font-family: var(--f-body); line-height: 1.55; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--sheet); padding: 8px 12px; z-index: 9; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }
#nav { background: var(--ink-deep); color: #dfe5f7; padding: 28px 0 40px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
#nav .brand { font-family: var(--f-display); font-weight: 700; font-size: 1.35rem; line-height: 1.15; color: #fff; padding: 0 24px 4px; margin: 0; }
#nav a.home { display: block; border: 0; padding: 0 24px 4px; }
#nav a.home::before { content: none; }
#nav a.home:hover { background: none; text-decoration: underline; }
#nav .sub { padding: 0 24px 18px; margin: 0; font-size: .85rem; color: #aab6dc; }
#nav ol { list-style: none; margin: 0; padding: 0; counter-reset: t; }
#nav li { counter-increment: t; }
#nav a { display: grid; grid-template-columns: 26px 1fr auto; gap: 6px; align-items: baseline; padding: 9px 24px; color: inherit; text-decoration: none; border-left: 4px solid transparent; }
#nav a::before { content: counter(t); font-family: var(--f-mono); font-size: .8rem; color: #8f9dcb; }
#nav a:hover { background: rgba(255, 255, 255, .07); }
#nav a[aria-current="page"] { background: var(--paper); color: var(--ink-deep); border-left-color: var(--hl); font-weight: 700; }
#nav a[aria-current="page"]::before { color: var(--ink); }
#nav .count { font-family: var(--f-mono); font-size: .75rem; color: #8f9dcb; }
#nav a[aria-current="page"] .count { color: var(--muted); }
#nav .count.full { color: #7fe0a8; }
#nav a[aria-current="page"] .count.full { color: var(--green); }

main { padding: 40px 48px 96px; max-width: 1080px; }
h1 { font-family: var(--f-display); font-weight: 700; font-size: 2.5rem; line-height: 1.05; letter-spacing: -.02em; margin: 0 0 10px; color: var(--ink-deep); }
h2 { font-family: var(--f-display); font-weight: 700; font-size: 1.3rem; margin: 32px 0 10px; color: var(--ink-deep); }
h3 { font-size: 1rem; margin: 18px 0 6px; }
.lead { font-size: 1.12rem; max-width: 62ch; margin: 0 0 22px; }
p { max-width: 70ch; }
code, .mono { font-family: var(--f-mono); font-size: .92em; }

.V { font-family: var(--f-mono); color: var(--ink); font-weight: 700; }
.T { font-family: var(--f-mono); color: var(--graphite); }
.E { font-family: var(--f-mono); color: var(--red); }
.R { white-space: nowrap; font-family: var(--f-mono); }
.dot { color: var(--red); font-weight: 700; padding: 0 1px; }
.orig { color: var(--muted); font-size: .85em; }

details.recipe { background: var(--sheet); border: 1px solid var(--rule); border-radius: 6px; padding: 0 18px; margin: 0 0 22px; max-width: 760px; }
details.recipe summary { cursor: pointer; padding: 12px 0; font-weight: 700; color: var(--ink-deep); }
details.recipe ol, details.recipe ul { margin: 0 0 14px; padding-left: 22px; }
details.recipe li { margin: 4px 0; }
.trap { border-left: 4px solid var(--red); padding: 2px 0 2px 12px; margin: 0 0 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--ink-deep); margin: 0 0 22px; }
.tabs button { font: inherit; font-weight: 700; border: 0; background: transparent; color: var(--muted); padding: 10px 18px; cursor: pointer; border-radius: 6px 6px 0 0; }
.tabs button[aria-selected="true"] { background: var(--ink-deep); color: #fff; }

label { display: block; font-weight: 700; font-size: .9rem; margin: 0 0 4px; }
textarea, input[type=text], select { font-family: var(--f-mono); font-size: .95rem; width: 100%; border: 1.5px solid var(--rule); border-radius: 6px; padding: 9px 11px; background: var(--sheet); color: var(--graphite); }
textarea { min-height: 128px; resize: vertical; line-height: 1.6; }
select { font-family: var(--f-body); }
textarea:focus, input:focus, select:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px rgba(29, 63, 174, .18); }
.hint { font-size: .85rem; color: var(--muted); margin: 4px 0 0; }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-bottom: 16px; }
.field { margin-bottom: 14px; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 20px; }
button.go { font: inherit; font-weight: 700; background: var(--ink); color: #fff; border: 0; border-radius: 6px; padding: 10px 18px; cursor: pointer; }
button.go:hover { background: var(--ink-deep); }
button.alt { font: inherit; background: var(--sheet); color: var(--ink-deep); border: 1.5px solid var(--ink-deep); border-radius: 6px; padding: 9px 16px; cursor: pointer; }
button.alt:hover { background: #e7ebf7; }
button.link { font: inherit; background: none; border: 0; color: var(--ink); text-decoration: underline; cursor: pointer; padding: 0; }
.err { color: var(--red); font-weight: 700; margin: 8px 0; }

.stage { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; padding: 18px 22px 22px; margin: 0 0 24px; }
.st-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.st-bar .n { font-family: var(--f-mono); font-size: .85rem; color: var(--muted); }
.st-bar .keys { margin-left: auto; font-size: .8rem; color: var(--muted); }
.prog { display: flex; gap: 3px; margin-bottom: 14px; }
.prog i { flex: 1; height: 5px; background: var(--rule); border-radius: 2px; }
.prog i.on { background: var(--ink); }
.phase { font-family: var(--f-display); font-weight: 700; color: var(--ink); margin: 0 0 2px; font-size: .95rem; }
.cap { font-size: 1.05rem; min-height: 3.2em; margin: 0 0 14px; max-width: 74ch; }
.cap .R { background: #eef1f8; padding: 1px 5px; border-radius: 4px; }
.split { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 22px; }

.gram { font-family: var(--f-mono); font-size: 1.05rem; }
.gram .gr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 2px; padding: 7px 0; border-bottom: 1px dashed var(--rule); }
.gram .gr.dead { opacity: .5; }
.gram .lhs { min-width: 64px; }
.gram .alt { padding: 2px 8px; border-radius: 4px; }
.gram .bar { color: #a3aabb; }
.alt.h { background: var(--hl); }
.alt.n { background: var(--hl-new); box-shadow: inset 0 -2px 0 var(--green); }
.alt.d { background: var(--hl-del); text-decoration: line-through; text-decoration-color: var(--red); }
.alt.u { background: var(--hl-unit); }
.gram .none { color: var(--muted); font-style: italic; font-family: var(--f-body); font-size: .9rem; }
.sets { border-left: 2px solid var(--rule); padding-left: 18px; }
.sets .s { margin-bottom: 12px; }
.sets .sl { font-size: .85rem; color: var(--muted); }
.sets .si { font-family: var(--f-mono); font-size: 1.05rem; }
.sets .fresh { background: var(--hl-new); border-radius: 3px; padding: 0 3px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 16px; }
.legend span i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -2px; margin-right: 5px; }

.task { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; padding: 18px 22px; margin-bottom: 18px; }
.task .q { font-size: 1.05rem; margin: 0 0 10px; }
.fb { border-radius: 8px; padding: 14px 18px; margin: 0 0 18px; background: var(--sheet); border: 1px solid var(--rule); }
.fb.ok { border-left: 6px solid var(--green); }
.fb.no { border-left: 6px solid var(--red); }
.fb h3 { margin: 0 0 6px; }
.fb ul { margin: 6px 0; padding-left: 20px; }
.fb .good { color: var(--green); font-weight: 700; }
.fb .bad { color: var(--red); font-weight: 700; }

.cyk { display: grid; gap: 5px; font-family: var(--f-mono); margin: 4px 0 6px; }
.cyk .c { border: 1.5px solid var(--rule); border-radius: 5px; min-height: 44px; display: flex; align-items: center; justify-content: center; padding: 4px; background: var(--sheet); text-align: center; }
.cyk .c.todo { color: transparent; }
.cyk .c.h { background: var(--hl); border-color: #c9a900; }
.cyk .c.p { background: #e3e9fb; border-color: var(--ink); }
.cyk .c.ok { background: var(--hl-new); border-color: var(--green); }
.cyk .c.no { background: var(--hl-del); border-color: var(--red); }
.cyk .w { text-align: center; font-weight: 700; padding-top: 4px; }
.cyk input { text-align: center; padding: 6px 2px; border: 0; background: transparent; width: 100%; }
.cyk .c:focus-within { border-color: var(--ink); }

.earley { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); }
.earley .col h3 { font-family: var(--f-mono); margin: 0 0 6px; border-bottom: 2px solid var(--ink-deep); }
.earley .it { padding: 2px 6px; border-radius: 4px; margin: 2px 0; font-size: .95rem; }
.earley .it.n { background: var(--hl-new); box-shadow: inset 0 -2px 0 var(--green); }
.earley .it.h { background: var(--hl); }
.earley .it.p { background: #e3e9fb; }
.word { font-family: var(--f-mono); font-size: 1.2rem; margin: 0 0 12px; letter-spacing: .1em; }
.word .seen { color: var(--muted); }
.word .cur { background: var(--hl); padding: 0 3px; border-radius: 3px; }
.word .bar { color: var(--red); font-weight: 700; }

.pda { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 26px; align-items: start; }
.tape { display: flex; font-family: var(--f-mono); font-size: 1.2rem; margin: 6px 0 14px; flex-wrap: wrap; }
.tape span { border: 1.5px solid var(--rule); min-width: 34px; height: 40px; display: flex; align-items: center; justify-content: center; margin-right: -1.5px; background: var(--sheet); }
.tape .seen { color: #a3aabb; background: #eef0f5; }
.tape .cur { background: var(--hl); border-color: #c9a900; position: relative; z-index: 1; }
.stack { display: flex; flex-direction: column; font-family: var(--f-mono); font-size: 1.15rem; border: 2px solid var(--ink-deep); border-top: 0; min-height: 150px; justify-content: flex-end; padding: 4px; border-radius: 0 0 6px 6px; }
.stack span { text-align: center; border: 1.5px solid var(--rule); margin-top: -1.5px; padding: 3px 0; background: var(--sheet); }
.stack span:first-child { background: var(--hl); }
.stack .mt { border: 0; color: var(--muted); font-family: var(--f-body); font-size: .85rem; background: none !important; }
.state { font-family: var(--f-mono); font-size: 1.1rem; display: inline-block; border: 2px solid var(--ink); border-radius: 999px; padding: 3px 16px; color: var(--ink); font-weight: 700; }
.state.fin { box-shadow: 0 0 0 3px var(--sheet), 0 0 0 5px var(--ink); }
.verdict { font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; }
.verdict.yes { color: var(--green); }
.verdict.no { color: var(--red); }

.pump { font-family: var(--f-mono); font-size: 1.35rem; margin: 10px 0; word-break: break-all; }
.pump .pu, .pump .pz { color: var(--muted); }
.pump .pv { background: var(--hl); }
.pump .px { background: #e3e9fb; }
.pump .py { background: var(--hl-unit); }
.sliders { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px 22px; margin: 12px 0; }
.sliders label { font-weight: 400; }
input[type=range] { width: 100%; accent-color: var(--ink); }
table.pt { border-collapse: collapse; font-family: var(--f-mono); margin: 10px 0; }
table.pt td, table.pt th { border-bottom: 1px solid var(--rule); padding: 6px 14px 6px 0; text-align: left; }
table.pt th { font-family: var(--f-body); font-size: .85rem; color: var(--muted); }

.cards { display: grid; gap: 12px; max-width: 800px; }
.card { background: var(--sheet); border: 1px solid var(--rule); border-radius: 8px; }
.card summary { cursor: pointer; padding: 14px 18px; font-weight: 700; }
.card .a { padding: 0 18px 14px; border-top: 1px dashed var(--rule); }
.road { list-style: none; padding: 0; margin: 0; max-width: 760px; counter-reset: r; }
.road li { counter-increment: r; border-bottom: 1px solid var(--rule); }
.road a { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 14px 4px; text-decoration: none; color: inherit; align-items: baseline; }
.road a::before { content: counter(r); font-family: var(--f-display); font-weight: 700; font-size: 1.3rem; color: var(--ink); }
.road a:hover b { text-decoration: underline; }
.road small { display: block; color: var(--muted); font-size: .9rem; }
.road .count { font-family: var(--f-mono); font-size: .85rem; color: var(--muted); }
.road .count.full { color: var(--green); font-weight: 700; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  #nav { position: static; height: auto; padding: 16px 0 8px; }
  #nav ol { display: flex; overflow-x: auto; }
  #nav a { white-space: nowrap; border-left: 0; border-bottom: 4px solid transparent; padding: 8px 14px; }
  #nav a[aria-current="page"] { border-bottom-color: var(--hl); }
  main { padding: 24px 16px 64px; }
  h1 { font-size: 1.9rem; }
  .row, .split, .pda { grid-template-columns: 1fr; }
  .sets { border-left: 0; padding-left: 0; border-top: 2px solid var(--rule); padding-top: 12px; }
}
@media (prefers-reduced-motion: no-preference) {
  .alt.n, .earley .it.n { animation: pop .35s ease-out; }
  @keyframes pop { from { transform: scale(.85); } to { transform: none; } }
}
