:root {
  --bg: #faf8f3;
  --panel: #fffdf8;
  --ink: #1f2328;
  --muted: #6b7280;
  --rule: #e6e0d4;
  --accent: #7a3e1d;
  --accent-soft: #f0e6d8;
  --code-bg: #f5f1e8;
  --redex-bg: #ffe39b;
  --redex-ink: #6b3b00;
  --ok: #1f6f43;
  --err: #b3261e;
  --mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--serif); line-height: 1.6; font-size: 18px;
}
a { color: var(--accent); }

.app { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }

/* ---- Sidebar / TOC ---- */
.sidebar {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  border-right: 1px solid var(--rule); background: var(--panel); padding: 22px 18px;
}
.site-footer { text-align: center; padding: 16px 24px 24px; border-top: 1px solid var(--rule); font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.site-footer a { color: var(--muted); text-decoration: underline; }
.site-footer a:hover { color: var(--fg); }
.home-link { display: block; font-family: var(--mono); font-size: 11px; color: var(--muted); text-decoration: none; letter-spacing: .05em; margin-bottom: 14px; }
.home-link:hover { color: var(--fg); }
.sidebar h1 { font-size: 17px; margin: 0 0 4px; letter-spacing: .2px; }
.sidebar .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 18px; font-family: var(--mono); }
.toc a { display: block; text-decoration: none; color: var(--ink); padding: 3px 6px; border-radius: 5px; font-size: 14.5px; }
.toc a.lvl-sec { font-weight: 700; margin-top: 10px; }
.toc a.lvl-sub { padding-left: 16px; color: #44484e; }
.toc a:hover { background: var(--accent-soft); }
.toc a.active { background: var(--accent-soft); color: var(--accent); }

/* ---- Reading column ---- */
.main { padding: 36px 0 120px; }
.reader { max-width: 760px; margin: 0 auto; padding: 0 28px; }
.reader h2 { font-size: 30px; margin: 8px 0 6px; }
.reader h2 .num { color: var(--accent); font-family: var(--mono); font-size: 22px; margin-right: 10px; }
.reader h3 { font-size: 22px; margin: 38px 0 4px; border-top: 1px solid var(--rule); padding-top: 26px; }
.reader h3 .num { color: var(--accent); font-family: var(--mono); font-size: 16px; margin-right: 8px; }
.reader h4 { font-size: 16px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 26px 0 2px; }
.reader p { margin: 14px 0; }
.reader code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.reader ul, .reader ol { margin: 12px 0; padding-left: 26px; }
.reader li { margin: 6px 0; }
blockquote { margin: 16px 0; padding: 12px 18px; background: var(--accent-soft); border-left: 4px solid var(--accent); border-radius: 0 6px 6px 0; }
blockquote p:first-child { margin-top: 0; } blockquote p:last-child { margin-bottom: 0; }

/* ---- Static code (non-live) ---- */
pre.static {
  font-family: var(--mono); font-size: 14.5px; line-height: 1.45;
  background: var(--code-bg); border: 1px solid var(--rule); border-radius: 8px;
  padding: 12px 14px; overflow-x: auto; margin: 14px 0;
}

/* ---- Live REPL block ---- */
.repl { margin: 16px 0; border: 1px solid var(--rule); border-radius: 9px; overflow: hidden; background: var(--panel); }
.repl .editor {
  width: 100%; border: 0; resize: vertical; min-height: 2.4em;
  font-family: var(--mono); font-size: 14.5px; line-height: 1.5; padding: 12px 14px;
  background: #fffef9; color: var(--ink); outline: none; display: block;
}
.repl .bar { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-top: 1px solid var(--rule); background: #faf6ed; }
.repl .bar .spacer { flex: 1; }
.repl button {
  font-family: var(--mono); font-size: 12.5px; cursor: pointer; border: 1px solid var(--rule);
  background: #fff; color: var(--ink); padding: 5px 12px; border-radius: 6px;
}
.repl button.run { background: var(--accent); color: #fff; border-color: var(--accent); }
.repl button:hover { filter: brightness(.97); }
.repl .out {
  font-family: var(--mono); font-size: 14px; white-space: pre-wrap; padding: 0 14px;
  max-height: 0; overflow: hidden; transition: max-height .15s ease, padding .15s ease;
}
.repl .out.show { max-height: 400px; overflow-y: auto; padding: 10px 14px; border-top: 1px dashed var(--rule); }
.repl .out .val { color: var(--ok); } .repl .out .disp { color: var(--ink); } .repl .out .err { color: var(--err); }
.repl .out .echo { color: var(--muted); }

/* ---- Stepper ---- */
.stepper { margin: 18px 0; border: 1px solid var(--accent); border-radius: 10px; overflow: hidden; background: var(--panel); }
.stepper .head { background: var(--accent); color: #fff; font-family: var(--mono); font-size: 12px; letter-spacing: .05em; padding: 6px 12px; text-transform: uppercase; }
.stepper .seed { width: 100%; border: 0; border-bottom: 1px solid var(--rule); resize: vertical; min-height: 3em; font-family: var(--mono); font-size: 14px; padding: 10px 14px; background: #fffef9; outline: none; }
.stepper .bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; background: #faf6ed; border-bottom: 1px solid var(--rule); }
.stepper .bar .count { margin-left: auto; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.stepper button { font-family: var(--mono); font-size: 12.5px; cursor: pointer; border: 1px solid var(--rule); background: #fff; padding: 5px 12px; border-radius: 6px; }
.stepper button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.stepper button:disabled { opacity: .4; cursor: default; }
.stepper .steps { font-family: var(--mono); font-size: 15px; line-height: 1.7; padding: 12px 14px 16px; overflow-x: auto; }
.stepper .row { display: flex; gap: 12px; padding: 2px 0; opacity: .45; transition: opacity .2s; }
.stepper .row.on { opacity: 1; }
.stepper .row .idx { color: var(--muted); user-select: none; min-width: 1.6em; text-align: right; }
.stepper .row .expr { white-space: pre; }
.stepper .row .note { color: var(--muted); font-size: 12.5px; align-self: center; }
.redex { background: var(--redex-bg); color: var(--redex-ink); border-radius: 3px; padding: 0 2px; box-shadow: 0 0 0 1px #e8c66a inset; }

/* ---- Notes drawer ---- */
.notes-toggle { position: fixed; right: 18px; bottom: 18px; z-index: 20; border: 1px solid var(--accent); background: var(--accent); color: #fff; font-family: var(--mono); font-size: 13px; padding: 9px 14px; border-radius: 22px; cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,.15); }
.notes { position: fixed; right: -380px; top: 0; width: 360px; height: 100vh; background: var(--panel); border-left: 1px solid var(--rule); transition: right .2s ease; z-index: 19; display: flex; flex-direction: column; box-shadow: -6px 0 24px rgba(0,0,0,.06); }
.notes.open { right: 0; }
.notes h3 { margin: 0; padding: 18px 18px 8px; font-family: var(--serif); font-size: 18px; }
.notes p.hint { margin: 0 18px 8px; color: var(--muted); font-size: 12.5px; }
.notes textarea { flex: 1; margin: 0 14px 14px; border: 1px solid var(--rule); border-radius: 8px; resize: none; padding: 12px; font-family: var(--mono); font-size: 14px; line-height: 1.5; outline: none; }
.notes .saved { padding: 0 18px 14px; color: var(--ok); font-size: 12px; font-family: var(--mono); }

@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--rule); }
}
