/* ==========================================================================
   Components — every lesson page is built only from these.
   See README.md → "Component cheat-sheet" for the HTML of each one.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Lesson hero (injected by layout.js into <div data-hero>)
   -------------------------------------------------------------------------- */

.lesson-hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  padding: var(--sp-7) var(--sp-6);
  margin-bottom: var(--sp-6);
  color: #fff;
  background:
    radial-gradient(600px 300px at 100% 0%, rgba(255, 255, 255, 0.22), transparent 60%),
    linear-gradient(135deg, var(--mod), var(--mod-2));
  box-shadow: 0 30px 60px -30px var(--mod);
  isolation: isolate;
}

.lesson-hero::after {
  content: attr(data-num);
  position: absolute;
  right: -10px;
  bottom: -60px;
  z-index: -1;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15rem;
  line-height: 1;
  color: rgba(255, 255, 255, 0.12);
  letter-spacing: -0.06em;
  pointer-events: none;
}

.hero-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: var(--sp-4);
}

.lesson-hero h1 {
  font-size: var(--fs-3xl);
  margin-bottom: var(--sp-3);
  max-width: 16ch;
  text-wrap: balance;
}

.content .lesson-hero p.hero-summary {
  color: rgba(255, 255, 255, 0.95);
}

.hero-summary {
  font-size: var(--fs-lg);
  max-width: 52ch;
  opacity: 0.94;
  margin-bottom: var(--sp-5);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 500;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(6px);
}

/* --------------------------------------------------------------------------
   "In one sentence" card
   -------------------------------------------------------------------------- */

.one-liner {
  position: relative;
  padding: var(--sp-6);
  margin-bottom: var(--sp-7);
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.one-liner::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
  background: linear-gradient(var(--mod), var(--mod-2));
}

.one-liner-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--mod);
  margin-bottom: var(--sp-3);
}

.one-liner .big {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 2.6vw, 1.7rem);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.015em;
  margin-bottom: var(--sp-4);
}

.analogy {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: var(--sp-4);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-muted);
  margin: 0;
}

.analogy > span:first-child {
  font-size: 1.6rem;
  line-height: 1;
}

/* --------------------------------------------------------------------------
   Sections
   -------------------------------------------------------------------------- */

.section {
  margin-bottom: var(--sp-8);
}

.section-head {
  margin-bottom: var(--sp-5);
}

.eyebrow {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--mod);
  margin-bottom: var(--sp-2);
}

.section-head h2 {
  font-size: var(--fs-2xl);
  margin-bottom: var(--sp-2);
}

.section-head p {
  color: var(--text-muted);
  margin: 0;
}

.content p,
.content li {
  color: var(--text-muted);
}
.content p strong,
.content li strong {
  color: var(--text);
}

/* Inline code */
.content :not(pre) > code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
  overflow-wrap: anywhere;
  word-break: break-word;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.82em;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 3px;
  background: var(--surface-2);
  color: var(--text);
}

/* --------------------------------------------------------------------------
   Why it matters
   -------------------------------------------------------------------------- */

.why-grid,
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
}

.why,
.mini-card {
  padding: var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease), border-color 0.25s;
}

.why:hover,
.mini-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--glow);
  border-color: color-mix(in srgb, var(--mod) 45%, var(--border));
}

.why-icon,
.mini-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  font-size: 1.4rem;
  background: color-mix(in srgb, var(--mod) 15%, transparent);
  margin-bottom: var(--sp-4);
}

.why h3,
.mini-card h3 {
  font-size: 1.05rem;
  margin-bottom: var(--sp-2);
}

.why p,
.mini-card p {
  font-size: var(--fs-sm);
  margin: 0;
}

.mini-card pre {
  margin-top: var(--sp-3);
}

/* --------------------------------------------------------------------------
   Steps
   -------------------------------------------------------------------------- */

.steps {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: step;
}

.step {
  position: relative;
  counter-increment: step;
  padding: 0 0 var(--sp-7) 64px;
  margin: 0 !important;
}

.step::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -4px;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: #fff;
  background: linear-gradient(135deg, var(--mod), var(--mod-2));
  box-shadow: 0 10px 22px -10px var(--mod);
}

.step::after {
  content: "";
  position: absolute;
  left: 21px;
  top: 48px;
  bottom: 8px;
  width: 2px;
  background: linear-gradient(color-mix(in srgb, var(--mod) 50%, transparent), transparent);
}

.step:last-child {
  padding-bottom: 0;
}
.step:last-child::after {
  display: none;
}

.step h3 {
  font-size: var(--fs-lg);
  padding-top: 6px;
}

/* --------------------------------------------------------------------------
   Code blocks (structure built by highlight.js)
   -------------------------------------------------------------------------- */

.content pre {
  margin: 0 0 var(--sp-5);
}

.code-block {
  margin: var(--sp-4) 0 var(--sp-5);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--code-bg);
  border: 1px solid #22284180;
  box-shadow: var(--shadow);
}

.code-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px 10px 8px 14px;
  background: var(--code-head);
  border-bottom: 1px solid #ffffff10;
}

