:root {
  --bg: #f7f7f4;
  --panel: #ffffff;
  --ink: #1d1f24;
  --muted: #6a6f7a;
  --line: #e2e2dc;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --code-bg: #f1f1ec;
  --ok: #1d7a46;
  --ok-soft: #e3f4ea;
  --err: #b4322a;
  --err-soft: #fbe9e7;
  --chip: #eef0f6;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --panel: #1c1f24; --ink: #e6e6e3; --muted: #9399a4; --line: #2d3138;
    --accent: #7b9cff; --accent-ink: #0f1320; --accent-soft: #232c45; --code-bg: #23262c;
    --ok: #5cc98a; --ok-soft: #183526; --err: #ff8a7f; --err-soft: #3a1f1d; --chip: #282c34;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --panel: #1c1f24; --ink: #e6e6e3; --muted: #9399a4; --line: #2d3138;
  --accent: #7b9cff; --accent-ink: #0f1320; --accent-soft: #232c45; --code-bg: #23262c;
  --ok: #5cc98a; --ok-soft: #183526; --err: #ff8a7f; --err-soft: #3a1f1d; --chip: #282c34;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: var(--accent); }
code, pre, textarea { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--code-bg); padding: 0.05em 0.3em; border-radius: 4px; }
.muted { color: var(--muted); }
.pad { padding: 24px; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.mark { font-family: var(--mono); background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 0 6px; font-size: 15px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 6px; color: var(--ink); text-decoration: none; }
.tabs a:hover { background: var(--chip); }
.tabs a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.core { margin-left: auto; font-size: 13px; }

.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.toc { border-right: 1px solid var(--line); padding: 16px 12px; background: var(--panel); position: sticky; top: 56px; align-self: start; max-height: calc(100vh - 56px); overflow-y: auto; }
.toc h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 16px 8px 6px; }
.toc h3:first-child { margin-top: 0; }
.toc a { display: flex; gap: 8px; padding: 5px 8px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 14.5px; }
.toc a:hover { background: var(--chip); }
.toc a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toc .n { color: var(--muted); min-width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; }
.toc .done .n::before { content: "✓"; color: var(--ok); }
.toc .done .n span { display: none; }
.toc .progress { margin: 18px 8px 0; font-size: 13px; color: var(--muted); }

main { padding: 24px 32px 64px; min-width: 0; }
.lesson-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 32px; align-items: start; }
.lesson { max-width: 62ch; }
.lesson .kicker { color: var(--muted); font-size: 14px; margin: 0; }
.lesson h1 { font-size: 28px; line-height: 1.2; margin: 4px 0 16px; }
.lesson p, .lesson li { margin: 0 0 12px; }
.lesson ul { padding-left: 20px; }
table.mini { border-collapse: collapse; margin: 0 0 14px; font-size: 14.5px; }
table.mini td { border-top: 1px solid var(--line); padding: 5px 10px 5px 0; vertical-align: top; }
.task { margin-top: 20px; padding: 14px 16px; border-radius: 10px; background: var(--accent-soft); border: 1px solid transparent; }
.task.done { background: var(--ok-soft); }
.task b { display: block; margin-bottom: 4px; }
.task .state { display: block; margin-top: 8px; font-size: 14px; color: var(--muted); }
.task.done .state { color: var(--ok); font-weight: 600; }
.nav { display: flex; justify-content: space-between; margin-top: 20px; gap: 12px; }
.nav a { text-decoration: none; }

.work { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.field label .muted { font-weight: 400; }
textarea {
  width: 100%; resize: vertical; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); line-height: 1.5; tab-size: 2; font-size: 14px;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.examples { display: contents; }
button {
  font: inherit; font-size: 14px; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.example { font-size: 13px; padding: 5px 10px; background: var(--chip); border-color: transparent; }
button:disabled { opacity: 0.6; cursor: progress; }

.result { min-height: 40px; }
.result .meta { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.rows-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); max-height: 420px; overflow-y: auto; }
table.rows { border-collapse: collapse; width: 100%; font-size: 14px; }
table.rows th { position: sticky; top: 0; background: var(--panel); text-align: left; font-family: var(--mono); font-weight: 600; color: var(--muted); padding: 7px 12px; border-bottom: 1px solid var(--line); }
table.rows td { padding: 6px 12px; border-top: 1px solid var(--line); vertical-align: top; }
table.rows tr:first-child td { border-top: 0; }
.empty { padding: 12px; color: var(--muted); }
.v-str { color: var(--ink); }
.v-str::before, .v-str::after { content: '"'; color: var(--muted); }
.v-lit { font-family: var(--mono); }
.v-lit small { color: var(--muted); margin-left: 4px; font-family: var(--sans); font-size: 11px; }
.v-ref { display: inline-block; background: var(--chip); border-radius: 5px; padding: 0 6px; cursor: help; }
.v-kw { font-family: var(--mono); color: var(--accent); }
.refusal { border-radius: 8px; padding: 12px 14px; background: var(--err-soft); }
.refusal .code { font-family: var(--mono); font-weight: 700; color: var(--err); }
.refusal p { margin: 6px 0 0; font-size: 14px; }
details { margin-top: 10px; font-size: 13px; }
details pre { background: var(--code-bg); padding: 10px; border-radius: 8px; overflow-x: auto; max-height: 300px; }

.page { max-width: 1100px; }
.page h1 { font-size: 26px; margin: 0 0 8px; }
.page h2 { font-size: 19px; margin: 28px 0 8px; }
.page > p { max-width: 75ch; }
.page pre { background: var(--code-bg); padding: 12px 14px; border-radius: 8px; overflow-x: auto; font-size: 13.5px; line-height: 1.5; }
.grid-table { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.grid-table table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.grid-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid-table td { padding: 6px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.grid-table td.id { font-family: var(--mono); font-size: 12px; color: var(--muted); word-break: break-all; }
.filter { margin: 8px 0 12px; padding: 7px 10px; border-radius: 7px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; width: min(360px, 100%); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 32px; }
.copy { cursor: pointer; }
.copy:hover { color: var(--accent); }

@media (max-width: 1100px) {
  .lesson-grid { grid-template-columns: minmax(0, 1fr); }
  .work { position: static; }
}
@media (max-width: 760px) {
  .top { position: static; padding: 10px 16px; gap: 10px; }
  .core { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .toc { position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); display: flex; overflow-x: auto; gap: 4px; padding: 8px 16px; }
  .toc h3, .toc .progress { display: none; }
  .toc a { flex: none; }
  .toc a .t { display: none; }
  main { padding: 16px 16px 48px; }
  .lesson h1 { font-size: 24px; }
}
