/* ==========================================================================
   Flowytales Visual STEM Reader — Layout, Dual-Theme SVG Tokens & Infographics
   - Visual Mode: sticky animated 16:9 SVG stage left, scrolling study rail right
   - Study Mode: centered textbook flow with inline diagrams & clean print
   - Daylight Paper & Chalkboard themes mapped via semantic CSS variables
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Semantic SVG & Diagram Token Map (Daylight Paper + Chalkboard)
   -------------------------------------------------------------------------- */
[data-page="stem-reader"] {
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: var(--font-body);
  --sans: var(--font-ui);

  --s1: #f8f5ec;
  --s2: #ffffff;
  --s3: rgba(24, 34, 52, 0.16);
  --w: #182233;
  --dim: rgba(24, 34, 52, 0.64);
  --g1: #9a6510;
  --g2: #724a0a;
  --gold: var(--g1);
  --a1: #b83b2e;
  --b: #b83b2e;
  --sage: #1f6b4a;
  --sky: #1e5a8c;
  --accent: #9a6510;
  --bg: var(--s1);
  --g1-soft: rgba(154, 101, 16, 0.11);
  --g1-mid: rgba(154, 101, 16, 0.28);
  --a1-soft: rgba(184, 59, 46, 0.12);
  --sage-soft: rgba(31, 107, 74, 0.14);
  --panel: rgba(255, 255, 255, 0.92);
  --line: rgba(154, 101, 16, 0.28);
  --grid1: rgba(24, 34, 52, 0.055);
  --grid2: rgba(24, 34, 52, 0.12);
  --stem-glow: none;
  --stem-fbox-bg: rgba(30, 78, 121, 0.06);
  --stem-fbox-inline-bg: rgba(30, 78, 121, 0.09);
}

[data-theme="candlelight"] [data-page="stem-reader"] {
  --s1: #0b0e17;
  --s2: #141a28;
  --s3: rgba(236, 229, 213, 0.16);
  --w: #ece5d5;
  --dim: rgba(236, 229, 213, 0.62);
  --g1: #ffd98a;
  --g2: #c9973b;
  --gold: var(--g1);
  --a1: #e87264;
  --b: #e06558;
  --sage: #8fca99;
  --sky: #7cb9eb;
  --accent: #ffd98a;
  --bg: var(--s1);
  --g1-soft: rgba(255, 217, 138, 0.10);
  --g1-mid: rgba(255, 217, 138, 0.30);
  --a1-soft: rgba(232, 114, 100, 0.15);
  --sage-soft: rgba(143, 202, 153, 0.18);
  --panel: rgba(18, 24, 38, 0.92);
  --line: rgba(255, 217, 138, 0.28);
  --grid1: #161b26;
  --grid2: #212838;
  --stem-glow: drop-shadow(0 0 7px rgba(255, 217, 138, 0.45));
  --stem-fbox-bg: rgba(255, 255, 255, 0.05);
  --stem-fbox-inline-bg: rgba(255, 255, 255, 0.08);
}

/* Easy Read typeface override */
body[data-page="stem-reader"][data-font-mode="easy"] {
  --font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --------------------------------------------------------------------------
   2. Chapter Frontispiece (#stem-cover)
   -------------------------------------------------------------------------- */
.stem-cover {
  max-width: 1020px;
  margin: 2rem auto 1.25rem;
  padding: 2.25rem 2.4rem;
  background: var(--paper-elevated);
  border: 1.5px solid var(--rule-strong);
  border-radius: 16px;
  box-shadow: var(--plate-shadow);
  position: relative;
}

.stem-cover-eyebrow {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brass-gold);
  font-weight: 600;
  margin: 0 0 0.45rem;
}

.stem-cover-title {
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 3.6vw, 2.8rem);
  line-height: 1.12;
  color: var(--ink);
  margin: 0 0 0.55rem;
  font-weight: 600;
}

.stem-cover-sub {
  font-size: 1.06rem;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0 0 1.3rem;
  max-width: 66ch;
}

.stem-cover-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 1.3rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--rule);
}

.stem-cover-label {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--peter-blue);
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.stem-goals-list {
  margin: 0;
  padding-left: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

.stem-section-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.stem-section-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.38rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.15s ease;
}

.stem-section-pill:hover,
.stem-section-pill:focus-visible {
  border-color: var(--brass-gold);
  background: var(--peter-blue-soft);
  transform: translateY(-1px);
}

.stem-section-pill strong {
  color: var(--brass-gold);
  font-family: var(--mono);
  font-size: 0.74rem;
}

