:root {
  color-scheme: light dark;
  --font-text: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  --font-code: "SFMono-Regular", "SF Mono", Consolas, "Liberation Mono", monospace;

  --article-width: 740px;
  accent-color: var(--accent);
}

:root,
:root[data-theme="light"] {
  --bg: #f3f2f7;
  --text: #1d1d1f;
  --heading: #1d1d1f;
  --muted: #6e6e73;
  --secondary: #515154;
  --border: #d2d2d7;
  --border-soft: #e3e2e9;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --code-bg: #ffffff;
  --code-text: #1d1d1f;
  --block-shadow: 0 1px 2px rgba(17, 17, 19, 0.05), 0 10px 24px rgba(17, 17, 19, 0.06);
  --accent: #0066cc;
  --accent-soft: #e8f2ff;
  --danger: #bf4b43;
  --warning: #a05f00;
  --example: #7251a5;
  --result: #278246;
  --chart-bar: #278246;
  --chart-shine: #72c488;
  --chart-neutral-bar: #64768a;
  --chart-track: #e4ece6;
  --article-logo: rgba(29, 29, 31, 0.34);
  --article-logo-hover: rgba(29, 29, 31, 0.66);

  --hl-yellow-bg: #fff2a8;
  --hl-yellow-text: #1d1d1f;
  --hl-blue-bg: #dceeff;
  --hl-blue-text: #123b63;
  --hl-green-bg: #daf3df;
  --hl-green-text: #174828;
  --hl-purple-bg: #eadcf8;
  --hl-purple-text: #40245c;
  --hl-red-bg: #f8d8d4;
  --hl-red-text: #6b2521;

  --ul-yellow: #c78b00;
  --ul-blue: #0066cc;
  --ul-green: #23863a;
  --ul-purple: #8557bd;
  --ul-red: #d23f31;
}

:root[data-theme="light"] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #08090a;
    --text: #f5f5f7;
    --heading: #ffffff;
    --muted: #a1a1a6;
    --secondary: #c7c7cc;
    --border: rgba(235, 235, 245, 0.24);
    --border-soft: rgba(235, 235, 245, 0.13);
    --surface: #18191b;
    --surface-elevated: #121315;
    --code-bg: #18191b;
    --code-text: #f5f5f7;
    --block-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
    --accent: #2997ff;
    --accent-soft: rgba(41, 151, 255, 0.14);
    --danger: #ff8a80;
    --warning: #ffd180;
    --example: #d0b3ff;
    --result: #7ee08d;
    --chart-bar: #7ee08d;
    --chart-shine: #c0f5c8;
    --chart-neutral-bar: #9aafc4;
    --chart-track: #263229;
    --article-logo: rgba(245, 245, 247, 0.34);
    --article-logo-hover: rgba(245, 245, 247, 0.68);

    --hl-yellow-bg: #5c4f20;
    --hl-yellow-text: #fff2b3;
    --hl-blue-bg: #173a5e;
    --hl-blue-text: #dceeff;
    --hl-green-bg: #1f4a2a;
    --hl-green-text: #d8f5dd;
    --hl-purple-bg: #432e5d;
    --hl-purple-text: #eddcff;
    --hl-red-bg: #5d302c;
    --hl-red-text: #ffd6d1;

    --ul-yellow: #ffd25f;
    --ul-blue: #60b2ff;
    --ul-green: #75d88c;
    --ul-purple: #c7a4ff;
    --ul-red: #ff8a80;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08090a;
  --text: #f5f5f7;
  --heading: #ffffff;
  --muted: #a1a1a6;
  --secondary: #c7c7cc;
  --border: rgba(235, 235, 245, 0.24);
  --border-soft: rgba(235, 235, 245, 0.13);
  --surface: #18191b;
  --surface-elevated: #121315;
  --code-bg: #18191b;
  --code-text: #f5f5f7;
  --block-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
  --accent: #2997ff;
  --accent-soft: rgba(41, 151, 255, 0.14);
  --danger: #ff8a80;
  --warning: #ffd180;
  --example: #d0b3ff;
  --result: #7ee08d;
  --chart-bar: #7ee08d;
  --chart-shine: #c0f5c8;
  --chart-neutral-bar: #9aafc4;
  --chart-track: #263229;
  --article-logo: rgba(245, 245, 247, 0.34);
  --article-logo-hover: rgba(245, 245, 247, 0.68);

  --hl-yellow-bg: #5c4f20;
  --hl-yellow-text: #fff2b3;
  --hl-blue-bg: #173a5e;
  --hl-blue-text: #dceeff;
  --hl-green-bg: #1f4a2a;
  --hl-green-text: #d8f5dd;
  --hl-purple-bg: #432e5d;
  --hl-purple-text: #eddcff;
  --hl-red-bg: #5d302c;
  --hl-red-text: #ffd6d1;

  --ul-yellow: #ffd25f;
  --ul-blue: #60b2ff;
  --ul-green: #75d88c;
  --ul-purple: #c7a4ff;
  --ul-red: #ff8a80;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-size: 100%;
  scroll-behavior: smooth;
  text-size-adjust: 100%;
  /* Enables height 0<->auto interpolation for the disclosure animation.
     Ignored where unsupported; disclosures then just open instantly. */
  interpolate-size: allow-keywords;
  transition: background-color 0.25s ease, color 0.25s ease;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.25s ease, color 0.25s ease;
}