.code-dots {
  display: flex;
  gap: 6px;
}
.code-dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff5f57;
}
.code-dots i:nth-child(2) {
  background: #febc2e;
}
.code-dots i:nth-child(3) {
  background: #28c840;
}

.code-file {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #aab3d6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7f89b3;
  padding: 3px 8px;
  border-radius: 6px;
  background: #ffffff0d;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid #ffffff1a;
  background: #ffffff0a;
  color: #cbd3f0;
  font-size: 0.76rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.copy-btn:hover {
  background: #ffffff18;
}
.copy-btn svg {
  width: 14px;
  height: 14px;
}
.copy-btn.copied {
  color: #4ade80;
  border-color: #4ade8055;
}

.code-block pre {
  margin: 0;
  padding: var(--sp-4) var(--sp-5);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.75;
  color: var(--code-text);
  tab-size: 4;
  scrollbar-width: thin;
  scrollbar-color: #343c5e transparent;
}

.code-block code {
  font-family: inherit;
  white-space: pre;
}

/* Highlighted lines: <code data-hl="3,5-7"> → .hl  */
.code-block .hl {
  display: inline-block;
  min-width: 100%;
  margin: 0 calc(-1 * var(--sp-5));
  padding: 0 var(--sp-5);
  background: color-mix(in srgb, var(--mod) 16%, transparent);
  box-shadow: inset 3px 0 0 var(--mod);
}

.tok-comment { color: var(--tok-comment); font-style: italic; }
.tok-keyword { color: var(--tok-keyword); }
.tok-string { color: var(--tok-string); }
.tok-number { color: var(--tok-number); }
.tok-variable { color: var(--tok-variable); }
.tok-class { color: var(--tok-class); }
.tok-function { color: var(--tok-function); }
.tok-tag { color: var(--tok-tag); }
.tok-attr { color: var(--tok-attr); }
.tok-directive { color: var(--tok-directive); font-weight: 500; }
.tok-operator { color: var(--tok-operator); }
.tok-builtin { color: var(--tok-builtin); }
.tok-prompt { color: #5b6590; user-select: none; }
.tok-output { color: #8f98bd; }

/* --------------------------------------------------------------------------
   Compare: ❌ Avoid / ✅ Do
   -------------------------------------------------------------------------- */

.compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.compare-card {
  min-width: 0;
  padding: var(--sp-5);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.compare-card.bad {
  background: linear-gradient(var(--bad-soft), var(--bad-soft)), var(--surface);
  border-color: color-mix(in srgb, var(--bad) 35%, var(--border));
}
.compare-card.good {
  background: linear-gradient(var(--ok-soft), var(--ok-soft)), var(--surface);
  border-color: color-mix(in srgb, var(--ok) 35%, var(--border));
}

.compare-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-3);
}
.bad .compare-label {
  color: var(--bad);
}
.good .compare-label {
  color: var(--ok);
}

.compare-card .code-block {
  margin-bottom: var(--sp-3);
}
.compare-card p:last-child {
  margin-bottom: 0;
}

/* --------------------------------------------------------------------------
   Callouts
   -------------------------------------------------------------------------- */

.callout {
  --c: var(--info);
  --c-soft: var(--info-soft);
  position: relative;
  padding: var(--sp-5);
  padding-left: calc(var(--sp-5) + 4px);
  margin: var(--sp-5) 0;
  border-radius: var(--radius);
  background: var(--c-soft);
  border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.callout::before {
  content: "";
  position: absolute;
  left: 0;
  top: 14px;
  bottom: 14px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--c);
}
.callout.tip {
  --c: var(--tip);
  --c-soft: var(--tip-soft);
}
.callout.warn {
  --c: var(--warn);
  --c-soft: var(--warn-soft);
}
.callout.try {
  --c: var(--ok);
  --c-soft: var(--ok-soft);
}

.callout-title {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--c);
  margin-bottom: var(--sp-2);
}

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

.callout .code-block {
  margin-bottom: var(--sp-3);
}

/* Big "Try it yourself" variant */
.callout.try.challenge {
  padding: var(--sp-6);
  border-style: dashed;
  border-width: 2px;
}
.callout.try.challenge .callout-title {
  font-size: var(--fs-lg);
}

/* --------------------------------------------------------------------------
   Key takeaways
   -------------------------------------------------------------------------- */

.takeaways {
  list-style: none;
  padding: var(--sp-5);
  margin: 0;
  display: grid;
  gap: var(--sp-3);
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}
.takeaways li {
  position: relative;
  margin: 0;
  padding-left: 38px;
  color: var(--text);
}
.takeaways li::before {
  content: "✓";
  position: absolute;
  left: 0;
  top: 1px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--ok), #10b981);
}

/* --------------------------------------------------------------------------
   Diagrams
   -------------------------------------------------------------------------- */

.diagram {
  margin: 0 0 var(--sp-5);
  padding: var(--sp-6) var(--sp-5);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 1px 1px, var(--border) 1px, transparent 0) 0 0 / 22px 22px,
    var(--surface);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.diagram figcaption {
  margin-top: var(--sp-5);
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-faint);
}

.diagram svg {
  margin: 0 auto;
  height: auto;
}

