/* 
  English Practice App - Unified Stylesheet
  Consolidated from: style.css, style_footer.css, tooltip_dark.css, web/tooltip_dark.css
  Version: 1.0.0 - 2025-12-16
*/

/* ==================== */
/* 1. CSS VARIABLES     */
/* ==================== */

:root {
    /* --- Color Palette --- */
    --primary: #6366F1;
    --primary-focus: #4F46E5;
    --primary-light: #e0e7ff;
    --primary-content: #FFFFFF;

    /* Backgrounds */
    --bg-app-wrapper: #F0F2F5;
    --bg-surface: #FFFFFF;
    --bg-body: #F9FAFB;
    --bg-subtle: #F3F4F6;

    /* Semantic Colors */
    --success: #10B981;
    --error: #EF4444;
    --warning: #F59E0B;

    /* Text Colors */
    --text-main: #1F2937;
    --text-sub: #4B5563;
    --text-hint: #9CA3AF;
    --text-inverse: #FFFFFF;

    /* Borders */
    --border-color: #E5E7EB;
    --border-focus: #6366F1;

    /* --- Spacing System (8pt Grid) --- */
    --space-0_5: 4px;
    --space-1: 8px;
    --space-1_5: 12px;
    --space-2: 16px;
    --space-3: 24px;
    --space-4: 32px;
    --space-6: 48px;

    /* --- Typography --- */
    --font-sans: 'Inter', 'Roboto', 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;

    /* --- Shapes & Effects --- */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-floating: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    /* --- Layout Dimensions --- */
    --header-height: 56px;
    --bottom-nav-height: 64px;
    --app-width-desktop: 480px;
    --app-max-height-desktop: 880px;

    /* --- Responsive Breakpoints --- */
    --breakpoint-tablet: 768px;
    --breakpoint-desktop: 1024px;
    --breakpoint-wide: 1440px;
}

/* ==================== */
/* 2. RESET & BASE      */
/* ==================== */

*,
*::before,
*::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* 移动端优化：防止文本选中 */
    -webkit-touch-callout: none;
}

/* 移动端基础优化 */
html {
    /* 防止 iOS 输入框自动缩放 */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    /* 优化移动端滚动 */
    -webkit-overflow-scrolling: touch;
    /* 防止拉伸效果 */
    overscroll-behavior-y: contain;
}

/* ==================== */
/* CUSTOM DECK SCREEN   */
/* ==================== */

/* 基本 Flex 設定由 .screen.active 處理，這裡只需處理特殊覆蓋 */
#custom-training-screen.screen.active {
    display: flex !important;
    flex-direction: column;
    padding: 12px 16px 12px 16px !important;
    gap: 16px;
}

/* 桌面端优化 */
@media (min-width: 768px) {
    #custom-training-screen.screen.active {
        padding: 16px 20px !important;
        gap: 20px;
    }
}

#custom-training-screen .card {
    box-shadow: var(--shadow-md);
}

/* Deck card hover effect */
.deck-card {
    transition: transform 0.2s, box-shadow 0.2s;
}

.deck-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--font-sans);
    background-color: var(--bg-app-wrapper);
    color: var(--text-main);
    height: 100vh;
    /* fallback */
    height: 100dvh;
    /* 动态 viewport，避免手机地址栏影响 */
    width: 100vw;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

body::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(#6366F1 0.5px, transparent 0.5px);
    background-size: 24px 24px;
    opacity: 0.03;
    pointer-events: none;
    z-index: -1;
}

/* ==================== */
/* 3. LAYOUT - APP SHELL */
/* ==================== */

#app-shell {
    position: relative;
    width: 100%;
    height: 100vh;
    /* fallback */
    height: 100dvh;
    /* 动态 viewport */
    background-color: var(--bg-surface);
    /* Grid 三段式布局：Header / Main / Footer */
    display: grid;
    grid-template-rows: auto 1fr auto;
    /* 固定 / 自适应 / 固定 */
    overflow: hidden;
    box-shadow: none;
}

