/* Layout: a route map in the left sidebar, one reading column, and wide figures
   (real screenshots, code, diagrams) that break out of the column.
   Colour: green-grey paper; the four UMLDoclet marker colours (C, A, I, E) are the
   kind colours used everywhere; one red is reserved for marks drawn on screenshots. */
:root {
  --bg: #f3f4ef;
  --surface: #ffffff;
  --surface-2: #e9ebe4;
  --ink: #1c2125;
  --muted: #59636a;
  --line: #d5d9cf;
  --accent: #276b57;
  --accent-ink: #ffffff;
  --accent-soft: #d9eae2;
  --mark: #d6334f;
  --mark-ink: #ffffff;
  --mark-soft: rgba(214, 51, 79, 0.12);
  --k-class: #add1b2;
  --k-abstract: #a9dcdf;
  --k-interface: #b4a7e5;
  --k-enum: #eb937f;
  --k-actor: #f2d27a;
  --k-ink: #1c2125;
  --code-bg: #f8f9f5;
  --code-ink: #23292e;
  --code-ln: #9aa29c;
  --code-hl: rgba(39, 107, 87, 0.13);
  --code-step: rgba(214, 51, 79, 0.14);
  --tok-keyword: #a1365a;
  --tok-type: #2a5f9e;
  --tok-string: #2f7a3a;
  --tok-number: #9a5b13;
  --tok-comment: #7b857d;
  --tok-title: #6a3fa0;
  --tok-meta: #8a6d1c;
  --note-java: #e6eef9;
  --note-tip: #e4f1ea;
  --note-warn: #fbeee0;
  --note-exam: #f3e8f7;
  --note-real: #eef0e8;
  --shadow: 0 1px 2px rgba(28, 33, 37, 0.06), 0 6px 18px rgba(28, 33, 37, 0.06);
  --ripple: rgba(39, 107, 87, 0.18);
  --ripple-on-accent: rgba(255, 255, 255, 0.32);
  --font-display: "Grenze Gotisch", "Palatino Linotype", "Book Antiqua", serif;
  --font-body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
  --font-code: "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.5rem;
  --step-3: 2.1rem;
  --radius: 10px;
  --sidebar-w: 290px;
  --main-w: 780px;
  --wide-w: 1160px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111416; --surface: #191d20; --surface-2: #22272b; --ink: #e3e6e0; --muted: #9ba5ab; --line: #2f363b;
    --accent: #79c6aa; --accent-ink: #0c1d17; --accent-soft: rgba(121, 198, 170, 0.14);
    --mark: #ff6a85; --mark-ink: #1b0b10; --mark-soft: rgba(255, 106, 133, 0.16);
    --k-ink: #15191c; --code-bg: #15191c; --code-ink: #dde2dc; --code-ln: #5f6a66;
    --code-hl: rgba(121, 198, 170, 0.15); --code-step: rgba(255, 106, 133, 0.18);
    --tok-keyword: #f08ab0; --tok-type: #8cb8f2; --tok-string: #9bd59a; --tok-number: #e6b673; --tok-comment: #7d8a84;
    --tok-title: #c6a6f2; --tok-meta: #d9c27a;
    --note-java: #1b2532; --note-tip: #17261f; --note-warn: #2c2219; --note-exam: #271d2d; --note-real: #1e221d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
    --ripple: rgba(121, 198, 170, 0.22); --ripple-on-accent: rgba(12, 29, 23, 0.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111416; --surface: #191d20; --surface-2: #22272b; --ink: #e3e6e0; --muted: #9ba5ab; --line: #2f363b;
  --accent: #79c6aa; --accent-ink: #0c1d17; --accent-soft: rgba(121, 198, 170, 0.14);
  --mark: #ff6a85; --mark-ink: #1b0b10; --mark-soft: rgba(255, 106, 133, 0.16);
  --k-ink: #15191c; --code-bg: #15191c; --code-ink: #dde2dc; --code-ln: #5f6a66;
  --code-hl: rgba(121, 198, 170, 0.15); --code-step: rgba(255, 106, 133, 0.18);
  --tok-keyword: #f08ab0; --tok-type: #8cb8f2; --tok-string: #9bd59a; --tok-number: #e6b673; --tok-comment: #7d8a84;
  --tok-title: #c6a6f2; --tok-meta: #d9c27a;
  --note-java: #1b2532; --note-tip: #17261f; --note-warn: #2c2219; --note-exam: #271d2d; --note-real: #1e221d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --ripple: rgba(121, 198, 170, 0.22); --ripple-on-accent: rgba(12, 29, 23, 0.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-underline-offset: 3px; }
img { max-width: 100%; }
code, kbd { font-family: var(--font-code); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { line-height: 1.35; text-wrap: balance; }

/* ---------- top bar ---------- */
.progress { position: fixed; top: 0; left: 0; height: 3px; width: 0; background: var(--accent); z-index: 60; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 50;
  display: flex; align-items: center; gap: 10px;
  height: 58px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; color: var(--ink); white-space: nowrap; border-radius: 8px; padding: 4px 8px; }
.brand b { font-family: var(--font-display); font-weight: 400; font-size: 1.65rem; letter-spacing: 0.02em; color: var(--accent); }
.brand span { font-size: 0.95rem; color: var(--muted); }
.topbar .spacer { flex: 1; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; min-width: 38px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.9rem; cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
#menu-btn { display: none; }
.search { position: relative; }
.search input {
  width: 230px; height: 38px; padding: 0 12px 0 34px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: 0.92rem;
}
.search svg { position: absolute; left: 11px; top: 10px; width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.search-results {
  position: absolute; right: 0; top: 44px; width: min(420px, 92vw); max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.search-results a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; line-height: 1.4; }
.search-results a:hover, .search-results a.active { background: var(--accent-soft); }
.search-results small { display: block; color: var(--muted); font-size: 0.8rem; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); align-items: start; }
.sidebar {
  position: sticky; top: 58px; height: calc(100vh - 58px); overflow-y: auto;
  border-right: 1px solid var(--line); padding: 18px 14px 40px;
}
.sidebar .part { margin: 18px 6px 6px; font-size: 0.78rem; letter-spacing: 0.08em; color: var(--muted); font-weight: 700; }
.sidebar .part:first-child { margin-top: 2px; }
.sidebar a {
  display: grid; grid-template-columns: 34px 1fr 18px; align-items: center; gap: 4px;
  padding: 7px 8px; border-radius: 9px; color: var(--ink); text-decoration: none; font-size: 0.93rem; line-height: 1.35;
}
.sidebar a .num { font-family: var(--font-code); font-size: 0.78rem; color: var(--muted); }
.sidebar a:hover { background: var(--surface-2); }
.sidebar a.current { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.sidebar a .check { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--line); }
.sidebar a.read .check { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }
.sidebar .route-progress { margin: 4px 6px 10px; font-size: 0.82rem; color: var(--muted); }
.sidebar .route-progress .bar { height: 6px; border-radius: 6px; background: var(--surface-2); margin-top: 6px; overflow: hidden; }
.sidebar .route-progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 6px; transition: width 0.4s; }

.content {
  min-width: 0;
  display: grid;
  grid-template-columns:
    [full-start] minmax(max(16px, env(safe-area-inset-left, 0px)), 1fr)
    [wide-start] minmax(0, calc((var(--wide-w) - var(--main-w)) / 2))
    [main-start] min(var(--main-w), 100% - 2 * max(16px, env(safe-area-inset-left, 0px)))
    [main-end] minmax(0, calc((var(--wide-w) - var(--main-w)) / 2))
    [wide-end] minmax(max(16px, env(safe-area-inset-right, 0px)), 1fr) [full-end];
  padding-block: 28px 80px;
}
.content > * { grid-column: main; min-width: 0; }
.content > .wide, .content > .shot, .content > .pair, .content > .stepper, .content > .diagram,
.content > .flipbook, .content > figure.code.wide, .content > .cols, .content > .gallery { grid-column: wide; }

/* ---------- chapter head ---------- */
.chapter-head { margin-bottom: 10px; }
.chapter-head .eyebrow { font-size: 0.85rem; color: var(--muted); letter-spacing: 0.06em; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chapter-head .eyebrow .lvl { font-family: var(--font-code); font-size: 0.78rem; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.chapter-head h1 { font-size: var(--step-3); margin: 6px 0 6px; letter-spacing: 0.01em; }
.chapter-head h1 .no { font-family: var(--font-display); font-weight: 400; color: var(--accent); margin-right: 12px; font-size: 1.15em; }
.chapter-head .lede { font-size: var(--step-1); color: var(--muted); margin: 0; }
.goals { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 14px 18px; margin: 18px 0 8px; }
.goals > b { display: block; font-size: 0.85rem; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 4px; }
.goals ul { margin: 0; padding-left: 1.2em; }

.content h2 { font-size: var(--step-2); margin: 2.4em 0 0.4em; padding-top: 0.2em; }
.content h2 .h-no { font-family: var(--font-code); font-size: 0.7em; color: var(--accent); margin-right: 10px; }
.content h3 { font-size: var(--step-1); margin: 1.8em 0 0.3em; }
.content p { margin: 0.6em 0 0.9em; }
.content ul, .content ol { padding-left: 1.4em; }
.content li { margin: 0.25em 0; }
.content :not(pre) > code {
  font-size: 0.88em; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--ink);
  overflow-wrap: anywhere;
}
kbd { font-size: 0.82em; padding: 1px 7px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: var(--surface); }
.content table { border-collapse: collapse; width: 100%; font-size: 0.94rem; }
.table-wrap { overflow-x: auto; margin: 1em 0; }
.content th, .content td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; }
.content th { font-size: 0.85rem; color: var(--muted); font-weight: 700; background: var(--surface-2); }
.content td code { white-space: nowrap; }
.content hr { border: 0; border-top: 1px solid var(--line); margin: 2.5em 0; }

/* ---------- chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; position: relative; overflow: hidden;
  padding: 0 8px 0 3px; height: 1.6em; line-height: 1.6em; vertical-align: 0.06em;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  font-family: var(--font-code); font-size: 0.86em; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.chip i {
  font-style: normal; font-weight: 700; font-size: 0.78em; width: 1.35em; height: 1.35em; line-height: 1.35em; text-align: center;
  border-radius: 50%; color: var(--k-ink); border: 1px solid rgba(0, 0, 0, 0.25); flex: none;
}
.chip.k-class i { background: var(--k-class); }
.chip.k-abstract i { background: var(--k-abstract); }
.chip.k-interface i { background: var(--k-interface); }
.chip.k-enum i { background: var(--k-enum); }
.chip.k-abstract .cn { font-style: italic; }
.chip.k-interface .cn { font-style: italic; }
.chip:hover { border-color: var(--accent); }
.pkg-chip { display: inline-block; font-family: var(--font-code); font-size: 0.84em; padding: 0 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.term { color: inherit; text-decoration: underline dotted var(--accent); text-decoration-thickness: 2px; text-underline-offset: 4px; cursor: help; }
.tip-pop {
  position: absolute; z-index: 80; max-width: 330px; padding: 10px 12px; border-radius: 10px;
  background: var(--ink); color: var(--bg); font-size: 0.86rem; line-height: 1.55; box-shadow: var(--shadow); pointer-events: none;
}
.tip-pop b { display: block; margin-bottom: 2px; }

/* ---------- notes ---------- */
.note { border-radius: var(--radius); padding: 12px 16px 12px 16px; margin: 1.2em 0; border: 1px solid var(--line); background: var(--note-real); }
.note > .note-title, .note > b:first-child { display: block; font-size: 0.9rem; margin-bottom: 2px; }
.note p:first-of-type { margin-top: 0.2em; }
.note p:last-child { margin-bottom: 0.1em; }
.note.java { background: var(--note-java); }
.note.tip { background: var(--note-tip); }
.note.warn { background: var(--note-warn); }
.note.exam { background: var(--note-exam); }
.note.real { background: var(--note-real); }
.note::before {
  display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; padding: 0 8px; border-radius: 999px;
  margin-bottom: 4px; background: var(--surface); border: 1px solid var(--line); color: var(--muted);
}
.note.java::before { content: "Java 语法"; }
.note.tip::before { content: "说人话"; }
.note.warn::before { content: "容易搞错"; }
.note.exam::before { content: "考试要点"; }
.note.real::before { content: "真实运行结果"; }

/* ---------- code ---------- */
figure.code { margin: 1.2em 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--code-bg); overflow: hidden; min-width: 0; }
figure.code figcaption {
  display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; justify-content: space-between;
  padding: 7px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); font-size: 0.82rem; color: var(--muted);
}
figure.code figcaption .path { font-family: var(--font-code); color: var(--ink); }
figure.code figcaption .title { font-family: var(--font-body); color: var(--ink); font-weight: 600; }
figure.code .scroll { overflow-x: auto; }
figure.code pre { margin: 0; padding: 8px 0; font-size: 13px; line-height: 1.62; color: var(--code-ink); min-width: max-content; }
figure.code .line { display: grid; grid-template-columns: 3.4em 1.6em 1fr; padding-right: 16px; }
figure.code .line .ln { text-align: right; color: var(--code-ln); user-select: none; padding-right: 2px; }
figure.code .line .mk { display: flex; align-items: center; justify-content: center; }
figure.code .line .src { white-space: pre; }
figure.code .line.hl { background: var(--code-hl); box-shadow: inset 3px 0 0 var(--accent); }
figure.code .line.step { background: var(--code-step); box-shadow: inset 3px 0 0 var(--mark); }
figure.code .line.dim { opacity: 0.45; }
figure.code .gap-line { color: var(--code-ln); padding-left: 5em; font-size: 12px; }
.badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 1.45em; height: 1.45em; padding: 0 0.3em; border-radius: 999px;
  background: var(--mark); color: var(--mark-ink); font: 700 0.74rem/1 var(--font-body);
}
figure.code .mk .badge { font-size: 0.68rem; }
.hljs-keyword, .hljs-literal, .hljs-built_in.hljs-keyword { color: var(--tok-keyword); }
.hljs-type, .hljs-class .hljs-title, .hljs-title.class_ { color: var(--tok-type); }
.hljs-string, .hljs-char { color: var(--tok-string); }
.hljs-number { color: var(--tok-number); }
.hljs-comment, .hljs-doctag { color: var(--tok-comment); font-style: italic; }
.hljs-title.function_, .hljs-function .hljs-title { color: var(--tok-title); }
.hljs-meta, .hljs-annotation { color: var(--tok-meta); }
.hljs-attr, .hljs-variable, .hljs-params { color: inherit; }
.hljs-attr { color: var(--tok-type); }