/* Flow: boxes joined by arrows */
.flow {
  display: flex;
  align-items: stretch;
  justify-content: center;
  flex-wrap: wrap;
  gap: 34px;
}

.flow-node {
  position: relative;
  flex: 1 1 120px;
  max-width: 190px;
  padding: var(--sp-4) var(--sp-3);
  border-radius: var(--radius);
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
}

.flow-node.accent {
  background: linear-gradient(135deg, var(--mod), var(--mod-2));
  border-color: transparent;
  color: #fff;
}
.flow-node.accent small {
  color: rgba(255, 255, 255, 0.85);
}

.flow-node + .flow-node::before {
  content: "→";
  position: absolute;
  left: -29px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--mod);
}

.flow-icon {
  display: block;
  font-size: 1.7rem;
  line-height: 1;
  margin-bottom: 8px;
}

.flow-node strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.98rem;
  color: inherit;
}

.flow-node small {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.flow.vertical {
  flex-direction: column;
  align-items: center;
}
.flow.vertical .flow-node {
  width: min(100%, 360px);
  max-width: 360px;
  flex: none;
}
.flow.vertical .flow-node + .flow-node::before {
  content: "↓";
  left: 50%;
  top: -31px;
  transform: translateX(-50%);
}

/* Layers: stacked labelled bands */
.layers {
  display: grid;
  gap: 10px;
}
.layer {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
}
.layer > span:first-child {
  font-size: 1.4rem;
}
.layer strong {
  font-family: var(--font-display);
  min-width: 130px;
}
.layer small {
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.layer:nth-child(odd) {
  border-left: 4px solid var(--mod);
}
.layer:nth-child(even) {
  border-left: 4px solid var(--mod-2);
}

/* Folder tree */
.tree {
  margin: 0 0 var(--sp-5) !important;
  padding: var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.8;
  color: var(--text);
  overflow-x: auto;
}
.tree .dir {
  color: var(--mod);
  font-weight: 600;
}
.tree .note {
  color: var(--text-faint);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Tables & glossary
   -------------------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  margin: 0 0 var(--sp-5);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.table-wrap th,
.table-wrap td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.table-wrap th {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  white-space: nowrap;
}

.table-wrap td {
  color: var(--text-muted);
}

.table-wrap tr:last-child td {
  border-bottom: 0;
}

.terms {
  display: grid;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
}
.terms > div {
  display: grid;
  grid-template-columns: minmax(120px, 190px) 1fr;
  gap: var(--sp-4);
  padding: var(--sp-4);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}
.terms dt {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--mod);
}
.terms dd {
  margin: 0;
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Quiz (built by quiz.js)
   -------------------------------------------------------------------------- */

.quiz {
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}

.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.quiz-head h3 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.quiz-score {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.quiz-bar {
  height: 4px;
  background: var(--surface-2);
}
.quiz-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--mod), var(--mod-2));
  transition: width 0.5s var(--ease);
}

.quiz-q {
  padding: var(--sp-5);
  border-bottom: 1px solid var(--border);
}

.quiz-q-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.06rem;
  color: var(--text);
  margin-bottom: var(--sp-4);
  display: flex;
  gap: 10px;
}

.quiz-q-num {
  flex: none;
  color: var(--mod);
}

.quiz-options {
  display: grid;
  gap: 10px;
}

.quiz-opt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.45;
  transition: border-color 0.15s, transform 0.15s var(--ease), background 0.15s;
}

.quiz-opt:not(:disabled):hover {
  border-color: var(--mod);
  transform: translateX(3px);
}

.quiz-opt:disabled {
  cursor: default;
}

.quiz-letter {
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-muted);
}

.quiz-opt.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}
.quiz-opt.correct .quiz-letter {
  background: var(--ok);
  color: #fff;
}
.quiz-opt.wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
  animation: shake 0.4s;
}
.quiz-opt.wrong .quiz-letter {
  background: var(--bad);
  color: #fff;
}
.quiz-opt.dim {
  opacity: 0.5;
}

.quiz-opt code {
  white-space: normal !important;
}

.quiz-explain {
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: 10px;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  background: var(--surface-2);
  animation: pop 0.35s var(--ease);
}
.quiz-explain strong.ok {
  color: var(--ok);
}
.quiz-explain strong.no {
  color: var(--bad);
}

.quiz-result {
  display: none;
  padding: var(--sp-6) var(--sp-5);
  text-align: center;
}
.quiz-result.show {
  display: block;
  animation: pop 0.45s var(--ease);
}
.quiz-result .big-emoji {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: var(--sp-3);
}
.quiz-result h3 {
  font-size: var(--fs-xl);
}
.quiz-result p {
  margin-bottom: var(--sp-4);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 12px;
  border: 0;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  color: #fff;
  background: linear-gradient(135deg, var(--mod), var(--mod-2));
  box-shadow: 0 12px 26px -12px var(--mod);
  transition: transform 0.2s var(--ease), box-shadow 0.2s;
}
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 30px -12px var(--mod);
}
.btn.ghost {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: none;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* --------------------------------------------------------------------------
   Pager (injected into <div data-pager>)
   -------------------------------------------------------------------------- */

.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
  margin-top: var(--sp-8);
}