#main-content {
    /* Grid 自动处理剩余空间，不需要 flex: 1 和 min-height: 0 */
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    /* 核心：唯一的垂直滚动容器 */
    -webkit-overflow-scrolling: touch;
    /* iOS 平滑滚动 */
    background-color: var(--bg-body);
    position: relative;
    scroll-behavior: smooth;
    gap: 16px;
    /* 底部 safe-area 保护 */
    padding-bottom: env(safe-area-inset-bottom, 0);
}

#main-content::-webkit-scrollbar {
    display: none;
}

/* ==================== */
/* RESPONSIVE DESIGN    */
/* ==================== */

/* Tablet (768px+): 适度放大 */
@media (min-width: 768px) {
    #app-shell {
        width: 520px;
        height: min(900px, calc(100dvh - 40px));
        /* 使用 dvh */
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-floating);
        border: 1px solid rgba(0, 0, 0, 0.08);
    }

    .card {
        padding: var(--space-3);
    }

    .btn {
        height: 52px;
        font-size: 1.05rem;
    }

    /* 桌面端优化底部导航 */
    .bottom-nav {
        border-top: 1px solid var(--border-color);
    }

    .nav-label {
        font-size: 0.9rem;
    }
}

/* Desktop (1024px+): 居中卡片布局 */
@media (min-width: 1024px) {
    #app-shell {
        width: 560px;
        height: min(920px, calc(100dvh - 60px));
        /* 使用 dvh */
    }

    /* 桌面端隐藏底部导航，使用侧边栏或顶部导航 */
    .bottom-nav {
        /* 保留底部导航，但优化样式 */
        background: linear-gradient(to top, var(--bg-surface), rgba(255, 255, 255, 0.95));
        backdrop-filter: blur(10px);
    }

    /* 优化卡片间距 */
    #main-content {
        gap: 20px;
        padding: 0 4px;
    }

    /* 桌面端优化输入框 */
    .input-field {
        font-size: 1rem;
        padding: 14px 16px;
    }

    /* 桌面端优化 chip 按钮 */
    .chip {
        padding: 10px 18px;
        font-size: 0.95rem;
    }
}

/* Wide Screen (1440px+): 可选的宽屏优化 */
@media (min-width: 1440px) {
    #app-shell {
        width: 600px;
        height: min(960px, calc(100dvh - 80px));
        /* 使用 dvh */
    }
}

/* ==================== */
/* 4. TOP BAR           */
/* ==================== */

.top-app-bar {
    height: var(--header-height);
    padding: 0 var(--space-2);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    z-index: 20;
    /* Grid 自动处理，不需要 flex-shrink: 0 */
    transition: box-shadow 0.2s;
}

.top-app-bar.scrolled {
    box-shadow: var(--shadow-sm);
}

.app-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-main);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