.theme-toggle {
  --theme-toggle-hide-y: 8px;
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  appearance: none;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--surface-elevated);
  background: color-mix(in srgb, var(--surface-elevated) 86%, transparent);
  color: var(--secondary);
  cursor: pointer;
  backdrop-filter: blur(16px);
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition:
    color 0.15s ease,
    border-color 0.15s ease,
    background-color 0.15s ease,
    opacity 0.2s ease,
    transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
    visibility 0s linear 0s;
}

.theme-toggle.is-scroll-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(var(--theme-toggle-hide-y)) scale(0.94);
  transition-delay: 0s, 0s, 0s, 0s, 0s, 0.2s;
}

.theme-toggle:hover {
  border-color: var(--border);
  background: var(--surface);
  color: var(--heading);
}

.theme-toggle:active {
  transform: scale(0.94);
}

.theme-toggle:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

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

/* Sun when the effective theme is light, moon when dark. */
.theme-toggle .theme-icon-moon {
  display: none;
}

.theme-toggle[data-theme-effective="dark"] .theme-icon-sun {
  display: none;
}

.theme-toggle[data-theme-effective="dark"] .theme-icon-moon {
  display: block;
}

/* No-JS / pre-hydration fallback: follow the OS preference. */
@media (prefers-color-scheme: dark) {
  .theme-toggle:not([data-theme-effective]) .theme-icon-sun {
    display: none;
  }

  .theme-toggle:not([data-theme-effective]) .theme-icon-moon {
    display: block;
  }
}

