/* Lesson pages */

/* SVG diagram text is positioned by x/y coordinates and never wraps on its own.
   Browsers default these <text> nodes to white-space:nowrap, which makes their
   reported scrollWidth exceed clientWidth even though nothing is visually
   clipped (overflow stays visible). Normalising white-space removes that false
   "clipped" signal without changing how the labels render. */
svg text { white-space: normal; }

.lesson-hero {
  padding: 56px 0 44px;
  border-bottom: 1px solid var(--rule);
  background:
    linear-gradient(180deg, transparent, var(--paper)),
    radial-gradient(ellipse 50% 60% at 85% 0%, color-mix(in oklch, var(--cyan-wash) 80%, transparent), transparent 70%);
}
.lesson-num {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--cyan-ink);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 16px;
}
.lesson-hero h1 {
  font-size: clamp(2.2rem, 5vw, 3.8rem);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.02;
}
.lesson-hero .subtitle {
  margin-top: 18px;
  font-size: 1.1rem;
  color: var(--ink-2);
  max-width: 640px;
  line-height: 1.55;
  font-family: var(--sans);
}
.lesson-hero .meta {
  margin-top: 22px;
  display: flex; gap: 20px; flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--ink-3);
  letter-spacing: 0.04em;
}
.lesson-hero .meta b { color: var(--ink); font-weight: 600; }

/* Section subnav — horizontal sticky strip below the topbar.
   Spans full container width so lesson content can use the whole column. */
.lesson-subnav {
  position: sticky;
  /* topbar is ~62px tall; sit flush beneath it */
  top: 62px;
  z-index: 30;
  margin: 0 -32px;
  padding: 0;
  background: color-mix(in oklch, var(--paper) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}
.lesson-subnav-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 32px;
  position: relative;
}
.lesson-subnav-inner::before,
.lesson-subnav-inner::after {
  content: '';
  position: absolute; top: 0; bottom: 0;
  width: 32px;
  pointer-events: none;
  z-index: 2;
}
.lesson-subnav-inner::before {
  left: 0;
  background: linear-gradient(to right, var(--paper), transparent);
}
.lesson-subnav-inner::after {
  right: 0;
  background: linear-gradient(to left, var(--paper), transparent);
}
.subnav-track {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-width: 100%;
  scroll-behavior: smooth;
  padding: 8px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.subnav-track::-webkit-scrollbar { display: none; }
.subnav-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink-3);
  text-decoration: none;
  white-space: nowrap;
  transition: color .15s, background .15s, border-color .15s;
}
.subnav-pill:hover {
  color: var(--ink);
  background: var(--paper-2);
  text-decoration: none;
}
.subnav-pill .n {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}
.subnav-pill .lbl {
  font-weight: 500;
}
.subnav-pill.active {
  color: var(--cyan-deep);
  background: var(--cyan-wash);
  border-color: color-mix(in oklch, var(--cyan) 35%, var(--rule));
}
.subnav-pill.active .n { color: var(--cyan-ink); }

@media (max-width: 720px) {
  .lesson-subnav { top: 56px; }
}

.lesson-body {
  display: block;
  padding: 36px 0 60px;
}
@media (max-width: 900px) { .lesson-body { padding: 24px 0 48px; } }

.lesson-content { max-width: 100%; }

/* Comparison tables can be wider than the mobile column — wrap them so
   they scroll horizontally inside their own box instead of widening the page. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
.table-scroll > table { min-width: 480px; }

/* On narrow screens, let comparison tables collapse to fit the column instead
   of forcing a 480px min-width (which pushes cells past the viewport). Cell text
   wraps and long unbreakable tokens break, so everything stays on-screen. */
