/* ==========================================================================
   Theme tokens
   --------------------------------------------------------------------------
   Light and dark palettes follow the paperAI product theme. custom.js applies
   `html.dark` from the same preference the rest of the site stores.
   ========================================================================== */

:root {
  color-scheme: light;

  /* ---- reading layout ---- */
  --read-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --read-size: 15px;      /* body text; headings, code and tables scale from it */
  --read-leading: 1.8;
  /* Keep prose comfortably narrow while allowing code and tables more room. */
  --prose-max: 860px;
  --article-max: calc(var(--prose-max) + 256px);
  --reading-max: var(--article-max);
  --col-max: calc(var(--prose-max) + 96px);
  --reading-pad: max(48px, (100vw - var(--article-max)) / 2);

  /* ---- light palette (paperAI product tokens) ---- */
  --bg: oklch(1 0 0);
  --bg-card: oklch(1 0 0);
  --bg-code: oklch(0.968 0.007 247.896);
  --bg-hover: color-mix(in oklab, oklch(0.208 0.042 265.755) 5%, transparent);
  --bg-active: oklch(0.968 0.007 247.896);
  --text: oklch(0.129 0.042 264.695);
  --text-secondary: oklch(0.37 0.03 260);
  --text-muted: oklch(0.554 0.046 257.417);
  /* Product primary / editorial accent — navy-blue, not teal/green */
  --accent: #1a56db;
  --accent-light: #eff6ff;
  --accent-dim: color-mix(in srgb, var(--accent) 22%, transparent);
  --border: oklch(0.929 0.013 255.508);
  --border-light: oklch(0.955 0.008 255);
  --code-keyword: #7C3AED;
  --code-string: #059669;
  --code-comment: #9CA3AF;
  --code-func: #2563EB;
  --code-number: #D97706;
  --progress-bar: #1a56db;
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --radius: 10px;
  --transition: 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* Dark palette — same tokens as the app's .dark theme. */
html.dark {
  color-scheme: dark;

  --bg: oklch(0.129 0.042 264.695);
  --bg-card: oklch(0.208 0.042 265.755);
  --bg-code: oklch(0.22 0.035 264);
  --bg-hover: color-mix(in oklab, #8cb4ff 10%, transparent);
  --bg-active: color-mix(in oklab, #8cb4ff 14%, var(--bg));
  --text: oklch(0.984 0.003 247.858);
  --text-secondary: oklch(0.86 0.015 256);
  --text-muted: oklch(0.704 0.04 256.788);
  --accent: #8cb4ff;
  --accent-light: color-mix(in oklab, var(--accent) 16%, var(--bg));
  --accent-dim: color-mix(in oklab, var(--accent) 32%, transparent);
  --border: oklch(1 0 0 / 12%);
  --border-light: oklch(1 0 0 / 8%);
  --code-keyword: #c4b5fd;
  --code-string: #6ee7b7;
  --code-comment: #9ca3af;
  --code-func: #93c5fd;
  --code-number: #fbbf24;
  --progress-bar: #8cb4ff;
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.7;
  letter-spacing: -0.01em;
}
body { overflow-x: hidden; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Page layout ---------- */
.content {
  /* Header + footer live in the Next.js shell around Docsify. */
  min-height: calc(100vh - 16rem);
  background: var(--bg);
}

/* Keep Docsify's optional navigation UI disabled even if stale settings are cached. */
.sidebar,
.sidebar-toggle,
.sidebar-nav,
.app-sub-sidebar { display: none !important; }

/* ---------- Content typography ---------- */
.markdown-section {
  max-width: var(--col-max);
  font-family: var(--read-font);
  margin: 0 auto;
  padding: 40px 48px 100px;
  /* Bare URLs (e.g. a "Sources" list) are one unbreakable word and pushed the
     page 138px sideways on phones. `break-word`, not `anywhere`: it does not
     lower min-content width, so table column sizing is unaffected. */
  overflow-wrap: break-word;
}
@media screen and (max-width: 768px) {
  .markdown-section { padding: 68px 20px 60px; }
}
/* Every size below is a multiple of --read-size, so the reader's text-size
   choice scales the whole hierarchy together. At the default 15px they work
   out to the original fixed values (30/26/16/19/16/15/13/14/13px). */
.markdown-section h1 {
  font-size: calc(var(--read-size) * 2);
  font-weight: 650;
  letter-spacing: -0.035em;
  line-height: 1.2;
  color: var(--text);
  margin: 0 0 10px;
  border-bottom: none;
}
@media screen and (max-width: 768px) {
  .markdown-section h1 { font-size: calc(var(--read-size) * 26 / 15); }
}
.markdown-section h1 + p {
  font-size: calc(var(--read-size) + 1px);
  color: var(--text-secondary);
  line-height: 1.6;
}
.markdown-section h2 {
  font-size: calc(var(--read-size) * 19 / 15);
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
  margin: 36px 0 10px;
  padding: 0;
  border-bottom: none;
  scroll-margin-top: 24px;
}
.markdown-section h3 {
  font-size: calc(var(--read-size) + 1px);
  font-weight: 600;
  margin: 24px 0 8px;
  color: var(--text);
}
.markdown-section p,
.markdown-section li {
  /* Body text sits close to full-strength text rather than at the
     secondary grey: comfortable for a paragraph, tiring for a 2,800-line
     guide. Mixed from the theme's own two colours, so it works in all 11
     themes (Daylight: 5.2:1 -> ~11:1). The first line is the fallback. */
  color: var(--text-secondary);
  color: color-mix(in srgb, var(--text) 84%, var(--bg));
  font-size: var(--read-size);
  line-height: var(--read-leading);
}
.markdown-section strong { color: var(--text); }
.markdown-section a {
  color: var(--accent);
  text-decoration: none;
}
.markdown-section a:hover { text-decoration: underline; }
/* Docsify wraps headings in <a> — keep them product text color, not accent. */
.markdown-section h1 a,
.markdown-section h2 a,
.markdown-section h3 a,
.markdown-section h4 a,
.markdown-section h5 a,
.markdown-section h6 a {
  color: inherit;
  text-decoration: none;
}
.markdown-section h1 a:hover,
.markdown-section h2 a:hover,
.markdown-section h3 a:hover,
.markdown-section h4 a:hover,
.markdown-section h5 a:hover,
.markdown-section h6 a:hover {
  text-decoration: none;
}
.markdown-section hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 32px 0;
}

/* ---------- Code blocks ---------- */
.markdown-section pre {
  background: var(--bg-code) !important;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 20px 22px;
  overflow-x: auto;
}
.markdown-section pre > code {
  font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Menlo, monospace;
  font-size: calc(var(--read-size) - 2px);
  line-height: 1.75;
  color: var(--text);
  background: none;
}
.markdown-section :not(pre) > code {
  background: var(--bg-code);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
  color: var(--text);
}
.token.keyword { color: var(--code-keyword); }
.token.string { color: var(--code-string); }
.token.comment { color: var(--code-comment); font-style: italic; }
.token.function { color: var(--code-func); }
.token.number { color: var(--code-number); }
.token.punctuation { color: var(--text-secondary); }

.docsify-copy-code-button {
  background: var(--bg-hover) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-secondary) !important;
  border-radius: 7px !important;
}

/* ---------- Tables ----------
   No base Docsify theme is loaded, so until now tables fell back to browser
   defaults: no borders, no padding, centred headers, cells vertically centred.
   In a 279-table corpus that made rows hard to tell apart. `.table-wrap` and
   the `.cell-*` classes are added by initTables() in custom.js. */
.markdown-section .table-wrap {
  margin: 20px 0 24px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  -webkit-overflow-scrolling: touch;
}
.markdown-section .table-wrap:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.markdown-section table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  margin: 0;
  font-size: calc(var(--read-size) - 1px);
  line-height: 1.6;
}
.markdown-section th,
.markdown-section td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-light);
}
/* Markdown alignment (`:---:`, `---:`) arrives as an inline style, which
   beats the left-align above, so explicitly aligned columns still work. */
