/* Clio — shared stylesheet. All design tokens live here; pages never inline styles. */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #fafaf8;
  --bg-elev: #ffffff;
  --bg-sunk: #f1f1ee;
  --fg: #1c1c1a;
  --fg-muted: #5f5f5a;
  --fg-faint: #8a8a83;
  --line: #e3e3de;
  --line-strong: #cfcfc8;
  --accent: #3b5bdb;
  --accent-soft: #e8edfd;
  --accent-fg: #ffffff;
  --note: #2f7a5f;
  --note-soft: #e6f4ee;
  --tip: #8a5a00;
  --tip-soft: #fff4dc;
  --gotcha: #b3261e;
  --gotcha-soft: #fde9e7;
  --world: #6d28d9;
  --world-soft: #f1ebfd;
  --code-bg: #f4f4f1;
  --code-line: #e3e3de;
  --diagram-bg: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --measure: 72ch;
  --toc-w: 240px;
  --gap: 40px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1114;
  --bg-elev: #161a1f;
  --bg-sunk: #0b0d10;
  --fg: #e7e7e3;
  --fg-muted: #a5a59e;
  --fg-faint: #6f6f69;
  --line: #262b32;
  --line-strong: #363c45;
  --accent: #8ea2ff;
  --accent-soft: #1b2340;
  --accent-fg: #0f1114;
  --note: #6fcba2;
  --note-soft: #12281f;
  --tip: #f0c060;
  --tip-soft: #2e2510;
  --gotcha: #ff8a80;
  --gotcha-soft: #3a1815;
  --world: #c4a6ff;
  --world-soft: #241a3d;
  --code-bg: #12151a;
  --code-line: #262b32;
  --diagram-bg: #12151a;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.65;
  font-feature-settings: "cv11", "ss01", "liga";
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg { max-width: 100%; height: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.01em; font-weight: 650; margin: 0; }
h1 { font-size: 2.1rem; letter-spacing: -0.02em; }
h2 { font-size: 1.5rem; margin-top: 3rem; margin-bottom: .9rem; padding-top: .5rem; }
h3 { font-size: 1.15rem; margin-top: 2rem; margin-bottom: .6rem; }
h4 { font-size: 1rem; margin-top: 1.5rem; margin-bottom: .4rem; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .06em; font-size: .8rem; }
p, ul, ol { margin: 0 0 1.1rem; }
li { margin: .25rem 0; }
li > ul, li > ol { margin-top: .3rem; margin-bottom: .3rem; }
strong { font-weight: 650; }
small { color: var(--fg-muted); }
:target { scroll-margin-top: 90px; }
h2[id], h3[id] { scroll-margin-top: 90px; }

code, kbd, pre {
  font-family: var(--font-mono);
  font-size: .86em;
  font-variant-ligatures: none;
}
:not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: 6px;
  padding: .08em .4em;
  white-space: nowrap;
}
@media (max-width: 600px) { :not(pre) > code { white-space: normal; overflow-wrap: anywhere; } }
pre {
  margin: 0;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  line-height: 1.55;
  background: var(--code-bg);
  border: 1px solid var(--code-line);
  border-radius: var(--radius-sm);
  font-size: .82rem;
  tab-size: 4;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; white-space: pre; }
.code { position: relative; margin: 1.2rem 0 1.4rem; }
.code .code-lang {
  position: absolute; top: .45rem; left: .9rem;
  font: 600 .68rem/1 var(--font-mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--fg-faint);
}
.code pre { padding-top: 1.9rem; }
.code .copy {
  position: absolute; top: .4rem; right: .5rem;
  font: 500 .72rem/1 var(--font-sans);
  background: var(--bg-elev); color: var(--fg-muted);
  border: 1px solid var(--line); border-radius: 6px;
  padding: .35rem .55rem; cursor: pointer; opacity: 0; transition: opacity .15s;
}
.code:hover .copy, .code .copy:focus-visible { opacity: 1; }
.code .copy:hover { color: var(--fg); border-color: var(--line-strong); }