/* ---------- screenshots ---------- */
.shot { margin: 1.4em 0; min-width: 0; }
.shot .frame { position: relative; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); background: #000; }
.shot .frame img { display: block; width: 100%; height: auto; }
.shot .frame svg.marks { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.crop { position: relative; overflow: hidden; }
.crop img { position: absolute; max-width: none; height: auto; display: block; }
.shot.cropped { margin-inline: auto; }
.shot .frame .mk-badge {
  position: absolute; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px #fff; z-index: 2;
  min-width: 1.7em; height: 1.7em; font-size: 0.8rem; transition: transform 0.15s, opacity 0.15s;
}
.shot .frame .mk-badge.lit { transform: translate(-50%, -50%) scale(1.25); }
.shot .frame .mk-badge.dim { opacity: 0.35; }
.shot .frame .mk-label {
  position: absolute; transform: translate(0.9em, -50%); z-index: 2; white-space: nowrap;
  background: var(--mark); color: var(--mark-ink); font-size: 0.78rem; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  box-shadow: 0 0 0 2px #fff;
}
.stepper .stage .row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.stepper .stage .row2 > * { margin: 0 !important; min-width: 0; }
.marks .m-box { fill: transparent; stroke: var(--mark); stroke-width: 3; vector-effect: non-scaling-stroke; transition: fill 0.2s; }
.marks .m-ring { fill: transparent; stroke: var(--mark); stroke-width: 3.5; vector-effect: non-scaling-stroke; }
.marks .m-line { stroke: var(--mark); stroke-width: 4; vector-effect: non-scaling-stroke; }
.marks .m-arrow { stroke: var(--mark); stroke-width: 3; fill: none; vector-effect: non-scaling-stroke; }
.marks .m-badge circle { fill: var(--mark); stroke: #fff; stroke-width: 2; vector-effect: non-scaling-stroke; }
.marks .m-badge text { fill: #fff; font: 700 15px var(--font-body); text-anchor: middle; dominant-baseline: central; }
.marks .m-label rect { fill: var(--mark); }
.marks .m-label text { fill: #fff; font: 600 14px var(--font-body); dominant-baseline: central; }
.marks g.mark.lit .m-box, .marks g.mark.lit .m-ring { fill: var(--mark-soft); stroke-width: 5; }
.marks g.mark.dim { opacity: 0.25; }
.shot figcaption { font-size: 0.9rem; color: var(--muted); margin-top: 8px; }
.shot figcaption .src-note { display: block; font-size: 0.78rem; }
.legend { list-style: none; padding: 0 !important; margin: 10px 0 0; display: grid; gap: 6px; }
.legend li { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 6px 10px; border-radius: 8px; cursor: default; margin: 0 !important; }
.legend li:hover, .legend li.lit { background: var(--mark-soft); }
.legend li .badge { margin-top: 0.25em; }
.legend.cols-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

/* side by side */
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; margin: 1.4em 0; }
.pair > * { min-width: 0; margin: 0 !important; }
.pair.code-left { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; margin: 1.2em 0; }
.cols > * { min-width: 0; }
.card { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 14px 16px; }
.card > h4 { margin: 0 0 6px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.gallery .shot { margin: 0; }

/* ---------- diagrams ---------- */
.diagram { margin: 1.4em 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 10px; }
.diagram .svg-wrap { overflow-x: auto; }
.diagram svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.diagram figcaption { font-size: 0.9rem; color: var(--muted); padding: 6px 6px 2px; }
.d-box rect.body { fill: var(--surface); stroke: var(--ink); stroke-width: 1.3; }
.d-box.k-actor rect.body { fill: var(--surface-2); stroke-dasharray: 4 3; }
.d-box.k-note rect.body { fill: var(--note-warn); stroke: var(--line); }
.d-box.k-data rect.body { fill: var(--note-real); stroke: var(--muted); stroke-dasharray: 2 3; }
.d-box circle.kind { stroke: rgba(0, 0, 0, 0.35); stroke-width: 1; }
.d-box.k-class circle.kind { fill: var(--k-class); }
.d-box.k-abstract circle.kind { fill: var(--k-abstract); }
.d-box.k-interface circle.kind { fill: var(--k-interface); }
.d-box.k-enum circle.kind { fill: var(--k-enum); }
.d-box text.kind { fill: var(--k-ink); font: 700 11px var(--font-body); text-anchor: middle; dominant-baseline: central; }
.d-box text.name { fill: var(--ink); font: 600 14px var(--font-code); dominant-baseline: central; }
.d-box.k-abstract text.name, .d-box.k-interface text.name { font-style: italic; }
.d-box text.sub { fill: var(--muted); font: 12px var(--font-body); dominant-baseline: central; }
.d-box text.label { fill: var(--ink); font: 600 14px var(--font-body); dominant-baseline: central; text-anchor: middle; }
.d-box a { cursor: pointer; }
.d-edge path { fill: none; stroke: var(--muted); stroke-width: 1.6; }
.d-edge.t-call path, .d-edge.t-use path { stroke: var(--ink); }
.d-edge.t-ret path, .d-edge.t-create path, .d-edge.t-impl path, .d-edge.t-dep path { stroke-dasharray: 6 4; }
.d-edge.t-data path { stroke-dasharray: 2 4; }
.d-edge text { fill: var(--ink); font: 12.5px var(--font-body); text-anchor: middle; dominant-baseline: central; }
.d-edge rect.lbl { fill: var(--surface); }
.d-mk-fill { fill: var(--ink); }
.d-mk-hollow { fill: var(--surface); stroke: var(--ink); stroke-width: 1.3; }
.d-mk-line { fill: none; stroke: var(--ink); stroke-width: 1.4; }
.has-focus .d-box, .has-focus .d-edge, .has-focus .s-msg, .has-focus .s-note { opacity: 0.28; transition: opacity 0.25s; }
.has-focus .is-on, .has-focus .is-past { opacity: 1; }
.has-focus .is-past { opacity: 0.75; }
.d-edge.is-on path, .s-msg.is-on path { stroke: var(--mark); stroke-width: 2.6; stroke-dasharray: 8 6; animation: flow 0.9s linear infinite; }
.d-edge.is-on .d-mk-fill, .s-msg.is-on .d-mk-fill { fill: var(--mark); }
.d-edge.is-on text, .s-msg.is-on text { fill: var(--mark); font-weight: 700; }
.d-box.is-on rect.body { stroke: var(--mark); stroke-width: 2.6; }
@keyframes flow { to { stroke-dashoffset: -28; } }
/* sequence */
.s-part rect { fill: var(--surface); stroke: var(--ink); stroke-width: 1.3; }
.s-part.k-actor rect { fill: var(--surface-2); stroke-dasharray: 4 3; }
.s-life { stroke: var(--line); stroke-width: 1.4; stroke-dasharray: 5 5; }
.s-msg path { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.s-msg.t-ret path, .s-msg.t-create path { stroke-dasharray: 6 4; stroke: var(--muted); }
.s-msg text { fill: var(--ink); font: 13px var(--font-body); dominant-baseline: central; }
.s-msg text.code { font-family: var(--font-code); font-size: 12.5px; }
.s-msg rect.lbl { fill: var(--surface); }
.s-msg .num { fill: var(--muted); font: 700 11px var(--font-code); }
.s-msg.is-on .num { fill: var(--mark); }
.s-note rect { fill: var(--note-warn); stroke: var(--line); }
.s-note text { fill: var(--ink); font: 12.5px var(--font-body); dominant-baseline: central; }

/* ---------- stepper & flipbook ---------- */
.stepper, .flipbook { margin: 1.6em 0; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.stepper .stage { padding: 14px; display: grid; gap: 14px; background: var(--bg); border-bottom: 1px solid var(--line); }
.stepper .stage > * { margin: 0 !important; min-width: 0; }
.stepper .stage.two { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.stepper .stage [data-stage][hidden] { display: none !important; }
.stepper .steps { list-style: none; margin: 0; padding: 0; }
.stepper .steps > li { display: none; padding: 14px 18px 4px; margin: 0; }
.stepper .steps > li.current { display: block; animation: stepIn 0.3s ease; }
@keyframes stepIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px 14px; }
.controls .count { font-family: var(--font-code); font-size: 0.85rem; color: var(--muted); min-width: 4.5em; text-align: center; }
.controls .dots { display: flex; gap: 5px; flex-wrap: wrap; flex: 1; justify-content: center; }
.controls .dots button { width: 11px; height: 11px; min-width: 0; padding: 0; border-radius: 50%; border: 0; background: var(--line); cursor: pointer; position: relative; overflow: hidden; }
.controls .dots button.on { background: var(--mark); }
.controls .dots button.done { background: var(--accent); }
.btn {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.92rem; font-weight: 600; cursor: pointer; text-decoration: none; user-select: none;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn[disabled] { opacity: 0.4; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.flipbook .fb-stage { position: relative; background: #000; }
.flipbook .fb-stage img { display: block; width: 100%; height: auto; }
.flipbook .fb-stage img.fb-frame { position: absolute; inset: 0; opacity: 0; transition: opacity 0.18s; }
.flipbook .fb-stage.crop img.fb-frame { inset: auto; }
.flipbook.cropped { margin-inline: auto; }
.flipbook .fb-stage img.fb-frame.on { opacity: 1; }
.flipbook .fb-stage img.fb-base { visibility: hidden; }
.flipbook .fb-cap { padding: 10px 16px 0; font-size: 0.93rem; min-height: 2.2em; }
.flipbook input[type=range] { flex: 1; min-width: 120px; accent-color: var(--mark); }

/* ---------- quiz ---------- */
details.quiz { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); margin: 0.8em 0; overflow: hidden; }
details.quiz summary { position: relative; overflow: hidden; cursor: pointer; padding: 12px 16px; font-weight: 600; list-style: none; display: flex; gap: 10px; align-items: baseline; }
details.quiz summary::-webkit-details-marker { display: none; }
details.quiz summary::before { content: "问"; flex: none; font-size: 0.75rem; padding: 0 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
details.quiz[open] summary { border-bottom: 1px solid var(--line); }
details.quiz .ans { padding: 10px 16px 12px; }
details.quiz .ans::before { content: "答"; display: inline-block; font-size: 0.75rem; padding: 0 7px; border-radius: 6px; background: var(--mark-soft); color: var(--mark); margin-right: 8px; }

/* ---------- uml image ---------- */
figure.uml { margin: 1.2em 0; text-align: center; }
figure.uml img { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; max-width: 100%; }
figure.uml figcaption { font-size: 0.85rem; color: var(--muted); }

/* ---------- chapter end ---------- */
.chapter-end { margin-top: 3em; display: grid; gap: 16px; }
.done-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pager a { position: relative; overflow: hidden; display: block; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); text-decoration: none; }
.pager a:hover { border-color: var(--accent); }
.pager a small { display: block; color: var(--muted); font-size: 0.8rem; }
.pager a.next { text-align: right; grid-column: 2; }

/* ---------- class encyclopedia ---------- */
.cls-filter { display: flex; flex-wrap: wrap; gap: 8px; margin: 1em 0; }
.cls-filter input { flex: 1; min-width: 200px; height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; }
.cls-filter .btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.cls-card { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); margin: 18px 0; padding: 16px 18px; scroll-margin-top: 80px; }
.cls-card:target { box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow); border-color: var(--accent); }
.cls-card header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.cls-card header h3 { margin: 0; font-family: var(--font-code); font-size: 1.15rem; }
.cls-card .one { margin: 6px 0 10px; font-size: 1.02rem; }
.cls-card dl { display: grid; grid-template-columns: 7.5em 1fr; gap: 6px 12px; margin: 0; font-size: 0.93rem; }
.cls-card dt { color: var(--muted); }
.cls-card dd { margin: 0; min-width: 0; }
.cls-card .uml-mini { margin-top: 10px; }
.cls-card .uml-mini summary { cursor: pointer; color: var(--accent); font-size: 0.9rem; position: relative; overflow: hidden; display: inline-block; padding: 2px 8px; border-radius: 6px; }
.cls-card .uml-mini img { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; margin-top: 6px; }
.glossary-list dt { font-weight: 700; margin-top: 1.2em; scroll-margin-top: 80px; }
.glossary-list dt small { color: var(--muted); font-weight: 400; font-family: var(--font-code); margin-left: 8px; }
.glossary-list dd { margin: 0.2em 0 0 0; }
.glossary-list dt:target { color: var(--accent); }

/* ---------- home ---------- */
.home-hero { padding: 10px 0 6px; }
.home-hero h1 { font-size: clamp(2rem, 5vw, 3rem); margin: 0 0 8px; }
.home-hero h1 b { font-family: var(--font-display); font-weight: 400; color: var(--accent); font-size: 1.15em; margin-right: 8px; }
.route { display: grid; gap: 14px; margin: 1.4em 0; }
.route .stage-row { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.route .stage-row > b { font-size: 0.85rem; color: var(--muted); padding-top: 12px; letter-spacing: 0.04em; }
.route .stops { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.route .stop { position: relative; overflow: hidden; display: block; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink); line-height: 1.45; }
.route .stop:hover { border-color: var(--accent); }
.route .stop .n { font-family: var(--font-display); color: var(--accent); font-size: 1.3rem; margin-right: 6px; }
.route .stop small { display: block; color: var(--muted); font-size: 0.82rem; margin-top: 2px; }
.route .stop.read { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- ripple ---------- */
.rp-host { position: relative; overflow: hidden; }
.ripple {
  position: absolute; border-radius: 50%; transform: scale(0); pointer-events: none;
  background: var(--ripple); animation: ripple 600ms linear;
}
.btn.primary .ripple, .controls .dots .ripple { background: var(--ripple-on-accent); }
@keyframes ripple { to { transform: scale(4); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .pair, .stepper .stage.two, .stepper .stage .row2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  #menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; z-index: 70; top: 58px; left: 0; bottom: 0; height: auto; width: min(86vw, 320px);
    background: var(--bg); transform: translateX(-102%); transition: transform 0.25s; box-shadow: var(--shadow);
    padding-left: max(14px, env(safe-area-inset-left, 0px));
  }
  body.nav-open .sidebar { transform: none; }
  .search input { width: 150px; }
  .brand span { display: none; }
}
@media (max-width: 560px) {
  .search input { width: 38px; padding-right: 0; }
  .search input:focus { width: 60vw; }
  .route .stage-row { grid-template-columns: minmax(0, 1fr); }
  .route .stage-row > b { padding-top: 0; }
  .cls-card dl { grid-template-columns: minmax(0, 1fr); }
  .cls-card dt { margin-top: 6px; }
  .pager { grid-template-columns: minmax(0, 1fr); }
  .pager a.next { grid-column: 1; }
  .chapter-head h1 { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) {
  .d-edge.is-on path, .s-msg.is-on path { animation: none; }
  .ripple { animation-duration: 1ms; }
  .stepper .steps > li.current { animation: none; }
}
.content > .shot.main, .content > .diagram.main { grid-column: main; }
.shot.half { max-width: 620px; }
.chip.big { font-size: 1rem; }
figure.code .line.hl-mark { background: var(--mark-soft); }
.shot.cropped, .flipbook.cropped { width: 100%; }
.pair figure.code pre { font-size: 12.5px; }
