/* Lesson reading aids. Calm by design: no backdrop, no looping motion, one accent. */

.reading-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  pointer-events: none;
}
.reading-progress i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--acid));
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 0.12s linear;
}

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -6px 0 6px;
}
.lesson-meta .pill.is-done {
  color: var(--emerald-ink);
  background: var(--emerald-soft);
  border-color: color-mix(in srgb, var(--acid) 35%, transparent);
}

/* Sections: a numbered marker, a lead sentence, and short paragraphs. */
.lesson-section {
  margin: 44px 0;
  scroll-margin-top: 96px;
}
.lesson-section h2 {
  outline: none;
}
.section-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.section-num {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--primary-soft);
  border: 1px solid color-mix(in srgb, var(--green) 28%, transparent);
  color: var(--green);
  font: 600 12px var(--mono);
}
.lesson-section p + p {
  margin-top: 16px;
}
.lesson-section .lesson-lead {
  font-size: 18px;
  line-height: 1.7;
  font-weight: 500;
  color: var(--ink);
  padding-left: 16px;
  border-left: 3px solid var(--green);
  margin-bottom: 18px;
}
.lesson-section p:not(.lesson-lead) {
  color: color-mix(in srgb, var(--ink) 88%, var(--muted));
}

/* Glossary terms: a dotted underline that opens the definition. */
.term {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: help;
  text-decoration: underline dotted color-mix(in srgb, var(--green) 70%, transparent);
  text-decoration-thickness: 1.5px;
  text-underline-offset: 4px;
}
.term:hover,
.term[aria-expanded='true'] {
  color: var(--green);
  background: var(--primary-soft);
  border-radius: 3px;
}
.term-pop {
  position: fixed;
  z-index: 60;
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}
.term-pop strong {
  color: var(--ink);
  font-size: 15px;
}

/* Code: a dark card with a header and a copy button. */
.code-figure {
  margin: 22px 0 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--code-line);
  box-shadow: var(--shadow-md);
}
.code-figure figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px 8px 16px;
  background: var(--code-bar);
  color: var(--code-muted);
  font: 500 11px var(--mono);
  letter-spacing: 0.04em;
}
.code-figure figcaption span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.code-figure figcaption i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--code-name);
}
.copy-code {
  border: 1px solid #334155;
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--code-ink);
  font: 500 12px var(--sans);
  padding: 4px 10px;
}
.copy-code:hover {
  background: rgba(148, 163, 184, 0.18);
}
.code-figure pre {
  margin: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* A quiet invitation to write, after each section. */
.note-nudge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
  padding: 6px 12px 6px 10px;
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  background: none;
  color: var(--subtle);
  font-size: 13px;
  transition:
    color 0.15s,
    border-color 0.15s,
    background 0.15s;
}
.note-nudge svg {
  width: 15px;
  height: 15px;
}
.note-nudge:hover {
  color: var(--warning-ink);
  border-color: color-mix(in srgb, var(--orange) 50%, transparent);
  background: var(--warning-surface);
}

/* Aside: the section index, the notes card, then the stage. */
.lesson-aside {
  padding: 2px 0 12px;
}
.lesson-aside .lesson-toc h3 {
  margin-bottom: 8px;
}
.lesson-toc ol {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  position: relative;
}
.lesson-toc ol:before {
  content: '';
  position: absolute;
  left: 13px;
  top: 14px;
  bottom: 14px;
  width: 2px;
  background: var(--line);
}
.lesson-toc a {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 8px 6px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  border-radius: var(--radius-sm);
}
.lesson-toc a span {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 22px;
  border-radius: 6px;
  background: var(--white);
  border: 1px solid var(--line-strong);
  font: 600 10px var(--mono);
  color: var(--subtle);
  transition:
    background 0.2s,
    color 0.2s,
    border-color 0.2s;
}
.lesson-toc a:hover {
  color: var(--ink);
}
.lesson-toc a.is-read span {
  background: var(--emerald-soft);
  border-color: color-mix(in srgb, var(--acid) 45%, transparent);
  color: var(--emerald-ink);
}
.lesson-toc a.is-active {
  color: var(--ink);
  font-weight: 600;
}
.lesson-toc a.is-active span {
  background: var(--green);
  border-color: var(--green);
  color: var(--on-accent);
}

