:root {
    --bg: #0A0E17;
    /* Deep Navy */
    --surface: #112240;
    /* Light Navy */
    --surface-2: #1d2d50;
    /* Lighter Navy */
    --border: rgba(100, 255, 218, 0.1);
    /* Neon Green tinted border */
    --text: #CCD6F6;
    /* Light Slate/White */
    --text-muted: #8892B0;
    /* Slate */
    --accent: #5EEAD4;
    /* Vibrant Teal/Cyan */
    --chip-ink: #0A0E17;
    /* Text laid on an --accent fill. The dark theme's accent is a *bright*
       teal, so the readable ink on it is near-black; the light theme's is a
       deep teal and needs white. Hard-coding either colour breaks one theme,
       which is why this is a token and not a literal. */
    --neon-green: #5EEAD4;
    --accent-glow: rgba(94, 234, 212, 0.2);
    --easy: #64FFDA;
    --medium: #FF9D00;
    /* Orange Accent */
    --hard: #F44336;
    /* Red Accent */
    --logic-token: #BD93F9;
    /* Purple Accent */
    --blue-accent: #8BE9FD;
    --review-bg: #4c3322;
    --review-text: #FF9D00;
    --card-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
    --vocab-panel-width: 640px;
    --vocab-bottom-gap: calc(24px + env(safe-area-inset-bottom, 0px));
    /* 通栏 54 + 21 + 进度条 5 + 21：窄屏上进度条上下的空白一起收小，
       卡片和评分键因此整体上移。 */
    --task-card-top: 101px;
    --vocab-card-width: 400px;
    --vocab-card-height: 480px;
    --vocab-card-radius: 24px;
    --vocab-card-action-gap: 34px;
    --vocab-card-action-height: 58px;
    /* 页面样式统一幅宽：手机上 min() 自动塌成满宽，故无需断点 */
    --page-width: 880px;
    --page-pad-x: 24px;
    --page-gap: 18px;
    --page-topbar-height: 54px;
    --page-topbar-slot: 44px;
    /* 通栏分割线：一条线 + 下缘高光，读起来像切割出的凹槽。
       全站唯一来源 —— 学习页的 .app-header::after 与统一顶栏 .page-topbar 共用。
       深色用主题青绿，浅色见 [data-theme="light"] 覆盖（青绿在浅背景上不可见）。 */
    --page-topbar-line: rgba(94, 234, 212, 0.18);
    --page-topbar-line-lip: rgba(255, 255, 255, 0.035);
    --page-content-top: 24px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none !important;
    -webkit-user-select: none !important;
}

input,
textarea,
[contenteditable=""],
[contenteditable="true"] {
    user-select: text !important;
    -webkit-user-select: text !important;
}

html {
    touch-action: auto;
}

/* hidden 属性必须真的隐藏。任何带 display 的类规则（.vd-known 是 block、
   .vd-choices 是 grid）特异性都高于 UA 的 [hidden]{display:none}，
   于是 el.hidden = true 会失效。这条一次性堵住这类 bug——
   仓库里各组件此前是逐个再写一遍 .x[hidden]{display:none} 来绕过的。 */
[hidden] {
    display: none !important;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, sans-serif;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: auto;
}

/* A single compensated canvas scales the complete vocabulary experience as one
   unit on short desktop viewports. Fixed overlays remain inside this canvas. */
#vocabPageRoot {
    position: fixed;
    top: 0;
    left: 50%;
    width: var(--vocab-page-logical-width, 100vw);
    height: var(--vocab-page-logical-height, 100dvh);
    overflow: hidden;
    background: var(--bg);
    transform: translateX(-50%) scale(var(--vocab-page-scale, 1));
    transform-origin: top center;
    isolation: isolate;
}

/* ─── 页面样式外壳 (Page Shell) ──────────────────────
   所有「页面样式」屏幕共用同一套幅宽、内边距与区块间距：
   结算 / 词义加固 / 听写 / 拼字 / 智能阅读 / 朗读练习。
   「卡片样式」（学习卡 .card-scene、插页 .interstitial-card）
   不走这一层，保持原有 --vocab-card-width 体系。 */

