/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f4f6f8;
  --bg-chrome: #f8fafc;
  --border: #e2e6eb;
  --text: #1f2328;
  --text-soft: #5b6470;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --on-accent: #ffffff;
  --code-bg: #f3f5f7;
  --mark: #fff1a8;
  --shadow: 0 10px 30px rgba(15, 23, 42, .14), 0 2px 6px rgba(15, 23, 42, .06);
  --hl-comment: #6a737d;
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-number: #0550ae;
  --hl-title: #8250df;
  --hl-builtin: #953800;
  --hl-tag: #116329;
  --hl-add: #116329;
  --hl-add-bg: #dafbe1;
  --hl-del: #82071e;
  --hl-del-bg: #ffebe9;
  --note: #0969da;
  --tip: #1a7f37;
  --important: #8250df;
  --warning: #9a6700;
  --caution: #cf222e;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", "Cascadia Mono", Consolas, ui-monospace, "SF Mono", Menlo, monospace;
  --topbar: 48px;
  --sidebar: 272px;
  --content-w: 860px;
}
:root.has-tabs { --topbar: 84px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1216;
    --bg-soft: #181d24;
    --bg-chrome: #12161c;
    --border: #29303a;
    --text: #e6edf3;
    --text-soft: #9aa3ad;
    --accent: #6ea8fe;
    --accent-soft: #19283f;
    --on-accent: #0b1220;
    --code-bg: #161b22;
    --mark: #5b4a00;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .3);
    --hl-comment: #8b949e;
    --hl-keyword: #ff7b72;
    --hl-string: #a5d6ff;
    --hl-number: #79c0ff;
    --hl-title: #d2a8ff;
    --hl-builtin: #ffa657;
    --hl-tag: #7ee787;
    --hl-add: #aff5b4;
    --hl-add-bg: #033a16;
    --hl-del: #ffdcd7;
    --hl-del-bg: #67060c;
    --note: #4493f8;
    --tip: #3fb950;
    --important: #ab7df8;
    --warning: #d29922;
    --caution: #f85149;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1216;
  --bg-soft: #181d24;
  --bg-chrome: #12161c;
  --border: #29303a;
  --text: #e6edf3;
  --text-soft: #9aa3ad;
  --accent: #6ea8fe;
  --accent-soft: #19283f;
  --on-accent: #0b1220;
  --code-bg: #161b22;
  --mark: #5b4a00;
  --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .3);
  --hl-comment: #8b949e;
  --hl-keyword: #ff7b72;
  --hl-string: #a5d6ff;
  --hl-number: #79c0ff;
  --hl-title: #d2a8ff;
  --hl-builtin: #ffa657;
  --hl-tag: #7ee787;
  --hl-add: #aff5b4;
  --hl-add-bg: #033a16;
  --hl-del: #ffdcd7;
  --hl-del-bg: #67060c;
  --note: #4493f8;
  --tip: #3fb950;
  --important: #ab7df8;
  --warning: #d29922;
  --caution: #f85149;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-padding-top: calc(var(--topbar) + 16px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar);
  display: flex;
  flex-direction: column;
  background: color-mix(in srgb, var(--bg-chrome) 90%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.tb-row {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px 0 8px;
}
.tb-left, .tb-right { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tb-right { flex-shrink: 0; }
.doc-title { display: flex; align-items: center; gap: 8px; min-width: 0; padding-left: 6px; }
#doc-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-path { font-size: 12.5px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dirty { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); flex-shrink: 0; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-soft);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.icon-btn.small { width: 28px; height: 28px; }
.icon-btn svg, .btn svg, .popover svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: var(--bg-soft); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text)); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: var(--caution); }
.btn.danger:hover { background: color-mix(in srgb, var(--caution) 10%, var(--bg)); }
.btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.btn svg { width: 16px; height: 16px; }
.narrow-only { display: none; }

