/* =====================================================================
   New Discovering Mathematics 1A — Interactive Textbook
   Shared Library Stylesheet (lib.css)

   Used by every section page. Optimized for landscape tablet (≥ 1024px).
   Companion: lib.js
   ===================================================================== */

/* ---------------------------------------------------------------------
   1. Color tokens (CSS custom properties)
   --------------------------------------------------------------------- */
:root {
  --bg: #f4f6f8;
  --page: #ffffff;
  --ink: #1f2933;
  --ink-soft: #5a6776;
  --ink-muted: #95a1ad;

  /* Brand colors from textbook */
  --teal: #1a8a8a;            /* section header text */
  --teal-pill: #2ea886;        /* subsection letter pill, green badges */
  --teal-dark: #1a6a55;
  --teal-strip: linear-gradient(90deg, #b9e3e8 0%, #d8eef0 100%);

  --magenta: #c0327a;          /* key term highlight, math callouts */
  --magenta-light: #fff5f8;
  --magenta-border: #f0c4d9;

  --lavender: #efe7f2;         /* definition box bg */
  --lavender-border: #cdb6d8;
  --lavender-ink: #2a2440;

  --activity-bg: #ede8f3;      /* activity-box bg */

  --think-yellow: #f6c84c;
  --think-bg: #fff7d6;
  --think-ink: #5a4a14;

  --spotlight-bg: #fdecec;
  --spotlight-border: #f5b8b8;
  --spotlight-ink: #d04a3a;

  --recall-bg: #e8f4ff;
  --recall-border: #a8cfee;
  --recall-ink: #2a4d7a;

  --extra-bg: #f0f7e8;
  --extra-border: #b8d8a0;
  --extra-ink: #4d6a2a;

  --discuss-bg: #fff4e0;
  --discuss-border: #f0c878;
  --discuss-ink: #7a5520;

  --coding-bg: #e8eef8;
  --coding-border: #a0b4d8;
  --coding-ink: #2a3d6a;

  --notation-bg: #fffbe0;
  --notation-border: #e8c870;
  --notation-ink: #6a5520;

  --equiv-bg: #f5f0fa;
  --equiv-border: #c8b4d8;
  --equiv-ink: #4a2a6a;

  --we-rail: #d04a3a;          /* worked-example red vertical line */

  --basic-band: #f0c878;
  --intermediate-band: #d0d878;
  --advanced-band: #d8a0a0;

  --correct: #2ea886;
  --correct-bg: #e6f7ef;
  --wrong: #d04a3a;
  --wrong-bg: #fdecec;

  --shadow-soft: 0 2px 10px rgba(0,0,0,.06);
  --shadow-pop: 0 8px 24px rgba(0,0,0,.18);
  --shadow-modal: 0 12px 30px rgba(0,0,0,.25);

  --radius: 8px;
  --radius-lg: 12px;
}

/* ---------------------------------------------------------------------
   2. Reset & base typography
   --------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
               "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
@media (min-width: 1024px) {
  body { font-size: 17px; }
}
p { margin: 8px 0; }
sup { font-size: .72em; vertical-align: super; }
sub { font-size: .72em; vertical-align: sub; }

/* ---------------------------------------------------------------------
   3. Page frame
   --------------------------------------------------------------------- */
.page {
  max-width: 1280px;
  margin: 0 auto;
  background: var(--page);
  min-height: 100vh;
  box-shadow: var(--shadow-soft);
  position: relative;
  padding-bottom: 96px;
}
.top-bar {
  background: var(--teal-strip);
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 12px;
  font-weight: 700;
  color: #2d6a72;
  letter-spacing: .04em;
}
.top-bar .page-num { color: var(--teal); font-size: 16px; }
.content { padding: 22px 28px 28px; }

/* Two-column layout: main + side rail (landscape ≥ 1024px) */
@media (min-width: 1024px) {
  .content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    column-gap: 32px;
    padding: 28px 36px 32px;
  }
  .main-col { min-width: 0; }
  .side-col { position: relative; }
}
@media (max-width: 1023px) {
  .side-col { display: contents; }
  .side-item { margin: 12px 0; }
}

/* ---------------------------------------------------------------------
   4. Section header (1.1 PRIMES …)
   --------------------------------------------------------------------- */
.section-title {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 4px 0 22px;
  grid-column: 1 / -1;
}
.section-num {
  width: 56px; height: 56px;
  background: var(--teal);
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 22px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.1);
}
.section-title h1 {
  margin: 0;
  font-size: 28px;
  color: var(--teal);
  font-weight: 800;
  letter-spacing: .02em;
  text-transform: uppercase;
}

/* Subsection letter pill (A / B / C / D / E) */
.subsec-letter {
  display: inline-grid;
  place-items: center;
  width: 36px; height: 36px;
  background: var(--teal-pill);
  color: #fff;
  border-radius: 50%;
  font-weight: 800;
  font-size: 18px;
  margin-right: 10px;
  vertical-align: middle;
}
h3.subsec-title {
  font-size: 22px;
  color: var(--teal);
  font-weight: 700;
  margin: 22px 0 10px;
}

/* ---------------------------------------------------------------------
   5. Definition box (purple)
   --------------------------------------------------------------------- */
