/* Lesson page: the two-column theory/lab grid from index3.html, plus the
   callouts the Markdown directives compile into and the practice engine. */

.content-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 32px;
  align-items: start;
}

/* A grid track defaults to min-width: auto, so it refuses to shrink below its
   content's intrinsic width. One unshrinkable child — a textarea with
   white-space: pre, a wide table, a lab card — then widens the whole grid past
   the viewport, and a phone answers by zooming out. min-width: 0 lets the
   tracks actually honour the column definition, and the children scroll their
   own overflow instead. */
.content-grid > * { min-width: 0; }

@media (max-width: 1100px) {
  .content-grid { grid-template-columns: 1fr; }
}

/* ---------- theory side ---------- */

.theory-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

.section + .section { margin-top: 34px; padding-top: 30px; border-top: 1px solid var(--border); }

/* Sections rise in as the lesson opens, staggered so the eye is led down the
   page in reading order rather than hit with everything at once. */
.section, .practice {
  animation: rise-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.section:nth-child(1) { animation-delay: 0.02s; }
.section:nth-child(2) { animation-delay: 0.08s; }
.section:nth-child(3) { animation-delay: 0.14s; }
.section:nth-child(4) { animation-delay: 0.20s; }
.practice { animation-delay: 0.16s; }
.lab-card { animation: rise-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.06s backwards; }

@keyframes rise-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

/* The callouts get a gentle lift on hover — they are the parts worth
   re-reading, so they should feel touchable. */
.analogy-box, .insight, .callout-warn, .callout-try, .decoder {
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease;
}
.analogy-box:hover, .insight:hover, .callout-warn:hover, .callout-try:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.section-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-label .step {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
}
/* Each of the six parts gets its own accent so the rhythm of the lesson is
   visible at a glance. */
.section[data-key="intuition"] .section-label { color: var(--accent-3); }
.section[data-key="intuition"] .section-label .step { background: var(--accent-3-soft); }
.section[data-key="math"] .section-label { color: var(--accent-2); }
.section[data-key="math"] .section-label .step { background: var(--accent-2-soft); }
.section[data-key="recap"] .section-label { color: var(--accent-2); }
.section[data-key="recap"] .section-label .step { background: var(--accent-2-soft); }

.prose h3 { font-size: 17px; margin: 26px 0 10px; font-weight: 700; }
.prose h4 { font-size: 15.5px; margin: 22px 0 8px; font-weight: 700; }
.prose > :first-child { margin-top: 0; }
.prose p {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.75;
  margin: 0 0 14px;
}
.prose strong { color: var(--text); font-weight: 700; }
.prose em { color: var(--text); }
.prose ul, .prose ol { color: var(--text-dim); font-size: 15px; line-height: 1.75; padding-left: 22px; margin: 0 0 14px; }
.prose li { margin-bottom: 7px; }
.prose li::marker { color: var(--accent); font-weight: 700; }
.prose hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* Inline code doubles as the inline-math style from the prototype. */
.prose code {
  font-family: var(--font-mono);
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  color: var(--accent);
  font-weight: 500;
}
.prose pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
}
.prose pre code { background: none; color: var(--text); padding: 0; }

.prose blockquote {
  margin: 16px 0;
  padding: 2px 0 2px 16px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-dim);
  font-style: italic;
}

/* ---------- directive callouts ---------- */

.math-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin: 16px 0;
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: var(--text);
  overflow-x: auto;
  line-height: 1.9;
  white-space: pre-wrap;
}

.analogy-box {
  background: linear-gradient(135deg, var(--accent-3-soft), var(--accent-2-soft));
  border: 1px solid rgba(255, 138, 61, 0.2);
  border-radius: 14px;
  padding: 18px 20px;
  margin: 20px 0;
  font-size: 14.5px;
  color: var(--text);
  line-height: 1.7;
}
.analogy-box p { color: var(--text); font-size: 14.5px; }
.analogy-box > :last-child { margin-bottom: 0; }

.analogy-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-3);
  margin-bottom: 8px;
  font-weight: 700;
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 7px;
}
.analogy-label::before { content: '◆'; font-size: 9px; }