.icon-btn {
    min-width: 44px;
    /* 移动端最小触控目标 */
    min-height: 44px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
    /* 移动端触控反馈 */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.icon-btn:hover {
    background-color: var(--bg-subtle);
}

.icon-btn:active {
    background-color: #E0E7FF;
    color: var(--primary);
}

.icon-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.icon-btn-primary {
    fill: white;
    background: linear-gradient(135deg, #6366F1 0%, #4F46E5 100%);
    border-radius: 50%;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.icon-btn-primary:hover {
    background: linear-gradient(135deg, #4F46E5 0%, #6366F1 100%);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
    transform: translateY(-2px) scale(1.05);
}

.icon-btn-primary:active {
    background: linear-gradient(135deg, #4338CA 0%, #4F46E5 100%);
    transform: translateY(0) scale(1);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

/* ==================== */
/* 5. BOTTOM NAVIGATION */
/* ==================== */

.bottom-nav {
    height: var(--bottom-nav-height);
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding-bottom: env(safe-area-inset-bottom);
    /* Grid 自动处理，不需要 flex-shrink: 0 */
    z-index: 20;
}

.nav-item {
    flex: 1;
    min-height: 64px;
    /* 确保足够的触控高度 */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-sub);
    background: transparent;
    border: none;
    cursor: pointer;
    position: relative;
    transition: color 0.2s;
    /* 移动端优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.1);
}

.nav-item svg {
    width: 24px;
    height: 24px;
    margin-bottom: 4px;
    fill: currentColor;
    transition: transform 0.2s;
}

.nav-label {
    font-size: 10px;
    font-weight: 500;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item.active svg {
    transform: translateY(-2px);
}

.nav-item.active::before {
    content: "";
    position: absolute;
    top: 8px;
    width: 48px;
    height: 28px;
    background-color: var(--primary-light);
    border-radius: 14px;
    z-index: -1;
    opacity: 0.5;
}

/* Practice Footer (from style_footer.css) */
.practice-footer {
    margin-top: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 8px;
}

.nav-row {
    width: 100% !important;
    margin: 0 !important;
    justify-content: space-between !important;
    background: white;
    padding: 12px 24px;
}

.large-nav {
    width: 56px !important;
    height: 56px !important;
    font-size: 2rem !important;
}

.full-width-play {
    width: 100%;
    padding: 16px;
    font-size: 1.2rem;
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow-md);
    font-weight: 700;
    background: #6366F1;
    color: white;
    border: none;
}

.full-width-play:active {
    transform: scale(0.98);
}

/* ==================== */
/* 6. SCREENS           */
/* ==================== */

.screen {
    display: none;
    /* padding: var(--space-2);  <-- Move padding to active state or specific screens to avoid double padding logic */
    min-height: 0;
    /* Changed from 100% to 0 to avoid overflow issues in flex container */
    animation: fade-in 0.2s ease-out;
}

.screen.active {
    display: flex;
    /* Changed from block */
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 16px;
    /* Apply padding here to ensure consistency */
}

#practice-screen.active {
    display: flex;
    flex-direction: column;
    flex: 1;
    /* 改用 flex，不用 height:100% */
    min-height: 0;
    padding: 12px !important;
    /* 小屏手机优化 */
    gap: 0;
    /* 移除 gap，使用 margin 控制 */
}

@keyframes fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== */
/* 7. COMPONENTS        */
/* ==================== */

/* Cards */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: var(--space-2);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: var(--text-base);
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    width: 100%;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--primary-content);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3);
}

.btn-primary:active {
    background-color: var(--primary-focus);
    transform: translateY(1px);
    box-shadow: none;
}

/* 桌面端悬停效果（非触控设备） */
@media (hover: hover) and (pointer: fine) {
    .btn-primary:hover {
        background-color: var(--primary-focus);
        box-shadow: 0 4px 8px rgba(99, 102, 241, 0.4);
        transform: translateY(-1px);
    }

    .btn-outline:hover {
        background-color: var(--bg-subtle);
        border-color: var(--primary);
    }

    .card:hover {
        box-shadow: var(--shadow-md);
    }

    .bento-item:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }

    .chip:hover {
        background-color: var(--bg-subtle);
    }

    .icon-btn:hover {
        background-color: var(--bg-subtle);
    }
}

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-outline:active {
    background-color: var(--bg-subtle);
}

.btn-text {
    background-color: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    border-radius: 24px;
    padding: 0 20px;
    height: 44px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.btn-text:hover {
    background-color: rgba(99, 102, 241, 0.08);
    border-color: var(--primary-focus);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
    transform: translateY(-1px);
}

.btn-text:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}

/* Input Fields */
.input-group {
    margin-bottom: var(--space-2);
}

