:root {
  --bg: #fafaf7;
  --surface: #ffffff;
  --ink: #1c1c1a;
  --muted: #6b6b66;
  --line: #d9d8d2;
  --accent: #1f4e79;
  --accent-soft: #e4ecf4;
  --warn: #8a3b12;
  --warn-soft: #f6e9e1;
  --code-bg: #f0efe9;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1b1b1a;
    --ink: #e8e7e2;
    --muted: #9a9993;
    --line: #34342f;
    --accent: #8db4dc;
    --accent-soft: #1d2a38;
    --warn: #e3a07a;
    --warn-soft: #2b1f18;
    --code-bg: #22221f;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.65 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 12px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  white-space: nowrap;
}
.brand { font-weight: 650; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.subjects { display: flex; gap: 18px; font-size: 14px; }
.subjects a { color: var(--muted); text-decoration: none; padding: 4px 0; border-bottom: 2px solid transparent; }
.subjects a:hover { color: var(--ink); }
.subjects a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 48px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 32px 24px 96px;
}
.toc { position: sticky; top: 72px; align-self: start; max-height: calc(100vh - 96px); overflow-y: auto; font-size: 14px; }
.toc:empty { display: none; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0 0 2px; }
.toc a { display: block; padding: 6px 8px; border-radius: 4px; color: var(--muted); text-decoration: none; line-height: 1.4; }
.toc a:hover { background: var(--accent-soft); color: var(--ink); }
.toc a.read { opacity: .55; }
.toc .id { display: block; font-size: 11px; letter-spacing: .06em; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-title { margin: 0 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.layout:has(.toc:empty) { grid-template-columns: minmax(0, 1fr); max-width: 820px; }

main { min-width: 0; max-width: 760px; }
.subject-head h1 { font-size: 34px; line-height: 1.2; margin: 4px 0 16px; letter-spacing: -.01em; }
.subject-head p { color: var(--muted); }
.chid { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-variant-numeric: tabular-nums; }

.chapter { padding-top: 48px; margin-top: 48px; border-top: 1px solid var(--line); }
.chapter h2 { font-size: 24px; line-height: 1.3; margin: 4px 0 20px; letter-spacing: -.005em; }
.badge { display: inline-block; margin-left: 10px; padding: 1px 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; font-weight: 500; color: var(--muted); vertical-align: middle; letter-spacing: 0; }

.chapter p { margin: 0 0 14px; }
.chapter ul, .chapter ol { margin: 0 0 16px; padding-left: 22px; }
.chapter li { margin: 0 0 6px; }
.chapter li > ul, .chapter li > ol { margin-top: 6px; }
.chapter strong { font-weight: 650; }
.chapter p > strong:first-child { color: var(--accent); }
code {
  font-family: ui-monospace, "Cascadia Code", Consolas, "SF Mono", monospace;
  font-size: .9em;
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  overflow-wrap: anywhere;
}
table { border-collapse: collapse; margin: 0 0 18px; font-size: 14px; display: block; overflow-x: auto; }
th, td { border: 1px solid var(--line); padding: 6px 12px; text-align: left; }
th { background: var(--accent-soft); font-weight: 600; }
hr { display: none; }

.done { margin: 28px 0 0 !important; font-size: 14px; color: var(--muted); }
.done label { cursor: pointer; display: inline-flex; gap: 8px; align-items: center; }
.done input { width: 16px; height: 16px; accent-color: var(--accent); }

figure.diagram {
  margin: 8px 0 22px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}
figure.diagram svg { display: block; width: 100%; height: auto; max-width: 720px; margin: 0 auto; }
figure.diagram figcaption { margin-top: 10px; font-size: 13px; color: var(--muted); text-align: center; }

/* SVG classes used by the diagrams (theme-aware) */
svg .ln   { stroke: var(--ink);   fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
svg .ln2  { stroke: var(--muted); fill: none; stroke-width: 1; }
svg .dash { stroke: var(--muted); fill: none; stroke-width: 1; stroke-dasharray: 4 3; }
svg .lna  { stroke: var(--accent); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .lnw  { stroke: var(--warn); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg .bx   { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; }
svg .bxa  { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.5; }
svg .bxw  { fill: var(--warn-soft); stroke: var(--warn); stroke-width: 1.5; }
svg .fa   { fill: var(--accent-soft); stroke: none; }
svg .fw   { fill: var(--warn-soft); stroke: none; }
svg .dot  { fill: var(--ink); stroke: none; }
svg .dota { fill: var(--accent); stroke: none; }
svg .tx   { fill: var(--ink);    font: 14px system-ui, sans-serif; }
svg .tm   { fill: var(--muted);  font: 12px system-ui, sans-serif; }
svg .ta   { fill: var(--accent); font: 14px system-ui, sans-serif; font-weight: 600; }
svg .tw   { fill: var(--warn);   font: 14px system-ui, sans-serif; font-weight: 600; }
svg .tb   { font-weight: 650; }
svg .mid  { text-anchor: middle; }
svg .end  { text-anchor: end; }
svg .math { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
svg .arr  { fill: var(--ink); }

/* index */
.cards { display: grid; gap: 28px; margin-top: 32px; }
.subject-card { padding-top: 24px; border-top: 1px solid var(--line); }
.subject-card h2 { margin: 4px 0 2px; font-size: 22px; }
.subject-card h2 a { color: var(--ink); text-decoration: none; }
.subject-card h2 a:hover { color: var(--accent); }
.subject-card .count { margin: 0 0 10px; color: var(--muted); font-size: 14px; }
.subject-card ul { margin: 0; padding-left: 18px; columns: 2 280px; column-gap: 32px; font-size: 14px; }
.subject-card li { margin: 0 0 4px; break-inside: avoid; }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 20px 16px 72px; }
  .toc { position: static; max-height: none; margin-bottom: 8px; }
  .toc ol { columns: 1; }
  .top { padding: 10px 16px; }
  .subject-head h1 { font-size: 28px; }
}
@media print {
  .top, .toc, .done { display: none; }
  .layout { display: block; padding: 0; }
  .chapter { break-inside: avoid-page; }
}

.toc summary { cursor: pointer; list-style: none; }
.toc summary::-webkit-details-marker { display: none; }
@media (min-width: 861px) { .toc summary { pointer-events: none; cursor: default; } }
@media (max-width: 860px) { .toc summary::after { content: " ▾"; } .toc details:not([open]) summary::after { content: " ▸"; } }

/* rumus KaTeX */
.katex { font-size: 1.06em; }
.katex-display { margin: 0.6em 0; overflow-x: auto; overflow-y: hidden; }
li .katex-display { margin: 0.3em 0; }
/* diagram tetap terbaca pada layar sempit: gulir mendatar, bukan mengecil */
figure.diagram { overflow-x: auto; }
figure.diagram svg { min-width: 560px; }
.chapter table { display: block; overflow-x: auto; }