.page-shell {
    width: 100%;
    max-width: var(--page-width);
    margin-inline: auto;
}

/* 文档流式页面（结算、朗读报告）：纵向堆叠 + 统一区块间距。
   听写/拼字/阅读那类满屏 flex 布局只取 .page-shell 的幅宽，不加这一层。 */
.page-shell--flow {
    display: grid;
    align-content: start;
    gap: var(--page-gap);
}

/* 页面样式屏幕的滚动容器：顶部对齐、整页可滚、隐藏滚动条 */
.page-scroll {
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: auto;
    padding: max(24px, env(safe-area-inset-top, 0px)) var(--page-pad-x) var(--vocab-bottom-gap);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.page-scroll::-webkit-scrollbar {
    display: none;
}

/* ─── 统一顶栏 (Page Topbar) ─────────────────────────
   左槽 ← ／ 中槽 页面名（居中）／ 右槽 按场景内容。
   右槽即使为空也必须保留，否则中间标题无法真正居中。
   右槽内容按语义填：任务页 = 主题切换，听写/拼字 = 计数，详情浮层 = 留空。

   分割线通栏：遮罩层带 --page-pad-x 横向内边距，这里用等量负外边距抵消，
   使顶栏横跨整个视口，而不是止步于 .page-shell 的 880px。 */
.page-topbar {
    flex-shrink: 0;
    align-self: stretch;
    margin-inline: calc(-1 * var(--page-pad-x));
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--bg);
    border-bottom: 1px solid var(--page-topbar-line);
    box-shadow: 0 1px 0 var(--page-topbar-line-lip);
}

.page-topbar-inner {
    display: grid;
    grid-template-columns: var(--page-topbar-slot) minmax(0, 1fr) var(--page-topbar-slot);
    align-items: center;
    gap: 8px;
    height: var(--page-topbar-height);
    padding-inline: max(8px, env(safe-area-inset-left, 0px)) max(8px, env(safe-area-inset-right, 0px));
}

/* 三个槽位显式绑定到栅格列：任何一个槽 display:none 时（例如智能阅读
   在必做状态下隐藏返回键），其余槽也不会串位，标题始终居中。 */
.page-topbar-start {
    grid-column: 1;
    justify-self: start;
}

.page-topbar-title {
    grid-column: 2;
}

.page-topbar-end {
    grid-column: 3;
    justify-self: end;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.page-topbar-title {
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 结算页在滚动容器内，顶栏需吸顶 */
.page-topbar--sticky {
    position: sticky;
    top: 0;
    z-index: 20;
}

/* 顶栏与其下方内容的统一间距 */
.page-topbar + .page-shell {
    padding-top: var(--page-content-top);
}

/* ─── 功能页外壳 (Page Frame) ────────────────────────
   整页占屏的功能页共用：满屏底色 + 横向内边距，顶栏用等量负外边距抵消该
   内边距实现通栏分割线，内容区自己滚（body 是 100dvh + overflow:hidden）。

   与 dashboard 的 .db-story-overlay 的区别只在语义：那一层是从别的页面滑出来
   的模态浮层，带 translateX 动画；这些页面是独立 URL，没有"滑出来"这回事，
   所以这里不带动画，也不占 z-index。 */
.page-frame {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    padding-inline: var(--page-pad-x);
}

/* 顶栏之下、占满剩余高度的纵向容器 */
.page-frame-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* 功能页的滚动区。滚动条隐藏与 .page-scroll 保持一致。 */
.page-pane {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0 40px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.page-pane::-webkit-scrollbar {
    display: none;
}

/* 功能页上承载一段内容的面板 */
.page-panel {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 14px;
}

/* ─── LOADING & ERROR ───────────────────────────── */
#loadingScreen,
#errorScreen,
#app,
#successView,
#summaryView,
#interstitialView {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    text-align: center;
    z-index: 2000;
    background: var(--bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    will-change: opacity;
    transform: translateZ(0);
}

#loadingScreen.show,
#errorScreen.show,
#app.show,
#successView.show,
#summaryView.show,
#interstitialView.show {
    opacity: 1;
    pointer-events: auto;
}

.error-retry-btn {
    margin-top: 18px;
    min-width: 180px;
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 28%, transparent);
}

.error-retry-btn:active {
    transform: translateY(1px);
}

/* 与 .page-scroll 同值；因基础规则用 id 选择器，此处必须保持 id 特异性。
   顶部内边距归零：吸顶顶栏自行处理安全区，其分割线需贴到视口顶部边缘。 */
#summaryView {
    justify-content: flex-start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: auto;
    padding: 0 var(--page-pad-x) var(--vocab-bottom-gap);
    scrollbar-width: none;
}

