/* Shared Ctrl+; answer peek: fixed top slot, no layout jitter.
   Host must use .practice-peek-host. Toggle .is-peek-open on the host. */

.practice-peek-host {
  --practice-peek-slot-height: min(34vh, 13.5rem);
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

/* Tailwind .hidden loses to .practice-peek-host { display:flex }; force hide */
.practice-peek-host.hidden,
.practice-peek-host.is-view-hidden {
  display: none !important;
}

.practice-answer-slot {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: var(--practice-peek-slot-height);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.5rem;
  box-sizing: border-box;
  pointer-events: none;
}

.practice-answer-slot .practice-answer-card,
.practice-answer-slot > [id$="-answer-card"],
#phrase-answer-card,
#scene-answer-card,
#answer-presentation {
  display: flex;
  justify-content: center;
  width: 100%;
  max-height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: rgb(71 85 105) transparent;
}

.practice-peek-panel {
  width: fit-content;
  max-width: min(94vw, 86rem);
  margin-inline: auto;
  border: 1px solid rgb(55 57 66);
  border-radius: 0.875rem;
  background: rgba(22, 22, 30, 0.96);
  padding: 0.55rem 0.65rem 0.5rem;
  backdrop-filter: blur(8px);
  text-align: center;
}

.practice-peek-host.is-peek-open > .practice-answer-slot {
  pointer-events: auto;
}

.practice-peek-host.is-peek-open .practice-answer-card,
.practice-peek-host.is-peek-open > .practice-answer-slot > [id$="-answer-card"],
.practice-peek-host.is-peek-open #phrase-answer-card,
.practice-peek-host.is-peek-open #scene-answer-card,
.practice-peek-host.is-peek-open #answer-presentation {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.practice-peek-host > .practice-practice-body,
.practice-peek-host > .phrase-practice-body {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
}

/* Permanently reserve the peek band above the typing stage so the (opaque)
   answer panel can never cover the Chinese prompt. Applied always — not on
   peek open — so there is zero layout jitter. Video lessons keep the old
   overlay-on-video behaviour (fitDockBlanks owns their vertical budget). */
.practice-peek-host > .phrase-practice-body {
  padding-top: var(--practice-peek-slot-height);
}

#phrase-practice-shell.is-video-lesson .practice-peek-host > .phrase-practice-body {
  padding-top: 0;
}

/* Text lessons also use the fixed-height dock now (参考产品式 in-place
   swap); the peek panel overlays the dock slot instead of reserving a band. */
#phrase-practice-shell .practice-peek-host > .phrase-practice-body {
  padding-top: 0;
}

/* 参考产品 layout (2026-09-05): prompt + blanks live at the BOTTOM of the
   stage permanently, the Ctrl+; hint band lives directly under the progress
   bar. Nothing moves when peeking — zero jitter, no slide compensation.
   The dock shrinks so its top clears the hint band (~120px cards). */
#phrase-practice-shell:not(.is-video-lesson) .practice-peek-host > .phrase-practice-body {
  justify-content: flex-end;
  padding-bottom: 1.5rem;
}

#phrase-practice-shell:not(.is-video-lesson) .phrase-practice-dock {
  --phrase-dock-h: min(40vh, 21.5rem);
  padding-top: 0.75rem;
}

#phrase-practice-shell:not(.is-video-lesson) .phrase-dock-slot {
  height: min(26vh, 13.5rem);
  min-height: min(26vh, 13.5rem);
  max-height: min(26vh, 13.5rem);
  flex-basis: min(26vh, 13.5rem);
}

#phrase-practice-shell:not(.is-video-lesson) .practice-answer-slot {
  top: 0.5rem;
  bottom: auto;
  height: auto;
  max-height: 34vh;
  padding-top: 0;
  align-items: flex-start;
  justify-content: center;
}

/* Grammar cards (completion + peek share structure; peek overrides size) */
.grammar-card-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 0.75rem 1.1rem;
  width: 100%;
  max-width: 62rem;
  margin: 0 auto;
}

.grammar-card {
  position: relative;
  min-width: 6rem;
  max-width: 10.5rem;
  padding-top: 0.65rem;
}

