:root {
  color-scheme: dark;
  --bg: #0a0015;
  --bg-elevated: rgba(20, 4, 31, 0.76);
  --bg-elevated-strong: rgba(36, 16, 59, 0.9);
  --surface: #14041f;
  --surface-soft: #19072a;
  --text: #f1e6ff;
  --muted: #b9a8d6;
  --muted-strong: #8775a6;
  --accent: #ff00ff;
  --accent-2: #00d4ff;
  --accent-3: #ff6b00;
  --accent-4: #9945ff;
  --success: #00f5c4;
  --border: rgba(153, 69, 255, 0.35);
  --border-strong: rgba(0, 255, 255, 0.28);
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  --shadow-soft: 0 16px 40px rgba(0, 0, 0, 0.22);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shell: min(1200px, calc(100vw - 40px));
  --reading-progress: linear-gradient(90deg, var(--accent), var(--accent-2), var(--accent-3));
  --hero-glow: radial-gradient(circle at top right, rgba(255, 0, 255, 0.18), transparent 42%),
    radial-gradient(circle at bottom left, rgba(0, 212, 255, 0.16), transparent 38%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0));
  --grid-line: rgba(255, 255, 255, 0.05);
  --link: #71e6ff;
  --button-text: #14041f;
  --selection: rgba(255, 0, 255, 0.24);
  --hero-title: linear-gradient(135deg, #fff6ff 0%, #ff93f5 40%, #8aedff 100%);
  --card-highlight: linear-gradient(90deg, rgba(255, 0, 255, 0.4), rgba(0, 212, 255, 0.34), rgba(255, 107, 0, 0.34));
}

:root[data-theme="sugar-glaze"] {
  color-scheme: light;
  --bg: #fff8ff;
  --bg-elevated: rgba(255, 255, 255, 0.82);
  --bg-elevated-strong: rgba(251, 242, 255, 0.92);
  --surface: #fff7ff;
  --surface-soft: #f7edff;
  --text: #24103b;
  --muted: #5f4e7e;
  --muted-strong: #8a74af;
  --accent: #cc29d2;
  --accent-2: #0089d0;
  --accent-3: #e36a1d;
  --accent-4: #6d3ef5;
  --success: #00a186;
  --border: rgba(109, 62, 245, 0.16);
  --border-strong: rgba(0, 137, 208, 0.18);
  --shadow: 0 24px 80px rgba(52, 31, 79, 0.12);
  --shadow-soft: 0 16px 40px rgba(52, 31, 79, 0.08);
  --hero-glow: radial-gradient(circle at top right, rgba(204, 41, 210, 0.1), transparent 45%),
    radial-gradient(circle at bottom left, rgba(0, 137, 208, 0.1), transparent 38%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0.4));
  --grid-line: rgba(53, 18, 92, 0.05);
  --link: #005ea9;
  --button-text: #fff8ff;
  --selection: rgba(204, 41, 210, 0.16);
  --hero-title: linear-gradient(135deg, #24103b 0%, #b61ac9 45%, #0089d0 100%);
  --card-highlight: linear-gradient(90deg, rgba(204, 41, 210, 0.34), rgba(0, 137, 208, 0.24), rgba(227, 106, 29, 0.24));
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: 90px;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 0, 170, 0.14), transparent 22%),
    radial-gradient(circle at 88% 12%, rgba(0, 212, 255, 0.1), transparent 20%),
    radial-gradient(circle at 50% 0%, rgba(153, 69, 255, 0.14), transparent 40%),
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 92%, #000 8%), var(--bg));
  color: var(--text);
  line-height: 1.7;
  letter-spacing: -0.01em;
  min-height: 100vh;
  overflow-x: hidden;
}

::selection {
  background: var(--selection);
}

a {
  color: var(--link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a:focus-visible,
button:focus-visible,
.button:focus-visible,
.theme-toggle:focus-visible,
#toc a:focus-visible,
.sidebar-link-button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent-2) 58%, var(--accent) 42%);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent-2) 16%, transparent 84%);
  text-decoration: none;
}