.stem-cover-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  margin-top: 1.35rem;
}

.stem-start-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.62rem 1.25rem;
  border-radius: 999px;
  border: 1.5px solid var(--brass-gold);
  background: var(--peter-blue);
  color: #ffffff;
  font-family: var(--font-ui);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-start-btn {
  background: var(--brass-gold);
  color: #10141f;
}

.stem-start-btn:hover {
  transform: translateY(-1px);
  opacity: 0.94;
}

.stem-cover-attr {
  font-family: var(--font-ui);
  font-size: 0.76rem;
  color: var(--ink-faint);
}

/* --------------------------------------------------------------------------
   3. Visual Mode Split Workspace
   -------------------------------------------------------------------------- */
.stem-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(350px, 0.98fr);
  gap: 1.75rem;
  max-width: 1540px;
  margin: 0 auto;
  padding: 1.25rem 1.75rem 5rem;
  align-items: start;
}

.stem-stage-col {
  position: sticky;
  top: calc(var(--header-h, 58px) + 14px);
  z-index: 20;
}

.stem-stage-card {
  background: var(--paper-elevated);
  border: 1.5px solid var(--rule);
  border-radius: 14px;
  box-shadow: var(--plate-shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.stem-stage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.95rem;
  border-bottom: 1px solid var(--rule);
  background: var(--paper-elevated);
}

.stem-stage-kicker {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-gold);
  white-space: nowrap;
}

.stem-stage-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stem-stage-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: calc(100vh - var(--header-h, 58px) - 135px);
  background: var(--s1);
  color: var(--w);
  overflow: hidden;
  transition: background-color 0.22s ease, border-color 0.22s ease;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-stage-viewport,
[data-theme="candlelight"] [data-page="stem-reader"] .stem-inline-svg {
  background: radial-gradient(ellipse at 50% 42%, #131929 0%, #0b0e17 80%);
  color: var(--w);
}

.stem-inline-svg {
  background: var(--s1);
  color: var(--w);
  transition: background-color 0.22s ease;
}

.stem-stage-slot {
  width: 100%;
  height: 100%;
}

.stem-stage-slot .scene {
  width: 100%;
  height: 100%;
  min-height: 0 !important;
  position: relative;
  overflow: hidden;
}

.stem-stage-slot svg.board,
.stem-inline-svg svg.board {
  width: 100%;
  height: 100%;
  display: block;
}

/* Stage Control Bar (always below diagram, never overlapping SVG) */
.stem-stage-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  padding: 0.55rem 0.85rem;
  border-top: 1px solid var(--rule);
  background: var(--paper-elevated);
}

.stem-stage-nav,
.stem-stage-scrub {
  display: flex;
  align-items: center;
  gap: 0.42rem;
}

.stem-stage-scrub {
  flex: 1 1 220px;
  justify-content: flex-end;
}

.stem-ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0.25rem 0.62rem;
  border-radius: 7px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.stem-ctrl-btn:hover:not(:disabled) {
  border-color: var(--brass-gold);
  background: var(--peter-blue-soft);
}

.stem-ctrl-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.stem-ctrl-btn--play[aria-pressed="true"],
.stem-ctrl-btn--sync {
  border-color: var(--brass-gold);
  color: var(--brass-gold);
}

.stem-scene-counter {
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
  min-width: 3.8rem;
  text-align: center;
}

.stem-scrubber {
  flex: 1 1 110px;
  max-width: 210px;
  accent-color: var(--brass-gold);
  cursor: pointer;
}