.pager a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--sp-5);
  border-radius: var(--radius);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.25s var(--ease), border-color 0.25s, box-shadow 0.25s;
  min-width: 0;
}
.pager a:hover {
  transform: translateY(-3px);
  border-color: var(--pc, var(--mod));
  box-shadow: 0 18px 36px -20px var(--pc, var(--mod));
}
.pager small {
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-faint);
  font-weight: 600;
}
.pager strong {
  font-family: var(--font-display);
  font-size: 1.12rem;
}
.pager span {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.pager .next {
  text-align: right;
  grid-column: 2;
}

/* --------------------------------------------------------------------------
   Module overview (generated by layout.js into <div data-module-overview>)
   -------------------------------------------------------------------------- */

.overview-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--sp-4);
  margin-bottom: var(--sp-7);
}

.panel {
  padding: var(--sp-5);
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--border);
}
.panel h3 {
  display: flex;
  align-items: center;
  gap: 10px;
}
.panel ul {
  margin: 0;
}

.lesson-list {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--sp-7);
  display: grid;
  gap: var(--sp-3);
}
.lesson-list li {
  margin: 0;
}

.lesson-card {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-4) var(--sp-5);
  border-radius: var(--radius);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.25s var(--ease), border-color 0.25s, box-shadow 0.25s;
}
.lesson-card:hover {
  transform: translateX(6px);
  border-color: var(--mod);
  box-shadow: var(--glow);
}
.lesson-card .n {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--mod), var(--mod-2));
}
.lesson-card .t {
  flex: 1;
  min-width: 0;
}
.lesson-card strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.08rem;
}
.lesson-card span.s {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.lesson-card .time {
  flex: none;
  font-size: var(--fs-sm);
  color: var(--text-faint);
  white-space: nowrap;
}

.checklist {
  list-style: none;
  padding: 0;
  margin: 0;
}
.checklist li {
  position: relative;
  padding-left: 32px;
}
.checklist li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 2px solid var(--mod);
}

/* --------------------------------------------------------------------------
   Projects: milestones timeline
   -------------------------------------------------------------------------- */

.milestones {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--sp-5);
  counter-reset: ms;
}

.milestones > li {
  position: relative;
  counter-increment: ms;
  margin: 0 0 var(--sp-4) !important;
  padding: var(--sp-5) var(--sp-5) var(--sp-5) 76px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.milestones > li::before {
  content: counter(ms, decimal-leading-zero);
  position: absolute;
  left: var(--sp-5);
  top: var(--sp-5);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.6rem;
  line-height: 1;
  background: linear-gradient(135deg, var(--mod), var(--mod-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.milestones h3 {
  margin-bottom: var(--sp-2);
}

.milestones p:last-child {
  margin-bottom: 0;
}

.link-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: var(--sp-3);
}

.chip-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  transition: border-color 0.15s, background 0.15s;
}
.chip-link:hover {
  border-color: var(--mod);
  background: color-mix(in srgb, var(--mod) 12%, var(--surface-2));
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 760px) {
  .lesson-hero {
    padding: var(--sp-6) var(--sp-5);
  }
  .lesson-hero::after {
    font-size: 9rem;
    bottom: -30px;
  }
  .one-liner {
    padding: var(--sp-5);
  }
  .overview-grid {
    grid-template-columns: 1fr;
  }
  .flow:not(.vertical) {
    flex-direction: column;
    align-items: center;
  }
  .flow:not(.vertical) .flow-node {
    width: min(100%, 320px);
    max-width: 320px;
    flex: none;
  }
  .flow:not(.vertical) .flow-node + .flow-node::before {
    content: "↓";
    left: 50%;
    top: -31px;
    transform: translateX(-50%);
  }
  .terms > div {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .layer {
    flex-wrap: wrap;
    gap: 6px 12px;
  }
  .layer strong {
    min-width: 0;
  }
  .pager {
    grid-template-columns: 1fr;
  }
  .pager .next {
    grid-column: 1;
  }
  .step {
    padding-left: 0;
    padding-top: 58px;
  }
  .step::after {
    display: none;
  }
  .step h3 {
    padding-top: 0;
  }
  .milestones > li {
    padding: 64px var(--sp-4) var(--sp-4);
  }
  .milestones > li::before {
    left: var(--sp-4);
    top: var(--sp-4);
  }
  .code-block pre {
    padding: var(--sp-4);
  }
  .code-dots {
    display: none;
  }
  .lesson-card .time {
    display: none;
  }
}

/* ==========================================================================
   Neon glass finish (dark theme)
   ========================================================================== */

.one-liner,
.why,
.mini-card,
.compare-card,
.takeaways,
.quiz,
.panel,
.lesson-card,
.pager a,
.terms > div,
.table-wrap,
.milestones > li,
.diagram {
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}

:root:not([data-theme="light"]) .eyebrow,
:root:not([data-theme="light"]) .one-liner-label {
  text-shadow: 0 0 14px color-mix(in srgb, var(--mod) 70%, transparent);
}

:root:not([data-theme="light"]) .lesson-hero {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08), 0 0 60px -10px color-mix(in srgb, var(--mod) 70%, transparent);
}

:root:not([data-theme="light"]) .why:hover,
:root:not([data-theme="light"]) .mini-card:hover,
:root:not([data-theme="light"]) .lesson-card:hover {
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--mod) 60%, transparent), 0 0 30px -6px color-mix(in srgb, var(--mod) 65%, transparent);
}

