@font-face { font-family: "Geist"; src: url(/static/fonts/Geist-Variable.woff2) format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url(/static/fonts/GeistMono-Variable.woff2) format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #FBFBFA; --surface: #FFFFFF; --side: #F6F6F3; --hover: #E9E9E4; --line: #E4E4E0; --line-soft: #EFEFEB; --field: #DCDCD6;
  --ink: #16181D; --ink-2: #30343D; --ink-3: #4A4F5C; --muted: #5F6473; --faint: #8A8F9C;
  --accent: #2346A0; --accent-ink: #16306F; --accent-bg: #E6EBF7; --ring: #DCE4F6;
  --code-bg: #EFEFEA; --mark: #FFF1B8; --ok: #1E5A33; --ok-bg: #E3F1E7; --btn: #16181D; --btn-ink: #FFFFFF;
  --pitfall: #B4471F; --recipe: #2E7D4A; --fact: #2346A0; --decision: #6B3FA0; --preference: #8A6A10;
  --sans: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111317; --surface: #181B21; --side: #14161B; --hover: #22262E; --line: #2A2E36; --line-soft: #23262D; --field: #353A44;
  --ink: #E7E8EC; --ink-2: #D0D2D9; --ink-3: #B3B6C0; --muted: #969AA7; --faint: #7D818D;
  --accent: #8FAEF5; --accent-ink: #B9CCF9; --accent-bg: #1D2742; --ring: #2A3A66;
  --code-bg: #22262E; --mark: #5C4A0E; --ok: #8ED1A4; --ok-bg: #16301F; --btn: #E7E8EC; --btn-ink: #111317;
  --pitfall: #F0916A; --recipe: #6CC892; --fact: #8FAEF5; --decision: #BE9AEE; --preference: #DDB84E;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #111317; --surface: #181B21; --side: #14161B; --hover: #22262E; --line: #2A2E36; --line-soft: #23262D; --field: #353A44;
    --ink: #E7E8EC; --ink-2: #D0D2D9; --ink-3: #B3B6C0; --muted: #969AA7; --faint: #7D818D;
    --accent: #8FAEF5; --accent-ink: #B9CCF9; --accent-bg: #1D2742; --ring: #2A3A66;
    --code-bg: #22262E; --mark: #5C4A0E; --ok: #8ED1A4; --ok-bg: #16301F; --btn: #E7E8EC; --btn-ink: #111317;
    --pitfall: #F0916A; --recipe: #6CC892; --fact: #8FAEF5; --decision: #BE9AEE; --preference: #DDB84E;
    color-scheme: dark;
  }
}

