/* ==========================================================================
   Deep Learning Notes — styles
   Pastel accents (green / blue / red / yellow), light + dark, one stylesheet.
   ========================================================================== */

@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("../fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --font: "Readex Pro", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f8f9f8;
  --bg-glass: rgba(248, 249, 248, .86);
  --surface: #ffffff;
  --surface-2: #f1f3f1;
  --panel: #f3f5f3;
  --code-bg: #eef1ee;
  --line: #e3e7e3;
  --line-strong: #cfd5cf;
  --hover: rgba(30, 45, 38, .06);
  --fg: #232628;
  --fg-2: #4a5053;
  --muted: #777e82;
  --rule: rgba(120, 140, 130, .10);

  --green: #cde8d4;  --green-ink: #2e6a46;
  --blue: #d0e1f6;   --blue-ink: #2c5f99;
  --red: #f7d3d3;    --red-ink: #a44a4d;
  --yellow: #f8ebbb; --yellow-ink: #86691a;

  --hl-yellow: rgba(247, 222, 110, .55);
  --hl-green: rgba(150, 214, 170, .5);
  --hl-blue: rgba(150, 190, 240, .45);
  --hl-red: rgba(244, 160, 160, .42);

  --shadow-sm: 0 1px 2px rgba(25, 40, 32, .05);
  --shadow: 0 1px 2px rgba(25, 40, 32, .05), 0 10px 28px -14px rgba(25, 40, 32, .18);
  --shadow-lg: 0 2px 6px rgba(25, 40, 32, .06), 0 24px 60px -18px rgba(25, 40, 32, .28);

  /* ---- spacing system (4pt grid) ---- */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-14: 56px;
  --radius-sm: 10px; --radius-md: 14px; --radius-lg: 18px; --radius-pill: 999px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #222224;
  --bg-glass: rgba(34, 34, 36, .86);
  --surface: #29292c;
  --surface-2: #303034;
  --panel: #262628;
  --code-bg: #2f2f33;
  --line: #36363b;
  --line-strong: #484850;
  --hover: rgba(255, 255, 255, .07);
  --fg: #ececee;
  --fg-2: #c8c8ce;
  --muted: #9a9aa3;
  --rule: rgba(255, 255, 255, .045);

  --green: #2a3b30;  --green-ink: #a9d9b6;
  --blue: #27374c;   --blue-ink: #a9c8ee;
  --red: #432b2d;    --red-ink: #f0b3b3;
  --yellow: #40392a; --yellow-ink: #ecd990;

  --hl-yellow: rgba(236, 217, 144, .28);
  --hl-green: rgba(169, 217, 182, .26);
  --hl-blue: rgba(169, 200, 238, .27);
  --hl-red: rgba(240, 179, 179, .26);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .25);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -14px rgba(0, 0, 0, .6);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .35), 0 24px 60px -18px rgba(0, 0, 0, .75);
}

