/* ============================================================
   cocodessert — warm "dessert" docs theme
   ============================================================ */
:root {
  --bg: #faf5ec;
  --bg-soft: #f3ead9;
  --surface: #fffdf8;
  --surface-2: #fbf4e8;
  --text: #2c211a;
  --text-soft: #5c4d40;
  --muted: #8a7a6a;
  --border: #e7dcc9;
  --border-strong: #d8c9b1;
  --accent: #c2552e;          /* terracotta */
  --accent-soft: #e6764a;
  --accent-weak: #f6e3d6;
  --honey: #cf8a2e;
  --link: #b8531f;
  --code-bg: #f4ecdd;
  --code-text: #5a3c2a;
  --shadow: 0 1px 2px rgba(60,40,20,.05), 0 8px 24px rgba(80,50,20,.06);
  --shadow-lg: 0 12px 40px rgba(70,45,20,.12);

  --warn-bg: #fdf3e3; --warn-bd: #e9b970; --warn-ic: #b9772a;
  --ok-bg: #eef6ec;   --ok-bd: #a9cf9e;   --ok-ic: #4f8b46;
  --info-bg: #eef2f7; --info-bd: #a8bfd6; --info-ic: #436690;

  --hl-key: #b5347a; --hl-str: #4f8b46; --hl-num: #b8531f;
  --hl-com: #9c8b78; --hl-fn: #436690;  --hl-builtin: #a85a2a;
  --hl-attr: #8a5a14; --hl-punct: #6b5a48;

  --sidebar-w: 290px;
  --toc-w: 230px;
  --content-max: 860px;
}
html[data-theme="dark"] {
  --bg: #181410;
  --bg-soft: #1f1a15;
  --surface: #211c16;
  --surface-2: #261f18;
  --text: #f0e6d6;
  --text-soft: #d3c4b1;
  --muted: #9d8c79;
  --border: #352c22;
  --border-strong: #463a2c;
  --accent: #e8794e;
  --accent-soft: #ef8a60;
  --accent-weak: #34251c;
  --honey: #e0a85a;
  --link: #ef9266;
  --code-bg: #15110d;
  --code-text: #e8c8a8;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 50px rgba(0,0,0,.5);

  --warn-bg: #2a2114; --warn-bd: #6b4f24; --warn-ic: #e0a85a;
  --ok-bg: #1a241a;   --ok-bd: #3c5a38;   --ok-ic: #8fcf83;
  --info-bg: #1a2129; --info-bd: #38506b; --info-ic: #8fb6e0;

  --hl-key: #e88abf; --hl-str: #9fd693; --hl-num: #f0a36a;
  --hl-com: #847460; --hl-fn: #8fb6e0;  --hl-builtin: #e0a85a;
  --hl-attr: #e0c07a; --hl-punct: #b6a690;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16.5px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-weak); color: var(--accent); }

/* ---------- layout ---------- */
#app { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 22px 16px 28px;
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  text-decoration: none; color: var(--text);
  padding: 6px 10px 18px; margin-bottom: 6px;
}
.brand-mark { font-size: 30px; filter: drop-shadow(0 2px 4px rgba(180,90,40,.25)); }
.brand-text {
  font-family: Fraunces, Georgia, serif; font-weight: 900; font-size: 23px;
  line-height: 1; display: flex; flex-direction: column; gap: 4px;
}
.brand-text small { font-family: Inter, sans-serif; font-weight: 500; font-size: 11.5px; color: var(--muted); letter-spacing: .02em; }

#nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin: 18px 12px 6px; }
.nav-group:first-child { margin-top: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 9px;
  text-decoration: none; color: var(--text-soft);
  padding: 8px 12px; border-radius: 9px; font-size: 14.5px; font-weight: 500;
  transition: background .14s, color .14s; position: relative;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav-link .nl-num { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); min-width: 26px; }
.nav-link.active .nl-num { color: var(--accent); }
.sidebar-foot { font-size: 12px; color: var(--muted); padding: 14px 12px 0; border-top: 1px solid var(--border); margin-top: 12px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- topbar ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  font-size: 17px; display: inline-flex; align-items: center; justify-content: center;
  transition: background .14s, border-color .14s, transform .1s; text-decoration: none;
}
.icon-btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.ghost { font-size: 18px; }
#menuBtn { display: none; }
.topbar-actions { display: flex; gap: 8px; }