@media (max-width: 640px) {
  .table-scroll > table { min-width: 0; }
  .table-scroll th,
  .table-scroll td {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
}

.lesson-sidebar {
  position: sticky; top: 80px;
  font-family: var(--mono);
  font-size: 0.8rem;
}
@media (max-width: 900px) { .lesson-sidebar { position: static; } }
.lesson-sidebar .toc-head {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 10px;
  font-weight: 600;
}
.lesson-sidebar ul { list-style: none; padding: 0; margin: 0; }
.lesson-sidebar li {
  margin: 2px 0;
}
.lesson-sidebar a {
  display: flex; gap: 10px;
  padding: 6px 10px;
  color: var(--ink-3);
  border-left: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  text-decoration: none;
  font-size: 0.82rem;
  line-height: 1.35;
}
.lesson-sidebar a .n { color: var(--ink-4); font-weight: 500; min-width: 24px; }
.lesson-sidebar a:hover { color: var(--ink); background: var(--paper-2); }
.lesson-sidebar a.active {
  color: var(--cyan-ink);
  border-left-color: var(--cyan);
  background: var(--cyan-wash);
}
.lesson-sidebar a.active .n { color: var(--cyan-ink); }

.lesson-content > section {
  padding: 24px 0 28px;
  border-bottom: 1px dashed var(--rule);
}
.lesson-content > section:last-child { border-bottom: 0; }
.lesson-content h2 {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(1.3rem, 2vw, 1.6rem);
  letter-spacing: -0.02em;
  margin-bottom: 18px;
}

/* footer nav */
.lesson-foot {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 32px;
  padding-top: 28px;
  border-top: 1px solid var(--rule);
}
@media (max-width: 640px) { .lesson-foot { grid-template-columns: 1fr; } }
.lesson-foot a {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  font-family: var(--mono);
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.lesson-foot a:hover {
  border-color: var(--cyan-ink);
  background: var(--cyan-wash);
  text-decoration: none;
  transform: translateY(-1px);
}
.lesson-foot .dir {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cyan-ink);
  font-weight: 600;
}
.lesson-foot .title { font-size: 0.95rem; font-weight: 600; }
.lesson-foot .next { text-align: right; align-items: flex-end; }

/* widgets — shared shell */
.w {
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  background: var(--paper);
  padding: 20px;
  margin: 18px 0;
  position: relative;
}
.w-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px;
}
.w-head .w-kind {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan-ink);
  font-weight: 700;
  padding: 3px 8px;
  background: var(--cyan-wash);
  border-radius: 4px;
}
.w-head .w-title {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}
.w-head .w-xp {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--ink-3);
}
.w-head .w-xp.earned { color: var(--ok); font-weight: 600; }

/* quiz */
.quiz-q { font-family: var(--sans); font-size: 0.98rem; color: var(--ink); line-height: 1.5; margin-bottom: 14px; }
.quiz-opts { display: flex; flex-direction: column; gap: 8px; }
.quiz-opt {
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--rule-2);
  background: var(--paper);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: var(--sans);
  line-height: 1.45;
  display: flex; align-items: flex-start; gap: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.quiz-opt:hover { border-color: var(--ink-3); }
.quiz-opt .letter {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-3);
  flex-shrink: 0;
  width: 20px;
}
.quiz-opt.correct {
  border-color: var(--ok);
  background: color-mix(in oklch, var(--ok) 8%, var(--paper));
}
.quiz-opt.correct .letter { color: var(--ok); }
.quiz-opt.wrong {
  border-color: var(--bad);
  background: color-mix(in oklch, var(--bad) 8%, var(--paper));
}
.quiz-opt.wrong .letter { color: var(--bad); }
.quiz-opt:disabled { cursor: default; }
.quiz-explanation {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--paper-2);
  border-left: 3px solid var(--cyan);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9rem;
  color: var(--ink-2);
  line-height: 1.55;
}
.quiz-explanation b { color: var(--ink); }


/* Flashcards */
.flashcards {
  position: relative;
}
.flash-stage {
  position: relative;
  min-height: 220px;
  perspective: 1200px;
}
.flashcard {
  position: relative;
  min-height: 220px;
  cursor: pointer;
  transition: transform 0.55s cubic-bezier(.2,.7,.2,1);
  transform-style: preserve-3d;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; gap: 14px;
  transition: box-shadow 0.15s;
}
.flashcard:hover .flashcard-face { box-shadow: var(--shadow-md); }
.flashcard-face.back { transform: rotateY(180deg); }
.flashcard-face .term {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cyan-ink);
  font-weight: 700;
}
.flashcard-face .q {
  font-family: var(--mono);
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  margin-top: 4px;
}
.flashcard-face .a {
  font-family: var(--sans);
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink-2);
  margin-top: 4px;
}
.flashcard-face .hint {
  margin-top: auto;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--ink-3);
}
.flash-ctrl {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px;
  gap: 10px;
}
.flash-ctrl .count {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink-3);
}

/* toast */
.toasts {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 999;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  background: var(--ink);
  color: oklch(0.95 0.005 240);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.82rem;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s cubic-bezier(.2,.7,.2,1);
  border-left: 3px solid var(--cyan);
}
.toast .xp { color: var(--cyan); font-weight: 700; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
