@import url("pygments.css");

:root {
  --bg: #f7f6f2; --panel: #ffffff; --ink: #1d1d1f; --muted: #66645e; --line: #e4e1d8;
  --accent: #2f6f4f; --accent-soft: #e3efe7; --code-bg: #272822; --out-bg: #f1efe8; --bad: #b3261e; --good: #2f6f4f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141513; --panel: #1c1d1b; --ink: #ecebe6; --muted: #a3a19a; --line: #2e2f2c;
    --accent: #7cc59d; --accent-soft: #1f2e25; --code-bg: #1e1f1c; --out-bg: #222320; --bad: #f08a80; --good: #7cc59d;
  }
}
:root[data-theme="dark"] {
  --bg: #141513; --panel: #1c1d1b; --ink: #ecebe6; --muted: #a3a19a; --line: #2e2f2c;
  --accent: #7cc59d; --accent-soft: #1f2e25; --code-bg: #1e1f1c; --out-bg: #222320; --bad: #f08a80; --good: #7cc59d;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 -apple-system, "Segoe UI", Inter, system-ui, sans-serif; }
a { color: var(--accent); }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--ink); text-decoration: none; }
.brand small { font-weight: 400; color: var(--muted); margin-left: 8px; }
.theme { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 16px; }

.layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.side { position: sticky; top: 57px; align-self: start; height: calc(100vh - 57px); overflow: auto; padding: 20px 12px; border-right: 1px solid var(--line); }
.side a { display: flex; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 15px; }
.side a span { color: var(--muted); font-variant-numeric: tabular-nums; width: 22px; }
.side a:hover { background: var(--panel); }
.side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { padding: 28px 32px 80px; min-width: 0; }

.kicker { text-transform: uppercase; letter-spacing: .08em; font-size: 12px; color: var(--accent); font-weight: 700; margin: 0 0 6px; }
h1 { font-size: 34px; line-height: 1.15; margin: 0 0 10px; letter-spacing: -.01em; }
.lesson-head { max-width: 900px; margin-bottom: 26px; }
.lesson-head > p { color: var(--muted); font-size: 18px; margin: 0 0 8px; }
.dl a { font-size: 14px; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.legend span { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }

.row { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 28px; padding: 24px 0; border-top: 1px solid var(--line); }
.row.full { grid-template-columns: minmax(0, 1fr); }
.row.full .explain { max-width: 820px; }
.explain { position: sticky; top: 80px; align-self: start; }
.explain h1 { font-size: 28px; } .explain h2 { font-size: 22px; margin: 0 0 8px; } .explain h3 { font-size: 18px; margin: 14px 0 6px; }
.explain p, .explain li { color: var(--ink); }
.explain code, .prose code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.explain pre, .prose pre { background: var(--out-bg); padding: 10px 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
.explain pre code, .prose pre code { background: none; padding: 0; }
.explain blockquote, .prose blockquote { margin: 12px 0; padding: 8px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 8px 8px 0; }
.explain table, .prose table, .results table { border-collapse: collapse; margin: 10px 0; font-size: 14px; display: block; overflow-x: auto; }
.explain th, .explain td, .prose th, .prose td, .results th, .results td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.explain th, .prose th, .results th { background: var(--panel); }

.code-col { min-width: 0; }
pre.code { background: var(--code-bg); color: #f8f8f2; padding: 14px 16px; border-radius: 10px; overflow-x: auto; font: 13.5px/1.55 "JetBrains Mono", Consolas, Menlo, monospace; margin: 0 0 10px; }
pre.out { background: var(--out-bg); border: 1px solid var(--line); padding: 10px 14px; border-radius: 8px; overflow-x: auto; font: 12.5px/1.5 Consolas, Menlo, monospace; margin: 0 0 10px; max-height: 360px; }
pre.out::before { content: "output"; display: block; font: 600 10px/1 system-ui, sans-serif; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
pre.err { color: var(--bad); }
img.plot { max-width: 100%; height: auto; background: #fff; border-radius: 8px; border: 1px solid var(--line); margin: 0 0 10px; display: block; }
.table-wrap { overflow-x: auto; margin: 0 0 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.table-wrap table { border-collapse: collapse; font-size: 12.5px; }
.table-wrap th, .table-wrap td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.table-wrap thead th { background: var(--out-bg); }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--line); }
.pager a { padding: 10px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); text-decoration: none; font-weight: 600; }

.hero { max-width: 760px; margin-bottom: 24px; }
.hero > p { font-size: 18px; color: var(--muted); }
.flow { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 28px; }
.flow span { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 14px; }
.flow span:not(:last-child)::after { content: " →"; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-bottom: 34px; }
.card { display: block; padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; color: var(--ink); text-decoration: none; transition: transform .12s, border-color .12s; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .num { color: var(--accent); font-weight: 700; font-size: 14px; }
.card h3 { margin: 4px 0 6px; font-size: 19px; } .card p { margin: 0; color: var(--muted); font-size: 15px; }
.results { max-width: 760px; }
.results tr.bad td { color: var(--bad); } .results tr.good td { color: var(--good); font-weight: 600; }
.prose { max-width: 820px; }
.prose h1 { margin-top: 0; } .prose h2 { margin-top: 36px; padding-top: 14px; border-top: 1px solid var(--line); }

@media (max-width: 1000px) {
  .row { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .explain { position: static; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; display: flex; overflow-x: auto; gap: 4px; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side a { white-space: nowrap; }
  main { padding: 20px 16px 60px; }
  h1 { font-size: 27px; }
  .brand small { display: none; }
}