.theme-toggle-label {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

::selection {
  background: color-mix(in srgb, var(--accent) 24%, transparent);
}

/* Static section navigator: one tick per heading, active section highlighted,
   heading label revealed on hover/active. Click jumps to the section. */
.section-rail {
  position: fixed;
  left: clamp(12px, 2vw, 26px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 78vh;
  padding: 4px 0;
  overflow-y: auto;
  scrollbar-width: none;
}

.section-rail::-webkit-scrollbar {
  display: none;
}

.section-rail.is-empty {
  display: none;
}

.section-tick {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 3px 0;
  margin: 0;
  border: 0;
  background: none;
  appearance: none;
  cursor: pointer;
}

.section-tick::before {
  content: "";
  flex: 0 0 auto;
  width: var(--tick-w, 14px);
  height: 2px;
  border-radius: 999px;
  background: var(--secondary);
  opacity: 0.4;
  transition: width 0.22s ease, opacity 0.2s ease, background-color 0.2s ease;
}

.section-tick[data-level="3"]::before {
  margin-left: 6px;
}

/* Active section: bright, full-strength tick, slightly longer. */
.section-tick.is-active::before {
  width: calc(var(--tick-w, 14px) + 4px);
  opacity: 1;
  background: var(--heading);
}

/* Hover: the tick grows and brightens. */
.section-tick:hover::before {
  width: calc(var(--tick-w, 14px) + 16px);
  opacity: 1;
  background: var(--heading);
}

.section-label {
  font-size: 13px;
  line-height: 1.25;
  color: var(--secondary);
  white-space: nowrap;
  max-width: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(-4px);
  transition: max-width 0.26s ease, opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

/* Heading label appears only on hover. */
.section-tick:hover .section-label {
  max-width: min(34vw, 280px);
  opacity: 1;
  transform: translateX(0);
  color: var(--heading);
}

.section-tick:focus-visible {
  outline: none;
}

.section-tick:focus-visible::before {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 3px;
}

@media (hover: none), (max-width: 900px) {
  .section-rail {
    display: none;
  }
}

.article {
  width: min(100% - 48px, var(--article-width));
  margin: 0 auto;
  padding: clamp(62px, 8vw, 88px) 0 clamp(72px, 9vw, 96px);
  hyphens: manual;
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  color: var(--heading);
  font-family: var(--font-display);
  hyphens: manual;
  letter-spacing: -0.012em;
  overflow-wrap: normal;
}

h1 {
  max-width: 720px;
  margin: 0 0 24px;
  font-size: clamp(40px, 4.6vw, 52px);
  font-weight: 700;
  line-height: 1.06;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h2 {
  margin: 62px 0 16px;
  font-size: clamp(26px, 2.8vw, 31px);
  font-weight: 600;
  line-height: 1.22;
  text-wrap: balance;
}

h3 {
  margin: 34px 0 10px;
  font-size: clamp(20px, 2vw, 22px);
  font-weight: 600;
  line-height: 1.26;
  text-wrap: balance;
}

.anchor-target,
.anchored-block {
  position: relative;
  scroll-margin-top: 32px;
}

.anchored-heading {
  position: relative;
}

.anchored-heading > .anchor-link {
  top: 0.62em;
  transform: translateY(-50%);
}

.heading-text {
  min-width: 0;
}

.anchor-link {
  position: absolute;
  left: -30px;
  top: 0.08em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  color: var(--muted);
  opacity: 0;
  text-decoration: none;
  transition: opacity 0.14s ease, color 0.14s ease, background-color 0.14s ease;
}

.anchor-link svg {
  width: 15px;
  height: 15px;
}

.anchor-link:hover {
  background: var(--surface);
  color: var(--secondary);
  text-decoration: none;
}

.anchor-link:focus-visible {
  opacity: 1;
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.anchor-target:hover > .anchor-link,
.anchor-target:focus-within > .anchor-link,
.anchored-block:hover > .anchor-link,
.anchored-block:focus-within > .anchor-link {
  opacity: 1;
}

.callout > .anchor-link {
  top: 14px;
}

.copy-notice {
  position: fixed;
  z-index: 20;
  top: max(14px, calc(env(safe-area-inset-top) + 10px));
  left: 50%;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  max-width: min(320px, calc(100vw - 32px));
  min-height: 44px;
  padding: 10px 16px 10px 13px;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-elevated) 86%, transparent);
  color: var(--heading);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.18);
  font-family: var(--font-text);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -10px) scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
  -webkit-backdrop-filter: blur(22px) saturate(1.45);
  backdrop-filter: blur(22px) saturate(1.45);
}

.copy-notice.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.copy-notice-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--result) 18%, transparent);
  color: var(--result);
}

.copy-notice-icon svg {
  width: 14px;
  height: 14px;
}