#summaryView::-webkit-scrollbar {
    display: none;
}

#app {
    --task-topbar-height: 54px;
    background: var(--bg);
    justify-content: flex-start;
    padding: var(--task-card-top) 0 var(--vocab-bottom-gap);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#app::-webkit-scrollbar {
    display: none;
}

/* Shared card anchor: the controls below the learning card never affect its Y position. */
#learningView {
    flex: 0 0 auto;
    justify-content: flex-start;
}

.loader-ring {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(124, 58, 237, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ─── HEADER & PROGRESS ─────────────────────────── */
.app-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 0;
    height: var(--task-topbar-height, 54px);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    flex-shrink: 0;
    background: var(--bg);
    z-index: 20;
}

.app-header::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: calc(var(--task-topbar-height, 54px) - 1px);
    height: 1px;
    /* 与 .page-topbar 共用同一条分割线 */
    background: var(--page-topbar-line);
    box-shadow: 0 1px 0 var(--page-topbar-line-lip);
    pointer-events: none;
    z-index: 2;
}

.header-top {
    width: 100%;
    display: flex;
    align-items: center;
    position: relative;
    background: var(--bg);
}

.header-top::after {
    content: none;
}

.task-header-inner {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    height: 54px;
    padding: 0 max(12px, env(safe-area-inset-right)) 0 max(4px, env(safe-area-inset-left));
    box-sizing: border-box;
}

/* Short canvases (iPad landscape, most laptops) are not a separate learning
   layout either. The bar, the progress bar and the card keep their size; only
   the air between them tightens: the card moves up (152px → 124px, the progress
   bar staying centred in the band), the card-to-controls gap takes the phone's
   34px and the controls drop from 80px to 64px. That stack is
   COMPACT_LAYOUT_HEIGHT in vocab-page-viewport.js, which sets this class and
   scales the canvas only when even the compact stack does not fit. The interstitial
   and sidecar cards anchor on --task-card-top and follow without their own rule. */
html.vocab-compact {
    --task-card-top: 124px;
    --vocab-card-action-gap: 34px;
    --vocab-card-action-height: 64px;
    --vocab-bottom-gap: calc(16px + env(safe-area-inset-bottom, 0px));
}

.app-header .back-btn,
.app-header .audio-toggle-btn {
    height: 54px;
    min-width: 40px;
    padding-top: 0;
    padding-bottom: 0;
    align-items: center;
    justify-content: center;
}

.back-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 6px;
    border-radius: 8px;
    flex-shrink: 0;
    transition: background 0.15s;
}
.back-btn:hover { background: var(--accent-glow); }

.back-btn svg,
.audio-toggle-btn svg,
.theme-toggle-btn svg {
    display: block;
}

.logo {
    font-weight: 700;
    font-size: 18px;
    color: var(--text);
    font-family: 'Noto Serif', serif;
    letter-spacing: 0.02em;
}