.live { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; font-size: 12px; color: var(--text-soft); }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--tip); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tip) 22%, transparent); }
.live.missing i { background: var(--caution); box-shadow: 0 0 0 3px color-mix(in srgb, var(--caution) 22%, transparent); }
.live.pulse i { animation: pulse 1s ease-out; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tip) 60%, transparent); }
  100% { box-shadow: 0 0 0 10px transparent; }
}

body.empty .doc-only, body.empty .live { display: none !important; }

/* ---------- Tabs ---------- */
.tabs { flex: none; height: 36px; display: flex; align-items: center; gap: 4px; padding: 0 8px; }
.tab-list { align-self: stretch; display: flex; align-items: flex-end; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tab {
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 31px;
  min-width: 84px;
  max-width: 220px;
  padding: 0 5px 0 12px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  color: var(--text-soft);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.tab:hover { background: var(--bg-soft); color: var(--text); }
.tab[aria-selected="true"] { background: var(--bg); border-color: var(--border); color: var(--text); font-weight: 500; }
.tab:focus-visible { outline-offset: -2px; }
.tab-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tab-dot { display: none; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--warning); }
.tab.unsaved .tab-dot { display: block; }
.tab-close {
  flex: none;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--text-soft);
  cursor: pointer;
  opacity: 0;
}
.tab:hover .tab-close, .tab[aria-selected="true"] .tab-close { opacity: 1; }
.tab-close:hover { background: color-mix(in srgb, var(--text) 12%, transparent); color: var(--text); }
.tab-close svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

/* ---------- Layout ---------- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  position: sticky;
  top: var(--topbar);
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  height: calc(100vh - var(--topbar));
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 18px 10px 14px 12px;
  background: var(--bg-chrome);
  border-right: 1px solid var(--border);
}
body.empty .sidebar, body.toc-closed .sidebar { display: none; }
.sidebar h2 {
  margin: 0 0 6px 8px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.toc a {
  display: block;
  width: 100%;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-soft);
  font-size: 13.5px;
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  overflow-wrap: anywhere;
}
.toc a.l1 { padding-left: 18px; }
.toc a.l2 { padding-left: 28px; font-size: 13px; }
.toc a.l3 { padding-left: 38px; font-size: 13px; }
.toc a:hover { color: var(--text); background: var(--bg-soft); }
.toc a.active { color: var(--accent); background: var(--accent-soft); font-weight: 500; }
.toc .muted { padding: 4px 8px; font-size: 13px; color: var(--text-soft); }
.doc-meta { margin-top: auto; padding: 0 8px; font-size: 12px; line-height: 1.5; color: var(--text-soft); }

main { flex: 1; min-width: 0; padding: 40px 48px 120px; }
.column { position: relative; max-width: var(--content-w); min-height: calc(100vh - var(--topbar) - 160px); margin: 0 auto; }

/* ---------- Resize handles: sidebar width and text width ---------- */
.side-resizer { position: sticky; top: var(--topbar); z-index: 5; flex: 0 0 0; width: 0; height: calc(100vh - var(--topbar)); touch-action: none; }
.side-resizer::before { content: ""; position: absolute; top: 0; bottom: 0; left: -5px; width: 9px; cursor: col-resize; }
.side-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -2px;
  width: 3px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .12s;
  pointer-events: none;
}
.side-resizer:is(:hover, :focus-visible, .dragging)::after { opacity: 1; }
.side-resizer:focus-visible, .col-resizer:focus-visible { outline: none; }
body.empty .side-resizer, body.toc-closed .side-resizer { display: none; }