.copy-fallback-field {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

hr + h2,
.asterism + h2 {
  margin-top: 0;
}

p,
ul,
ol,
blockquote,
pre,
table,
.article-image,
.article-gallery,
.callout,
.example-grid,
.summary {
  margin-top: 0;
  margin-bottom: 24px;
}

p {
  max-width: 740px;
  text-wrap: pretty;
}

.lead {
  max-width: 720px;
  margin-bottom: 32px;
  color: var(--secondary);
  font-size: clamp(21px, 1.8vw, 23px);
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: -0.003em;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

/* Centered/right text should span the full reading column so it actually
   reads as centered, not the narrower measure paragraphs cap themselves to. */
.text-center > :where(p),
.text-right > :where(p) {
  max-width: none;
}

mark {
  padding: 0.02em 0.2em 0.05em;
  border-radius: 5px;
  color: inherit;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.hl-yellow {
  background: var(--hl-yellow-bg);
  color: var(--hl-yellow-text);
}

.hl-blue {
  background: var(--hl-blue-bg);
  color: var(--hl-blue-text);
}

.hl-green {
  background: var(--hl-green-bg);
  color: var(--hl-green-text);
}

.hl-purple {
  background: var(--hl-purple-bg);
  color: var(--hl-purple-text);
}

.hl-red {
  background: var(--hl-red-bg);
  color: var(--hl-red-text);
}

.underline {
  text-decoration-line: underline;
  text-decoration-thickness: 0.12em;
  text-decoration-skip-ink: auto;
  text-underline-offset: 0.18em;
}

.underline-yellow {
  text-decoration-color: var(--ul-yellow);
}

.underline-blue {
  text-decoration-color: var(--ul-blue);
}

.underline-green {
  text-decoration-color: var(--ul-green);
}

.underline-purple {
  text-decoration-color: var(--ul-purple);
}

.underline-red {
  text-decoration-color: var(--ul-red);
}

a {
  color: var(--accent);
  text-decoration-thickness: 0.08em;
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 0.18em;
  transition: text-decoration-color 0.12s ease;
}

a:hover {
  text-decoration-color: currentColor;
}

blockquote {
  margin: 30px 0;
  padding: 0 0 0 18px;
  border: 0;
  border-left: 3px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--secondary);
  font-size: 18px;
  font-style: normal;
  font-weight: 400;
  line-height: 1.62;
}

blockquote::before {
  content: none;
}

blockquote > :last-child {
  margin-bottom: 0;
}

q {
  quotes: "«" "»" "„" "“";
}

hr {
  height: 1px;
  margin: 48px 0;
  border: 0;
  background: var(--border-soft);
}

.asterism {
  margin: 50px 0 44px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-align: center;
}

ul,
ol {
  padding-left: 1.2em;
}

li {
  margin: 7px 0;
  padding-left: 0.12em;
}

li::marker {
  color: var(--accent);
}

code,
pre {
  font-family: var(--font-code);
}

code {
  padding: 0.08em 0.22em 0.1em;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 0.82em;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

/* Inline brand/logo icons inserted via the {icon:name} token. */
.inline-logo {
  display: inline-block;
  width: auto;
  height: 1.15em;
  margin: 0 0.08em;
  vertical-align: -0.2em;
  user-select: none;
}

h1 .inline-logo,
h2 .inline-logo,
h3 .inline-logo {
  vertical-align: -0.16em;
}

.code-figure {
  position: relative;
  margin: 0 0 36px;
}

.code-figure figcaption {
  position: absolute;
  top: 16px;
  right: 44px;
  z-index: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

pre {
  position: relative;
  overflow-x: auto;
  margin: 0;
  padding: 26px 20px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--code-bg);
  color: var(--code-text);
  box-shadow: var(--block-shadow, none);
  font-size: 14px;
  line-height: 1.62;
  white-space: pre;
  scrollbar-width: thin;
  scrollbar-color: var(--border-soft) transparent;
}

.code-copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  appearance: none;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface-elevated);
  background: color-mix(in srgb, var(--surface-elevated) 86%, transparent);
  color: var(--secondary);
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.code-copy-button svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.code-copy-button:hover {
  border-color: var(--border);
  background: var(--surface);
  color: var(--heading);
}

.code-copy-button:active {
  transform: scale(0.92);
}

.code-copy-button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

pre::-webkit-scrollbar {
  height: 8px;
}

pre::-webkit-scrollbar-track {
  background: transparent;
}

pre::-webkit-scrollbar-thumb {
  background: var(--border-soft);
  border-radius: 99px;
}

pre::-webkit-scrollbar-thumb:hover {
  background: var(--border);
}

pre code {
  display: block;
  min-width: max-content;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: inherit;
  white-space: pre;
  overflow-wrap: normal;
}

/* PrismJS Theme Integration */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--muted);
  font-style: italic;
}

.token.punctuation {
  color: var(--secondary);
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
  color: var(--danger);
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
  color: var(--result);
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
  color: var(--secondary);
}

.token.atrule,
.token.attr-value,
.token.keyword {
  color: var(--accent);
  font-weight: 600;
}

.token.function,
.token.class-name {
  color: var(--example);
}

