/* ── Theme toggle + dark-mode component overrides ──────────────────────────────
   Loaded last so these rules win over the component defaults. Everything that is
   already driven by a token in tokens.css flips on its own; what lives here is the
   handful of surfaces that were painted with literal colours because they only ever
   had to work on a light page. */

/* ── The toggle control ── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-muted);
  cursor: pointer;
  padding: 0;
  transition: color var(--transition-fast), border-color var(--transition-fast),
              background var(--transition-fast);
}

.theme-toggle:hover {
  color: var(--color-link);
  border-color: var(--color-link);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--color-link);
  outline-offset: 2px;
}

.theme-toggle__icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Sun in light mode, moon in dark mode — only one is ever in the render tree. */
.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; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

/* ── Figure controls (download / full screen) ── */
.figure-block {
  margin: var(--space-xl) 0;
}

.figure-block__canvas {
  position: relative;
}

.figure-block__tools {
  display: flex;
  gap: var(--space-xs);
  justify-content: flex-end;
  margin-top: calc(-1 * var(--space-sm));
}

.figure-tool {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 2px 8px;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.figure-tool:hover { color: var(--color-link); border-color: var(--color-link); }
.figure-tool:focus-visible { outline: 2px solid var(--color-link); outline-offset: 2px; }

.figure-block__canvas:fullscreen {
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
}

.figure-block__canvas:fullscreen svg { max-height: 92vh; width: auto; }

/* Diagram labels that are deliberately faint read as low-contrast once the canvas
   goes dark, because the ink is now the lighter of the two colours. Lift the floor
   for exactly the faint values the older diagrams use — the hierarchy survives, the
   contrast ratio clears AA. */
:root[data-theme="dark"] .article-body svg text[opacity="0.5"],
:root[data-theme="dark"] .article-body svg text[opacity="0.55"] { opacity: 0.68; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .article-body svg text[opacity="0.5"],
  :root:not([data-theme="light"]) .article-body svg text[opacity="0.55"] { opacity: 0.68; }
}

/* ── Dark-mode component fixes ─────────────────────────────────────────────── */
:root[data-theme="dark"] .site-header { background: rgba(15,24,38,0.92); }
:root[data-theme="dark"] .code-block-header { background: #1B2A3F; }
:root[data-theme="dark"] pre[class*="language-"],
:root[data-theme="dark"] code[class*="language-"],
:root[data-theme="dark"] .article-body pre:not([class*="language-"]) { color: #D7E3F4; }
:root[data-theme="dark"] .article-body table thead { background: #22344E; }
:root[data-theme="dark"] .article-body table tbody tr:hover { background: #1E3149; }
:root[data-theme="dark"] .article-body h1 { background-image: linear-gradient(135deg, #DCEBFF, #7FC0FF); }
:root[data-theme="dark"] .text-gradient { background-image: linear-gradient(135deg, #DCEBFF, #7FC0FF); }
:root[data-theme="dark"] .section-card--fundamentals .section-card__icon { background: linear-gradient(135deg, #1B2E4A, #24405F); }
:root[data-theme="dark"] .section-card--branching .section-card__icon { background: linear-gradient(135deg, #3B2716, #55391F); }
:root[data-theme="dark"] .section-card--conflict .section-card__icon { background: linear-gradient(135deg, #16304A, #1E4667); }
:root[data-theme="dark"] .section-card--formats .section-card__icon { background: linear-gradient(135deg, #17392C, #1F513C); }
:root[data-theme="dark"] .token.comment,
:root[data-theme="dark"] .token.prolog,
:root[data-theme="dark"] .token.doctype,
:root[data-theme="dark"] .token.cdata { color: #93A9C2; }
:root[data-theme="dark"] .token.punctuation { color: #A9BDD6; }
:root[data-theme="dark"] .token.property,
:root[data-theme="dark"] .token.tag,
:root[data-theme="dark"] .token.boolean,
:root[data-theme="dark"] .token.number,
:root[data-theme="dark"] .token.constant,
:root[data-theme="dark"] .token.symbol { color: #8CC6FF; }
:root[data-theme="dark"] .token.selector,
:root[data-theme="dark"] .token.attr-name,
:root[data-theme="dark"] .token.string,
:root[data-theme="dark"] .token.char,
:root[data-theme="dark"] .token.builtin { color: #7FDCAB; }
:root[data-theme="dark"] .token.operator,
:root[data-theme="dark"] .token.entity,
:root[data-theme="dark"] .token.url,
:root[data-theme="dark"] .language-css .token.string { color: #FFB27A; }
:root[data-theme="dark"] .token.atrule,
:root[data-theme="dark"] .token.attr-value,
:root[data-theme="dark"] .token.keyword { color: #D5AEFF; }
:root[data-theme="dark"] .token.function,
:root[data-theme="dark"] .token.class-name { color: #8CC6FF; }
:root[data-theme="dark"] .token.regex,
:root[data-theme="dark"] .token.important,
:root[data-theme="dark"] .token.variable { color: #FFB27A; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .site-header { background: rgba(15,24,38,0.92); }
  :root:not([data-theme="light"]) .code-block-header { background: #1B2A3F; }
  :root:not([data-theme="light"]) pre[class*="language-"],
  :root:not([data-theme="light"]) code[class*="language-"],
  :root:not([data-theme="light"]) .article-body pre:not([class*="language-"]) { color: #D7E3F4; }
  :root:not([data-theme="light"]) .article-body table thead { background: #22344E; }
  :root:not([data-theme="light"]) .article-body table tbody tr:hover { background: #1E3149; }
  :root:not([data-theme="light"]) .article-body h1 { background-image: linear-gradient(135deg, #DCEBFF, #7FC0FF); }
  :root:not([data-theme="light"]) .text-gradient { background-image: linear-gradient(135deg, #DCEBFF, #7FC0FF); }
  :root:not([data-theme="light"]) .section-card--fundamentals .section-card__icon { background: linear-gradient(135deg, #1B2E4A, #24405F); }
  :root:not([data-theme="light"]) .section-card--branching .section-card__icon { background: linear-gradient(135deg, #3B2716, #55391F); }
  :root:not([data-theme="light"]) .section-card--conflict .section-card__icon { background: linear-gradient(135deg, #16304A, #1E4667); }
  :root:not([data-theme="light"]) .section-card--formats .section-card__icon { background: linear-gradient(135deg, #17392C, #1F513C); }
  :root:not([data-theme="light"]) .token.comment,
  :root:not([data-theme="light"]) .token.prolog,
  :root:not([data-theme="light"]) .token.doctype,
  :root:not([data-theme="light"]) .token.cdata { color: #93A9C2; }
  :root:not([data-theme="light"]) .token.punctuation { color: #A9BDD6; }
  :root:not([data-theme="light"]) .token.property,
  :root:not([data-theme="light"]) .token.tag,
  :root:not([data-theme="light"]) .token.boolean,
  :root:not([data-theme="light"]) .token.number,
  :root:not([data-theme="light"]) .token.constant,
  :root:not([data-theme="light"]) .token.symbol { color: #8CC6FF; }
  :root:not([data-theme="light"]) .token.selector,
  :root:not([data-theme="light"]) .token.attr-name,
  :root:not([data-theme="light"]) .token.string,
  :root:not([data-theme="light"]) .token.char,
  :root:not([data-theme="light"]) .token.builtin { color: #7FDCAB; }
  :root:not([data-theme="light"]) .token.operator,
  :root:not([data-theme="light"]) .token.entity,
  :root:not([data-theme="light"]) .token.url,
  :root:not([data-theme="light"]) .language-css .token.string { color: #FFB27A; }
  :root:not([data-theme="light"]) .token.atrule,
  :root:not([data-theme="light"]) .token.attr-value,
  :root:not([data-theme="light"]) .token.keyword { color: #D5AEFF; }
  :root:not([data-theme="light"]) .token.function,
  :root:not([data-theme="light"]) .token.class-name { color: #8CC6FF; }
  :root:not([data-theme="light"]) .token.regex,
  :root:not([data-theme="light"]) .token.important,
  :root:not([data-theme="light"]) .token.variable { color: #FFB27A; }
}

/* Mobile nav: a second tier for the newest topics */
.mobile-nav__heading {
  margin: var(--space-lg) 0 var(--space-xs);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
}