[data-c="green"]  { --c: var(--green);  --ink: var(--green-ink);  --hlc: #9bd8b0; }
[data-c="blue"]   { --c: var(--blue);   --ink: var(--blue-ink);   --hlc: #9cc3f0; }
[data-c="red"]    { --c: var(--red);    --ink: var(--red-ink);    --hlc: #f4a3a3; }
[data-c="yellow"] { --c: var(--yellow); --ink: var(--yellow-ink); --hlc: #f7de6e; }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 76px; }
body {
  margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font);
  font-size: 16px; line-height: 1.6; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
html.modal-open { overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--blue-ink); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- themed scrollbars (thin, with gutter margin) ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); border: 3px solid transparent; background-clip: content-box; }
.skip { position: absolute; left: 12px; top: -48px; z-index: 200; background: var(--surface); padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); }
.skip:focus { top: 12px; }
[hidden] { display: none !important; }

.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: var(--fg-2);
  transition: background .15s, color .15s; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn[aria-pressed="true"] { background: var(--blue); color: var(--blue-ink); }
kbd { font: 500 11px/1 var(--mono); padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: 11px; font-size: 14px; font-weight: 600; border: 1px solid var(--line); background: var(--surface);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn.primary { background: var(--blue); color: var(--blue-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(.97); }
.btn.danger { color: var(--red-ink); }

/* ---------- global header (library view) ---------- */
body[data-view="note"] .site-header { display: none; }
.site-header { position: sticky; top: 0; z-index: 20; background: var(--bg-glass); backdrop-filter: saturate(1.3) blur(12px); -webkit-backdrop-filter: saturate(1.3) blur(12px); border-bottom: 1px solid transparent; transition: border-color .2s; }
.site-header.scrolled { border-bottom-color: var(--line); }
.hdr { max-width: 1120px; margin: 0 auto; padding: var(--sp-3) var(--sp-6); display: grid; grid-template-columns: 1fr minmax(0, 520px) 1fr; align-items: center; gap: var(--sp-4); }
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); text-decoration: none; font-weight: 750; font-size: 18px; letter-spacing: -.02em; justify-self: start; }
.brand svg { width: 30px; height: 30px; }
.hdr-actions { justify-self: end; display: flex; gap: var(--sp-1); }
.search-trigger {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; height: 42px; padding: 0 var(--sp-3) 0 var(--sp-4); text-align: left;
  border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--surface); color: var(--muted);
  transition: border-color .15s, box-shadow .15s;
}
.search-trigger:hover { border-color: var(--line-strong); box-shadow: var(--shadow-sm); }
.search-trigger > span { flex: 1; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.theme-btn .i-moon { display: none; }
:root[data-theme="dark"] .theme-btn .i-sun { display: none; }
:root[data-theme="dark"] .theme-btn .i-moon { display: block; }

/* ---------- library ---------- */
.home { position: relative; max-width: 1120px; margin: 0 auto; padding: 0 var(--sp-6) var(--sp-14); }
.home-bg {
  position: absolute; left: 0; right: 0; top: 0; height: 380px; pointer-events: none; z-index: -1;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 31px, var(--rule) 31px, var(--rule) 32px);
  -webkit-mask-image: linear-gradient(#000 30%, transparent); mask-image: linear-gradient(#000 30%, transparent);
}
.home-bg::after { content: ""; position: absolute; top: 0; bottom: 0; left: 8px; width: 1px; background: var(--red); }
.hero { padding: var(--sp-14) 0 var(--sp-8); max-width: 700px; }
.hero h1 { margin: 0 0 var(--sp-4); font-size: clamp(30px, 4.8vw, 46px); line-height: 1.07; letter-spacing: -.035em; font-weight: 800; text-wrap: balance; }
.hero p { margin: 0; font-size: 18px; line-height: 1.55; color: var(--fg-2); max-width: 54ch; text-wrap: pretty; }
.hero-stats { margin-top: var(--sp-5); display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-5); font-size: 14px; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin: var(--sp-2) 0 var(--sp-8); min-height: 34px; }
.chip-btn { height: 32px; padding: 0 var(--sp-3); border-radius: var(--radius-pill); border: 1px solid var(--line); background: var(--surface); font-size: 13.5px; color: var(--fg-2); transition: background .15s, border-color .15s; }
.chip-btn:hover { border-color: var(--line-strong); }
.chip-btn[aria-pressed="true"] { background: var(--blue); border-color: transparent; color: var(--blue-ink); font-weight: 650; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: var(--sp-5); }
.card {
  position: relative; display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); text-decoration: none; box-shadow: var(--shadow-sm);
  transition: transform .18s ease, border-color .18s, box-shadow .18s;
  content-visibility: auto; contain-intrinsic-size: auto 300px;
}
.card:hover, .card:focus-visible { transform: translateY(-2px); border-color: var(--c, var(--blue)); box-shadow: 0 0 0 3px var(--c, var(--blue)), var(--shadow); }
.card-head { display: flex; align-items: center; gap: var(--sp-3); }
.tile { width: 46px; height: 46px; flex: none; border-radius: var(--radius-md); background: var(--c, var(--blue)); color: var(--ink, var(--blue-ink)); display: grid; place-items: center; font-size: 23px; line-height: 1; }
.tile .i { width: 22px; height: 22px; }
.card-title { font-size: 17px; font-weight: 700; letter-spacing: -.015em; line-height: 1.25; text-wrap: balance; }
.card-sum { margin: 0; font-size: 14.5px; line-height: 1.55; color: var(--fg-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card-outline { list-style: none; margin: var(--sp-1) 0 0; padding: 0; display: grid; gap: var(--sp-1); font-size: 13px; color: var(--muted); }
.card-outline li { display: flex; gap: var(--sp-2); align-items: baseline; min-width: 0; }
.card-outline li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ink, var(--blue-ink)); opacity: .6; flex: none; transform: translateY(-1px); }
.card-outline span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-tags { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-top: auto; }
.tag { padding: 2px 9px; border-radius: var(--radius-pill); background: var(--c, var(--blue)); color: var(--ink, var(--blue-ink)); font-size: 11.5px; font-weight: 700; }
.card-foot { margin-top: auto; padding-top: var(--sp-3); border-top: 1px dashed var(--line); display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); font-size: 12.5px; color: var(--muted); }
.card-tags + .card-foot { margin-top: var(--sp-3); }
.card.skel { pointer-events: none; }
.sk { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--hover), var(--surface-2)); background-size: 200% 100%; animation: sk 1.3s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- folder / collection cards ---------- */
.card-folder { border-style: dashed; border-width: 1.5px; background: color-mix(in srgb, var(--c, var(--blue)) 22%, var(--surface)); }
.card-folder:hover, .card-folder:focus-within { transform: translateY(-2px); border-color: var(--c, var(--blue)); box-shadow: 0 0 0 3px var(--c, var(--blue)), var(--shadow); }
.tile-folder { border: 1.5px dashed var(--ink, var(--blue-ink)); background: var(--surface); color: var(--ink, var(--blue-ink)); }
.folder-count { margin-left: auto; flex: none; font-size: 11.5px; font-weight: 700; color: var(--ink, var(--blue-ink)); background: var(--surface); border: 1px solid var(--line); padding: 2px 9px; border-radius: var(--radius-pill); text-decoration: none; }
/* whole-card link: stretched overlay; tag buttons sit above it so they stay clickable */
.card-folder { cursor: pointer; }
.folder-hit { position: absolute; inset: 0; border-radius: inherit; }
.folder-hit:focus-visible { outline: 2px solid var(--blue-ink); outline-offset: 3px; }
.card-folder .card-tags { position: relative; z-index: 1; }
.folder-list { list-style: none; margin: var(--sp-1) 0 0; padding: 0; display: grid; gap: var(--sp-2); }
.folder-list li { min-width: 0; }
.f-link { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line); border-radius: var(--sp-3); background: var(--surface); text-decoration: none; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.f-link:hover { border-color: var(--c, var(--blue)); box-shadow: 0 0 0 2px var(--c, var(--blue)); transform: translateY(-1px); }
.f-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink, var(--blue-ink)); flex: none; }
.f-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.f-min { flex: none; font-size: 12.5px; color: var(--muted); }
.f-link.is-pending { color: var(--muted); }
.f-link.is-static { cursor: default; }
.tag-btn { cursor: pointer; border: 0; }
.tag-btn:hover { filter: brightness(.96); }
.f-more { display: flex; align-items: center; justify-content: center; width: 100%; padding: var(--sp-2) var(--sp-3); border: 1px dashed var(--line-strong); border-radius: var(--sp-3); background: transparent; font-size: 12.5px; font-weight: 700; color: var(--ink, var(--blue-ink)); text-decoration: none; transition: background .15s, border-color .15s; }
.f-more:hover { background: var(--surface); border-color: var(--c, var(--blue)); }
/* ---------- folder detail page ---------- */
.crumbs { padding-top: var(--sp-6); display: flex; align-items: center; gap: var(--sp-2); }
.crumb-sep { color: var(--muted); }
.hero-folder { padding-top: var(--sp-4); }
.folder-hero-head { display: flex; align-items: center; gap: var(--sp-4); }
.folder-hero-head h1 { margin: 0 0 var(--sp-1); }
.folder-hero-head .tile { width: 52px; height: 52px; }
/* common card height: rows stretch together, folder lists cap at 2 + more */
.grid { align-items: stretch; }
.grid > .card { height: 100%; }