/* Stage Step Pills (Multi-phase diagrams) */
.stem-stage-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.stem-step-pill {
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.stem-step-pill:hover {
  border-color: var(--brass-gold);
  color: var(--ink);
}

.stem-step-pill.is-active {
  border-color: var(--brass-gold);
  background: var(--peter-blue-soft);
  color: var(--ink);
  font-weight: 600;
}

/* Expanded Diagram Modal State */
body.stem-stage-expanded {
  overflow: hidden;
}

body.stem-stage-expanded .stem-stage-col {
  position: fixed;
  inset: var(--header-h, 58px) 0 0 0;
  z-index: 80;
  background: rgba(11, 14, 23, 0.84);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

body.stem-stage-expanded .stem-stage-card {
  width: min(1280px, 96vw);
  max-height: calc(100vh - var(--header-h, 58px) - 2rem);
}

body.stem-stage-expanded .stem-stage-viewport {
  max-height: calc(100vh - var(--header-h, 58px) - 130px);
}

/* --------------------------------------------------------------------------
   4. Right-Hand Study Rail & Textbook Cards
   -------------------------------------------------------------------------- */
.stem-content-col {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  min-width: 0;
}

.stem-section-banner {
  margin-top: 1rem;
  padding: 0.9rem 1.15rem;
  border-radius: 12px;
  background: var(--peter-blue-soft);
  border-left: 4px solid var(--brass-gold);
}

.stem-section-banner:first-child {
  margin-top: 0;
}

.stem-section-num {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-gold);
  font-weight: 600;
  margin: 0 0 0.2rem;
}

.stem-section-heading {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
  line-height: 1.2;
}

.stem-scene {
  scroll-margin-top: calc(var(--header-h, 58px) + 18px);
  padding: 1.1rem 1.15rem;
  border-radius: 14px;
  border: 1.5px solid var(--rule);
  background: var(--paper-elevated);
  display: flex;
  flex-direction: column;
  gap: 0.95rem;
  transition: border-color 0.22s ease, box-shadow 0.22s ease;
}

body[data-stem-mode="visual"] .stem-scene {
  min-height: 44vh;
}

.stem-scene.is-active {
  border-color: var(--brass-gold);
  box-shadow: 0 10px 28px -16px rgba(154, 101, 16, 0.38);
}

.stem-scene-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--rule);
}

.stem-scene-kicker {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--brass-gold);
  font-weight: 600;
}

.stem-scene-title {
  font-family: var(--font-display);
  font-size: 1.18rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0.15rem 0 0;
}

.stem-jump-stage-btn {
  flex: 0 0 auto;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 0.7rem;
  cursor: pointer;
}

.stem-jump-stage-btn:hover {
  border-color: var(--brass-gold);
  color: var(--ink);
}

.stem-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.stem-card--free {
  padding: 0.75rem 0.95rem;
  border-radius: 10px;
  background: var(--paper);
  border-left: 3px dashed var(--brass-gold);
}

.stem-card-kicker {
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--peter-blue);
  font-weight: 600;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-card-kicker {
  color: var(--brass-gold);
}

.stem-card p {
  margin: 0;
  font-family: var(--font-body);
  font-size: calc(1.04rem * var(--font-scale, 1));
  line-height: 1.68;
  color: var(--ink);
}

/* Formula Blocks & Inline Pills (.fbox / .fboxi) */
.stem-workspace .fbox {
  display: block;
  margin: 0.45rem 0;
  padding: 0.78rem 1rem;
  background: var(--stem-fbox-bg);
  border-left: 3px solid var(--g1);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: calc(0.92rem * var(--font-scale, 1));
  line-height: 1.65;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-x: auto;
}

.stem-workspace .fboxcap {
  display: block;
  margin: 0.55rem 0 -0.25rem 0.8rem;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.stem-workspace .fboxi {
  display: inline;
  padding: 0.1rem 0.42rem;
  margin: 0 0.1rem;
  background: var(--stem-fbox-inline-bg);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.89em;
  color: var(--ink);
  white-space: pre-wrap;
}

/* --------------------------------------------------------------------------
   5. Study Mode (Inline 16:9 Figures, Linear Textbook Layout)
   -------------------------------------------------------------------------- */
.stem-inline-figure {
  display: none;
  border: 1px solid var(--rule);
  border-radius: 10px;
  overflow: hidden;
  background: var(--s1);
}

body[data-stem-mode="study"] .stem-stage-col {
  display: none;
}

body[data-stem-mode="study"] .stem-workspace {
  grid-template-columns: minmax(0, 1fr);
  max-width: 860px;
}

body[data-stem-mode="study"] .stem-scene {
  min-height: 0;
  padding: 1.3rem 1.45rem;
}

body[data-stem-mode="study"] .stem-jump-stage-btn {
  display: none;
}

body[data-stem-mode="study"] .stem-inline-figure {
  display: block;
}

.stem-inline-svg {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--s1);
  overflow: hidden;
}

.stem-inline-svg .scene {
  width: 100%;
  height: 100%;
  min-height: 0 !important;
}

.stem-inline-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0.8rem;
  background: var(--paper);
  border-top: 1px solid var(--rule);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  color: var(--ink-soft);
}

.stem-inline-scrub {
  width: 150px;
  accent-color: var(--brass-gold);
}

/* --------------------------------------------------------------------------
   6. Flowytales STEM Infographics (Harmonized with .info-graphic)
   -------------------------------------------------------------------------- */
