:root {
  color-scheme: light;
  --bg: #f1f2ed;
  --surface: #fdfdf9;
  --panel: #e7ebe2;
  --line: #d8ddd3;
  --ink: #1a2620;
  --muted: #526159;
  --accent: #246246;
  --accent-soft: #e1eddd;
  --hero: #1a3c31;
  --hero-ink: #f1f6e8;
  --lime: #d9f27d;
  --code: #18251e;
  --code-ink: #eef4e9;
  --focus: #367b52;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "DejaVu Sans Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #131d18; --surface: #1b2922; --panel: #23362b; --line: #34483b;
    --ink: #e9f0e7; --muted: #a6b8ab; --accent: #a9e0ac; --accent-soft: #2c4635;
    --hero: #1c382e; --focus: #a9e0ac;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131d18; --surface: #1b2922; --panel: #23362b; --line: #34483b;
  --ink: #e9f0e7; --muted: #a6b8ab; --accent: #a9e0ac; --accent-soft: #2c4635;
  --hero: #1c382e; --focus: #a9e0ac;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 1rem/1.55 var(--sans); }
a { color: var(--accent); }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 3px;
}
h1, h2, h3, p { margin: 0; }
pre, code, kbd, .eyebrow, .version { font-family: var(--mono); }
.muted { color: var(--muted); }
.sr-only, .copy-buffer, .skip:not(:focus) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%);
}
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 10; padding: .6rem 1rem; background: var(--surface); }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 91rem; margin: auto; display: grid; grid-template-columns: minmax(9rem, 14rem) minmax(8rem, 26rem) 1fr;
  align-items: center; gap: 1.4rem; min-height: 4.45rem; padding: .6rem clamp(1rem, 3vw, 3.3rem);
}
.brand { color: var(--ink); display: flex; align-items: center; gap: .7rem; text-decoration: none; font-weight: 800; font-size: 1.25rem; letter-spacing: -.055em; }
.brand-mark { display: grid; place-items: center; background: #1a3c31; color: #d9f27d; font: 1.35rem/1 var(--mono); width: 2.1rem; height: 2.1rem; border-radius: .55rem; }
.brand-ref { color: var(--accent); }
.search-open { background: var(--bg); border: 1px solid var(--line); display: flex; align-items: center; gap: .6rem; border-radius: .55rem; padding: .46rem .68rem; color: var(--muted); text-align: left; min-height: 2.45rem; min-width: 0; font-size: .88rem; }
.search-open span { flex: 1; }
svg { display: block; }
.search-open svg, .icon-button svg { width: 1.15rem; height: 1.15rem; stroke: currentColor; fill: none; stroke-width: 1.65; stroke-linecap: round; }
kbd { border: 1px solid var(--line); border-radius: .28rem; padding: .05rem .37rem; font-size: .82rem; }
.icon-button { display: grid; place-items: center; justify-self: end; width: 2.45rem; height: 2.45rem; border: 1px solid var(--line); border-radius: .55rem; background: var(--surface); }
.icon-button:hover, .search-open:hover { background: var(--panel); }

.layout { max-width: 91rem; min-height: calc(100vh - 4.5rem); margin: auto; padding: 0 clamp(1rem, 3vw, 3.3rem); display: grid; grid-template-columns: minmax(9.5rem, 13rem) minmax(0, 1fr); gap: clamp(1.5rem, 3.2vw, 3.8rem); }
.sidebar { display: flex; flex-direction: column; align-items: stretch; align-self: start; position: sticky; top: 0; padding: 2.35rem 0 1.5rem; min-height: min(84vh, 40rem); }
.nav-label, .eyebrow { color: var(--accent); font: 700 .78rem/1.45 var(--mono); letter-spacing: .12em; text-transform: uppercase; }
.nav-label { margin: 0 .7rem .85rem; color: var(--muted); }
.sidebar nav a { display: flex; gap: .6rem; align-items: center; color: var(--muted); font-weight: 600; padding: .58rem .7rem; margin-bottom: .25rem; border-radius: .52rem; text-decoration: none; white-space: nowrap; font-size: .92rem; }
.sidebar nav a:hover, .sidebar nav a[aria-current] { background: var(--accent-soft); color: var(--accent); }
.nav-icon { width: 1.1rem; text-align: center; font-size: 1.05rem; line-height: 1; }
.sidebar-foot { border-top: 1px solid var(--line); margin-top: auto; padding: .8rem .3rem; display: flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .8rem; }
.version { background: var(--panel); border: 1px solid var(--line); border-radius: .25rem; padding: .03rem .3rem; }
main { min-width: 0; padding: 2.25rem 0 3.5rem; outline: none; }

.hero {
  position: relative; min-height: 23rem; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(12rem, .9fr); align-items: center;
  color: var(--hero-ink); background: var(--hero); border-radius: 1.12rem;
  border: 1px solid #355448; padding: clamp(1.45rem, 4vw, 3.7rem); gap: 1.4rem;
}
.hero .eyebrow { color: var(--lime); margin-bottom: 1.15rem; display: flex; align-items: center; gap: .55rem; }
.hero h1 { font-size: clamp(2.7rem, 5.4vw, 5rem); line-height: .99; letter-spacing: -.072em; font-weight: 780; }
.hero h1 em { font-style: normal; color: var(--lime); }
.hero-copy > p:not(.eyebrow) { color: #cfdfd0; margin-top: 1.25rem; max-width: 35ch; }
.hero-actions { margin-top: 1.5rem; display: flex; flex-wrap: wrap; gap: .55rem; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 2.6rem; padding: .48rem .8rem; border: 1px solid transparent; text-decoration: none; border-radius: .5rem; font-weight: 700; font-size: .9rem; }
.button.primary { background: var(--lime); color: #1b3424; }
.button.primary:hover { background: #ebffad; }
.button.secondary { border-color: var(--line); color: var(--ink); background: var(--surface); }
.button.secondary:hover { background: var(--panel); }
.hero .button.secondary { border-color: #769184; color: var(--hero-ink); background: transparent; }
.hero .button.secondary:hover { background: #2b5042; }
.hero-graphic { min-width: 0; }
.hero-graphic svg { width: 100%; }
.graphic-grid { fill: #497160; }
.graphic-path { fill: none; stroke-width: 2; }
.graphic-path.soft { stroke: #688676; stroke-dasharray: 3 5; }
.graphic-path.accent { stroke: #a8ca76; }
.graphic-node { fill: #274a3a; stroke: #8eac7a; stroke-width: 1.4; }
.graphic-node.active { fill: var(--lime); stroke: var(--lime); }
.graphic-node.faded { fill: #244438; stroke: #6d8a79; }
.hero-graphic text { text-anchor: middle; dominant-baseline: middle; fill: #e7f2d7; font: 20px var(--mono); }
.hero-graphic text:nth-of-type(1), .hero-graphic text:nth-of-type(4) { fill: #182c20; }
.hero-graphic text.caption { fill: #a8c2b1; font-size: 12px; }

.home-section { margin-top: 2rem; }
.section-top { display: flex; justify-content: space-between; align-items: end; gap: .75rem; margin-bottom: .9rem; }
.section-top h2 { font-size: 1.65rem; letter-spacing: -.045em; line-height: 1.2; margin-top: .2rem; }
.section-hint { color: var(--muted); font-size: .88rem; }
.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.home-cards, .year-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { display: block; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: .8rem; padding: 1rem 1.12rem; text-decoration: none; }
.card:hover { border-color: var(--accent); }
.card h2, .card h3 { font-size: 1.08rem; line-height: 1.25; margin: .4rem 0; letter-spacing: -.025em; }
.card p { color: var(--muted); font-size: .94rem; }
.home-card { display: flex; flex-direction: column; align-items: start; }
.card-meta { display: block; color: var(--accent); font-size: .81rem; font-weight: 680; }
.home-card .card-meta { margin-top: auto; padding-top: .85rem; }
.tile-icon { display: grid; place-items: center; width: 1.95rem; height: 1.95rem; margin-bottom: .35rem; background: var(--accent-soft); color: var(--accent); border-radius: .48rem; font-size: 1.15rem; font-weight: 700; }
.page-heading { margin: .2rem 0 1.45rem; }
.page-heading h1 { font-size: clamp(1.9rem, 5vw, 3.15rem); line-height: 1.09; letter-spacing: -.055em; margin: .38rem 0 .65rem; overflow-wrap: anywhere; }
.intro { color: var(--muted); font-size: 1.02rem; max-width: 65ch; }
.intro:empty { display: none; }
.breadcrumb { font-size: .93rem; display: inline-block; margin-bottom: .68rem; }
.filters, .tag-row { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
.filters { margin-bottom: 1.05rem; }
.filter, .pill { font-size: .86rem; border-radius: .45rem; }
.filter { border: 1px solid var(--line); background: var(--surface); padding: .4rem .6rem; }
.filter:hover, .filter[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: var(--accent); }
.pill { color: var(--accent); background: var(--accent-soft); padding: .2rem .5rem; font-weight: 640; }
.algorithm-card h2 { margin-top: 0; }
.algorithm-complexity { display: flex; align-items: baseline; flex-wrap: wrap; column-gap: .7rem; row-gap: .2rem; margin-top: .55rem; color: var(--muted); font-size: .86rem; }
.algorithm-complexity span { white-space: nowrap; }
.algorithm-complexity span + span::before { content: "·"; margin-right: .7rem; color: var(--muted); }
.algorithm-complexity code, .algorithm-card p code { color: var(--accent); font-weight: 650; }
.algorithm-card .algorithm-complexity { font-size: .83rem; }
.algorithm-detail .page-heading { margin-bottom: .9rem; }
.algorithm-detail .page-heading h1 { margin-top: .05rem; }
.algorithm-detail .breadcrumb { margin-bottom: .4rem; }
.algorithm-conditions { max-width: 88ch; }
.algorithm-conditions h2 { font-size: 1.03rem; }
.algorithm-conditions ul { margin: .32rem 0 .85rem; padding-inline-start: 1.18rem; }
.algorithm-conditions li + li { margin-top: .26rem; }
.algorithm-conditions code, .memory-guide code, .algorithm-detail .intro code {
  background: var(--accent-soft); color: var(--accent); border-radius: .23rem; padding: .07rem .25rem; font-size: .9em;
}
.algorithm-detail .detail-block { max-width: 88ch; margin-block: 1.35rem; }
.algorithm-example { display: flex; align-items: stretch; gap: .6rem; }
.algorithm-example .usage { flex: 1; min-width: 0; margin: 0; }
.example-answer { display: grid; align-content: center; gap: .25rem; min-width: 6rem; padding: .55rem .8rem; border-radius: .65rem; background: var(--accent-soft); color: var(--accent); }
.example-answer span { font-size: .8rem; }
.example-answer samp { font: 700 1.1rem var(--mono); }
.memory-guide { padding: .9rem 1rem; border-radius: .65rem; border: 1px solid var(--line); border-inline-start: .28rem solid var(--accent); background: var(--surface); }
.memory-guide ol { padding-inline-start: 1.35rem; margin: .5rem 0 .1rem; }
.memory-guide li { padding-inline-start: .16rem; }
.memory-guide li + li { margin-top: .35rem; }
.verification-runs { list-style: none; margin: 0; padding: 0; border-block: 1px solid var(--line); }
.verification-runs li { padding: .65rem 0; }
.verification-runs li + li { border-top: 1px solid var(--line); }
.check-title { font-weight: 660; }
.check-result { display: flex; flex-wrap: wrap; align-items: baseline; gap: .15rem .5rem; margin-top: .2rem; color: var(--muted); font-size: .9rem; }
.check-status { font-weight: 650; color: var(--ink); }
.practice-links { margin: .75rem 0; }
.practice-links h3 { font-size: .95rem; }
.practice-links .source-list { margin-block: .25rem .7rem; }
.verification-details summary { cursor: pointer; font-weight: 650; color: var(--accent); padding-block: .3rem; }
.verification-details .usage, .verification-details p { margin-top: .4rem; }
.badges { margin-bottom: 1.4rem; }
.detail-block { max-width: 76ch; margin: 1.1rem 0; }
.detail-block h2, .code-header h2 { font-size: 1.16rem; margin-bottom: .46rem; }
.code-panel, .usage { overflow: hidden; border-radius: .7rem; }
.code-panel { color: var(--code-ink); background: var(--code); margin: 1.5rem 0; border: 1px solid #34493d; }
.code-header { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: space-between; align-items: center; border-bottom: 1px solid #34493d; padding: .65rem .95rem; }
.code-header h2 { font: 700 .88rem var(--mono); margin: 0; }
.code-header .button { color: var(--code-ink); background: #283d31; border-color: #536a5b; margin-left: .3rem; }
.code-header .button:hover { background: #385342; }
.algorithm-detail .code-panel { margin-top: .85rem; }
.algorithm-detail .code-panel pre { max-height: min(54vh, 27rem); overflow: auto; }
.algorithm-detail .code-panel pre:focus-visible { outline: 2px solid var(--lime); outline-offset: -2px; }
.code-actions { display: flex; flex-wrap: wrap; gap: .36rem; }
.code-actions .button { margin: 0; }
.code-actions .copy-code { background: var(--lime); color: #1b3424; border-color: var(--lime); }
.code-actions .copy-code:hover { background: #ebffad; }
.button.small { min-height: 2rem; font-size: .82rem; padding: .24rem .55rem; }
.code-panel pre, .usage { padding: .9rem 1rem; margin: 0; overflow-x: auto; font: .88rem/1.58 var(--mono); }
.usage { border: 1px solid var(--line); background: var(--surface); margin-bottom: .65rem; }
.tok-preprocessor { color: #a7c1aa; }
.tok-keyword { color: #d9f27d; }
.tok-number { color: #f2c986; }
.list-panel { border: 1px solid var(--line); background: var(--surface); border-radius: .7rem; margin-bottom: 1.1rem; overflow: hidden; }
.list-row { display: flex; align-items: center; gap: .7rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 620; }
.list-row:last-child { border: 0; }
.list-row:hover { background: var(--accent-soft); color: var(--accent); }
.task-letter { color: var(--accent); background: var(--accent-soft); padding: .08rem .34rem; min-width: 1.5rem; text-align: center; border-radius: .26rem; font-family: var(--mono); }
.solution, .notice { border: 1px solid var(--line); background: var(--surface); padding: .85rem 1rem; margin: 1rem 0; border-radius: .62rem; }
.solution summary { cursor: pointer; font-weight: 700; }
.solution p { margin-top: .75rem; }
.source-list { padding-left: 1.25rem; margin-top: .5rem; }
.prose { max-width: 68rem; padding: clamp(.9rem, 3vw, 1.8rem); border: 1px solid var(--line); border-radius: .8rem; background: var(--surface); overflow-wrap: anywhere; }
.prose p, .prose ul, .prose ol { margin-block: 0 .85rem; }
.prose .katex-display { overflow-x: auto; padding: .3rem .15rem; margin: .25rem 0 .75rem; }
.prose code { padding: .1rem .26rem; background: var(--panel); border-radius: .24rem; font-size: .87em; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; margin-bottom: .95rem; }
.prose td, .prose th { border: 1px solid var(--line); padding: .55rem; }
.prose th { background: var(--panel); text-align: left; }

dialog { color: var(--ink); background: var(--surface); width: min(38rem, calc(100% - 1.5rem)); max-height: min(80vh, 44rem); padding: 0; border: 1px solid var(--line); border-radius: .9rem; margin: min(12vh, 6rem) auto 0; }
dialog::backdrop { background: #0d1c16a8; }
.search-panel { padding: .9rem; }
.search-panel header { display: flex; align-items: center; justify-content: space-between; gap: .4rem; margin-bottom: .6rem; }
.search-panel h2 { font-size: 1.15rem; }
.search-panel input { width: 100%; min-height: 2.8rem; padding: .45rem .65rem; border: 1px solid var(--line); border-radius: .5rem; color: var(--ink); background: var(--bg); }
.search-panel input + p { margin: .65rem 0 .35rem; font-size: .88rem; }
.search-row { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .48rem .55rem; border-radius: .4rem; color: var(--ink); text-decoration: none; }
.search-row:hover, .search-row:focus-visible { background: var(--accent-soft); }
.search-row small { color: var(--muted); text-align: right; flex-shrink: 0; }

@media (max-width: 960px) {
  .hero { grid-template-columns: minmax(0, 1.25fr) minmax(9rem, .7fr); gap: .6rem; }
}
@media (max-width: 730px) {
  .layout { display: block; }
  .topbar-inner { grid-template-columns: auto minmax(0, 1fr) auto; gap: .65rem; }
  .sidebar { position: static; min-height: 0; padding: .75rem 0 0; }
  .nav-label, .sidebar-foot { display: none; }
  .sidebar nav { display: flex; gap: .35rem; overflow-x: auto; }
  .sidebar nav a { padding: .45rem .52rem; font-size: .88rem; }
  .nav-icon { display: none; }
  main { padding-top: .8rem; }
  .hero { min-height: 19rem; }
}
@media (max-width: 490px) {
  .hero { grid-template-columns: minmax(0, 1fr); min-height: auto; }
  .hero-graphic { display: none; }
  .home-cards, .cards:not(.year-cards) { grid-template-columns: 1fr; }
  .year-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-hint, .search-open kbd { display: none; }
  .search-open svg { flex: none; }
  .search-open span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .archive-nav-suffix { display: none; }
  .sidebar nav a { padding-inline: .4rem; font-size: .82rem; }
  .search-row small { max-width: 30%; }
  .algorithm-complexity { column-gap: .42rem; }
  .algorithm-complexity span + span::before { margin-right: .42rem; }
  .algorithm-complexity span { white-space: normal; }
  .algorithm-detail .breadcrumb, .algorithm-detail .intro { display: none; }
  .algorithm-detail .page-heading h1 { font-size: 1.72rem; margin-bottom: .45rem; }
  .algorithm-example { flex-direction: column; }
  .example-answer { display: flex; align-items: baseline; gap: .65rem; }
}
@media (max-width: 345px) {
  .sidebar nav { flex-wrap: wrap; }
}