:root:not([data-theme="light"]) .code-block {
  border-color: color-mix(in srgb, var(--mod) 28%, transparent);
  box-shadow: 0 0 40px -18px color-mix(in srgb, var(--mod) 70%, transparent);
}

:root:not([data-theme="light"]) .step::before,
:root:not([data-theme="light"]) .btn {
  box-shadow: 0 0 22px -4px color-mix(in srgb, var(--mod) 75%, transparent);
}

/* ==========================================================================
   Playful layer — plain-English components
   ========================================================================== */

/* 🧒 Simple version box (auto-injected under every lesson hero) */
.eli5 {
  position: relative;
  display: flex;
  gap: var(--sp-4);
  align-items: flex-start;
  padding: var(--sp-5);
  margin: calc(-1 * var(--sp-3)) 0 var(--sp-6);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(var(--bg), var(--bg)) padding-box,
    linear-gradient(120deg, #a855f7, #f472b6, #22d3ee) border-box;
  border: 2px solid transparent;
  box-shadow: 0 0 40px -18px #a855f7;
}
.eli5-face {
  flex: none;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  font-size: 1.8rem;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.25), rgba(34, 211, 238, 0.25));
  animation: wiggle 4s ease-in-out infinite;
}
.eli5-label {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--neon-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 4px;
}
.content .eli5 p {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.6;
  color: var(--text);
}
@keyframes wiggle {
  0%, 90%, 100% { transform: rotate(0); }
  93% { transform: rotate(-10deg); }
  96% { transform: rotate(10deg); }
}