code {
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.92em;
  background: color-mix(in srgb, var(--surface-soft) 80%, transparent 20%);
  border: 1px solid var(--border);
  padding: 0.16rem 0.42rem;
  border-radius: 10px;
}

.shell {
  width: var(--shell);
  margin: 0 auto;
}

.reading-progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 4px;
  z-index: 40;
  background: transparent;
}

.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--reading-progress);
  box-shadow: 0 0 24px rgba(255, 0, 255, 0.36);
}

.background-grid,
.background-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.background-grid {
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.48), transparent 90%);
}

.background-glow-a {
  background: radial-gradient(circle at 12% 14%, rgba(255, 0, 170, 0.18), transparent 30%);
}

.background-glow-b {
  background: radial-gradient(circle at 82% 20%, rgba(0, 212, 255, 0.15), transparent 22%);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 0 14px;
  backdrop-filter: blur(12px);
}

.site-header::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, var(--border-strong) 72%, transparent 28%) 14%,
    color-mix(in srgb, var(--border) 82%, transparent 18%) 86%,
    transparent 100%
  );
  z-index: -1;
}

.site-header::after {
  content: "";
  position: absolute;
  inset: -10px -20px auto;
  height: calc(100% + 18px);
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bg) 74%, transparent 26%) 0%,
    color-mix(in srgb, var(--bg) 48%, transparent 52%) 70%,
    transparent 100%
  );
  z-index: -2;
  pointer-events: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
  min-width: 0;
  flex: 0 1 auto;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: var(--button-text);
  box-shadow: 0 10px 28px rgba(255, 0, 170, 0.24);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 1rem;
  line-height: 1.05;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.2;
  margin-top: 4px;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
  margin-left: auto;
}

button,
.button {
  font: inherit;
}

.ghost-button,
.theme-toggle,
.button {
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 92%, transparent 8%);
  color: var(--text);
  border-radius: 999px;
  padding: 0.82rem 1.1rem;
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.ghost-button:hover,
.theme-toggle:hover,
.button:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent-2) 45%, var(--border) 55%);
  text-decoration: none;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.12);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
}

.button-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  color: var(--button-text);
  border-color: transparent;
  box-shadow: 0 14px 36px rgba(255, 0, 170, 0.18);
}

.button-secondary {
  background: color-mix(in srgb, var(--bg-elevated) 90%, transparent 10%);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle-track {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-2) 18%, transparent 82%);
}

.theme-toggle-label {
  font-size: 0.95rem;
}

.hero {
  position: relative;
  padding: 48px 0 18px;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 6px auto 2px 0;
  width: calc(100% - clamp(280px, 24vw, 340px) - 28px);
  border-radius: 32px;
  background: var(--hero-glow);
  border: 1px solid transparent;
  opacity: 0.72;
  z-index: -1;
}

.hero-copy,
.article-section,
.sidebar-card,
.site-footer {
  position: relative;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 96%, transparent 4%);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.hero-copy::before,
.article-section::before,
.sidebar-card::before,
.site-footer::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--card-highlight);
  opacity: 0.9;
  border-radius: inherit;
}

.hero-copy {
  border-radius: var(--radius-xl);
  padding: 30px 32px;
  max-width: 42rem;
}

.eyebrow,
.section-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
}

.hero h1 {
  font-size: clamp(2.4rem, 8vw, 4.8rem);
  line-height: 1.02;
  margin: 0;
  padding-bottom: 0.08em;
  letter-spacing: -0.05em;
  background: var(--hero-title);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-wrap: balance;
}

.subtitle {
  margin: 18px 0 0;
  font-size: clamp(1.05rem, 2.8vw, 1.2rem);
  color: color-mix(in srgb, var(--text) 92%, var(--muted) 8%);
  max-width: 42ch;
  text-wrap: balance;
}

.hero-actions,
.cta-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.publication-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-top: 18px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.publication-item {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  color: color-mix(in srgb, var(--text) 90%, var(--muted) 10%);
}

.publication-line #reading-time-pill {
  color: var(--muted);
}

.publication-line a {
  color: color-mix(in srgb, var(--text) 78%, var(--link) 22%);
  text-underline-offset: 0.16em;
}