.token.regex,
.token.important,
.token.variable {
  color: var(--warning);
}

.token.important,
.token.bold {
  font-weight: bold;
}

.token.italic {
  font-style: italic;
}

.token.entity {
  cursor: help;
}

.article-image {
  margin: 34px 0;
}

.article-youtube {
  margin: 36px 0;
}

.youtube-facade {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 16px;
  background: #111;
  box-shadow: inset 0 0 0 1px var(--border-soft);
  contain: layout paint;
}

.youtube-thumbnail,
.youtube-player {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}

.youtube-thumbnail {
  object-fit: cover;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}

.youtube-facade-link {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(0, 0, 0, 0.14);
  text-decoration: none;
  transition: background-color 0.18s ease;
}

.youtube-play {
  display: grid;
  place-items: center;
  width: 66px;
  height: 46px;
  border-radius: 13px;
  background: #f03;
  color: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s ease, background-color 0.18s ease;
}

.youtube-play svg {
  width: 27px;
  height: 27px;
  transform: translateX(1px);
}

.youtube-facade-link:focus-visible {
  outline: 3px solid #fff;
  outline-offset: -6px;
}

.youtube-facade-link:focus-visible .youtube-play {
  outline: 3px solid #fff;
  outline-offset: 4px;
}

.article-youtube figcaption {
  margin-top: 11px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  text-wrap: pretty;
}

@media (hover: hover) and (pointer: fine) {
  .youtube-facade-link:hover {
    background: rgba(0, 0, 0, 0.06);
  }

  .youtube-facade-link:hover .youtube-play {
    background: #ff1744;
    transform: scale(1.06);
  }

  .youtube-facade:has(.youtube-facade-link:hover) .youtube-thumbnail {
    transform: scale(1.015);
  }
}

.article-image img,
.gallery-slide img {
  display: block;
  width: 100%;
  max-height: min(72vh, 760px);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  background: var(--surface-elevated);
  object-fit: contain;
}

.article-image img {
  height: auto;
}

.article-image figcaption,
.gallery-caption {
  margin-top: 11px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  text-align: center;
  text-wrap: pretty;
}

.article-gallery {
  --gallery-frame-ratio: 4 / 3;
  --gallery-frame-radius: 26px;
  --gallery-caption-min-lines: 3;
  margin: 38px 0;
}

.gallery-track {
  display: flex;
  align-items: stretch;
  gap: 14px;
  overflow-x: auto;
  scroll-behavior: smooth;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Without JS the controls stay hidden, so keep a scrollbar as the affordance.
   Once article.js marks the gallery ready, arrows/dots take over and it hides. */
.article-gallery.is-ready .gallery-track {
  scrollbar-width: none;
}

.article-gallery.is-ready .gallery-track::-webkit-scrollbar {
  display: none;
}

.gallery-track:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 26%, transparent);
  outline-offset: 4px;
  border-radius: 16px;
}

.gallery-slide {
  flex: 0 0 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin: 0;
  scroll-snap-align: start;
}

.gallery-frame {
  position: relative;
  aspect-ratio: var(--gallery-frame-ratio);
  overflow: hidden;
  border-radius: var(--gallery-frame-radius);
  background: var(--surface-elevated);
  box-shadow: inset 0 0 0 1px var(--border-soft);
  contain: paint;
  isolation: isolate;
  -webkit-mask-image: -webkit-radial-gradient(white, black);
  backface-visibility: hidden;
  transform: translate3d(0, 0, 0);
}

.gallery-track {
  height: 100%;
  border-radius: inherit;
}

.gallery-slide {
  position: relative;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
}

.gallery-slide img {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  max-height: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  object-fit: contain;
}

.gallery-captions {
  font-size: 14px;
  line-height: 1.45;
  min-height: calc(var(--gallery-caption-min-lines) * 1lh);
}

.gallery-caption {
  margin-bottom: 0;
}

.article-gallery.is-ready .gallery-caption {
  display: none;
}

.article-gallery.is-ready .gallery-caption.is-active {
  display: block;
}

.gallery-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 18px;
}

.article-gallery:not(.is-ready) .gallery-controls {
  display: none;
}

.gallery-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  appearance: none;
  border: 1px solid var(--border-soft);
  border-radius: 50%;
  background: var(--surface-elevated);
  color: var(--secondary);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.gallery-arrow svg {
  width: 18px;
  height: 18px;
}