.insight {
  background: var(--accent-2-soft);
  border: 1px solid rgba(0, 184, 169, 0.2);
  border-radius: 14px;
  padding: 16px 20px;
  margin: 20px 0;
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
}
.insight p { color: var(--text); font-size: 14px; }
.insight > :last-child { margin-bottom: 0; }
.insight-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-2);
  margin-bottom: 8px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.callout-warn {
  background: #FFF9E6;
  border: 1px solid rgba(255, 138, 61, 0.28);
  border-left: 3px solid var(--accent-3);
  border-radius: 12px;
  padding: 15px 18px;
  margin: 18px 0;
  font-size: 14px;
  line-height: 1.7;
}
.callout-warn > :last-child { margin-bottom: 0; }
.callout-warn-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-3);
  margin-bottom: 6px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.callout-try {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  padding: 15px 18px;
  margin: 18px 0;
  font-size: 14px;
  line-height: 1.7;
}
.callout-try > :last-child { margin-bottom: 0; }
.callout-try-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 6px;
  font-weight: 700;
  font-family: var(--font-mono);
}

/* symbol decoder table */
.decoder {
  margin: 20px 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}
.decoder-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 11px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.decoder table, .prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.decoder th, .prose th {
  text-align: left;
  padding: 9px 16px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.decoder td, .prose td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-dim);
  vertical-align: top;
}
.decoder tr:last-child td, .prose tr:last-child td { border-bottom: none; }
.decoder td:first-child { font-family: var(--font-mono); color: var(--accent); font-weight: 600; white-space: nowrap; }

/* ---------- lab side ---------- */

/* Capped to the viewport so `sticky` genuinely pins the lab while the theory
   scrolls past it — a column taller than the screen would just scroll away. */
.lab-column {
  min-width: 0;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.lab-column::-webkit-scrollbar { width: 5px; }
.lab-column::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

@media (max-width: 1100px) {
  .lab-column { position: static; max-height: none; overflow: visible; }
}

.lab-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.lab-header {
  padding: 15px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.lab-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.lab-type { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }

/* Sized against the viewport so the sliders underneath stay above the fold —
   a lab whose controls you cannot see reads as a lab that does not work. */
.lab-canvas-wrap {
  position: relative;
  width: 100%;
  height: clamp(300px, 46vh, 520px);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(255, 77, 109, 0.05), transparent 60%),
    linear-gradient(180deg, #FDFDFB 0%, #F4F4F1 100%);
  cursor: crosshair;
  touch-action: none;
}
.lab-canvas-wrap canvas { display: block; width: 100%; height: 100%; }
.lab-canvas-wrap.grabbing { cursor: grabbing; }
.lab-canvas-wrap.dom { cursor: default; }

/* Labs that are DOM rather than canvas (tokenizer, attention grid) scroll
   inside the same frame.

   overflow-x matters as much as overflow-y: the attention grid needs about
   366px for its eleven columns, and .lab-card is overflow:hidden, so on a
   narrow phone the last columns were cut off with no way to reach them. */
.lab-canvas-wrap.dom {
  height: auto;
  min-height: 240px;
  max-height: 460px;
  overflow: auto;
  padding: 18px 20px;
  overscroll-behavior: contain;
}

.lab-overlay {
  position: absolute;
  top: 14px; left: 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 5;
  max-width: calc(100% - 28px);
  /* Two-line overlays wrap to five or six lines in a narrow frame and cover
     the top third of the drawing they are annotating. */
  max-height: calc(100% - 28px);
  overflow: hidden;
}
.lab-overlay .value { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.lab-overlay .value.teal { color: var(--accent-2); }
.lab-overlay .value.amber { color: var(--accent-3); }

/* Tabular figures throughout the lab: without them, every digit change nudges
   the layout sideways and a live readout becomes unreadable. */
.control-value, .lab-overlay { font-variant-numeric: tabular-nums; }

/* The thumb swells while you drag, so the control you are holding is obvious
   even when your cursor is over the chart. */
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.3); }
input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 4px rgba(255, 77, 109, 0.22);
}

.lab-controls {
  padding: 18px 22px;
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.control-row { display: flex; align-items: center; gap: 14px; }
.control-label {
  font-size: 12px;
  color: var(--text-dim);
  min-width: 62px;
  font-family: var(--font-mono);
  font-weight: 600;
}
.control-label .hint { display: block; font-size: 10px; color: var(--text-faint); font-weight: 500; }
.control-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  min-width: 48px;
  text-align: right;
  font-weight: 600;
  background: var(--bg);
  padding: 4px 8px;
  border-radius: 6px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  outline: none;
  border: 1px solid var(--border);
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(255, 77, 109, 0.4);
  transition: transform 0.15s ease;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 3px solid #fff;
}
input[type="range"].teal::-webkit-slider-thumb { background: var(--accent-2); box-shadow: 0 2px 6px rgba(0, 184, 169, 0.4); }
input[type="range"].teal::-moz-range-thumb { background: var(--accent-2); }
input[type="range"].amber::-webkit-slider-thumb { background: var(--accent-3); box-shadow: 0 2px 6px rgba(255, 138, 61, 0.4); }
input[type="range"].amber::-moz-range-thumb { background: var(--accent-3); }

