:root {
  --ink: #0f172a;
  --ink-soft: #46536b;
  --ink-faint: #6b7891;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --line: #e5e8ef;
  --line-soft: #eef0f5;
  --surface: #ffffff;
  --page: #f6f7fb;

  /* code panel */
  --code-bg: #0d1424;
  --code-bg-2: #161e33;
  --code-line: #1f2a44;

  /* demo palette */
  --c1: #6366f1;
  --c2: #0ea5e9;
  --c3: #14b8a6;
  --c4: #f59e0b;
  --c5: #ec4899;
  --c6: #8b5cf6;

  --sidebar: 288px;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  letter-spacing: -0.02em;
  line-height: 1.2;
}

a {
  color: var(--accent);
}

.mono,
code {
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono",
    Menlo, monospace;
}

/* inline code inside prose */
.prose code {
  font-size: 0.88em;
  background: var(--accent-soft);
  color: #3730a3;
  padding: 0.12em 0.4em;
  border-radius: 5px;
  white-space: nowrap;
}

/* ---------------- Shell ---------------- */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  align-items: start;
}

/* ---------------- Sidebar ---------------- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 26px 18px 60px;
}

.brand {
  display: block;
  text-decoration: none;
  color: inherit;
  padding: 0 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 18px;
}

.brand__name {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.brand__sub {
  font-size: 12.5px;
  color: var(--ink-faint);
}

.nav__group + .nav__group {
  margin-top: 22px;
}

.nav__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  padding: 0 10px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.nav__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--c1);
}

.nav__group--grid .nav__dot {
  background: var(--c3);
}

.nav__group--anim .nav__dot {
  background: var(--c5);
}

.nav__group--adv .nav__dot {
  background: var(--c6);
}

.nav__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav__link {
  display: block;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--ink-soft);
  text-decoration: none;
  border-left: 2px solid transparent;
}

.nav__link:hover {
  background: var(--page);
  color: var(--ink);
}

.nav__link.is-active {
  background: var(--accent-soft);
  color: #3730a3;
  font-weight: 600;
}

/* ---------------- Main ---------------- */

.main {
  min-width: 0;
  padding: 0 40px 120px;
}

.hero {
  max-width: 780px;
  margin: 0 auto;
  padding: 72px 0 40px;
  text-align: center;
}

.hero__eyebrow {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
}

.hero h1 {
  margin: 0 0 18px;
  font-size: clamp(32px, 5vw, 46px);
}

.hero p {
  margin: 0 auto;
  max-width: 62ch;
  font-size: 17.5px;
  color: var(--ink-soft);
}