.input-field {
    width: 100%;
    padding: var(--space-1_5);
    font-size: 16px;
    /* 最小 16px 防止 iOS 自动缩放 */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-body);
    transition: border-color 0.2s;
    font-family: inherit;
    /* 移动端优化 */
    -webkit-appearance: none;
    appearance: none;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--bg-surface);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input-field.success {
    border-color: var(--success) !important;
    background-color: #ECFDF5 !important;
}

.input-field.error {
    border-color: var(--error) !important;
    background-color: #FEF2F2 !important;
}

/* Chips */
.chip-group {
    display: flex;
    gap: var(--space-1);
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.chip-group::-webkit-scrollbar {
    display: none;
}

#tier1-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
}

#tier1-chips .chip {
    flex: 1;
    text-align: center;
    justify-content: center;
    padding-left: 4px;
    padding-right: 4px;
}

.chip {
    padding: 6px 16px;
    border-radius: var(--radius-full);
    background-color: var(--bg-body);
    border: 1px solid var(--border-color);
    font-size: var(--text-sm);
    color: var(--text-sub);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.chip.active {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ==================== */
/* 8. HOME SCREEN       */
/* ==================== */

.home-header-card {
    text-align: center;
    padding: var(--space-3);
    margin-bottom: var(--space-2);
}

.stats-summary {
    display: flex;
    justify-content: center;
    gap: var(--space-4);
    margin-top: var(--space-2);
}

.stat-item .value {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.stat-item .label {
    font-size: var(--text-xs);
    color: var(--text-hint);
}

.bento-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-1_5);
}

/* 平板和桌面端优化网格间距 */
@media (min-width: 768px) {
    .bento-grid {
        gap: var(--space-2);
    }

    .bento-item {
        height: 110px;
        padding: var(--space-3);
    }

    .bento-item.hero {
        height: 90px;
    }
}

.bento-item {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: var(--space-2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    height: 100px;
}

.bento-item:active {
    transform: scale(0.98);
}

.bento-item.hero {
    grid-column: span 2;
    flex-direction: row;
    height: 80px;
    background: linear-gradient(135deg, var(--bg-surface) 0%, #EEF2FF 100%);
}

.bento-item.hero .icon {
    width: 32px;
    height: 32px;
    margin: 0 var(--space-2) 0 0;
    fill: var(--primary);
}

.bento-item .icon {
    width: 28px;
    height: 28px;
    margin-bottom: var(--space-1);
    fill: var(--text-sub);
}

.bento-item .label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-main);
}

/* ==================== */
/* 9. FLASHCARD         */
/* ==================== */

.flashcard-container {
    perspective: 1000px;
    width: 90%;
    height: 100%;
    /* Fill parent height */
    margin: 0 auto;
    max-width: 600px;
    position: relative;
    z-index: 50;
}

/* 小屏幕优化 (< 400px) - 适配 S24 等小屏手机 */
@media (max-width: 400px) {
    :root {
        --text-sm: 0.8rem;
        --text-base: 0.9rem;
        --space-2: 10px;
        --space-3: 16px;
    }

    /* 翻卡容器优化 - 完全 flex 驱动 */
    .flashcard-container {
        max-width: 98%;
        width: 98%;
        flex: 1;
        /* 占满剩余空间 */
        min-height: 0;
        /* 让 flex 自动计算 */
        display: flex;
        flex-direction: column;
    }

    .flashcard {
        height: 100%;
        /* 占满容器 */
        min-height: 0;
        /* 移除固定限制，完全自适应 */
    }

    /* practice-screen 优化 */
    #practice-screen.active {
        padding: 4px 6px !important;
        /* 更小 padding，给卡片更多空间 */
        gap: 4px;
        /* 减小元素间隙 */
    }

    /* 减小进度条区域的 margin */
    #practice-screen .progress-container {
        margin-bottom: 4px !important;
        /* 进一步减小 */
    }

    /* 优化翻卡外层容器 - 占满可用空间 */
    .flashcard-wrapper {
        flex: 1;
        /* 占满剩余空间 */
        min-height: 0;
        /* 移除固定限制，让 flex 自由计算 */
        padding: 0 0 16px 0;
        /* 底部留 16px 边距 */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 卡片内容字体自适应 */
    .card-front-text {
        /* 使用 clamp() 函数实现自适应字体 */
        /* clamp(最小值, 首选值, 最大值) */
        font-size: clamp(1rem, 3.5vw, 1.5rem) !important;
        /* 进一步减小 */
    }

    .card-back-text {
        font-size: clamp(0.9rem, 2.5vw, 1rem) !important;
    }

    /* 例句字体缩小 */
    #card-sentence-en,
    #card-sentence-zh {
        font-size: 0.85rem;
    }

    /* 控制按钮区域压缩 - 减少占用空间 */
    .practice-controls {
        gap: 24px !important;
        /* 减小按钮间距 */
        padding: 0 !important;
        /* 移除 padding */
        margin: 0 auto 12px auto !important;
        /* 上边距0，依靠 wrapper 的 padding */
        max-width: 280px !important;
    }

    /* 按钮尺寸调整 - 增大触摸区域 */
    .icon-btn,
    .icon-btn-primary {
        min-width: 48px !important;
        min-height: 48px !important;
        width: 48px !important;
        height: 48px !important;
    }

    .icon-btn svg {
        width: 28px !important;
        height: 28px !important;
    }

    /* 卡片内边距缩小 */
    .card-face {
        padding: var(--space-2) !important;
    }

    /* Quiz 和 Verb3 优化 */
    #quiz-screen .card,
    #verb3-screen .card {
        padding: 14px;
    }

    .btn {
        height: 44px;
        font-size: 0.9rem;
        padding: 0 16px;
    }
}