.grammar-card__badge {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.25;
  color: #fff;
  background: var(--grammar-color);
  box-shadow: 0 0 0 2px #000;
  white-space: nowrap;
}

.grammar-card__body {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1.5px solid var(--grammar-color);
  border-radius: 1.125rem;
  background: rgba(255, 255, 255, 0.02);
  padding: 1.25rem 0.85rem 0.85rem;
  min-height: 10.5rem;
  width: 100%;
  box-sizing: border-box;
}

.grammar-card__ipa {
  min-height: 1.15rem;
  font-size: 0.875rem;
  line-height: 1.2;
  font-weight: 400;
  color: #94a3b8;
  letter-spacing: 0.01em;
}

.grammar-card__word {
  margin-top: 0.5rem;
  border: none;
  background: transparent;
  font-size: clamp(2rem, 4.8vh, 3rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
}

.grammar-card__word:hover { opacity: 0.9; }

.grammar-card__bar {
  margin-top: 0.55rem;
  height: 3px;
  width: 100%;
  border-radius: 999px;
  background: var(--grammar-color);
  opacity: 1;
}

.grammar-card__zh {
  margin-top: 0.6rem;
  max-width: 100%;
  text-align: center;
  font-size: 0.9375rem;
  line-height: 1.3;
  font-weight: 500;
  color: #e2e8f0;
}

.grammar-card__pos {
  margin-top: 0.22rem;
  font-size: 0.8125rem;
  line-height: 1.25;
  color: #64748b;
}

.grammar-card--plain .grammar-card__body {
  border-color: rgba(148, 163, 184, 0.45);
}

.grammar-card--plain .grammar-card__word {
  color: #ffffff;
}

.grammar-card--plain .grammar-card__ipa,
.grammar-card--plain .grammar-card__zh {
  color: #94a3b8;
}

.grammar-card--plain .grammar-card__bar {
  background: rgba(148, 163, 184, 0.55);
}

.grammar-card-grid--peek {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: center;
  gap: 0.45rem 0.55rem;
  width: max-content;
  max-width: none;
  margin: 0 auto;
  padding-bottom: 0.15rem;
}

.grammar-card--peek {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  min-width: 4.35rem;
  max-width: 6.25rem;
  padding-top: 0.55rem;
}

.grammar-card--peek.grammar-card--wide {
  min-width: 5.35rem;
  max-width: 7.5rem;
}

.grammar-card--peek .grammar-card__body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  min-height: 5.35rem;
  padding: 0.7rem 0.45rem 0.55rem;
  border-radius: 0.8rem;
  box-sizing: border-box;
}

.grammar-card--peek .grammar-card__ipa {
  min-height: 0.85rem;
  font-size: 0.6875rem;
  line-height: 1.15;
  color: #94a3b8;
}

.grammar-card--peek .grammar-card__word {
  margin-top: 0.28rem;
  font-size: 1.125rem;
  line-height: 1.1;
  color: #ffffff;
  white-space: nowrap;
}

.grammar-card--peek .grammar-card__bar {
  margin-top: auto;
  height: 2px;
}

.grammar-card--peek .grammar-card__zh {
  margin-top: 0.32rem;
  font-size: 0.6875rem;
  line-height: 1.2;
  color: #e2e8f0;
}

.grammar-card--peek .grammar-card__pos {
  margin-top: 0.12rem;
  font-size: 0.625rem;
  line-height: 1.15;
  color: #64748b;
}

.grammar-card--peek .grammar-card__badge {
  font-size: 0.5625rem;
  padding: 0.1rem 0.4rem;
  box-shadow: 0 0 0 2px #000;
}

.grammar-card__badge--spacer {
  visibility: hidden;
  background: transparent !important;
  box-shadow: none !important;
  min-width: 2rem;
}

/* Line-completion: 参考产品式 role groups (正确答案在上，中文在下) */
.grammar-group {
  position: relative;
  padding-top: 0.7rem;
  max-width: 100%;
}

.grammar-group__badge {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 2;
  transform: translateX(-50%);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.25;
  color: #fff;
  background: var(--grammar-color);
  box-shadow: 0 0 0 2px #000;
  white-space: nowrap;
}

