/* MUSA Grader documentation — one stylesheet for guides and API pages. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-sunken: #eef0f3;
  --surface: #ffffff;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1c2129;
  --text-soft: #4a5260;
  --text-muted: #6b7380;
  --accent: #0b5cad;
  --accent-soft: #e8f1fb;
  --accent-strong: #08467f;
  --code-bg: #f3f5f8;
  --code-text: #1c2129;
  --sig-bg: #f4f7fb;
  --sig-border: #0b5cad;
  --ok: #1a7f37;
  --ok-soft: #e7f5ec;
  --warn: #9a6700;
  --warn-soft: #fdf4dc;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 10px;
  --topbar-h: 56px;
  --sidebar-w: 280px;
  --toc-w: 230px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --bg-soft: #151a20;
    --bg-sunken: #1b2129;
    --surface: #151a20;
    --border: #262d37;
    --border-strong: #353e4b;
    --text: #e6e9ee;
    --text-soft: #b7bec9;
    --text-muted: #8a93a1;
    --accent: #6cb2ff;
    --accent-soft: #14273d;
    --accent-strong: #9ccbff;
    --code-bg: #1a2028;
    --code-text: #e6e9ee;
    --sig-bg: #16202c;
    --sig-border: #6cb2ff;
    --ok: #4ac26b;
    --ok-soft: #12291a;
    --warn: #d6a234;
    --warn-soft: #2b2310;
    --bad: #f47067;
    --bad-soft: #2f1414;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --bg-soft: #151a20;
  --bg-sunken: #1b2129;
  --surface: #151a20;
  --border: #262d37;
  --border-strong: #353e4b;
  --text: #e6e9ee;
  --text-soft: #b7bec9;
  --text-muted: #8a93a1;
  --accent: #6cb2ff;
  --accent-soft: #14273d;
  --accent-strong: #9ccbff;
  --code-bg: #1a2028;
  --code-text: #e6e9ee;
  --sig-bg: #16202c;
  --sig-border: #6cb2ff;
  --ok: #4ac26b;
  --ok-soft: #12291a;
  --warn: #d6a234;
  --warn-soft: #2b2310;
  --bad: #f47067;
  --bad-soft: #2f1414;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--topbar-h) + 16px); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.filled { fill: currentColor; stroke: none; }

.skip-link { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 6px; }
.skip-link:focus { left: 8px; }

/* ---------- Top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; font-size: 16px; letter-spacing: -.01em; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { width: 28px; height: 28px; }
.logo-bg { fill: var(--accent); stroke: none; }
.logo-check { stroke: #fff; stroke-width: 3; fill: none; }
.version { font-size: 12px; font-weight: 500; color: var(--text-muted); background: var(--bg-sunken); border: 1px solid var(--border); padding: 1px 7px; border-radius: 999px; }

.search-trigger {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  width: min(340px, 40vw); height: 36px; padding: 0 10px;
  font: inherit; font-size: 14px; color: var(--text-muted);
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer;
}
.search-trigger:hover { border-color: var(--border-strong); }
.search-trigger span { flex: 1; text-align: left; }
kbd { font: 12px var(--mono); color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; }

.topbar-actions { display: flex; gap: 4px; }
.icon-button { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; border: 0; background: transparent; color: var(--text-soft); cursor: pointer; }
.icon-button:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.menu-button { display: none; }

.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
}

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--toc-w);
  max-width: 1480px; margin: 0 auto;
}

.sidebar {
  position: sticky; top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
  padding: 24px 16px 48px 20px;
  border-right: 1px solid var(--border);
  font-size: 14.5px;
}
.nav-section { margin: 22px 0 6px; padding: 0 10px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.nav-section:first-child { margin-top: 0; }
.nav-list, .nav-list ul { list-style: none; margin: 0; padding: 0; }
.nav-list a { display: block; padding: 5px 10px; border-radius: 6px; color: var(--text-soft); line-height: 1.4; }
.nav-list a:hover { background: var(--bg-sunken); color: var(--text); text-decoration: none; }
.nav-list a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-list a code { font-size: 13px; background: none; padding: 0; color: inherit; }
.nav-group-label { display: block; margin: 10px 0 2px; padding: 0 10px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.nav-group ul a { padding-left: 18px; }

.content { min-width: 0; padding: 40px 56px 64px; }
.prose { max-width: 820px; }
.content-api .prose { max-width: 900px; }

.toc-column { padding: 40px 20px 40px 0; }
.toc { position: sticky; top: calc(var(--topbar-h) + 40px); max-height: calc(100vh - var(--topbar-h) - 80px); overflow-y: auto; font-size: 13.5px; border-left: 1px solid var(--border); padding-left: 16px; }
.toc-title { margin: 0 0 8px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc a { display: block; padding: 3px 0; color: var(--text-muted); line-height: 1.4; }
.toc a:hover { color: var(--text); text-decoration: none; }
.toc a.active { color: var(--accent); font-weight: 600; }
.toc-l3 a { padding-left: 12px; font-size: 13px; }

/* ---------- Typography ---------- */