/* 🏠 Real life ↔ 💻 Code */
.real-code {
  display: grid;
  grid-template-columns: minmax(0, 0.75fr) auto minmax(0, 1.25fr);
  align-items: stretch;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
}
.real-code > .side {
  min-width: 0;
  padding: var(--sp-5);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
.real-code > .side .code-block { margin-bottom: 0; }
.real-code > .side.real { border-top: 3px solid #fbbf24; }
.real-code > .side.code { border-top: 3px solid #22d3ee; }
.side-tag {
  display: inline-flex;
  gap: 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-sm);
  margin-bottom: var(--sp-3);
}
.real .side-tag { color: #fbbf24; }
.code .side-tag { color: #22d3ee; }
:root[data-theme="light"] .real .side-tag { color: #b45309; }
:root[data-theme="light"] .code .side-tag { color: #0e7490; }
.real-code > .equals {
  align-self: center;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--mod);
  text-shadow: var(--neon-glow);
}
.real-code .big-emoji {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: var(--sp-3);
}
.content .real-code p:last-child { margin-bottom: 0; }

/* 💬 Chat explainer */
.chat {
  display: grid;
  gap: var(--sp-3);
  margin: 0 0 var(--sp-5);
}
.msg {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-end;
  max-width: 88%;
}
.msg .avatar {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  border-radius: 50%;
  background: var(--surface-3);
}
.msg .bubble {
  padding: 12px 16px;
  border-radius: 18px 18px 18px 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  line-height: 1.55;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
}
.msg .bubble b { color: var(--mod); }
.msg.me {
  margin-left: auto;
  flex-direction: row-reverse;
}
.msg.me .bubble {
  border-radius: 18px 18px 4px 18px;
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, color-mix(in srgb, var(--mod) 80%, #000), color-mix(in srgb, var(--mod-2) 70%, #000));
}
.msg.me .bubble b { color: #fff; }
.msg .bubble code { white-space: normal !important; }

/* 🏛️ Pillars */
.pillars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--sp-4);
  margin: 0 0 var(--sp-5);
}
.pillar {
  --pc: var(--mod);
  position: relative;
  display: block;
  padding: var(--sp-5) var(--sp-4) var(--sp-4);
  border-radius: var(--radius-lg);
  text-decoration: none;
  text-align: center;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--pc) 45%, transparent);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  transition: transform 0.3s var(--ease), box-shadow 0.3s;
}
.pillar:hover {
  transform: translateY(-6px);
  box-shadow: 0 0 34px -8px var(--pc);
}
.pillar .p-icon {
  font-size: 2.6rem;
  line-height: 1;
  margin-bottom: var(--sp-3);
  display: block;
  filter: drop-shadow(0 0 12px color-mix(in srgb, var(--pc) 60%, transparent));
}
.pillar strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--pc);
}
.pillar small {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.45;
}
.pillar .p-num {
  position: absolute;
  top: 10px;
  right: 14px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* Big banner that opens each topic inside a long page */
.topic-banner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
  border-radius: var(--radius-lg);
  color: #fff;
  background: linear-gradient(120deg, var(--tc1, var(--mod)), var(--tc2, var(--mod-2)));
  box-shadow: 0 0 40px -14px var(--tc1, var(--mod));
}
.topic-banner .tb-icon {
  font-size: 2.6rem;
  line-height: 1;
}
.topic-banner h2 {
  margin: 0;
  font-size: var(--fs-2xl);
  color: #fff;
}
.content .topic-banner p {
  margin: 4px 0 0;
  color: rgba(255, 255, 255, 0.92);
}
.content .topic-banner code {
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
}

/* 🔁 Flip cards */
.flip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-4);
  margin: 0 0 var(--sp-5);
}
.flip-card {
  position: relative;
  min-height: 200px;
  perspective: 900px;
  cursor: pointer;
  border: 0;
  padding: 0;
  background: none;
  text-align: center;
  color: inherit;
}
.flip-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.6s var(--ease);
}
.flip-card.is-flipped .flip-inner {
  transform: rotateY(180deg);
}
.flip-front,
.flip-back {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: var(--sp-4);
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.flip-front {
  background: var(--surface);
  border: 1px solid var(--border-strong);
}
.flip-front .f-icon { font-size: 2.2rem; line-height: 1; }
.flip-front strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--text);
}
.flip-front small {
  font-size: 0.7rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.flip-back {
  transform: rotateY(180deg);
  color: #fff;
  background: linear-gradient(140deg, color-mix(in srgb, var(--mod) 85%, #000), color-mix(in srgb, var(--mod-2) 75%, #000));
  font-size: 0.9rem;
  line-height: 1.5;
}
.flip-back b { font-family: var(--font-display); font-size: 1rem; }
.content .flip-back code {
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  white-space: normal;
}
.flip-card:hover .flip-front {
  border-color: var(--mod);
  box-shadow: 0 0 24px -6px var(--mod);
}

/* HTTP method badges: <span class="m get">GET</span> */
.m {
  display: inline-block;
  min-width: 62px;
  padding: 2px 8px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  letter-spacing: 0.03em;
  color: #0a0720;
  vertical-align: 1px;
}
.m.get { background: #22d3ee; }
.m.post { background: #a3e635; }
.m.put { background: #fbbf24; }
.m.patch { background: #c084fc; }
.m.delete { background: #fb7185; }

/* Memory hook: "remember it like this" */
.memory {
  position: relative;
  padding: var(--sp-5) var(--sp-5) var(--sp-5) 70px;
  margin: var(--sp-5) 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.13), rgba(244, 114, 182, 0.09));
  border: 1px dashed rgba(251, 191, 36, 0.55);
}
.memory::before {
  content: "🧠";
  position: absolute;
  left: 20px;
  top: 18px;
  font-size: 1.8rem;
}
.memory-title {
  font-family: var(--font-display);
  font-weight: 700;
  color: #fbbf24;
  margin-bottom: 4px;
}
:root[data-theme="light"] .memory-title { color: #b45309; }
.content .memory p:last-child { margin-bottom: 0; }

/* ==========================================================================
   Live demos (built by demos.js)
   ========================================================================== */

.demo {
  margin: 0 0 var(--sp-6);
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--mod) 45%, transparent);
  box-shadow: 0 0 50px -24px var(--mod);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  overflow: hidden;
}
.demo-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, color-mix(in srgb, var(--mod) 20%, transparent), transparent);
  flex-wrap: wrap;
}
.demo-head strong {
  font-family: var(--font-display);
  font-size: 1.02rem;
}
.live-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #65a30d;
  background: rgba(163, 230, 53, 0.14);
}
:root:not([data-theme="light"]) .live-dot { color: #a3e635; }
.live-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a3e635;
  box-shadow: 0 0 8px #a3e635;
  animation: blinkdot 1.4s infinite;
}
@keyframes blinkdot { 50% { opacity: 0.3; } }
.demo-body {
  padding: var(--sp-5);
}
.content .demo-hint {
  font-size: var(--fs-sm);
  margin: 0 0 var(--sp-4);
}

.demo-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--sp-4);
}
.dbtn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 600;
  transition: transform 0.15s var(--ease), border-color 0.15s, box-shadow 0.15s;
}
.dbtn:hover {
  transform: translateY(-2px);
  border-color: var(--mod);
  box-shadow: 0 0 18px -6px var(--mod);
}
.dbtn.is-active {
  border-color: var(--mod);
  background: color-mix(in srgb, var(--mod) 24%, var(--surface-2));
}
.dbtn.danger:hover {
  border-color: #fb7185;
  box-shadow: 0 0 18px -6px #fb7185;
}
.dbtn.primary {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--mod), var(--mod-2));
}

.console {
  margin: 0;
  padding: 14px 18px;
  min-height: 70px;
  border-radius: var(--radius);
  background: var(--code-bg);
  border: 1px solid #ffffff12;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.7;
  color: var(--code-text);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}