/* A line along the right edge of the text; hovering it shows a grip to drag. */
.col-resizer { position: absolute; top: 0; bottom: 0; right: -33px; width: 17px; cursor: col-resize; touch-action: none; }
.col-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 8px;
  width: 1px;
  background: var(--border);
  transition: background .12s;
}
.col-resizer:is(:hover, :focus-visible, .dragging)::before { background: var(--accent); }
.col-resizer i {
  position: sticky;
  top: calc(50vh - 22px);
  display: block;
  width: 7px;
  height: 44px;
  margin-left: 5px;
  border-radius: 4px;
  background: var(--accent);
  opacity: 0;
  transition: opacity .12s;
}
.col-resizer:is(:hover, :focus-visible, .dragging) i { opacity: 1; }
body.editing .col-resizer { display: none; }
body.editing .column { min-height: 0; }
body.resizing { cursor: col-resize; user-select: none; }

/* ---------- Edit mode: editor + live preview side by side ---------- */
.editor-pane, .pane-switch { display: none; }
body.editing main {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar));
  padding: 0;
}
body.editing .doc {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}
body.editing .editor-pane { display: block; min-height: 0; border-right: 1px solid var(--border); }
body.editing .preview-pane { overflow: auto; padding: 32px 36px 120px; scroll-padding-top: 16px; }
body.editing .banner { margin: 12px 16px; max-width: none; }
#editor {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 28px 32px 30vh;
  border: 0;
  outline: none;
  resize: none;
  background: var(--bg-chrome);
  color: var(--text);
  font: 14px/1.65 var(--mono);
  font-variant-ligatures: none;
  tab-size: 2;
  caret-color: var(--accent);
}

