:root {
  color-scheme: light;
  --page: #f5f5f2;
  --surface: #ffffff;
  --sidebar: #fafaf8;
  --ink: #223039;
  --muted: #66767a;
  --faint: #8a989b;
  --line: #e1e5e2;
  --accent: #b01212;
  --accent-deep: #870d0d;
  --accent-wash: #fbefed;
  --example: #f8faf9;
  --code: #19252d;
  --code-ink: #dfe9e9;
  --shadow: 0 15px 40px rgba(32, 49, 52, .045);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--page); color: var(--ink); font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
button, input { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent-deep); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

.topbar { position: sticky; top: 0; z-index: 20; height: 76px; border-bottom: 1px solid var(--line); background: var(--surface); }
.topbar-inner { display: flex; align-items: center; gap: 17px; width: min(1600px, 100%); height: 100%; margin: auto; padding: 0 32px; }
.brand { display: inline-flex; align-items: center; gap: 13px; min-width: 0; color: var(--ink); text-decoration: none; }
.brand-mark { display: flex; align-items: center; justify-content: center; width: 43px; height: 43px; flex: 0 0 auto; border-radius: 11px; background: var(--accent); box-shadow: 0 6px 15px rgba(176, 18, 18, .16); color: white; font-weight: 850; letter-spacing: -.09em; line-height: 1; white-space: nowrap; }
.brand-mark span { color: #ffc5ba; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.25; }
.brand-copy strong { font-size: 1.06rem; letter-spacing: -.025em; }
.brand-copy small { margin-top: 3px; color: var(--muted); font-size: .73rem; font-weight: 600; letter-spacing: .015em; }
.topbar-actions { display: flex; align-items: center; gap: 17px; margin-left: auto; }
.pdf-link { color: var(--muted); font-size: .82rem; font-weight: 700; text-decoration: none; }
.pdf-link:hover { color: var(--accent); }
.pdf-link span { margin-left: 3px; font-size: 1rem; }
.icon-button { display: grid; place-items: center; width: 37px; height: 37px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--muted); font-size: 1.15rem; line-height: 1; }
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.menu-toggle { display: none; }

.app-shell { display: grid; grid-template-columns: 332px minmax(0, 1fr); width: min(1600px, 100%); min-height: calc(100vh - 76px); margin: auto; }
.sidebar { border-right: 1px solid var(--line); background: var(--sidebar); }
.sidebar-inner { position: sticky; top: 76px; display: flex; flex-direction: column; height: calc(100vh - 76px); min-height: 360px; padding: 28px 18px 16px; }
.sidebar-heading { display: flex; align-items: baseline; justify-content: space-between; padding: 0 10px; font-size: .96rem; font-weight: 780; letter-spacing: -.01em; }
.count { color: var(--faint); font-size: .72rem; font-weight: 650; }
.sidebar-home { display: block; margin: 0 1px 16px; padding: 9px 11px; border-radius: 8px; color: var(--muted); font-size: .82rem; font-weight: 720; text-decoration: none; }
.sidebar-home:hover, .sidebar-home[aria-current="page"] { background: var(--accent-wash); color: var(--accent-deep); }
.search-box { display: flex; align-items: center; gap: 7px; margin: 19px 1px 16px; padding: 0 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--muted); }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.search-box > span { font-size: 1.35rem; line-height: 1; }
.search-box input { width: 100%; min-width: 0; height: 41px; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: .82rem; }
.search-box input::placeholder { color: var(--faint); }
.search-box kbd { padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--faint); font-size: .72rem; line-height: 1.5; }
#toc { flex: 1; overflow: auto; padding: 1px 1px 20px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.toc-chapter { margin-bottom: 12px; }
.toc-chapter > summary, .toc-section > summary { display: flex; align-items: center; list-style: none; cursor: pointer; }
.toc-chapter > summary::-webkit-details-marker, .toc-section > summary::-webkit-details-marker { display: none; }
.toc-chapter > summary { gap: 9px; padding: 9px 10px; border-radius: 9px; color: var(--ink); font-size: .78rem; font-weight: 760; line-height: 1.3; }
.toc-chapter > summary:hover, .toc-section > summary:hover { background: var(--accent-wash); }
.chapter-number { display: grid; place-items: center; width: 25px; height: 25px; flex: 0 0 auto; border-radius: 7px; background: var(--accent-wash); color: var(--accent); font-size: .73rem; }
.chapter-title { flex: 1; }
.chapter-count, .toc-section-count { color: var(--faint); font-size: .69rem; font-weight: 650; }
.toc-chapter-content { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 10px; }
.toc-section { margin-bottom: 3px; }
.toc-section > summary { gap: 8px; padding: 8px 9px; border-radius: 7px; color: var(--muted); font-size: .79rem; font-weight: 700; }
.toc-section-label { display: flex; align-items: baseline; flex: 1; gap: 8px; }
.toc-section-number { color: var(--accent); font-size: .71rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.toc-exercises { padding: 2px 0 6px 7px; }
.exercise-item { display: block; margin: 2px 0; padding: 7px 10px; border-radius: 7px; color: var(--muted); font-size: .76rem; font-weight: 720; font-variant-numeric: tabular-nums; text-decoration: none; }
.exercise-item:hover { background: var(--accent-wash); color: var(--accent-deep); }
.exercise-item[aria-current="page"] { background: var(--accent); color: white; box-shadow: 0 3px 8px rgba(176, 18, 18, .15); }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding: 15px 10px 0; color: var(--faint); font-size: .72rem; }
.sidebar-foot a { color: var(--accent); font-weight: 700; text-decoration: none; }
.sidebar-foot a:hover, .page-footer a:hover { text-decoration: underline; }
.empty-search { padding: 12px; color: var(--muted); font-size: .85rem; }