.prose h1 { font-size: 2.3rem; line-height: 1.15; letter-spacing: -.025em; margin: 0 0 12px; font-weight: 700; }
.prose h2 { font-size: 1.55rem; line-height: 1.25; letter-spacing: -.015em; margin: 52px 0 14px; padding-top: 6px; font-weight: 650; }
.prose h3 { font-size: 1.2rem; line-height: 1.3; margin: 34px 0 10px; font-weight: 650; }
.prose h4, .prose h5 { font-size: 1rem; margin: 24px 0 8px; font-weight: 650; }
.prose h2 + p, .prose h3 + p { margin-top: 0; }
.prose p, .prose ul, .prose ol { margin: 0 0 16px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 4px 0; }
.prose li > ul { margin: 4px 0; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 40px 0; }
.prose strong { font-weight: 650; }
.prose blockquote { margin: 0 0 16px; padding: 4px 16px; border-left: 3px solid var(--border-strong); color: var(--text-soft); }

.lead { font-size: 1.15rem; color: var(--text-soft); line-height: 1.6; }
.eyebrow { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--accent); letter-spacing: .02em; }
.eyebrow a { color: inherit; }
.muted { color: var(--text-muted); }
.small { font-size: 14px; }

.headerlink { margin-left: 8px; color: var(--text-muted); opacity: 0; font-weight: 400; text-decoration: none; transition: opacity .1s; }
h1:hover .headerlink, h2:hover .headerlink, h3:hover .headerlink, .sig:hover .headerlink, .headerlink:focus { opacity: 1; }
.headerlink:hover { color: var(--accent); text-decoration: none; }

/* ---------- Code ---------- */