.grammar-group__body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: 1.5px solid var(--grammar-color);
  border-radius: 1.125rem;
  background: rgba(255, 255, 255, 0.02);
  padding: 1.15rem 1rem 0.9rem;
  box-sizing: border-box;
  min-width: 5.5rem;
}

.grammar-group__tokens {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 0.55rem 1rem;
}

.grammar-group__token {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.5rem;
}

.grammar-group__ipa {
  min-height: 1rem;
  font-size: 0.8125rem;
  line-height: 1.15;
  font-weight: 400;
  color: #94a3b8;
}

.grammar-group__word {
  margin-top: 0.35rem;
  border: none;
  background: transparent;
  padding: 0;
  font-size: clamp(1.45rem, 3.6vh, 2.15rem);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
}

.grammar-group__word:hover { opacity: 0.9; }

.grammar-group__bar {
  margin-top: 0.45rem;
  height: 3px;
  width: 100%;
  border-radius: 999px;
  background: var(--grammar-color);
}

.grammar-group__glosses {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 0.35rem 1rem;
  margin-top: 0.55rem;
}

.grammar-group__gloss {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.5rem;
  text-align: center;
}

.grammar-group__zh {
  font-size: 0.875rem;
  line-height: 1.25;
  font-weight: 500;
  color: #e2e8f0;
}

.grammar-group__pos {
  margin-top: 0.12rem;
  font-size: 0.75rem;
  line-height: 1.2;
  color: #64748b;
}

/* 参考产品 sense-group chunks (意群): no role badge, group-level gloss. */
.grammar-group--chunk {
  padding-top: 0;
}

/* Ctrl+; peek: compact single-row sense groups (fits the fixed peek slot). */
.chunk-peek-grid {
  align-items: flex-start;
  gap: 0.4rem 0.6rem;
}

.chunk-peek-grid .grammar-group__body {
  padding: 0.55rem 0.7rem 0.85rem;
  border-radius: 0.8rem;
  border-width: 1px;
}

.chunk-peek-grid .grammar-group__tokens {
  gap: 0.15rem 0.5rem;
}

.chunk-peek-grid .grammar-group__token {
  min-width: 1.6rem;
}

.chunk-peek-grid .grammar-group__ipa {
  min-height: 0.95rem;
  font-size: 0.78rem;
}

.chunk-peek-grid .grammar-group__word {
  margin-top: 0.1rem;
  font-size: clamp(1.15rem, 2.4vh, 1.5rem);
}

.chunk-peek-grid .grammar-group__bar {
  margin-top: 0.25rem;
  height: 2px;
}

.chunk-peek-grid .grammar-group__zh--chunk {
  margin-top: 0.5rem;
  font-size: 0.92rem;
}


.grammar-group__zh--chunk {
  margin-top: 0.55rem;
  text-align: center;
  font-size: 0.9375rem;
  line-height: 1.3;
  font-weight: 500;
  color: #e2e8f0;
}

.grammar-card-grid--completion {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 0.85rem 1.15rem;
  width: 100%;
  max-width: min(94vw, 72rem);
  margin: 0 auto;
}

@media (max-width: 640px) {
  .grammar-card { min-width: 5.25rem; max-width: 9rem; }
  .grammar-card__body { min-height: 9.25rem; padding: 1.05rem 0.65rem 0.75rem; }
  .grammar-card__word { font-size: clamp(1.75rem, 6.5vw, 2.35rem); }
  .grammar-card__badge { font-size: 0.625rem; padding: 0.15rem 0.5rem; }
  .grammar-group__word { font-size: clamp(1.25rem, 5vw, 1.75rem); }
  .grammar-group__body { padding: 1rem 0.75rem 0.75rem; }
}

/* =====================================================================
   Non-video phrase practice — 参考产品式 in-place dock swap (2026-09-04)
   After the learner finishes typing, the blank letter rows and the answer
   chunk cards swap inside the SAME fixed-height slot: the Chinese prompt
   (`#phrase-zh`) stays exactly where it is, and nothing else reflows —
   zero page jump on submit. (Video lessons already use this dock; extend
   the same fixed-height mechanism to text lessons.)
   ===================================================================== */