.stem-info {
  padding: 0.9rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.stem-info--intuition {
  border-left: 4px solid var(--brass-gold);
  background: color-mix(in srgb, var(--brass-gold) 6%, var(--paper));
}

.stem-info-eyebrow {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-gold);
  font-weight: 700;
}

.stem-info-title {
  font-family: var(--font-display);
  font-size: 1.12rem;
  font-weight: 600;
  margin: 0.08rem 0 0;
  color: var(--ink);
}

.stem-info-body {
  margin: 0;
  font-size: calc(0.96rem * var(--font-scale, 1));
  line-height: 1.6;
  color: var(--ink-soft);
}

.stem-info-compare-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.stem-info-compare-col {
  padding: 0.72rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
}

.stem-info-compare-col h4 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-size: 0.98rem;
  color: var(--peter-blue);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-info-compare-col h4 {
  color: var(--brass-gold);
}

.stem-info-compare-col ul {
  margin: 0;
  padding-left: 1rem;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.stem-info-formula-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.stem-info-formula-tile {
  padding: 0.6rem 0.72rem;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stem-info-formula-label {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.stem-info-formula-expr {
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--brass-gold);
  word-break: break-word;
}

.stem-info-formula-note {
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.stem-info-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
}

.stem-info-step {
  display: none;
  grid-template-columns: 1.6rem minmax(0, 1fr);
  gap: 0.55rem;
  padding: 0.55rem 0.7rem;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  align-items: start;
}

.stem-info-step.is-visible {
  display: grid;
  animation: stemStepFade 0.22s ease;
}

.stem-info-step.is-current-step {
  border-left: 3px solid var(--brass-gold);
}

@keyframes stemStepFade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.stem-info-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stem-derivation-counter {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
}

.stem-step-tag {
  display: inline-block;
  margin-bottom: 0.22rem;
  padding: 0.08rem 0.42rem;
  border-radius: 4px;
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
  font-family: var(--font-ui);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-step-tag {
  color: var(--brass-gold);
}

.stem-derivation-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.2rem;
}

.stem-ctrl-btn--next-step {
  border-color: var(--brass-gold);
  background: var(--peter-blue-soft);
  font-weight: 600;
}

.stem-info-step-num {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.stem-info-step-expr {
  display: block;
  font-family: var(--mono);
  font-size: 0.88rem;
  color: var(--ink);
}

.stem-info-step-why {
  display: block;
  font-size: 0.82rem;
  color: var(--ink-soft);
  margin-top: 0.15rem;
}

.stem-info-pitfall-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.stem-pitfall-box {
  padding: 0.68rem 0.78rem;
  border-radius: 9px;
  background: var(--paper-elevated);
  border: 1px solid var(--rule);
}

.stem-pitfall-box--wrong {
  border-left: 3px solid var(--radish-rose);
}

.stem-pitfall-box--right {
  border-left: 3px solid var(--garden-sage);
}

.stem-pitfall-tag {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.stem-pitfall-box--wrong .stem-pitfall-tag { color: var(--radish-rose); }
.stem-pitfall-box--right .stem-pitfall-tag { color: var(--garden-sage); }

.stem-pitfall-box code {
  font-family: var(--mono);
  font-size: 0.86rem;
  color: var(--ink);
  white-space: pre-wrap;
}

/* Interactive Checkpoint Accordion */
.stem-info--checkpoint {
  border-left: 4px solid var(--peter-blue);
}

.stem-checkpoint-prompt {
  margin: 0;
  font-size: calc(0.98rem * var(--font-scale, 1));
  color: var(--ink);
  font-weight: 500;
}

.stem-checkpoint-details {
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  padding: 0.48rem 0.72rem;
}

.stem-checkpoint-details summary {
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--peter-blue);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-checkpoint-details summary {
  color: var(--brass-gold);
}

.stem-checkpoint-answer {
  margin-top: 0.45rem;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.stem-checkpoint-answer p {
  margin: 0.25rem 0;
}

/* Formula Sheet in Drawer */
.stem-drawer-formula-group {
  margin-bottom: 1.15rem;
}

.stem-drawer-formula-group h3 {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass-gold);
  margin: 0 0 0.45rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--rule);
}

.stem-drawer-formula-item {
  padding: 0.48rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper);
  margin-bottom: 0.42rem;
}

.stem-drawer-formula-item strong {
  display: block;
  font-size: 0.8rem;
  color: var(--ink);
}

.stem-drawer-formula-item code {
  display: block;
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--brass-gold);
  margin: 0.15rem 0;
  white-space: pre-wrap;
}

.stem-drawer-formula-item span {
  display: block;
  font-size: 0.76rem;
  color: var(--ink-faint);
}

/* --------------------------------------------------------------------------
   7. Mobile Portrait Split & Responsive Rules (<= 960px)
   -------------------------------------------------------------------------- */
@media (max-width: 960px) {
  .stem-cover {
    margin: 1rem 0.85rem 0.75rem;
    padding: 1.35rem 1.2rem;
  }

  .stem-cover-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .stem-workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
    padding: 0.75rem 0.85rem 4rem;
  }

  .stem-stage-col {
    position: sticky;
    top: calc(var(--header-h, 54px) + 4px);
    z-index: 30;
  }

  .stem-stage-viewport {
    max-height: 36dvh;
  }

  .stem-ctrl-btn {
    min-height: 38px;
    padding: 0.3rem 0.68rem;
  }

  body[data-stem-mode="visual"] .stem-scene {
    min-height: 0;
  }
}