/* ── Progress section (replaces old progress-container) ── */
.header-progress-section {
    position: absolute;
    top: var(--task-topbar-height, 54px);
    left: 0;
    right: 0;
    width: min(calc(100vw - 36px), 420px);
    max-width: none;
    height: calc(var(--task-card-top, 101px) - var(--task-topbar-height, 54px));
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    /* 进度条落在通栏线与卡片上缘的正中。这一带只剩一根细条：贴着分割线，
       它读成通栏下的第二条线，下方的空白像没用上；居中才是通栏与卡片之间
       独立的一层。空白多少由 --task-card-top 定，窄屏收小，两边一起收。 */
    justify-content: center;
    padding: 0;
    box-sizing: border-box;
}

/* legacy selectors kept for other pages that may use them */
.header-progress-container {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

#standardHeaderContent {
    width: 100%;
}

.progress-meta {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.progress-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

/* The session bar on the word card and the 拼字 / 听写 cards: one segment per
   card (_renderProgressSegments in js/vocab/shared.js). Finished cards are
   filled; the count itself is on the card. */
.progress-bar-track {
    width: 100%;
    height: 5px;
    display: flex;
    gap: 4px;
}

.progress-bar-track.is-dense { gap: 2px; }
.progress-bar-track.is-crowded { gap: 1px; }

.progress-seg {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    border-radius: 999px;
    overflow: hidden;
    background: color-mix(in srgb, var(--text-muted) 20%, transparent);
}

/* A finished segment fills from its left end, so the bar still reads as moving
   forward while each card stays one step. */
.progress-seg::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: var(--accent);
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 0.36s cubic-bezier(0.22, 1, 0.36, 1);
}

.progress-seg.is-done::after {
    transform: scaleX(1);
}

@media (prefers-reduced-motion: reduce) {
    .progress-seg::after { transition: none; }
}

.retry-hint {
    font-size: 11px;
    font-weight: 700;
    color: #ffe7b0;
    letter-spacing: 0.04em;
    text-align: right;
    padding: 4px 10px;
    min-height: 0;
    border-radius: 999px;
    border: 1px solid rgba(255, 189, 89, 0.22);
    background: rgba(255, 174, 73, 0.1);
    box-shadow: inset 0 1px 0 rgba(255, 248, 214, 0.08);
}

/* At the top bar's right end, level with the back button. */
.app-header .retry-hint {
    margin-left: auto;
    flex: none;
}

/* ─── 发音键：声波动画 ─────────────────────────────
   凡是带 .audio-wave-control 的喇叭，播放时两道声波按同一个节奏呼吸。放在这里
   而不是 vocab.css 里，是因为拼读专项那一页只加载 common.css + practice.css +
   srs-card.css —— 动画留在 vocab.css 就意味着同一颗键在两页上的行为不一样。 */
.audio-wave {
    transform-box: fill-box;
    transform-origin: left center;
}

.audio-wave-control.is-playing .audio-wave-inner {
    animation: audio-wave-breathe 0.72s ease-out infinite;
}

.audio-wave-control.is-playing .audio-wave-outer {
    animation: audio-wave-breathe 0.72s ease-out 0.12s infinite;
}