/* ---------- reference bookshelf strip ---------- */
.books-strip { margin-top: var(--sp-6); display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-4) var(--sp-5); border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg); background: color-mix(in srgb, var(--c, var(--yellow)) 22%, var(--surface)); text-decoration: none; box-shadow: var(--shadow-sm); transition: transform .18s ease, border-color .18s, box-shadow .18s; }
.books-strip:hover { transform: translateY(-2px); border-color: var(--c, var(--yellow)); box-shadow: 0 0 0 3px var(--c, var(--yellow)), var(--shadow); }
.tile-sm { width: 40px; height: 40px; border-radius: var(--radius-sm); }
.tile-sm .i { width: 20px; height: 20px; }
.books-text { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.books-text strong { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.books-text span:last-child { font-size: 13.5px; line-height: 1.5; color: var(--fg-2); }
.books-text code { font: 500 12px var(--mono); background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.books-cta { margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: var(--sp-2); height: 34px; padding: 0 var(--sp-4); border-radius: var(--radius-pill); background: var(--c, var(--yellow)); color: var(--ink, var(--yellow-ink)); font-size: 13.5px; font-weight: 700; white-space: nowrap; }
@media (max-width: 760px) { .books-strip { flex-wrap: wrap; } .books-cta { margin-left: 0; } }

.site-footer {
  max-width: 1120px; margin: 0 auto; padding: var(--sp-6) var(--sp-6) var(--sp-8); border-top: 1px solid var(--line);
  display: flex; justify-content: space-between; gap: var(--sp-3) var(--sp-6); flex-wrap: wrap; color: var(--muted); font-size: 13px;
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--fg-2); text-underline-offset: 3px; }
.site-footer a:hover { color: var(--fg); }

.notice { max-width: 560px; margin: 72px auto; padding: 30px 28px; border: 1px dashed var(--line-strong); border-radius: 18px; text-align: center; color: var(--fg-2); background: var(--surface); }
.notice h2 { margin: 0 0 8px; font-size: 20px; color: var(--fg); letter-spacing: -.02em; }
.notice p { margin: 8px 0; }
.notice code { font: 500 13px var(--mono); background: var(--code-bg); padding: 3px 7px; border-radius: 7px; }

/* ---------- search modal ---------- */
.sm { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 9vh 16px 16px; }
.sm-scrim { position: absolute; inset: 0; background: rgba(22, 26, 24, .4); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade .15s ease-out; }
.sm-box { position: relative; width: min(980px, 100%); height: min(620px, 82vh); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg); overflow: hidden; animation: pop .16s ease-out; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } }
.sm-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); color: var(--muted); }
.sm-head input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font: inherit; font-size: 17px; color: var(--fg); }
.sm-head input::placeholder { color: var(--muted); }
.sm-status { font-size: 12.5px; white-space: nowrap; }
.sm-body { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); flex: 1; min-height: 0; }
.sm-list { list-style: none; margin: 0; padding: 8px; overflow: auto; border-right: 1px solid var(--line); overscroll-behavior: contain; }
.sm-group { padding: 10px 12px 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.res { display: block; width: 100%; text-align: left; padding: 10px 12px; border-radius: 12px; cursor: pointer; }
.res[aria-selected="true"] { background: var(--c, var(--blue)); }
.res-top { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); min-width: 0; }
.res[aria-selected="true"] .res-top { color: var(--ink, var(--blue-ink)); }
.res-top span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink, var(--blue-ink)); flex: none; }
.res-title { margin-top: 2px; font-size: 14.5px; font-weight: 650; line-height: 1.35; }
.res-sn { margin-top: 3px; font-size: 13px; line-height: 1.45; color: var(--fg-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sm mark { background: var(--hl-yellow); color: inherit; border-radius: 3px; padding: 0 1px; }
.sm-preview { padding: 22px 26px; overflow: auto; overscroll-behavior: contain; }
.pv-top { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.pv-path { margin-top: 6px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.pv-title { margin: 12px 0 10px; font-size: 21px; line-height: 1.25; letter-spacing: -.02em; font-weight: 750; }
.pv-text { margin: 0 0 18px; font-size: 14.5px; line-height: 1.7; color: var(--fg-2); overflow-wrap: anywhere; }
.pv-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.pv-list { margin: 0 0 18px; padding-left: 18px; color: var(--fg-2); font-size: 14px; line-height: 1.7; }
.sm-empty { display: grid; place-items: center; height: 100%; min-height: 160px; padding: 24px; text-align: center; color: var(--muted); font-size: 14.5px; }
.sm-foot { display: flex; align-items: center; gap: 18px; padding: 10px 18px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }
.sm-foot span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- reader ---------- */
.reader { --rail-w: 36px; --toc-w: 292px; --doc-w: 720px; min-height: 100vh; }

.rail { position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail-w); z-index: 31; background: var(--bg); overflow: hidden; padding: 28px 0 16px 8px; display: flex; flex-direction: column; align-items: flex-start; }
.tick { display: flex; align-items: center; width: 26px; height: var(--th, 10px); flex: none; cursor: pointer; }
.tick::before { content: ""; height: 3px; width: var(--tw, 12px); border-radius: 2px; background: var(--line-strong); transition: background .15s, width .15s; }
.tick[data-d="1"] { --tw: 18px; } .tick[data-d="2"] { --tw: 13px; } .tick[data-d="3"] { --tw: 9px; }
.tick:hover::before { background: var(--muted); }
.tick.on::before { background: var(--blue-ink); }

.toc {
  position: fixed; left: var(--rail-w); top: 0; bottom: 0; width: var(--toc-w); z-index: 30; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); visibility: hidden; opacity: 0; pointer-events: none;
  transform: translateX(-16px); transition: transform .22s cubic-bezier(.2, .8, .2, 1), opacity .16s, visibility 0s .22s;
}
.reader.toc-open .toc, .reader.pinned .toc { visibility: visible; opacity: 1; pointer-events: auto; transform: none; transition-delay: 0s; }
.reader:not(.pinned).toc-open .toc { box-shadow: var(--shadow-lg); }
.toc-head { display: flex; align-items: center; justify-content: space-between; padding: 22px 16px 10px 22px; }
.toc-head h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.005em; }
.toc-pin { width: 32px; height: 32px; border: 1px solid transparent; border-radius: 9px; }
.reader.pinned .toc-pin { border-color: var(--line-strong); background: var(--surface-2); color: var(--fg); }
.toc-tabs { display: flex; gap: 4px; padding: 0 16px 8px 18px; }
.toc-tab { height: 28px; padding: 0 10px; border-radius: 8px; font-size: 13px; color: var(--muted); }
.toc-tab[aria-selected="true"] { color: var(--fg); background: var(--hover); font-weight: 600; }
.toc-body { flex: 1; overflow-y: auto; padding: 4px 10px 40px; overscroll-behavior: contain; scrollbar-width: thin; }
.toc-list { list-style: none; margin: 0; padding: 0; }
.toc-list a {
  display: block; position: relative; padding: 7px 10px 7px calc(16px + var(--l, 0) * 10px); border-radius: 8px; text-decoration: none;
  font-size: 13.5px; line-height: 1.35; color: var(--muted); transition: background .12s, color .12s;
}
.toc-list .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toc-list a:hover { color: var(--fg); background: var(--hover); }
.toc-list a[aria-current="true"] { color: var(--fg); font-weight: 600; background: var(--hover); }
.toc-list a[aria-current="true"]::before { content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px; border-radius: 3px; background: var(--fg); }
.toc-list .m-raw { font-size: .9em; }
.scrim { display: none; position: fixed; inset: 0; z-index: 29; background: rgba(20, 24, 22, .4); }

.doc-wrap { margin-left: var(--rail-w); padding: 0 clamp(18px, 4vw, 48px) 140px; transition: margin-left .22s cubic-bezier(.2, .8, .2, 1); }
.reader.pinned .doc-wrap { margin-left: calc(var(--rail-w) + var(--toc-w)); }

.topbar { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 4px; height: 54px; margin: 0 calc(-1 * clamp(18px, 4vw, 48px)); padding: 0 clamp(14px, 3vw, 24px); background: var(--bg-glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.topbar .sp { flex: 1; }
.back { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px 0 6px; border-radius: 10px; font-size: 14px; font-weight: 600; text-decoration: none; color: var(--fg-2); flex: none; }
.back:hover { background: var(--hover); color: var(--fg); }
.crumbs-bar { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; overflow: hidden; }
.crumb-link { font-size: 14px; font-weight: 600; color: var(--fg-2); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb-link:hover { color: var(--fg); text-decoration: underline; text-underline-offset: 3px; }
.crumb-current { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { display: flex; align-items: center; gap: 10px; margin-left: 8px; font-size: 14px; color: var(--fg-2); min-width: 0; }
.status svg { width: 26px; height: 26px; flex: none; }
.status span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; }
.progress i { display: block; height: 100%; background: var(--blue-ink); opacity: .7; transform-origin: 0 50%; transform: scaleX(var(--p, 0)); }

.doc { max-width: var(--doc-w); margin: 0 auto; padding-top: 38px; font-size: 16px; line-height: 1.7; overflow-wrap: break-word; }
.doc-skel { display: grid; gap: 14px; max-width: var(--doc-w); margin: 48px auto; }
.chunk { content-visibility: auto; contain-intrinsic-size: auto 1000px; }
.chunk > :last-child { margin-bottom: 0; }
.chunk:not(:first-child) > h2:first-child, .chunk:not(:first-child) > h3:first-child, .chunk:not(:first-child) > h4:first-child { margin-top: 1.1em; }
.chunk + .chunk { padding-top: .2em; }

.doc h1 { margin: 0 0 .9em; padding-bottom: .7em; font-size: 2.05rem; line-height: 1.16; letter-spacing: -.03em; font-weight: 800; border-bottom: 1px solid var(--line); text-wrap: balance; }
.doc h2 { margin: 2.2em 0 .8em; padding-bottom: .45em; font-size: 1.55rem; line-height: 1.25; letter-spacing: -.022em; font-weight: 750; border-bottom: 1px solid var(--line); text-wrap: balance; }
.doc h3 { margin: 1.9em 0 .6em; font-size: 1.2rem; line-height: 1.3; letter-spacing: -.015em; font-weight: 700; }
.doc h4 { margin: 1.6em 0 .5em; font-size: 1.03rem; line-height: 1.35; font-weight: 700; }
.doc h5, .doc h6 { margin: 1.4em 0 .4em; font-size: .95rem; font-weight: 700; color: var(--fg-2); }
.doc .anchor { display: inline-block; margin-left: .45em; font-size: .8em; font-weight: 500; text-decoration: none; color: var(--muted); opacity: 0; transition: opacity .15s; }
.doc .anchor::before { content: "#"; }
.doc :is(h1, h2, h3, h4, h5, h6):hover .anchor, .doc .anchor:focus-visible { opacity: .85; }
.doc p { margin: 0 0 1.05em; }
.doc strong { font-weight: 650; }
.doc a { color: var(--blue-ink); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--blue-ink) 40%, transparent); text-underline-offset: 3px; }
.doc a:hover { text-decoration-color: currentColor; }
.doc ul, .doc ol { margin: 0 0 1.1em; padding-left: 1.5em; }
.doc li { margin: .32em 0; padding-left: .15em; }
.doc li > p { margin: .4em 0; }
.doc li > :is(ul, ol) { margin: .3em 0 .2em; }
.doc ul { list-style: disc; } .doc ul ul { list-style: circle; } .doc ul ul ul { list-style: square; }
.doc li::marker { color: var(--muted); }
.doc li.task { list-style: none; margin-left: -1.4em; }
.doc li.task input { margin: 0 .5em 0 0; accent-color: var(--blue-ink); transform: translateY(1px); }
.doc hr { margin: 2.2em 0; border: 0; border-top: 2px solid var(--line); }
.doc blockquote { margin: 1.3em 0; padding: .05em 0 .05em 1.1em; border-left: 3px solid var(--line-strong); color: var(--fg-2); }
.doc blockquote p { margin: .55em 0; }
.doc blockquote strong { color: var(--fg); }
.doc blockquote blockquote { margin: .8em 0; }
.doc blockquote.callout { padding: .75em 1.1em .35em; border: 0; border-radius: 12px; background: var(--c, var(--blue)); color: var(--fg); }
.callout-title { margin-bottom: .1em; font-size: .85rem; font-weight: 700; color: var(--ink, var(--blue-ink)); }
.doc img { display: block; max-width: 100%; height: auto; margin: 1.3em auto; border-radius: 10px; }
.doc details { margin: 1em 0; padding: .6em 1em; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.doc summary { cursor: pointer; font-weight: 600; }
.doc kbd { font-size: .8em; }

.chip { display: inline-block; padding: .05em .55em; margin-right: .1em; border-radius: 7px; font-size: .78em; font-weight: 700; line-height: 1.55; background: var(--c, var(--blue)); color: var(--ink, var(--blue-ink)); vertical-align: .08em; letter-spacing: .005em; }

.table-wrap { overflow-x: auto; margin: 1.4em 0; border: 1px solid var(--line); border-radius: 12px; }
.doc table { width: 100%; border-collapse: collapse; font-size: .92em; line-height: 1.5; }
.doc th, .doc td { padding: .6em .95em; text-align: start; vertical-align: top; border-bottom: 1px solid var(--line); }
.doc th { background: var(--surface-2); font-weight: 650; }
.doc :is(th, td)[align="center"] { text-align: center; }
.doc :is(th, td)[align="right"] { text-align: right; }
.doc tr:last-child td { border-bottom: 0; }

.doc code { font-family: var(--mono); font-size: .875em; background: var(--code-bg); padding: .14em .4em; border-radius: 6px; }
.code-block { margin: 1.3em 0; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); font: 500 12px var(--mono); color: var(--muted); }
.code-head .copy { height: 26px; padding: 0 9px; border-radius: 7px; font: 600 12px var(--font); color: var(--muted); }
.code-head .copy:hover { background: var(--hover); color: var(--fg); }
.code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; tab-size: 4; }
.code-block code { padding: 0; background: none; font-size: .86rem; line-height: 1.65; border-radius: 0; }
.hljs-comment, .hljs-quote { color: var(--muted); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag, .hljs-deletion { color: var(--red-ink); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: var(--green-ink); }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-variable, .hljs-template-variable, .hljs-attr { color: var(--yellow-ink); }
.hljs-title, .hljs-section, .hljs-selector-id, .hljs-selector-class, .hljs-built_in, .hljs-type, .hljs-name { color: var(--blue-ink); }
.hljs-emphasis { font-style: italic; } .hljs-strong { font-weight: 700; }

.m-raw { font: 500 .85em var(--mono); color: var(--muted); background: none !important; padding: 0 !important; white-space: pre-wrap; }
.m.md { display: block; margin: 1.2em 0; padding: .2em 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
.m.md:not([data-r]) { min-height: 2.6em; }
.m.md .katex-display { margin: 0; }
.m .eqn-num[data-n]::before { content: "(" attr(data-n) ")"; counter-increment: none; }
.m.md .katex { font-size: 1.14em; }
.m .katex { font-size: 1.05em; }
.m.m-err { color: var(--red-ink); }
.m-pre { display: none; }

.mermaid-box { position: relative; margin: 1.5em 0; padding: 12px; min-height: 90px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow: hidden; text-align: center; }
.mm-scroll { overflow-x: auto; overflow-y: hidden; }
.mm-skel { padding: 30px 0; font-size: 13px; color: var(--muted); }
.mm-svg svg { display: block; margin: 0 auto; max-width: none; }
.mm-expand { position: absolute; top: 8px; right: 8px; z-index: 1; opacity: 0; background: var(--surface); border: 1px solid var(--line); transition: opacity .15s; }
.mermaid-box:hover .mm-expand, .mm-expand:focus-visible { opacity: 1; }
@media (hover: none) { .mm-expand { opacity: 1; } }
.mm-error { text-align: left; color: var(--red-ink); font-size: 14px; }
.mm-error pre { margin: 8px 0 0; white-space: pre-wrap; font: 500 12.5px var(--mono); color: var(--fg-2); }

/* ---------- static figures (hand-written inline SVG) ---------- */
.fig { margin: 1.5em 0; padding: 16px 12px 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); overflow-x: auto; text-align: center; }
.fig svg { display: inline-block; max-width: 100%; height: auto; }
.fig-cap { font-size: 13px; color: var(--muted); margin: 8px 4px 6px; line-height: 1.5; }

.lb { position: fixed; inset: 0; z-index: 90; display: flex; flex-direction: column; background: var(--bg); }
.lb-bar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.lb-bar .sp { flex: 1; } .lb-zoom { min-width: 52px; text-align: center; font-size: 13px; color: var(--muted); }
.lb-stage { flex: 1; overflow: auto; padding: 28px; }
.lb-stage svg { display: block; max-width: none; height: auto; margin: 0 auto; }

.doc :is(h1, h2, h3, h4, h5, h6).flash-h { animation: hflash 1.7s ease; border-radius: 6px; }
@keyframes hflash { 0%, 50% { background: var(--hl-yellow); box-shadow: 0 0 0 8px var(--hl-yellow); } 100% { background: transparent; box-shadow: 0 0 0 8px transparent; } }
html.theming, html.theming *, html.theming *::before, html.theming *::after { transition: background-color .25s, border-color .25s, color .25s, fill .25s, stroke .25s !important; }

/* ---------- annotations ---------- */
mark.ann { --hl: var(--hl-yellow); background: var(--hl); color: inherit; border-radius: 3px; cursor: pointer; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
mark.ann[data-c="green"] { --hl: var(--hl-green); } mark.ann[data-c="blue"] { --hl: var(--hl-blue); } mark.ann[data-c="red"] { --hl: var(--hl-red); }
mark.ann.has-note { border-bottom: 2px dotted var(--fg-2); }
mark.ann.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 55% { outline: 3px solid var(--blue-ink); outline-offset: 2px; } 100% { outline: 3px solid transparent; outline-offset: 2px; } }
.annotating .doc ::selection { background: var(--hl-yellow); }

.dock { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 40; display: flex; align-items: center; gap: 4px; padding: 7px 9px; max-width: calc(100vw - 20px); overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); animation: rise .2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.dock { -webkit-user-select: none; user-select: none; }
.dock .btn { height: 34px; padding: 0 11px; border-color: transparent; background: none; font-size: 13.5px; white-space: nowrap; }
.dock .btn:hover { background: var(--hover); }
.dock .btn.primary { background: var(--blue); }
.dock .sep { width: 1px; height: 22px; margin: 0 5px; background: var(--line); flex: none; }
.swatch { width: 26px; height: 26px; flex: none; border-radius: 50%; background: var(--hlc); border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.swatch[aria-checked="true"] { border-color: var(--surface); box-shadow: 0 0 0 2px var(--fg); }

.pop { position: absolute; z-index: 50; width: min(310px, calc(100vw - 24px)); padding: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg); animation: pop .14s ease-out; }
.pop-q { margin: 0 0 10px; padding-left: 9px; border-left: 3px solid var(--hlc); font-size: 12.5px; line-height: 1.5; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pop textarea { width: 100%; min-height: 78px; resize: vertical; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--fg); font: inherit; font-size: 14px; line-height: 1.5; }
.pop-row { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.pop-row .sp { flex: 1; }
.pop .swatch { width: 22px; height: 22px; }

.ann-list { list-style: none; margin: 0; padding: 4px 4px 20px; }
.ann-empty { padding: 20px 14px; font-size: 13.5px; line-height: 1.55; color: var(--muted); }
.ann-item { display: block; width: 100%; padding: 9px 12px; margin: 2px 0; text-align: left; border-radius: 10px; border-left: 3px solid var(--hlc); }
.ann-item:hover { background: var(--hover); }
.ann-q { font-size: 13px; line-height: 1.4; color: var(--fg); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ann-n { margin-top: 4px; font-size: 12.5px; line-height: 1.45; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ann-item.orphan { opacity: .55; }
.ann-tools { display: flex; gap: 6px; padding: 8px 12px 0; }
.ann-tools .btn { height: 30px; font-size: 12.5px; padding: 0 10px; }

#toast { position: fixed; left: 50%; top: 18px; z-index: 120; padding: 9px 16px; border-radius: 12px; background: var(--fg); color: var(--bg); font-size: 14px; font-weight: 500; transform: translate(-50%, -14px); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; box-shadow: var(--shadow-lg); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .rail { display: none; }
  .reader { --rail-w: 0px; }
  .reader.pinned .doc-wrap { margin-left: 0; }
  .toc { left: 0; width: min(86vw, 320px); box-shadow: var(--shadow-lg); }
  .toc-pin { display: none; }
  .reader.toc-open .scrim { display: block; }
}
@media (max-width: 760px) {
  .hdr { grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--sp-2); padding: var(--sp-2) var(--sp-4); }
  .brand > span { display: none; }
  .search-trigger kbd { display: none; }
  .home { padding: 0 var(--sp-4) var(--sp-14); }
  .hero { padding: var(--sp-10) 0 var(--sp-5); }
  .hero p { font-size: 16.5px; }
  .grid { grid-template-columns: 1fr; }
  .sm { padding: 0; }
  .sm-box { height: 100%; border-radius: 0; border: 0; }
  .sm-body { grid-template-columns: 1fr; }
  .sm-preview { display: none; }
  .sm-list { border-right: 0; }
  .doc { font-size: 15.5px; }
  .doc h1 { font-size: 1.75rem; } .doc h2 { font-size: 1.35rem; }
  .status span { display: none; }
  .back span { display: none; }
}

/* ---------- motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- print / save as PDF ---------- */
@media print {
  @page { margin: 16mm 14mm; }
  :root, :root[data-theme] {
    color-scheme: light; --bg: #fff; --surface: #fff; --surface-2: #f4f5f4; --panel: #fff; --code-bg: #f1f3f1;
    --line: #dde1dd; --line-strong: #c4c9c4; --fg: #14181a; --fg-2: #33383b; --muted: #656b6e;
    --green: #cde8d4; --green-ink: #2e6a46; --blue: #d0e1f6; --blue-ink: #2c5f99; --red: #f7d3d3; --red-ink: #a44a4d; --yellow: #f8ebbb; --yellow-ink: #86691a;
    --hl-yellow: rgba(247, 222, 110, .6); --hl-green: rgba(150, 214, 170, .55); --hl-blue: rgba(150, 190, 240, .5); --hl-red: rgba(244, 160, 160, .5);
  }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { background: #fff !important; }
  .site-header, .rail, .toc, .topbar, .dock, .pop, .lb, .sm, .scrim, #toast, .mm-expand, .copy, .doc .anchor { display: none !important; }
  .reader .doc-wrap { margin: 0 !important; padding: 0 !important; }
  .doc { max-width: none; padding: 0; font-size: 10.5pt; line-height: 1.55; }
  .doc h1 { font-size: 22pt; } .doc h2 { font-size: 16pt; } .doc h3 { font-size: 13pt; }
  .chunk { content-visibility: visible !important; contain: none !important; }
  .doc :is(h1, h2, h3, h4, h5) { break-after: avoid; page-break-after: avoid; }
  .code-block, .table-wrap, .mermaid-box, .fig, .m.md, blockquote, img, tr, .callout { break-inside: avoid; page-break-inside: avoid; }
  .code-block pre { white-space: pre-wrap; overflow: visible; }
  .table-wrap, .mermaid-box, .fig, .m.md { overflow: visible; }
  .mm-svg svg { max-width: 100% !important; height: auto !important; }
  .fig svg { max-width: 100% !important; height: auto !important; }
  .doc a { color: inherit; text-decoration: none; }
}