@media (max-width: 600px) {
  .stem-info-compare-grid,
  .stem-info-formula-grid,
  .stem-info-pitfall-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .stem-stage-head {
    padding: 0.45rem 0.7rem;
  }

  .stem-stage-bar {
    padding: 0.45rem 0.65rem;
  }
}

/* --------------------------------------------------------------------------
   8. Print Support (Forces Study Layout on Paper)
   -------------------------------------------------------------------------- */
@media print {
  .book-header,
  .stem-stage-col,
  .stem-inline-bar,
  .stem-jump-stage-btn,
  .comfort-popover,
  .toc-drawer,
  .toc-backdrop {
    display: none !important;
  }

  .stem-workspace {
    display: block !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  .stem-inline-figure {
    display: block !important;
    break-inside: avoid;
  }

  .stem-scene,
  .stem-info {
    break-inside: avoid;
  }

  .stem-info-step {
    display: grid !important;
  }

  .stem-derivation-controls {
    display: none !important;
  }

  .stem-stage-banner,
  .stem-fig-modal,
  .stem-term-popover,
  .stem-section-mastery-btn,
  .stem-print-formulas-bar {
    display: none !important;
  }

  /* Print-only 1-Page Formula Cheat Sheet Mode */
  body[data-print-mode="formulas"] .stem-cover,
  body[data-print-mode="formulas"] .stem-workspace,
  body[data-print-mode="formulas"] .colophon {
    display: none !important;
  }

  body[data-print-mode="formulas"] .toc-drawer {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    border: none !important;
    box-shadow: none !important;
    transform: none !important;
  }

  body[data-print-mode="formulas"] .toc-drawer-head button,
  body[data-print-mode="formulas"] .toc-tabs,
  body[data-print-mode="formulas"] #toc-panel-sections,
  body[data-print-mode="formulas"] #toc-panel-chapters {
    display: none !important;
  }

  body[data-print-mode="formulas"] #toc-panel-formulas {
    display: block !important;
  }
}

/* --------------------------------------------------------------------------
   9. Interactive Figure Chips, Spotlight Banner, Glossary & Mastery Controls
   -------------------------------------------------------------------------- */
.stem-stage-head {
  flex-direction: column;
  align-items: stretch;
  gap: 0.2rem;
}

.stem-stage-head-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stem-stage-figs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.stem-stage-fig-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.08rem 0.48rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 600;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-stage-fig-pill {
  color: var(--brass-gold);
}

.stem-stage-card.is-spotlight {
  animation: stemSpotlightPulse 1.3s ease;
}

@keyframes stemSpotlightPulse {
  0% { box-shadow: 0 0 0 0 rgba(154, 101, 16, 0.55), var(--plate-shadow); border-color: var(--brass-gold); }
  50% { box-shadow: 0 0 0 6px rgba(154, 101, 16, 0.22), var(--plate-shadow); border-color: var(--brass-gold); }
  100% { box-shadow: var(--plate-shadow); }
}

body.is-reduced-motion .stem-stage-card.is-spotlight {
  animation: none;
  border-color: var(--brass-gold);
}

.stem-stage-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem 0.65rem;
  padding: 0.48rem 0.85rem;
  background: var(--peter-blue-soft);
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--ink);
}

.stem-stage-banner[hidden] {
  display: none !important;
}