/* ---------- Banner ---------- */
.banner {
  max-width: var(--content-w);
  margin: -16px auto 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 8px 8px 14px;
  border: 1px solid color-mix(in srgb, var(--note) 35%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--note) 8%, var(--bg));
  font-size: 14px;
}
.banner.warn {
  border-color: color-mix(in srgb, var(--warning) 45%, var(--border));
  background: color-mix(in srgb, var(--warning) 10%, var(--bg));
}
#banner-text { flex: 1; }
.banner-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- Welcome ---------- */
.welcome { max-width: 600px; margin: 6vh auto 0; text-align: center; }
.welcome img { border-radius: 16px; }
.welcome.locked { margin-top: 14vh; }
.locked h1 { overflow-wrap: anywhere; }
.welcome h1 { margin: 16px 0 4px; font-size: 28px; font-weight: 650; letter-spacing: -.01em; }
.welcome .lead { margin: 0 0 24px; color: var(--text-soft); }
.welcome code { font: .9em var(--mono); background: var(--code-bg); padding: .1em .35em; border-radius: 5px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.actions .btn { height: 38px; padding: 0 16px; font-size: 14px; }
.recent { margin-top: 36px; text-align: left; }
.recent h2, .howto summary { font-size: 13px; font-weight: 600; color: var(--text-soft); }
.recent h2 { margin: 0 0 8px; letter-spacing: .04em; text-transform: uppercase; font-size: 11.5px; }
.recent-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.recent-list li + li { border-top: 1px solid var(--border); }
.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: var(--bg);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.recent-item:hover { background: var(--bg-soft); }
.recent-item .name { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .when { flex-shrink: 0; font-size: 12px; color: var(--text-soft); }
.howto { margin-top: 28px; padding: 12px 16px; text-align: left; border: 1px solid var(--border); border-radius: 10px; }
.howto summary { cursor: pointer; }
.howto ol { margin: 12px 0 4px; padding-left: 1.3em; font-size: 14px; line-height: 1.6; }
.howto li + li { margin-top: 6px; }
.hints { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-top: 28px; font-size: 12.5px; color: var(--text-soft); }
.about { margin: 32px 0 24px; font-size: 12.5px; color: var(--text-soft); }
.about a { color: var(--accent); text-decoration: none; }
.about a:hover { text-decoration: underline; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: .05em .4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-soft);
  font: 11.5px/1.5 var(--mono);
  text-align: center;
  color: var(--text);
}

/* ---------- Overlays ---------- */
.drop {
  position: fixed;
  inset: 10px;
  z-index: 50;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent) 10%, color-mix(in srgb, var(--bg) 85%, transparent));
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  pointer-events: none;
}
.popover {
  position: fixed;
  z-index: 40;
  width: 340px;
  max-height: 60vh;
  overflow: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: var(--shadow);
}
.popover ul { list-style: none; margin: 0; padding: 0; }
.popover .recent-item { border-radius: 8px; padding: 8px 10px; }
.recent-item .with-icon { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.recent-item .with-icon svg { width: 16px; height: 16px; color: var(--text-soft); }
.popover .empty-note { padding: 10px; font-size: 13px; color: var(--text-soft); }
.popover .recent-item[aria-checked="true"], .popover .recent-item[aria-checked="true"] svg { color: var(--accent); }
.popover .recent-item[aria-checked="true"] { background: var(--accent-soft); }

/* A question that has to be answered, in place of the browser's confirm(). */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 20px 20px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(15, 23, 42, .4); }
.dialog h2 { margin: 0 0 6px; font-size: 16px; font-weight: 650; line-height: 1.35; overflow-wrap: anywhere; }
.dialog p { margin: 0 0 20px; font-size: 14px; color: var(--text-soft); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.dialog-actions .btn { height: 36px; padding: 0 16px; font-size: 14px; }
.popover hr { margin: 6px 4px; border: 0; border-top: 1px solid var(--border); }
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity .18s, transform .18s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Rendered markdown ---------- */
.markdown-body { font-size: 16px; line-height: 1.7; overflow-wrap: break-word; }
.markdown-body > :first-child { margin-top: 0 !important; }
.markdown-body > :last-child { margin-bottom: 0 !important; }
.markdown-body :is(h1, h2, h3, h4, h5, h6) { position: relative; margin: 1.6em 0 .6em; font-weight: 650; line-height: 1.28; }
.markdown-body h1 { font-size: 2em; padding-bottom: .3em; border-bottom: 1px solid var(--border); letter-spacing: -.012em; }
.markdown-body h2 { font-size: 1.5em; padding-bottom: .3em; border-bottom: 1px solid var(--border); letter-spacing: -.008em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body h5 { font-size: .9em; }
.markdown-body h6 { font-size: .85em; color: var(--text-soft); }
.markdown-body .anchor {
  position: absolute;
  left: -1.05em;
  padding-right: .3em;
  font-weight: 400;
  color: var(--text-soft);
  text-decoration: none;
  opacity: 0;
}
.markdown-body :is(h1, h2, h3, h4, h5, h6):hover .anchor { opacity: 1; }
.markdown-body :where(p, ul, ol, dl, blockquote, table, pre, details, .mermaid-block) { margin: 0 0 1em; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body :is(ul, ol) { padding-left: 2em; }
.markdown-body :is(ul, ol) :is(ul, ol) { margin: .25em 0 0; }
.markdown-body li + li { margin-top: .25em; }
.markdown-body li > p { margin: .5em 0; }
.markdown-body li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.5em; }
.markdown-body li > input[type="checkbox"] { margin: 0 .45em .2em 0; vertical-align: middle; accent-color: var(--accent); }
.markdown-body code {
  padding: .15em .4em;
  border-radius: 6px;
  background: var(--code-bg);
  font: .86em var(--mono);
  font-variant-ligatures: none;
}
.markdown-body pre {
  position: relative;
  padding: 14px 16px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--code-bg);
  font-size: 13.5px;
  line-height: 1.55;
}
.markdown-body pre code { padding: 0; background: none; font-size: inherit; white-space: pre; }
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text-soft);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.markdown-body pre:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { color: var(--text); }
.copy-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.markdown-body blockquote { margin-left: 0; margin-right: 0; padding: 0 1em; color: var(--text-soft); border-left: .25em solid var(--border); }
.markdown-body table { display: block; width: max-content; max-width: 100%; overflow: auto; border-collapse: collapse; font-size: .95em; }
.markdown-body :is(th, td) { padding: 6px 13px; border: 1px solid var(--border); }
.markdown-body th { font-weight: 600; background: var(--bg-soft); }
.markdown-body tbody tr:nth-child(2n) td { background: color-mix(in srgb, var(--bg-soft) 55%, transparent); }
.markdown-body img { max-width: 100%; height: auto; border-radius: 4px; }
.markdown-body img.missing { opacity: .7; }
.markdown-body hr { height: 1px; margin: 2em 0; border: 0; background: var(--border); }
.markdown-body mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 .15em; }
.markdown-body details { padding: .5em 1em; border: 1px solid var(--border); border-radius: 8px; }
.markdown-body details[open] > summary { margin-bottom: .5em; }
.markdown-body summary { cursor: pointer; font-weight: 500; }
.markdown-body details.frontmatter { font-size: .9em; }
.markdown-body details.frontmatter pre { margin: 0; }
.markdown-body .alert { color: inherit; border-left-color: var(--c); }
.markdown-body .alert-title { display: flex; align-items: center; gap: .5em; margin: .5em 0 .25em; font-weight: 600; color: var(--c); }
.markdown-body .alert-title svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.markdown-body .alert > :last-child { margin-bottom: .5em; }
.alert-note { --c: var(--note); }
.alert-tip { --c: var(--tip); }
.alert-important { --c: var(--important); }
.alert-warning { --c: var(--warning); }
.alert-caution { --c: var(--caution); }
.mermaid-block { text-align: center; }
.mermaid-loading { padding: 32px; border: 1px dashed var(--border); border-radius: 10px; font-size: 13.5px; color: var(--text-soft); }
.mermaid-block svg { max-width: 100%; height: auto; }
.mermaid-block .mermaid-error { text-align: left; border-color: color-mix(in srgb, var(--caution) 45%, var(--border)); white-space: pre-wrap; }

