/* Public document reader. Colours, fonts, width and radius come from the document's theme
   as CSS variables set on <body> by docs-reader.js. */

*, *::before, *::after { box-sizing: border-box; }
html { scroll-padding-top: 76px; }
body.dr {
  --bg: #111113; --surface: #18181b; --text: #ececef; --muted: #a1a1aa; --border: #2a2a2f;
  --accent: #1e9bff; --radius: 10px; --width: 780px;
  --font: Inter, system-ui, sans-serif; --heading-font: var(--font);
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.7 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button { font: inherit; color: inherit; }
.dr-muted { color: var(--muted); }
.dr-loading { padding: 80px 20px; text-align: center; color: var(--muted); }
.dr-skip { position: absolute; left: -999px; top: 8px; z-index: 100; padding: 8px 12px; background: var(--surface); border-radius: 6px; }
.dr-skip:focus { left: 8px; }

/* ---------- top bar ---------- */
.dr-draftbar { padding: 8px 16px; text-align: center; font-size: 14px; background: color-mix(in srgb, var(--accent) 18%, var(--bg)); border-bottom: 1px solid var(--border); }
.dr-top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 14px; height: 60px; padding: 0 20px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.dr-brand { display: flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); text-decoration: none; font: 700 16px/1.2 var(--heading-font); }
.dr-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dr-logo:empty { display: none; }
.dr-logo img { display: block; width: 30px; height: 30px; border-radius: calc(var(--radius) * 0.6); object-fit: cover; }
.dr-menu { display: none; width: 38px; height: 38px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.dr-search { position: relative; flex: 1; max-width: 420px; margin-left: auto; }
.dr-search input { width: 100%; height: 38px; padding: 0 34px 0 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; outline: none; }
.dr-search input:focus { border-color: var(--accent); }
.dr-search kbd { position: absolute; right: 10px; top: 9px; padding: 0 6px; border: 1px solid var(--border); border-radius: 4px; font: 12px/18px ui-monospace, monospace; color: var(--muted); pointer-events: none; }
.dr-search input:focus + kbd { display: none; }
.dr-results { position: absolute; left: 0; right: 0; top: 44px; max-height: 60vh; overflow: auto; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3); }
.dr-results a { display: grid; gap: 2px; padding: 8px 10px; border-radius: calc(var(--radius) * 0.6); color: var(--text); text-decoration: none; }
.dr-results a:hover, .dr-results a.is-active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.dr-results span { font-size: 13px; line-height: 1.5; color: var(--muted); }
.dr-results mark { background: color-mix(in srgb, var(--accent) 35%, transparent); color: inherit; border-radius: 2px; }
.dr-results p { margin: 8px 10px; font-size: 14px; }
.dr-icon { width: 38px; height: 38px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; }

.dr-banner { height: 180px; background: center / cover no-repeat; border-bottom: 1px solid var(--border); }