.stem-stage-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.stem-banner-btn {
  padding: 0.2rem 0.58rem;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.stem-banner-btn--primary {
  border-color: var(--brass-gold);
  color: var(--peter-blue);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-banner-btn--primary {
  color: var(--brass-gold);
}

.stem-banner-close {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.82rem;
  padding: 0.15rem 0.3rem;
}

/* Clickable Inline Figure / Table Chips in Prose */
.stem-fig-ref {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
  padding: 0.05rem 0.46rem;
  margin: 0 0.08rem;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
  font-family: var(--mono);
  font-size: 0.84em;
  font-weight: 600;
  line-height: 1.35;
  cursor: pointer;
  vertical-align: baseline;
  transition: transform 0.14s ease, border-color 0.14s ease, background-color 0.14s ease;
}

.stem-fig-ref:hover {
  border-color: var(--brass-gold);
  transform: translateY(-1px);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-fig-ref {
  color: var(--brass-gold);
  background: rgba(255, 217, 138, 0.1);
}

/* Interactive Glossary Term Triggers */
.stem-term-btn {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  border-bottom: 1.5px dotted var(--brass-gold);
  cursor: help;
  transition: color 0.12s ease, background-color 0.12s ease;
}

.stem-term-btn:hover,
.stem-term-btn:focus-visible {
  color: var(--peter-blue);
  background: var(--peter-blue-soft);
  border-radius: 3px;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-term-btn:hover,
[data-theme="candlelight"] [data-page="stem-reader"] .stem-term-btn:focus-visible {
  color: var(--brass-gold);
}

.stem-term-popover {
  position: fixed;
  z-index: 95;
  width: min(340px, calc(100vw - 24px));
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  border: 1.5px solid var(--rule-strong);
  background: var(--paper-elevated);
  box-shadow: var(--plate-shadow);
  color: var(--ink);
}

.stem-term-popover[hidden] {
  display: none !important;
}

.stem-term-popover-head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.4rem;
}

.stem-term-popover-head strong {
  font-family: var(--font-display);
  font-size: 1.02rem;
  color: var(--ink);
}

.stem-term-symbol {
  font-family: var(--mono);
  font-size: 0.74rem;
  padding: 0.08rem 0.4rem;
  border-radius: 5px;
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-term-symbol {
  color: var(--brass-gold);
}

.stem-term-popover-head .comfort-close-btn {
  margin-left: auto;
}

.stem-term-def {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--ink-soft);
}

.stem-term-ex {
  margin: 0;
  padding: 0.35rem 0.5rem;
  border-radius: 7px;
  background: var(--paper);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--ink);
}

/* Diagram Quick-Peek Modal (Study Mode & Mobile) */
.stem-fig-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.stem-fig-modal[hidden] {
  display: none !important;
}

.stem-fig-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 14, 23, 0.72);
  backdrop-filter: blur(2px);
}

.stem-fig-modal-card {
  position: relative;
  z-index: 1;
  width: min(860px, 100%);
  background: var(--paper-elevated);
  border: 1.5px solid var(--rule-strong);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--plate-shadow);
}

.stem-fig-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 0.95rem;
  border-bottom: 1px solid var(--rule);
}

.stem-fig-modal-viewport {
  max-height: 68vh;
}

/* Section Mastery Toggle & Printable Formula Bar */
.stem-section-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.stem-section-mastery-btn {
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--rule-strong);
  background: var(--paper-elevated);
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.stem-section-mastery-btn[aria-pressed="true"] {
  border-color: var(--sage);
  background: var(--sage-soft);
  color: var(--sage);
}

.stem-print-formulas-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--rule);
}

.stem-print-formulas-btn {
  padding: 0.34rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--brass-gold);
  background: var(--peter-blue-soft);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   10. Novel-Adopted Visual STEM Infographics
   (concept-roadmap, toolbox-grid, theorem-roster, scale-gauge, timeline)
   -------------------------------------------------------------------------- */
.stem-info-sub {
  margin: -0.15rem 0 0.35rem;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-soft);
}

/* 10a. Concept Roadmap (from Novel route-map) */
.stem-roadmap-svg-wrap {
  border-radius: 10px;
  border: 1px solid var(--rule);
  background: var(--s1);
  padding: 0.4rem;
  overflow: hidden;
}

.stem-roadmap-svg-wrap svg {
  width: 100%;
  height: auto;
  display: block;
}

.stem-roadmap-stops {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
}

.stem-roadmap-stop {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  padding: 0.24rem 0.62rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  color: var(--ink-soft);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  font-weight: 500;
}

button.stem-roadmap-stop {
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.14s ease;
}

button.stem-roadmap-stop:hover {
  border-color: var(--brass-gold);
  color: var(--ink);
  transform: translateY(-1px);
}

.stem-roadmap-stop.is-reached {
  color: var(--ink);
  border-color: var(--rule-strong);
}