#search { position: relative; flex: 1; max-width: 520px; }
#searchInput {
  width: 100%; padding: 9px 14px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14.5px; font-family: inherit; transition: border-color .14s, box-shadow .14s;
}
#searchInput:focus { outline: none; border-color: var(--accent-soft); box-shadow: 0 0 0 3px var(--accent-weak); }
#searchResults {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); max-height: 60vh; overflow-y: auto; z-index: 40; padding: 6px;
}
.sr-item { display: block; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--text); }
.sr-item:hover, .sr-item.sel { background: var(--accent-weak); }
.sr-doc { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); font-weight: 700; }
.sr-title { font-size: 14.5px; font-weight: 500; }
.sr-empty { padding: 14px; color: var(--muted); font-size: 14px; }

/* ---------- content layout ---------- */
#layout { display: flex; justify-content: center; gap: 36px; padding: 30px 32px 80px; }
#content { width: 100%; max-width: var(--content-max); min-width: 0; }
#toc {
  width: var(--toc-w); flex: 0 0 var(--toc-w); position: sticky; top: 78px;
  align-self: flex-start; max-height: calc(100vh - 110px); overflow-y: auto;
  font-size: 13px; padding-left: 4px;
}
#toc .toc-title { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 700; margin-bottom: 10px; }
#toc a { display: block; padding: 4px 10px; color: var(--muted); text-decoration: none; border-left: 2px solid var(--border); line-height: 1.4; transition: color .12s, border-color .12s; }
#toc a.lvl-3 { padding-left: 22px; font-size: 12.5px; }
#toc a:hover { color: var(--text); }
#toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }

/* ---------- doc typography ---------- */
.doc { color: var(--text); }
.doc h1, .doc h2, .doc h3, .doc h4 { font-family: Fraunces, Georgia, serif; font-weight: 600; line-height: 1.22; scroll-margin-top: 84px; letter-spacing: -.01em; }
.doc h1 { font-size: 2.5rem; font-weight: 900; margin: 6px 0 18px; letter-spacing: -.02em; }
.doc h2 { font-size: 1.65rem; margin: 52px 0 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.doc h3 { font-size: 1.28rem; margin: 34px 0 12px; }
.doc h4 { font-size: 1.08rem; margin: 26px 0 10px; font-family: Inter, sans-serif; font-weight: 700; }
.doc h2 .anchor, .doc h3 .anchor { opacity: 0; margin-left: 8px; color: var(--accent); text-decoration: none; font-size: .75em; transition: opacity .12s; }
.doc h2:hover .anchor, .doc h3:hover .anchor { opacity: .6; }
.doc p { margin: 0 0 16px; }
.doc a { color: var(--link); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--link) 30%, transparent); transition: border-color .12s; }
.doc a:hover { border-bottom-color: var(--link); }
.doc ul, .doc ol { margin: 0 0 16px; padding-left: 26px; }
.doc li { margin: 6px 0; }
.doc li::marker { color: var(--accent-soft); }
.doc strong { font-weight: 700; color: var(--text); }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 40px 0; }
.doc img { max-width: 100%; }

/* blockquotes & callouts */
.doc blockquote {
  margin: 18px 0; padding: 14px 18px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
}
.doc blockquote p { margin: 0 0 8px; } .doc blockquote p:last-child { margin: 0; }
.doc blockquote.cal-warn { background: var(--warn-bg); border-color: var(--warn-bd); border-left-color: var(--warn-ic); }
.doc blockquote.cal-ok { background: var(--ok-bg); border-color: var(--ok-bd); border-left-color: var(--ok-ic); }
.doc blockquote.cal-info { background: var(--info-bg); border-color: var(--info-bd); border-left-color: var(--info-ic); }

/* tables */
.doc .table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.doc table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.doc thead th { background: var(--surface-2); text-align: left; font-weight: 700; font-size: 13px; letter-spacing: .01em; }
.doc th, .doc td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.doc tbody tr:last-child td { border-bottom: none; }
.doc tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.doc td code { white-space: nowrap; }