.notes-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin-bottom: 22px;
  padding: 14px;
  border: 1px solid color-mix(in srgb, var(--orange) 35%, var(--line));
  border-radius: var(--radius-lg);
  background: var(--warning-surface);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition:
    border-color 0.15s,
    box-shadow 0.15s,
    transform 0.15s;
}
.notes-toggle:hover,
.notes-toggle[aria-expanded='true'] {
  border-color: var(--orange);
  box-shadow: var(--shadow-md);
}
.notes-toggle:hover .notes-toggle-arrow {
  transform: translateX(3px);
}
.notes-toggle-text {
  flex: 1;
  min-width: 0;
}
.notes-toggle-text strong {
  display: block;
  font-size: 15px;
  font-weight: 600;
}
.notes-toggle-text small {
  display: block;
  font: 11px var(--mono);
  color: var(--muted);
  margin-top: 2px;
}
.notes-toggle-arrow {
  color: var(--warning-ink);
  font-size: 18px;
  transition: transform 0.15s;
}
.notes-toggle.has-notes .notes-icon {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 25%, transparent);
}
.notes-drawer header {
  display: flex;
  align-items: center;
  gap: 8px;
}
.notes-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--orange);
  color: #fff;
}
.notes-icon svg {
  width: 16px;
  height: 16px;
}
.notes-count {
  white-space: nowrap;
  font: 11px var(--mono);
  color: var(--muted);
}
.notes-prompt {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  margin: 4px 0 0;
}
.notes-next {
  border: 0;
  background: none;
  padding: 0;
  color: var(--warning-ink);
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.stage-heading {
  font: 600 11px var(--mono);
  letter-spacing: 0.07em;
  color: var(--subtle);
  margin-bottom: 8px;
}
.aside-note {
  font-size: 12px;
  margin-top: 18px;
}

/* The drawer: the same notes, reachable while reading anywhere in the lesson. */
.notes-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px 11px 13px;
  border: 1px solid color-mix(in srgb, var(--orange) 40%, transparent);
  border-radius: 999px;
  background: var(--white);
  color: var(--warning-ink);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.notes-fab svg {
  width: 18px;
  height: 18px;
}
.notes-fab.is-visible,
.notes-fab[aria-expanded='true'] {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.notes-fab.has-notes:after {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--orange);
}
.notes-drawer {
  position: fixed;
  top: 68px;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: min(400px, 100vw);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 22px;
  background: var(--white);
  border-left: 1px solid var(--line);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.22s ease;
}
.notes-drawer.is-open {
  transform: none;
}
.notes-drawer h2 {
  font-size: 20px;
  margin-right: auto;
}
.notes-drawer textarea {
  flex: 1;
  width: 100%;
  min-height: 200px;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(transparent 27px, color-mix(in srgb, var(--orange) 10%, transparent) 28px) 0
      6px / 100% 28px,
    var(--warning-surface);
  color: var(--ink);
  font-size: 15px;
  line-height: 28px;
  resize: none;
}
.notes-drawer textarea:focus-visible {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--orange) 22%, transparent);
}
.notes-drawer footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

@media (max-width: 900px) {
  .lesson-aside {
    max-height: none;
    overflow: visible;
  }
  .lesson-aside .lesson-toc,
  .lesson-aside .stage-heading {
    display: none;
  }
}
@media (max-width: 650px) {
  .lesson-section .lesson-lead {
    font-size: 16px;
  }
  /* Notes float just above the phone bar; the reading line runs along its top edge. */
  .notes-fab {
    right: 16px;
    bottom: calc(var(--phone-bar) + env(safe-area-inset-bottom) + 14px);
  }
  .reading-progress {
    position: fixed;
    bottom: calc(var(--phone-bar) + env(safe-area-inset-bottom));
    z-index: 36;
  }
  .lesson-section {
    scroll-margin-top: 16px;
  }
}