@keyframes audio-wave-breathe {
    0% {
        opacity: 0.35;
        transform: scaleX(0.65) translateX(-1px);
    }
    45% {
        opacity: 1;
        transform: scaleX(1.12) translateX(1px);
    }
    100% {
        opacity: 0.45;
        transform: scaleX(0.86) translateX(0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .audio-wave-control.is-playing .audio-wave-inner,
    .audio-wave-control.is-playing .audio-wave-outer {
        animation: none;
        opacity: 1;
    }
}

/* ─── SRS OVERLAY ───────────────────────────────── */
.footer-btns {
    position: relative;
    margin-top: 56px;
    width: 100%;
    max-width: 352px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    z-index: 50;

    /* Ensure stability: always occupy space but start hidden */
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s;
    margin-left: auto;
    margin-right: auto;
}

.footer-btns.show {
    visibility: visible;
    opacity: 1;
}

/* Shared four-rating geometry for word and phonogram cards. Keep dimensions
   here so both flows respond identically instead of copying breakpoint rules. */
.footer-btns.srs-four-up {
    max-width: 400px;
    margin-top: var(--vocab-card-action-gap);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.srs-four-up .srs-grade-btn {
    min-height: var(--vocab-card-action-height);
    border-radius: 18px;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 10px 4px 9px;
    text-align: center;
}

.srs-four-up .grade-title {
    font-size: 14px;
}

.srs-four-up:not(.compact-mode) .grade-main {
    gap: 0;
    width: auto;
    justify-content: center;
}

.srs-four-up:not(.compact-mode) .grade-icon {
    display: none;
}

.srs-four-up:not(.compact-mode) .grade-copy {
    align-items: center;
}

.srs-four-up .grade-hint {
    font-size: 10px;
    letter-spacing: 0.02em;
}

.footer-btns.compact-mode {
    max-width: 288px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.footer-btns.single-choice {
    max-width: 288px;
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
}

.footer-btns.single-choice .srs-grade-btn {
    width: 100%;
}

.srs-grade-btn {
    min-height: 68px;
    border-radius: 22px;
    font-size: 16px;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        background-color 0.2s ease,
        filter 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 4px;
    padding: 14px 16px;
    text-align: left;
    transform-origin: center;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.srs-grade-btn.is-hidden {
    display: none;
}

.grade-title {
    font-weight: 800;
    line-height: 1;
    white-space: nowrap;
}

.grade-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 14px;
    min-width: 0;
}

.grade-copy {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
    flex: 1;
}

.grade-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: stretch;
    width: 24px;
    min-height: 100%;
    opacity: 0.52;
}

.grade-icon svg {
    display: block;
    width: 18px;
    height: 18px;
}

.grade-hint {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    opacity: 0.72;
    white-space: nowrap;
}

.srs-grade-btn:disabled {
    cursor: not-allowed;
    opacity: 0.45;
    transform: none !important;
    box-shadow: none !important;
}

.btn-again {
    border: 1px solid var(--hard);
    background: rgba(244, 67, 54, 0.05);
    color: var(--hard);
}

.btn-again:hover:not(:disabled) {
    background: rgba(244, 67, 54, 0.15);
    box-shadow: 0 5px 20px rgba(244, 67, 54, 0.3), 0 0 25px rgba(244, 67, 54, 0.2);
    transform: translateY(-2px);
}

.btn-hard {
    border: 1px solid var(--medium);
    background: rgba(255, 157, 0, 0.08);
    color: var(--medium);
}

.btn-hard:hover:not(:disabled) {
    background: rgba(255, 157, 0, 0.16);
    box-shadow: 0 5px 20px rgba(255, 157, 0, 0.22), 0 0 25px rgba(255, 157, 0, 0.12);
    transform: translateY(-2px);
}

.btn-good {
    border: 1px solid rgba(94, 234, 212, 0.55);
    background: rgba(94, 234, 212, 0.08);
    color: var(--accent);
}

.btn-good:hover:not(:disabled) {
    background: rgba(94, 234, 212, 0.16);
    box-shadow: 0 5px 20px rgba(94, 234, 212, 0.16), 0 0 25px rgba(94, 234, 212, 0.12);
    transform: translateY(-2px);
}

.btn-easy {
    background: var(--accent);
    border: none;
    color: #0A0E17;
    font-weight: 800;
    box-shadow: 0 0 15px var(--accent-glow);
}

.btn-easy:hover:not(:disabled) {
    background: var(--accent);
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-glow), 0 0 30px rgba(94, 234, 212, 0.4);
}

.srs-grade-btn:active:not(:disabled) {
    transform: translateY(0);
}

.footer-caption {
    width: 100%;
    max-width: 352px;
    margin: 14px auto 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-muted);
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.footer-btns.show + .footer-caption {
    opacity: 1;
    visibility: visible;
}

/* Keep the SRS guidance in the existing card-to-controls gap. It should not
   add another normal-flow row or enlarge the page's scrollable height. */
#srsHint.footer-caption {
    position: absolute;
    top: calc(var(--vocab-card-height) + 12px);
    left: 50%;
    width: min(100%, 504px);
    max-width: calc(100vw - 48px);
    margin: 0;
    transform: translateX(-50%);
    z-index: 51;
    pointer-events: none;
}

.footer-btns.compact-mode .grade-main {
    width: 100%;
    justify-content: space-between;
    gap: 12px;
}

.footer-btns.compact-mode .grade-copy {
    align-items: flex-start;
}

@media (max-width: 520px) {
    :root {
        --vocab-card-width: 400px;
        --vocab-card-height: 476px;
    }

    .app-header {
        padding: 0;
    }

    .header-progress-section {
        width: min(calc(100vw - 36px), 400px);
        max-width: none;
    }

    #srsButtons.footer-btns.compact-mode {
        max-width: 300px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    #srsButtons.footer-btns.compact-mode.single-choice {
        max-width: 300px;
        grid-template-columns: minmax(0, 1fr);
        justify-items: center;
    }

    #srsButtons.footer-btns.compact-mode .srs-grade-btn {
        align-items: flex-start;
        text-align: left;
        padding: 10px 12px 9px;
    }

    #srsButtons.footer-btns.compact-mode .grade-main {
        width: 100%;
        justify-content: space-between;
        gap: 8px;
    }

    #srsButtons.footer-btns.compact-mode .grade-copy {
        align-items: flex-start;
    }

    #srsButtons.footer-btns.compact-mode .grade-icon {
        display: inline-flex;
        width: 20px;
        opacity: 0.56;
    }

    #srsButtons.footer-btns.compact-mode .grade-icon svg {
        width: 15px;
        height: 15px;
    }

    #srsHint.footer-caption {
        max-width: 400px;
        margin: 0;
        font-size: 11px;
        line-height: 1.35;
    }
}