/* inline + block code */
.doc code { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: .86em; background: var(--code-bg); color: var(--code-text); padding: .12em .4em; border-radius: 6px; border: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.doc pre { margin: 0 0 20px; }
.doc pre.codeblock { background: var(--code-bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; overflow-x: auto; box-shadow: var(--shadow); }
.doc pre.codeblock code { background: none; border: none; padding: 0; font-size: 13.5px; line-height: 1.6; color: var(--text); }

/* ASCII diagram cards (the few left un-converted) */
.doc pre.diagram {
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 14px;
  padding: 20px 22px; overflow-x: auto; box-shadow: var(--shadow);
  display: flex; justify-content: center;
}
.doc pre.diagram code { background: none; border: none; padding: 0; font-family: 'JetBrains Mono', monospace; font-size: 12.5px; line-height: 1.5; color: var(--text-soft); white-space: pre; }

/* mermaid */
.doc .mermaid-fig { margin: 0 0 22px; padding: 20px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); display: flex; justify-content: center; overflow-x: auto; }
.doc .mermaid-fig svg { max-width: 100%; height: auto; }

/* syntax tokens */
.hljs-keyword,.hljs-selector-tag,.hljs-literal { color: var(--hl-key); }
.hljs-string,.hljs-regexp,.hljs-meta-string { color: var(--hl-str); }
.hljs-number,.hljs-symbol { color: var(--hl-num); }
.hljs-comment,.hljs-quote { color: var(--hl-com); font-style: italic; }
.hljs-title,.hljs-title.function_,.hljs-section { color: var(--hl-fn); }
.hljs-built_in,.hljs-class,.hljs-type,.hljs-title.class_ { color: var(--hl-builtin); }
.hljs-attr,.hljs-attribute,.hljs-property,.hljs-variable { color: var(--hl-attr); }
.hljs-params,.hljs-punctuation,.hljs-operator { color: var(--hl-punct); }
.hljs-bullet,.hljs-link { color: var(--accent); }

/* flashcards */
.doc details { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; margin: 0 0 10px; padding: 0; box-shadow: var(--shadow); overflow: hidden; transition: border-color .14s; }
.doc details[open] { border-color: var(--accent-soft); }
.doc details > summary { cursor: pointer; padding: 13px 18px; font-weight: 500; list-style: none; display: flex; gap: 8px; align-items: baseline; transition: background .12s; }
.doc details > summary::-webkit-details-marker { display: none; }
.doc details > summary::before { content: "▸"; color: var(--accent); font-size: 12px; transition: transform .15s; }
.doc details[open] > summary::before { transform: rotate(90deg); }
.doc details > summary:hover { background: var(--surface-2); }
.doc details > summary b { color: var(--accent); font-weight: 700; }
.doc details > *:not(summary) { padding: 2px 18px 16px; margin: 0; }
.doc details > p { padding: 2px 18px 16px; margin: 0; }
.doc details ul { padding-left: 42px; padding-bottom: 14px; }

/* footer / pager */
#pagefoot { border-top: 1px solid var(--border); }
.pager { max-width: var(--content-max); margin: 0 auto; padding: 26px 32px 60px; display: flex; justify-content: space-between; gap: 16px; }
.pager a { flex: 1; max-width: 48%; text-decoration: none; border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; color: var(--text); background: var(--surface); transition: border-color .14s, transform .1s; }
.pager a:hover { border-color: var(--accent-soft); transform: translateY(-1px); }
.pager a.next { text-align: right; }
.pager .pg-label { font-size: 12px; color: var(--muted); }
.pager .pg-title { font-weight: 600; color: var(--accent); }

/* scrollbars */
#sidebar::-webkit-scrollbar, #toc::-webkit-scrollbar, #searchResults::-webkit-scrollbar, .table-wrap::-webkit-scrollbar, pre::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; }
*::-webkit-scrollbar-track { background: transparent; }

/* loading shimmer */
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) { #toc { display: none; } }
@media (max-width: 860px) {
  #menuBtn { display: inline-flex; }
  #sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; height: 100vh;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }
  #scrim { position: fixed; inset: 0; background: rgba(20,12,6,.4); z-index: 50; }
  #layout { padding: 22px 18px 60px; }
  .doc h1 { font-size: 2rem; }
  .doc h2 { font-size: 1.4rem; }
  body { font-size: 16px; }
}
