/* ========================================
   響應式設計 (RWD) - Responsive Web Design
   斷點: 手機 (<768px) | 平板 (768-1200px) | 桌面 (>1200px)
   ======================================== */

/* ==================== 漢堡選單按鈕 ==================== */
.mobile-menu-btn {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    transition: all 0.3s ease;
}

.mobile-menu-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 25px rgba(45, 91, 255, 0.4);
}

.mobile-menu-btn:active {
    transform: scale(0.95);
}

/* ==================== 移動端側邊欄覆蓋層 ==================== */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    backdrop-filter: blur(4px);
}

.mobile-overlay.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==================== 移動端側邊欄 ==================== */
.sidebar.mobile-active,
.vocabulary-panel.mobile-active {
    display: block !important;
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 999;
    animation: slideInRight 0.3s ease;
}

.sidebar.mobile-active {
    left: 0;
    width: 280px;
    animation: slideInLeft 0.3s ease;
}

.vocabulary-panel.mobile-active {
    right: 0;
    width: 320px;
}

@keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

/* ==================== 底部導航欄 (手機版) ==================== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    padding: 12px 0;
    z-index: 997;
}

.mobile-bottom-nav-content {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
}

.mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.mobile-nav-btn .nav-icon {
    font-size: 24px;
}

.mobile-nav-btn:active {
    transform: scale(0.95);
}

.mobile-nav-btn.active {
    color: var(--primary);
}

/* ==================== 平板版 (768px - 1200px) ==================== */
@media (max-width: 1200px) and (min-width: 768px) {
    .app-container {
        grid-template-columns: 280px 1fr;
        padding: 16px;
        gap: 16px;
    }

    /* 隱藏生詞本，改用浮動按鈕 */
    .vocabulary-panel {
        display: none;
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 320px;
        z-index: 999;
        box-shadow: var(--shadow-xl);
    }

    .vocabulary-panel.mobile-active {
        display: block;
        animation: slideInRight 0.3s ease;
    }

    /* 顯示浮動按鈕 */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 優化標題 */
    .header {
        padding: 16px 20px;
    }

    .logo-text {
        font-size: 18px;
    }

    /* 優化按鈕 */
    .header-actions .btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    /* 用戶資訊簡化 */
    .user-email {
        display: none;
    }
}

