/* dokt site stylesheet: layout and typography.
 *
 * Every page loads, in this order: style.css (this file), theme.css (the color
 * variables, generated from [theme] in dokt.toml), then any files listed under
 * `css` in dokt.toml. Because later files win, your own CSS can override
 * anything here. Colors are only ever used through variables, so changing a
 * variable restyles everything that uses it.
 *
 * Variables available to your CSS:
 *   colors   --bg --fg --muted --line --soft --accent --broken --todo   (theme.css)
 *   layout   --sidebar (sidebar width), --logo-height
 *   fonts    --sans, --mono
 *
 * Sections: sidebar, brand header, keyboard helpers, page content, alerts,
 * Mermaid, TODOs, narrow screens.
 */
:root {
  --sidebar: 17.5rem;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 var(--sans);
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}
a { color: var(--accent); }
a:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- sidebar ---- */
#nav {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: 1.1rem 1rem 2rem;
  border-right: 1px solid var(--line);
  background: var(--soft);
  font-size: 0.9rem;
  line-height: 1.4;
}
/* Brand header: logo, site title, theme button. */
#nav .nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
#nav .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  color: var(--fg);
  font-weight: 650;
  font-size: 1.02rem;
  text-decoration: none;
}
#nav .site-title { overflow-wrap: anywhere; }
.brand-logo { height: var(--logo-height, 1.7rem); width: auto; max-width: 9rem; flex: none; }
/* Two logos: show the one that matches the active theme. */
.brand-logo.dark-only { display: none; }
:root[data-theme="dark"] .brand-logo.light-only { display: none; }
:root[data-theme="dark"] .brand-logo.dark-only { display: inline-block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .brand-logo.light-only { display: none; }
  :root:not([data-theme]) .brand-logo.dark-only { display: inline-block; }
}
#theme-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
#theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
#theme-toggle svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Keyboard: skip link, highlighted filter result, shortcut help. */
.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 0.9rem;
  border-radius: 0 0 6px 0;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
}
.skip-link:focus { left: 0; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
main:focus { outline: none; }
#tree a.kb-active {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
dialog#help {
  width: min(30rem, calc(100vw - 2rem));
  padding: 1.2rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
}
dialog#help::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog#help h2 { margin: 0 0 0.8rem; font-size: 1.15rem; }
dialog#help dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.45rem 1rem; margin: 0 0 1rem; }
dialog#help dt { white-space: nowrap; }
dialog#help dd { margin: 0; color: var(--muted); }
dialog#help button {
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--soft);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0.05em 0.45em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--soft);
  font: 0.85em/1.4 var(--mono);
  text-align: center;
}

.site-footer {
  max-width: 46rem;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}
.broken-embed {
  padding: 0.05em 0.4em;
  border: 1px dashed var(--broken);
  border-radius: 4px;
  color: var(--broken);
  font-size: 0.9em;
  cursor: help;
}
#filter {
  width: 100%;
  margin-bottom: 0.8rem;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
#tree ul { list-style: none; margin: 0; padding: 0; }
#tree ul ul { margin-left: 0.55rem; padding-left: 0.6rem; border-left: 1px solid var(--line); }
#tree li { margin: 0; }
#tree a {
  display: block;
  padding: 0.18rem 0.4rem;
  border-radius: 4px;
  color: var(--fg);
  text-decoration: none;
  overflow-wrap: anywhere;
}
#tree a:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
#tree a[aria-current="page"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
  font-weight: 600;
}
#tree summary { cursor: pointer; padding: 0.18rem 0.4rem; color: var(--muted); }
#tree .hidden { display: none; }