/* ---------- Syntax highlighting (highlight.js classes) ---------- */
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-template-tag, .hljs-type { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-char.escape_ { color: var(--hl-string); }
.hljs-number, .hljs-literal, .hljs-variable, .hljs-template-variable, .hljs-attr, .hljs-attribute,
.hljs-selector-attr, .hljs-selector-class, .hljs-selector-id, .hljs-property, .hljs-operator { color: var(--hl-number); }
.hljs-title, .hljs-title.class_, .hljs-title.function_, .hljs-section { color: var(--hl-title); }
.hljs-built_in, .hljs-symbol, .hljs-bullet { color: var(--hl-builtin); }
.hljs-meta, .hljs-meta .hljs-keyword { color: var(--hl-title); }
.hljs-name, .hljs-tag, .hljs-selector-pseudo { color: var(--hl-tag); }
.hljs-section, .hljs-strong { font-weight: 700; }
.hljs-emphasis { font-style: italic; }
.hljs-link { color: var(--hl-string); text-decoration: underline; }
.hljs-addition { color: var(--hl-add); background: var(--hl-add-bg); }
.hljs-deletion { color: var(--hl-del); background: var(--hl-del-bg); }

/* ---------- Narrow screens ---------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: var(--topbar);
    z-index: 25;
    width: min(var(--sidebar), 85vw);
    box-shadow: var(--shadow);
  }
  .side-resizer, .col-resizer { display: none; }
  body:not(.toc-open) .sidebar { display: none; }
  main { padding: 24px 16px 96px; }
  .doc-path, .btn .label, .live span { display: none; }
  .btn { padding: 0 9px; }
  .markdown-body .anchor { display: none; }
  /* Too narrow for two panes: the editor and the preview take turns. */
  body.editing .doc { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  body.editing .pane-switch { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg-chrome); }
  .pane-switch button {
    flex: 1;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text-soft);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
  }
  .pane-switch button[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
  body.editing .editor-pane { border-right: 0; }
  body.editing.show-preview .editor-pane, body.editing:not(.show-preview) .preview-pane { display: none; }
  body.editing .preview-pane { padding: 20px 16px 80px; }
  #editor { padding: 16px 16px 30vh; }
}

