/* ─────────────────────────────────────────────────────────────────────── */
/* Phase 7 — Pre-teach + I-Need-Help tutor styles (STUD-16, STUD-18).      */
/* Calm cream-on-dark-gray palette per DSGN-01..05 — no decorative fills. */
/* ─────────────────────────────────────────────────────────────────────── */

/* Pre-teach block (07-02 Task 1) */
.preteach-block {
  background: var(--color-bg, #f7f3ec);
  border: 1px solid var(--color-border, #d8d2c5);
  border-radius: var(--radius-md, 12px);
  padding: 20px 22px;
  margin: 0 0 20px 0;
}
.preteach-block__heading {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0 0 8px 0;
}
.preteach-block__subheading {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 16px 0 6px 0;
  color: var(--color-text-secondary, #5a5448);
}
.preteach-overview {
  margin: 0 0 4px 0;
  font-size: 0.9375rem;
  line-height: 1.55;
}
.preteach-vocab {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 12px;
  row-gap: 6px;
  margin: 0;
  padding: 0;
}
.preteach-vocab dt {
  font-weight: 600;
}
.preteach-vocab dd {
  margin: 0;
}
.preteach-watchlist {
  margin: 0;
  padding-left: 20px;
}
.preteach-watchlist li {
  margin-bottom: 4px;
}
.preteach-primer {
  margin: 12px 0 0 0;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--color-text-secondary, #5a5448);
}
.preteach-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Teacher approval queue */
.preteach-approval-queue {
  background: var(--color-bg, #f7f3ec);
  border: 1px solid var(--color-border, #d8d2c5);
  border-radius: var(--radius-md, 12px);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.preteach-approval-queue__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.preteach-approval-queue__title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.preteach-approval-queue__badge {
  background: var(--color-blue, #2c6da3);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full, 999px);
  padding: 2px 10px;
}
.preteach-approval-queue__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.preteach-approval-queue__item {
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-sm, 8px);
  padding: 12px 14px;
  background: #fff;
}
.preteach-approval-queue__overview {
  margin: 0 0 8px 0;
  font-size: 0.9375rem;
}
.preteach-approval-queue__vocab {
  list-style: disc;
  padding-left: 20px;
  margin: 0 0 10px 0;
  font-size: 0.875rem;
}
.preteach-approval-queue__actions {
  display: flex;
  gap: 8px;
}

/* I-Need-Help widget (07-02 Task 2c) */
.ai-help-widget {
  display: block;
  margin-top: 12px;
}
.ai-help-widget [data-help-toggle] {
  font-size: 0.875rem;
  background: transparent;
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-full, 999px);
  padding: 6px 12px;
  cursor: pointer;
  color: var(--color-text-primary, #2a2521);
}
.ai-help-widget [data-help-toggle]:hover {
  background: var(--color-bg, #f7f3ec);
}
.ai-help-panel {
  margin-top: 10px;
  background: var(--color-bg, #f7f3ec);
  border: 1px solid var(--color-border, #d8d2c5);
  border-radius: var(--radius-md, 12px);
  padding: 14px 16px;
}
.ai-help-panel fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 8px 0;
}
.ai-help-panel legend {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-secondary, #5a5448);
  margin-bottom: 4px;
}
.ai-help-panel label {
  margin-right: 12px;
  font-size: 0.875rem;
}
.ai-help-panel textarea[data-help-selection] {
  width: 100%;
  min-height: 60px;
  font-family: inherit;
  font-size: 0.9375rem;
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-sm, 8px);
  padding: 8px 10px;
  margin: 6px 0;
  resize: vertical;
}
.ai-help-panel [data-help-submit] {
  font-size: 0.875rem;
  border: 0;
  background: var(--color-blue, #2c6da3);
  color: #fff;
  border-radius: var(--radius-full, 999px);
  padding: 6px 14px;
  cursor: pointer;
}
.ai-help-output {
  margin-top: 10px;
  font-size: 0.9375rem;
  line-height: 1.55;
  white-space: pre-wrap;
  min-height: 1.5em;
}

/* Loading indicator while the tutor generates — gentle pulse, ND-safe (no spin,
   no flash). Inserted by ai-help.js on Ask, replaced by the answer. */
.ai-help-thinking {
  color: var(--color-text-secondary, #5a5448);
  font-style: italic;
}
.ai-help-thinking__dots {
  display: inline-block;
  margin-left: 2px;
}
.ai-help-thinking__dot {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.25;
  animation: ai-help-dot-pulse 1.4s ease-in-out infinite;
}
.ai-help-thinking__dot:nth-child(2) { animation-delay: 0.2s; }
.ai-help-thinking__dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-help-dot-pulse {
  0%, 60%, 100% { opacity: 0.25; }
  30%           { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .ai-help-thinking__dot { animation: none; opacity: 0.6; }
}
.ai-help-anchor {
  margin: 8px 0 0 0;
  font-size: 0.8125rem;
  color: var(--color-text-secondary, #5a5448);
  font-style: italic;
}
.ai-help-anchor:empty {
  display: none;
}
.ai-help-cooldown {
  font-size: 0.8125rem;
  color: var(--color-text-secondary, #5a5448);
  background: #fff8e1;
  border: 1px solid #ecd9a3;
  border-radius: var(--radius-sm, 8px);
  padding: 6px 10px;
  margin-top: 8px;
}

/* ─────────────────────────────────────────────────────────────────────── */
/* Phase 13 — Advance Organizer + Term Cards + Micro-Check styles          */
/* (ORG-09, ORG-10, ORG-11, ORG-12, ORG-14)                               */
/* Append-only: never modify existing .preteach-* rules above.             */
/* Design tokens only — no hardcoded hex colors or px font sizes.          */
/* ─────────────────────────────────────────────────────────────────────── */

/* Organizer block wrapper */
.organizer-block {
  background: var(--color-bg, #f7f3ec);
  border: 1px solid var(--color-border, #d8d2c5);
  border-radius: var(--radius-md, 12px);
  padding: 20px 22px;
  margin: 0 0 20px 0;
}
.organizer-block__subheading {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 16px 0 6px 0;
  color: var(--color-text-secondary, #5a5448);
}

/* Schema-frame ribbon (ORG-09) */
.organizer-ribbon {
  margin-bottom: 16px;
}
.organizer-ribbon__heading {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 0 0 8px 0;
}
.organizer-ribbon__frame {
  margin: 0 0 8px 0;
}
.organizer-ribbon__frame-name {
  margin: 0 0 4px 0;
  font-size: 0.9375rem;
}
.organizer-ribbon__prior-hook,
.organizer-ribbon__move-ahead {
  margin: 0 0 4px 0;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--color-text-secondary, #5a5448);
}
.organizer-ribbon__anxiety {
  margin: 8px 0 0 0;
  font-size: 0.875rem;
  font-style: italic;
  color: var(--color-text-secondary, #5a5448);
}

/* Organizer body (kind-specific sections) */
.organizer-body {
  margin-bottom: 12px;
}
.organizer-what-to-look-for {
  margin-bottom: 12px;
}
.organizer-watchlist {
  margin: 0;
  padding-left: 20px;
}
.organizer-watchlist li {
  margin-bottom: 4px;
  font-size: 0.9375rem;
}

/* Worked example skeleton (problem_schema extended only) */
.organizer-worked-example {
  margin-top: 12px;
  border-top: 1px solid var(--color-border, #d8d2c5);
  padding-top: 10px;
}
.organizer-worked-example__steps {
  margin: 0;
  padding-left: 20px;
}
.organizer-worked-example__step {
  margin-bottom: 8px;
}

/* Narrative arc (ORG-10) */
.organizer-narrative__beat {
  margin: 0 0 10px 0;
  font-size: 0.9375rem;
  line-height: 1.55;
}
.organizer-narrative__nodes {
  margin: 0;
  padding-left: 20px;
}
.organizer-narrative__node {
  margin-bottom: 8px;
  font-size: 0.9375rem;
}
.organizer-narrative__node-summary {
  display: block;
  color: var(--color-text-secondary, #5a5448);
  font-size: 0.875rem;
}

/* Problem schema (ORG-10) */
.organizer-problem-schema__type,
.organizer-problem-schema__goal {
  margin: 0 0 8px 0;
  font-size: 0.9375rem;
}
.organizer-problem-schema__label {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 12px 0 4px 0;
  color: var(--color-text-secondary, #5a5448);
}
.organizer-problem-schema__givens {
  margin: 0 0 8px 0;
  padding-left: 20px;
  font-size: 0.9375rem;
}

/* Concept map (ORG-10, D-26 no-SVG) */
.organizer-concept-map {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.organizer-concept-map__hub {
  background: var(--color-blue, #2c6da3);
  color: #fff;
  border-radius: var(--radius-md, 12px);
  padding: 12px 16px;
  text-align: center;
}
.organizer-concept-map__hub-label {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}
.organizer-concept-map__spokes {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
@media (min-width: 640px) {
  .organizer-concept-map__spokes { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .organizer-concept-map__spokes { grid-template-columns: repeat(3, 1fr); }
}
.organizer-concept-map__spoke {
  background: var(--color-bg, #f7f3ec);
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-sm, 8px);
  padding: 10px 12px;
}
.organizer-concept-map__spoke-label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.organizer-concept-map__spoke-relation {
  display: block;
  font-size: 0.875rem;
  color: var(--color-text-secondary, #5a5448);
}

/* Timeline (ORG-10, organizer-timeline__* — collision-isolated from STUD-17) */
.organizer-timeline {
  margin: 0;
}
.organizer-timeline__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.organizer-timeline__event {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.organizer-timeline__when {
  flex-shrink: 0;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-secondary, #5a5448);
  min-width: 5rem;
}
.organizer-timeline__body {
  flex: 1;
}
.organizer-timeline__label {
  margin: 0 0 2px 0;
  font-size: 0.9375rem;
}
.organizer-timeline__significance {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-text-secondary, #5a5448);
  line-height: 1.45;
}

/* Term card grid (ORG-11, ORG-14 — Responsive Grid Contract) */
.term-card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin: 12px 0;
}
@media (min-width: 640px) {
  .term-card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .term-card-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Term card */
.term-card {
  background: #fff;
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-sm, 8px);
  padding: 12px 14px;
  position: relative;
}
.term-card--anchored {
  border-left: 3px solid var(--color-blue, #2c6da3);
}
.term-card__face {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.term-card__badge {
  display: inline-block;
  background: var(--color-blue, #2c6da3);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  border-radius: var(--radius-full, 999px);
  padding: 2px 8px;
  align-self: flex-start;
  transition: background-color 200ms ease;
}
.term-card__badge.is-highlighted {
  background: var(--color-orange, #e07030);
}
@media (prefers-reduced-motion: reduce) {
  .term-card__badge { transition: none; }
}
.term-card__term {
  font-size: 1rem;
  font-weight: 700;
}
.term-card__def {
  margin: 0;
  font-size: 0.875rem;
  color: var(--color-text-secondary, #5a5448);
  line-height: 1.45;
}
.term-card__audio-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-full, 999px);
  padding: 4px 10px;
  font-size: 0.8125rem;
  cursor: pointer;
  min-height: 44px;
  color: var(--color-text-primary, #2a2521);
}
.term-card__audio-btn:focus-visible {
  outline: 2px solid var(--color-blue, #2c6da3);
  outline-offset: 2px;
}
.term-card__expand-btn {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-full, 999px);
  padding: 4px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
  margin-top: 4px;
  min-height: 44px;
  color: var(--color-text-primary, #2a2521);
}
.term-card__expand-btn:focus-visible {
  outline: 2px solid var(--color-blue, #2c6da3);
  outline-offset: 2px;
}
.term-card__body {
  margin-top: 10px;
  border-top: 1px solid var(--color-border, #d8d2c5);
  padding-top: 8px;
  font-size: 0.875rem;
  line-height: 1.5;
}
.term-card__body p {
  margin: 0 0 6px 0;
}
.term-card__morphology {
  color: var(--color-text-secondary, #5a5448);
  font-style: italic;
}

/* Organizer micro-check (ORG-12) */
.organizer-microcheck {
  border-top: 1px solid var(--color-border, #d8d2c5);
  margin-top: 16px;
  padding-top: 16px;
}
.organizer-microcheck__heading {
  font-size: 1rem;
  font-weight: 700;
  margin: 0 0 6px 0;
}
.organizer-microcheck__question {
  margin: 0 0 12px 0;
  font-size: 0.9375rem;
}
.organizer-microcheck__choices {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.organizer-microcheck__choice {
  flex: 1 1 auto;
  min-width: 80px;
  min-height: 44px;
  background: var(--color-bg, #f7f3ec);
  border: 1px solid var(--color-border-md, #c8c1b0);
  border-radius: var(--radius-sm, 8px);
  padding: 8px 12px;
  font-size: 0.9375rem;
  cursor: pointer;
  color: var(--color-text-primary, #2a2521);
  transition: background-color 150ms ease, border-color 150ms ease;
}
.organizer-microcheck__choice:focus-visible {
  outline: 2px solid var(--color-blue, #2c6da3);
  outline-offset: 2px;
}
.organizer-microcheck__choice.is-selected {
  background: var(--color-blue, #2c6da3);
  border-color: var(--color-blue, #2c6da3);
  color: #fff;
}
@media (prefers-reduced-motion: reduce) {
  .organizer-microcheck__choice { transition: none; }
}
.organizer-microcheck__foggy-hint {
  margin: 0 0 10px 0;
  font-size: 0.875rem;
  color: var(--color-text-secondary, #5a5448);
}
.organizer-microcheck__foggy-hint a {
  color: var(--color-blue, #2c6da3);
}
.organizer-microcheck__actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
/* Honor the [hidden] attribute: the display:flex above would otherwise
   override the UA's [hidden]{display:none}, revealing Skip / "I'm ready"
   before any readiness tap (found in 13-04 live verify). */
.organizer-microcheck__actions[hidden],
.preteach-actions[hidden] {
  display: none;
}

/* D-31 anchor-badge counterpart pulse (Wave 3 .is-highlighted toggle) */
/* Both .term-card__badge and organizer node [data-anchor-badge] use this transition */
[data-anchor-badge] {
  transition: background-color 200ms ease;
}
[data-anchor-badge].is-highlighted {
  background-color: var(--color-orange, #e07030);
  color: #fff;
}
@media (prefers-reduced-motion: reduce) {
  [data-anchor-badge] { transition: none; }
}

/* ─────────────────────────────────────────────────────────────────────── */
/* Phase 13 Wave 3 — Sticky term-chip strip + chip popovers (ORG-13, D-33, D-34) */
/* Append-only: no Wave-2 or Phase-7 rules modified above this line.      */
/* ─────────────────────────────────────────────────────────────────────── */

/* D-25 first-step gate rule: hide the first step until JS removes data-step-gated on
   organizer dismiss. JS removes the attribute; the step then renders normally. */
.lesson-step[data-step-gated] {
  display: none;
}

/* Strip container — slim sticky row atop the lesson player (D-33) */
.organizer-strip {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--color-bg, #f7f3ec);
  border-bottom: 1px solid var(--color-border, #d8d2c5);
  padding: 8px 16px;
}

/* Inner scrollable chip row — horizontal scroll when 5–7 chips (D-33) */
.organizer-strip__chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Prevent scrollbar from adding layout height on macOS overlaid scrollbars */
  scrollbar-width: none;
}
.organizer-strip__chips::-webkit-scrollbar {
  display: none;
}

/* Term chip — pill button, 44px touch target (UI-SPEC Accessibility Contract) */
.term-chip {
  flex: 0 0 auto;
  min-height: 44px;
  border-radius: var(--radius-full, 999px);
  border: 1px solid var(--color-border, #d8d2c5);
  background: var(--color-surface, #fff);
  padding: 0 16px;
  white-space: nowrap;
  font-size: 0.875rem;
  color: var(--color-text-primary, #2a2521);
  cursor: pointer;
  /* NOTE: no position:relative here — the popover is a SIBLING of the chip
     (a <button> cannot contain interactive descendants), so the chip can never
     be its containing block. Anchoring is done in JS (positionTermPopover). */
}

/* View-overview chip — visually distinguishable from term chips via font-weight;
   no accent fill (accent reserved list per UI-SPEC) */
.organizer-strip__view-overview {
  font-weight: 600;
  border-style: dashed;
}

/* Term chip popover — containing block is .organizer-strip (position:sticky).
   The popover sits inside the overflow-x:auto chips row but escapes its clip
   because its containing block is OUTSIDE the scroller. Horizontal anchoring
   under the tapped chip is computed in JS (positionTermPopover in
   ai-preteach.js) — left:0 here is only the pre-JS fallback.
   max-width clamps to viewport edge on 320px so no horizontal page overflow occurs. */
.term-chip__popover {
  position: absolute;
  /* Place below the chips row with a small gap */
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  /* Viewport-clamped width: respects 320px screens (Pitfall 4 / UI-SPEC) */
  max-width: min(280px, calc(100vw - 32px));
  width: max-content;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #d8d2c5);
  border-radius: var(--radius-md, 12px);
  padding: 12px;
  /* Ensure popover sits above other page content */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* Popover content text — rem-based, inherits font-size-scale (ORG-14) */
.term-chip__popover-def {
  margin: 0 0 8px 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-text-primary, #2a2521);
}

/* Popover example paragraph — hidden until data-chip-more is tapped (D-34) */
.term-chip__popover-example {
  margin: 6px 0 0 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--color-text-secondary, #5a5448);
}

/* Popover action buttons — minimum 44×44 touch targets (UI-SPEC Accessibility) */
.term-chip__popover [data-term-audio],
.term-chip__popover [data-chip-more],
.term-chip__popover [data-chip-close] {
  min-height: 44px;
  min-width: 44px;
  background: transparent;
  border: 1px solid var(--color-border, #d8d2c5);
  border-radius: var(--radius-full, 999px);
  padding: 4px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
  color: var(--color-text-primary, #2a2521);
  margin-top: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Focus-visible ring: chips and popover buttons (UI-SPEC Accessibility Contract) */
.term-chip:focus-visible,
.term-chip__popover button:focus-visible {
  outline: 2px solid var(--color-accent, var(--color-blue, #2c6da3));
  outline-offset: 2px;
}

/* D-31 .is-highlighted — applied by JS anchor-badge pulse. Reuses the
   background-color transition already declared on [data-anchor-badge] above
   so no new keyframes are needed (DSGN-05 motion constraint). The JS adds
   this class then removes it via setTimeout after ~1s. */
.is-highlighted {
  background-color: var(--color-orange, #e07030) !important;
  color: #fff !important;
}

/* Reduced-motion guard: make the .is-highlighted pulse instantaneous for
   users who have prefers-reduced-motion enabled (DSGN-05). The transition:none
   block already covers [data-anchor-badge] above; the broader selector here
   covers any future elements that receive .is-highlighted. */
@media (prefers-reduced-motion: reduce) {
  .is-highlighted {
    transition: none;
  }
}