.hero__legend {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.chip {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
}

/* course banner */

.course-banner {
  max-width: 1080px;
  margin: 56px auto 0;
  padding: 30px 34px;
  border-radius: var(--radius);
  color: #fff;
  background: linear-gradient(120deg, #4f46e5, #7c3aed 55%, #2563eb);
}

.course-banner--grid {
  background: linear-gradient(120deg, #0d9488, #0ea5e9 55%, #4f46e5);
}

.course-banner--anim {
  background: linear-gradient(120deg, #db2777, #f59e0b 55%, #8b5cf6);
}

.course-banner--adv {
  background: linear-gradient(120deg, #0f172a, #6d28d9 52%, #0891b2);
}

.course-banner__label {
  margin: 0 0 8px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.85;
}

.course-banner h2 {
  margin: 0 0 10px;
  font-size: 27px;
}

.course-banner p {
  margin: 0;
  max-width: 70ch;
  font-size: 15.5px;
  opacity: 0.92;
}

/* ---------------- Section ---------------- */

.section {
  max-width: 1080px;
  margin: 0 auto;
  padding-top: 56px;
}

.section__head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--line);
}

.section__num {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
}

.section__head h3 {
  margin: 0;
  font-size: 23px;
}

.section__intro {
  margin: 14px 0 0;
  max-width: 78ch;
  color: var(--ink-soft);
  font-size: 15.5px;
}

/* ---------------- Topic ---------------- */

.topic {
  margin-top: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  scroll-margin-top: 20px;
}

.topic__head {
  padding: 22px 26px 18px;
}

.topic__title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 18.5px;
}

.topic__badge {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  color: #3730a3;
  background: var(--accent-soft);
  border: 1px solid #dcdffb;
  border-radius: 6px;
  padding: 3px 8px;
}

.prose {
  margin: 0;
  max-width: 82ch;
  color: var(--ink-soft);
  font-size: 15.5px;
}

.prose + .prose {
  margin-top: 10px;
}

.prose strong {
  color: var(--ink);
  font-weight: 600;
}

/* note callout */
.note {
  display: flex;
  gap: 10px;
  margin: 16px 26px 0;
  padding: 12px 15px;
  border-radius: 10px;
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #78431a;
  font-size: 14.5px;
}

.note--tip {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: #166534;
}

.note__icon {
  flex: none;
  font-weight: 700;
}

/* ---------------- Split: code + demo ---------------- */

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1px;
  margin-top: 18px;
  background: var(--line);
  border-top: 1px solid var(--line);
}

.split--stacked {
  grid-template-columns: minmax(0, 1fr);
}

.pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.pane__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 16px;
  background: #fafbfd;
  border-bottom: 1px solid var(--line-soft);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------------- Code ---------------- */

.code {
  margin: 0;
  padding: 16px 18px;
  background: var(--code-bg);
  color: #c8d3e8;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.75;
  overflow-x: auto;
  tab-size: 2;
}

.code + .code {
  border-top: 1px solid var(--code-line);
}

/* let the last block fill the pane so both columns end level */
.code:last-child {
  flex: 1;
}

.code__label {
  display: block;
  margin: -4px 0 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5d6b8a;
}

/* token colours */
.t-comment   { color: #64748b; font-style: italic; }
.t-sel-class { color: #fbbf72; }
.t-sel-id    { color: #fbbf72; }
.t-sel-el    { color: #7ee787; }
.t-sel-pseudo{ color: #c4b5fd; }
.t-sel-attr  { color: #fbbf72; }
.t-at        { color: #ff8a80; }
.t-prop      { color: #7cc4ff; }
.t-val       { color: #a5d6ff; }
.t-num       { color: #ffd479; }
.t-func      { color: #d2a8ff; }
.t-str       { color: #a5d6ff; }
.t-punct     { color: #8494b0; }
.t-tag       { color: #7ee787; }
.t-attr      { color: #fbbf72; }
.t-text      { color: #c8d3e8; }
.t-kw        { color: #ff8a80; }

/* ---------------- Demo stage ---------------- */

.stage {
  flex: 1;
  padding: 22px;
  background-color: #fbfcfe;
  background-image: radial-gradient(#dfe4ee 1px, transparent 1px);
  background-size: 14px 14px;
}

.stage .container {
  border: 1px dashed #a5b0c6;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  padding: 12px;
}

.stage .box {
  display: grid;
  place-items: center;
  min-width: 34px;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 7px;
  background: var(--c1);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  font-family: "JetBrains Mono", Consolas, monospace;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18);
}

.stage .box:nth-child(6n + 2) { background: var(--c2); }
.stage .box:nth-child(6n + 3) { background: var(--c3); }
.stage .box:nth-child(6n + 4) { background: var(--c4); }
.stage .box:nth-child(6n + 5) { background: var(--c5); }
.stage .box:nth-child(6n + 6) { background: var(--c6); }

.stage .box--ghost {
  background: #f1f5f9;
  color: #64748b;
  border: 1px dashed #cbd5e1;
  box-shadow: none;
}

/* generic labelled surfaces used by layout demos */
.stage .zone {
  display: grid;
  place-items: center;
  padding: 14px 10px;
  border-radius: 7px;
  background: #e6eaf5;
  color: #43506b;
  font-size: 12.5px;
  font-weight: 600;
  font-family: "JetBrains Mono", Consolas, monospace;
}

.stage .zone--head { background: #c7d2fe; color: #312e81; }
.stage .zone--nav  { background: #bae6fd; color: #075985; }
.stage .zone--main { background: #fff; border: 1px solid #dbe2ef; }
.stage .zone--side { background: #ccfbf1; color: #115e59; }
.stage .zone--foot { background: #e2e8f0; color: #475569; }

/* axis annotation */
.stage .axis {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
  font-family: "JetBrains Mono", Consolas, monospace;
}

.stage .axis__line {
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, #94a3b8, #cbd5e1);
  position: relative;
}

.stage .axis__line::after {
  content: "";
  position: absolute;
  right: 0;
  top: -3px;
  border-left: 7px solid #94a3b8;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
}

.caption {
  margin: 0;
  padding: 11px 18px 14px;
  font-size: 12.5px;
  color: var(--ink-faint);
  text-align: center;
  border-top: 1px solid var(--line-soft);
  background: var(--surface);
}

/* side-by-side comparison inside one stage */
.stage .compare {
  display: grid;
  gap: 14px;
}

.stage .compare > figure {
  margin: 0;
}

.stage .compare figcaption {
  margin-bottom: 6px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11.5px;
  font-weight: 600;
  color: #475569;
}

/* ---- shared scaffolding for the animation demos ---- */

/* a lane that shows how far something has travelled */
.stage .track {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 46px;
  padding: 6px;
  border: 1px dashed #a5b0c6;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
}

.stage .track + .track {
  margin-top: 8px;
}

/* demo contents keep their own size inside the lane */
.stage .track > :not(.track__name) {
  flex: none;
}

.stage .track--center { justify-content: center; }
.stage .track--bottom { align-items: flex-end; min-height: 94px; }
.stage .track--tall   { min-height: 130px; }
.stage .track--gap    { gap: 10px; }

/* generic vertical stack for multi-part demos */
.stage .demo {
  display: grid;
  gap: 10px;
}

.stage .track__name {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11px;
  color: #94a3b8;
  pointer-events: none;
}

/* the thing that moves */
.stage .puck {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--c1);
  color: #fff;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.18);
}

.stage .puck--2 { background: var(--c2); }
.stage .puck--3 { background: var(--c3); }
.stage .puck--4 { background: var(--c4); }
.stage .puck--5 { background: var(--c5); }
.stage .puck--6 { background: var(--c6); }

/* scrollable region for scroll-driven animation demos */
.stage .scroller {
  height: 190px;
  overflow-y: auto;
  padding: 10px;
  border: 1px dashed #a5b0c6;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
}

.stage .filler {
  display: grid;
  place-items: center;
  height: 150px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: #eef2f8;
  color: #8894ab;
  font-size: 12px;
}

.stage .hint {
  margin: 0 0 8px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11px;
  color: #8894ab;
}

/* ---- shared scaffolding for the advanced CSS demos ---- */

.stage .row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.stage .stack {
  display: grid;
  gap: 10px;
}

.stage .panel {
  padding: 14px 16px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e2e8f2;
}

.stage .copy {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: #43506b;
}

.stage .label {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11px;
  color: #8894ab;
}

/* colour demos: a strip of labelled chips */
.stage .swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stage .swatch {
  display: grid;
  align-content: end;
  min-width: 68px;
  height: 58px;
  padding: 7px;
  border-radius: 8px;
  background: #e2e8f0;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 10.5px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(15, 23, 42, 0.45);
}

/* stands in for an image without loading one */
.stage .thumb {
  display: grid;
  place-items: center;
  height: 64px;
  border-radius: 8px;
  background: linear-gradient(135deg, #c7d2fe, #a5f3fc);
  color: #3730a3;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11px;
}

.stage .field {
  display: grid;
  gap: 5px;
}

.stage input,
.stage textarea,
.stage select {
  font: inherit;
  font-size: 13px;
  padding: 6px 9px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: inherit;
}

/* horizontal counterpart of .scroller, for scroll-snap demos */
.stage .scroller--x {
  height: auto;
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ---------------- Controls ---------------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: #fafbfd;
  border-bottom: 1px solid var(--line-soft);
}

.controls__label {
  margin-right: 4px;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--ink-faint);
}

.ctrl {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 4px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.ctrl:hover {
  border-color: #b8bdf3;
  color: var(--accent);
}

.ctrl.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ctrl--action {
  font-weight: 600;
  color: #3730a3;
  background: var(--accent-soft);
  border-color: #dcdffb;
}

.ctrl:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------- Reference table ---------------- */

.table-wrap {
  margin: 0;
  padding: 4px 26px 22px;
  overflow-x: auto;
}

table.ref {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
}

table.ref th,
table.ref td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

table.ref th {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom: 1px solid var(--line);
}

table.ref td:first-child {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
  color: #3730a3;
  white-space: nowrap;
}

/* ---------------- Checklist ---------------- */

.checklist {
  margin: 0;
  padding: 0 26px 22px 26px;
  list-style: none;
}

.checklist li {
  position: relative;
  padding: 7px 0 7px 30px;
  color: var(--ink-soft);
  font-size: 15px;
  border-bottom: 1px solid var(--line-soft);
}

.checklist li:last-child {
  border-bottom: 0;
}

.checklist li::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 15px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.55;
}

/* ---------------- Top bar (mobile) ---------------- */

.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 20;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar__btn {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

/* ---------------- Responsive ---------------- */

@media screen and (max-width: 1080px) {
  .split {
    grid-template-columns: minmax(0, 1fr);
  }
}

/*
 * Respect the user's motion preference for the guide's own chrome.
 * The lesson demos are deliberately left alone: switching them off would
 * remove the thing being taught.
 */
@media (prefers-reduced-motion: reduce) {
  .btn,
  .ctrl,
  .nav__link,
  .sidebar,
  .item__title,
  .chevron {
    transition: none;
  }
}

/* ---------------- Print ---------------- */

@page {
  size: A4;
  margin: 12mm 10mm;
}

@media print {
  .sidebar,
  .topbar,
  .controls,
  .pane__bar .ctrl {
    display: none;
  }

  body {
    background: #fff;
    font-size: 9.5pt;
    line-height: 1.45;
  }

  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .main {
    padding: 0;
  }

  .hero {
    padding: 0 0 16pt;
  }

  .hero h1 {
    font-size: 24pt;
  }

  .hero p {
    font-size: 10.5pt;
  }

  .course-banner,
  .section,
  .topic {
    max-width: none;
  }

  /* keep gradients and dark code panels in the export */
  .course-banner,
  .code,
  .stage,
  .stage .box,
  .stage .zone,
  .note,
  .topic__badge {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .course-banner {
    break-before: page;
    padding: 16pt 18pt;
  }

  .section {
    padding-top: 18pt;
  }

  .section__head h3 {
    font-size: 14pt;
  }

  .topic {
    margin-top: 12pt;
  }

  /* keep a heading with its code, and never split a panel down the middle */
  .topic__head,
  .pane__bar {
    break-after: avoid;
  }

  .code,
  .stage,
  .note,
  .caption {
    break-inside: avoid;
  }

  .topic__head {
    padding: 12pt 14pt 10pt;
  }

  .topic__title {
    font-size: 12pt;
  }

  .prose {
    font-size: 9.5pt;
  }

  .code {
    padding: 9pt 11pt;
    font-size: 7.5pt;
    line-height: 1.55;
    overflow: hidden;
    white-space: pre-wrap;
  }

  .stage {
    padding: 12pt;
  }

  /* code above result reads better than two narrow columns on paper */
  .split {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
  }

  /* plain block flow paginates cleanly; stretched flex panes leave empty boxes */
  .pane {
    display: block;
  }

  /* the divider colour would otherwise fill the gap left by a page break */
  .split {
    background: transparent;
    border-top-color: var(--line-soft);
  }

  .code:last-child,
  .stage {
    flex: none;
  }
}

@media screen and (max-width: 860px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    display: flex;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.18);
  }

  .sidebar.is-open {
    transform: none;
  }

  .main {
    padding: 0 18px 90px;
  }

  .hero {
    padding: 36px 0 24px;
  }

  .course-banner {
    padding: 22px;
  }

  .topic__head,
  .table-wrap,
  .checklist {
    padding-left: 18px;
    padding-right: 18px;
  }

  .note {
    margin-left: 18px;
    margin-right: 18px;
  }
}