.stem-roadmap-stop.is-current {
  border-color: var(--brass-gold);
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
  font-weight: 600;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-roadmap-stop.is-current {
  color: var(--brass-gold);
}

.stem-stop-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 7px;
}

/* 10b. Method Toolbox Grid (from Novel inventory-grid) */
.stem-toolbox-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
}

.stem-toolbox-slot {
  padding: 0.62rem 0.74rem;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.stem-toolbox-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.4rem;
}

.stem-toolbox-num {
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--brass-gold);
}

.stem-toolbox-name {
  font-family: var(--font-display);
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--ink);
}

.stem-toolbox-formula {
  display: inline-block;
  align-self: flex-start;
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.14rem 0.45rem;
  border-radius: 5px;
  background: var(--stem-fbox-inline-bg);
  color: var(--peter-blue);
  word-break: break-word;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-toolbox-formula {
  color: var(--brass-gold);
}

.stem-toolbox-note {
  font-size: 0.8rem;
  line-height: 1.42;
  color: var(--ink-soft);
}

/* 10c. Theorem & Concept Roster (from Novel character-roster) */
.stem-roster-list {
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
}

.stem-roster-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.56rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--roster-accent, var(--peter-blue));
  background: var(--paper-elevated);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-roster-row {
  border-left-color: var(--roster-accent-dark, var(--brass-gold));
}

.stem-roster-badge {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--rule-strong);
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-roster-badge {
  color: var(--brass-gold);
}

.stem-roster-body {
  min-width: 0;
  flex: 1 1 auto;
}

.stem-roster-top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.55rem;
}

.stem-roster-top strong {
  font-family: var(--font-display);
  font-size: 0.98rem;
  color: var(--ink);
}

.stem-roster-formula {
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--brass-gold);
}

.stem-roster-role {
  display: block;
  margin-top: 0.14rem;
  font-size: 0.82rem;
  line-height: 1.44;
  color: var(--ink-soft);
}

/* 10d. Concept Scale & Strength Gauge (from Novel countdown-gauge) */
.stem-gauge-box {
  padding: 0.82rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--rule-strong);
  background: var(--paper-elevated);
}

.stem-gauge-labels {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-family: var(--font-ui);
  font-size: 0.74rem;
  color: var(--ink-soft);
  margin-bottom: 0.42rem;
}

.stem-gauge-labels strong {
  color: var(--brass-gold);
  font-size: 0.84rem;
  text-align: center;
}

.stem-gauge-track {
  height: 10px;
  border-radius: 999px;
  background: var(--paper-deep);
  overflow: hidden;
  border: 1px solid var(--rule);
}

.stem-gauge-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--peter-blue), var(--brass-gold), var(--sage));
}

.stem-gauge-rungs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.stem-gauge-rung {
  padding: 0.16rem 0.52rem;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--paper);
  font-family: var(--mono);
  font-size: 0.73rem;
  color: var(--ink-soft);
}

.stem-gauge-rung.is-peak {
  border-color: var(--brass-gold);
  color: var(--ink);
  font-weight: 600;
}

.stem-gauge-notes {
  margin: 0.6rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.82rem;
  line-height: 1.48;
  color: var(--ink-soft);
}

/* 10e. Step-by-Step Sequence Timeline (from Novel timeline) */
.stem-timeline-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.48rem;
}

.stem-timeline-item {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.54rem 0.72rem;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
}

.stem-tl-marker {
  flex: 0 0 auto;
  padding: 0.14rem 0.48rem;
  border-radius: 6px;
  background: var(--peter-blue-soft);
  color: var(--peter-blue);
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  margin-top: 0.1rem;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-tl-marker {
  color: var(--brass-gold);
}

.stem-tl-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.stem-tl-label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--ink);
}

.stem-tl-detail {
  display: block;
  margin-top: 0.12rem;
  font-size: 0.82rem;
  line-height: 1.44;
  color: var(--ink-soft);
}

@media (max-width: 600px) {
  .stem-toolbox-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --------------------------------------------------------------------------
   11. Option C: TL;DR Banners, Semantic Card Voices, Guided Folds,
       Live Math Sandboxes & Predict-First Micro-Checks
   -------------------------------------------------------------------------- */
@media (max-width: 760px) {
  #stem-depth-switch {
    display: none;
  }
}

/* Scene Plain-English TL;DR Banner & Real-World Anchor */
.stem-tldr-banner {
  padding: 0.72rem 0.92rem;
  border-radius: 10px;
  border: 1px solid var(--rule-strong);
  border-left: 3.5px solid var(--brass-gold);
  background: var(--g1-soft);
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
}