.publication-line a:hover {
  color: var(--link);
}

.article blockquote {
  margin: 0;
  padding: 18px 20px;
  border-left: 3px solid color-mix(in srgb, var(--accent-2) 50%, var(--accent) 50%);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface-soft) 78%, transparent 22%);
  font-size: 1.08rem;
  color: color-mix(in srgb, var(--text) 94%, var(--muted) 6%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.content-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(280px, 340px);
  gap: 28px;
  align-items: start;
  padding: 14px 0 70px;
}

.article {
  display: grid;
  gap: 18px;
}

.article-section {
  border-radius: var(--radius-lg);
  padding: 28px 28px 30px;
  scroll-margin-top: 90px;
  overflow: hidden;
}

.section-lede {
  font-size: 1.08rem;
}

.section-lede::first-letter {
  float: left;
  font-size: 3rem;
  line-height: 0.9;
  padding-right: 0.12em;
  font-weight: 700;
  color: color-mix(in srgb, var(--accent-2) 60%, var(--accent) 40%);
}

.article-section h2,
.sidebar-card h2 {
  margin: 0 0 16px;
  font-size: clamp(1.45rem, 2.5vw, 2rem);
  line-height: 1.1;
  text-wrap: balance;
}

.article-section h2 {
  position: relative;
  padding-bottom: 14px;
}

.article-section h2::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 92px;
  height: 2px;
  background: var(--card-highlight);
  border-radius: 999px;
}

.article-section h3 {
  margin: 0 0 12px;
  font-size: 1.02rem;
}

.article-section p,
.article-section li,
.sidebar-card p {
  color: color-mix(in srgb, var(--text) 92%, var(--muted) 8%);
}

.article-section > p,
.article-section > blockquote,
.article-section > ul,
.article-section > ol {
  max-width: 68ch;
}

.article-section ul li::marker,
.article-section ol li::marker {
  color: color-mix(in srgb, var(--accent-2) 55%, var(--accent) 45%);
}

.article-section p:last-child,
.article-section ul:last-child,
.article-section ol:last-child {
  margin-bottom: 0;
}

.feature-list,
.numbered-list,
.article-section ul,
.article-section ol {
  padding-left: 1.15rem;
}

.feature-list.compact {
  columns: 2;
  column-gap: 28px;
}

.callout-grid,
.problem-solution-grid,
.split-panel {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.callout-card,
.problem-solution-grid article,
.split-panel article,
.mapping-card {
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-soft) 76%, transparent 24%);
  padding: 18px 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.callout-card.wide {
  margin-top: 18px;
}

.lead-figure {
  margin: 0;
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated) 95%, transparent 5%);
  box-shadow: var(--shadow-soft);
}

.lead-figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: calc(var(--radius-lg) - 8px);
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--surface-soft) 82%, transparent 18%);
}

.lead-figure figcaption {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.mapping-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.numbered-list {
  display: grid;
  gap: 14px;
}

.numbered-list li {
  padding-left: 6px;
}

.sidebar {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 18px;
}

.sidebar-card {
  border-radius: var(--radius-lg);
  padding: 22px;
}

.publication-card {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bg-elevated) 95%, transparent 5%),
    color-mix(in srgb, var(--surface-soft) 78%, transparent 22%)
  );
}

.support-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.sidebar-link-button {
  display: inline-flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0.82rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-soft) 80%, transparent 20%);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}

.sidebar-link-button:hover {
  text-decoration: none;
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.publication-note {
  margin-top: 14px !important;
  font-size: 0.96rem;
  color: var(--muted);
}

.principle-note {
  margin-top: 18px !important;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  color: color-mix(in srgb, var(--text) 90%, var(--muted) 10%);
}

.sidebar-header {
  margin-bottom: 10px;
}

#toc {
  display: grid;
  gap: 6px;
}

#toc a {
  display: block;
  padding: 0.7rem 0.82rem;
  border-radius: 12px;
  color: var(--muted);
  border: 1px solid transparent;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

#toc a:hover {
  text-decoration: none;
  color: var(--text);
  transform: translateX(2px);
}

