.mastery-dashboard { width: min(100% - 32px, 980px); margin: 12px auto 48px; }
.mastery-top-bar { position: relative; z-index: 10000010; display: grid; grid-template-columns: minmax(190px, .7fr) minmax(680px, 2fr) auto; align-items: center; gap: 1.5px; height: auto; min-height: 72px; padding-block: 8px; overflow: visible; }
.mastery-top-bar .top-bar-left { position: relative; z-index: 1000; min-width: 0; }
.mastery-top-bar .top-bar-right { position: relative; z-index: 1000; justify-self: end; gap: 1.5px; }
.mastery-header-controls { position: relative; z-index: 1000; min-width: 0; display: grid; grid-template-columns: minmax(200px, max-content) minmax(360px, max-content) max-content; align-items: stretch; justify-content: center; gap: 6px; }
.mastery-header-controls:has(.mastery-subject-picker[open]) { z-index: 10000020 !important; overflow: visible !important; }
body.mastery-subject-menu-open .mastery-top-bar,
body.mastery-subject-menu-open .mastery-header-controls,
body.mastery-subject-menu-open .mastery-subject-cards {
  z-index: 10000030 !important;
  overflow: visible !important;
}

/* Keep the recitation controls centered in the viewport on desktop. */
@media (min-width: 1181px) {
  body.mastery-page .mastery-top-bar {
    grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr) !important;
  }

  body.mastery-page .mastery-header-controls {
    grid-column: 2 !important;
    justify-self: center !important;
    width: min(930px, calc(100vw - 520px)) !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-left {
    grid-column: 1 !important;
    justify-self: start !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right {
    grid-column: 3 !important;
    justify-self: end !important;
  }

  body.mastery-page .mastery-review-stage {
    display: flex !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  body.mastery-page .mastery-card-scene,
  body.mastery-page .mastery-bottom-controls {
    margin-inline: auto !important;
  }
}

body.mastery-subject-menu-open .mastery-dashboard,
body.mastery-subject-menu-open .mastery-review,
body.mastery-subject-menu-open .mastery-review-stage,
body.mastery-subject-menu-open .mastery-card-scene {
  z-index: 1 !important;
}
.mastery-top-card-tools { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 54px; padding: 6px; border: 1px solid color-mix(in srgb, var(--primary-color) 16%, rgba(255,255,255,.72)); border-radius: 20px; background: linear-gradient(135deg, color-mix(in srgb, var(--primary-light) 62%, rgba(255,255,255,.82) 38%), color-mix(in srgb, var(--panel-bg) 74%, var(--primary-light) 26%)); box-shadow: inset 0 1px 0 rgba(255,255,255,.82), 0 12px 28px rgba(31,54,38,.10); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.mastery-top-card-tools .flashcard-icon-btn { display: inline-grid; place-items: center; width: 44px; min-width: 44px; height: 44px; min-height: 44px; padding: 0 !important; border: 1px solid color-mix(in srgb, var(--primary-color) 18%, rgba(255,255,255,.72)) !important; border-radius: 16px; background: color-mix(in srgb, var(--panel-bg) 70%, var(--primary-light) 30%) !important; color: var(--primary-color) !important; box-shadow: inset 0 1px 0 rgba(255,255,255,.82), 0 7px 18px rgba(47,107,47,.08) !important; }
.mastery-top-card-tools .flashcard-icon-btn svg,
.mastery-top-card-tools .flashcard-icon-btn i { width: 18px !important; min-width: 18px !important; height: 18px !important; flex: 0 0 18px !important; stroke-width: 2.1; }
.mastery-top-card-tools .flashcard-icon-btn:hover, .mastery-top-card-tools .flashcard-icon-btn:focus-visible { border-color: color-mix(in srgb, var(--primary-color) 34%, rgba(255,255,255,.72)) !important; background: color-mix(in srgb, var(--primary-light) 72%, #fff 28%) !important; box-shadow: inset 0 1px 0 rgba(255,255,255,.9), 0 10px 22px rgba(47,107,47,.13) !important; }
.mastery-top-card-tools .flashcard-icon-btn.is-active { color: #fff !important; border-color: color-mix(in srgb, var(--primary-color) 78%, #fff 22%) !important; background: linear-gradient(135deg, var(--primary-color), color-mix(in srgb, var(--primary-color) 72%, #10b981 28%)) !important; box-shadow: 0 9px 20px color-mix(in srgb, var(--primary-color) 25%, transparent) !important; }
.mastery-top-card-tools .flashcard-icon-btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.mastery-hidden-top-actions { display: none !important; }
.mastery-immersive-exit-btn {
  position: fixed !important;
  top: max(10px, env(safe-area-inset-top)) !important;
  right: 10px !important;
  z-index: 10000030 !important;
  display: none;
  place-items: center;
  width: 40px !important;
  height: 40px !important;
  border: none !important;
  border-radius: 999px !important;
  background: transparent !important;
  color: var(--primary-color) !important;
  box-shadow: none !important;
  cursor: pointer !important;
  padding: 0 !important;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.mastery-immersive-exit-btn:active {
  transform: scale(0.92);
  opacity: 0.8;
}
.mastery-immersive-exit-btn svg,
.mastery-immersive-exit-btn i { width: 20px !important; min-width: 20px !important; height: 20px !important; flex: 0 0 20px !important; stroke-width: 2.2; }
body.mastery-immersive .mastery-immersive-exit-btn { display: grid !important; }

@media (max-width: 1400px) {
  body.mastery-page .mastery-top-bar {
    display: grid !important;
    grid-template-columns: minmax(210px, .72fr) minmax(720px, 1.9fr) auto !important;
    align-items: center !important;
    gap: 14px !important;
    height: auto !important;
    min-height: 78px !important;
    padding: 10px 24px !important;
    overflow: visible !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-left {
    display: flex !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    align-items: center !important;
    gap: 16px !important;
    min-width: 0 !important;
  }

  body.mastery-page .mastery-top-bar .current-chapter-info {
    display: block !important;
    min-width: 0;
  }

  body.mastery-page .mastery-header-controls {
    grid-column: 2 !important;
    grid-row: 1 !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right {
    grid-column: 3 !important;
    grid-row: 1 !important;
  }
}
.mastery-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.mastery-heading h1 { margin: 0; font-size: 1.55rem; }
.mastery-eyebrow { margin: 0 0 4px; color: var(--primary-color); font-weight: 700; font-size: .82rem; }
.mastery-next-review { margin: 0; color: var(--text-muted); font-size: .9rem; }
.mastery-stat-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mastery-stat { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; align-items: center; padding: 18px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--panel-bg); }
.mastery-stat i { grid-row: span 2; color: var(--primary-color); width: 18px; height: 18px; }
.mastery-stat strong { font-size: 1.45rem; line-height: 1; }
.mastery-stat span { color: var(--text-muted); font-size: .82rem; }
.mastery-filter-bar { display: flex; gap: 8px; margin: 24px 0 14px; overflow-x: auto; }
.mastery-filter { flex: 0 0 auto; border: 1px solid var(--border-color); border-radius: 8px; padding: 8px 14px; background: var(--panel-bg); color: var(--text-muted); font-weight: 700; cursor: pointer; }
.mastery-filter.active { border-color: var(--primary-color); color: var(--primary-color); background: var(--primary-light); }
.mastery-groups { display: grid; gap: 12px; }
.mastery-subject-cards { display: flex; align-items: stretch; justify-content: center; min-height: 54px; margin: 0; }
.mastery-subject-picker { position: relative; width: fit-content; min-width: 230px; z-index: 1; }
.mastery-subject-picker[open] { z-index: 10000030; }
.mastery-subject-picker > summary { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 54px; padding: 0 16px; border: 1px solid var(--border-color); border-radius: 13px; background: var(--panel-bg); color: var(--primary-color); font-size: .96rem; font-weight: 800; cursor: pointer; list-style: none; box-shadow: inset 0 1px 0 rgba(255,255,255,.62), 0 8px 20px rgba(31,54,38,.06); }
.mastery-subject-picker > summary::-webkit-details-marker { display: none; }
.mastery-subject-picker > summary svg { width: 16px; height: 16px; transition: transform .16s ease; }
.mastery-subject-picker[open] > summary svg { transform: rotate(180deg); }
.mastery-subject-summary-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mastery-subject-summary-count { flex: 0 0 auto; color: var(--text-muted); font-size: .82em; }
.mastery-subject-menu { position: absolute; z-index: 10000040; top: calc(100% + 6px); right: 0; display: grid; min-width: 252px; max-height: min(72vh, 520px); overflow-y: auto; padding: 8px; border: 1px solid var(--border-color); border-radius: 12px; background: var(--panel-bg); box-shadow: 0 10px 28px rgba(31, 54, 38, .14); }
body.mastery-subject-menu-open .mastery-subject-menu {
  position: fixed !important;
  left: var(--mastery-subject-menu-left, 16px) !important;
  right: auto !important;
  top: var(--mastery-subject-menu-top, 82px) !important;
  width: var(--mastery-subject-menu-width, 252px) !important;
  min-width: var(--mastery-subject-menu-width, 252px) !important;
  max-height: calc(100dvh - var(--mastery-subject-menu-top, 82px) - 12px) !important;
  z-index: 10000060 !important;
}
.mastery-subject-menu button { display: flex; align-items: center; justify-content: space-between; gap: 18px; width: 100%; padding: 9px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--text-main); font: inherit; cursor: pointer; }
.mastery-subject-menu button:hover, .mastery-subject-menu button.is-active { background: var(--primary-light); color: var(--primary-color); }
.mastery-subject-menu strong { font-size: .82rem; }
.mastery-menu-section-title { margin: 6px 4px 4px; padding-top: 6px; border-top: 1px solid color-mix(in srgb, var(--border-color) 72%, transparent); color: var(--text-muted); font-size: .74rem; font-weight: 800; letter-spacing: .04em; }
.mastery-menu-section-title:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.mastery-menu-hint { padding: 9px 10px; color: var(--text-muted); font-size: .82rem; line-height: 1.35; }
.mastery-new-folder-btn { color: var(--primary-color) !important; font-weight: 800 !important; }
.mastery-subject-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px; border: 1px solid var(--border-color); border-radius: 8px; background: var(--panel-bg); }
.mastery-subject-card.is-active { border-color: var(--primary-color); box-shadow: 0 0 0 2px var(--primary-light); }
.mastery-subject-card strong { display: block; margin-top: 7px; font-size: 1.35rem; }
.mastery-subject-card p { margin: 4px 0 0; color: var(--text-muted); font-size: .84rem; }
.mastery-review { margin-top: 4px; padding: 0; border: 0; border-radius: 0; background: transparent; }
.mastery-review-heading { display: flex; align-items: center; justify-content: flex-end; gap: 12px; width: min(100%, 760px); margin: 0 auto 4px; padding-inline: 4px; }
.mastery-review-heading h2 { margin: 6px 0 0; font-size: 1.08rem; }
.mastery-review-count { color: var(--primary-color); font-weight: 700; white-space: nowrap; }
.mastery-review-stage { width: min(100%, 900px); margin: 0 auto; padding-inline: 62px; }
.mastery-card-scene { flex: 0 1 720px; width: min(100%, 720px); min-height: 560px; height: min(72vh, 720px); max-height: 760px; }
.mastery-review-card { min-height: 0; }
.mastery-review-card .card-front .card-meta-row { justify-content: space-between; }
.mastery-review-card .card-source-badge { flex: 0 0 auto; }
.mastery-review-card .card-question-text { font-size: clamp(1.2rem, 2.2vw, 1.55rem); font-weight: 700; align-items: center; }
.mastery-review-card .card-answer-text { text-align: left; }
.mastery-review-card .tap-hint { margin-top: 14px; flex-shrink: 0; }
/* v238: recitation cards keep actions visible while long content scrolls inside the card. */
.mastery-review-card .card-question-text,
.mastery-review-card .card-answer-text-container,
.mastery-review-card .card-answer-text {
  min-height: 0;
  max-width: 100%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 116, 94, 0.36) transparent;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.mastery-review-card .card-question-text::-webkit-scrollbar,
.mastery-review-card .card-answer-text-container::-webkit-scrollbar,
.mastery-review-card .card-answer-text::-webkit-scrollbar { width: 8px; }
.mastery-review-card .card-question-text::-webkit-scrollbar-thumb,
.mastery-review-card .card-answer-text-container::-webkit-scrollbar-thumb,
.mastery-review-card .card-answer-text::-webkit-scrollbar-thumb { border-radius: 999px; background: rgba(95, 116, 94, 0.36); }
/* v239: allow the recitation page itself to scroll when card + controls exceed the viewport. */
.mastery-dashboard,
.mastery-review,
.mastery-review-stage {
  min-height: 0;
}
/* v239: allow the recitation page itself to scroll when card + controls exceed the viewport on small screens. */
@media (max-width: 768px) {
  .mastery-review,
  .mastery-review-stage {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}
body.mastery-inline-editing .mastery-review-card { cursor: text; }
body.mastery-inline-editing .mastery-review-card .tap-hint,
body.mastery-inline-editing .mastery-review-stage .floating-nav-btn { display: none !important; }
body:not(.mastery-inline-editing) .mastery-review-card,
body:not(.mastery-inline-editing) .mastery-review-card .card-face,
body:not(.mastery-inline-editing) .mastery-review-card .card-question-text,
body:not(.mastery-inline-editing) .mastery-review-card .card-answer-text,
body:not(.mastery-inline-editing) .mastery-review-card .card-answer-text-container,
body:not(.mastery-inline-editing) .mastery-review-card .cloze-mask,
body:not(.mastery-inline-editing) .mastery-review-card .cloze-content {
  -webkit-touch-callout: none !important;
}
body.mastery-annotation-active .mastery-review-card { cursor: crosshair; }
body.mastery-annotation-active .mastery-review-card,
body.mastery-annotation-active .mastery-review-card * {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-user-drag: none !important;
}
body.mastery-annotation-active ::selection {
  background: transparent !important;
  color: inherit !important;
}
body.mastery-annotation-active .mastery-review-card .card-back .tap-hint { display: none !important; }
body.mastery-inline-editing .mastery-review-card .card-question-text[contenteditable="true"],
body.mastery-inline-editing .mastery-review-card .card-answer-text[contenteditable="true"] { min-height: 96px; }
.mastery-bottom-controls { margin-top: 12px; }
.mastery-bottom-controls .card-quick-controls { background: color-mix(in srgb, var(--primary-light) 48%, transparent); }
.mastery-inline-editor-actions { display: flex; align-items: center; justify-content: center; gap: 6px; width: min(100%, 380px); padding: 4px 6px; border: 1px solid color-mix(in srgb, var(--primary-color) 14%, transparent); border-radius: 12px; background: color-mix(in srgb, var(--panel-bg) 66%, transparent); box-shadow: 0 6px 18px rgba(31,54,38,.10); backdrop-filter: blur(10px); }
.mastery-inline-editor-actions .btn { flex: 1 1 0; min-width: 80px; width: auto; min-height: 36px; padding: 6px 10px; border-radius: 9px; font-size: .82rem; font-weight: 800; white-space: nowrap; }
.mastery-unmaster-btn { color: #fff; background: #b42318; border-color: #b42318; }
.mastery-unmaster-btn:hover, .mastery-unmaster-btn:focus-visible { filter: brightness(.96); transform: translateY(-1px); }
.mastery-group { border: 1px solid var(--border-color); border-radius: 8px; background: var(--panel-bg); padding: 18px; }
.mastery-group header { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.mastery-group h2 { margin: 5px 0; font-size: 1.05rem; }
.mastery-group p { margin: 0; color: var(--text-muted); font-size: .86rem; }
.mastery-subject { display: inline-block; color: var(--primary-color); background: var(--primary-light); border-radius: 4px; padding: 3px 7px; font-size: .76rem; font-weight: 700; }
.mastery-group-actions { display: flex; gap: 8px; align-items: center; }
.icon-only-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--border-color); border-radius: 7px; color: var(--text-muted); background: var(--panel-bg); cursor: pointer; }
.mastery-preview-list { margin: 16px 0 0; padding-left: 20px; color: var(--text-main); line-height: 1.6; }
.mastery-preview-list li { margin: 4px 0; }
.mastery-more { display: block; margin-top: 8px; color: var(--text-muted); font-size: .84rem; }
.mastery-empty-state { min-height: 250px; display: grid; place-items: center; align-content: center; gap: 10px; border: 1px dashed var(--border-color); border-radius: 8px; color: var(--text-muted); text-align: center; }
.mastery-empty-state i { width: 28px; height: 28px; color: var(--primary-color); }

.recitation-review-tabs { display: inline-flex; align-items: center; justify-content: center; gap: 8px; margin: 0; width: auto; min-width: 0; min-height: 54px; padding: 6px; border: 1px solid color-mix(in srgb, var(--primary-color) 12%, var(--border-color)); border-radius: 22px; background: color-mix(in srgb, var(--panel-bg) 84%, var(--primary-light) 16%); box-shadow: 0 10px 24px rgba(31,54,38,.06); }
.recitation-review-tab { display: inline-flex; align-items: center; justify-content: center; gap: 9px; min-width: 116px; min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: 17px; background: transparent; color: var(--text-main); text-align: center; cursor: pointer; box-shadow: none; }
.recitation-review-tab span { color: var(--text-muted); font-size: .9rem; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recitation-review-tab strong { display: inline-grid; place-items: center; min-width: 27px; height: 27px; padding: 0 8px; border-radius: 999px; color: var(--primary-color); background: color-mix(in srgb, var(--primary-light) 68%, #fff 32%); font-size: 1rem; line-height: 1; }
.recitation-review-tab.is-active { border-color: color-mix(in srgb, var(--primary-color) 34%, var(--border-color)); background: #fff; box-shadow: 0 8px 18px rgba(47,107,47,.10); }
.recitation-review-tab.is-empty { opacity: .62; }
.mastery-review-heading p { margin: 4px 0 0; color: var(--text-muted); font-size: .82rem; }
.mastery-bottom-controls { display: flex; align-items: center; flex-direction: column; gap: 9px; }
.mastery-bottom-controls .card-review-controls { width: min(100%, 420px); }
.recitation-editor-modal[hidden] { display: none; }
.recitation-editor-modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 18px; background: rgba(15,23,42,.28); backdrop-filter: blur(8px); }
.recitation-editor-card { width: min(100%, 560px); max-height: calc(100dvh - 36px); overflow: auto; display: grid; gap: 12px; padding: 18px; border: 1px solid var(--border-color); border-radius: 14px; background: var(--panel-bg); box-shadow: 0 24px 60px rgba(15,23,42,.22); }
.recitation-editor-card header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.recitation-editor-card h3 { margin: 0; font-size: 1.05rem; }
.recitation-editor-card header button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 999px; background: var(--primary-light); color: var(--primary-color); cursor: pointer; font-size: 1.2rem; }
.recitation-editor-card label { display: grid; gap: 6px; color: var(--text-muted); font-size: .82rem; font-weight: 800; }
.recitation-editor-card input, .recitation-editor-card select, .recitation-editor-card textarea { width: 100%; border: 1px solid var(--border-color); border-radius: 9px; padding: 10px 11px; background: var(--bg-color); color: var(--text-main); font: inherit; box-sizing: border-box; }
.recitation-editor-card textarea { resize: vertical; line-height: 1.55; }
.recitation-answer-editor { display: grid; gap: 10px; }
.recitation-answer-mode-toggle { display: inline-flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: .82rem; font-weight: 800; }
.recitation-answer-mode-toggle label { display: inline-flex; align-items: center; gap: 5px; }
.recitation-editor-list-area { display: flex; flex-direction: column; gap: 10px; }
.recitation-editor-list-area[hidden],
.recitation-editor-text-area[hidden] { display: none !important; }
.recitation-editor-list-container { display: grid; gap: 9px; }
.recitation-editor-rich-text { min-height: 180px; }
.recitation-editor-card footer { display: flex; justify-content: flex-end; gap: 10px; }
.recitation-folder-modal[hidden] { display: none !important; }
.recitation-folder-modal { position: fixed; inset: 0; z-index: 10000100; display: grid; place-items: center; padding: 18px; background: rgba(15,23,42,.34); backdrop-filter: blur(10px); opacity: 0; transition: opacity .16s ease; }
.recitation-folder-modal.is-open { opacity: 1; }
.recitation-folder-card { width: min(100%, 430px); display: grid; gap: 14px; padding: 18px; border: 1px solid color-mix(in srgb, var(--primary-color) 16%, var(--border-color)); border-radius: 18px; background: color-mix(in srgb, var(--panel-bg) 94%, var(--primary-light) 6%); box-shadow: 0 28px 72px rgba(15,23,42,.24); }
.recitation-folder-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.recitation-folder-card h3 { margin: 0 0 4px; color: var(--text-main); font-size: 1.04rem; }
.recitation-folder-card p { margin: 0; color: var(--text-muted); font-size: .86rem; line-height: 1.45; }
.recitation-folder-close { display: grid; place-items: center; flex: 0 0 34px; width: 34px; height: 34px; border: 0; border-radius: 999px; background: var(--primary-light); color: var(--primary-color); cursor: pointer; font-size: 1.2rem; }
.recitation-folder-list { display: grid; gap: 8px; max-height: 260px; overflow: auto; padding-right: 2px; }
.recitation-folder-list[hidden] { display: none !important; }
.recitation-folder-option { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 0 12px; border: 1px solid var(--border-color); border-radius: 12px; background: #fff; color: var(--text-main); font: inherit; font-weight: 800; cursor: pointer; }
.recitation-folder-option:hover, .recitation-folder-option:focus-visible, .recitation-folder-option.is-current { border-color: color-mix(in srgb, var(--primary-color) 44%, var(--border-color)); background: var(--primary-light); color: var(--primary-color); }
.recitation-folder-option strong { color: var(--text-muted); font-size: .78rem; }
.recitation-folder-new { display: grid; gap: 7px; color: var(--text-muted); font-size: .82rem; font-weight: 850; }
.recitation-folder-new input { width: 100%; border: 1px solid var(--border-color); border-radius: 12px; padding: 12px 13px; background: var(--bg-color); color: var(--text-main); font: inherit; box-sizing: border-box; }
.recitation-folder-new input:focus { outline: 0; border-color: var(--primary-color); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-light) 75%, transparent); }
.recitation-folder-empty { padding: 14px; border: 1px dashed var(--border-color); border-radius: 12px; color: var(--text-muted); text-align: center; }
.recitation-folder-card footer { display: flex; justify-content: flex-end; gap: 10px; }

body.mastery-page {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

body.mastery-page .app-container,
body.mastery-page .main-content {
  height: auto;
  min-height: calc(100dvh / var(--study-page-zoom, 1));
  overflow-x: hidden;
}

.mastery-dashboard {
  width: min(100% - 32px, 980px);
  margin: 12px auto 48px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

.mastery-review,
.mastery-review-stage {
  overflow: visible;
}

.mastery-review-stage {
  width: min(100%, 900px);
  margin: 0 auto;
  padding-inline: 62px;
  padding-bottom: 0;
}

.mastery-card-scene {
  flex: 0 0 auto;
  width: min(100%, 760px);
  height: clamp(500px, calc(100dvh - 210px), 700px);
  min-height: clamp(500px, calc(100dvh - 210px), 700px);
  max-height: none;
}

.mastery-review-card,
.mastery-review-card .card-face {
  min-height: 0;
}

.mastery-review-card .card-question-text,
.mastery-review-card .card-answer-text-container {
  flex: 1 1 0%;
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.mastery-review-card .card-question-text {
  align-items: flex-start;
  justify-content: flex-start;
}

.mastery-review-card .card-answer-text {
  max-height: none;
  overflow: visible;
}

/* 名词解释沿用闪卡的点击显现方式，答案 HTML 的行内颜色不重写。 */
.mastery-review-card.is-definition-review {
  transform: none !important;
  cursor: pointer;
}

.mastery-review-card.is-definition-review .card-front {
  backface-visibility: visible;
  gap: 14px;
}

.mastery-review-card.is-definition-review .card-question-text {
  flex: 0 0 auto !important;
  flex-grow: 0 !important;
  min-height: auto !important;
  height: auto !important;
  max-height: none !important;
  display: block !important;
  padding: 6px 12px 14px !important;
  margin: 4px 0 6px !important;
  text-align: center !important;
  border-bottom: 1px solid var(--border-color) !important;
  width: 100% !important;
}

.mastery-definition-answer {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  margin-top: 0;
  padding: 0 4px 12px;
  border: none !important;
  border-radius: 0;
  background: transparent !important;
  overflow-x: hidden !important;
}

.mastery-definition-answer .card-tag {
  margin-bottom: 8px;
}

.mastery-definition-answer .card-answer-text-container {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  padding-top: 0;
}

.mastery-definition-answer .mastery-answer-text span[style*="#10b981"],
.mastery-definition-answer .mastery-answer-text span[style*="#059669"],
.mastery-definition-answer .mastery-answer-text span[style*="#16a34a"],
.mastery-definition-answer .mastery-answer-text span[style*="#22c55e"] {
  color: #047857 !important;
  background: rgba(16, 185, 129, 0.16) !important;
  font-weight: 750 !important;
  border-radius: 4px;
}

.mastery-definition-answer .mastery-answer-text span[style*="#0284c7"],
.mastery-definition-answer .mastery-answer-text span[style*="#0891b2"] {
  color: #0369a1 !important;
  background: rgba(2, 132, 199, 0.14) !important;
  font-weight: 750 !important;
  border-radius: 4px;
}

.mastery-definition-answer .mastery-answer-text span[style*="#ea580c"],
.mastery-definition-answer .mastery-answer-text span[style*="#f97316"] {
  color: #c2410c !important;
  background: rgba(234, 88, 12, 0.14) !important;
  font-weight: 750 !important;
  border-radius: 4px;
}

.mastery-definition-answer .mastery-answer-text span[style*="#e11d48"],
.mastery-definition-answer .mastery-answer-text span[style*="#f43f5e"] {
  color: #be123c !important;
  background: rgba(225, 29, 72, 0.14) !important;
  font-weight: 750 !important;
  border-radius: 4px;
}

body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#10b981"],
body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#059669"],
body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#16a34a"],
body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#22c55e"] {
  color: #4ade80 !important;
  background: rgba(74, 222, 128, 0.22) !important;
}

body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#0284c7"],
body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#0891b2"] {
  color: #38bdf8 !important;
  background: rgba(56, 189, 248, 0.22) !important;
}

body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#ea580c"],
body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#f97316"] {
  color: #fb923c !important;
  background: rgba(251, 146, 60, 0.22) !important;
}

body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#e11d48"],
body.dark-theme .mastery-definition-answer .mastery-answer-text span[style*="#f43f5e"] {
  color: #fb7185 !important;
  background: rgba(251, 113, 133, 0.22) !important;
}

.mastery-bottom-controls {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  margin-top: 14px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
  transform: none;
}

body.mastery-immersive {
  overflow: hidden !important;
  background: var(--bg-color) !important;
}
body.mastery-page.mastery-immersive .app-container {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  z-index: 10000020 !important;
  background: var(--bg-color) !important;
  isolation: isolate !important;
  margin: 0 !important;
  padding: 0 !important;
}
body.mastery-page.mastery-immersive .main-content {
  width: 100vw !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}
body.mastery-page.mastery-immersive .mastery-top-bar,
body.mastery-page.mastery-immersive .recitation-review-tabs,
body.mastery-page.mastery-immersive .glow-container,
body.mastery-page.mastery-immersive #feedback-trigger-btn,
body.mastery-page.mastery-immersive .ai-qa-launcher,
body.mastery-page.mastery-immersive .ai-chat-launcher,
body.mastery-page.mastery-immersive .modal-backdrop,
body.mastery-page.mastery-immersive .settings-modal,
body.mastery-page.mastery-immersive .pwa-help-modal,
body.mastery-page.mastery-immersive .account-sync-panel,
body.mastery-page.mastery-immersive .account-sync-backdrop {
  display: none !important;
}
body.mastery-immersive .mastery-dashboard {
  width: min(100% - 20px, 980px) !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  margin: 0 auto !important;
  padding: max(14px, env(safe-area-inset-top)) 10px max(14px, env(safe-area-inset-bottom)) !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
}
body.mastery-immersive .mastery-card-scene {
  height: clamp(380px, calc(100dvh - 150px), 640px) !important;
  max-height: calc(100dvh - 140px) !important;
}

@media (min-width: 769px) and (max-width: 1180px) {
  .mastery-top-bar {
    grid-template-columns: max-content minmax(0, 1fr) max-content;
    align-items: center;
    column-gap: 10px;
    min-height: 66px;
    padding: 7px 16px;
  }
  body.mastery-page .mastery-top-bar {
    grid-template-columns: max-content minmax(0, 1fr) max-content !important;
    column-gap: 10px !important;
    min-height: 66px !important;
    padding: 7px 16px !important;
  }
  .mastery-top-bar .top-bar-left {
    min-width: 126px;
    gap: 10px;
  }
  body.mastery-page .mastery-top-bar .top-bar-left {
    grid-column: 1 !important;
    grid-row: 1 !important;
    gap: 10px !important;
  }
  body.mastery-page .mastery-top-bar .top-bar-left .toggle-btn {
    width: 52px !important;
    min-width: 52px !important;
    height: 38px !important;
    min-height: 38px !important;
    border-radius: 8px !important;
    padding: 0 10px !important;
    display: inline-grid !important;
    place-items: center !important;
  }
  .mastery-top-bar .current-chapter-info h2 { font-size: 1rem; margin: 0; }
  .mastery-top-bar .current-chapter-info span { display: none !important; }
  .mastery-header-controls {
    grid-column: 2;
    grid-row: 1;
    grid-template-columns: minmax(160px, 190px) minmax(305px, 1fr) max-content;
    justify-content: center;
    align-items: stretch;
    width: 100%;
    gap: 7px;
  }
  body.mastery-page .mastery-header-controls {
    grid-column: 2 !important;
    grid-row: 1 !important;
    grid-template-columns: minmax(160px, 190px) minmax(305px, 1fr) max-content !important;
    width: 100% !important;
  }
  .mastery-subject-cards { min-height: 48px; }
  .mastery-subject-picker { min-width: 0; width: 100%; }
  .mastery-subject-picker > summary { min-height: 48px; padding: 0 11px; border-radius: 12px; font-size: .88rem; }
  .recitation-review-tabs { width: 100%; min-height: 48px; gap: 5px; padding: 5px; border-radius: 18px; }
  .recitation-review-tab { flex: 1 1 0; min-width: 0; min-height: 38px; padding: 0 8px; gap: 6px; border-radius: 14px; }
  .recitation-review-tab span { font-size: .82rem; }
  .recitation-review-tab strong { min-width: 23px; height: 23px; padding: 0 6px; font-size: .9rem; }
  .mastery-top-card-tools { min-height: 48px; gap: 5px; padding: 5px; border-radius: 16px; }
  .mastery-top-card-tools .flashcard-icon-btn { width: 38px; min-width: 38px; height: 38px; min-height: 38px; border-radius: 12px; }
  .mastery-top-bar .top-bar-right {
    grid-column: 3;
    grid-row: 1;
  }
  body.mastery-page .mastery-top-bar .top-bar-right {
    grid-column: 3 !important;
    grid-row: 1 !important;
  }
  .mastery-dashboard { width: min(100% - 28px, 940px); margin-top: 12px; }
  .mastery-review-stage { width: 100%; padding-inline: 44px; }
  .mastery-card-scene {
    width: min(100%, 760px);
    height: clamp(420px, calc(100dvh - 206px), 590px);
    min-height: clamp(420px, calc(100dvh - 206px), 590px);
  }
}

@media (max-width: 768px) {
  body.mastery-page,
  body.mastery-page .app-container,
  body.mastery-page .main-content {
    height: auto;
    overflow-y: auto;
  }

  body.mastery-page .mastery-top-bar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) max-content !important;
    grid-template-rows: 44px auto !important;
    align-items: center !important;
    gap: 8px 10px !important;
    min-height: 0 !important;
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px !important;
    overflow: visible !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-left {
    grid-column: 1 !important;
    grid-row: 1 !important;
    display: flex !important;
    align-items: center !important;
    min-width: 0 !important;
    gap: 10px !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right {
    grid-column: 2 !important;
    grid-row: 1 !important;
    align-self: center !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px !important;
  }

  body.mastery-page .mastery-top-bar .current-chapter-info {
    display: block !important;
    min-width: 0 !important;
  }

  body.mastery-page .mastery-top-bar .current-chapter-info h2 {
    margin: 0 !important;
    font-size: 1.08rem !important;
    line-height: 1.1 !important;
  }

  body.mastery-page .mastery-top-bar .current-chapter-info span {
    display: none !important;
  }

  body.mastery-page .mastery-header-controls {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    width: 100% !important;
    min-width: 0 !important;
    gap: 8px !important;
    overflow-x: auto !important;
    overflow-y: visible !important;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.mastery-page .mastery-header-controls::-webkit-scrollbar { display: none; }

  body.mastery-page .mastery-header-controls .mastery-subject-cards,
  body.mastery-page .mastery-header-controls .recitation-review-tabs,
  body.mastery-page .mastery-header-controls .mastery-top-card-tools {
    flex: 0 0 auto !important;
    width: auto !important;
    min-height: 46px !important;
  }

  body.mastery-page .mastery-subject-picker { width: clamp(176px, 52vw, 244px); min-width: 0; }
  body.mastery-page .mastery-subject-picker > summary { min-height: 46px; padding: 0 14px; border-radius: 16px; }
  body.mastery-page .mastery-subject-picker > summary span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body.mastery-page .mastery-subject-menu { left: 0; right: auto; transform: none; min-width: min(260px, calc(100vw - 24px)); }

  body.mastery-page .recitation-review-tabs {
    width: auto !important;
    min-width: max-content !important;
    min-height: 46px !important;
    padding: 4px !important;
    gap: 4px !important;
    overflow: visible !important;
    border-radius: 18px !important;
  }

  body.mastery-page .recitation-review-tab {
    flex: 0 0 auto !important;
    min-width: 86px !important;
    min-height: 38px !important;
    padding: 0 10px !important;
    gap: 5px !important;
    border-radius: 14px !important;
  }

  body.mastery-page .recitation-review-tab span { max-width: 74px; font-size: .78rem; }
  body.mastery-page .recitation-review-tab strong { min-width: 22px; height: 22px; padding: 0 6px; font-size: .82rem; }

  body.mastery-page .mastery-top-card-tools {
    min-height: 46px !important;
    padding: 4px !important;
    gap: 5px !important;
    border-radius: 16px !important;
  }

  body.mastery-page .mastery-top-card-tools .flashcard-icon-btn {
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    border-radius: 13px !important;
  }

  .mastery-dashboard {
    width: min(100% - 16px, 760px);
    min-height: calc(100dvh - var(--study-topbar-height, 62px));
    margin: 8px auto 0;
    display: flex;
    flex-direction: column;
  }

  .mastery-review { flex: 1 1 auto; min-height: 0; }
  .mastery-review-stage { width: 100%; padding-inline: 34px; margin-top: 0; }
  .mastery-card-scene {
    width: min(100%, 430px);
    height: clamp(350px, calc(100dvh - 188px), 620px);
    min-height: clamp(350px, calc(100dvh - 188px), 620px);
  }
  .mastery-review-card .card-face { padding: 16px 14px; }
  .mastery-review-card .card-question-text { font-size: clamp(1.08rem, 5vw, 1.38rem); }
  .mastery-review-stage .floating-nav-btn { width: 34px; height: 34px; }
  .mastery-review-stage .floating-nav-prev { left: 0; }
  .mastery-review-stage .floating-nav-next { right: 0; }
  .mastery-bottom-controls { margin-top: 10px; }
  .mastery-bottom-controls .card-quick-controls { width: min(100%, 250px); }
  .mastery-bottom-controls .card-review-controls { width: min(100%, 330px); }
  .recitation-editor-modal { align-items: end; padding: 10px; }
  .recitation-editor-card { max-height: calc(100dvh - 20px); border-radius: 16px 16px 10px 10px; }
  body.mastery-immersive .mastery-dashboard { height: 100dvh; margin-top: 0; }
  body.mastery-immersive .mastery-card-scene { height: calc(100dvh - 120px); }
}

/* Mastery card stage: share the flashcard viewport layout, with card text scrolling inside. */
html.mastery-shell-page {
  --mastery-stage-gap: clamp(18px, 2.4dvh, 28px);
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.mastery-page {
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.mastery-page .app-container,
body.mastery-page .main-content {
  min-height: 0 !important;
  overflow: hidden !important;
}

body.mastery-page .main-content {
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
}

body.mastery-page .mastery-dashboard {
  flex: 1 1 auto !important;
  display: flex !important;
  flex-direction: column !important;
  width: min(100% - 28px, 1040px) !important;
  min-height: 0 !important;
  height: auto !important;
  margin: 8px auto 0 !important;
  padding-bottom: max(6px, env(safe-area-inset-bottom)) !important;
  overflow: hidden !important;
}

body.mastery-page .mastery-review {
  flex: 1 1 auto !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: minmax(0, 1fr) auto !important;
  align-items: stretch;
  width: 100% !important;
  min-height: 0 !important;
  height: 100% !important;
  gap: var(--mastery-stage-gap) !important;
  margin: 0 !important;
  overflow: hidden !important;
}

body.mastery-page .mastery-review-stage {
  justify-self: center !important;
  min-height: 0 !important;
  height: auto !important;
  width: min(100%, 960px) !important;
  padding-inline: 62px !important;
  align-self: stretch !important;
  align-items: stretch !important;
  overflow: visible !important;
}

body.mastery-page .mastery-card-scene {
  align-self: stretch;
  width: min(100%, 800px) !important;
  height: var(--mastery-card-height, 100%) !important;
  min-height: 0 !important;
  max-height: var(--mastery-card-height, 100%) !important;
}

body.mastery-page .mastery-review-card,
body.mastery-page .mastery-review-card .card-face {
  min-height: 0 !important;
}

body.mastery-page .mastery-review-card .card-question-text,
body.mastery-page .mastery-review-card .card-answer-text-container {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  max-height: 100% !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
}

body.mastery-page .mastery-review-card .card-answer-text {
  max-height: none !important;
  overflow: visible !important;
}

body.mastery-page .mastery-bottom-controls {
  justify-self: center !important;
  flex: 0 0 auto !important;
  width: min(100%, 420px) !important;
  min-height: 52px !important;
  margin-top: 0 !important;
  padding-bottom: max(2px, env(safe-area-inset-bottom)) !important;
  overflow: visible !important;
}

/* Mastery editing layout: match flippable card with full-height editor. */
body.mastery-inline-editing .mastery-review-card {
  height: 100% !important;
  min-height: 0 !important;
  cursor: text !important;
}

body.mastery-inline-editing .mastery-review-card .card-face {
  height: 100% !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: flex-start !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain !important;
  -webkit-overflow-scrolling: touch !important;
  touch-action: pan-y !important;
  padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important;
}

body.mastery-inline-editing .mastery-review-card .card-question-text[contenteditable="true"],
body.mastery-inline-editing .mastery-review-card .card-answer-text-container {
  flex: 0 0 auto !important;
  min-height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  -webkit-overflow-scrolling: auto !important;
  touch-action: pan-y !important;
}

body.mastery-inline-editing .mastery-review-card .card-question-text[contenteditable="true"],
body.mastery-inline-editing .mastery-review-card .card-answer-text[contenteditable="true"] {
  flex: 0 0 auto !important;
  min-height: calc(100% - 12px) !important;
  max-height: none !important;
  overflow: visible !important;
  touch-action: pan-y !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

body.mastery-immersive .main-content,
body.mastery-immersive .mastery-dashboard,
body.mastery-immersive .mastery-review {
  height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  min-height: 0 !important;
  overflow: hidden !important;
}

body.mastery-immersive .mastery-dashboard {
  width: min(100% - 18px, 1100px) !important;
  margin: 0 auto !important;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)) !important;
}

body.mastery-immersive .mastery-review-stage {
  width: min(100%, 1020px) !important;
}

@media (min-width: 769px) and (max-width: 1180px) {
  body.mastery-page .mastery-dashboard {
    width: min(100% - 22px, 960px) !important;
    margin-top: 7px !important;
  }

  body.mastery-page .mastery-review-stage {
    width: 100% !important;
    padding-inline: 44px !important;
  }

  body.mastery-page .mastery-card-scene {
    width: min(100%, 820px) !important;
    height: var(--mastery-card-height, 100%) !important;
    min-height: 0 !important;
    max-height: var(--mastery-card-height, 100%) !important;
  }

  body.mastery-page .mastery-review-card .card-face {
    padding: 22px 28px !important;
  }
}

@media (hover: hover) and (pointer: fine) and (min-width: 769px) {
  html.mastery-shell-page:not(.touch-study-device):not(:has(body.mastery-immersive)) {
    height: auto !important;
    min-height: 100% !important;
    overflow: auto !important;
  }

  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) {
    height: auto !important;
    min-height: 100vh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) .app-container,
  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) .main-content {
    height: auto !important;
    min-height: 100vh !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) .mastery-dashboard {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 12px auto 48px !important;
    padding-bottom: calc(28px + env(safe-area-inset-bottom)) !important;
    overflow: visible !important;
  }

  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) .mastery-review {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: auto auto !important;
    justify-items: center !important;
    align-items: start !important;
    height: auto !important;
    min-height: 0 !important;
    gap: var(--mastery-stage-gap) !important;
    overflow: visible !important;
  }

  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) .mastery-review-stage {
    justify-self: center !important;
    height: auto !important;
    align-items: center !important;
    overflow: visible !important;
  }

  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) .mastery-card-scene {
    height: clamp(500px, calc(100dvh - 210px), 700px) !important;
    min-height: clamp(500px, calc(100dvh - 210px), 700px) !important;
    max-height: none !important;
  }

  html:not(.touch-study-device) body.mastery-page:not(.mastery-immersive) .mastery-bottom-controls {
    justify-self: center !important;
    margin-top: 0 !important;
    padding-bottom: max(0px, env(safe-area-inset-bottom)) !important;
  }
}

@media (max-width: 768px) {
  body.mastery-page .main-content {
    height: calc(100dvh / var(--study-page-zoom, 1)) !important;
  }

  body.mastery-page .mastery-dashboard {
    width: min(100% - 12px, 760px) !important;
    min-height: 0 !important;
    height: auto !important;
    margin-top: 5px !important;
    padding-bottom: max(5px, env(safe-area-inset-bottom)) !important;
  }

  body.mastery-page .mastery-review {
    --mastery-stage-gap: clamp(4px, 1dvh, 8px);
    gap: var(--mastery-stage-gap) !important;
  }

  body.mastery-page .mastery-review-stage {
    width: 100% !important;
    padding-inline: 5px !important;
    overflow: visible !important;
  }

  body.mastery-page .mastery-card-scene {
    width: 100% !important;
    height: var(--mastery-card-height, 100%) !important;
    min-height: 0 !important;
    max-height: var(--mastery-card-height, 100%) !important;
  }

  body.mastery-page .mastery-review-card .card-face {
    padding: clamp(14px, 3.6vw, 20px) clamp(12px, 3.2vw, 18px) !important;
  }

  body.mastery-page .mastery-review-stage .floating-nav-btn {
    top: 50% !important;
    z-index: 18 !important;
    width: 34px !important;
    height: 34px !important;
    border: 0 !important;
    border-radius: 999px !important;
    background: transparent !important;
    color: rgba(45, 90, 39, 0.46) !important;
    box-shadow: none !important;
    transform: translateY(-50%) !important;
  }

  body.mastery-page .mastery-review-stage .floating-nav-prev {
    left: 6px !important;
  }

  body.mastery-page .mastery-review-stage .floating-nav-next {
    right: 6px !important;
  }

  body.mastery-page .mastery-review-stage .floating-nav-symbol {
    font-size: 1.72rem !important;
  }

  body.mastery-page .mastery-bottom-controls {
    margin-top: 4px !important;
    padding-bottom: max(2px, env(safe-area-inset-bottom)) !important;
  }

  body.mastery-page .mastery-bottom-controls .card-review-controls {
    width: min(100%, 330px) !important;
  }
}

/* Final override: keep review-mode tabs centered after folder/action buttons were added. */
body.mastery-page .mastery-header-controls {
  display: grid !important;
  grid-template-columns: minmax(180px, 1fr) minmax(390px, max-content) minmax(180px, 1fr) !important;
  justify-content: stretch !important;
  align-items: stretch !important;
}

body.mastery-page .mastery-subject-cards { justify-self: end !important; }
body.mastery-page .recitation-review-tabs { justify-self: center !important; }
body.mastery-page .mastery-top-card-tools { justify-self: start !important; }

@media (max-width: 768px) {
  body.mastery-page .mastery-header-controls {
    display: flex !important;
    justify-content: flex-start !important;
  }
}

/* v0.22: compact mobile header with larger queue labels and wider green glass tools. */
@media (max-width: 768px) {
  body.mastery-page .mastery-top-bar {
    --mastery-subject-mobile-slot: clamp(108px, 29vw, 124px);
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) max-content !important;
    grid-template-rows: auto auto !important;
    align-items: center !important;
    gap: 6px 6px !important;
    padding: calc(7px + env(safe-area-inset-top)) 8px 7px !important;
    overflow: visible !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-left {
    grid-column: 1 !important;
    grid-row: 1 !important;
    z-index: 2 !important;
    width: auto !important;
    min-width: 48px !important;
    gap: 0 !important;
  }

  body.mastery-page .mastery-top-bar .current-chapter-info {
    display: none !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-left .toggle-btn {
    width: 48px !important;
    min-width: 48px !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 8px !important;
    border-radius: 8px !important;
    display: inline-grid !important;
    place-items: center !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-left .toggle-btn svg,
  body.mastery-page .mastery-top-bar .top-bar-left .toggle-btn i {
    width: 18px !important;
    min-width: 18px !important;
    height: 18px !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right {
    grid-column: 2 !important;
    grid-row: 1 !important;
    z-index: 2 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 1.5px !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right .theme-btn,
  body.mastery-page .mastery-top-bar .top-bar-right .settings-btn,
  body.mastery-page .mastery-top-bar .top-bar-right .account-sync-btn,
  body.mastery-page .mastery-top-bar .top-bar-right .account-profile-trigger {
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    min-height: 36px !important;
    aspect-ratio: 1 / 1 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 50% !important;
    background: transparent !important;
    box-shadow: none !important;
    display: inline-grid !important;
    place-items: center !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right .theme-btn svg {
    width: 22px !important;
    min-width: 22px !important;
    height: 22px !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right .settings-btn svg,
  body.mastery-page .mastery-top-bar .top-bar-right .account-sync-btn svg,
  body.mastery-page .mastery-top-bar .top-bar-right .account-profile-trigger svg {
    width: 25px !important;
    min-width: 25px !important;
    height: 25px !important;
  }

  body.mastery-page .mastery-top-bar .top-bar-right .account-sync-btn > span:not(.account-sync-avatar),
  body.mastery-page .mastery-top-bar .top-bar-right .account-profile-trigger > span:not(.account-sync-avatar) {
    display: none !important;
  }

  body.mastery-page .mastery-header-controls {
    display: contents !important;
    overflow: visible !important;
  }

  body.mastery-page .recitation-review-tabs {
    grid-column: 1 !important;
    grid-row: 1 !important;
    justify-self: stretch !important;
    align-self: center !important;
    width: auto !important;
    min-width: 0 !important;
    min-height: 44px !important;
    margin-left: 46px !important;
    padding: 3px 4px !important;
    gap: 3px !important;
    border-radius: 18px !important;
    overflow: visible !important;
  }

  body.mastery-page .recitation-review-tab {
    flex: 1 1 0 !important;
    min-width: 0 !important;
    min-height: 38px !important;
    padding: 0 3px !important;
    gap: 3px !important;
    border-radius: 14px !important;
  }

  body.mastery-page .recitation-review-tab:nth-child(2) {
    flex-grow: 1.42 !important;
  }

  body.mastery-page .recitation-review-tab:nth-child(3) {
    flex-grow: .82 !important;
  }

  body.mastery-page .recitation-review-tab span {
    max-width: none !important;
    font-size: .74rem !important;
    letter-spacing: 0 !important;
  }

  body.mastery-page .recitation-review-tab strong {
    min-width: 22px !important;
    height: 22px !important;
    padding: 0 5px !important;
    font-size: .84rem !important;
  }

  body.mastery-page .mastery-subject-cards {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    justify-self: stretch !important;
    width: 100% !important;
    min-width: 0 !important;
    min-height: 40px !important;
    padding-right: calc(100% - var(--mastery-subject-mobile-slot)) !important;
    box-sizing: border-box !important;
  }

  body.mastery-page .mastery-subject-picker {
    width: min(var(--mastery-subject-mobile-slot), 100%) !important;
    min-width: 104px !important;
  }

  body.mastery-page .mastery-subject-picker > summary {
    min-height: 46px !important;
    padding: 0 9px !important;
    gap: 6px !important;
    border-radius: 17px !important;
  }

  body.mastery-page .mastery-subject-picker > summary .mastery-subject-summary-label {
    min-width: 0 !important;
    overflow: hidden !important;
    text-overflow: clip !important;
    white-space: nowrap !important;
  }

  body.mastery-page .mastery-subject-picker > summary .mastery-subject-summary-count {
    display: none !important;
  }

  body.mastery-page .mastery-top-card-tools {
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    justify-self: end !important;
    align-self: center !important;
    width: calc(100% - var(--mastery-subject-mobile-slot) - 6px) !important;
    min-height: 46px !important;
    flex-wrap: nowrap !important;
    padding: 3px !important;
    gap: 2px !important;
    border-radius: 19px !important;
    border: 1px solid color-mix(in srgb, var(--primary-color) 17%, rgba(255,255,255,.72)) !important;
    background: linear-gradient(135deg, color-mix(in srgb, var(--primary-light) 64%, rgba(255,255,255,.84) 36%), color-mix(in srgb, var(--panel-bg) 70%, var(--primary-light) 30%)) !important;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.86), 0 10px 24px rgba(31,54,38,.11) !important;
    backdrop-filter: blur(16px) !important;
    -webkit-backdrop-filter: blur(16px) !important;
    overflow: visible !important;
  }

  body.mastery-page .mastery-top-card-tools .flashcard-icon-btn {
    flex: 1 1 0 !important;
    width: auto !important;
    min-width: 40px !important;
    height: 40px !important;
    min-height: 40px !important;
    border-radius: 15px !important;
    border-color: color-mix(in srgb, var(--primary-color) 18%, rgba(255,255,255,.72)) !important;
    background: color-mix(in srgb, var(--panel-bg) 72%, var(--primary-light) 28%) !important;
    color: var(--primary-color) !important;
    box-shadow: inset 0 1px 0 rgba(255,255,255,.84), 0 6px 15px rgba(47,107,47,.08) !important;
  }

  body.mastery-page .mastery-top-card-tools .flashcard-icon-btn svg,
  body.mastery-page .mastery-top-card-tools .flashcard-icon-btn i {
    width: 19px !important;
    min-width: 19px !important;
    height: 19px !important;
  }

  @media (max-width: 420px) {
    body.mastery-page .recitation-review-tab span {
      width: auto !important;
      max-width: none !important;
      font-size: 0 !important;
      line-height: 1 !important;
    }

    body.mastery-page .recitation-review-tab span::before {
      display: inline-block !important;
      color: var(--text-muted) !important;
      font-size: .72rem !important;
      font-weight: 900 !important;
      white-space: nowrap !important;
    }

    body.mastery-page .recitation-review-tab[data-review-mode="overdue"] span::before { content: "\903E\671F"; }
    body.mastery-page .recitation-review-tab[data-review-mode="due"] span::before { content: "\5F85\590D\4E60"; }
    body.mastery-page .recitation-review-tab[data-review-mode="future"] span::before { content: "\4EE5\540E"; }
  }

  @media (max-width: 380px) {
    body.mastery-page .mastery-top-bar {
      --mastery-subject-mobile-slot: 104px;
    }

    body.mastery-page .mastery-top-bar .top-bar-left {
      width: auto !important;
      min-width: 44px !important;
    }

    body.mastery-page .mastery-top-bar .top-bar-left .toggle-btn {
      width: 44px !important;
      min-width: 44px !important;
      height: 34px !important;
      min-height: 34px !important;
      padding: 0 6px !important;
      border-radius: 8px !important;
    }

    body.mastery-page .mastery-top-bar .top-bar-right .theme-btn,
    body.mastery-page .mastery-top-bar .top-bar-right .settings-btn,
    body.mastery-page .mastery-top-bar .top-bar-right .account-sync-btn,
    body.mastery-page .mastery-top-bar .top-bar-right .account-profile-trigger {
      width: 38px !important;
      min-width: 38px !important;
      height: 38px !important;
      min-height: 38px !important;
      aspect-ratio: 1 / 1 !important;
      border: none !important;
      background: transparent !important;
      box-shadow: none !important;
    }

    body.mastery-page .recitation-review-tab {
      padding-inline: 2px !important;
    }

    body.mastery-page .recitation-review-tab strong {
      min-width: 20px !important;
      height: 20px !important;
      padding: 0 4px !important;
      font-size: .78rem !important;
    }

    body.mastery-page .mastery-top-card-tools .flashcard-icon-btn {
      min-width: 37px !important;
    }
  }
}

/* ==========================================================================
   Touch device & Tablet Mastery card layout: Flatten 3D context so Android/HarmonyOS/iPad touch scrolling works natively.
   ========================================================================== */
html.touch-study-device body.mastery-page .mastery-card-scene,
body.mastery-page .mastery-card-scene {
  perspective: none !important;
}

html.touch-study-device body.mastery-page .mastery-review-card,
body.mastery-page .mastery-review-card {
  transform: none !important;
  transform-style: flat !important;
  transition: none !important;
}

html.touch-study-device body.mastery-page .mastery-review-card .card-face,
body.mastery-page .mastery-review-card .card-face {
  inset: 0 !important;
  transform: none !important;
  backface-visibility: visible !important;
  -webkit-backface-visibility: visible !important;
  transition: opacity 0.18s ease, visibility 0.18s ease !important;
}

html.touch-study-device body.mastery-page .mastery-review-card .card-face.card-back,
body.mastery-page .mastery-review-card .card-face.card-back {
  display: flex !important;
  flex-direction: column !important;
  justify-content: flex-start !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain !important;
  -webkit-overflow-scrolling: touch !important;
  touch-action: pan-y !important;
  padding-bottom: calc(24px + env(safe-area-inset-bottom)) !important;
}

html.touch-study-device body.mastery-page .mastery-review-card:not(.is-flipped) .card-front,
body.mastery-page .mastery-review-card:not(.is-flipped) .card-front {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

html.touch-study-device body.mastery-page .mastery-review-card:not(.is-flipped) .card-back,
body.mastery-page .mastery-review-card:not(.is-flipped) .card-back {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

html.touch-study-device body.mastery-page .mastery-review-card.is-flipped .card-front,
body.mastery-page .mastery-review-card.is-flipped .card-front {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

html.touch-study-device body.mastery-page .mastery-review-card.is-flipped .card-back,
body.mastery-page .mastery-review-card.is-flipped .card-back {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

html.touch-study-device body.mastery-page .mastery-review-card.is-flipped .card-answer-text-container,
body.mastery-page .mastery-review-card.is-flipped .card-answer-text-container {
  position: relative !important;
  flex: 0 0 auto !important;
  min-height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  -webkit-overflow-scrolling: auto !important;
  touch-action: pan-y !important;
}

html.touch-study-device body.mastery-page .mastery-review-card.is-flipped .card-answer-text,
body.mastery-page .mastery-review-card.is-flipped .card-answer-text {
  max-height: none !important;
  overflow: visible !important;
  touch-action: pan-y !important;
}

body.mastery-page:not(.mastery-annotation-active) .mastery-annotation-canvas {
  pointer-events: none !important;
  touch-action: auto !important;
}

body.mastery-page .mastery-annotation-canvas.is-active {
  pointer-events: auto !important;
}

body.mastery-page .mastery-annotation-canvas.is-active.touch-draw-disabled {
  touch-action: pan-y !important;
}

body.mastery-page .mastery-annotation-canvas.is-active.touch-draw-enabled {
  touch-action: none !important;
}

body.mastery-page .mastery-annotation-toolbar:not([hidden]) {
  position: fixed !important;
  left: calc(50% + var(--flashcard-annotation-toolbar-x, 0px)) !important;
  right: auto !important;
  top: auto !important;
  bottom: calc(92px + env(safe-area-inset-bottom)) !important;
  z-index: 1000025 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-wrap: nowrap !important;
  gap: 6px !important;
  width: max-content !important;
  max-width: calc(100vw - 24px) !important;
  margin: 0 !important;
  padding: 7px 8px !important;
  box-sizing: border-box !important;
  border-radius: 18px !important;
  box-shadow: 0 16px 36px rgba(31, 54, 38, 0.18) !important;
  transform: translate(-50%, var(--flashcard-annotation-toolbar-y, 0px)) !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scrollbar-width: none !important;
  touch-action: none !important;
  -webkit-overflow-scrolling: touch !important;
}

body.mastery-page .mastery-annotation-toolbar:not([hidden])::-webkit-scrollbar {
  display: none !important;
}

body.mastery-page .mastery-annotation-toolbar.is-dragging {
  cursor: grabbing !important;
  user-select: none !important;
}

body.mastery-page .mastery-annotation-toolbar .anno-color {
  flex: 0 0 30px !important;
  width: 30px !important;
  height: 30px !important;
}

body.mastery-page .mastery-annotation-toolbar .anno-width {
  flex: 0 0 124px !important;
  max-width: 124px !important;
  min-width: 124px !important;
  justify-content: center !important;
  gap: 6px !important;
  white-space: nowrap !important;
}

body.mastery-page .mastery-annotation-toolbar .anno-width input {
  width: 66px !important;
}

body.mastery-page .mastery-annotation-toolbar .btn {
  flex: 0 0 auto !important;
  min-height: 34px !important;
  padding: 0 10px !important;
  border-radius: 11px !important;
  font-size: 0.82rem !important;
  line-height: 1 !important;
  white-space: nowrap !important;
}

body.mastery-page .mastery-annotation-toolbar [data-anno-action="undo"],
body.mastery-page .mastery-annotation-toolbar [data-anno-action="close"] {
  min-width: 58px !important;
}

body.mastery-page .mastery-annotation-toolbar .anno-eraser-btn {
  min-width: 70px !important;
}

body.mastery-page .mastery-annotation-toolbar .anno-drag-handle {
  flex: 0 0 26px !important;
  width: 26px !important;
  height: 34px !important;
  display: inline-grid !important;
  grid-template-rows: repeat(3, 4px) !important;
  row-gap: 3px !important;
  place-items: center !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 999px !important;
  background: color-mix(in srgb, var(--primary-light) 54%, transparent) !important;
  cursor: grab !important;
  touch-action: none !important;
}

body.mastery-page .mastery-annotation-toolbar.is-dragging .anno-drag-handle,
body.mastery-page .mastery-annotation-toolbar .anno-drag-handle:active {
  cursor: grabbing !important;
}

body.mastery-page .mastery-annotation-toolbar .anno-drag-handle span,
body.mastery-page .mastery-annotation-toolbar .anno-drag-handle::before,
body.mastery-page .mastery-annotation-toolbar .anno-drag-handle::after {
  content: "";
  display: block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary-color) 62%, transparent);
}

body.mastery-page .mastery-annotation-toolbar:not([hidden]) * {
  pointer-events: auto !important;
}

@media (max-width: 768px) {
  body.mastery-immersive .mastery-dashboard {
    width: calc(100vw - 10px) !important;
    max-width: none !important;
    margin: 0 auto !important;
    padding: max(5px, env(safe-area-inset-top)) 0 max(6px, env(safe-area-inset-bottom)) !important;
  }

  body.mastery-immersive .mastery-review {
    --mastery-stage-gap: clamp(5px, 1dvh, 9px);
  }

  body.mastery-immersive .mastery-review-stage {
    width: 100% !important;
    max-width: none !important;
    padding-inline: 0 !important;
  }

  body.mastery-immersive .mastery-card-scene {
    width: 100% !important;
    max-width: none !important;
  }

  body.mastery-immersive .mastery-review-card .card-face {
    padding-inline: clamp(13px, 3.4vw, 18px) !important;
  }

  body.mastery-page .mastery-annotation-toolbar:not([hidden]) {
    left: 50% !important;
    bottom: calc(88px + env(safe-area-inset-bottom)) !important;
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    justify-content: center !important;
    align-content: center !important;
    flex-wrap: wrap !important;
    gap: 7px 6px !important;
    padding: 7px 6px !important;
    overflow: visible !important;
    transform: translate(-50%, var(--flashcard-annotation-toolbar-y, 0px)) !important;
  }

  body.mastery-page .mastery-annotation-toolbar .anno-color {
    flex-basis: 28px !important;
    width: 28px !important;
    height: 28px !important;
  }

  body.mastery-page .mastery-annotation-toolbar .anno-width {
    flex: 0 1 114px !important;
    min-width: 108px !important;
    max-width: 118px !important;
  }

  body.mastery-page .mastery-annotation-toolbar .anno-width input {
    width: 56px !important;
  }

  body.mastery-page .mastery-annotation-toolbar .btn {
    min-height: 32px !important;
    padding: 0 9px !important;
    font-size: 0.78rem !important;
  }

  body.mastery-page .mastery-annotation-toolbar .anno-eraser-btn {
    min-width: 64px !important;
  }
}

/* ==========================================================================
   Mastery Immersive Mode - Definitive Override (Placed at end of file)
   ========================================================================== */
body.mastery-immersive {
  overflow: hidden !important;
  background: var(--bg-color) !important;
}

body.mastery-page.mastery-immersive .app-container {
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100% !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  z-index: 10000020 !important;
  background: var(--bg-color) !important;
  isolation: isolate !important;
  margin: 0 !important;
  padding: 0 !important;
}

body.mastery-page.mastery-immersive .main-content {
  width: 100vw !important;
  height: 100% !important;
  height: 100dvh !important;
  min-height: 100dvh !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

body.mastery-page.mastery-immersive .mastery-top-bar,
body.mastery-page.mastery-immersive .recitation-review-tabs,
body.mastery-page.mastery-immersive .glow-container,
body.mastery-page.mastery-immersive #feedback-trigger-btn,
body.mastery-page.mastery-immersive .ai-qa-launcher,
body.mastery-page.mastery-immersive .ai-chat-launcher,
body.mastery-page.mastery-immersive .modal-backdrop,
body.mastery-page.mastery-immersive .settings-modal,
body.mastery-page.mastery-immersive .pwa-help-modal,
body.mastery-page.mastery-immersive .account-sync-panel,
body.mastery-page.mastery-immersive .account-sync-backdrop,
body.mastery-page.mastery-immersive .study-pull-square-hit-zone {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

body.mastery-page.mastery-immersive .mastery-dashboard {
  width: min(100% - 16px, 980px) !important;
  max-width: 980px !important;
  height: 100% !important;
  height: 100dvh !important;
  max-height: 100dvh !important;
  margin: 0 auto !important;
  padding: max(14px, env(safe-area-inset-top)) 8px max(14px, env(safe-area-inset-bottom)) !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
}

body.mastery-page.mastery-immersive .mastery-review {
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  align-items: center !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: 100% !important;
}

body.mastery-page.mastery-immersive .mastery-review-stage {
  width: 100% !important;
  max-width: 920px !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  padding-inline: 0 !important;
}

body.mastery-page.mastery-immersive .mastery-card-scene {
  width: 100% !important;
  height: clamp(380px, calc(100dvh - 160px), 640px) !important;
  max-height: calc(100dvh - 140px) !important;
}

body.mastery-page.mastery-immersive .mastery-immersive-exit-btn {
  display: grid !important;
  position: fixed !important;
  top: max(14px, env(safe-area-inset-top)) !important;
  right: 14px !important;
  z-index: 10000030 !important;
}

@media (min-width: 769px) {
  body.mastery-page.mastery-immersive .mastery-dashboard {
    width: 100vw !important;
    max-width: 100vw !important;
    padding: max(22px, env(safe-area-inset-top)) max(48px, env(safe-area-inset-right)) max(22px, env(safe-area-inset-bottom)) max(48px, env(safe-area-inset-left)) !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  body.mastery-page.mastery-immersive .mastery-review {
    width: min(100%, 980px) !important;
    max-width: 980px !important;
    align-items: center !important;
    justify-content: center !important;
    gap: clamp(12px, 2dvh, 22px) !important;
    margin-inline: auto !important;
  }

  body.mastery-page.mastery-immersive .mastery-review-stage {
    width: min(100%, 920px) !important;
    max-width: 920px !important;
    align-items: center !important;
    justify-content: center !important;
    margin-inline: auto !important;
  }

  body.mastery-page.mastery-immersive .mastery-card-scene {
    width: min(100%, 820px) !important;
    max-width: 820px !important;
    margin-inline: auto !important;
  }

  body.mastery-page.mastery-immersive .mastery-bottom-controls {
    width: min(100%, 430px) !important;
    margin-inline: auto !important;
  }
}


/* Mastery Mobile Immersive Fullscreen Spacing Optimization */
@media (max-width: 768px) {
  body.mastery-page.mastery-immersive .mastery-dashboard {
    width: calc(100vw - 8px) !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    margin: 0 auto !important;
    padding: max(4px, env(safe-area-inset-top)) 4px max(4px, env(safe-area-inset-bottom)) !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    gap: 4px !important;
  }

  body.mastery-page.mastery-immersive .mastery-review {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
    width: 100% !important;
    gap: 4px !important;
  }

  body.mastery-page.mastery-immersive .mastery-review-stage {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: stretch !important;
    padding-inline: 0 !important;
  }

  body.mastery-page.mastery-immersive .mastery-card-scene {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 auto !important;
    height: 100% !important;
    max-height: none !important;
    min-height: 0 !important;
  }

  body.mastery-page.mastery-immersive .mastery-review-card {
    height: 100% !important;
    min-height: 0 !important;
  }

  body.mastery-page.mastery-immersive .mastery-review-card .card-face {
    height: 100% !important;
    padding: 14px 12px !important;
  }

  body.mastery-page.mastery-immersive .mastery-bottom-controls {
    margin-top: 2px !important;
    margin-bottom: max(2px, env(safe-area-inset-bottom)) !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
    width: 100% !important;
  }
}

/* Final override: keep definition question and answer spacing aligned with flashcard mode. */
body.mastery-page .mastery-review-card.is-definition-review .card-front {
  justify-content: flex-start !important;
  gap: 14px !important;
}

body.mastery-page .mastery-review-card.is-definition-review .card-question-text {
  flex: 0 0 auto !important;
  flex-grow: 0 !important;
  min-height: auto !important;
  height: auto !important;
  max-height: none !important;
  display: block !important;
  align-items: initial !important;
  justify-content: initial !important;
  padding: 6px 12px 14px !important;
  margin: 4px 0 6px !important;
  text-align: center !important;
  border-bottom: 1px solid var(--border-color) !important;
  width: 100% !important;
}

body.mastery-page .mastery-review-card.is-definition-review .mastery-definition-answer {
  flex: 1 1 auto !important;
  margin-top: 0 !important;
}

@media (max-width: 768px) {
  body.mastery-page .mastery-dashboard {
    width: min(100% - 8px, 760px) !important;
  }

  body.mastery-page .mastery-review-stage {
    padding-inline: 16px !important;
  }

  body.mastery-page .mastery-card-scene {
    width: min(100%, 460px) !important;
  }

  body.mastery-page .mastery-review-card .card-face {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }

  body.mastery-page .mastery-review-card.is-definition-review .card-question-text {
    padding-left: 6px !important;
    padding-right: 6px !important;
  }

  body.mastery-page .mastery-definition-answer {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  body.mastery-page .mastery-definition-answer .card-answer-text-container,
  body.mastery-page .mastery-definition-answer .mastery-answer-text {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }
}

/* Final override: desktop/tablet immersive review must stay centered after page zoom compensation. */
@supports (zoom: 1) {
  @media (min-width: 769px) {
    body.mastery-page.mastery-immersive .app-container,
    body.mastery-page.mastery-immersive .main-content,
    body.mastery-page.mastery-immersive .mastery-dashboard {
      width: calc(100vw / var(--study-page-zoom, 1)) !important;
      max-width: none !important;
      height: calc(100dvh / var(--study-page-zoom, 1)) !important;
      min-height: calc(100dvh / var(--study-page-zoom, 1)) !important;
      box-sizing: border-box !important;
    }

    body.mastery-page.mastery-immersive .mastery-dashboard {
      margin: 0 auto !important;
      align-items: center !important;
      justify-content: center !important;
    }

    body.mastery-page.mastery-immersive .mastery-review,
    body.mastery-page.mastery-immersive .mastery-review-stage,
    body.mastery-page.mastery-immersive .mastery-card-scene,
    body.mastery-page.mastery-immersive .mastery-bottom-controls {
      margin-left: auto !important;
      margin-right: auto !important;
    }
  }
}