/* highlight.js token colors, tied to theme */
.hljs { color: var(--fg); background: transparent; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-built_in { color: #7c3aed; }
.hljs-string, .hljs-meta .hljs-string { color: #0f766e; }
.hljs-number { color: #b45309; }
.hljs-comment, .hljs-quote { color: var(--fg-faint); font-style: italic; }
.hljs-title, .hljs-title.function_, .hljs-title.class_ { color: #1d4ed8; }
.hljs-attr, .hljs-name, .hljs-tag { color: #9f1239; }
.hljs-meta, .hljs-symbol, .hljs-variable { color: #6b21a8; }
.hljs-type { color: #0e7490; }
[data-theme="dark"] .hljs-keyword, [data-theme="dark"] .hljs-selector-tag, [data-theme="dark"] .hljs-literal, [data-theme="dark"] .hljs-built_in { color: #c4b5fd; }
[data-theme="dark"] .hljs-string { color: #6ee7b7; }
[data-theme="dark"] .hljs-number { color: #fcd34d; }
[data-theme="dark"] .hljs-title, [data-theme="dark"] .hljs-title.function_, [data-theme="dark"] .hljs-title.class_ { color: #93c5fd; }
[data-theme="dark"] .hljs-attr, [data-theme="dark"] .hljs-name, [data-theme="dark"] .hljs-tag { color: #fda4af; }
[data-theme="dark"] .hljs-meta, [data-theme="dark"] .hljs-symbol, [data-theme="dark"] .hljs-variable { color: #d8b4fe; }
[data-theme="dark"] .hljs-type { color: #67e8f9; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.site-header .inner {
  max-width: calc(var(--measure) + var(--toc-w) + var(--gap) + 2rem);
  margin: 0 auto; padding: .7rem 1rem;
  display: flex; align-items: center; gap: 1rem;
}
.wordmark {
  font-weight: 750; letter-spacing: -0.03em; font-size: 1.15rem; color: var(--fg);
  display: inline-flex; align-items: center; gap: .5rem;
}
.wordmark:hover { text-decoration: none; }
.wordmark .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.crumbs { display: flex; align-items: center; gap: .45rem; color: var(--fg-muted); font-size: .9rem; min-width: 0; }
.crumbs a { color: var(--fg-muted); }
.crumbs a:hover { color: var(--fg); }
.crumbs .sep { color: var(--fg-faint); }
.crumbs .current { color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--fg-muted); cursor: pointer;
}
.theme-toggle:hover { color: var(--fg); border-color: var(--line-strong); }
.theme-toggle svg { width: 18px; height: 18px; }
.theme-toggle .sun { display: none; }
[data-theme="dark"] .theme-toggle .sun { display: block; }
[data-theme="dark"] .theme-toggle .moon { display: none; }

/* ---------- Layout ---------- */
.page { max-width: calc(var(--measure) + var(--toc-w) + var(--gap) + 2rem); margin: 0 auto; padding: 2.5rem 1rem 5rem; }
.page.with-toc { display: grid; grid-template-columns: minmax(0, var(--measure)) var(--toc-w); gap: var(--gap); align-items: start; }
.page.with-toc > .content { min-width: 0; }
.toc {
  position: sticky; top: 84px;
  font-size: .84rem; line-height: 1.45;
  max-height: calc(100vh - 100px); overflow-y: auto;
  padding-left: 1rem; border-left: 1px solid var(--line);
}
.toc .toc-title { font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-faint); font-weight: 650; margin-bottom: .6rem; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a { display: block; color: var(--fg-muted); padding: .22rem 0; }
.toc a:hover { color: var(--fg); text-decoration: none; }
.toc li.h3 a { padding-left: .9rem; font-size: .8rem; }
.toc a.active { color: var(--accent); font-weight: 600; }
.toc-mobile { display: none; }
@media (max-width: 1100px) {
  .page.with-toc { display: block; }
  .toc { display: none; }
  .toc-mobile { display: block; margin-bottom: 2rem; }
}
details.toc-mobile { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .6rem .9rem; background: var(--bg-elev); }
details.toc-mobile summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
details.toc-mobile ol { list-style: none; padding: .5rem 0 0; margin: 0; font-size: .9rem; }
details.toc-mobile li.h3 { padding-left: 1rem; }
details.toc-mobile a { display: block; padding: .15rem 0; color: var(--fg-muted); }

/* ---------- Article front matter ---------- */
.article-head { margin-bottom: 2.5rem; }
.eyebrow { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 650; margin-bottom: .8rem; }
.article-head h1 { margin-bottom: .8rem; }
.summary { font-size: 1.15rem; color: var(--fg-muted); margin: 0 0 1rem; line-height: 1.5; }
.meta { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; font-size: .84rem; color: var(--fg-faint); }
.meta span { display: inline-flex; align-items: center; gap: .35rem; }

/* ---------- Content blocks ---------- */
.content h2 { border-top: 1px solid var(--line); padding-top: 1.6rem; }
.content h2:first-of-type { border-top: 0; padding-top: 0; margin-top: 0; }
.lead { font-size: 1.05rem; color: var(--fg-muted); }
.figure { margin: 1.4rem 0 1.8rem; }
.figure .frame {
  background: var(--diagram-bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; overflow-x: auto; box-shadow: var(--shadow);
}
.figure figcaption { font-size: .84rem; color: var(--fg-muted); margin-top: .6rem; padding: 0 .2rem; }
.figure figcaption b { color: var(--fg); font-weight: 650; }
pre.mermaid { background: transparent; border: 0; padding: 0; margin: 0; text-align: center; font-size: 1rem; }
pre.mermaid svg { display: inline-block; max-width: 100%; height: auto; vertical-align: top; }
pre.mermaid:not([data-processed]) { color: transparent; min-height: 120px; }
.svg-diagram { display: block; margin: 0 auto; font-family: var(--font-sans); }
.svg-diagram .box { fill: var(--bg-elev); stroke: var(--line-strong); stroke-width: 1.2; }
.svg-diagram .box.sys { fill: var(--accent-soft); stroke: var(--accent); }
.svg-diagram .box.app { fill: var(--note-soft); stroke: var(--note); }
.svg-diagram .box.zyg { fill: var(--tip-soft); stroke: var(--tip); }
.svg-diagram .box.hw { fill: var(--bg-sunk); stroke: var(--line-strong); }
.svg-diagram .inner { fill: var(--bg-elev); stroke: var(--line); stroke-width: 1; }
.svg-diagram .t { fill: var(--fg); font-size: 13px; font-weight: 600; }
.svg-diagram .ts { fill: var(--fg-muted); font-size: 11.5px; }
.svg-diagram .tk { fill: var(--fg-faint); font-size: 10.5px; font-family: var(--font-mono); }
.svg-diagram .arrow { stroke: var(--fg-muted); stroke-width: 1.4; fill: none; marker-end: url(#arrowhead); }
.svg-diagram .arrow.dashed { stroke-dasharray: 4 4; }
.svg-diagram .arrow-label { fill: var(--fg-muted); font-size: 11px; }
.svg-diagram marker path { fill: var(--fg-muted); }

.callout {
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  background: var(--bg-elev); border-radius: var(--radius-sm);
  padding: .9rem 1.1rem; margin: 1.3rem 0;
  font-size: .95rem;
}
.callout .label { display: block; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; margin-bottom: .3rem; }
.callout p:last-child, .callout ul:last-child { margin-bottom: 0; }
.callout.note { border-left-color: var(--note); background: var(--note-soft); }
.callout.note .label { color: var(--note); }
.callout.tip { border-left-color: var(--tip); background: var(--tip-soft); }
.callout.tip .label { color: var(--tip); }
.callout.gotcha { border-left-color: var(--gotcha); background: var(--gotcha-soft); }
.callout.gotcha .label { color: var(--gotcha); }
.callout.world { border-left-color: var(--world); background: var(--world-soft); }
.callout.world .label { color: var(--world); }
.callout.world ul { padding-left: 1.1rem; margin: .2rem 0 0; }
.callout.world li { margin: .3rem 0; }
.figure.map .frame { padding: 0; overflow: hidden; }
.mindmap { width: 100%; height: 520px; font-family: var(--font-sans); }
.mindmap:fullscreen { width: 100vw; height: 100vh; }
.mindmap .mind-elixir-toolbar.rb { top: 12px; right: 12px; bottom: auto; }
.mindmap .mind-elixir-toolbar.lt { top: 12px; left: 12px; }
.mindmap me-tpc { font-size: 14px; }
.mindmap me-root me-tpc { font-size: 16px; font-weight: 650; }
.mindmap me-main > me-wrapper > me-parent > me-tpc { font-weight: 600; }
.map-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-top: .6rem; }
.map-tools button {
  font: 500 .74rem/1 var(--font-sans); color: var(--fg-muted);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px;
  padding: .4rem .75rem; cursor: pointer;
}
.map-tools button:hover { color: var(--fg); border-color: var(--line-strong); }
.map-hint { font-size: .78rem; color: var(--fg-faint); }
@media (max-width: 600px) { .mindmap { height: 420px; } .map-hint { display: none; } }

.term {
  display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.2rem;
  margin: 1.3rem 0; padding: 1rem 1.2rem;
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: .93rem;
}
.term dt { font-family: var(--font-mono); font-size: .82rem; font-weight: 600; color: var(--accent); padding-top: .15rem; }
.term dd { margin: 0; color: var(--fg); }
@media (max-width: 600px) { .term { grid-template-columns: 1fr; gap: .15rem; } .term dd { margin-bottom: .5rem; } }

table { border-collapse: collapse; width: 100%; font-size: .92rem; margin: 1.2rem 0 1.5rem; }
.table-wrap { overflow-x: auto; margin: 1.2rem 0 1.5rem; }
.table-wrap table { margin: 0; min-width: 640px; }
th, td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-muted); font-weight: 650; background: var(--bg-sunk); }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
td code { white-space: nowrap; }

.steps { counter-reset: step; list-style: none; padding: 0; margin: 1.2rem 0 1.5rem; }
.steps li { position: relative; padding-left: 2.6rem; margin: .7rem 0; }
.steps li::before {
  counter-increment: step; content: counter(step);
  position: absolute; left: 0; top: .1rem;
  width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  font-weight: 700; font-size: .8rem; display: grid; place-items: center;
}

.recap { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.5rem; }
.recap ul { margin: 0; padding-left: 1.2rem; }
.recap li { margin: .45rem 0; }

/* ---------- Questions (part 2) ---------- */
.part-divider { margin: 4rem 0 2.5rem; border-top: 2px dashed var(--line-strong); }
.questions h2 { border-top: 0; padding-top: 0; margin-top: 0; }
.questions .qa-tools { display: flex; gap: .6rem; margin: -.4rem 0 1.4rem; }
.qa-tools button {
  font: 500 .78rem/1 var(--font-sans); color: var(--fg-muted);
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 999px;
  padding: .45rem .8rem; cursor: pointer;
}
.qa-tools button:hover { color: var(--fg); border-color: var(--line-strong); }
details.qa {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg-elev); margin: .7rem 0; overflow: hidden;
}
details.qa summary {
  cursor: pointer; padding: .9rem 1.1rem .9rem 2.6rem; font-weight: 600; position: relative;
  list-style: none;
}
details.qa summary::-webkit-details-marker { display: none; }
details.qa summary::before {
  content: "Q"; position: absolute; left: .9rem; top: .95rem;
  width: 1.25rem; height: 1.25rem; border-radius: 6px; font-size: .7rem; font-weight: 800;
  background: var(--accent-soft); color: var(--accent); display: grid; place-items: center;
}
details.qa summary::after {
  content: ""; position: absolute; right: 1rem; top: 1.15rem;
  width: .5rem; height: .5rem; border-right: 2px solid var(--fg-faint); border-bottom: 2px solid var(--fg-faint);
  transform: rotate(45deg); transition: transform .15s;
}
details.qa[open] summary::after { transform: rotate(-135deg); top: 1.35rem; }
details.qa[open] summary { border-bottom: 1px solid var(--line); }
details.qa .answer { padding: 1rem 1.2rem 1rem 2.6rem; font-size: .95rem; background: var(--bg); }
details.qa .answer > p:first-child { font-weight: 600; }
details.qa .answer p:last-child, details.qa .answer ul:last-child, details.qa .answer ol:last-child { margin-bottom: 0; }

/* ---------- Hub / index pages ---------- */
.hero { padding: 1rem 0 2.5rem; }
.hero h1 { font-size: 2.6rem; margin-bottom: .8rem; }
.hero p { font-size: 1.15rem; color: var(--fg-muted); max-width: 60ch; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; margin: 1.5rem 0; }
.card {
  display: block; padding: 1.2rem 1.3rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg-elev); color: var(--fg); box-shadow: var(--shadow); transition: transform .15s, border-color .15s;
}
.card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.card.soon { opacity: .55; pointer-events: none; }
.card .card-title { font-weight: 700; font-size: 1.1rem; margin-bottom: .3rem; display: flex; align-items: center; gap: .5rem; }
.card .card-desc { color: var(--fg-muted); font-size: .92rem; }
.card .badge { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; padding: .2rem .5rem; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.card .count { font-size: .8rem; color: var(--fg-faint); margin-top: .8rem; }

.article-list { list-style: none; padding: 0; margin: 1.5rem 0; }
.article-list li { border-top: 1px solid var(--line); padding: 1.1rem 0; }
.article-list li:last-child { border-bottom: 1px solid var(--line); }
.article-list a.title { font-size: 1.15rem; font-weight: 650; color: var(--fg); }
.article-list a.title:hover { color: var(--accent); text-decoration: none; }
.article-list .desc { color: var(--fg-muted); margin: .3rem 0 .4rem; }
.article-list .meta { font-size: .8rem; }

/* ---------- Footer nav ---------- */
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 4rem; }
.pager a { display: block; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--fg); }
.pager a:hover { text-decoration: none; border-color: var(--accent); }
.pager .dir { display: block; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--fg-faint); margin-bottom: .25rem; }
.pager .next { text-align: right; }
.pager .empty { visibility: hidden; }
.site-footer { text-align: center; color: var(--fg-faint); font-size: .8rem; padding: 3rem 1rem 2rem; border-top: 1px solid var(--line); }

@media (max-width: 600px) {
  body { font-size: 16px; }
  h1 { font-size: 1.7rem; }
  h2 { font-size: 1.3rem; }
  .hero h1 { font-size: 2rem; }
  .crumbs { display: none; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { text-align: left; }
  .code .copy { opacity: 1; }
}