/* ---------- three columns ---------- */
.dr-body { display: grid; grid-template-columns: 260px minmax(0, 1fr) 220px; grid-template-areas: "side main toc"; max-width: calc(var(--width) + 560px); margin: 0 auto; }
body.dr-right .dr-body { grid-template-columns: 220px minmax(0, 1fr) 260px; grid-template-areas: "toc main side"; }
.dr-side { grid-area: side; position: sticky; top: 60px; align-self: start; max-height: calc(100vh - 60px); overflow: auto; padding: 24px 16px 40px 20px; }
.dr-main { grid-area: main; min-width: 0; max-width: var(--width); width: 100%; margin: 0 auto; padding: 32px 28px 80px; outline: none; }
.dr-toc { grid-area: toc; position: sticky; top: 60px; align-self: start; max-height: calc(100vh - 60px); overflow: auto; padding: 32px 20px; font-size: 13px; }
.dr-toc p { margin: 0 0 8px; font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.dr-toc ul { list-style: none; margin: 0; padding: 0; border-left: 1px solid var(--border); }
.dr-toc li.l3 { padding-left: 12px; }
.dr-toc a { display: block; padding: 3px 0 3px 12px; margin-left: -1px; border-left: 2px solid transparent; color: var(--muted); text-decoration: none; line-height: 1.45; }
.dr-toc a:hover { color: var(--text); }
.dr-toc a.is-active { color: var(--accent); border-left-color: var(--accent); }

.dr-tree { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.dr-tree.is-nested { padding-left: 12px; margin-left: 10px; border-left: 1px solid var(--border); }
.dr-tree a { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: calc(var(--radius) * 0.6); color: var(--muted); text-decoration: none; line-height: 1.4; }
.dr-tree a:hover { color: var(--text); background: var(--surface); }
.dr-tree a.is-active { color: var(--text); font-weight: 600; background: color-mix(in srgb, var(--accent) 14%, transparent); }
.dr-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none; }
.dr-more, .dr-guild { font-size: 13px; color: var(--muted); padding: 0 10px; }
.dr-guild { margin-top: 24px; }

/* ---------- article ---------- */
.dr-staff { margin: 0 0 16px; padding: 8px 12px; font-size: 14px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.dr-h1, .dr-content h1 { margin: 0 0 8px; font: 700 2.1em/1.2 var(--heading-font); letter-spacing: -0.02em; }
.dr-content h1 + * { margin-top: 0; }
.dr-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; justify-content: space-between; margin: 0 0 28px; padding-bottom: 16px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.dr-actions { display: flex; gap: 8px; align-items: center; }
.dr-actions > button, .dr-dl summary { padding: 4px 10px; border: 1px solid var(--border); border-radius: calc(var(--radius) * 0.6); background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer; list-style: none; }
.dr-dl { position: relative; }
.dr-dl summary::-webkit-details-marker { display: none; }
.dr-dl > div { position: absolute; right: 0; top: 34px; z-index: 20; display: grid; min-width: 230px; padding: 6px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3); }
.dr-dl a, .dr-dl button { padding: 7px 10px; border: 0; border-radius: 6px; background: none; color: var(--text); text-align: left; text-decoration: none; font-size: 14px; cursor: pointer; }
.dr-dl a:hover, .dr-dl button:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }

.dr-content { overflow-wrap: break-word; }
.dr-content h2, .dr-content h3, .dr-content h4 { position: relative; font-family: var(--heading-font); line-height: 1.3; margin: 2em 0 0.6em; }
.dr-content h2 { font-size: 1.5em; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.dr-content h3 { font-size: 1.2em; }
.dr-content h4 { font-size: 1.05em; }
.dr-anchor { opacity: 0; margin-left: 6px; color: var(--muted); text-decoration: none; font-weight: 400; }
.dr-content :is(h1, h2, h3, h4):hover .dr-anchor, .dr-anchor:focus { opacity: 1; }
.dr-content p, .dr-content ul, .dr-content ol, .dr-content pre, .dr-content blockquote, .dr-content .table-wrap, .dr-content .callout { margin: 0 0 1.1em; }
.dr-content ul, .dr-content ol { padding-left: 1.5em; }
.dr-content li { margin: 0.25em 0; }
.dr-content li > ul, .dr-content li > ol { margin: 0.25em 0; }
.dr-content li.task { list-style: none; margin-left: -1.4em; }
.dr-content li.task input { margin-right: 6px; accent-color: var(--accent); }
.dr-content img { max-width: 100%; height: auto; border-radius: var(--radius); }
.dr-content hr { border: 0; border-top: 1px solid var(--border); margin: 2em 0; }
.dr-content code { padding: 0.15em 0.4em; border-radius: 5px; background: var(--surface); border: 1px solid var(--border); font: 0.88em ui-monospace, SFMono-Regular, Menlo, monospace; }
.dr-content pre { padding: 14px 16px; overflow: auto; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); line-height: 1.5; }
.dr-content pre code { padding: 0; border: 0; background: none; font-size: 0.86em; }
.dr-content blockquote { padding: 2px 16px; border-left: 3px solid var(--border); color: var(--muted); }
.dr-content .table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.dr-content table { width: 100%; border-collapse: collapse; font-size: 0.94em; }
.dr-content th, .dr-content td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.dr-content th { background: var(--surface); font-weight: 600; }
.dr-content tr:last-child td { border-bottom: 0; }
.dr-content .callout { --c: #3b82f6; padding: 12px 16px; border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); border-left: 4px solid var(--c); border-radius: var(--radius); background: color-mix(in srgb, var(--c) 9%, transparent); }
.dr-content .callout > :last-child { margin-bottom: 0; }
.dr-content .callout-title { margin: 0 0 4px; font-weight: 700; color: var(--c); }
.dr-content .callout-tip { --c: #22c55e; }
.dr-content .callout-info { --c: #06b6d4; }
.dr-content .callout-warning { --c: #f59e0b; }
.dr-content .callout-danger { --c: #ef4444; }
.dr-content .callout-important { --c: #a855f7; }

.dr-pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 48px; }
.dr-pager a { display: grid; gap: 2px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; font-weight: 600; }
.dr-pager a:hover { border-color: var(--accent); }
.dr-pager small { font-weight: 500; font-size: 12px; color: var(--muted); }
.dr-pager .is-next { text-align: right; grid-column: 2; }

.dr-msg { max-width: 560px; padding: 40px 0; }
.dr-msg.is-full { margin: 0 auto; padding: 100px 20px; text-align: center; }
.dr-msg h1 { font: 700 1.8em/1.2 var(--heading-font); margin: 0 0 10px; }
.dr-kicker { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.dr-btn { display: inline-block; margin-top: 8px; padding: 10px 18px; border-radius: var(--radius); background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; }

.dr-list { max-width: 720px; margin: 0 auto; padding: 60px 20px; }
.dr-list h1 { font: 700 2em/1.2 var(--heading-font); }
.dr-list ul { list-style: none; padding: 0; display: grid; gap: 10px; }
.dr-list a { display: grid; gap: 2px; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.dr-list a:hover { border-color: var(--accent); }
.dr-list span, .dr-list small { color: var(--muted); }

.dr-scrim { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.5); }

/* ---------- smaller screens ---------- */
@media (max-width: 1180px) {
  .dr-body, body.dr-right .dr-body { grid-template-columns: 250px minmax(0, 1fr); grid-template-areas: "side main"; }
  body.dr-right .dr-body { grid-template-columns: minmax(0, 1fr) 250px; grid-template-areas: "main side"; }
  .dr-toc { display: none; }
}
@media (max-width: 860px) {
  .dr-body, body.dr-right .dr-body { display: block; }
  .dr-menu { display: grid; place-items: center; }
  .dr-side { position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(300px, 85vw); max-height: none; background: var(--bg); border-right: 1px solid var(--border); transform: translateX(-100%); transition: transform 0.2s; }
  body.dr-right .dr-side { left: auto; right: 0; border-right: 0; border-left: 1px solid var(--border); transform: translateX(100%); }
  body.dr-nav-open .dr-side { transform: none; }
  .dr-main { padding: 24px 16px 60px; }
  .dr-top { gap: 8px; padding: 0 12px; }
  .dr-title { display: none; }
  .dr-banner { height: 110px; }
  .dr-search kbd { display: none; }
}

/* ---------- print / PDF ---------- */
@media print {
  body.dr { background: #fff; color: #000; --text: #000; --muted: #444; --border: #ccc; --surface: #f5f5f5; font-size: 12pt; }
  .dr-top, .dr-side, .dr-toc, .dr-pager, .dr-actions, .dr-banner, .dr-draftbar, .dr-staff, .dr-anchor, .dr-scrim { display: none !important; }
  .dr-body { display: block; max-width: none; }
  .dr-main { max-width: none; padding: 0; }
  .dr-content a { color: #000; }
  .dr-content pre, .dr-content .callout, .dr-content table { break-inside: avoid; }
}