.console .ok { color: #a3e635; }
.console .err { color: #fb7185; }
.console .dim { color: #6b7599; }
.console .hi { color: #22d3ee; }
.console .warn { color: #fbbf24; }
.console .flash { animation: flashline 0.8s; display: inline-block; }
@keyframes flashline {
  from { background: color-mix(in srgb, var(--mod) 40%, transparent); }
  to { background: transparent; }
}

/* API playground */
.pg-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--sp-4);
}
.pg-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.pg-reqline {
  display: flex;
  gap: 8px;
  margin-bottom: var(--sp-3);
}
.pg-reqline select,
.pg-reqline input,
.pg-body {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--code-text);
  background: var(--code-bg);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 10px;
  min-width: 0;
}
.pg-reqline select { flex: none; font-weight: 700; }
.pg-reqline input { flex: 1; }
.pg-body {
  display: block;
  width: 100%;
  min-height: 118px;
  resize: vertical;
  line-height: 1.6;
}
.pg-send {
  margin-top: var(--sp-3);
  width: 100%;
  justify-content: center;
}
.pg-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.pg-status.s2 { color: #65a30d; }
.pg-status.s4 { color: #d97706; }
:root:not([data-theme="light"]) .pg-status.s2 { color: #a3e635; }
:root:not([data-theme="light"]) .pg-status.s4 { color: #fbbf24; }
.pg-explain {
  margin-top: var(--sp-3);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: var(--fs-sm);
  color: var(--text);
  background: color-mix(in srgb, var(--mod) 12%, transparent);
  border-left: 3px solid var(--mod);
}
.pg-explain code { white-space: normal !important; }
.pg-table-wrap {
  margin-top: var(--sp-5);
  overflow-x: auto;
}
.pg-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}
.pg-table th,
.pg-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.pg-table th {
  color: var(--text-faint);
  font-weight: 600;
}
.pg-table td { color: var(--text); }
.pg-table tr.trashed td {
  color: var(--text-faint);
  text-decoration: line-through;
  text-decoration-color: #fb7185;
}
.pg-table tr.trashed td:last-child { text-decoration: none; color: #fb7185; }
.pg-table tr.changed td { animation: rowflash 1.4s; }
@keyframes rowflash {
  from { background: color-mix(in srgb, var(--mod) 40%, transparent); }
  to { background: transparent; }
}
.pg-table .nullv { color: #fb7185; font-style: italic; }

/* Side-by-side record comparison (PUT vs PATCH demo) */
.records {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-3);
}
.record {
  padding: var(--sp-4);
  border-radius: var(--radius);
  background: var(--code-bg);
  border: 1px solid #ffffff12;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--code-text);
}
.record h4 {
  font-family: var(--font-display);
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: #fff;
}
.record .k { color: #c4b5fd; }
.record .changed { color: #a3e635; font-weight: 700; }
.record .lost { color: #fb7185; font-weight: 700; }

/* Request journey */
.journey {
  display: grid;
  gap: 10px;
  margin-bottom: var(--sp-4);
}
.j-step {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  opacity: 0.45;
  transition: opacity 0.3s, border-color 0.3s, box-shadow 0.3s, transform 0.3s var(--ease);
}
.j-step .j-icon { font-size: 1.6rem; flex: none; }
.j-step .j-text { min-width: 0; }
.j-step strong { font-family: var(--font-display); display: block; }
.j-step small { color: var(--text-muted); display: block; line-height: 1.45; }
.j-step .j-code {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-faint);
  text-align: right;
}
.j-step.done { opacity: 0.85; }
.j-step.active {
  opacity: 1;
  border-color: var(--mod);
  box-shadow: 0 0 26px -8px var(--mod);
  transform: translateX(6px);
}

/* Responsive for the playful layer */
@media (max-width: 760px) {
  .real-code { grid-template-columns: minmax(0, 1fr); }
  .real-code > .equals { justify-self: center; transform: rotate(90deg); }
  .pg-grid { grid-template-columns: minmax(0, 1fr); }
  .msg { max-width: 100%; }
  .eli5 { flex-direction: column; }
  .j-step .j-code { display: none; }
  .topic-banner { flex-direction: column; align-items: flex-start; }
}

/* ==========================================================================
   Responsive hardening — every screen from 320px phones to 4K
   ========================================================================== */

.content,
.content p,
.content li,
.content td,
.content dd,
.bubble,
.flow-node,
.layer,
.mini-card,
.why,
.compare-card,
.callout,
.pillar,
.memory {
  overflow-wrap: break-word;
  min-width: 0;
}

.quiz-opt > span:last-child,
.lesson-card .t,
.pager a,
.j-step .j-text,
.layer > *,
.stop-card {
  min-width: 0;
  overflow-wrap: anywhere;
}

.content img,
.content svg,
.content video,
.content iframe {
  max-width: 100%;
  height: auto;
}

/* Tables: keep readable, scroll inside their card on small screens */
.table-wrap {
  -webkit-overflow-scrolling: touch;
}
.table-wrap table {
  min-width: 520px;
}
.table-wrap td code,
.table-wrap th code {
  white-space: nowrap;
}

/* Tablets */
@media (max-width: 1024px) {
  .lesson-hero h1 {
    max-width: none;
  }
}

/* Small phones */
@media (max-width: 480px) {
  :root {
    --fs-2xl: 1.6rem;
    --fs-xl: 1.3rem;
    --fs-3xl: clamp(1.8rem, 9vw, 2.3rem);
  }
  .lesson-hero {
    padding: var(--sp-5) var(--sp-4);
    border-radius: var(--radius);
  }
  .lesson-hero::after {
    font-size: 6.5rem;
    bottom: -18px;
    right: -6px;
  }
  .hero-summary {
    font-size: var(--fs-md);
  }
  .chip {
    font-size: 0.78rem;
    padding: 5px 10px;
  }
  .one-liner,
  .why,
  .mini-card,
  .compare-card,
  .panel,
  .demo-body,
  .takeaways {
    padding: var(--sp-4);
  }
  .callout {
    padding: var(--sp-4) var(--sp-4) var(--sp-4) calc(var(--sp-4) + 4px);
  }
  .diagram {
    padding: var(--sp-4) var(--sp-3);
  }
  .step {
    padding-top: 54px;
    padding-bottom: var(--sp-6);
  }
  .step::before {
    width: 40px;
    height: 40px;
  }
  .code-block pre {
    padding: var(--sp-3);
    font-size: 0.8rem;
  }
  .code-head {
    padding: 6px 8px 6px 10px;
    gap: 8px;
  }
  .code-lang {
    display: none;
  }
  .copy-btn span {
    display: none;
  }
  .quiz-q,
  .quiz-head {
    padding: var(--sp-4);
  }
  .quiz-opt {
    padding: 10px 12px;
    font-size: 0.9rem;
  }
  .eli5 {
    padding: var(--sp-4);
  }
  .eli5-face {
    width: 44px;
    height: 44px;
    font-size: 1.5rem;
  }
  .topic-banner {
    padding: var(--sp-4);
  }
  .topic-banner .tb-icon {
    font-size: 2rem;
  }
  .real-code > .side {
    padding: var(--sp-4);
  }
  .msg .avatar {
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
  }
  .msg .bubble {
    padding: 10px 13px;
    font-size: 0.95rem;
  }
  .flip-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-3);
  }
  .flip-card {
    min-height: 210px;
  }
  .flip-back {
    font-size: 0.8rem;
    padding: var(--sp-3);
  }
  .pillars {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--sp-3);
  }
  .pillar {
    padding: var(--sp-4) var(--sp-3) var(--sp-3);
  }
  .pillar .p-icon {
    font-size: 2rem;
  }
  .dbtn {
    padding: 8px 11px;
    font-size: 0.8rem;
  }
  .pg-reqline select {
    padding: 9px 6px;
  }
  .lesson-card {
    padding: var(--sp-3) var(--sp-4);
    gap: var(--sp-3);
  }
  .lesson-card .n {
    width: 40px;
    height: 40px;
  }
  .memory {
    padding: var(--sp-4) var(--sp-4) var(--sp-4) 56px;
  }
  .memory::before {
    left: 14px;
    font-size: 1.5rem;
  }
}

/* Very small phones (iPhone SE 1st gen, Galaxy Fold folded) */
@media (max-width: 360px) {
  .flip-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .flip-card {
    min-height: 170px;
  }
}

/* Large desktops and TVs: scale everything up a little */
@media (min-width: 1600px) {
  html {
    font-size: 17px;
  }
}
@media (min-width: 2200px) {
  html {
    font-size: 19px;
  }
  :root {
    --content-w: 58rem;
  }
}
@media (min-width: 3000px) {
  html {
    font-size: 22px;
  }
}

/* ==========================================================================
   Reading helpers: progress bar, back-to-top, "On this page" menu
   ========================================================================== */

.read-progress {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  right: 0;
  height: 3px;
  z-index: 60;
  pointer-events: none;
}
.read-progress span {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: 0 50%;
  transform: scaleX(0);
  background: linear-gradient(90deg, var(--mod), var(--brand-3, #f472b6), var(--mod-2));
  box-shadow: 0 0 12px var(--mod);
}

.to-top {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 45;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text);
  font-size: 1.2rem;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s var(--ease), border-color 0.2s, box-shadow 0.2s;
}
.to-top.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.to-top:hover {
  border-color: var(--mod);
  box-shadow: 0 0 20px -4px var(--mod);
}

.toc {
  display: none;
}

@media (min-width: 1400px) {
  body.has-toc .shell {
    padding-right: var(--toc-w);
  }
  .toc {
    display: block;
    position: fixed;
    top: calc(var(--topbar-h) + 28px);
    right: 0;
    width: var(--toc-w);
    max-height: calc(100vh - var(--topbar-h) - 56px);
    overflow-y: auto;
    padding: 0 var(--sp-5) 0 var(--sp-3);
    scrollbar-width: thin;
  }
  .toc-title {
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-faint);
    margin: 0 0 var(--sp-3) var(--sp-3);
  }
  .toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
    border-left: 1px solid var(--border);
  }
  .toc li {
    margin: 0;
  }
  .toc a {
    display: block;
    padding: 6px 12px;
    margin-left: -1px;
    border-left: 2px solid transparent;
    font-size: 0.84rem;
    line-height: 1.4;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s, border-color 0.15s;
  }
  .toc a:hover {
    color: var(--text);
  }
  .toc a.active {
    color: var(--text);
    font-weight: 600;
    border-left-color: var(--mod);
    text-shadow: var(--neon-glow);
  }
}