/* Phones: the tab already shows the file name, and the theme and PDF export move into the "More" menu. */
@media (max-width: 600px) {
  .wide-only { display: none !important; }
  .narrow-only { display: inline-grid; }
  :root.has-tabs .doc-title { display: none; }
  .tb-row { gap: 8px; }
  .tb-left, .tb-right { gap: 0; }
  /* Without their labels, the bordered buttons would look like boxes among plain icons. */
  .tb-row .btn:not([aria-pressed="true"]) { border-color: transparent; background: transparent; color: var(--text-soft); }
}

/* Touch: targets of at least 44px, and no controls that only appear on hover. */
@media (pointer: coarse) {
  :root.has-tabs { --topbar: 88px; }
  .icon-btn, .tb-row .btn { min-width: 44px; height: 44px; justify-content: center; }
  .icon-btn.small { min-width: 36px; width: 36px; height: 36px; }
  .tabs { height: 40px; }
  .tab { height: 36px; }
  .tab-close { width: 30px; height: 30px; }
  .popover .recent-item { min-height: 44px; }
  .dialog-actions .btn, .pane-switch button { height: 44px; }
}
@media (hover: none) {
  .copy-btn, .tab-close { opacity: 1; }
  .tab:not([aria-selected="true"]) .tab-close { visibility: hidden; }
}
/* Keyboard shortcuts are only worth listing where there is a keyboard. */
@media (hover: none), (pointer: coarse) {
  .hints { display: none; }
}

/* ---------- Print: just the document, always light ---------- */
@media print {
  :root:not(#_) {
    color-scheme: light;
    --bg: #fff; --bg-soft: #f4f6f8; --bg-chrome: #f8fafc; --border: #d8dde3; --text: #000; --text-soft: #444;
    --accent: #1a4fc4; --accent-soft: #e8efff; --on-accent: #fff; --code-bg: #f5f7f9; --mark: #fff1a8;
    --hl-comment: #6a737d; --hl-keyword: #cf222e; --hl-string: #0a3069; --hl-number: #0550ae;
    --hl-title: #8250df; --hl-builtin: #953800; --hl-tag: #116329;
    --hl-add: #116329; --hl-add-bg: #dafbe1; --hl-del: #82071e; --hl-del-bg: #ffebe9;
    --note: #0969da; --tip: #1a7f37; --important: #8250df; --warning: #9a6700; --caution: #cf222e;
  }
  @page { margin: 16mm 15mm 18mm; }
  .topbar, .sidebar, .banner, .copy-btn, .anchor, .toast, .welcome, .editor-pane, .pane-switch, .popover, .drop, .dialog,
  .markdown-body details.frontmatter, .mermaid-loading, .side-resizer, .col-resizer { display: none !important; }
  .column { max-width: none; min-height: 0; }
  main, body.editing main { display: block; height: auto; padding: 0; }
  body.editing .doc { display: block; height: auto; }
  body.editing .preview-pane { overflow: visible; padding: 0; }
  /* Keep code, table and alert backgrounds even when "Background graphics" is off. */
  .markdown-body { max-width: none; font-size: 11pt; line-height: 1.55; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .markdown-body pre { white-space: pre-wrap; overflow: visible; break-inside: avoid; }
  .markdown-body pre code { white-space: pre-wrap; }
  .markdown-body :is(h1, h2, h3, h4, h5, h6) { break-after: avoid; break-inside: avoid; }
  .markdown-body :is(img, tr, blockquote, .mermaid-block) { break-inside: avoid; }
  .markdown-body table { display: table; width: auto; max-width: 100%; overflow: visible; }
  .markdown-body :is(p, li) { orphans: 3; widows: 3; }
}