#toc a.active {
  color: var(--text);
  background: color-mix(in srgb, var(--surface-soft) 84%, transparent 16%);
  border-color: var(--border-strong);
}

.sticky-note.soft {
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bg-elevated) 92%, transparent 8%),
    color-mix(in srgb, var(--surface-soft) 75%, transparent 25%)
  );
}

.cta-section {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-soft) 72%, transparent 28%), transparent),
    color-mix(in srgb, var(--bg-elevated) 96%, transparent 4%);
}

.site-footer {
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 28px 32px 36px;
  margin-bottom: 0;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-soft) 78%, transparent 22%), color-mix(in srgb, var(--bg-elevated) 96%, transparent 4%)),
    color-mix(in srgb, var(--bg-elevated) 96%, transparent 4%);
}

.site-footer p {
  margin: 0;
}

.footer-meta {
  margin-top: 8px !important;
  color: var(--muted);
  font-size: 0.94rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 18px);
  min-width: min(320px, calc(100vw - 32px));
  padding: 0.9rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-elevated-strong) 96%, transparent 4%);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  text-align: center;
  z-index: 50;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 420ms ease, transform 420ms ease;
}

.reveal.reveal-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .hero {
    padding: 40px 0 10px;
  }

  .hero::before {
    inset: 6px 0 0;
    width: auto;
  }

  .hero-copy {
    max-width: none;
  }

  .content-shell {
    grid-template-columns: 1fr;
    padding-top: 12px;
  }

  .sidebar {
    position: static;
    margin-top: 6px;
  }

  .toc-card {
    display: none;
  }

  .feature-list.compact {
    columns: 1;
  }
}

@media (max-width: 780px) {
  :root {
    --shell: min(100vw - 28px, 100%);
  }

  .background-glow-a,
  .background-glow-b {
    opacity: 0.7;
  }

  .site-header {
    gap: 12px;
    align-items: center;
    padding: 12px 0 8px;
  }

  .site-header::before {
    inset: 0 -8px 2px;
    height: auto;
    border-radius: 24px;
    background: color-mix(in srgb, var(--bg-elevated) 88%, transparent 12%);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
  }

  .site-header::after {
    display: none;
  }

  .brand {
    flex: 1 1 auto;
    min-width: 0;
  }

  .brand-copy {
    min-width: 0;
  }

  .brand strong {
    font-size: 0.98rem;
  }

  .brand small {
    font-size: 0.75rem;
  }

  .header-actions {
    flex: 0 0 auto;
    gap: 0;
    margin-left: 0;
  }

  .theme-toggle {
    min-width: 44px;
    min-height: 44px;
    gap: 0;
    padding: 0.72rem;
    justify-content: center;
  }

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

  .hero {
    padding-top: 24px;
  }

  .hero::before {
    opacity: 0.58;
  }

  .hero-copy,
  .article-section,
  .sidebar-card,
  .site-footer,
  .lead-figure {
    padding: 22px;
  }

  .hero-actions .button,
  .cta-actions .button,
  .sidebar-link-button {
    width: 100%;
    justify-content: center;
  }

  .subtitle {
    max-width: none;
    font-size: 1.08rem;
  }

  .article-section > p,
  .article-section > blockquote,
  .article-section > ul,
  .article-section > ol {
    max-width: none;
  }

  .article-section p,
  .article-section li {
    font-size: 1rem;
  }

  .callout-grid,
  .problem-solution-grid,
  .split-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .site-header {
    gap: 10px;
  }

  .site-header::before {
    inset: 0 -6px 2px;
  }

  .site-header::after {
    display: none;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .hero-copy,
  .article-section,
  .sidebar-card,
  .site-footer,
  .lead-figure {
    padding: 20px;
  }

  .hero h1 {
    font-size: clamp(2.4rem, 15vw, 3.2rem);
  }

  .subtitle {
    font-size: 1.05rem;
  }

  .publication-line {
    display: grid;
    gap: 6px;
  }

  .section-lede::first-letter {
    font-size: 2.4rem;
  }
}

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

  *,
  *::before,
  *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }
}