#phrase-practice-shell .phrase-practice-dock {
  --phrase-dock-h: min(52vh, 27.5rem);
  position: relative;
  flex: 0 0 var(--phrase-dock-h);
  flex-grow: 0;
  flex-shrink: 0;
  width: 100%;
  height: var(--phrase-dock-h);
  min-height: var(--phrase-dock-h);
  max-height: var(--phrase-dock-h);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem 1rem 0.5rem;
  box-sizing: border-box;
  contain: layout style;
}

#phrase-practice-shell .phrase-dock-slot {
  position: relative;
  width: 100%;
  height: min(38vh, 19.5rem);
  min-height: min(38vh, 19.5rem);
  max-height: min(38vh, 19.5rem);
  flex: 0 0 min(38vh, 19.5rem);
  overflow: hidden;
}

/* The anti-jitter nudge pulls the answer deck up so the WORD lands on the
   typed-letter baseline — which pushes the card's top border a few px above
   the slot box, and overflow:hidden clipped it (2026-09-04). Let the border
   bleed into the prompt's margin gap instead. Unsupported browsers keep the
   old behaviour. */
#phrase-practice-shell:not(.is-video-lesson) .phrase-dock-slot {
  overflow: clip;
  overflow-clip-margin: 26px;
}

/* The completion layer itself is overflow:hidden (inset:0 of the slot), so
   it clipped the card tops even after the slot got clip-margin — the outer
   slot is the only clipper we need on text lessons. */
#phrase-practice-shell:not(.is-video-lesson) .phrase-dock-completion {
  overflow: visible;
}

/* Full-width chain: without this the align-items:center dock shrink-wraps
   its inner column to content width, and the fit loop spirals the font
   down to the floor (2026-09-04 tiny-letters bug). */
#phrase-practice-shell .phrase-dock-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100%;
  flex: 0 0 auto;
}

/* Roomier gap between the Chinese prompt and the English letter row. */
#phrase-practice-shell #phrase-zh {
  margin-bottom: 1.9rem;
}

/* 参考产品 answer layout: the sentence Chinese lives UNDER the answer cards
   (#phrase-dock-completion-zh). Hide the top prompt during completion —
   visibility (not display) keeps its space so nothing jumps. */
#phrase-practice-shell.is-dock-completion:not(.is-video-lesson) #phrase-zh {
  visibility: hidden;
}

#phrase-practice-shell .phrase-dock-practice,
#phrase-practice-shell .phrase-dock-completion {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  text-align: center;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.18s ease-out;
}

#phrase-practice-shell .phrase-dock-practice.is-hidden,
#phrase-practice-shell .phrase-dock-completion.is-hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Keep `hidden` from display:none so the cross-fade works */
#phrase-practice-shell .phrase-dock-practice.hidden,
#phrase-practice-shell .phrase-dock-completion.hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  display: flex !important;
}

/* Blank letter rows sit at the top of the locked slot; no jumpy margins */
#phrase-practice-shell .phrase-dictation-blanks,
#phrase-practice-shell #phrase-blanks {
  margin-top: 0.25rem !important;
  min-height: 0;
  padding-bottom: 0.5rem;
  align-items: flex-start !important;
  flex: 0 0 auto;
}

/* Text lessons: ONE line by default (fitDockBlanks shrinks the font before
   ever allowing a break). Long sentences get a JS-inserted full-width break
   element + .has-row-break, which re-enables wrapping for two big rows. */
#phrase-practice-shell:not(.is-video-lesson) .phrase-dictation-blanks:not(.has-row-break),
#phrase-practice-shell:not(.is-video-lesson) #phrase-blanks:not(.has-row-break) {
  flex-wrap: nowrap !important;
}
#phrase-practice-shell:not(.is-video-lesson) .phrase-dictation-blanks.has-row-break,
#phrase-practice-shell:not(.is-video-lesson) #phrase-blanks.has-row-break {
  flex-wrap: wrap !important;
  /* Row 1's IPA is absolute and bleeds ~20px below its blank box — the gap
     must clear it so row 2's letters never collide with row 1's phonetics. */
  row-gap: 1.45rem;
}
#phrase-blanks .phrase-blank-row-break {
  flex: 0 0 100%;
  width: 100%;
  height: 0;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

