:root {
    --bg: #f2f7f2;
    --paper: #fff;
    --ink: #112015;
    --muted: #405b46;
    --brand: #146356;
    --line: #dce9dd;
    --radius: 18px;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: radial-gradient(ellipse at top left, #d9ecdf, transparent 55%), var(--bg);
    color: var(--ink);
    font-family: "Space Grotesk", "Segoe UI", sans-serif;
    line-height: 1.65;
}
a { color: var(--brand); text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #b5750a; outline-offset: 4px; }
.skip-link { position: absolute; left: 1rem; top: -5rem; z-index: 10; padding: .6rem 1rem; background: white; }
.skip-link:focus { top: 1rem; }
.site-nav {
    width: min(1120px, 92vw);
    margin: 1.2rem auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.wordmark { font-weight: 700; font-size: 1.2rem; text-decoration: none; letter-spacing: -.04em; }
.wordmark span { color: #597461; font-weight: 400; }
.site-nav > div { display: flex; gap: 1.2rem; font-size: .9rem; }
.guide-wrap { width: min(1120px, 92vw); margin: 0 auto 3rem; }
.guide-hero {
    position: relative;
    overflow: hidden;
    padding: clamp(1.5rem, 5vw, 3.4rem);
    background: linear-gradient(135deg, #146356, #09352d);
    color: #f7fff9;
    border-radius: 28px;
    box-shadow: 0 18px 60px #0f361f24;
}
.guide-hero::after {
    content: "";
    position: absolute;
    width: 350px;
    height: 350px;
    right: -180px;
    top: -180px;
    border: 45px solid #f59e0b22;
    border-radius: 50%;
    pointer-events: none;
}
.eyebrow { font-family: "IBM Plex Mono", Consolas, monospace; text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; }
.guide-hero h1 { font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.08; letter-spacing: -.04em; max-width: 21ch; margin: .8rem 0 1rem; }
.guide-hero p:last-child { max-width: 68ch; color: #d2ebdb; margin-bottom: 0; }
.guide-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 2rem; margin-top: 2rem; align-items: start; }
.guide-toc { position: sticky; top: 1rem; padding: 1rem 0; }
.guide-toc h2 { font-size: .75rem; text-transform: uppercase; letter-spacing: .12em; margin: 0 0 .8rem; color: var(--muted); }
.guide-toc ol { list-style: none; padding: 0; margin: 0; }
.guide-toc a { display: block; padding: .55rem .7rem; border-radius: 9px; text-decoration: none; font-size: .88rem; }
.guide-toc a:hover { background: #e1eee4; }
.guide-toc a[aria-current="page"] { background: #146356; color: white; }
.guide-article { min-width: 0; }
.guide-article section { margin-bottom: 1.4rem; padding: clamp(1rem, 3vw, 1.8rem); background: #ffffffdc; border: 1px solid var(--line); border-radius: var(--radius); }
.guide-article h2 { font-size: 1.45rem; line-height: 1.2; color: #0f3f31; margin: 0 0 1rem; letter-spacing: -.025em; }
.guide-article h3 { font-size: 1.05rem; color: #114738; margin: 1.4rem 0 .35rem; }
.guide-article p { margin: .6rem 0 1rem; }
.guide-article li { margin-bottom: .5rem; }
.guide-article ul, .guide-article ol { padding-left: 1.3rem; }
code, pre { font-family: "IBM Plex Mono", Consolas, monospace; font-size: .84em; }
code { overflow-wrap: anywhere; }
p code, li code, dd code { background: #e8f3ec; padding: .12em .3em; border-radius: 4px; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; background: #091b14; color: #cbf3d4; padding: 1.2rem; border-radius: 12px; line-height: 1.7; }
pre code { font-size: inherit; }
.callout { border-left: 3px solid #b5750a; padding: .5rem 1rem; background: #fff7e8; border-radius: 0 9px 9px 0; }
.source-links { font-size: .85rem; color: var(--muted); }
.source-links a { display: inline-block; margin: .2rem .6rem .2rem 0; }
.next-page { display: flex; justify-content: space-between; gap: 1rem; margin: 1.8rem 0; flex-wrap: wrap; }
.site-footer { width: min(1120px, 92vw); margin: 2rem auto; text-align: center; font-size: .85rem; color: #4f6d59; }
.contents-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; list-style: none; padding: 0; counter-reset: chapters; }
.contents-grid li { counter-increment: chapters; }
.contents-grid a { display: block; height: 100%; padding: 1.1rem; background: white; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; transition: transform .2s, box-shadow .2s; }
.contents-grid a::before { content: "0" counter(chapters); display: block; font: .75rem "IBM Plex Mono", Consolas, monospace; color: #597461; margin-bottom: .5rem; }
.contents-grid a:hover { transform: translateY(-3px); box-shadow: 0 10px 24px #12362019; }
.contents-grid strong { display: block; margin-bottom: .4rem; color: #114738; }
.contents-grid span { font-size: .9rem; color: #405b46; line-height: 1.5; }
.explainer { margin: 1.4rem 0 0; }
.diagram {
    border: 1px solid #284d3f;
    border-radius: 14px;
    background: radial-gradient(ellipse at 50% 0, #173f32, #091b14 80%);
    padding: .7rem;
    overflow-x: auto;
}
.diagram svg { display: block; width: 100%; min-width: 560px; height: auto; }
.diagram text { fill: #d7efe1; font-family: "Space Grotesk", "Segoe UI", sans-serif; font-size: 16px; text-anchor: middle; }
.diagram .small { font-family: "IBM Plex Mono", Consolas, monospace; font-size: 11px; fill: #a1c2af; }
.diagram .node rect { fill: #122f25; stroke: #3e6c56; stroke-width: 1.5; transition: fill .4s, stroke .4s; }
.diagram .node.is-current rect { fill: #21553e; stroke: #86efac; stroke-width: 2; }
.diagram .node.is-complete rect { fill: #183c2d; stroke: #649b7c; }
.diagram .blue rect { fill: #102e3f; stroke: #5081a0; }
.diagram .amber rect { fill: #392e18; stroke: #a58648; }
.diagram .wire { fill: none; stroke: #375b49; stroke-width: 2; }
.diagram .signal { fill: none; stroke: #86efac; stroke-width: 4; stroke-linecap: round; stroke-dasharray: 3 97; opacity: 0; }
.diagram .signal.is-current { opacity: 1; animation: transmit 2.4s linear infinite; filter: drop-shadow(0 0 4px #86efac80); }
.diagram .blue.signal { stroke: #7dd3fc; }
.diagram .amber.signal { stroke: #fcd34d; }
.diagram .memory-cell { fill: #204b36; stroke: #446f55; }
.diagram .is-current .memory-cell { animation: cell-pulse 1.4s ease-in-out infinite alternate; }
.diagram .is-current .memory-cell:nth-child(2) { animation-delay: .2s; }
.diagram .is-current .memory-cell:nth-child(3) { animation-delay: .4s; }
.animation-toolbar { display: none; align-items: center; justify-content: space-between; gap: .7rem; margin: 1rem 0; flex-wrap: wrap; }
.explainer.ready .animation-toolbar { display: flex; }
.animation-toolbar > div { display: flex; gap: .5rem; }
.animation-toolbar button { font: inherit; font-size: .8rem; background: white; border: 1px solid #a7c8b4; border-radius: 999px; color: #164d38; padding: .4rem .85rem; cursor: pointer; }
.animation-toolbar button:hover { background: #e8f3ec; }
.animation-status { font: .7rem "IBM Plex Mono", Consolas, monospace; color: var(--muted); }
.guide-article .animation-steps { list-style: none; padding: 0; display: grid; gap: .5rem; }
.animation-steps li { margin: 0; border-left: 2px solid #dce9dd; padding: .65rem .85rem; transition: background .3s, border-color .3s; }
.animation-steps button { color: #164d38; font: inherit; font-weight: 700; border: 0; background: none; padding: 0; text-align: left; }
.explainer.ready .animation-steps button { cursor: pointer; }
.animation-steps .step-detail { display: block; color: var(--muted); font-size: .9rem; margin-top: .25rem; }
.animation-steps .is-current { border-color: #146356; background: #eaf4ed; border-radius: 0 8px 8px 0; }
.explainer.is-paused .diagram *, .explainer.is-paused .diagram *::after { animation-play-state: paused !important; }
figcaption { color: var(--muted); font-size: .8rem; margin: .8rem 0; }
@keyframes transmit { from { stroke-dashoffset: 100; } to { stroke-dashoffset: 0; } }
@keyframes cell-pulse { to { fill: #67bd86; } }
@media (max-width: 850px) {
    .guide-layout { grid-template-columns: 1fr; gap: 1rem; }
    .guide-toc { position: static; padding: 0; }
    .guide-toc ol { display: flex; flex-wrap: wrap; gap: .2rem; }
    .guide-toc a { border: 1px solid var(--line); padding: .4rem .6rem; font-size: .8rem; }
}
@media (max-width: 540px) {
    .contents-grid { grid-template-columns: 1fr; }
    .wordmark span { display: none; }
    .site-nav > div { gap: .8rem; }
    .guide-hero { border-radius: 18px; }
    .guide-article section { padding: 1rem; }
    .diagram { padding: .2rem; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
    .hero, .section { opacity: 1 !important; transform: none !important; }
    .contents-grid a:hover { transform: none; }
    .diagram .signal.is-current { stroke-dasharray: none; opacity: .7; }
}