.gallery-arrow:active:not(:disabled) {
  transform: scale(0.92);
}

.gallery-arrow:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 2px;
}

.gallery-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.gallery-dot {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.gallery-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--border);
  transition: width 0.2s ease, background-color 0.2s ease;
}

.gallery-dot.is-active::before {
  width: 20px;
  background: var(--accent);
}

.gallery-dot:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: 0;
  border-radius: 999px;
}

@media (hover: hover) and (pointer: fine) {
  .gallery-arrow:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
  }

  .gallery-dot:hover:not(.is-active)::before {
    background: var(--secondary);
  }
}

@media (pointer: coarse) {
  .theme-toggle {
    width: 44px;
    height: 44px;
  }

  .gallery-arrow {
    width: 44px;
    height: 44px;
  }

  .gallery-dot {
    width: 44px;
    height: 44px;
  }

  .code-copy-button {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .gallery-track {
    scroll-behavior: auto;
  }

  .gallery-arrow:active:not(:disabled) {
    transform: none;
  }

  .theme-toggle,
  .theme-toggle.is-scroll-hidden {
    transition: none;
    transform: none;
  }
}

.callout {
  display: block;
  padding: 17px 18px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--block-shadow, none);
}

.callout h3 {
  margin: 0 0 8px;
  color: var(--heading);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.callout p {
  margin: 0;
  color: var(--secondary);
  font-size: 16px;
  line-height: 1.55;
}

.callout p + p,
.callout p + ul,
.callout ul + p {
  margin-top: 10px;
}

.callout > :last-child {
  margin-bottom: 0;
}

.callout-icon {
  display: none;
}

.callout-idea h3 {
  color: var(--accent);
}

.callout-warning h3 {
  color: var(--danger);
}

.callout-example h3 {
  color: var(--example);
}

.callout-result h3 {
  color: var(--result);
}

/* Disclosure (collapsible block) */
.anchored-block {
  margin: 24px 0;
}

.anchored-block + .anchored-block {
  margin-top: -14px;
}

.block-anchor {
  top: 11px;
}

.disclosure {
  /* Shared metrics so the body text aligns under the title (chevron in gutter). */
  --disc-pad-x: 18px;
  --disc-chevron: 17px;
  --disc-gap: 11px;
  margin: 0;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface-elevated);
  box-shadow: var(--block-shadow, none);
  overflow: clip;
}

.disclosure + .disclosure {
  margin-top: 10px;
}

.disclosure summary {
  display: flex;
  align-items: center;
  gap: var(--disc-gap);
  padding: 15px var(--disc-pad-x);
  list-style: none;
  cursor: pointer;
  color: var(--heading);
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  transition: background-color 0.15s ease;
}

.disclosure summary::-webkit-details-marker {
  display: none;
}

.disclosure summary:hover {
  background: color-mix(in srgb, var(--text) 4%, transparent);
}

.disclosure summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 30%, transparent);
  outline-offset: -3px;
}

.disclosure-chevron {
  flex: 0 0 auto;
  width: var(--disc-chevron);
  height: var(--disc-chevron);
  color: var(--muted);
  transition: transform 0.25s ease, color 0.15s ease;
}

.disclosure summary:hover .disclosure-chevron {
  color: var(--secondary);
}

.disclosure[open] .disclosure-chevron {
  transform: rotate(90deg);
  color: var(--accent);
}

.disclosure-title {
  min-width: 0;
}

.disclosure-body {
  padding: 12px var(--disc-pad-x) 18px
    calc(var(--disc-pad-x) + var(--disc-chevron) + var(--disc-gap));
  color: var(--secondary);
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.disclosure-body > :last-child {
  margin-bottom: 0;
}

.disclosure::details-content {
  overflow: hidden;
}

.disclosure[open] .disclosure-body {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .disclosure-body {
    transition: none;
    transform: none;
  }

  .copy-notice {
    transition: none;
    transform: translate(-50%, 0);
  }

  .disclosure-chevron {
    transition: color 0.15s ease;
  }
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 28px;
}

.mini-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--bg);
}

.mini-card:nth-child(3) {
  grid-column: 1 / -1;
}