/* ---- content ---- */
main { padding: 2.2rem 2.5rem 5rem; min-width: 0; }
article { max-width: 46rem; }
article h1, article h2, article h3, article h4 { line-height: 1.25; margin: 2em 0 0.5em; }
article h1 { font-size: 2rem; margin-top: 0; letter-spacing: -0.01em; }
article h2 { font-size: 1.45rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--line); }
article h3 { font-size: 1.15rem; }
article h4 { font-size: 1rem; }
article .anchor { text-decoration: none; margin-left: 0.4rem; opacity: 0; }
article .anchor::before { content: "#"; color: var(--muted); }
article :is(h1, h2, h3, h4):hover .anchor, article .anchor:focus-visible { opacity: 1; }
article p, article ul, article ol, article table, article pre, article blockquote { margin: 0 0 1rem; }
article img { max-width: 100%; height: auto; }
article code {
  font: 0.875em/1.4 var(--mono);
  background: var(--soft);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}
article pre {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.85rem 1rem;
  overflow-x: auto;
  line-height: 1.45;
}
article pre code { background: none; padding: 0; font-size: 0.85rem; }
article blockquote {
  margin-left: 0;
  padding: 0.1rem 1rem;
  border-left: 3px solid var(--line);
  color: var(--muted);
}
article table { border-collapse: collapse; display: block; overflow-x: auto; }
article th, article td { border: 1px solid var(--line); padding: 0.4rem 0.7rem; text-align: left; }
article th { background: var(--soft); }
article hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }
article ul.contains-task-list { list-style: none; padding-left: 1.2rem; }

/* Wikilinks to pages that do not exist. */
article a[href="#"][title^="Not found"] {
  color: var(--broken);
  text-decoration: underline dotted;
  cursor: help;
}

/* Alerts: > [!NOTE], > [!WARNING], ... */
.markdown-alert {
  margin: 0 0 1rem;
  padding: 0.5rem 1rem;
  border-left: 4px solid var(--accent);
  background: var(--soft);
  border-radius: 0 6px 6px 0;
  color: var(--fg);
}
.markdown-alert > :last-child { margin-bottom: 0; }
.markdown-alert-title { font-weight: 650; margin-bottom: 0.3rem; }
.markdown-alert-warning, .markdown-alert-caution { border-left-color: var(--broken); }
.markdown-alert-tip { border-left-color: #1a7f37; }
.markdown-alert-important { border-left-color: #8250df; }

/* Mermaid */
pre.mermaid {
  background: none;
  border: 0;
  padding: 0;
  text-align: center;
  overflow-x: auto;
  font-family: var(--sans);
}

.page-list { padding-left: 1.1rem; }

/* TODO markers in page text, and the TODOs page. */
mark.dokt-todo {
  background: var(--todo);
  color: inherit;
  padding: 0.05em 0.3em;
  border-radius: 3px;
  font-weight: 650;
}
mark.dokt-todo:target { outline: 2px solid var(--accent); outline-offset: 1px; }
#nav .todo-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  text-decoration: none;
}
#nav .todo-link[aria-current="page"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
#nav .todo-link .badge {
  min-width: 1.5em;
  padding: 0 0.45em;
  border-radius: 999px;
  background: var(--todo);
  color: var(--fg);
  font-size: 0.8em;
  font-weight: 650;
  text-align: center;
}
.todo-summary { font-size: 1.05rem; }
.todo-note { color: var(--muted); font-size: 0.92rem; }
.todo-list { list-style: none; padding-left: 0; }
.todo-item { display: flex; gap: 0.5rem; align-items: baseline; padding: 0.2rem 0; }
.todo-item input { flex: none; transform: translateY(0.1em); }
.todo-item.done a { color: var(--muted); text-decoration: line-through; }
.todo-line { margin-left: auto; padding-left: 0.75rem; color: var(--muted); white-space: nowrap; }
article h3 small { font-weight: 400; color: var(--muted); font-size: 0.8em; margin-left: 0.4rem; }

@media (max-width: 860px) {
  body { grid-template-columns: minmax(0, 1fr); }
  #nav { position: static; height: auto; max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 1.5rem 1.1rem 4rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