.main-content { min-width: 0; }
.content-wrap { width: min(970px, 100%); margin: 0 auto; padding: 36px clamp(28px, 5vw, 68px) 24px; }
.landing-view { padding: clamp(24px, 5vw, 60px) 0 0; }
.landing-kicker { margin: 0 0 12px; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.landing-view h1 { margin: 0; color: var(--ink); font-size: clamp(2.6rem, 6vw, 4.5rem); line-height: 1.08; letter-spacing: -.055em; }
.landing-lead { max-width: 64ch; margin: 23px 0 0; color: var(--muted); font-size: clamp(1rem, 1.7vw, 1.15rem); line-height: 1.75; }
.landing-source { max-width: 75ch; margin-top: clamp(43px, 6vw, 70px); padding: clamp(21px, 3vw, 29px); border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.landing-source h2 { margin: 0 0 13px; color: var(--ink); font-size: 1rem; }
.landing-source p { margin: 0 0 12px; color: var(--muted); font-size: .85rem; line-height: 1.75; }
.landing-source p:last-child { margin-bottom: 0; }
.landing-source a { color: var(--accent-deep); font-weight: 700; }
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 28px; color: var(--faint); font-size: .75rem; font-weight: 650; }
.breadcrumbs span:last-child { color: var(--accent); }
.exercise-heading { margin-bottom: 29px; }
.eyebrow { color: var(--accent); font-size: .69rem; font-weight: 820; letter-spacing: .15em; text-transform: uppercase; }
.exercise-heading h1 { margin: 5px 0 2px; color: var(--ink); font-size: clamp(2rem, 3.3vw, 2.9rem); line-height: 1.18; letter-spacing: -.055em; }
.content-card, .solution-details { border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: var(--shadow); }
.statement-card { padding: clamp(22px, 3.5vw, 35px); }
.statement-body { max-width: 75ch; color: var(--ink); font-size: 1rem; line-height: 1.85; overflow-wrap: anywhere; }
.statement-body > :first-child, .solution-notes > :first-child { margin-top: 0; }
.statement-body > :last-child, .solution-notes > :last-child { margin-bottom: 0; }
.statement-body p { margin: 0 0 1em; }
.statement-body ol, .statement-body ul { padding-left: 1.5em; }
.statement-body li { padding-left: .25em; margin: .3em 0; }
.statement-body ol[type="a"] > li::marker { content: "(" counter(list-item, lower-alpha) ") "; }
.statement-body code, .statement-body tt, .solution-notes code { padding: .11em .34em; border-radius: 4px; background: var(--accent-wash); color: var(--accent-deep); font: .88em/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
.statement-body math { max-width: 100%; }
.statement-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.statement-body td, .statement-body th { padding: 6px 10px; border: 1px solid var(--line); }
.statement-body blockquote { margin: 18px 0; padding: 2px 18px; border-left: 3px solid var(--accent); color: var(--muted); }

.examples-section { margin-top: 22px; }
.statement-body .exercise-part { margin-block: 1.4em; }
.statement-body .exercise-part:first-child { margin-top: 0; }
.part-examples { margin-top: 12px; font-size: 1rem; line-height: 1.65; }
.examples-grid { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(310px, 1fr); gap: 1.25rem; align-items: stretch; max-width: 100%; overflow-x: auto; padding: .75rem .25rem 1rem; scrollbar-width: thin; scrollbar-color: var(--line) transparent; scroll-snap-type: x proximity; }
.part-examples .examples-grid { grid-auto-columns: minmax(200px, 1fr); }
.examples-grid::-webkit-scrollbar { height: 7px; }
.examples-grid::-webkit-scrollbar-thumb { border-radius: 999px; background: var(--line); }
.example-card { position: relative; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); scroll-snap-align: start; transition: border-color .2s, box-shadow .2s, transform .2s; }
.example-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.example-card-heading { display: flex; align-items: center; gap: 8px; padding: .7rem 1rem; border-bottom: 1px solid var(--line); background: var(--example); color: var(--accent); font-size: .92rem; font-weight: 750; }
.example-card-heading::before { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--accent); content: ""; }
.example-steps { padding: .5rem 1rem .75rem; }
.example-step { margin-top: .7rem; }
.example-step:first-child { margin-top: 0; }
.step-label { display: inline-flex; width: fit-content; margin-bottom: .3rem; padding: .2rem .55rem; border-radius: 6px; background: #e0f2fe; color: #0369a1; font-size: .72rem; font-weight: 750; letter-spacing: .02em; }
.example-output .step-label { background: #dcfce7; color: #15803d; }
.example-error .step-label { background: #fee2e2; color: #b91c1c; }
.example-file .step-label { max-width: 100%; flex-wrap: wrap; column-gap: .35rem; background: #e0f2fe; color: #0369a1; }
.example-command .step-label { background: var(--accent-wash); color: var(--accent); }
.file-name { min-width: 0; color: inherit; font: 700 .75rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.example-step pre { overflow-x: auto; margin: 0; padding: .75rem 1rem; border: 1px solid var(--line); border-radius: 8px; background: var(--example); color: var(--ink); font: .8rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.terminal-transcript { display: flex; flex: 1; flex-direction: column; gap: .28rem; min-width: 0; overflow-x: auto; margin: .75rem 1rem 1rem; padding: .8rem .9rem; border: 1px solid var(--line); border-radius: 8px; background: var(--example); color: var(--ink); font: .8rem/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }
.transcript-row { display: grid; grid-template-columns: 1.35rem minmax(0, 1fr); align-items: baseline; }
.transcript-prefix { color: var(--faint); user-select: none; }
.transcript-output .transcript-text, .transcript-input .transcript-text { grid-column: 1 / -1; }
.transcript-text { white-space: pre; }
.transcript-input { padding: .17rem .45rem; border-radius: 6px; background: rgba(3, 105, 161, .09); color: #0369a1; font-weight: 700; }
.transcript-error { color: #b91c1c; }
.transcript-error .transcript-prefix { color: inherit; }
.transcript-command { color: var(--accent-deep); }
.transcript-command .transcript-prefix { color: inherit; }
.transcript-file { color: #0369a1; }
.transcript-file .transcript-prefix { color: inherit; }

.solution-section { margin-top: 35px; }
.solution-details { overflow: hidden; }
.solution-details > summary { display: flex; align-items: center; gap: 14px; padding: 19px 23px; list-style: none; cursor: pointer; }
.solution-details > summary::-webkit-details-marker { display: none; }
.solution-details > summary:hover { background: var(--accent-wash); }
.solution-summary-icon { display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 auto; border-radius: 10px; background: var(--accent-wash); color: var(--accent); font: 700 .78rem ui-monospace, SFMono-Regular, Consolas, monospace; }
.solution-summary-copy { display: flex; flex-direction: column; line-height: 1.35; }
.solution-summary-copy strong { font-size: .95rem; }
.solution-summary-copy small { margin-top: 3px; color: var(--muted); font-size: .74rem; }
.summary-chevron { margin-left: auto; color: var(--accent); font-size: 1.5rem; transition: transform .2s; }
.solution-details[open] .summary-chevron { transform: rotate(180deg); }
.solution-body { border-top: 1px solid var(--line); padding: 20px 23px 23px; }
.solution-notes { margin-bottom: 20px; font-size: .89rem; line-height: 1.7; }
.solution-notes:last-child { margin-bottom: 0; }
.no-solution { margin: 0; color: var(--muted); font-size: .85rem; }
.code-panel { overflow: hidden; margin-top: 14px; border: 1px solid #273943; border-radius: 10px; background: var(--code); }
.code-panel:first-child { margin-top: 0; }
.code-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 43px; padding: 6px 12px 6px 15px; border-bottom: 1px solid #354650; color: var(--code-ink); font-size: .75rem; }
.code-file { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.file-dot { width: 8px; height: 8px; border-radius: 50%; background: #e79580; }
.code-title { color: #f4c6b9; }
.code-file-separator { color: #799097; }
.language-pill { margin-left: 2px; padding: 1px 5px; border: 1px solid #40515b; border-radius: 4px; color: #93a6ac; font-size: .62rem; }
.copy-button { flex: 0 0 auto; border: 0; border-radius: 5px; padding: 5px 8px; background: #344750; color: #dce7e7; font-size: .69rem; font-weight: 700; }
.copy-button:hover { background: #49616c; }
.code-block { overflow: auto; max-height: 620px; margin: 0; padding: 13px 0; color: var(--code-ink); font: .77rem/1.62 ui-monospace, SFMono-Regular, Consolas, monospace; tab-size: 2; }
.code-line { display: flex; min-width: max-content; }
.code-line:hover { background: #22323b; }
.line-number { width: 42px; flex: 0 0 auto; padding-right: 13px; color: #718891; text-align: right; user-select: none; }
.source-line { padding-right: 20px; white-space: pre; }
.syntax-comment { color: #86a6a0; }
.syntax-string { color: #f4b894; }
.syntax-keyword { color: #a8b8f0; }
.syntax-type { color: #85d0c6; }
.syntax-number { color: #e3bc84; }
.syntax-preprocessor { color: #cfb9e9; }

.exercise-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; margin-top: 25px; }
.pager-link { display: flex; flex-direction: column; padding: 13px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); text-decoration: none; }
.pager-link:hover { border-color: var(--accent); color: var(--accent); }
.pager-next { text-align: right; }
.pager-label { color: var(--muted); font-size: .67rem; font-weight: 650; }
.pager-link strong { margin-top: 2px; font-size: .82rem; }
.page-footer { margin-top: 36px; border-top: 1px solid var(--line); padding-top: 19px; color: var(--muted); font-size: .74rem; line-height: 1.65; }
.page-footer a { color: var(--accent); text-decoration: none; }
.mobile-scrim { display: none; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #10191b;
  --surface: #192629;
  --sidebar: #152124;
  --ink: #e1ebea;
  --muted: #abbdbb;
  --faint: #829998;
  --line: #2e4244;
  --accent: #84d2c8;
  --accent-deep: #a8e4dd;
  --accent-wash: #203c3c;
  --example: #203134;
  --shadow: none;
}
:root[data-theme="dark"] .brand-mark { background: #285753; box-shadow: none; }
:root[data-theme="dark"] .brand-mark span { color: #a9e7de; }
:root[data-theme="dark"] .exercise-item[aria-current="page"] { background: #285753; box-shadow: none; }
:root[data-theme="dark"] .example-input .step-label { background: rgba(3, 105, 161, .25); color: #7dd3fc; }
:root[data-theme="dark"] .example-output .step-label { background: rgba(21, 128, 61, .25); color: #86efac; }
:root[data-theme="dark"] .example-error .step-label { background: rgba(185, 28, 28, .25); color: #fca5a5; }
:root[data-theme="dark"] .example-file .step-label { background: rgba(3, 105, 161, .25); color: #7dd3fc; }
:root[data-theme="dark"] .transcript-input { background: rgba(125, 211, 252, .11); color: #7dd3fc; }
:root[data-theme="dark"] .transcript-error { color: #fca5a5; }
:root[data-theme="dark"] .transcript-file { color: #7dd3fc; }
:root[data-theme="dark"] .code-panel { border-color: #344a4f; }

@media (max-width: 950px) {
  .app-shell { grid-template-columns: 285px minmax(0, 1fr); }
  .content-wrap { padding-inline: 30px; }
}

@media (max-width: 720px) {
  .topbar { height: 65px; }
  .topbar-inner { padding: 0 16px; gap: 10px; }
  .menu-toggle { display: grid; }
  .brand-mark { width: 36px; height: 36px; border-radius: 9px; font-size: .85rem; }
  .brand-copy strong { font-size: .9rem; }
  .brand-copy small { font-size: .62rem; }
  .pdf-link { display: none; }
  .topbar-actions { gap: 0; }
  .app-shell { display: block; min-height: calc(100vh - 65px); }
  .sidebar { position: fixed; top: 65px; bottom: 0; left: 0; z-index: 30; width: min(340px, 88vw); border-right: 1px solid var(--line); box-shadow: 20px 0 50px rgba(0,0,0,.15); transform: translateX(-105%); transition: transform .22s ease; }
  .menu-open .sidebar { transform: translateX(0); }
  .sidebar-inner { top: 65px; height: calc(100vh - 65px); }
  .mobile-scrim:not([hidden]) { position: fixed; inset: 65px 0 0; z-index: 25; display: block; width: 100%; border: 0; background: rgba(18, 31, 34, .45); }
  .content-wrap { padding: 25px 19px 22px; }
  .breadcrumbs { margin-bottom: 22px; }
  .statement-card { padding: 22px 19px; }
  .statement-body { font-size: .94rem; }
  .examples-section { margin-top: 20px; }
  .examples-grid { grid-auto-columns: minmax(260px, 1fr); gap: .75rem; }
  .part-examples .examples-grid { grid-auto-columns: minmax(260px, 1fr); }
  .solution-body { padding: 15px; }
  .solution-details > summary { padding: 16px; }
  .exercise-pager { gap: 9px; }
  .pager-link { padding: 10px; }
}

@media (max-width: 380px) {
  .brand-copy small { display: none; }
  .exercise-pager { grid-template-columns: 1fr; }
  .pager-next { text-align: left; }
}