.mini-card h3 {
  margin: 0 0 8px;
  color: var(--heading);
  font-size: 15px;
  font-weight: 700;
}

.mini-card p {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.checklist {
  padding-left: 0;
  list-style: none;
}

.checklist li {
  position: relative;
  margin: 9px 0;
  padding-left: 30px;
}

.checklist li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 0.02em;
  color: var(--accent);
  font-weight: 700;
}

.checklist li.is-unchecked::before {
  content: "";
  top: 0.32em;
  width: 0.74em;
  height: 0.74em;
  border: 1px solid var(--border);
  border-radius: 50%;
}

.table-wrap {
  overflow-x: auto;
  margin: 16px 0 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.article-chart {
  margin: 34px 0 42px;
  padding: 22px 0 4px;
  border-top: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
}

.article-chart-neutral {
  --chart-bar: var(--chart-neutral-bar);
}

.article-chart figcaption {
  margin-bottom: 20px;
  color: var(--heading);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
}

.chart-visual {
  display: grid;
  gap: 13px;
  padding-bottom: 20px;
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(150px, 2fr) minmax(180px, 4fr) minmax(52px, auto);
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.chart-label,
.chart-value {
  min-width: 0;
  font-size: 14px;
  line-height: 1.3;
}

.chart-label {
  overflow-wrap: anywhere;
  color: var(--secondary);
}

.chart-value {
  color: var(--heading);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.chart-track {
  display: block;
  width: 100%;
  height: 10px;
  overflow: clip;
  border-radius: 999px;
  background: var(--chart-track);
}

.chart-bar {
  position: relative;
  display: block;
  width: var(--chart-value);
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
  background: var(--chart-bar);
  transform-origin: left center;
  animation: chart-bar-reveal 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chart-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent 22%, var(--chart-shine) 50%, transparent 78%);
  opacity: 0.72;
  transform: translate3d(-120%, 0, 0);
  animation: chart-bar-shine 3.8s ease-in-out 0.65s 1 both paused;
  pointer-events: none;
}

.article-chart.is-shine-visible .chart-bar::after {
  animation-play-state: running;
}

.article-chart-neutral .chart-bar::after {
  content: none;
  animation: none;
}

.chart-data {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

@keyframes chart-bar-reveal {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes chart-bar-shine {
  0% { transform: translate3d(-120%, 0, 0); }
  58% { transform: translate3d(120%, 0, 0); }
  100% { transform: translate3d(120%, 0, 0); }
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 16px;
  line-height: 1.52;
}

th,
td {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

td {
  color: var(--secondary);
}

.cell-label {
  display: none;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.summary {
  margin-top: 64px;
  padding: 22px 24px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--block-shadow, none);
}

.summary h2 {
  margin: 0 0 8px;
  padding: 0;
  border: 0;
  color: var(--heading);
  font-size: 17px;
  line-height: 1.35;
}

.summary p {
  margin: 0;
  color: var(--secondary);
  font-size: 17px;
  line-height: 1.58;
}

@supports not (background: color-mix(in srgb, white, black)) {
  ::selection {
    background: rgba(0, 102, 204, 0.18);
  }
}

@media (max-width: 720px) {
  body {
    font-size: 17px;
    line-height: 1.56;
  }

  .article {
    width: min(100% - 32px, var(--article-width));
    padding: max(92px, calc(env(safe-area-inset-top, 0px) + 70px)) 0 58px;
  }

  h1 {
    margin-bottom: 20px;
    font-size: clamp(32px, 8.8vw, 38px);
    line-height: 1.12;
  }

  h2 {
    margin-top: 40px;
    font-size: 24px;
    line-height: 1.2;
  }

  h3 {
    margin-top: 26px;
    font-size: 21px;
  }

  h2 + :is(.article-image, .article-gallery, .anchored-block, .example-grid),
  h3 + :is(.article-image, .article-gallery, .anchored-block, .example-grid) {
    margin-top: 18px;
  }

  .anchor-link {
    display: none;
  }

  .lead {
    margin-bottom: 28px;
    font-size: 19px;
    line-height: 1.45;
  }

  p:has(mark) {
    line-height: 1.66;
  }

  code {
    padding: 0.03em 0.15em 0.05em;
    border-color: color-mix(in srgb, var(--border-soft) 65%, transparent);
    border-radius: 4px;
    background: color-mix(in srgb, var(--code-bg) 58%, transparent);
    font-size: 0.84em;
    line-height: inherit;
    white-space: normal;
    overflow-wrap: anywhere;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }

  blockquote {
    margin: 28px 0;
    padding: 0 0 0 16px;
    border-left: 3px solid var(--border);
    border-radius: 0;
    font-size: 17px;
    line-height: 1.55;
  }

  hr {
    margin: 38px 0;
  }

  .asterism {
    margin: 42px 0 38px;
  }

  .callout {
    padding: 18px;
    border-radius: 12px;
  }

  .callout-icon {
    display: none;
  }

  .callout p {
    font-size: 16px;
  }

  .anchored-block {
    margin: 20px 0;
  }

  .disclosure {
    --disc-pad-x: 14px;
    --disc-chevron: 16px;
    --disc-gap: 9px;
  }

  .disclosure summary {
    padding: 14px var(--disc-pad-x);
  }

  .disclosure-body {
    padding: 10px var(--disc-pad-x) 16px;
  }

  .article-image,
  .article-gallery,
  .article-youtube {
    margin: 30px 0;
  }

  .youtube-facade {
    border-radius: 12px;
  }

  .youtube-play {
    width: 60px;
    height: 42px;
    border-radius: 11px;
  }

  .article-gallery {
    --gallery-frame-radius: 18px;
    --gallery-caption-min-lines: 2;
  }

  .article-image img {
    max-height: 68vh;
    border-radius: 12px;
  }

  .gallery-controls {
    margin-top: 4px;
  }

  .example-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .code-figure {
    margin-bottom: 30px;
  }

  .code-figure::after {
    content: "";
    position: absolute;
    top: 1px;
    right: 1px;
    bottom: 1px;
    z-index: 1;
    width: 34px;
    border-radius: 0 11px 11px 0;
    background: linear-gradient(90deg, transparent, var(--code-bg));
    pointer-events: none;
  }

  .code-copy-button,
  .code-figure figcaption {
    z-index: 2;
  }

  pre {
    padding: 22px 48px 22px 14px;
    font-size: 13px;
    -webkit-overflow-scrolling: touch;
  }

  pre::-webkit-scrollbar {
    height: 10px;
  }

  pre::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--secondary) 34%, transparent);
  }

  .code-figure figcaption {
    top: 12px;
    right: 40px;
  }

  .summary {
    margin-top: 42px;
    padding: 20px;
  }

  .summary p {
    font-size: 16px;
  }

  .theme-toggle {
    --theme-toggle-hide-y: -8px;
    top: max(14px, calc(env(safe-area-inset-top, 0px) + 12px));
    right: max(14px, calc(env(safe-area-inset-right, 0px) + 14px));
    bottom: auto;
    width: 44px;
    height: 44px;
    opacity: 0.88;
  }

  .theme-toggle svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 560px) {
  .article-chart {
    margin: 30px 0 36px;
    padding-top: 18px;
  }

  .article-chart figcaption {
    margin-bottom: 18px;
    font-size: 15px;
  }

  .chart-visual {
    gap: 17px;
  }

  .chart-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "label value"
      "track track";
    gap: 7px 12px;
  }

  .chart-label {
    grid-area: label;
    font-size: 13px;
  }

  .chart-value {
    grid-area: value;
    font-size: 13px;
  }

  .chart-track {
    grid-area: track;
    height: 9px;
  }

  .table-wrap {
    overflow: visible;
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    background: var(--surface);
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  tr {
    padding: 14px 0;
    border-bottom: 1px solid var(--border-soft);
  }

  tbody tr:last-child {
    border-bottom: 0;
  }

  td {
    padding: 5px 16px;
    border-bottom: 0;
  }

  td + td {
    margin-top: 8px;
  }

  td::before {
    content: none;
  }

  .cell-label {
    display: block;
    margin-bottom: 1px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chart-bar {
    animation: none;
  }

  .chart-bar::after {
    content: none;
    animation: none;
  }

  .youtube-thumbnail,
  .youtube-facade-link,
  .youtube-play {
    transition: none;
  }
}