.t-pitfall { --c: var(--pitfall); } .t-recipe { --c: var(--recipe); } .t-fact { --c: var(--fact); }
.t-decision { --c: var(--decision); } .t-preference { --c: var(--preference); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-ink); text-decoration: underline; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code, pre, .mono, .kbd { font-family: var(--mono); }
h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.label { margin: 16px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.label a { color: inherit; }
.dot { width: 8px; height: 8px; border-radius: 2px; background: var(--c, var(--faint)); flex-shrink: 0; display: inline-block; }
.phone-only { display: none !important; }

/* Top bar */
.top { position: sticky; top: 0; z-index: 20; height: 60px; padding: 0 24px; display: grid; grid-template-columns: 272px minmax(0, 1fr) auto; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; color: var(--ink); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand:hover { color: var(--ink); text-decoration: none; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--btn); color: var(--btn-ink); display: inline-flex; align-items: center; justify-content: center; font-family: var(--mono); font-size: 12px; flex-shrink: 0; }
.search { justify-self: center; width: min(560px, 100%); height: 38px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 1px solid var(--field); border-radius: 9px; background: var(--side); color: var(--muted); font-size: 14px; }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); background: var(--surface); }
.search input { flex-grow: 1; min-width: 0; border: 0; background: transparent; font: inherit; color: var(--ink); outline: none; }
.search input::-webkit-search-cancel-button { display: none; }
.kbd { font-size: 12px; padding: 1px 6px; border: 1px solid var(--field); border-radius: 5px; background: var(--surface); }
.top-end { display: flex; align-items: center; justify-content: flex-end; gap: 16px; font-size: 14px; }
.top-links { display: flex; gap: 20px; }
.top-links a { color: var(--muted); }
.theme { display: flex; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--side); }
.theme button { width: 30px; height: 28px; border: 0; border-radius: 6px; background: none; color: var(--muted); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.theme button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.unlocked { display: flex; align-items: center; gap: 6px; padding: 4px 4px 4px 10px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); font-size: 13px; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; display: flex; align-items: center; justify-content: center; color: var(--ink-2); cursor: pointer; }
.btn { min-height: 32px; padding: 0 12px; border: 1px solid var(--field); border-radius: 7px; background: var(--surface); font: inherit; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.btn.small { min-height: 26px; padding: 0 8px; border-radius: 999px; }
.btn.primary { height: 44px; border: 0; border-radius: 9px; background: var(--btn); color: var(--btn-ink); font-size: 15px; font-weight: 500; }

/* Frame and tree */
.frame { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: calc(100vh - 60px); }
.tree { position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; border-right: 1px solid var(--line); background: var(--side); padding: 20px 12px 40px; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.tree a { color: var(--ink-2); }
.tree a:hover { text-decoration: none; background: var(--hover); }
.tree-home, .tree-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 7px; }
.tree-home { justify-content: flex-start; font-weight: 500; }
.tree .current { background: var(--hover); color: var(--ink); font-weight: 500; }
.tree summary { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-radius: 6px; cursor: pointer; list-style: none; color: var(--ink-2); }
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before { content: ""; width: 6px; height: 6px; margin: 0 3px; border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint); transform: rotate(-45deg); transition: transform .15s; flex-shrink: 0; }
.tree details[open] > summary { color: var(--ink); font-weight: 500; }
.tree details[open] > summary::before { transform: rotate(45deg); border-color: var(--ink); }
.tree summary:hover { background: var(--hover); }
.tree .name { flex-grow: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { font-family: var(--mono); font-size: 12px; color: var(--muted); font-weight: 400; }
.leaf, .group-link { display: block; margin-left: 22px; padding: 6px 10px; border-radius: 6px; line-height: 1.35; }
.group-link { font-size: 13px; color: var(--muted) !important; }
.leaf[aria-current="page"] { background: var(--accent-bg); color: var(--accent-ink) !important; }
.leaf code, .card-line code, .row-title code, .results code, .prevnext code, .side-list code { font-size: .9em; }
.lock-label { display: flex; align-items: center; gap: 6px; }
body.is-unlocked .lock-label { color: var(--ok); }
.scrim { display: none; }

/* Pages */
.main { min-width: 0; }
.page { padding: 48px 64px 64px; display: flex; flex-direction: column; gap: 40px; max-width: 1180px; }
.page > h1, .intro h1 { margin: 0; font-size: 36px; font-weight: 600; letter-spacing: -0.02em; }
.kind { margin: 0 0 -32px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.intro { display: flex; flex-direction: column; gap: 12px; }
.lead { margin: 0; max-width: 720px; font-size: 16px; line-height: 1.6; color: var(--ink-3); }
.pills { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: 13px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 16px; }
.section-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.section-head a { font-size: 14px; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); }
.card:hover { text-decoration: none; border-color: var(--field); color: var(--ink-2); }
.card:hover .mono { color: var(--accent); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.card-head .mono { font-size: 15px; font-weight: 500; color: var(--ink); }
.card-line { font-size: 14px; line-height: 1.45; }
.rows { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.row { display: grid; grid-template-columns: 12px minmax(0, 1fr) 120px 100px; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line-soft); font-size: 14px; color: var(--ink); }
.row:last-child { border-bottom: 0; }
.row:hover { text-decoration: none; background: var(--side); color: var(--accent); }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .mono { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.row .date { text-align: right; font-size: 13px; }
.badge { display: inline-block; vertical-align: middle; padding: 1px 8px; border-radius: 999px; font: 500 12px/1.6 var(--sans); letter-spacing: 0; }
.badge.stale { background: #FDF1D6; color: #7A5200; border: 1px solid #EBD39A; }
:root[data-theme="dark"] .badge.stale { background: #3A2E0E; color: #F0CF7A; border-color: #5C4A1A; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .badge.stale { background: #3A2E0E; color: #F0CF7A; border-color: #5C4A1A; } }

/* Lesson */
.lesson-page { display: grid; grid-template-columns: minmax(0, 720px) 300px; gap: 0 56px; max-width: none; padding-right: 0; align-items: start; }
.lesson { display: flex; flex-direction: column; gap: 28px; min-width: 0; }
.lesson-head { display: flex; flex-direction: column; gap: 14px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.lesson h1 { margin: 0; font-size: 32px; line-height: 1.25; font-weight: 600; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.lesson h1 code { font-size: .8em; font-weight: 500; background: var(--code-bg); padding: 2px 7px; border-radius: 6px; }
.type-note { display: flex; gap: 12px; padding: 14px 16px; border-radius: 10px; font-size: 15px; line-height: 1.55; color: var(--ink); background: color-mix(in srgb, var(--c) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--c) 28%, var(--surface)); }
.type-note svg { flex-shrink: 0; margin-top: 2px; color: var(--c); }
.prose { display: flex; flex-direction: column; gap: 14px; font-size: 16px; line-height: 1.7; color: var(--ink-2); }
.prose > * { margin: 0; }
.prose h2 { margin-top: 14px; font-size: 20px; font-weight: 600; color: var(--ink); scroll-margin-top: 80px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 17px; color: var(--ink); }
.anchor { margin-left: 8px; color: var(--faint); opacity: 0; font-weight: 400; }
h2:hover .anchor, .anchor:focus { opacity: 1; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li + li { margin-top: 6px; }
.prose code { font-size: 14px; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }
.prose pre { margin: 0; padding: 14px; font-size: 14px; line-height: 1.6; color: var(--ink); overflow-x: auto; background: var(--surface); }
.prose pre code { background: none; padding: 0; font-size: inherit; overflow-wrap: normal; }
.prose > pre, .code { border-radius: 10px; border: 1px solid var(--line); background: var(--surface); overflow: hidden; }
.code-bar { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line-soft); font-family: var(--mono); font-size: 12px; color: var(--muted); }
.code-bar .btn { min-height: 30px; padding: 0 10px; font-size: 12px; background: var(--bg); }
.prose blockquote { padding-left: 14px; border-left: 3px solid var(--line); color: var(--ink-3); }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.prose img { max-width: 100%; height: auto; }
.prevnext { display: flex; justify-content: space-between; gap: 24px; padding-top: 20px; border-top: 1px solid var(--line); font-size: 14px; }
.prevnext a { display: flex; flex-direction: column; gap: 2px; max-width: 48%; line-height: 1.4; }
.prevnext .next { text-align: right; margin-left: auto; }
.prevnext .muted { font-size: 12px; }
.side { position: sticky; top: 60px; max-height: calc(100vh - 60px); overflow-y: auto; margin-top: -48px; padding: 48px 28px 40px; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 28px; font-size: 14px; min-height: calc(100vh - 60px); }
.side .label { margin: 0; }
.side-list { display: flex; flex-direction: column; gap: 10px; line-height: 1.4; }
.toc a { color: var(--ink-3); }
.toc a.active { color: var(--ink); font-weight: 500; }
.facts { margin: 0; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.facts > div { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
.facts > div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; overflow-wrap: anywhere; }
.facts code { font-size: 12px; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.side .facts .dot { background: var(--c); }
.tag { font-family: var(--mono); font-size: 12px; padding: 1px 7px; border-radius: 5px; background: var(--code-bg); color: var(--ink-2); }
.tag:hover { text-decoration: none; color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; background: var(--code-bg); color: var(--ink-2); }
.chip.type { background: color-mix(in srgb, var(--c) 12%, var(--surface)); color: color-mix(in srgb, var(--c) 75%, var(--ink)); }

/* Protected */
.unlock { width: min(480px, 100%); margin: 8vh auto 0; display: flex; flex-direction: column; gap: 24px; grid-column: 1 / -1; }
.unlock-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--btn); color: var(--btn-ink); display: flex; align-items: center; justify-content: center; }
.unlock h1 { margin: 0 0 8px; font-size: 28px; font-weight: 600; letter-spacing: -0.015em; }
.unlock form { display: flex; flex-direction: column; gap: 10px; }
.unlock label { font-size: 14px; font-weight: 500; }
.unlock input { height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 9px; background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; }
.unlock .btn.primary:disabled { opacity: .6; cursor: progress; }
.encrypted-content .decrypt-prompt { display: none; }
.decrypted { display: contents; }
.protected-list { display: flex; flex-direction: column; gap: 28px; }
.protected-list h1 { margin: 0; font-size: 36px; font-weight: 600; letter-spacing: -0.02em; }
.protected-list h2 { margin: 0 0 12px; font-size: 18px; font-weight: 600; }

/* Search panel */
.search-panel { position: fixed; inset: 60px 0 0 0; z-index: 15; display: grid; grid-template-columns: 272px minmax(0, 1fr); background: var(--bg); }
.filters { border-right: 1px solid var(--line); background: var(--side); padding: 24px 20px; display: flex; flex-direction: column; gap: 24px; font-size: 14px; overflow-y: auto; }
.filters fieldset { margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 4px; }
.filters legend { margin: 0 0 8px; padding: 0; }
.filters label { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 36px; cursor: pointer; }
.filters label > span { display: flex; align-items: center; gap: 10px; min-width: 0; }
.filters input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.results { padding: 32px 64px; overflow-y: auto; }
.results h1 { margin: 0 0 16px; font-size: 22px; font-weight: 600; }
.result { display: flex; flex-direction: column; gap: 8px; padding: 18px 20px; margin-bottom: 10px; max-width: 880px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.result:hover, .result.selected { text-decoration: none; border-color: var(--accent); color: var(--ink); }
.result-meta { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.result-title { font-size: 17px; font-weight: 600; line-height: 1.35; }
.result-snip { font-size: 14px; line-height: 1.6; color: var(--ink-3); overflow-wrap: anywhere; }
mark { background: var(--mark); color: var(--ink); padding: 0 2px; border-radius: 3px; }

/* Narrow screens: the tree goes behind the menu button */
@media (max-width: 1180px) {
  .lesson-page { grid-template-columns: minmax(0, 1fr); padding-right: 64px; }
  .side { position: static; max-height: none; min-height: 0; margin: 40px 0 0; padding: 28px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .phone-only { display: flex !important; }
  .top { height: 56px; padding: 0 8px; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px; }
  .top-links, .kbd { display: none; }
  .search { display: none; position: fixed; z-index: 21; justify-self: stretch; left: 0; right: 0; top: 56px; width: auto; height: 52px; padding: 0 20px; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: var(--surface); }
  .search:focus-within { border-color: var(--line); box-shadow: none; }
  body.searching .search { display: flex; }
  .top-end { gap: 4px; }
  .theme button { width: 28px; }
  .unlocked { font-size: 0; padding: 4px; gap: 4px; }
  .frame { display: block; }
  .tree { position: fixed; top: 56px; left: 0; bottom: 0; z-index: 30; width: min(320px, 86vw); height: auto; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open .tree { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 56px 0 0 0; z-index: 25; background: rgba(0, 0, 0, .35); }
  .page, .lesson-page { padding: 20px 20px 40px; gap: 28px; }
  .lesson { gap: 18px; }
  .lesson h1 { font-size: 24px; line-height: 1.3; }
  .type-note { display: none; }
  .prose { font-size: 16px; line-height: 1.65; }
  .prose h2 { font-size: 18px; }
  .page > h1, .intro h1 { font-size: 28px; }
  .kind { margin-bottom: -20px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .row { grid-template-columns: 12px minmax(0, 1fr) auto; }
  .row .mono { display: none; }
  .search-panel { inset: 108px 0 0 0; display: block; overflow-y: auto; }
  .filters { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 20px; flex-direction: row; flex-wrap: wrap; gap: 8px 24px; overflow: visible; }
  .filters fieldset { flex-direction: row; flex-wrap: wrap; gap: 0 14px; }
  .filters legend { width: 100%; margin-bottom: 0; }
  .filters label { min-height: 44px; }
  #search-note { display: none; }
  .results { padding: 20px; overflow: visible; }
  .prevnext { flex-direction: column; }
  .prevnext a { max-width: none; }
  .unlock { margin-top: 24px; }
}
@media (max-width: 380px) {
  .brand { font-size: 15px; gap: 8px; }
  .logo { width: 24px; height: 24px; font-size: 11px; }
  .theme button { width: 26px; }
}

/* Reading helpers */
.skip { position: absolute; left: 12px; top: -48px; z-index: 50; padding: 8px 14px; border-radius: 8px; background: var(--btn); color: var(--btn-ink); font-weight: 500; }
.skip:focus { top: 12px; color: var(--btn-ink); text-decoration: none; }
.main:focus { outline: none; }
.stale-reason { margin: 0; padding: 10px 14px; border-radius: 10px; font-size: 15px; background: #FDF1D6; color: #5C3D00; border: 1px solid #EBD39A; }
:root[data-theme="dark"] .stale-reason { background: #3A2E0E; color: #F0CF7A; border-color: #5C4A1A; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .stale-reason { background: #3A2E0E; color: #F0CF7A; border-color: #5C4A1A; } }
@media print {
  .top, .tree, .scrim, .search-panel, .skip, .code-bar .btn, .anchor, .prevnext, .unlocked { display: none !important; }
  body { background: #FFFFFF; color: #000000; }
  .frame { display: block; min-height: 0; }
  .page, .lesson-page { display: block; padding: 0; max-width: none; }
  .side { position: static; max-height: none; min-height: 0; margin: 24px 0 0; padding: 16px 0 0; border-left: 0; border-top: 1px solid #CCCCCC; }
  .toc { display: none; }
  .prose pre { white-space: pre-wrap; overflow-wrap: anywhere; }
  a { color: inherit; }
}