.stem-tldr-eyebrow {
  font-family: var(--font-ui);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass-gold);
}

.stem-tldr-text {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--ink);
  font-weight: 500;
}

.stem-realworld-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  align-self: flex-start;
  padding: 0.16rem 0.56rem;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  font-family: var(--font-ui);
  font-size: 0.74rem;
  color: var(--ink-soft);
}

/* Semantic Card Voices */
.stem-card-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.stem-role-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink-soft);
}

.stem-card--definition {
  border-left: 3.5px solid var(--peter-blue);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-card--definition {
  border-left-color: var(--brass-gold);
}

.stem-card--definition .stem-role-badge {
  color: var(--peter-blue);
  background: var(--peter-blue-soft);
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-card--definition .stem-role-badge {
  color: var(--brass-gold);
}

.stem-card--example {
  border-left: 3.5px solid var(--sage);
}

.stem-card--example .stem-role-badge {
  color: var(--sage);
  background: var(--sage-soft);
}

.stem-card--story {
  border-left: 3.5px solid var(--brass-gold);
  background: var(--g1-soft);
}

.stem-card--story .stem-role-badge {
  color: var(--brass-gold);
}

.stem-card--exercise {
  border-left: 3.5px solid var(--a1);
}

.stem-card--exercise .stem-role-badge {
  color: var(--a1);
  background: var(--a1-soft);
}

/* Guided Mode Collapsible Textbook Details & Worked Example Solutions */
.stem-guided-fold,
.stem-example-solution {
  margin-top: 0.25rem;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper);
  padding: 0.42rem 0.68rem;
}

.stem-guided-fold summary,
.stem-example-solution summary {
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--peter-blue);
  list-style: none;
}

[data-theme="candlelight"] [data-page="stem-reader"] .stem-guided-fold summary,
[data-theme="candlelight"] [data-page="stem-reader"] .stem-example-solution summary {
  color: var(--brass-gold);
}

.stem-fold-body {
  margin-top: 0.45rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

@media print {
  .stem-guided-fold,
  .stem-example-solution {
    display: block !important;
  }
  .stem-guided-fold .stem-fold-body,
  .stem-example-solution .stem-fold-body {
    display: flex !important;
  }
}

/* Live Interactive Math Sandbox (.stem-info--lab) */
.stem-lab-canvas {
  border-radius: 10px;
  border: 1px solid var(--rule-strong);
  background: var(--s1);
  overflow: hidden;
  padding: 0.25rem;
}

.stem-lab-canvas svg {
  width: 100%;
  height: auto;
  display: block;
}

.stem-lab-readout {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 0.65rem;
  padding: 0.5rem 0.72rem;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--ink);
}

.stem-lab-status {
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 700;
}

.stem-lab-status.is-pass {
  background: var(--sage-soft);
  color: var(--sage);
}

.stem-lab-status.is-warn {
  background: var(--a1-soft);
  color: var(--a1);
}

.stem-lab-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.55rem 0.8rem;
  padding: 0.58rem 0.72rem;
  border-radius: 9px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
}

.stem-lab-slider-row {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
}

.stem-lab-slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--ink-soft);
}

.stem-lab-slider-head strong {
  color: var(--brass-gold);
}

.stem-lab-slider {
  width: 100%;
  accent-color: var(--brass-gold);
  cursor: pointer;
}

.stem-lab-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

/* Predict-First Micro-Check (.stem-info--predict) */
.stem-predict-q {
  margin: 0;
  font-size: 0.94rem;
  line-height: 1.52;
  color: var(--ink);
  font-weight: 500;
}

.stem-predict-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.42rem;
}

.stem-predict-opt {
  padding: 0.38rem 0.78rem;
  border-radius: 8px;
  border: 1.5px solid var(--rule-strong);
  background: var(--paper-elevated);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.14s ease, background-color 0.14s ease, transform 0.12s ease;
}

.stem-predict-opt:hover {
  border-color: var(--brass-gold);
  transform: translateY(-1px);
}

.stem-predict-opt.is-correct {
  border-color: var(--sage);
  background: var(--sage-soft);
  color: var(--sage);
}

.stem-predict-opt.is-wrong {
  border-color: var(--a1);
  background: var(--a1-soft);
  color: var(--a1);
}

.stem-predict-feedback {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--paper-elevated);
  font-size: 0.86rem;
  line-height: 1.48;
  color: var(--ink);
}

.stem-predict-feedback[hidden] {
  display: none !important;
}