/* 小屏幕优化 */
@media (max-height: 700px) {
    .flashcard-container {
        max-width: 95%;
        /* 增大宽度 */
        /* 移除 aspect-ratio，让它自适应高度 */
    }
}

/* 桌面端优化翻卡尺寸 */
@media (min-width: 768px) {
    .flashcard-container {
        max-width: 480px;
        /* 移除 max-height，让它自适应 */
    }

    .card-face {
        font-size: 1.1rem;
    }
}

@media (min-width: 1024px) {
    .flashcard-container {
        max-width: 520px;
    }
}

.flashcard-stage {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.flashcard {
    position: relative;
    width: 100%;
    height: 100%;
    /* 占满容器 */
    min-height: 0;
    /* 移除固定 vh，让 flex 自动计算 */
    text-align: center;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-style: preserve-3d;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.flashcard.flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-4);
}

.card-face.front {
    justify-content: center;
    /* Center content on front */
}

.card-face.back {
    transform: rotateY(180deg);
    /* Critical for card flip */
    justify-content: flex-start;
    padding: 20px 24px;
    gap: 16px;
    /* Increase gap for better spacing */
}

/* CRITICAL FIX: Prevent inactive face from blocking clicks
   Both faces are position:absolute at same coordinates.
   Even when rotated 180deg, the FRONT face (defined first in DOM)
   still intercepts pointer events, blocking interactive words on BACK.
   Solution: Disable pointer-events on the face that's turned away. */

/* When NOT flipped: disable back face pointer events */
.flashcard:not(.flipped) .card-face.back {
    pointer-events: none;
    visibility: hidden;
    /* Extra safety: completely remove from render tree */
}

/* When flipped: disable front face pointer events */
.flashcard.flipped .card-face.front {
    pointer-events: none;
    visibility: hidden;
}

/* 翻卡外层区域优化 */
.flashcard-wrapper {
    flex: 1;
    /* CRITICAL: provide height */
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
}

/* 卡片文字自适应字体 */
.card-front-text {
    /* 使用 clamp() 实现响应式字体 */
    /* 语法: clamp(最小值, 理想值, 最大值) */
    font-size: clamp(1.5rem, 5vw, 2.5rem) !important;
    /* !important 覆盖内联样式 */
    font-weight: 600;
    color: var(--text-main);
    line-height: 1.4;
    margin: auto;
    /* 居中 */
}