.definition-box {
  background: var(--lavender);
  border: 1.5px solid var(--lavender-border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  margin: 14px 0;
  color: var(--lavender-ink);
}
.definition-box ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.definition-box li {
  position: relative;
  padding-left: 18px;
  margin: 6px 0;
  font-weight: 600;
}
.definition-box li::before {
  content: "○";
  position: absolute; left: 0; top: 0;
  color: #8a6aa3;
  font-size: 12px;
}
.definition-box.compact { padding: 10px 14px; }
.key-term { color: var(--magenta); font-weight: 700; }

/* ---------------------------------------------------------------------
   6. Activity badge + box (green)
   --------------------------------------------------------------------- */
.activity-badge, .think-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px 6px 12px;
  border-radius: 18px;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  position: relative;
  z-index: 2;
  letter-spacing: .04em;
}
.activity-badge {
  background: var(--teal-pill);
  margin-left: 4px;
}
.activity-badge::before {
  content: "";
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 4px;
  background-image:
    linear-gradient(45deg, #f6c84c 0 50%, transparent 50%),
    linear-gradient(-45deg, #ec5a5a 0 50%, #4f9bd8 50%);
  border: 1px solid #1a6a55;
}
.activity-box {
  background: var(--activity-bg);
  border-radius: var(--radius);
  padding: 28px 18px 16px;
  margin-top: -16px;
  margin-bottom: 18px;
}
.activity-box .objective {
  margin: 4px 0 14px;
  font-weight: 600;
}

/* Numbered Q list inside activity */
ol.q-list { list-style: none; padding: 0; margin: 0; counter-reset: ord; }
ol.q-list > li {
  position: relative;
  padding-left: 30px;
  margin-bottom: 14px;
  counter-increment: ord;
}
ol.q-list > li::before {
  content: counter(ord);
  position: absolute;
  left: 0; top: 1px;
  width: 22px; height: 22px;
  background: var(--teal-pill);
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}

/* ---------------------------------------------------------------------
   7. THINK² badge + box (yellow)
   --------------------------------------------------------------------- */
.think-wrap { margin: 18px 0; }
.think-badge {
  background: var(--think-yellow);
  color: var(--think-ink);
  padding-left: 8px;
}
.think-badge::before {
  content: "";
  width: 22px; height: 22px;
  background: var(--teal-pill);
  border-radius: 50%;
  background-image: radial-gradient(circle at 30% 30%, #fff 2px, transparent 3px);
}
.think-badge sup { font-size: .7em; margin-left: 2px; }
.think-box {
  background: var(--think-bg);
  border-top: 2px solid var(--think-yellow);
  padding: 14px 18px 12px;
  margin-top: -8px;
  border-radius: 0 0 var(--radius) var(--radius);
}
.think-box ol.q-list > li::before { background: var(--teal-pill); }

/* ---------------------------------------------------------------------
   8. Worked Example (red rail + numbered steps + Methods)
   --------------------------------------------------------------------- */
.worked-example {
  position: relative;
  padding: 4px 0 16px 24px;
  margin: 22px 0 18px;
  border-left: 3px solid var(--we-rail);
}
.worked-example::before {
  content: "";
  position: absolute;
  left: -7px; top: 0;
  width: 11px; height: 11px;
  background: var(--we-rail);
  border-radius: 50%;
}
.worked-example::after {
  content: "";
  position: absolute;
  left: -7px; bottom: 4px;
  width: 11px; height: 11px;
  background: #fff;
  border: 2px solid var(--we-rail);
  border-radius: 50%;
}
.we-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 17px;
  color: #c84a3a;
  margin-bottom: 10px;
  letter-spacing: .03em;
}
.we-badge::before {
  content: "📖";
  filter: hue-rotate(-30deg);
}
.we-badge .num {
  font-size: 26px;
  color: #c84a3a;
}
.we-question { margin: 6px 0 14px; }
.solution-label, .analysis-label {
  display: inline-block;
  background: var(--we-rail);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  padding: 3px 12px;
  border-radius: 4px;
  margin: 12px 0 8px;
  letter-spacing: .04em;
}
.analysis-label { background: #d6804a; }
.method-label {
  font-weight: 700;
  color: var(--we-rail);
  margin: 14px 0 6px;
  font-size: 15px;
}
.step-label {
  display: inline-block;
  background: #fff;
  border: 2px solid var(--we-rail);
  color: var(--we-rail);
  font-weight: 700;
  border-radius: 16px;
  padding: 2px 14px;
  font-size: 13px;
  margin: 10px 0 6px;
}
.step-label .step-n { font-weight: 800; }
.we-note {
  background: #fff;
  border-left: 3px solid var(--we-rail);
  padding: 6px 12px;
  margin: 8px 0;
  font-size: 14px;
  color: var(--ink-soft);
}
.we-note::before {
  content: "NOTE";
  display: inline-block;
  background: var(--we-rail);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 3px;
  margin-right: 8px;
  letter-spacing: .04em;
}

/* ---------------------------------------------------------------------
   9. Try It Yourself
   --------------------------------------------------------------------- */
.try-it {
  margin: 16px 0 18px;
  padding: 4px 0 12px 24px;
  border-left: 3px solid #f0a040;
  position: relative;
}
.try-it::before {
  content: "";
  position: absolute;
  left: -7px; top: 0;
  width: 11px; height: 11px;
  background: #f0a040;
  border-radius: 50%;
}
.tiy-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  font-size: 16px;
  color: #c87a20;
  margin-bottom: 8px;
}
.tiy-badge::before { content: "👤"; }
.tiy-badge .num { font-size: 22px; color: #c87a20; }

/* ---------------------------------------------------------------------
   10. Practice Exercise
   --------------------------------------------------------------------- */
.practice-exercise {
  margin-top: 28px;
}
.pe-header {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--teal-pill);
  color: #fff;
  padding: 8px 18px;
  border-radius: 22px;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .04em;
  box-shadow: 0 2px 6px rgba(0,0,0,.1);
}
.pe-header::before { content: "🏅"; filter: saturate(1.3); }
.pe-tier {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 22px 0 12px;
  font-weight: 800;
  font-size: 15px;
  color: var(--ink);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.pe-tier::before {
  content: "";
  display: inline-block;
  width: 18px; height: 18px;
  border-radius: 4px;
}
.pe-tier.basic::before        { background: var(--basic-band); }
.pe-tier.intermediate::before { background: var(--intermediate-band); }
.pe-tier.advanced::before     { background: var(--advanced-band); }
.pe-tier.basic        { border-bottom: 2px solid var(--basic-band); padding-bottom: 4px; }
.pe-tier.intermediate { border-bottom: 2px solid var(--intermediate-band); padding-bottom: 4px; }
.pe-tier.advanced     { border-bottom: 2px solid var(--advanced-band); padding-bottom: 4px; }

/* Two-column exercise grid on landscape */
@media (min-width: 1024px) {
  .exercise-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 28px;
  }
}
.exercise {
  break-inside: avoid;
  margin: 8px 0 14px;
  padding: 6px 0 8px 30px;
  position: relative;
}
.exercise .qnum {
  position: absolute;
  left: 0; top: 4px;
  width: 22px; height: 22px;
  background: #f0a040;
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}
.exercise.open .qnum::after {
  content: "OPEN";
  position: absolute;
  top: -10px; left: 24px;
  background: #f0a040;
  color: #fff;
  font-size: 8px;
  padding: 1px 4px;
  border-radius: 3px;
  letter-spacing: .04em;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------
   11. Side rail variants (landscape only)
   --------------------------------------------------------------------- */
.side-item {
  background: #fff;
  border: 1.5px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.55;
  position: relative;
}
.side-item .side-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.side-item.spotlight   { background: var(--spotlight-bg); border-color: var(--spotlight-border); }
.side-item.spotlight   .side-label { color: var(--spotlight-ink); }
.side-item.spotlight   .side-label::before { content: "🔦"; }
.side-item.recall      { background: var(--recall-bg); border-color: var(--recall-border); }
.side-item.recall      .side-label { color: var(--recall-ink); }
.side-item.recall      .side-label::before { content: "⏱"; }
.side-item.extra       { background: var(--extra-bg); border-color: var(--extra-border); }
.side-item.extra       .side-label { color: var(--extra-ink); }
.side-item.extra       .side-label::before { content: "🌐"; }
.side-item.discuss     { background: var(--discuss-bg); border-color: var(--discuss-border); }
.side-item.discuss     .side-label { color: var(--discuss-ink); }
.side-item.discuss     .side-label::before { content: "💬"; }
.side-item.coding      { background: var(--coding-bg); border-color: var(--coding-border); }
.side-item.coding      .side-label { color: var(--coding-ink); }
.side-item.coding      .side-label::before { content: "💻"; }
.side-item.notations   { background: var(--notation-bg); border-color: var(--notation-border); }
.side-item.notations   .side-label { color: var(--notation-ink); }
.side-item.notations   .side-label::before { content: "✎"; }
.side-item.equivalence { background: var(--equiv-bg); border-color: var(--equiv-border); }
.side-item.equivalence .side-label { color: var(--equiv-ink); }
.side-item.equivalence .side-label::before { content: "≡"; }

.side-item .professor {
  display: block;
  width: 56px; height: 56px;
  margin: 8px auto 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #b0d8e0, #80a8c0);
  position: relative;
}
.side-item .professor::after {
  content: "👨‍🏫";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 32px;
}

/* ---------------------------------------------------------------------
   12. Tables (factor table, grouping table)
   --------------------------------------------------------------------- */
.dm-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 10px 0 14px;
  background: #fff;
  border: 2px solid var(--teal-pill);
  border-radius: 6px;
  overflow: hidden;
  font-size: 15px;
}
.dm-table th {
  background: var(--teal-pill);
  color: #fff;
  padding: 8px 10px;
  text-align: left;
  font-weight: 700;
}
.dm-table td {
  padding: 8px 10px;
  border-top: 1px solid #cfe8df;
  vertical-align: middle;
}
.dm-table td + td { border-left: 1px solid #cfe8df; }
.dm-table tr:nth-child(even) td { background: #f0f8f5; }

/* ---------------------------------------------------------------------
   13. Form inputs (blanks, textareas, etc.)
   --------------------------------------------------------------------- */
.blank {
  border: none;
  border-bottom: 1.5px dashed var(--teal-pill);
  background: transparent;
  font: inherit;
  padding: 4px 6px;
  color: var(--teal-dark);
  outline: none;
  min-width: 70px;
}
.blank:focus { background: #fffbe6; border-bottom-color: #f59e0b; }
.blank.short {
  width: 56px;
  text-align: center;
  border: 1px solid var(--teal-pill);
  border-radius: 4px;
  padding: 4px;
}
.blank.short:focus { background: #fffbe6; border-color: #f59e0b; }
.blank.correct {
  border-color: var(--correct) !important;
  background: var(--correct-bg) !important;
  color: var(--teal-dark) !important;
}
.blank.wrong {
  border-color: var(--wrong) !important;
  background: var(--wrong-bg) !important;
  color: #8a2a20 !important;
}
.blank-textarea {
  width: 100%;
  border: 1px solid var(--teal-pill);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
  background: #f0f8f5;
  outline: none;
  resize: vertical;
}
.blank-textarea:focus { background: #fffbe6; border-color: #f59e0b; }

/* "Re-do required" state — input was cleared after showing the answer */
.blank.redo-pending {
  border-color: #f0a040 !important;
  background: #fff7e0 !important;
  color: #5a4a14 !important;
  animation: redo-pulse 1.4s ease-in-out infinite;
}
@keyframes redo-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240,160,64,0); }
  50%      { box-shadow: 0 0 0 4px rgba(240,160,64,.18); }
}
.redo-prompt {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  background: #fff7e0;
  border: 1px solid #f0a040;
  border-radius: 10px;
  color: #c87a20;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
  white-space: nowrap;
}
.redo-prompt::before { content: "↻ "; }

/* "Got it right after seeing the answer" — slightly different visual to acknowledge effort */
.mark.ok-redo {
  background: linear-gradient(135deg, #2ea886, #f0a040);
}

/* Inline ✓/✗ marks */
.mark {
  display: inline-block;
  width: 20px; height: 20px;
  border-radius: 50%;
  text-align: center;
  line-height: 20px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  margin-left: 4px;
  vertical-align: middle;
}
.mark.ok { background: var(--correct); }
.mark.no { background: var(--wrong); cursor: pointer; }
.mark.no::after { content: "✗"; }
.mark.ok::after { content: "✓"; }

/* ---------------------------------------------------------------------
   14. Math figures: factor tree (SVG container)
   --------------------------------------------------------------------- */
.factor-tree-set {
  display: flex;
  flex-wrap: wrap;
  gap: 28px;
  align-items: flex-start;
  margin: 14px 0;
}
.factor-tree {
  display: inline-block;
  text-align: center;
}
.factor-tree-label {
  font-weight: 700;
  margin-bottom: 6px;
}
.factor-tree svg {
  font-family: inherit;
  font-size: 16px;
}
.factor-tree svg circle {
  fill: #fff;
  stroke: #2a4d7a;
  stroke-width: 1.5;
  cursor: pointer;
}
.factor-tree svg circle.filled {
  fill: #e8f4ff;
  stroke: #2a4d7a;
}
.factor-tree svg circle.given {
  fill: #c8e8c8;
  stroke: #4a7a4a;
}
.factor-tree svg circle.correct {
  fill: var(--correct-bg);
  stroke: var(--correct);
  stroke-width: 2;
}
.factor-tree svg circle.wrong {
  fill: var(--wrong-bg);
  stroke: var(--wrong);
  stroke-width: 2;
}
.factor-tree svg line { stroke: #2a4d7a; stroke-width: 1.5; }
.factor-tree svg line.dotted { stroke-dasharray: 4 4; stroke: #888; }
.factor-tree svg text { fill: var(--ink); font-weight: 600; user-select: none; pointer-events: none; }
.factor-tree input.tree-input {
  position: absolute;
  width: 36px; height: 28px;
  border: 1.5px solid var(--teal-pill);
  border-radius: 14px;
  text-align: center;
  font: inherit;
  background: #fff;
  outline: none;
}
.factor-tree input.tree-input:focus { background: #fffbe6; border-color: #f59e0b; }
.factor-tree-host { position: relative; display: inline-block; }

/* ---------------------------------------------------------------------
   15. Successive short division grid
   --------------------------------------------------------------------- */
.short-div {
  display: inline-block;
  margin: 10px 16px 10px 0;
  font-family: "SF Mono", Menlo, monospace;
  font-size: 17px;
}
.short-div .row {
  display: flex;
  align-items: stretch;
  min-height: 34px;
}
.short-div .divisor {
  width: 56px;
  text-align: right;
  padding-right: 10px;
  color: var(--magenta);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-shrink: 0;
}
.short-div .bar {
  width: 2px;
  background: #1f2933;
  flex-shrink: 0;
}
.short-div .dividend {
  min-width: 80px;
  border-top: 1.5px solid #1f2933;
  padding: 4px 10px 0;
  white-space: nowrap;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.short-div .row:first-child .dividend { border-top: none; }
.short-div .row.final .dividend { padding-left: 14px; }
.short-div .row.final .divisor { /* empty, no input on final quotient row */ }
.short-div input.div-input {
  width: 64px;
  border: 1.5px solid var(--teal-pill);
  border-radius: 6px;
  padding: 2px 6px;
  text-align: left;
  font: inherit;
  background: #fff;
  outline: none;
}
.short-div input.div-input.divisor-in {
  width: 36px;
  text-align: center;
  margin-right: 6px;
}
.short-div .annot {
  margin-left: 8px;
  color: var(--ink-muted);
  font-family: inherit;
  font-size: 13px;
  font-style: italic;
}

/* ---------------------------------------------------------------------
   16. Index notation diagram (base/index labels)
   --------------------------------------------------------------------- */
.index-diagram {
  display: inline-block;
  position: relative;
  text-align: center;
  margin: 10px 0;
  padding: 28px 60px;
}
.index-diagram .core {
  font-family: serif;
  font-size: 56px;
  color: var(--magenta);
  font-weight: 600;
  line-height: 1;
  position: relative;
  z-index: 1;
}
.index-diagram .core sup { font-size: .55em; }
.index-diagram .label {
  position: absolute;
  font-size: 13px;
  color: var(--magenta);
  white-space: nowrap;
}
.index-diagram .label.base  { bottom: 0; left: 50%; transform: translateX(-65%); }
.index-diagram .label.index { top: -2px; right: 0; }
.index-diagram .label.read  { left: -10px; top: 50%; transform: translate(-100%, -50%); }
.index-diagram .arrow {
  position: absolute;
  pointer-events: none;
  color: var(--magenta);
}

/* ---------------------------------------------------------------------
   17. Word lookup popover
   --------------------------------------------------------------------- */
.w {
  cursor: pointer;
  border-radius: 3px;
  transition: background .12s;
  padding: 0 1px;
}
.w.term { border-bottom: 1.5px dotted var(--magenta); }
.w.active { background: #fff3a8; }

.popover {
  position: fixed;
  z-index: 100;
  background: #fff;
  border: 1px solid #d6dee5;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  width: min(360px, calc(100vw - 24px));
  max-height: 70vh;
  overflow-y: auto;
  padding: 14px 16px 12px;
  font-size: 15px;
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.popover.show { opacity: 1; pointer-events: auto; }
.pop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.pop-word { font-size: 20px; font-weight: 700; color: var(--teal-dark); }
.pop-tier { font-size: 11px; color: #fff; padding: 2px 8px; border-radius: 8px; font-weight: 700; letter-spacing: .04em; }
.pop-tier.t1 { background: var(--magenta); }
.pop-tier.t2 { background: var(--teal-pill); }
.pop-cn { font-size: 16px; color: var(--ink); margin: 4px 0; font-weight: 600; }
.pop-note { font-size: 13px; color: var(--ink-soft); background: #f7f9fb; border-left: 3px solid var(--teal-pill); padding: 6px 10px; border-radius: 4px; margin-top: 8px; line-height: 1.5; }
.pop-example { font-size: 13px; color: #5a6776; margin-top: 6px; padding-left: 12px; border-left: 2px solid #ddd; font-style: italic; }
.pop-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pop-btn {
  flex: 1;
  min-height: 36px;
  border: 1px solid var(--teal-pill);
  background: #fff;
  color: var(--teal-dark);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 12px;
  font-family: inherit;
}
.pop-btn.primary { background: var(--teal-pill); color: #fff; }
.pop-btn:active { transform: scale(.97); }
.pop-loading { color: var(--ink-soft); font-size: 13px; margin-top: 6px; }

/* Rich-lookup panels (IPA + audio + multi-POS definitions) */
.pop-phonetic {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 6px;
  font-size: 14px;
  color: #5a6776;
}
.pop-phonetic .ipa {
  font-family: "Doulos SIL", "Charis SIL", "Lucida Sans Unicode", serif;
  font-style: italic;
  color: var(--teal-dark);
}
.pop-phonetic .audio-btn {
  background: transparent;
  border: 1px solid #d6dee5;
  border-radius: 16px;
  width: 26px;
  height: 26px;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.pop-phonetic .audio-btn:active { transform: scale(.92); }
.pop-defs {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed #e3e8ec;
}
.pop-defs-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--teal-dark);
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.pop-def-group { margin-bottom: 10px; }
.pop-def-group:last-child { margin-bottom: 0; }
.pop-pos {
  font-style: italic;
  font-size: 12px;
  color: var(--magenta);
  font-weight: 700;
  margin-bottom: 3px;
  text-transform: lowercase;
}
.pop-def {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink);
  margin: 2px 0;
}
.pop-def b { color: var(--teal-pill); margin-right: 4px; }
.pop-def-ex {
  font-size: 12.5px;
  font-style: italic;
  color: #6a7682;
  margin: 2px 0 4px 14px;
  padding-left: 8px;
  border-left: 2px solid #e3e8ec;
}
.pop-syn {
  font-size: 12px;
  color: var(--ink-soft);
  background: #f7f9fb;
  border-radius: 4px;
  padding: 4px 8px;
  margin-top: 4px;
}

.pop-close {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--ink-muted);
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
}

/* ---------------------------------------------------------------------
   18. Selection translation bar
   --------------------------------------------------------------------- */
.sel-bar {
  position: fixed;
  z-index: 99;
  background: #1f2933;
  color: #fff;
  border-radius: 22px;
  padding: 0 4px 0 14px;
  font-size: 14px;
  display: none;
  align-items: center;
  gap: 4px;
  height: 40px;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
  transform: translate(-50%, -100%);
}
.sel-bar.show { display: inline-flex; }
.sel-bar button {
  background: var(--teal-pill);
  color: #fff;
  border: none;
  border-radius: 16px;
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  margin-left: 6px;
  cursor: pointer;
  font-family: inherit;
}

/* ---------------------------------------------------------------------
   19. Self-assessment widget (✓ / ~ / ✗)
   --------------------------------------------------------------------- */
.self-assess {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  padding: 8px 10px;
  background: #f7f9fb;
  border-radius: 8px;
  font-size: 14px;
  flex-wrap: wrap;
}
.self-assess .label { font-weight: 600; color: var(--ink-soft); margin-right: 4px; }
.self-assess button {
  border: 1.5px solid #d6dee5;
  background: #fff;
  border-radius: 18px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  color: var(--ink);
}
.self-assess button.selected.right     { background: var(--correct); color: #fff; border-color: var(--correct); }
.self-assess button.selected.partial   { background: #f0a040; color: #fff; border-color: #f0a040; }
.self-assess button.selected.wrong     { background: var(--wrong); color: #fff; border-color: var(--wrong); }

/* ---------------------------------------------------------------------
   20. Concept checkpoint UI
   --------------------------------------------------------------------- */
.checkpoint-section {
  margin-top: 32px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #fff7e0, #fef0f8);
  border-radius: var(--radius-lg);
  border-left: 5px solid #f0a040;
}
.checkpoint-section h3 {
  margin: 0 0 6px;
  color: #c84a3a;
  font-size: 19px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.checkpoint-section h3::before { content: "🎯"; }
.checkpoint-section .intro { color: var(--ink-soft); font-size: 14px; margin-bottom: 14px; }
.checkpoint {
  background: #fff;
  border: 1px solid #e8d8c0;
  border-radius: 8px;
  padding: 12px 14px;
  margin: 10px 0;
}
.checkpoint .cp-num {
  display: inline-block;
  background: #f0a040;
  color: #fff;
  width: 24px; height: 24px;
  border-radius: 50%;
  text-align: center;
  line-height: 24px;
  font-size: 13px;
  font-weight: 800;
  margin-right: 8px;
  vertical-align: middle;
}
.checkpoint .cp-question { margin: 0 0 8px; font-weight: 600; }
.checkpoint .cp-options { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.checkpoint .cp-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1.5px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  background: #fff;
  font-family: inherit;
  font-size: 15px;
  text-align: left;
  width: 100%;
}
.checkpoint .cp-option:hover { background: #f7f9fb; }
.checkpoint .cp-option.selected { border-color: var(--teal-pill); background: var(--correct-bg); }
.checkpoint .cp-option.correct  { border-color: var(--correct); background: var(--correct-bg); }
.checkpoint .cp-option.wrong    { border-color: var(--wrong); background: var(--wrong-bg); }
.checkpoint .cp-option .opt-letter {
  display: inline-grid;
  place-items: center;
  width: 24px; height: 24px;
  background: #e0e0e0;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  flex-shrink: 0;
}
.checkpoint .cp-option.correct  .opt-letter { background: var(--correct); color: #fff; }
.checkpoint .cp-option.wrong    .opt-letter { background: var(--wrong); color: #fff; }
.checkpoint .cp-feedback {
  margin-top: 8px;
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 6px;
  display: none;
}
.checkpoint .cp-feedback.show { display: block; }
.checkpoint .cp-feedback.right { background: var(--correct-bg); color: var(--teal-dark); }
.checkpoint .cp-feedback.wrong { background: var(--wrong-bg); color: #8a2a20; }

/* ---------------------------------------------------------------------
   20a. Vocabulary entry card — slim link to standalone vocab module
   --------------------------------------------------------------------- */
.vocab-entry-card {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 28px 0 16px;
  padding: 16px 22px;
  background: linear-gradient(135deg, #efe7f2 0%, #fff5f8 100%);
  border-left: 5px solid var(--magenta);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--ink);
  transition: transform .12s ease, box-shadow .12s ease;
  box-shadow: 0 2px 6px rgba(192, 50, 122, .08);
}
.vocab-entry-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(192, 50, 122, .15);
}
.vocab-entry-card:active { transform: translateY(0); }
.vocab-entry-card .vec-icon {
  font-size: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.08);
}
.vocab-entry-card .vec-body { flex: 1; min-width: 0; }
.vocab-entry-card .vec-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--magenta);
  margin-bottom: 2px;
}
.vocab-entry-card .vec-sub {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.vocab-entry-card .vec-sub b { color: var(--magenta); font-weight: 800; }
.vocab-entry-card .vec-arrow {
  font-size: 22px;
  color: var(--magenta);
  font-weight: 700;
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------
   20b. Vocabulary Review (term flashcard / quiz module)
   --------------------------------------------------------------------- */
.vocab-review-section {
  margin-top: 32px;
  padding: 20px 24px 26px;
  background: linear-gradient(135deg, #efe7f2 0%, #fff5f8 100%);
  border-radius: var(--radius-lg);
  border-left: 5px solid var(--magenta);
}
.vocab-review-section h3 {
  margin: 0 0 6px;
  color: var(--magenta);
  font-size: 19px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.vocab-review-section h3::before { content: "📝"; }
.vocab-review-section .intro {
  color: var(--ink-soft);
  font-size: 14px;
  margin-bottom: 16px;
}
.vocab-review-section .intro b { color: var(--magenta); }

.vocab-due-prompt {
  background: linear-gradient(90deg, #fff5f8, #efe7f2);
  border-left: 4px solid var(--magenta);
  padding: 10px 14px;
  margin: 8px 0 16px;
  border-radius: 0 6px 6px 0;
  font-size: 14px;
  color: var(--lavender-ink);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.vocab-due-prompt .info { flex: 1; min-width: 0; }
.vocab-due-prompt b { color: var(--magenta); font-size: 16px; }
.vocab-due-prompt .vocab-jump-btn {
  background: var(--magenta);
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: 16px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.vocab-due-prompt .vocab-jump-btn:active { transform: scale(.97); }
.vocab-due-prompt .vocab-dismiss-btn {
  background: transparent;
  border: none;
  color: var(--ink-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0 8px;
  line-height: 1;
}
.vocab-due-prompt .vocab-dismiss-btn:hover { color: var(--ink); }

.vocab-review-section .round-badge {
  display: inline-block;
  background: var(--magenta);
  color: #fff;
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .03em;
  margin: 4px 0 10px;
}

.vocab-q {
  background: #fff;
  border: 1px solid #e0d0e8;
  border-radius: 10px;
  padding: 14px 16px 14px 22px;
  margin: 12px 0;
  position: relative;
}
.vocab-q .q-num {
  position: absolute;
  top: -10px;
  left: 14px;
  background: var(--magenta);
  color: #fff;
  width: 24px; height: 24px;
  border-radius: 50%;
  text-align: center;
  line-height: 24px;
  font-size: 13px;
  font-weight: 800;
}
.vocab-q .q-prompt {
  margin: 4px 0 12px;
  font-size: 16px;
  color: var(--ink);
  line-height: 1.55;
}
.vocab-q .q-prompt b {
  color: var(--magenta);
  font-size: 18px;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
}
.vocab-q .vq-source {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-right: 8px;
  letter-spacing: .03em;
  vertical-align: middle;
  font-family: -apple-system, sans-serif;
  font-style: normal;
  color: #fff;
}
.vocab-q .vq-source.math { background: var(--magenta); }
.vocab-q .vq-source.personal { background: #2092c4; }
.vocab-q .q-prompt .hint {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--ink-soft);
  font-style: italic;
}

.vocab-q .q-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0;
}
@media (max-width: 600px) {
  .vocab-q .q-options { grid-template-columns: 1fr; }
}
.vocab-q .vq-option {
  padding: 10px 14px;
  border: 1.5px solid #d6c8e0;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 14.5px;
  text-align: left;
  color: var(--ink);
  transition: background .12s;
}
.vocab-q .vq-option:hover:not(:disabled) {
  background: #f7eef9;
  border-color: var(--magenta);
}
.vocab-q .vq-option:disabled { cursor: default; }
.vocab-q .vq-option.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
  color: var(--teal-dark);
  font-weight: 700;
}
.vocab-q .vq-option.wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong);
  color: #8a2a20;
  font-weight: 700;
}

.vocab-q .q-input-row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}
.vocab-q .vq-input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid #d6c8e0;
  border-radius: 8px;
  font: inherit;
  font-size: 15px;
}
.vocab-q .vq-input:focus {
  outline: none;
  border-color: var(--magenta);
  background: #fff5f8;
}
.vocab-q .vq-input.right {
  border-color: var(--correct);
  background: var(--correct-bg);
  color: var(--teal-dark);
  font-weight: 700;
}
.vocab-q .vq-input.barely {
  border-color: #f0a040;
  background: #fff7e0;
  color: #c87a20;
  font-weight: 700;
}
.vocab-q .vq-input.wrong {
  border-color: var(--wrong);
  background: var(--wrong-bg);
  color: #8a2a20;
}
.vocab-q .vq-submit {
  background: var(--magenta);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.vocab-q .vq-submit:disabled { background: #c8b4d8; cursor: default; }

.vocab-q .q-feedback {
  display: none;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.55;
}
.vocab-q .q-feedback.show { display: block; }
.vocab-q .q-feedback.right { background: var(--correct-bg); color: var(--teal-dark); }
.vocab-q .q-feedback.barely { background: #fff7e0; color: #c87a20; border-left: 3px solid #f0a040; padding-left: 10px; }
.vocab-q .q-feedback.wrong { background: var(--wrong-bg); color: #8a2a20; }
.vocab-q .q-feedback b { color: var(--magenta); }
.vocab-q .q-feedback i { color: inherit; font-style: italic; }

.vocab-summary {
  margin-top: 18px;
  padding: 12px 16px;
  background: #fff;
  border: 1.5px solid var(--magenta);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-weight: 600;
}
.vocab-summary .score {
  color: var(--magenta);
  font-size: 16px;
}
.vocab-summary .score b { font-size: 22px; }
.vocab-regen-btn {
  background: var(--magenta);
  color: #fff;
  border: none;
  border-radius: 22px;
  padding: 9px 18px;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.vocab-regen-btn:active { transform: scale(.97); }

/* ---------------------------------------------------------------------
   21. Confirm modal
   --------------------------------------------------------------------- */
.confirm-mask {
  position: fixed; inset: 0;
  background: rgba(15,20,25,.5);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.confirm-mask.show { display: flex; }
.confirm-box {
  background: #fff;
  border-radius: 14px;
  padding: 22px 22px 18px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-modal);
}
.confirm-box h3 { margin: 0 0 8px; font-size: 17px; color: var(--ink); }
.confirm-box p { margin: 0 0 16px; font-size: 14px; color: var(--ink-soft); line-height: 1.6; }
.confirm-actions { display: flex; gap: 8px; }
.confirm-actions button {
  flex: 1;
  height: 40px;
  border-radius: 8px;
  border: 1px solid #d6dee5;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.confirm-actions .primary { background: var(--think-yellow); border-color: #d9a93a; color: var(--think-ink); }

/* ---------------------------------------------------------------------
   22. Toast / progressive hint
   --------------------------------------------------------------------- */
.answer-toast {
  position: fixed;
  z-index: 110;
  background: #1f2933;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-pop);
  transform: translate(-50%, -100%);
  opacity: 0;
  transition: opacity .2s;
  max-width: 280px;
  line-height: 1.5;
}
.answer-toast.show { opacity: 1; }
.answer-toast::after {
  content: "";
  position: absolute;
  bottom: -6px; left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1f2933;
  border-bottom: 0;
}
.answer-toast .level { font-size: 11px; color: var(--think-yellow); margin-bottom: 4px; letter-spacing: .04em; }
.answer-toast .level .dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #555; margin: 0 2px; }
.answer-toast .level .dot.on { background: var(--think-yellow); }

/* ---------------------------------------------------------------------
   23. Sample answer panel (English-first 30s gate)
   --------------------------------------------------------------------- */
.sample-answer {
  background: #fff7e0;
  border-left: 4px solid var(--think-yellow);
  padding: 12px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 8px 0 14px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--think-ink);
}
.sample-answer.hidden { display: none; }
.sample-answer b { color: var(--magenta); }
.sample-en {
  background: #fffbed;
  border: 1px solid #f0d77a;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--lavender-ink);
}
.sample-en .lang-label, .sample-cn .lang-label {
  display: inline-block;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 8px;
  margin-right: 6px; letter-spacing: .04em;
  color: #fff;
}
.sample-en .lang-label { background: var(--teal-pill); }
.sample-cn .lang-label { background: var(--magenta); }
.sample-cn-gate {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 0;
}
.sample-cn-gate .countdown {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1.5px solid var(--think-yellow);
  color: var(--think-ink);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
}
.sample-cn-gate .countdown b { color: var(--wrong); }
.sample-cn-gate .unlock-btn {
  display: none;
  background: var(--teal-pill);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.sample-cn-gate.unlocked .countdown { display: none; }
.sample-cn-gate.unlocked .unlock-btn { display: inline-flex; align-items: center; gap: 4px; }
.sample-cn {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--magenta-light);
  border: 1px solid var(--magenta-border);
  border-radius: 6px;
  font-size: 15px;
  color: var(--lavender-ink);
}
.sample-cn.hidden { display: none; }

/* Reveal button + lock state */
.reveal-btn, .check-btn {
  border: none;
  border-radius: 22px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.check-btn { background: var(--teal-pill); color: #fff; }
.check-btn:active { transform: scale(.97); }
.reveal-btn { background: #fff; color: var(--magenta); border: 1.5px solid var(--magenta-border); }
.reveal-btn:active { transform: scale(.97); }
.reveal-btn.locked {
  background: #f1f3f6;
  border-color: #d6dee5;
  color: var(--ink-muted);
  cursor: not-allowed;
}
.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 8px 0 14px;
}
.check-result { font-size: 14px; font-weight: 600; color: var(--ink-soft); }
.check-result.all-right { color: var(--correct); }
.check-result.has-wrong { color: var(--wrong); }
.lock-hint { font-size: 12px; color: var(--ink-muted); margin-left: 6px; }

/* ---------------------------------------------------------------------
   24. Peek counter (top-right corner)
   --------------------------------------------------------------------- */
.peek-counter {
  position: fixed;
  top: 8px; right: 12px;
  background: rgba(255,247,224,.95);
  border: 1px solid var(--think-yellow);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  color: var(--think-ink);
  z-index: 40;
  font-weight: 600;
}
.peek-counter.warn { background: var(--wrong-bg); border-color: var(--spotlight-border); color: #8a2a20; }

/* ---------------------------------------------------------------------
   25. Bottom controls
   --------------------------------------------------------------------- */
.controls {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,.95);
  backdrop-filter: blur(8px);
  border: 1px solid #dde3eb;
  border-radius: 28px;
  padding: 6px 8px;
  display: flex;
  gap: 6px;
  box-shadow: 0 6px 20px rgba(0,0,0,.1);
  z-index: 50;
  font-size: 13px;
}
.controls button {
  background: transparent;
  border: none;
  padding: 8px 14px;
  border-radius: 22px;
  font-size: 13px;
  color: #2d3e50;
  cursor: pointer;
  font-weight: 600;
  font-family: inherit;
}
.controls button.on { background: var(--teal-pill); color: #fff; }

/* Idle-pause overlay */
.idle-mask {
  position: fixed; inset: 0;
  z-index: 150;
  background: rgba(15,20,25,.7);
  display: none;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.idle-mask.show { display: flex; }
.idle-mask .msg {
  text-align: center;
  background: #fff;
  color: var(--ink);
  padding: 24px 32px;
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.6;
}
.idle-mask .msg b { color: var(--teal); }

/* ---------------------------------------------------------------------
   26. Hint banner (top of page)
   --------------------------------------------------------------------- */
.hint-banner {
  background: linear-gradient(90deg, #fff7e0, #fef0f8);
  border-left: 4px solid var(--think-yellow);
  padding: 10px 14px;
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--think-ink);
  border-radius: 0 6px 6px 0;
}
.hint-banner b { color: var(--magenta); }

/* ---------------------------------------------------------------------
   27. Helpers
   --------------------------------------------------------------------- */
.nowrap { white-space: nowrap; }
.muted { color: var(--ink-muted); }
.center { text-align: center; }
.tight { margin: 0; }
.hidden { display: none !important; }

/* KaTeX adjustments */
.katex { font-size: 1.05em; }
.katex-display { margin: 8px 0; }

/* ---------------------------------------------------------------------
   28. Dark mode
   --------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d;
    --page: #1c2127;
    --ink: #d8dee5;
    --ink-soft: #aab4bf;
    --ink-muted: #6c7884;
    --activity-bg: #2a2438;
    --lavender: #2c2236;
    --lavender-border: #4d3d5d;
    --lavender-ink: #e6dcef;
    --think-bg: #3a3018;
    --spotlight-bg: #3a1a1a;
    --spotlight-border: #6a3030;
    --recall-bg: #1a2a3a;
    --recall-border: #2a4a6a;
    --extra-bg: #1a2a18;
    --extra-border: #2a4a28;
    --discuss-bg: #2a2010;
    --discuss-border: #4a3818;
    --coding-bg: #1a1f2a;
    --coding-border: #2a3848;
    --notation-bg: #2a2510;
    --notation-border: #4a4218;
    --equiv-bg: #251a35;
    --equiv-border: #3a2858;
    --correct-bg: #1a2a22;
    --wrong-bg: #2a1a1a;
  }
  .dm-table { background: #1c2127; }
  .dm-table tr:nth-child(even) td { background: #20272d; }
  .popover { background: #1c2127; color: var(--ink); border-color: #3a4451; }
  .pop-note { background: #20272d; }
  .pop-defs { border-top-color: #2a3038; }
  .pop-def-ex { border-left-color: #2a3038; color: #99a6b3; }
  .pop-syn { background: #20272d; }
  .pop-phonetic .audio-btn { border-color: #3a4451; color: var(--ink); }
  .checkpoint-section { background: linear-gradient(135deg, #2a2510, #2a1a25); }
  .checkpoint { background: #1c2127; border-color: #3a3025; }
  .checkpoint .cp-option { background: #1c2127; border-color: #2a3038; color: var(--ink); }
  .checkpoint .cp-option:hover { background: #20272d; }
  .blank { color: #82d8b4; }
  .factor-tree svg circle { fill: #1c2127; stroke: #80a8c8; }
  .factor-tree svg line { stroke: #80a8c8; }
  .factor-tree svg text { fill: var(--ink); }
}
