:root {
  --top: 68px;
  --side: 340px;
  --side-bg: #3b3b3b;
  --side-head: #444444;
  --side-text: #ececec;
  --side-active: #545454;
  --text: #222;
  --muted: #777;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --red: #e8553e;
  --blue: #0b5cad;
  --mint: #e3fbf1;
}

* { box-sizing: border-box; }
html { scroll-padding-top: calc(var(--top) + 16px); }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #fff;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--top); z-index: 30;
  display: flex; align-items: center; gap: 14px; padding: 0 28px 0 64px;
  background: #fff; border-bottom: 1px solid #e6e6e6;
}
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #111; }
.logo svg { width: 30px; height: 30px; }
.logo span { font-size: 23px; font-weight: 700; letter-spacing: -0.3px; }
.logo span em { font-style: normal; color: var(--red); }
.top-right { margin-left: auto; color: var(--muted); font-size: 14px; }
.menu-btn {
  display: none; border: 1px solid #ddd; background: #fff; border-radius: 8px;
  width: 40px; height: 40px; font-size: 20px; cursor: pointer; color: #333;
}

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  position: fixed; top: var(--top); bottom: 0; left: 0; width: var(--side); z-index: 20;
  background: var(--side-bg); overflow-y: auto; overscroll-behavior: contain;
  scrollbar-color: #666 transparent;
}
.sec-head {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 22px 22px 22px 16px; border: 0; background: var(--side-head); color: #fff;
  font: inherit; font-size: 18px; font-weight: 700; text-align: left; cursor: pointer;
}
.sec-head b { margin-right: 6px; }
.sec-head:hover { background: #4b4b4b; }
.chev { fill: none; stroke: #ddd; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; flex: none; transition: transform .2s; }
.sec.collapsed .chev { transform: rotate(180deg); }
.sec.collapsed .items { display: none; }
.items { list-style: none; margin: 0; padding: 10px 4px 14px; }
.items a {
  display: block; padding: 18px 40px; border-radius: 4px; color: var(--side-text);
  text-decoration: none; font-size: 16px; font-weight: 500; line-height: 1.3;
}
.items a:hover { background: #474747; }
.items a.active { background: var(--side-active); color: #fff; }

/* ---------------------------------------------------------------- content */
.main { margin-left: var(--side); padding: calc(var(--top) + 26px) 48px 80px; }
.lesson { max-width: 1060px; margin: 0 auto; font-size: 17px; line-height: 1.8; }
.crumb { color: var(--muted); font-size: 14px; font-weight: 600; letter-spacing: .3px; text-transform: uppercase; }
.lesson h1 { font-size: 44px; line-height: 1.15; margin: 6px 0 26px; letter-spacing: -0.5px; }
.lesson h2 { font-size: 32px; margin: 42px 0 14px; letter-spacing: -0.3px; }
.lesson h3 { font-size: 21px; margin: 30px 0 12px; }
.lesson p { margin: 0 0 16px; text-align: justify; }
.lesson ul, .lesson ol { padding-left: 30px; margin: 0 0 18px; }
.lesson li { margin-bottom: 8px; }
.lesson a { color: var(--blue); }
.lesson strong { font-weight: 700; }
.chip {
  font-family: var(--mono); font-size: .86em; background: #efefef; border: 1px solid #d9d9d9;
  border-radius: 4px; padding: 1px 5px; white-space: nowrap;
}
.math { font-family: "Times New Roman", "STIX Two Text", serif; font-size: 1.08em; white-space: nowrap; }
.math sup { font-size: .7em; }
.note {
  border-left: 4px solid var(--red); background: #fff6f3; padding: 12px 18px; border-radius: 0 6px 6px 0;
  margin: 0 0 18px;
}
.lesson hr { border: 0; border-top: 1px solid #e6e6e6; margin: 26px 0; }

.example {
  border: 1px solid #e3e3e3; border-radius: 10px; padding: 22px 28px; margin: 0 0 18px;
  font-family: var(--mono); font-size: 16px; color: var(--blue); line-height: 1.75; overflow-x: auto;
  white-space: pre-wrap; word-break: break-word;
}
.expl { text-align: left !important; }

.tbl { border-collapse: collapse; margin: 0 0 20px; font-size: 15.5px; width: 100%; }
.tbl th, .tbl td { border: 1px solid #e3e3e3; padding: 8px 12px; text-align: left; vertical-align: top; }
.tbl th { background: #f6f6f6; }

/* ---------------------------------------------------------------- diagrams */
.dg { margin: 18px 0 22px; overflow-x: auto; }
.dg figcaption { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.dgrow { display: flex; align-items: flex-end; gap: 30px; flex-wrap: wrap; }
.dgline { display: flex; gap: 36px; flex-wrap: wrap; align-items: flex-end; }
.dgline .dg { margin: 10px 0; }
.arr { display: flex; align-items: flex-end; font-family: var(--mono); }
.col { display: flex; flex-direction: column; align-items: center; min-width: 38px; }
.col.br, .col.name { min-width: 0; }
.col.br .v { padding: 0 1px; }
.col.ch { min-width: 26px; }
.ptrs { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.tag {
  font-size: 12px; line-height: 1; padding: 3px 6px; border: 1.3px solid #555; border-radius: 4px;
  color: #444; background: #fff; margin-top: 3px; white-space: nowrap;
}
.tag.on { border-color: var(--red); color: var(--red); background: #fff4f1; }
.down { width: 1.5px; height: 14px; background: #555; position: relative; margin-top: 1px; }
.down::after {
  content: ""; position: absolute; left: -4px; bottom: -2px; border: 4.5px solid transparent;
  border-top: 6px solid #555; border-bottom: 0;
}
.down.on { background: var(--red); }
.down.on::after { border-top-color: var(--red); }
.v { font-size: 19px; line-height: 1.6; padding: 0 5px; border-radius: 5px; white-space: pre; color: #111; }
.ix { font-size: 11.5px; color: #8a8a8a; height: 16px; }
.col.hl .v { background: #ffe2cc; }
.col.hl2 .v { background: #d6e9ff; }
.col.dim .v { color: #bbb; }
.col.ghost .v { color: transparent; }
.ll .node .box {
  display: inline-block; min-width: 36px; text-align: center; border: 1.6px solid #444; border-radius: 7px;
  padding: 0 6px; background: #fff; font-size: 18px; line-height: 32px;
}
.ll .node.hl .box { background: #ffe2cc; border-color: var(--red); }
.ll .node.hl2 .box { background: #d6e9ff; border-color: #3c7bd0; }
.ll .node.dim .box { color: #bbb; border-color: #ccc; }
.ll .node .v, .ll .link .v { line-height: 36px; }
.ll .node .v { padding: 0; background: none !important; }
.ll .link { min-width: 22px; color: #555; }
.ll .ix { display: none; }
.tail { font-size: 14px; color: #888; }
.state {
  font-family: var(--mono); font-size: 15.5px; background: #f1f1f1; border: 1.6px dashed #a2a2a2;
  border-radius: 7px; padding: 9px 16px; margin-bottom: 18px; white-space: pre-wrap; line-height: 1.6;
}
.dg > .state { display: inline-block; margin: 0; }
.state .chip { background: #fff; }

.grid { border-collapse: collapse; font-family: var(--mono); font-size: 16px; }
.grid td, .grid th { width: 40px; height: 36px; text-align: center; padding: 0 4px; }
.grid td { border: 1.4px solid #bdbdbd; background: #fff; }
.grid th { color: #8a8a8a; font-size: 12.5px; font-weight: 500; }
.grid td.hl { background: #ffe2cc; }
.grid td.hl2 { background: #d6e9ff; }
.grid td.dim { color: #bbb; background: #f6f6f6; }

svg.tree line, svg.graph line { stroke: #666; stroke-width: 1.6; }
svg.tree circle, svg.graph circle { fill: #fff; stroke: #444; stroke-width: 1.6; }
svg.tree text, svg.graph text { font-family: var(--mono); font-size: 14px; text-anchor: middle; fill: #111; }
svg .hl circle { fill: #ffe2cc; stroke: var(--red); }
svg .hl2 circle { fill: #d6e9ff; stroke: #3c7bd0; }
svg.graph line.hot { stroke: var(--red); stroke-width: 2.6; }
svg.graph text.wt { font-size: 12.5px; fill: #555; }
svg.bars rect { fill: #cfcfcf; }
svg.bars rect.hl { fill: #f7a37e; }
svg.bars rect.hl2 { fill: #8fbdf0; }
svg.bars rect.dim { fill: #ececec; }
svg.bars .gridline { stroke: #eee; }
svg.bars text { font-family: var(--mono); font-size: 12px; fill: #777; }
svg.bars text.tick { text-anchor: middle; }
svg.bars text.lab { text-anchor: end; fill: #333; }

pre.ascii {
  font-family: var(--mono); font-size: 15px; line-height: 1.5; background: #fafafa; border: 1px solid #ececec;
  border-radius: 8px; padding: 14px 18px; overflow-x: auto; margin: 0 0 20px;
}

/* ---------------------------------------------------------------- code tabs */
.codebox { border: 1px solid #d8d8d8; border-radius: 10px; overflow: hidden; margin: 8px 0 26px; }
.tabs { display: flex; align-items: flex-end; gap: 4px; background: var(--mint); padding: 8px 14px 0; border-bottom: 1px solid #d8d8d8; }
.tab {
  border: 1px solid transparent; border-bottom: 0; background: none; padding: 9px 20px; font: inherit; font-size: 16px;
  color: #444; cursor: pointer; border-radius: 8px 8px 0 0; margin-bottom: -1px;
}
.tab:hover { color: #000; }
.tab.active { background: #fff; border-color: #d8d8d8; color: #0a5c3c; font-weight: 600; }
.copy {
  margin: 0 0 7px auto; border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 6px; position: relative;
  display: flex; align-items: center; gap: 6px; color: #333;
}
.copy:hover { background: rgba(0, 0, 0, .06); }
.copy svg { fill: none; stroke: #333; stroke-width: 1.8; }
.copy .copied { display: none; font-size: 13px; color: #0a7a4a; }
.copy.done .copied { display: inline; }
.pane { display: none; margin: 0; padding: 18px 22px; overflow-x: auto; font-family: var(--mono); font-size: 15px; line-height: 1.65; background: #fff; }
.pane.active { display: block; }
.tk { color: #d73a49; }
.tf { color: #6f42c1; }
.tb { color: #e36209; }
.tv { color: #0550ae; }
.ts { color: #0a6b2e; }
.tn { color: #005cc5; }
.tc { color: #6a737d; font-style: italic; }
.td { color: #b0560b; }

.cx li { margin-bottom: 10px; }

/* ---------------------------------------------------------------- pager */
.pager { display: flex; justify-content: space-between; gap: 16px; margin-top: 56px; padding-top: 24px; border-top: 1px solid #e6e6e6; }
.pager a {
  display: flex; flex-direction: column; text-decoration: none; color: #111; font-weight: 600; padding: 12px 18px;
  border: 1px solid #e3e3e3; border-radius: 10px; max-width: 48%;
}
.pager a:hover { border-color: #bbb; background: #fafafa; }
.pager a.next { text-align: right; margin-left: auto; }
.pager small { color: var(--muted); font-weight: 500; font-size: 13px; }

.scrim { display: none; }

/* ---------------------------------------------------------------- narrow */
@media (max-width: 1100px) {
  :root { --side: 300px; }
  .main { padding-left: 32px; padding-right: 32px; }
}
@media (max-width: 900px) {
  :root { --top: 60px; }
  .topbar { padding: 0 14px; }
  .menu-btn { display: block; }
  .sidebar { width: min(330px, 86vw); transform: translateX(-100%); transition: transform .22s ease; box-shadow: 4px 0 20px rgba(0, 0, 0, .25); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: var(--top) 0 0 0; background: rgba(0, 0, 0, .35); z-index: 15; }
  body.nav-open { overflow: hidden; }
  .main { margin-left: 0; padding: calc(var(--top) + 18px) 18px 60px; }
  .lesson { font-size: 16px; }
  .lesson h1 { font-size: 32px; }
  .lesson h2 { font-size: 26px; }
  .lesson p { text-align: left; }
  .example { padding: 16px; font-size: 14.5px; }
  .top-right { display: none; }
  .items a { padding: 14px 28px; }
}

/* ================================================================ kits & home */
:root { --green: #1fae7a; --green-d: #128a5e; --mint-l: #d9f7ea; }
.top-right a { color: #333; text-decoration: none; font-weight: 600; font-size: 15px; padding: 8px 14px; border-radius: 8px; }
.top-right a:hover { background: #f2f2f2; }

/* sidebar header with progress */
.side-head { padding: 22px 22px 18px; border-bottom: 1px solid #4a4a4a; }
.side-head .back { color: #bfbfbf; text-decoration: none; font-size: 13.5px; font-weight: 600; }
.side-head .back:hover { color: #fff; }
.side-title { color: #e4e4e4; font-size: 23px; font-weight: 700; line-height: 1.2; margin: 14px 0 12px; letter-spacing: -.2px; }
.side-progress { color: #fff; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.bar { height: 6px; background: #2a2a2a; border-radius: 4px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--green); border-radius: 4px; transition: width .3s; }
.items a.done::after { content: " ✓"; color: #36d399; }

.chapters { list-style: none; margin: 0; padding: 14px 10px 30px; }
.chapters a {
  display: flex; align-items: center; gap: 12px; padding: 20px 12px; border-radius: 6px; color: #f1f1f1;
  text-decoration: none; font-size: 16px; font-weight: 500; line-height: 1.35;
}
.chapters a:hover { background: #474747; }
.chapters a.active { background: var(--side-active); }
.chapters .cn { color: #a9a9a9; font-size: 15px; min-width: 22px; }
.chapters .ct { flex: 1; }
.chapters .go { fill: none; stroke: #36c08c; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.chapters .ok { color: #36d399; font-weight: 700; }

/* chapter header */
.bignum { font-size: 92px; font-weight: 800; color: var(--green); line-height: .95; letter-spacing: -2px; margin-top: 10px; }
.lesson h1.chap { margin-top: 2px; }

.talk { border-left: 3px solid #e3e3e3; padding: 2px 0 2px 18px; margin: 0 0 20px; }
.talk p { margin-bottom: 10px; }
.figcap { text-align: center !important; color: #333; font-size: 15px; margin-top: -6px !important; }
.dg.center .dgrow { justify-content: center; }
.tblwrap { overflow-x: auto; margin: 0 0 20px; }
.tblwrap .tbl { margin: 0; }

/* architecture diagrams */
svg.flow line { stroke: #555; stroke-width: 1.5; }
svg.flow rect, svg.flow path.db, svg.flow ellipse.db { stroke: #2b3a33; stroke-width: 1.4; fill: #fff; }
svg.flow rect.client { fill: #e7f1ff; stroke: #3c6fb0; }
svg.flow rect.service { fill: #fff; }
svg.flow rect.cache { fill: #fff3e0; stroke: #c27a1a; }
svg.flow rect.queue { fill: #f3ecff; stroke: #6b4bb0; }
svg.flow rect.store { fill: #eef7f2; }
svg.flow rect.ml { fill: var(--mint-l); stroke: var(--green-d); }
svg.flow rect.ext { fill: #fafafa; stroke-dasharray: 5 4; }
svg.flow rect.note { fill: #fffbe6; stroke: #d6c27a; }
svg.flow path.db, svg.flow ellipse.db { fill: #e9f7f0; stroke: var(--green-d); }
svg.flow .qline { stroke: #6b4bb0; stroke-width: 1; }
svg.flow text.nl { font-size: 13.5px; text-anchor: middle; fill: #1d2b24; font-weight: 600; }
svg.flow text.nl tspan.sub { font-size: 11.5px; font-weight: 400; fill: #555; }
svg.flow text.el { font-size: 11.5px; text-anchor: middle; fill: #444; paint-order: stroke; stroke: #fff; stroke-width: 4px; stroke-linejoin: round; }

/* complete button */
.complete { margin: 46px 0 0; display: flex; justify-content: center; }
.mark {
  font: inherit; font-size: 16px; font-weight: 600; padding: 12px 28px; border-radius: 10px; cursor: pointer;
  border: 1.5px solid var(--green); color: var(--green-d); background: #fff;
}
.mark:hover { background: #effbf6; }
.mark.is-done { background: var(--green); color: #fff; }

/* ---- home page ---- */
#home { display: none; }
body.home #home { display: block; }
body.home .sidebar, body.home .main, body.home .menu-btn { display: none; }
.hero { padding: calc(var(--top) + 70px) 24px 70px; background: radial-gradient(1200px 400px at 50% 0%, #e6fbf2 0%, #fff 70%); text-align: center; }
.hero-in { max-width: 920px; margin: 0 auto; }
.eyebrow { display: inline-block; font-size: 13.5px; font-weight: 700; color: var(--green-d); background: var(--mint-l); padding: 6px 14px; border-radius: 999px; letter-spacing: .3px; text-transform: uppercase; }
.hero h1 { font-size: 56px; line-height: 1.08; letter-spacing: -1.2px; margin: 22px 0 18px; }
.hl-word { background: linear-gradient(transparent 62%, #a8efcf 62%); }
.lead { font-size: 19px; color: #444; line-height: 1.65; max-width: 760px; margin: 0 auto 30px; }
.cta { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.btn { font: inherit; font-size: 17px; font-weight: 700; padding: 15px 30px; border-radius: 999px; cursor: pointer; text-decoration: none; border: 2px solid var(--green); }
.btn.primary { background: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-d); border-color: var(--green-d); }
.btn.ghost { background: #fff; color: var(--green-d); }
.btn.ghost:hover { background: #effbf6; }
.stats { display: flex; justify-content: center; gap: 48px; margin-top: 46px; flex-wrap: wrap; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-size: 34px; color: #111; }
.stats span { color: #666; font-size: 14px; }

.kits { background: #f5f5f5; padding: 70px 24px 80px; }
.section-title { text-align: center; font-size: 40px; letter-spacing: -.6px; margin: 0 0 44px; }
.section-title span { background: linear-gradient(transparent 88%, var(--green) 88%); background-size: 32% 100%; background-repeat: no-repeat; padding-bottom: 6px; }
.kit-grid { max-width: 1320px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 34px; }
.kit {
  position: relative; display: flex; flex-direction: column; background: #fff; border: 1.5px solid #dcdcdc; border-radius: 22px;
  padding: 14px; text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s;
}
.kit:hover { transform: translateY(-4px); box-shadow: 0 12px 30px rgba(0, 0, 0, .1); }
.kit-title {
  background: #3ed6a1; color: #0d2a1f; border-radius: 14px; padding: 14px 12px; text-align: center; font-size: 21px; font-weight: 700;
  line-height: 1.2; min-height: 76px; display: flex; align-items: center; justify-content: center;
}
.kit-art { background: #f4fdf9; border-radius: 12px; margin-top: 12px; padding: 8px; }
.kit-art svg { display: block; width: 100%; height: auto; }
.kit-foot { padding: 14px 6px 4px; flex: 1; display: flex; flex-direction: column; }
.kit-foot p { margin: 0 0 14px; color: #444; font-size: 15px; line-height: 1.55; flex: 1; }
.kit-meta { display: flex; gap: 10px; align-items: center; font-size: 14px; color: #666; font-weight: 600; }
.kit-done { color: var(--green-d); }
.kit-go { margin-left: auto; color: var(--green-d); }
.badge { position: absolute; top: -10px; right: -8px; background: #4b2fd6; color: #fff; font-size: 12px; font-weight: 700; padding: 5px 12px; border-radius: 999px; transform: rotate(8deg); }

.how { padding: 70px 24px 60px; }
.steps { max-width: 1100px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 30px; }
.step { border: 1px solid #e6e6e6; border-radius: 16px; padding: 26px; }
.step b { display: inline-flex; width: 36px; height: 36px; border-radius: 50%; background: var(--mint-l); color: var(--green-d); align-items: center; justify-content: center; font-size: 17px; }
.step h3 { margin: 14px 0 8px; font-size: 20px; }
.step p { margin: 0; color: #555; line-height: 1.65; }
.foot { text-align: center; color: #888; font-size: 14px; padding: 30px 20px 40px; border-top: 1px solid #eee; }

@media (max-width: 1200px) { .kit-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) {
  .kit-grid { grid-template-columns: repeat(2, 1fr); gap: 20px; }
  .hero h1 { font-size: 38px; }
  .section-title { font-size: 30px; }
  .steps { grid-template-columns: 1fr; }
  .bignum { font-size: 64px; }
  .top-right { display: block; }
}
@media (max-width: 560px) {
  .kit-grid { grid-template-columns: 1fr; }
  .stats { gap: 26px; }
  .top-right { display: none; }
}
.lesson h2, .lesson h3 { line-height: 1.3; }
svg.flow { max-width: 100%; height: auto; }