.formula-input, .text-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.formula-input:focus, .text-input:focus { border-color: var(--accent); background: #fff; }
.formula-input.invalid { border-color: var(--accent); background: var(--accent-soft); }

.formula-error {
  font-size: 11.5px;
  color: var(--accent);
  font-family: var(--font-mono);
  margin-top: -6px;
}

.lab-try {
  padding: 14px 22px;
  background: var(--accent-3-soft);
  border-top: 1px solid rgba(255, 138, 61, 0.18);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
}
.lab-try b {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-3);
  margin-bottom: 4px;
}

.lab-fallback {
  padding: 40px 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

/* ---------- practice ---------- */

.practice { margin-top: 34px; padding-top: 30px; border-top: 1px solid var(--border); }

.practice-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.practice-head .section-label { margin-bottom: 0; }
.practice-score {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-faint);
}
.practice-score.done { color: var(--accent-2); }

.exercise {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 14px;
  background: var(--surface);
  transition: border-color 0.2s ease, background 0.2s ease;
}
.exercise.correct { border-color: rgba(0, 184, 169, 0.45); background: var(--accent-2-soft); }
.exercise.wrong { border-color: rgba(255, 77, 109, 0.45); background: var(--accent-soft); }

.exercise-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 12px;
}
.exercise-n {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  flex-shrink: 0;
}
.exercise-prompt { font-size: 14.5px; line-height: 1.65; color: var(--text); font-weight: 500; }
.exercise-prompt code {
  font-family: var(--font-mono);
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  color: var(--accent);
}

.choices { display: flex; flex-direction: column; gap: 8px; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-dim);
  transition: all 0.15s ease;
  text-align: left;
  font-family: var(--font-body);
  width: 100%;
}
.choice:hover:not(:disabled) { border-color: var(--border-strong); background: var(--bg); color: var(--text); }
.choice.picked { border-color: var(--accent); background: var(--accent-soft); color: var(--text); font-weight: 600; }
.choice.right { border-color: var(--accent-2); background: var(--accent-2-soft); color: var(--text); font-weight: 600; }
.choice.wrong { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.choice:disabled { cursor: default; }

.choice-key {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 5px;
  width: 20px; height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--bg);
}
.choice.picked .choice-key { border-color: var(--accent); color: var(--accent); }
.choice.right .choice-key { border-color: var(--accent-2); color: var(--accent-2); }

.numeric-row { display: flex; gap: 10px; align-items: center; }
.numeric-row .unit { font-family: var(--font-mono); font-size: 13px; color: var(--text-faint); }
.numeric-row .text-input { max-width: 180px; }

/* order exercise */
.order-list { display: flex; flex-direction: column; gap: 8px; }
.order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 14px;
  color: var(--text-dim);
  cursor: grab;
}
.order-item[aria-grabbed="true"] { opacity: 0.5; }
.order-item .grip { color: var(--text-faint); font-size: 14px; line-height: 1; cursor: grab; }
.order-item .pos {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  width: 18px;
  flex-shrink: 0;
}
.order-move {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.order-move button {
  width: 24px; height: 24px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 5px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1;
  padding: 0;
}
.order-move button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.order-move button:disabled { opacity: 0.35; cursor: not-allowed; }

.exercise-actions { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }

.feedback {
  margin-top: 13px;
  padding: 13px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.65;
  background: var(--surface);
  border: 1px solid var(--border);
}
.feedback .verdict {
  font-weight: 700;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.feedback.ok .verdict { color: var(--accent-2); }
.feedback.no .verdict { color: var(--accent); }
.feedback .explain { color: var(--text-dim); }
.feedback .reveal { margin-top: 7px; font-size: 13px; color: var(--text); }
.feedback .reveal b { font-family: var(--font-mono); color: var(--accent-2); }

.hint-text {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 8px;
  border: 1px dashed var(--border-strong);
}

/* ---------- lesson footer ---------- */

.lesson-footer {
  margin-top: 36px;
  padding: 26px 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}
.lesson-footer .done-note { font-size: 13.5px; color: var(--text-dim); }
.lesson-footer .done-note b { color: var(--accent-2); }
.lesson-footer .spacer { flex: 1; }

.notes-card { padding: 22px; }
.notes-card h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-faint);
  font-family: var(--font-mono);
  margin-bottom: 10px;
}
.notes-card textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  outline: none;
}
.notes-card textarea:focus { border-color: var(--accent); background: #fff; }
.notes-status { font-size: 11px; color: var(--text-faint); margin-top: 6px; font-family: var(--font-mono); }