/* Answer deck: one line until it would go tiny — then the chunk cards wrap
   into two rows too (.is-wrapped set by fitDockCompletion). */
#phrase-practice-shell:not(.is-video-lesson) .phrase-dock-completion .grammar-card-grid--completion {
  flex-wrap: nowrap !important;
  align-items: center;
  gap: 0.6rem 0.8rem;
}
#phrase-practice-shell:not(.is-video-lesson) .phrase-dock-completion .grammar-card-grid--completion.is-wrapped {
  flex-wrap: wrap !important;
  justify-content: center;
  row-gap: 0.5rem;
  /* JS also sets max-width to availW — keep a CSS floor so wrap can't be
     defeated by a grow-to-fit grid (2026-09-06 clip of The…students). */
  max-width: 100%;
  width: 100%;
  box-sizing: border-box;
}

#phrase-practice-shell:not(.is-video-lesson) .phrase-dock-completion .grammar-group__tokens {
  flex-wrap: nowrap;
}

#phrase-practice-shell.is-dock-completion .phrase-dictation-blanks {
  /* hidden while the answer layer is up; geometry untouched */
  pointer-events: none;
}

/* Answer chunk cards in the shared slot — slightly larger than the video
   dock so text lessons stay readable, still below the stat HUD. */
#phrase-practice-shell .phrase-dock-completion .grammar-card-grid--completion {
  gap: 0.7rem 0.9rem;
  max-width: min(94vw, 72rem);
  align-items: flex-start;
}

#phrase-practice-shell .phrase-dock-completion .grammar-group {
  padding-top: 0.55rem;
}

#phrase-practice-shell .phrase-dock-completion .grammar-group__body {
  padding: 0.7rem 0.8rem 0.6rem;
  min-height: 0;
  border-radius: 0.875rem;
}

#phrase-practice-shell .phrase-dock-completion .grammar-group__tokens {
  gap: 0.3rem 0.5rem;
}

#phrase-practice-shell .phrase-dock-completion .grammar-group__word {
  font-size: clamp(1.3rem, 3.4vh, 1.9rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0;
}

/* Height is LOCKED (not just min-height): the IPA glyphs load with a font
   swap, and a reflowing IPA line shifts the word below it ~6px AFTER the
   anti-jitter fit pass has measured it — reintroducing the reveal jitter
   (2026-09-04). Fixed box = stable geometry. */
#phrase-practice-shell .phrase-dock-completion .grammar-group__ipa {
  font-size: 0.78rem;
  height: 1.05rem;
  line-height: 1.05rem;
  min-height: 0;
  overflow: hidden;
  color: rgb(148 163 184);
}

#phrase-practice-shell .phrase-dock-completion .grammar-group__zh,
#phrase-practice-shell .phrase-dock-completion .grammar-group__zh--chunk {
  font-size: 0.8rem;
  font-weight: 500;
  margin-top: 0.35rem;
  color: rgb(209 213 219);
}

#phrase-practice-shell .phrase-dock-completion .grammar-group__pos {
  font-size: 10px;
  font-weight: 400;
  color: rgb(156 163 175);
}

#phrase-practice-shell .phrase-dock-completion .grammar-group__badge {
  font-size: 9px;
  font-weight: 500;
  padding: 0.12rem 0.4rem;
  letter-spacing: 1px;
}

/* Full-sentence Chinese stays under the answer deck (参考产品: 答案在上，中文在下) */
#phrase-practice-shell .phrase-completion-zh--dock {
  max-width: 42rem;
  margin-top: 0.75rem;
  font-size: clamp(1.15rem, 2.6vh, 1.5rem);
  font-weight: 500;
  line-height: 1.45;
  color: #ffffff;
}

@media (max-width: 640px) {
  #phrase-practice-shell .phrase-practice-dock {
    --phrase-dock-h: min(56vh, 28rem);
    padding-top: 0.75rem;
  }
  #phrase-practice-shell #phrase-zh {
    margin-bottom: 1.2rem;
  }
  #phrase-practice-shell .phrase-dock-slot {
    height: min(42vh, 21rem);
    min-height: min(42vh, 21rem);
    max-height: min(42vh, 21rem);
    flex-basis: min(42vh, 21rem);
  }
}
