:root {
    color-scheme: light dark;
    --page: #f3f5f9;
    --surface: #ffffff;
    --soft: #f7f8fc;
    --ink: #172033;
    --muted: #667085;
    --line: #dce2ec;
    --accent: #4557c7;
    --accent-soft: #eef0ff;
    --teal: #087b70;
    --shadow: 0 18px 48px rgba(23, 32, 51, 0.09);
}

html[data-theme="dark"] {
    --page: #080d17;
    --surface: #111827;
    --soft: #182235;
    --ink: #edf2fb;
    --muted: #a6b1c4;
    --line: #2c3950;
    --accent: #9ba9ff;
    --accent-soft: #222c50;
    --teal: #62d6c5;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--page); font: 16px/1.55 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; }
button, input { font: inherit; }
.shell { width: min(1160px, calc(100% - 32px)); margin-inline: auto; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 10; padding: 9px 12px; transform: translateY(-150%); border-radius: 8px; color: white; background: var(--accent); }
.skip-link:focus { transform: none; }
.site-header { position: sticky; top: 0; z-index: 5; border-bottom: 1px solid color-mix(in srgb, var(--line) 82%, transparent); background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(16px); }
.topbar { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; }
.brand > span { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 11px; color: white; background: var(--accent); font-weight: 850; }
.brand strong { line-height: 1.05; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 0.68rem; font-weight: 700; }
.topbar-actions { display: flex; align-items: center; gap: 7px; }
.topbar-actions a, .topbar-actions button { padding: 8px 10px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: 0.76rem; font-weight: 760; text-decoration: none; cursor: pointer; }
.topbar-actions a:hover, .topbar-actions button:hover { color: var(--ink); background: var(--soft); }
.topbar-actions .home-link { color: white; background: var(--accent); }
.hero { padding: clamp(56px, 9vw, 100px) 0 38px; }
.eyebrow { margin: 0 0 14px; color: var(--teal); font-size: 0.76rem; font-weight: 850; letter-spacing: 0.1em; text-transform: uppercase; }
h1 { max-width: 820px; margin: 0; font-size: clamp(2.65rem, 7vw, 5.4rem); line-height: 0.98; letter-spacing: -0.065em; }
h1 em { color: var(--accent); font-style: normal; }
.hero > p:not(.eyebrow, .result-count) { max-width: 720px; color: var(--muted); font-size: 1.02rem; }
.search { width: min(620px, 100%); min-height: 52px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 9px; margin-top: 25px; padding: 0 15px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.search span { color: var(--accent); font-size: 1.3rem; }
.search input { width: 100%; padding: 13px 0; border: 0; outline: 0; color: var(--ink); background: transparent; }
.result-count { margin: 8px 0 0; color: var(--muted); font-size: 0.74rem; }
.lecture-index { position: sticky; top: 69px; z-index: 4; display: flex; gap: 5px; padding: 9px 0; overflow-x: auto; background: var(--page); scrollbar-width: thin; }
.lecture-index a { flex: 0 0 auto; min-width: 34px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--surface); font: 750 0.68rem ui-monospace, SFMono-Regular, Menlo, monospace; text-align: center; text-decoration: none; }
.lecture-index a:hover { border-color: var(--accent); color: var(--accent); }
.code-viewer { scroll-margin-top: 125px; margin: 18px 0 4px; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.code-viewer[hidden] { display: none; }
.code-viewer > header { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 18px; border-bottom: 1px solid #29354a; color: #e4ebf8; background: #101827; }
.code-viewer header span { display: block; color: #8190aa; font-size: 0.62rem; font-weight: 850; letter-spacing: 0.09em; text-transform: uppercase; }
.code-viewer h2 { margin-top: 2px; color: #f1f5fb; font-size: 0.96rem; }
.code-viewer header code { display: block; margin-top: 3px; color: #9ba9ff; font-size: 0.66rem; }
.viewer-actions { display: flex; align-items: center; gap: 7px; }
.viewer-actions a, .viewer-actions button { min-height: 38px; display: inline-flex; align-items: center; padding: 7px 10px; border: 1px solid #35425a; border-radius: 9px; color: #dce5f4; background: #1b263a; font-size: 0.7rem; font-weight: 800; text-decoration: none; cursor: pointer; }
.viewer-actions a:hover, .viewer-actions button:hover { border-color: #9ba9ff; color: white; }
.viewer-actions button:disabled { opacity: 0.48; cursor: wait; }
.source-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
#code-source { width: 100%; min-height: min(62vh, 620px); display: block; resize: vertical; box-sizing: border-box; padding: 20px 22px; border: 0; outline: 0; color: #dbe5f5; background: #080e1a; font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; tab-size: 4; white-space: pre; }
#code-source:focus { box-shadow: inset 0 0 0 2px #9ba9ff; }
#code-viewer-status { margin: 0; padding: 8px 18px; border-top: 1px solid #263249; color: #9aa8bd; background: #101827; font-size: 0.68rem; }
.example-groups { display: grid; gap: 20px; padding: 22px 0 80px; }
.lecture-group { scroll-margin-top: 125px; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.lecture-group[hidden], .example-card[hidden] { display: none; }
.lecture-group > header { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 14px; align-items: center; padding: 20px; border-bottom: 1px solid var(--line); background: linear-gradient(110deg, var(--accent-soft), transparent 72%); }
.lecture-group > header > span { width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid color-mix(in srgb, var(--accent) 38%, var(--line)); border-radius: 13px; color: var(--accent); font: 850 0.74rem ui-monospace, SFMono-Regular, Menlo, monospace; }
h2 { margin: 0; font-size: 1.04rem; letter-spacing: -0.025em; }
.lecture-group header p { margin: 3px 0 0; color: var(--muted); font-size: 0.76rem; }
/* Separators are a 1px ring on each card that fills the 1px gap, NOT the
   container colour showing through the gaps: a lecture with an odd number of
   examples left the empty half-row rendering as a grey phantom tile. Rings
   also stay correct when search hides cards, and leave the focus outline free.
   `.lecture-group` clips the rings at the outer edges via overflow: hidden. */
.example-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; background: var(--surface); }
.example-card { min-width: 0; display: flex; flex-direction: column; gap: 5px; padding: 18px 20px; background: var(--surface); box-shadow: 0 0 0 1px var(--line); text-decoration: none; transition: background 150ms ease; }
.example-card:hover { background: var(--soft); }
.example-card strong { color: var(--ink); font-size: 0.9rem; }
.example-card span { color: var(--muted); font-size: 0.76rem; }
.example-card code { width: fit-content; max-width: 100%; margin-top: 8px; overflow: hidden; color: var(--accent); font-size: 0.67rem; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 70px 20px; color: var(--muted); text-align: center; }
footer { border-top: 1px solid var(--line); color: var(--muted); background: var(--surface); font-size: 0.72rem; }
footer .shell { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
footer code { color: var(--accent); }

@media (max-width: 720px) {
    .shell { width: min(100% - 20px, 1160px); }
    .topbar { min-height: 60px; }
    .topbar-actions > a:not(.home-link) { display: none; }
    .topbar-actions .home-link { font-size: 0; }
    .topbar-actions .home-link::after { content: "Home"; font-size: 0.72rem; }
    .hero { padding-top: 44px; }
    .lecture-index { top: 61px; }
    .code-viewer > header { align-items: flex-start; flex-direction: column; }
    .viewer-actions { width: 100%; }
    .viewer-actions a, .viewer-actions button { flex: 1; justify-content: center; }
    #code-source { min-height: 56vh; padding: 16px 14px; font-size: 12px; }
    .example-grid { grid-template-columns: 1fr; }
    .lecture-group > header { padding: 16px; }
    footer .shell { align-items: flex-start; flex-direction: column; justify-content: center; padding-block: 15px; }
}

@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition-duration: 0.01ms !important; } }