@media (max-width: 767px) {
    body:not(.dashboard-body) {
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow-y: auto;
        overflow-x: hidden;
        display: block;
        align-items: stretch;
        justify-content: flex-start;
    }

    body:not(.dashboard-body) #app {
        position: relative;
        inset: auto;
        min-height: 100vh;
        min-height: 100dvh;
        height: auto;
        overflow: visible;
        transform: none;
    }

    body:not(.dashboard-body) #app:not(.show) {
        display: none;
    }

    /* Vocabulary lives inside a fixed, clipped visual-viewport canvas. The
       legacy document-scrolling rule above would grow #app beyond that canvas,
       leaving the rating buttons clipped with no scrollable ancestor. Keep
       this screen bounded and scroll its contents, including bottom safe space. */
    #vocabPageRoot #app {
        position: absolute;
        inset: 0;
        min-height: 0;
        height: 100%;
        overflow-y: auto;
        overflow-x: hidden;
    }
}

/* ─── iPad 竖屏 (≥768px) ───────────────────────── */
@media (min-width: 768px) {
    :root {
        --task-card-top: 152px;
        --vocab-card-width: 560px;
        --vocab-card-height: 540px;
        --vocab-card-action-gap: 44px;
        --vocab-card-action-height: 80px;
    }

    .app-header {
        padding: 0;
    }

    .header-progress-section {
        width: min(calc(100vw - 64px), 560px);
        max-width: none;
    }

    /* SRS 按钮：4 列横排，更大点击区 */
    .footer-btns.srs-four-up {
        max-width: 504px;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 12px;
        margin-top: var(--vocab-card-action-gap);
    }

    #srsButtons.footer-btns.compact-mode {
        max-width: 360px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
    }

    #srsButtons.footer-btns.compact-mode.single-choice {
        max-width: 320px;
        grid-template-columns: minmax(0, 1fr);
        justify-items: center;
    }

    .srs-four-up .srs-grade-btn {
        min-height: var(--vocab-card-action-height);
        border-radius: 22px;
        align-items: center;
        justify-content: center;
        gap: 4px;
        padding: 12px 6px;
        text-align: center;
    }

    .srs-four-up .grade-title {
        font-size: 17px;
    }

    .srs-four-up .grade-hint {
        font-size: 12px;
        letter-spacing: 0.02em;
    }

    /* 4 列时隐藏图标，居中对齐 */
    .srs-four-up:not(.compact-mode) .grade-icon {
        display: none;
    }

    .srs-four-up:not(.compact-mode) .grade-copy {
        align-items: center;
    }

    /* compact-mode (2按钮) 保持左对齐 */
    #srsButtons.footer-btns.compact-mode .srs-grade-btn {
        align-items: flex-start;
        text-align: left;
        padding: 16px 18px;
    }

    #srsButtons.footer-btns.compact-mode .grade-main {
        width: 100%;
        justify-content: space-between;
        gap: 10px;
    }

    #srsButtons.footer-btns.compact-mode .grade-copy {
        align-items: flex-start;
    }

    #srsButtons.footer-btns.compact-mode .grade-icon {
        display: inline-flex;
        width: 22px;
        opacity: 0.56;
    }

    #srsButtons.footer-btns.compact-mode .grade-icon svg {
        width: 16px;
        height: 16px;
    }

    #srsHint.footer-caption {
        max-width: 504px;
        font-size: 13px;
        margin: 0;
    }

    /* ── Header text enlargement on iPad ── */
    .logo {
        font-size: 24px;
    }

    .progress-bar-track {
        height: 6px;
    }

    .retry-hint {
        font-size: 12px;
        padding: 5px 12px;
    }
}