.card-back-text {
    font-size: clamp(1rem, 3vw, 1.3rem) !important;
    font-weight: 500;
    color: var(--text-main);
    line-height: 1.5;
}

/* 例句容器触摸优化 */
.example-sentence-container,
.example-sentence-area,
[class*="example"] {
    touch-action: manipulation;
}

@media (prefers-reduced-motion: reduce) {
    .flashcard {
        transition: transform 0s;
    }

    .screen {
        animation: none;
    }
}

/* ==================== */
/* 10. QUIZ             */
/* ==================== */

#quiz-screen.active {
    text-align: center;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-height: 0;
    /* Allow flex shrinking */
    flex: 1;
    /* Take available space */
}

#quiz-full-info {
    margin-top: 32px;
    text-align: left;
    background: white;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#quiz-next-btn {
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.3);
}

#quiz-next-btn:active {
    transform: translateY(1px);
}

/* ==================== */
/* 11. TOOLTIP (UNIFIED) */
/* ==================== */

#translation-tooltip {
    /* Position */
    position: fixed;
    left: var(--tooltip-x, 0);
    top: var(--tooltip-y, 0);
    z-index: 9999;

    /* Size */
    max-width: 280px;
    padding: 10px 16px;

    /* Appearance */
    background: rgba(31, 41, 55, 0.95);
    color: white;
    border: none;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);

    /* Typography */
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.5;

    /* Default Hidden State */
    display: none;
    opacity: 0;
    visibility: hidden;

    /* Interaction */
    pointer-events: none;

    /* Animation */
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    transform: translateY(5px);
}

#translation-tooltip.visible {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

#translation-tooltip strong {
    color: #A5B4FC;
    font-weight: 600;
}

/* Interactive Word Styling */
.interactive-word {
    /* 移动端触摸优化 */
    display: inline-block;
    touch-action: manipulation;

    cursor: pointer;
    border-bottom: 1px dashed var(--text-hint);
    color: var(--primary);
    transition: all 0.2s;
    padding: 0 2px;
}

.interactive-word:hover {
    background: var(--primary-light);
    border-bottom-color: var(--primary);
    border-radius: 4px;
}

/* Legacy .token class (for backward compatibility) */
.token {
    cursor: pointer;
    border-bottom: 1px dashed var(--text-hint);
    color: var(--primary);
    transition: all 0.2s;
    padding: 0 2px;
}

.token:hover {
    background: var(--primary-light);
    border-bottom-color: var(--primary);
    border-radius: 4px;
}

/* ==================== */
/* 12. UTILITIES        */
/* ==================== */

.hidden {
    display: none !important;
}

.text-error {
    color: var(--error);
}

.text-success {
    color: var(--success);
}

/* ==================== */
/* 13. DECK CARDS       */
/* ==================== */

.deck-create-section {
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-color);
}

.deck-create-section h3 {
    margin-top: 0;
    margin-bottom: var(--space-2);
    font-size: var(--text-lg);
    color: var(--text-main);
}

.deck-list-section h3 {
    margin-top: 0;
    margin-bottom: var(--space-2);
    font-size: var(--text-lg);
    color: var(--text-main);
}

.deck-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
    transition: box-shadow 0.2s, transform 0.1s;
}

.deck-card:hover {
    box-shadow: var(--shadow-sm);
}

.deck-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-1);
}

.deck-header h4 {
    margin: 0;
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text-main);
}

.deck-meta {
    font-size: var(--text-sm);
    color: var(--text-sub);
    margin-bottom: var(--space-2);
}

.deck-modes {
    display: flex;
    gap: var(--space-1);
}

.deck-modes .btn {
    flex: 1;
    height: 40px;
    font-size: var(--text-sm);
    padding: 0 var(--space-1_5);
}