/* ==================== 手機版 (< 768px) ==================== */
@media (max-width: 767px) {
    body {
        padding-bottom: 80px; /* 為底部導航留空間 */
    }

    .app-container {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
        height: auto;
        min-height: calc(100vh - 80px);
    }

    /* ===== Header 優化 ===== */
    .header {
        padding: 12px 16px;
        border-radius: 12px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .logo {
        gap: 8px;
    }

    .logo-icon {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .logo-text {
        font-size: 16px;
    }

    .header-actions {
        width: 100%;
        order: 3;
    }

    .header-actions #notLoggedIn,
    .header-actions #loggedIn {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
    }

    .header-actions .btn {
        flex: 1;
        min-width: 120px;
        padding: 8px 12px;
        font-size: 13px;
    }

    .user-info {
        width: 100%;
        padding: 8px 12px;
    }

    .user-email {
        font-size: 12px;
    }

    .logout-btn {
        padding: 5px 10px;
        font-size: 11px;
    }

    /* ===== 側邊欄隱藏，改用底部導航 ===== */
    .sidebar {
        display: none;
    }

    .sidebar.mobile-active {
        display: block;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 999;
        animation: slideInLeft 0.3s ease;
    }

    /* ===== 對話容器優化 ===== */
    .chat-container {
        border-radius: 16px;
        height: calc(100vh - 200px);
        min-height: 500px;
    }

    .chat-header {
        padding: 14px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }

    .chat-title {
        font-size: 18px;
    }

    .chat-controls {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }

    .control-btn {
        width: 100%;
        padding: 10px;
        font-size: 14px;
    }

    /* ===== 訊息區域優化 ===== */
    .messages-area {
        padding: 12px;
    }

    .message {
        gap: 10px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .message-bubble {
        padding: 10px 14px;
        font-size: 14px;
        max-width: calc(100vw - 100px);
    }

    /* 隱藏/顯示按鈕優化 */
    .toggle-visibility {
        font-size: 11px;
        padding: 5px 10px;
    }

    /* ===== 輸入區域優化 ===== */
    .input-area {
        padding: 12px;
        gap: 8px;
    }

    .voice-btn {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }

    .text-input {
        font-size: 14px;
        padding: 10px 14px;
    }

    .send-btn {
        padding: 10px 16px;
        font-size: 13px;
    }

    /* ===== 生詞本隱藏 ===== */
    .vocabulary-panel {
        display: none;
    }

    .vocabulary-panel.mobile-active {
        display: block;
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 90%;
        max-width: 320px;
        z-index: 999;
        animation: slideInRight 0.3s ease;
    }

    /* ===== 生詞項目優化 ===== */
    .vocab-item {
        padding: 12px 14px;
        border-radius: 10px;
        margin-bottom: 10px;
    }

    .vocab-word {
        font-size: 15px;
    }

    .vocab-definition {
        font-size: 12px;
    }

    .vocab-translation {
        font-size: 13px;
        padding: 6px 10px;
    }

    .vocab-action-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    /* ===== 顯示移動端元素 ===== */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-bottom-nav {
        display: block;
    }

    .mobile-overlay.active {
        display: block;
    }

    /* ===== 情境按鈕優化 ===== */
    .scenario-btn {
        padding: 12px 16px;
        font-size: 14px;
    }

    .scenario-icon {
        font-size: 20px;
    }

    /* ===== 空狀態優化 ===== */
    .empty-state {
        padding: 40px 20px;
    }

    .empty-state-icon {
        font-size: 48px;
    }

    .empty-state-text {
        font-size: 13px;
    }

    /* ===== 認證 Modal 優化 ===== */
    .auth-modal {
        width: 90%;
        max-width: 400px;
        padding: 28px;
        margin: 20px;
    }

    .auth-modal h2 {
        font-size: 22px;
    }

    .auth-input {
        font-size: 14px;
        padding: 12px;
    }

    .auth-btn {
        padding: 12px;
        font-size: 14px;
    }
}

/* ==================== 極小螢幕 (< 375px) ==================== */
@media (max-width: 374px) {
    .app-container {
        padding: 8px;
        gap: 8px;
    }

    .header {
        padding: 10px 12px;
    }

    .logo-text {
        font-size: 14px;
    }

    .chat-container {
        height: calc(100vh - 180px);
        min-height: 400px;
    }

    .message-bubble {
        font-size: 13px;
        padding: 8px 12px;
    }

    .text-input {
        font-size: 13px;
    }

    .vocab-word {
        font-size: 14px;
    }

    .vocab-definition {
        font-size: 11px;
    }
}

/* ==================== 觸控優化 ==================== */
@media (hover: none) and (pointer: coarse) {
    /* 增加觸控目標大小 */
    .btn,
    .control-btn,
    .scenario-btn,
    .vocab-action-btn,
    .toggle-visibility {
        min-height: 44px;
        min-width: 44px;
    }

    /* 移除 hover 效果，改用 active */
    .btn:hover,
    .control-btn:hover,
    .scenario-btn:hover {
        transform: none;
    }

    .btn:active,
    .control-btn:active,
    .scenario-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }

    /* 優化滾動 */
    .messages-area,
    .sidebar,
    .vocabulary-panel {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
}

/* ==================== 橫向模式優化 (Landscape) ==================== */
@media (max-width: 900px) and (orientation: landscape) {
    .chat-container {
        height: calc(100vh - 160px);
    }

    .chat-header {
        padding: 10px 14px;
    }

    .input-area {
        padding: 10px;
    }

    body {
        padding-bottom: 70px;
    }

    .mobile-bottom-nav {
        padding: 8px 0;
    }

    .mobile-nav-btn {
        padding: 4px;
        font-size: 10px;
    }

    .mobile-nav-btn .nav-icon {
        font-size: 20px;
    }
}

/* ==================== 測驗響應式樣式 ==================== */

/* 手機版測驗樣式 */
@media (max-width: 767px) {
    .quiz-modal {
        width: 95%;
        max-width: none;
        max-height: 90vh;
        border-radius: 16px;
    }

    .quiz-header {
        padding: 16px 20px;
        border-radius: 16px 16px 0 0;
    }

    .quiz-header h2 {
        font-size: 20px;
    }

    .quiz-progress {
        left: 20px;
        font-size: 12px;
    }

    .quiz-content {
        padding: 20px 16px;
    }

    .quiz-question h3 {
        font-size: 24px;
    }

    .quiz-question p {
        font-size: 14px;
    }

    .quiz-buttons {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding: 8px;
    }

    .quiz-start-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .quiz-option {
        padding: 14px 16px;
        font-size: 15px;
    }

    .option-letter {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .result-emoji {
        font-size: 56px;
    }

    .quiz-result h2 {
        font-size: 22px;
    }

    .score-circle {
        width: 120px;
        height: 120px;
    }

    .score-number {
        font-size: 40px;
    }

    .score-total {
        font-size: 16px;
    }

    .score-percentage {
        font-size: 20px;
    }

    .quiz-result-actions {
        flex-direction: column;
    }

    .quiz-btn {
        width: 100%;
    }

    .listening-icon {
        font-size: 48px;
    }

    .quiz-question.listening {
        padding: 24px;
    }
}

/* 平板版測驗樣式 */
@media (min-width: 768px) and (max-width: 1200px) {
    .quiz-modal {
        width: 85%;
        max-width: 650px;
    }

    .quiz-buttons {
        grid-template-columns: repeat(4, 1fr);
    }

    .quiz-start-btn {
        font-size: 12px;
        padding: 9px 14px;
    }
}

/* ==================== 打印樣式 ==================== */
@media print {
    .header,
    .sidebar,
    .vocabulary-panel,
    .input-area,
    .mobile-menu-btn,
    .mobile-bottom-nav,
    .toggle-visibility,
    .vocab-actions {
        display: none !important;
    }

    .app-container {
        grid-template-columns: 1fr;
        background: white;
    }

    .chat-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }

    .message {
        page-break-inside: avoid;
    }
}