.next-session-btn {
    flex: 1;
    margin-top: 0;
    height: 52px;
    background: transparent;
    border: 1px solid var(--accent);
    border-radius: 12px;
    color: var(--accent);
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.next-session-btn:hover {
    background: rgba(79, 209, 197, 0.1);
}

.exit-btn {
    flex: 1;
    height: 52px;
    background: transparent;
    border: 1px solid var(--text-muted);
    border-radius: 12px;
    color: var(--text-muted);
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

.exit-btn:hover {
    background: rgba(100, 116, 139, 0.1);
    border-color: var(--text);
    color: var(--text);
}

.success-actions {
    display: flex;
    gap: 12px;
    width: 100%;
    margin-top: 16px;
}

.next-session-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── AUDIO AUTOPLAY TOGGLE BUTTON ──────────── */
.audio-toggle-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
    cursor: pointer;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    line-height: 0;
}

.audio-toggle-btn:hover {
    opacity: 1;
}

/* ─── THEME TOGGLE BUTTON ────────────────────── */
.theme-toggle-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
    cursor: pointer;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.3s ease;
    line-height: 0;
}

.theme-toggle-btn:hover {
    opacity: 1;
    transform: rotate(20deg);
}

/* ─── LIGHT (SCHOLAR) THEME ──────────────────── */
[data-theme="light"] {
    --bg:          #F4F1EB;
    --surface:     #FFFFFF;
    --surface-2:   #EAE5DC;
    --border:      rgba(0, 0, 0, 0.09);
    --text:        #1C1712;
    --text-muted:  #6E675E;
    --accent:      #0F766E;
    --chip-ink:    #FFFFFF;
    --neon-green:  #0F766E;
    --accent-glow: rgba(15, 118, 110, 0.18);
    --easy:        #0F766E;
    --medium:      #C2540A;
    --hard:        #DC2626;
    --logic-token: #7C3AED;
    --blue-accent: #1D4ED8;
    --review-bg:   #FEF3C7;
    --review-text: #C2540A;
    --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.07), 0 1px 4px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] #app {
    background: var(--bg);
}

/* Fix portal cards with hardcoded dark colors */
[data-theme="light"] .level-pill {
    background: var(--surface-2);
}

[data-theme="light"] .stat-card {
    background: var(--surface);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* Fix icon SVG fills that used the dark bg color */
[data-theme="light"] .header-icon svg rect[fill="#0A0E17"],
[data-theme="light"] .header-icon svg path[fill="#0A0E17"] {
    fill: #FFFFFF;
}

/* Fix task submit button text (hardcoded dark bg color in task.css) */
[data-theme="light"] .task-submit-btn {
    color: #FFFFFF;
}

/* Fix MCQ prompt (was rgba(255,255,255,0.54)) */
[data-theme="light"] #mcqPrompt {
    color: var(--text-muted) !important;
}