.btn-sm {
    height: 36px;
    padding: 0 var(--space-1_5);
    font-size: var(--text-sm);
}

.empty-state {
    text-align: center;
    padding: var(--space-4);
    color: var(--text-hint);
    font-size: var(--text-sm);
    line-height: 1.6;
}

/* ==================== */
/* END                  */
/* ==================== */

/* ==================== */
/* 13. FLOATING ELEMENTS */
/* ==================== */

.floating-back-btn {
    position: absolute;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 48px);
    max-width: 480px;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 14px 20px;
    border-radius: 12px;
    background-color: #2b2b2b;
    color: #e3e3e3;
    border: 1px solid #444;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.floating-back-btn:active {
    transform: translateX(-50%) scale(0.98);
    background-color: #363636;
}

.floating-back-btn svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

.floating-back-btn.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* ==================== */
/* 14. CUSTOM SETS      */
/* ==================== */

.custom-set-card {
    padding: 16px;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid var(--border-color);
}

.custom-set-card:active {
    transform: scale(0.99);
}

.custom-set-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.custom-set-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.custom-set-info {
    font-size: 0.8rem;
    color: var(--text-sub);
}

.custom-set-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.custom-set-actions .btn-sm {
    padding: 6px 4px;
    font-size: 0.85rem;
}

/* ==================== */
/* RESPONSIVE UTILITIES */
/* ==================== */

/* 移动端显示/隐藏 */
.mobile-only {
    display: block;
}

.desktop-only {
    display: none;
}

@media (min-width: 768px) {
    .mobile-only {
        display: none;
    }

    .desktop-only {
        display: block;
    }
}

/* ==================== */
/* MOBILE TOUCH OPTIMIZATION */
/* ==================== */

/* 移动端触控反馈优化 */
@media (hover: none) and (pointer: coarse) {

    /* 移动设备上的触控反馈 */
    .btn:active,
    .chip:active,
    .bento-item:active,
    .nav-item:active {
        opacity: 0.7;
        transform: scale(0.98);
    }

    /* 移动端卡片点击反馈 */
    .card:active {
        transform: scale(0.99);
    }

    /* 增强触控区域 */
    .icon-btn {
        min-width: 48px;
        min-height: 48px;
    }

    /* 优化翻卡触控 */
    .flashcard {
        cursor: pointer;
    }
}

/* 性能优化：促进 GPU 加速 */
/* NOTE: .flashcard 不能使用 backface-visibility: hidden，
   否则翻转后所有子元素都无法被点击（hit-testing 失败）*/
.card,
.btn,
.chip {
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* 移动端优化 */
    transform: translateZ(0);
}

/* 打印样式 */
@media print {

    .bottom-nav,
    .floating-back-btn,
    .top-app-bar button {
        display: none !important;
    }

    #app-shell {
        width: 100%;
        height: auto;
        box-shadow: none;
    }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 500px) {
    .flashcard-container {
        max-height: 70vh;
    }

    .flashcard {
        min-height: 60vh;
    }

    .top-app-bar {
        height: 48px;
    }

    .bottom-nav {
        height: 56px;
    }
}

/* 小屏手机的 Quiz/Verb3 模式优化 */
@media (max-width: 400px) {

    #quiz-screen .card,
    #verb3-screen .card {
        padding: 16px;
    }

    #quiz-question,
    #verb3-question {
        font-size: 1.2rem;
    }

    .input-field {
        padding: 10px 12px;
    }

    .btn {
        height: 44px;
        font-size: 0.9rem;
    }
}

/* 桌面端调整浮动按钮位置（相对于 app-shell）*/
@media (min-width: 768px) {
    .floating-back-btn {
        left: calc(50% - 280px);
        bottom: 90px;
    }
}

@media (min-width: 1024px) {
    .floating-back-btn {
        left: calc(50% - 300px);
    }
}