:root {
  --paper: #FAF8F4;
  --card: #fffefa;
  --ink: #1f2420;
  --muted: #545c54;
  --rule: #ddd8cc;
  --green: #176348;
  --pale: #e3efe6;
  --red: #a8261d;
  --pale-red: #f8e4e1;
  --amber: #8a5a00;
  --blue: #1f4e8c;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; color: var(--ink); background: var(--paper); font: 17px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--green); }
:focus-visible { outline: 3px solid #276cb0; outline-offset: 3px; }
.skip { position: absolute; top: -80px; left: 12px; padding: 10px; background: var(--card); z-index: 5; }
.skip:focus { top: 8px; }

.mast { display: flex; align-items: center; gap: 16px; max-width: 1240px; margin: 0 auto; padding: 14px 24px; border-bottom: 1px solid var(--rule); }
.brand { font-weight: 760; font-size: 20px; color: var(--ink); text-decoration: none; letter-spacing: -.4px; }
.mast-topic { color: var(--muted); font-size: 14px; }
.mast-link { margin-left: auto; font-size: 15px; }

main { max-width: 1240px; margin: 0 auto; padding: 26px 24px 40px; }
.intro { max-width: 760px; }
.eyebrow, .part { font-family: var(--mono); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--green); font-weight: 700; margin: 0 0 6px; }
h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: 40px; line-height: 1.1; letter-spacing: -1px; margin: 0 0 10px; }
h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 500; font-size: 28px; line-height: 1.15; margin: 0 0 10px; }
h3 { font-size: 18px; margin: 0 0 6px; }
.intro p { margin: 0 0 18px; color: var(--muted); }