/* MCQ options */
[data-theme="light"] .mcq-option {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.1);
    color: var(--text);
}

/* Lens mode popup */
[data-theme="light"] .lens-content {
    background: var(--surface);
    border-color: var(--accent);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .lens-close-btn {
    background: var(--surface-2);
    border-color: color-mix(in srgb, var(--accent) 40%, var(--surface-2));
}

/* Badge overlay */
[data-theme="light"] .badge-base {
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 252, 229, 0.96) 0%, rgba(255, 233, 156, 0.92) 18%, rgba(255, 197, 84, 0.88) 34%, rgba(194, 115, 17, 0.9) 72%, rgba(104, 52, 4, 0.94) 100%);
    border-color: rgba(255, 246, 210, 0.96);
    box-shadow:
        0 0 0 1px rgba(255, 248, 220, 0.5) inset,
        0 0 24px rgba(255, 191, 63, 0.34),
        0 0 52px rgba(255, 179, 43, 0.28),
        0 18px 36px rgba(94, 58, 8, 0.22);
}

[data-theme="light"] .correct-badge-overlay {
    background:
        radial-gradient(circle at 50% 52%, rgba(255, 204, 82, 0.22) 0%, rgba(255, 189, 49, 0.1) 24%, rgba(255, 255, 255, 0) 58%),
        rgba(84, 55, 7, 0.08);
}

[data-theme="light"] .badge-icon {
    color: #fffaf0;
    filter: drop-shadow(0 0 10px rgba(255, 195, 77, 0.42));
}

[data-theme="light"] .badge-text {
    color: #fffaf0;
    text-shadow:
        0 0 8px rgba(255, 226, 146, 0.38),
        0 0 18px rgba(255, 179, 43, 0.22);
}

/* Easy button text (dark bg text stays readable) */
[data-theme="light"] .btn-easy {
    color: #FFFFFF;
}

/* Neural loading labels */
[data-theme="light"] .neural-word-label {
    background: rgba(244, 241, 235, 0.94);
    border-color: rgba(15, 118, 110, 0.3);
    color: rgba(15, 118, 110, 0.9);
    text-shadow: 0 0 8px rgba(15, 118, 110, 0.3);
}

/* History panel */
[data-theme="light"] .reader-history-panel {
    background: var(--surface);
}

[data-theme="light"] .history-item {
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .history-item:hover {
    background: rgba(15, 118, 110, 0.05);
}

/* Interstitial overlay */
[data-theme="light"] .interstitial-overlay {
    background: radial-gradient(circle at 50% 50%, rgba(203, 233, 229, 0.95) 0%, rgba(244, 241, 235, 0.98) 100%);
}

/* 浅色主题：青绿在米色背景上几乎不可见，改用灰色沟槽 —— 深线在上、
   白色高光在下（光自上方）。所有顶栏共用，无需逐个覆盖。 */
[data-theme="light"] {
    --page-topbar-line: rgba(0, 0, 0, 0.1);
    --page-topbar-line-lip: rgba(255, 255, 255, 0.8);
}

[data-theme="light"] .progress-seg {
    background: color-mix(in srgb, var(--text-muted) 26%, transparent);
}

[data-theme="light"] .retry-hint {
    color: #9a4f0a;
    border-color: rgba(205, 128, 42, 0.22);
    background: rgba(255, 174, 73, 0.12);
}

/* Transition for smooth switching */
body,
#app,
.card-face,
.stat-card,
.xp-card,
.lib-word-card,
.story-card,
.reader-history-panel {
    transition: background-color 0.25s ease, background 0.25s ease,
                border-color 0.25s ease, color 0.25s ease,
                box-shadow 0.25s ease;
}
/* Smart Reader comprehension task returned after a first all-wrong attempt. */
.task-redo-badge {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    padding: 2px 7px;
    border-radius: 5px;
    background: rgba(239, 68, 68, 0.14);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
}