/* Lesson diagrams: static figures drawn from data (diagram.js). */
.lesson-diagram {
  margin: 28px 0 8px;
  padding: 20px 20px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background-color: var(--white);
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 20px 20px;
  box-shadow: var(--shadow-sm);
}
.lesson-diagram svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.lesson-diagram figcaption {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}
.dg-shape {
  stroke-width: 1.5;
}
.dg-shape.dg-muted {
  fill: var(--surface-raised);
  stroke: var(--line-strong);
}
.dg-shape.dg-primary {
  fill: var(--primary-soft);
  stroke: color-mix(in srgb, var(--green) 55%, transparent);
}
.dg-shape.dg-success {
  fill: var(--emerald-soft);
  stroke: color-mix(in srgb, var(--acid) 60%, transparent);
}
.dg-shape.dg-warning {
  fill: var(--warning-surface);
  stroke: color-mix(in srgb, var(--orange) 60%, transparent);
}
.dg-shape.dg-agent {
  fill: color-mix(in srgb, #8b5cf6 12%, var(--white));
  stroke: color-mix(in srgb, #8b5cf6 60%, transparent);
}
.dg-shape.dg-note {
  stroke-dasharray: 5 4;
}
.dg-shape.dg-out {
  opacity: 0.45;
}
.dg-db-rim,
.dg-table-rule {
  fill: none;
  stroke-width: 1.5;
}
.dg-db-rim.dg-muted,
.dg-table-rule.dg-muted {
  stroke: var(--line-strong);
}
.dg-db-rim.dg-primary,
.dg-table-rule.dg-primary {
  stroke: color-mix(in srgb, var(--green) 55%, transparent);
}
.dg-db-rim.dg-success,
.dg-table-rule.dg-success {
  stroke: color-mix(in srgb, var(--acid) 60%, transparent);
}
.dg-db-rim.dg-warning {
  stroke: color-mix(in srgb, var(--orange) 60%, transparent);
}
.lesson-diagram text {
  font-family: var(--sans);
}
.dg-node-label {
  font-size: 13px;
  font-weight: 600;
  fill: var(--ink);
  text-anchor: middle;
}
.dg-node-sub {
  font: 10.5px var(--mono);
  fill: var(--muted);
  text-anchor: middle;
}
.dg-row {
  font: 11px var(--mono);
  fill: var(--muted);
}
.dg-cell {
  font: 600 17px var(--mono);
  fill: var(--ink);
  text-anchor: middle;
}
.dg-edge {
  fill: none;
  stroke-width: 1.8;
}
.dg-edge.dg-dashed {
  stroke-dasharray: 6 5;
}
.dg-edge.dg-muted,
.dg-head.dg-muted {
  stroke: var(--subtle);
  fill: var(--subtle);
}
.dg-edge.dg-primary,
.dg-head.dg-primary {
  stroke: var(--green);
  fill: var(--green);
}
.dg-edge.dg-success,
.dg-head.dg-success {
  stroke: var(--acid);
  fill: var(--acid);
}
.dg-edge.dg-warning,
.dg-head.dg-warning {
  stroke: var(--orange);
  fill: var(--orange);
}
.dg-edge.dg-agent,
.dg-head.dg-agent {
  stroke: #8b5cf6;
  fill: #8b5cf6;
}
.dg-edge {
  fill: none !important;
}
.dg-head {
  stroke: none !important;
}
.dg-label-bg {
  fill: var(--white);
  opacity: 0.92;
}
.dg-edge-label {
  font: 500 10.5px var(--mono);
  text-anchor: middle;
}
.dg-muted-text {
  fill: var(--muted);
}
.dg-primary-text {
  fill: var(--green);
}
.dg-success-text {
  fill: var(--emerald-ink);
}
.dg-warning-text {
  fill: var(--warning-ink);
}
.dg-agent-text {
  fill: #7c3aed;
}
.dg-group {
  fill: none;
  stroke-width: 1.5;
  stroke-dasharray: 7 6;
}
.dg-group.dg-primary {
  stroke: color-mix(in srgb, var(--green) 45%, transparent);
}
.dg-group.dg-success {
  stroke: color-mix(in srgb, var(--acid) 55%, transparent);
}
.dg-group-label {
  font: 600 10.5px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.dg-lifeline {
  stroke: var(--line-strong);
  stroke-dasharray: 4 5;
}
.dg-row-label {
  font: 500 12px var(--mono);
  fill: var(--muted);
  text-anchor: end;
}
.dg-bar {
  stroke: none;
}
.dg-bar.dg-muted {
  fill: var(--surface-hover);
}
.dg-bar.dg-primary {
  fill: color-mix(in srgb, var(--green) 70%, transparent);
}
.dg-bar.dg-success {
  fill: color-mix(in srgb, var(--acid) 75%, transparent);
}
.dg-bar.dg-warning {
  fill: color-mix(in srgb, var(--orange) 75%, transparent);
}
.dg-bar.dg-agent {
  fill: color-mix(in srgb, #8b5cf6 70%, transparent);
}
.dg-bar-label {
  font: 600 10.5px var(--sans);
  fill: var(--ink);
  text-anchor: middle;
}
.dg-track {
  fill: var(--surface-raised);
  stroke: var(--line);
}
.dg-bar-value {
  font: 600 12px var(--mono);
}
.dg-axis {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 1.5;
}
.dg-axis-label {
  font: 11px var(--mono);
  fill: var(--muted);
  text-anchor: end;
}
.dg-axis-y {
  text-anchor: end;
}
.dg-marker {
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}
.dg-marker.dg-warning {
  stroke: var(--orange);
}
.dg-marker-label {
  font: 600 10.5px var(--mono);
  text-anchor: middle;
}
.dg-curve {
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
}
.dg-curve.dg-muted {
  stroke: var(--subtle);
}
.dg-curve.dg-primary {
  stroke: var(--green);
}
.dg-curve.dg-success {
  stroke: var(--acid);
}
.dg-curve.dg-warning {
  stroke: var(--orange);
}
.dg-curve-label {
  font: 600 12px var(--mono);
}
.dg-bracket {
  fill: none;
  stroke: var(--green);
  stroke-width: 1.5;
}
@media (max-width: 650px) {
  .lesson-diagram {
    padding: 12px 10px 10px;
    margin-inline: -4px;
  }
  /* Keep labels legible: the drawing scrolls sideways instead of shrinking. */
  .lesson-diagram svg {
    min-width: 540px;
  }
  .lesson-content {
    min-width: 0;
  }
}
