:root {
  color-scheme: light;
  --page: #f7f7fc;
  --surface: #fff;
  --ink: #172238;
  --muted: #38465c;
  --line: #b9c4d9;
  --accent: #4432a0;
  --note: #e9e8fa;
  --gradient: linear-gradient(115deg, #4832a1, #086678);
  --gradient-ink: linear-gradient(100deg, #4832a1, #07596a);
  --gradient-border: linear-gradient(135deg, #6650b4, #087b85);
  --gradient-footer: linear-gradient(115deg, #e9e8fa, #d8f0f0);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111728;
  --surface: #1c2540;
  --ink: #f5f7ff;
  --muted: #d0dbeb;
  --line: #647391;
  --accent: #c3bbff;
  --note: #283454;
  --gradient: linear-gradient(115deg, #38306f, #075262);
  --gradient-ink: linear-gradient(100deg, #e1c4ff, #8fe9e9);
  --gradient-border: linear-gradient(135deg, #a894f3, #6bdbdc);
  --gradient-footer: linear-gradient(115deg, #27244d, #163c49);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--page); color: var(--ink); font: 1rem/1.65 system-ui, sans-serif; }
img { display: block; max-width: 100%; height: auto; }
a { color: inherit; }
button { font: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.container { width: min(100% - 2rem, 1160px); margin-inline: auto; }
.skip-link { position: absolute; z-index: 5; top: -6rem; left: 1rem; min-height: 44px; padding: .6rem 1rem; background: var(--surface); color: var(--ink); }
.skip-link:focus { top: 1rem; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-inner { width: min(100% - 2rem, 1160px); min-height: 76px; margin: auto; display: flex; align-items: center; flex-wrap: wrap; gap: .5rem 1rem; padding-block: .7rem; }
.brand { font-size: 1.3rem; font-weight: 800; text-decoration: none; white-space: nowrap; }
.brand, .site-header nav a, .theme-toggle, .footer-inner a { display: inline-flex; align-items: center; min-height: 44px; }
.site-header nav { margin-left: auto; }
.site-header nav a { font-weight: 650; text-decoration: none; }
.site-header nav a:hover, .footer-inner a:hover { text-decoration: underline; }
.theme-toggle { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 2rem; padding: .5rem 1rem; cursor: pointer; }
.theme-toggle:hover { background: var(--note); }
.theme-icon { margin-right: .4rem; }
.eyebrow, .chapter-number { margin: 0; color: var(--accent); font-size: .8rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.16; }
h1, h2 { font-family: Georgia, serif; }

.home-hero { background: var(--gradient); color: #fff; padding-block: clamp(4rem, 10vw, 8rem); }
.home-hero .eyebrow { color: #fff; }
.home-hero h1 { max-width: 800px; margin: 1rem 0; font-size: clamp(2.8rem, 8vw, 6.5rem); }
.home-hero em { color: #ffe6b0; }
.home-hero p:not(.eyebrow) { max-width: 600px; font-size: clamp(1.1rem, 2vw, 1.35rem); }
.button-link { display: inline-flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 44px; padding: .8rem 1.2rem; background: #fff; color: #22234c; border-radius: .5rem; font-weight: 750; text-decoration: none; }
.button-link:hover { background: #e8f7f8; }
.chapters { padding-block: 4rem 6rem; }
.chapters h2, .chapter-content h1 { background: var(--gradient-ink); background-clip: text; -webkit-background-clip: text; color: transparent; }
.chapters h2 { font-size: clamp(2.2rem, 5vw, 4rem); margin: .5rem 0 2rem; }
.chapter-grid { display: grid; grid-template-columns: 1fr; gap: 1.4rem; }
.chapter-card { border: 2px solid transparent; border-radius: .9rem; background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--gradient-border) border-box; overflow: hidden; }
.chapter-card a { display: block; height: 100%; min-height: 44px; text-decoration: none; }
.chapter-card a:hover .card-cta { text-decoration: underline; }
.card-image img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.card-body { padding: 1.3rem; }
.card-body h3 { font: 1.6rem/1.2 Georgia, serif; margin: .6rem 0; }
.card-body p { color: var(--muted); }
.card-cta { display: block; border-top: 1px solid var(--line); padding-top: .7rem; color: var(--accent); font-weight: 750; }

.chapter-hero { margin: 0; background: var(--note); }
.chapter-hero img { width: 100%; height: auto; }
.chapter-content { width: min(100% - 2rem, 760px); margin: 3rem auto 4rem; }
.chapter-content h1 { font-size: clamp(2.5rem, 6vw, 5rem); margin: .75rem 0 1.5rem; }
.chapter-content .lead { font-size: clamp(1.15rem, 2vw, 1.4rem); }
.chapter-content section { margin-top: 2.5rem; }
.chapter-content h2 { font-size: clamp(1.7rem, 3vw, 2.3rem); margin-bottom: .7rem; }
.chapter-content section p { color: var(--muted); }
/* Enrichment cards use theme surfaces and borders in both color modes. */
.chapter-content .story-card, .chapter-content .example-card, .chapter-content .try-it-card {
  padding: clamp(1rem, 4vw, 1.5rem);
  border: 1px solid var(--line);
  border-radius: .8rem;
  background: var(--surface);
}
.chapter-content .story-card h2, .chapter-content .example-card h2, .chapter-content .try-it-card h2 {
  color: var(--accent);
}
.chapter-content .story-card p:last-child, .chapter-content .example-card p:last-child { margin-bottom: 0; }
.fun-fact { margin-top: 2.5rem; padding: 1.25rem 1.5rem; border-left: 4px solid var(--accent); background: var(--note); }
.fun-fact h2 { font-size: 1.4rem; }
.fun-fact p { margin: 0; color: var(--muted); }
.try-it-card ol { margin: 0; padding-left: 1.5rem; color: var(--muted); }
.try-it-card li { padding-left: .35rem; }
.try-it-card li + li { margin-top: .5rem; }
.detail-note { margin-top: 3rem; padding: 1.5rem; border-left: 4px solid var(--accent); background: var(--note); }
.detail-note h2 { font-size: 1.4rem; }
.detail-note p { margin: 0; }
.chapter-nav { display: grid; grid-template-columns: 1fr; gap: 1rem; padding-bottom: 5rem; }
.chapter-nav a { display: flex; flex-direction: column; justify-content: center; min-height: 88px; padding: 1rem; border: 2px solid transparent; border-radius: .7rem; background: linear-gradient(var(--surface), var(--surface)) padding-box, var(--gradient-border) border-box; text-decoration: none; }
.chapter-nav a:hover { background: var(--note); }
.chapter-nav span { color: var(--accent); font-weight: 750; }
.chapter-nav strong { font: 1.25rem/1.4 Georgia, serif; }
.site-footer { background: var(--gradient-footer); }
.footer-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem; min-height: 100px; padding-block: 1rem; }
.footer-inner span:first-child { font-weight: 800; }
.footer-inner a { text-decoration: none; }

@media (min-width: 600px) {
  .chapter-grid, .chapter-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chapter-nav a:last-child { text-align: right; }
}
@media (min-width: 920px) {
  .chapter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1250px) {
  .chapter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .chapters.container { width: min(100% - 2rem, 1400px); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