code { font-family: var(--mono); font-size: .875em; background: var(--code-bg); color: var(--code-text); padding: .12em .38em; border-radius: 5px; overflow-wrap: anywhere; }
a code { color: var(--accent); }
pre { position: relative; margin: 0 0 18px; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
pre code { display: block; padding: 14px 16px; background: none; font-size: 13.5px; line-height: 1.6; overflow-wrap: normal; white-space: pre; }
pre code.hljs { background: none; padding: 14px 16px; }
.code-title { margin: 0; padding: 7px 14px; font: 12.5px var(--mono); color: var(--text-muted); background: var(--bg-sunken); border: 1px solid var(--border); border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
.code-title + pre { border-top-left-radius: 0; border-top-right-radius: 0; }
.copy-button { position: absolute; top: 8px; right: 8px; padding: 3px 9px; font: 12px var(--font); color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; opacity: 0; transition: opacity .15s; }
pre:hover .copy-button, .copy-button:focus { opacity: 1; }
.copy-button:hover { color: var(--text); border-color: var(--border-strong); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { padding: 9px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { font-weight: 600; font-size: 13px; color: var(--text-soft); background: var(--bg-soft); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td code { font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 650; background: var(--bg-soft); }

/* ---------- Callouts, cards, badges ---------- */

.callout { margin: 0 0 20px; padding: 14px 18px; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); background: var(--bg-soft); }
.callout > :last-child { margin-bottom: 0; }
.callout-title { margin: 0 0 6px; font-weight: 650; font-size: 14.5px; }
.callout-tip { border-left-color: var(--ok); }
.callout-warn { border-left-color: var(--warn); background: var(--warn-soft); }
.callout-danger { border-left-color: var(--bad); background: var(--bad-soft); }
.callout pre { background: var(--bg); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin: 0 0 24px; }
.card { display: block; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); transition: border-color .15s, box-shadow .15s, transform .15s; }
a.card:hover { border-color: var(--accent); box-shadow: var(--shadow); text-decoration: none; transform: translateY(-1px); }
.card-title { display: block; margin: 0 0 6px; font-size: 1rem; font-weight: 650; }
.card p { margin: 0; font-size: 14.5px; color: var(--text-soft); }
.card .card-icon { display: grid; place-items: center; width: 34px; height: 34px; margin-bottom: 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }

.hero { padding: 12px 0 8px; }
.hero h1 { font-size: 2.8rem; }
.hero .lead { max-width: 680px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0 8px; }
.button { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 8px; font-weight: 600; font-size: 15px; border: 1px solid var(--border-strong); color: var(--text); background: var(--surface); }
.button:hover { text-decoration: none; border-color: var(--accent); }
.button-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-strong); color: #fff; }
:root[data-theme="dark"] .button-primary { color: #0f1216; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .button-primary { color: #0f1216; } }

.badge { display: inline-block; margin-right: 8px; padding: 1px 8px; font-size: 12px; font-weight: 600; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); vertical-align: middle; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-gray { background: var(--bg-sunken); color: var(--text-muted); }

.pipeline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 24px; padding: 18px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); }
.pipeline span { padding: 6px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-weight: 550; }
.pipeline i { color: var(--text-muted); font-style: normal; }

.steps { counter-reset: step; list-style: none; padding-left: 0 !important; }
.steps > li { position: relative; padding-left: 44px; margin: 0 0 22px; }
.steps > li::before { counter-increment: step; content: counter(step); position: absolute; left: 0; top: 0; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-weight: 700; font-size: 14px; }
.steps > li > strong:first-child { display: block; margin-bottom: 4px; }

/* ---------- API reference ---------- */

.module-title { font-size: 2rem !important; }
.module-title code { background: none; padding: 0; font-size: 1em; color: var(--text); }
.module-doc { margin-bottom: 8px; }
.module-doc h3 { font-size: 1.05rem; margin-top: 26px; }

.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin: 0 0 24px; }
.module-card { display: flex; flex-direction: column; gap: 6px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.module-card:hover { border-color: var(--accent); text-decoration: none; box-shadow: var(--shadow); }
.module-card code { background: none; padding: 0; font-weight: 600; color: var(--accent); font-size: 14px; }
.module-card span { font-size: 14px; color: var(--text-soft); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.module-card small { margin-top: auto; font-size: 12.5px; color: var(--text-muted); }

.summary-table td:first-child { white-space: nowrap; }
.kind { font-size: 12px; color: var(--text-muted); }

.api-class { margin: 28px 0 40px; }
.sig {
  position: relative;
  display: block;
  margin: 0;
  padding: 10px 70px 10px 14px;
  font: 14px/1.55 var(--mono);
  background: var(--sig-bg);
  border-left: 3px solid var(--sig-border);
  border-radius: 0 8px 8px 0;
  overflow-wrap: anywhere;
}
.sig-class { font-size: 15px; padding-top: 12px; padding-bottom: 12px; }
.sig-kind { color: var(--text-muted); font-style: italic; }
.sig-name { font-weight: 700; color: var(--text); }
.sig-params { color: var(--text-soft); }
.sig .xref, .field-table .xref { color: var(--accent); }
.sig .headerlink { font-family: var(--font); }
.source-link { position: absolute; right: 12px; top: 10px; font: 12px var(--font); color: var(--text-muted); }
.source-link:hover { color: var(--accent); }

.api-body { padding: 14px 0 0 17px; }
.class-meta:empty { display: none; }
.class-meta { margin: 0 0 10px !important; font-size: 13.5px; color: var(--text-muted); }
.class-meta code { font-size: 12.5px; }

dl.api-object { margin: 0 0 22px; }
dl.api-object > dt.sig { font-size: 13.5px; background: transparent; border-left-color: var(--border-strong); }
dl.api-object > dt.sig:target, .api-class:target > .sig { background: var(--accent-soft); }
dl.api-object > dd { margin: 0; padding: 8px 0 0 17px; }
dl.api-object > dd > :last-child { margin-bottom: 0; }

.rubric { margin: 26px 0 12px !important; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); display: flex; align-items: center; gap: 8px; }
.rubric::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.rubric .count { font-size: 11.5px; padding: 0 7px; border-radius: 999px; background: var(--bg-sunken); letter-spacing: 0; }
.field-table table { font-size: 13.5px; }
.field-name { font-weight: 600; background: none; padding: 0; white-space: nowrap; overflow-wrap: normal; }
.doc-literal code { font-size: 13px; }
.doc-heading { font-size: 1rem !important; }

/* ---------- Footer & pager ---------- */

.page-footer { max-width: 820px; margin-top: 64px; }
.content-api .page-footer { max-width: 900px; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.pager a { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.pager a:hover { border-color: var(--accent); text-decoration: none; }
.pager small { font-size: 12.5px; color: var(--text-muted); }
.pager span { font-weight: 600; color: var(--accent); overflow-wrap: anywhere; }
.pager-next { grid-column: 2; text-align: right; }
.footer-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--text-muted); }

/* ---------- Search ---------- */

.search-dialog { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 10vh 16px 16px; background: rgba(10, 14, 20, .45); backdrop-filter: blur(2px); }
.search-dialog[hidden] { display: none; }
.search-panel { width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.search-input-row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text-muted); }
.search-input-row input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: 16px var(--font); color: var(--text); }
.search-input-row input::-webkit-search-cancel-button { display: none; }
.search-results { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.search-results:empty { display: none; }
.search-results a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); }
.search-results a:hover, .search-results li[aria-selected="true"] a { background: var(--accent-soft); text-decoration: none; }
.search-results .r-title { display: flex; align-items: baseline; gap: 8px; font-weight: 600; font-size: 14.5px; }
.search-results .r-kind { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.search-results .r-where { margin-left: auto; font: 12px var(--mono); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
.search-results .r-desc { display: block; margin-top: 2px; font-size: 13px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results mark { background: none; color: var(--accent); }
.search-hint { margin: 0; padding: 10px 16px; font-size: 13px; color: var(--text-muted); border-top: 1px solid var(--border); }

/* ---------- Responsive ---------- */

@media (max-width: 1200px) {
  .layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .toc-column { display: none; }
}

@media (max-width: 900px) {
  :root { --topbar-h: 54px; }
  .layout { display: block; }
  .menu-button { display: inline-grid; margin-left: -8px; }
  .topbar { padding: 0 16px; gap: 10px; }
  .version { display: none; }
  .search-trigger { width: auto; margin-left: auto; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .sidebar {
    position: fixed; z-index: 40; top: 0; left: 0; bottom: 0;
    width: min(300px, 85vw); height: 100vh;
    background: var(--bg); box-shadow: var(--shadow);
    transform: translateX(-105%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: none; }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 35; background: rgba(10, 14, 20, .4); }
  body.nav-open .sidebar-scrim { display: block; }
  .content { padding: 28px 16px 48px; }
  .prose h1, .hero h1 { font-size: 1.9rem; }
  .prose h2 { font-size: 1.35rem; margin-top: 40px; }
  .sig { padding-right: 14px; }
  .source-link { position: static; display: inline-block; margin-left: 8px; }
  .api-body, dl.api-object > dd { padding-left: 4px; }
  .pager { grid-template-columns: 1fr; }
  .pager-next { grid-column: 1; }
}

@media print {
  .topbar, .sidebar, .toc-column, .pager, .copy-button { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; }
}

.rubric-ref { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; margin: 0 0 8px !important; font-size: 14.5px; }
.rubric-ref strong { margin-right: 10px; }
.config-keys { font-size: 13.5px; line-height: 1.9; }
.config-keys code { font-size: 12px; margin-right: 2px; }