.rungs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 22px; }
.rungs a { display: inline-block; padding: 9px 14px; min-height: 44px; border: 1px solid var(--rule); border-radius: 22px; background: var(--card); color: var(--ink); text-decoration: none; font-size: 15px; line-height: 24px; }
.rungs a:hover { border-color: var(--green); }
.rungs a[aria-current="page"] { background: var(--green); border-color: var(--green); color: #fff; font-weight: 650; }

.rung { display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }
.rung[hidden] { display: none; }
.rung-text, .rung-stage { min-width: 0; }
.rung-text > p { margin: 0 0 14px; }
.rung-stage { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 14px; }

.predict { border: 1px solid var(--rule); border-radius: 12px; background: var(--card); padding: 14px 16px 12px; margin: 0 0 16px; }
.predict legend { font-weight: 700; padding: 0 6px; }
.question { margin: 0 0 10px; font-weight: 600; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; margin: 0 0 6px; border: 1px solid var(--rule); border-radius: 8px; cursor: pointer; min-height: 44px; }
.choice:hover { border-color: var(--green); }
.choice input { margin-top: 5px; accent-color: var(--green); flex: none; }
.choice:has(input:checked) { border-color: var(--green); background: var(--pale); }
button { font: inherit; color: inherit; background: var(--card); border: 1px solid #b9c1b7; border-radius: 8px; min-height: 44px; padding: 8px 14px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--green); background: var(--pale); }
button:disabled { opacity: .5; cursor: default; }
.lock { margin-top: 6px; background: var(--green); border-color: var(--green); color: #fff; font-weight: 650; }
.lock:hover:not(:disabled) { background: #104431; color: #fff; }
.record { margin: 8px 0 0; color: var(--muted); font-size: 15px; min-height: 1.4em; }

.reveal { border-left: 4px solid var(--red); background: var(--pale-red); border-radius: 0 10px 10px 0; padding: 12px 16px; }
.reveal.is-right, .reveal.is-fixed { border-left-color: var(--green); background: var(--pale); }
.reveal.is-fixed h3, .reveal.is-fixed .verdict { color: var(--green); }
.reveal.is-fixed .next-step { color: var(--ink); }
.reveal p { margin: 0 0 8px; }
.verdict { font-weight: 700; }
.next-step { color: var(--muted); }

.stage { display: block; width: 100%; height: auto; }
.caption { min-height: 3.1em; margin: 6px 0 10px; font-size: 17px; font-weight: 600; }
.scrub { display: flex; align-items: center; gap: 12px; margin: 0 0 12px; }
.scrub label { font-weight: 650; }
.scrub input { flex: 1; min-width: 0; accent-color: var(--green); min-height: 44px; }
.scrub output { font-family: var(--mono); font-size: 14px; color: var(--muted); white-space: nowrap; }
.rule-toggle { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.rule-toggle button[aria-pressed="true"], .rule-toggle button[aria-pressed="true"]:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); color: #fff; }
.rule-toggle button[data-rule="fixed"][aria-pressed="true"], .rule-toggle button[data-rule="fixed"][aria-pressed="true"]:hover:not(:disabled) { background: var(--green); border-color: var(--green); }
.logic { margin: 0; padding: 12px 14px; background: #f3f0e8; border: 1px solid var(--rule); border-radius: 8px; font: 14px/1.5 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
p code, .question code { font: 0.92em var(--mono); background: #efeadf; border: 1px solid var(--rule); border-radius: 4px; padding: 0 4px; }
dfn { font-style: normal; font-weight: 700; }

/* SVG stage */
.panel-title { font: 700 22px system-ui, sans-serif; fill: var(--muted); }
.card rect { fill: #fffefa; stroke: #9aa398; stroke-width: 2; }
.card text { font: 600 22px var(--mono); fill: var(--ink); }
.card.run rect { fill: #dbe7f5; stroke: var(--blue); stroke-width: 3; }
.card.check rect { fill: #fffefa; stroke: var(--blue); stroke-width: 3; stroke-dasharray: 8 5; }
.card.bad rect { fill: var(--pale-red); stroke: var(--red); stroke-width: 4; }
.card.ok rect { fill: var(--pale); stroke: var(--green); stroke-width: 3; }
.card.dim rect { fill: #f1eee7; stroke: #c4beb1; }
.card.dim text { fill: #8c877d; }
.box-frame { fill: none; stroke: var(--amber); stroke-width: 3; stroke-dasharray: 10 6; }
.box-tag { font: 700 22px system-ui, sans-serif; fill: var(--amber); }
.border-line { stroke: var(--green); stroke-width: 5; }
.tray-base { stroke: #6f776e; stroke-width: 4; }
.tile rect { fill: #e3efe6; stroke: var(--green); stroke-width: 2; }
.tile text { font: 700 22px var(--mono); text-anchor: middle; fill: var(--ink); }
.tile.ghost rect { fill: #fffefa; stroke: var(--blue); stroke-dasharray: 6 4; }
.tile.bad rect { fill: var(--pale-red); stroke: var(--red); }
.tray-empty { font: 600 22px system-ui, sans-serif; text-anchor: middle; fill: #8c877d; }
.screen rect { fill: #1f2420; }
.screen text { font: 700 22px var(--mono); text-anchor: middle; fill: #fff; }
.screen.blank text { fill: #9aa398; }
.arrow { fill: none; stroke: var(--blue); stroke-width: 3; }
.arrow-head { fill: var(--blue); }
.arrow.ok { stroke: var(--green); }
.arrow-head.ok { fill: var(--green); }
.arrow.rejected { stroke: var(--red); stroke-dasharray: 6 5; opacity: .8; }
.reject-mark { font: 800 28px system-ui, sans-serif; text-anchor: middle; fill: var(--red); }
.alarm { font: 800 24px system-ui, sans-serif; text-anchor: middle; fill: var(--red); }
.alarm.good { fill: var(--green); }
.room rect { fill: var(--pale); stroke: var(--green); stroke-width: 3; }
.outside rect { fill: #f1eee7; stroke: #a7a196; stroke-width: 2; stroke-dasharray: 6 5; }
.room text, .outside text { font: 700 22px system-ui, sans-serif; text-anchor: middle; fill: var(--ink); }
.outside text { fill: var(--muted); }
.wall { stroke: var(--red); stroke-width: 6; }
.wall-label { font: 700 22px system-ui, sans-serif; text-anchor: middle; fill: var(--red); }
.mark { stroke-width: 3; }
.mark.ok { fill: #8fc4a5; stroke: var(--green); }
.mark.bad { fill: #e9a49c; stroke: var(--red); }
.mark.fake { fill: #fbeccf; stroke: var(--amber); stroke-dasharray: 5 4; }
.mark-label { font: 700 22px system-ui, sans-serif; text-anchor: middle; fill: var(--ink); }
.mark-label.start { text-anchor: start; }
.mark-label.end { text-anchor: end; }
.dial rect { fill: #fffefa; stroke: #6f776e; stroke-width: 2; }
.dial text { font: 700 22px var(--mono); text-anchor: middle; fill: var(--ink); }

.notebook { margin-top: 32px; border-top: 1px solid var(--rule); padding-top: 18px; max-width: 760px; }
.notebook p { color: var(--muted); margin: 0 0 8px; }
.entries { margin: 0; padding-left: 22px; }
footer { display: flex; flex-wrap: wrap; gap: 18px; max-width: 1240px; margin: 0 auto; padding: 18px 24px 30px; border-top: 1px solid var(--rule); font-size: 15px; }
.noscript { max-width: 760px; margin: 0 auto 30px; padding: 0 24px; }

@media (min-width: 960px) {
  .rung { grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr); align-items: start; gap: 32px; }
  h1 { font-size: 46px; }
}
@media (max-width: 620px) {
  body { font-size: 16px; }
  .mast { padding: 12px 16px; gap: 10px; }
  .mast-topic { display: none; }
  main { padding: 20px 16px 32px; }
  h1 { font-size: 32px; }
  h2 { font-size: 25px; }
  .rungs a { font-size: 14px; padding: 9px 11px; }
  .rung-stage { padding: 10px; }
  .logic { font-size: 13px; }
  footer { padding: 16px; }
}
@media (prefers-reduced-motion: no-preference) {
  .choice, button, .rungs a { transition: border-color .15s, background-color .15s; }
}