.markdown-section th {
  background: var(--bg-code);
  color: var(--text);
  font-weight: 600;
  font-size: calc(var(--read-size) - 2px);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.markdown-section td { color: var(--text-secondary); }
.markdown-section tbody tr:last-child td { border-bottom: none; }
.markdown-section tbody tr:nth-child(even) td { background: var(--bg-hover); }
/* The first column is usually the row's label (Phase, Book, Option...). */
.markdown-section td:first-child { color: var(--text); font-weight: 500; }
.markdown-section td.cell-short { white-space: nowrap; }
.markdown-section td.cell-long { min-width: 14em; }
@media screen and (max-width: 768px) {
  .markdown-section th,
  .markdown-section td { padding: 8px 12px; }
}

/* ---------- Pagination ---------- */
.pagination-item-label { color: var(--text-muted); }
.pagination-item-title { color: var(--accent) !important; }

/* ---------- Reading progress bar ---------- */
#reading-progress {
  position: fixed;
  /* Sit under the fixed SiteHeader (h-16). */
  top: 4rem;
  left: 0;
  right: 0;
  height: 2.5px;
  z-index: 30;
  pointer-events: none;
}
#reading-progress > div {
  height: 100%;
  width: 0%;
  background: var(--progress-bar);
  opacity: 0.85;
  border-radius: 0 2px 2px 0;
  transition: width 80ms linear;
}

/* ---------- Wide-screen layout ----------
   From 1201px the article is centred in the page, at most
   --article-max wide. Paragraphs, lists and headings stop at --prose-max to
   keep lines trackable; code blocks and tables use the remaining width. */
@media screen and (min-width: 1201px) {
  /* 1116px at the default 860px prose width; follows the reader's width choice. */
  :root { --article-max: calc(var(--prose-max) + 256px); }

  .content {
    padding-left: var(--reading-pad);
    padding-right: var(--reading-pad);
  }
  .markdown-section {
    width: 100%;
    max-width: var(--article-max);
    margin: 0;
    padding: 40px 0 100px;
  }
}
