/* ═══════════════════════════════════════════════════════════════
   🎨 試題透視鏡 v25.9 - 森林蜜桃主題 (視覺修復版)
   ═══════════════════════════════════════════════════════════════ */

:root {
    --forest-deep: #2D4A3E;
    --forest-main: #4A6655;
    --forest-light: #6B8F71;
    --forest-pale: #E8F0E8;
    --peach-deep: #D4845A;
    --peach-main: #E8A87C;
    --peach-light: #F5D0B5;
    --peach-pale: #FFF5EE;
    --correct: #22C55E;
    --wrong: #EF4444;
    --warning: #F59E0B;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: linear-gradient(135deg, var(--forest-pale) 0%, var(--peach-pale) 100%);
    min-height: 100vh;
    color: var(--forest-deep);
    line-height: 1.6;
}

/* 導覽列 */
.navbar {
    background: linear-gradient(135deg, var(--forest-deep), var(--forest-main));
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

/* 手機版導覽列優化 */
@media (max-width: 768px) {
    .navbar {
        padding: 10px 16px;
    }
    
    .navbar-brand h1 {
        font-size: 1.1rem;
    }
    
    .navbar-brand .version {
        font-size: 0.6rem;
        padding: 2px 6px;
    }
    
    .mode-btn, .nav-btn {
        font-size: 0.75rem;
        padding: 5px 10px;
    }
}

.navbar-brand h1 {
    color: white;
    font-size: 1.4rem;
    display: inline-block;
    margin-right: 8px;
}

.navbar-brand .version {
    background: var(--peach-main);
    color: var(--forest-deep);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
}

.year-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    padding: 6px 12px;
    border-radius: 20px;
    color: white;
}

.year-selector select {
    background: white;
    border: none;
    padding: 6px 12px;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
}

.navbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.mode-switch {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
}

.mode-btn {
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 0.85rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.8);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-btn.active {
    background: white;
    color: var(--forest-deep);
}

.nav-btn {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 6px 14px;
    border-radius: 16px;
    cursor: pointer;
    font-size: 0.85rem;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* 🌟 首次進站脈動提示：設定 / 介紹按鈕呼吸光暈，讓老師發現它們 */
@keyframes navBtnPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 235, 130, 0.85); transform: scale(1); }
    50%      { box-shadow: 0 0 0 8px rgba(255, 235, 130, 0);    transform: scale(1.04); }
}
.nav-btn.pulse-hint {
    position: relative;
    background: rgba(255, 235, 130, 0.35);
    border-color: rgba(255, 235, 130, 0.9);
    animation: navBtnPulse 1.8s ease-in-out infinite;
}
.nav-btn.pulse-hint:hover {
    animation: none;
}
@media (prefers-reduced-motion: reduce) {
    .nav-btn.pulse-hint { animation: none; }
}

/* 主內容 */
.main-container {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 80px);
}

@media (max-width: 900px) {
    .main-container {
        grid-template-columns: 1fr;
    }
}

.panel {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    background: linear-gradient(135deg, var(--forest-main), var(--forest-light));
    color: white;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 1rem;
}

.panel-body {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
}

/* 右側詳情面板優化：防止教學工具箱下方空白 */
.panel-main .panel-body {
    flex: 0 0 auto;     /* 不縮、不長，自然撐開 */
    min-height: 200px;
    overflow: visible;  /* 移除內層 scrollbar，由 .panel-main 統一滾動 */
}

/* AI 區塊摺疊：預設只顯示標題列 */
.ai-header {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}
.ai-header:hover {
    background: rgba(168,194,168,0.08);
}
.ai-toggle-chevron {
    display: inline-block;
    font-size: 0.85rem;
    color: var(--forest-light);
    margin-left: 6px;
    transition: transform 0.2s;
}
.ai-section.collapsed .ai-toggle-chevron {
    transform: rotate(0deg); /* ▼ 朝下 = 收起 */
}
.ai-section:not(.collapsed) .ai-toggle-chevron {
    transform: rotate(180deg); /* ▲ 朝上 = 展開 */
}
.ai-section.collapsed .ai-body-collapsible {
    display: none;
}

/* ✨ [Fix 3] 會考題庫：右側詳情面板 sticky，滾動時停留在視野內 */
.panel-main {
    position: sticky;
    top: 80px; /* navbar 高度 + 間距 */
    align-self: start;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}

/* 📱 手機/平板：移除 sticky 與最大高度限制，整頁自然滾動 */
@media (max-width: 900px) {
    .panel-main {
        position: static;
        max-height: none;
        overflow: visible;
    }
}

/* 題目列表 */
.question-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.question-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.question-item:hover {
    background: var(--forest-pale);
}

.question-item.active {
    background: var(--peach-pale);
    border-color: var(--peach-main);
}

.q-num {
    width: 36px;
    height: 36px;
    background: var(--forest-pale);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.question-item.active .q-num {
    background: var(--peach-main);
    color: white;
}

.q-info {
    flex: 1;
    min-width: 0;
}

.q-type {
    font-size: 0.75rem;
    color: var(--forest-light);
}

.q-preview {
    font-size: 0.8rem;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.q-index {
    font-size: 0.8rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 12px;
    background: var(--forest-pale);
    color: var(--forest-main);
    flex-shrink: 0;      /* ✅ 防止被壓縮 */
    min-width: 40px;     /* ✅ 確保能容納兩位數 */
    text-align: center;  /* ✅ 數字置中顯示 */
}
.q-index.mid {
    background: #FEF3C7;  /* 淡黃色 */
    color: #D97706;       /* 橘色 */
}

.q-index.high {
    background: #FEE2E2;
    color: var(--wrong);
}

/* 題目詳情 */
.detail-section {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--forest-pale);
}

.detail-section.compact {
    margin-bottom: 15px;
    padding-bottom: 12px;
}

.section-title {
    font-weight: 700;
    color: var(--forest-main);
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.passage-box {
    background: var(--forest-pale);
    padding: 16px;
    border-radius: 10px;
    line-height: 1.8;
    font-size: 0.95rem;
}

.passage-box p {
    margin-bottom: 12px;
    text-indent: 2em;
}

/* 📌 題組引言 */
.group-intro {
    background: linear-gradient(135deg, #FFF8F6, #FFFBF0);
    padding: 16px;
    border-radius: 10px;
    border-left: 4px solid var(--peach-main);
    line-height: 1.8;
    font-size: 0.95rem;
    color: var(--forest-deep);
}

.group-intro p {
    margin-bottom: 12px;
}

/* 📖 註釋框 */
.notes-box {
    background: #F8FAFB;
    padding: 16px;
    border-radius: 10px;
    border: 2px dashed var(--forest-light);
}

.note-item {
    padding: 8px 12px;
    margin-bottom: 8px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid var(--forest-main);
    line-height: 1.6;
    font-size: 0.9rem;
    color: #555;
}

.note-item:last-child {
    margin-bottom: 0;
}

/* 註釋項目的編號樣式 */
.note-item::before {
    content: "📖";
    margin-right: 8px;
    opacity: 0.6;
}

.question-text {
    font-size: 1rem;
    line-height: 1.8;
    padding: 12px;
    background: #FAFAFA;
    border-radius: 8px;
}

/* 🎨 題目特殊格式樣式 */
/* 1. 畫底線（畫線處） */
.underline {
    text-decoration: underline;
    text-decoration-color: var(--peach-main);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
    font-weight: 600;
    color: var(--forest-deep);
}

/* 2. 框起來（重點標記） */
.boxed {
    display: inline-block;
    padding: 2px 8px;
    background: var(--peach-pale);
    border: 2px solid var(--peach-main);
    border-radius: 6px;
    font-weight: 600;
    color: var(--forest-deep);
    margin: 0 2px;
}

/* 📐 段距空白（v7 \n\n 段落間距）— 視為一個空白行高度 */
.para-gap {
    display: block;
    height: 0.7em;
}

/* 📊 引文框（雙文/多資料對讀題）— >>>標籤\n內容\n<<< 標記 */
.data-box {
    background: #FAF6F0;
    border: 1px solid #D4B896;
    border-radius: 8px;
    padding: 14px 18px 14px 22px;
    margin: 12px 0;
    position: relative;
    line-height: 1.8;
}
.data-box::before {
    content: '【' attr(data-label) '】';
    display: block;
    font-weight: bold;
    color: #8B5A3C;
    margin-bottom: 6px;
}
/* 裝飾性後綴 label 不顯示——會考實際題目並無這種標籤
   （注意：純 《書名》 不在此列，因為會考真會出現如「《說文解字》：...」格式） */
.data-box[data-label$="介紹"]::before,
.data-box[data-label$="說明"]::before,
.data-box[data-label$="簡介"]::before,
.data-box[data-label$="概述"]::before,
.data-box[data-label$="原文"]::before,
.data-box[data-label$="內容"]::before,
.data-box[data-label$="文本"]::before {
    display: none;
}

/* 🔡 ASCII 表格（如 Q14 投壺計分表）— 偵測到 │ 字元時用等寬字體保持對齊 */
.ascii-table {
    font-family: ui-monospace, "Cascadia Code", Menlo, "MingLiU", "PMingLiU", "Microsoft JhengHei", monospace;
    background: #FAFAF6;
    border: 1px solid var(--forest-pale);
    border-radius: 8px;
    padding: 12px 14px;
    margin: 10px 0;
    font-size: 0.92rem;
    line-height: 1.8;
    white-space: pre;
    overflow-x: auto;
    color: var(--text-main);
}

/* 3. 註釋/說明 */
.note {
    font-size: 0.85rem;
    color: var(--forest-light);
    font-style: italic;
    background: var(--forest-pale);
    padding: 2px 6px;
    border-radius: 4px;
    margin: 0 2px;
}

/* 4. 粗體強調（已有標準strong樣式，這裡再強化） */
.question-text strong,
.passage-box strong {
    color: var(--forest-deep);
    font-weight: 700;
}

/* 手機版文本區域優化 */
@media (max-width: 768px) {
    .passage-box {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .question-text {
        font-size: 0.95rem;
        padding: 10px;
    }
    
    .analysis-box {
        padding: 12px;
        font-size: 0.9rem;
    }
}

/* 🖼️ 多圖輪播樣式 */
.image-gallery {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 8px;
    white-space: nowrap;
}

.image-gallery img {
    height: 180px;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid #eee;
    cursor: zoom-in;
    flex-shrink: 0;
    transition: transform 0.2s;
}

.image-gallery img:hover {
    transform: scale(1.02);
}

/* 手機版圖片優化 */
@media (max-width: 768px) {
    .image-gallery img {
        height: 140px;
    }
    
    .image-gallery {
        gap: 8px;
    }
}

/* 🖼️ 選項圖片網格 (新增) */
.option-image-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* 手機版選項圖片優化 */
@media (max-width: 768px) {
    .option-image-grid {
        gap: 8px;
    }
    
    .opt-img-item img {
        height: 100px;
    }
}

.opt-img-item {
    position: relative;
    border: 2px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    cursor: zoom-in;
}

.opt-img-item:hover {
    border-color: var(--peach-main);
}

.opt-img-label {
    position: absolute;
    top: 0;
    left: 0;
    background: var(--forest-main);
    color: white;
    padding: 2px 8px;
    font-size: 0.8rem;
    font-weight: bold;
    border-bottom-right-radius: 8px;
}

.opt-img-item img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    display: block;
    background: #fff;
}

/* 選項分析 */
.opt-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}

.opt-letter {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    background: var(--forest-pale);
    color: var(--forest-main);
    flex-shrink: 0;
}

.opt-letter.correct {
    background: var(--correct);
    color: white;
}

.opt-track {
    flex: 1;
    height: 12px;
    background: #E5E7EB;
    border-radius: 6px;
    overflow: hidden;
}

.opt-fill {
    height: 100%;
    transition: width 0.5s ease;
}

.opt-value {
    width: 48px;
    font-size: 0.85rem;
    color: #666;
    text-align: right;
    font-weight: 600;
}

.opt-diagnosis {
    margin-left: 44px;
    font-size: 0.85rem;
    color: #b91c1c;
    background: #fef2f2;
    padding: 6px 10px;
    border-radius: 6px;
    border-left: 3px solid #ef4444;
    margin-bottom: 8px;
}

/* 解析區 */
.analysis-box {
    background: var(--peach-pale);
    padding: 14px;
    border-radius: 10px;
    font-size: 0.95rem;
    line-height: 1.8;
    border-left: 4px solid var(--peach-main);
    white-space: pre-wrap;
}

.analysis-box .opt-tag {
    color: var(--forest-deep);
    background: rgba(255, 255, 255, 0.6);
    padding: 1px 5px;
    border-radius: 4px;
    margin-right: 4px;
}

/* AI 區塊 */
.ai-section {
    border-top: 2px dashed var(--forest-pale);
    padding: 12px 16px 14px;
    background: #fff;
    margin-top: 0;
}

.ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.ai-header span {
    font-weight: 700;
    color: var(--forest-main);
}

.ai-modes {
    display: flex;
    gap: 6px;
}

.ai-mode-btn {
    padding: 5px 12px;
    border: 1px solid var(--forest-light);
    border-radius: 14px;
    background: white;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-mode-btn.active {
    background: var(--forest-main);
    color: white;
    border-color: var(--forest-main);
}

.ai-run-btn {
    width: 100%;
    padding: 12px;
    background: var(--peach-main);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 12px;
}

.ai-run-btn:hover:not(:disabled) {
    background: var(--peach-deep);
}

.ai-run-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-output {
    background: white;
    padding: 16px;
    border-radius: 10px;
    font-size: 0.95rem;
    border: 1px solid var(--forest-pale);
    line-height: 1.8;
    display: none;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* 匯出按鈕容器 */
.export-buttons {
    display: none;
    gap: 12px;
    margin-top: 24px;
    padding: 16px;
    background: linear-gradient(135deg, var(--forest-pale), var(--peach-pale));
    border-radius: 10px;
    flex-wrap: wrap;
    justify-content: center;
}


/* Markdown 樣式 */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    color: var(--forest-deep);
}

.markdown-body ul,
.markdown-body ol {
    padding-left: 1.5em;
    margin-bottom: 1em;
}

.markdown-body p {
    margin-bottom: 0.8em;
}

.markdown-body strong {
    background: linear-gradient(to top, rgba(255, 235, 59, 0.35) 35%, transparent 35%);
    padding: 1px 2px;
}

/* ── markdown-body 表格（歷史還原 / Claude審題 / 比較報告）── */
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 0.92rem;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 3px 10px rgba(74, 102, 85, 0.12);
    background: white;
}
.markdown-body th {
    background: linear-gradient(135deg, var(--forest-deep), var(--forest-main));
    color: white;
    padding: 11px 14px;
    text-align: left;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 0.3px;
}
.markdown-body td {
    padding: 10px 14px;
    border-bottom: 1px solid #e8ebe9;
    vertical-align: top;
    line-height: 1.75;
}
.markdown-body tr:nth-child(even) td { background-color: #f9faf9; }
.markdown-body tr:hover td { background-color: #f0f4f1; }

/* blockquote（還原後的引言區塊）*/
.markdown-body blockquote {
    border-left: 4px solid var(--forest-light);
    margin: 12px 0;
    padding: 10px 16px;
    background: #f7faf8;
    border-radius: 0 8px 8px 0;
    color: #555;
    line-height: 1.8;
}

/* 錯誤框 */
.error-box {
    background: #FEF2F2;
    color: #B91C1C;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #FCA5A5;
    text-align: center;
}

/* 通用 UI */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-backdrop.show {
    opacity: 1;
    visibility: visible;
}

.modal-card {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-backdrop.show .modal-card {
    transform: scale(1);
}

.modal-header {
    background: linear-gradient(135deg, var(--forest-main), var(--forest-light));
    color: white;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(90vh - 130px);
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    cursor: zoom-out;
    transition: all 0.3s;
}

.lightbox.active {
    opacity: 1;
    visibility: visible;
}

.lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--forest-deep);
    color: white;
    padding: 12px 24px;
    border-radius: 25px;
    font-weight: 600;
    opacity: 0;
    transition: all 0.3s;
    z-index: 99999;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0;
}

.toast.success {
    background: var(--correct);
}

/* 手機版 Toast 和 Modal 優化 */
@media (max-width: 768px) {
    .modal-card {
        width: 95%;
        max-width: none;
        max-height: 85vh;
    }
    
    .modal-body {
        padding: 16px;
        font-size: 0.95rem;
    }
    
    .toast {
        bottom: 20px;
        padding: 10px 20px;
        font-size: 0.9rem;
        max-width: 90%;
        text-align: center;
    }
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--forest-light);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.loading {
    text-align: center;
    padding: 20px;
    color: #888;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--forest-pale);
    border-top-color: var(--forest-main);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

/* 🍑 可愛的水蜜桃 Loading */
.peach-loading {
    font-size: 1.5rem;  /* 改小，更精緻 */
    animation: peach-bounce 1s ease-in-out infinite;
    margin: 0 auto 10px;
    display: inline-block;
}

@keyframes peach-bounce {
    0%, 100% {
        transform: translateY(0) rotate(0deg) scale(1);
    }
    25% {
        transform: translateY(-8px) rotate(-5deg) scale(1.1);  /* 跳動幅度也稍微調小 */
    }
    50% {
        transform: translateY(0) rotate(0deg) scale(1);
    }
    75% {
        transform: translateY(-4px) rotate(5deg) scale(1.05);  /* 跳動幅度也稍微調小 */
    }
}

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

/* ═══════════════════════════════════════════════════════════════
   📺 補丁：展演模式 & 工具箱
   ═══════════════════════════════════════════════════════════════ */

/* 展演模式 - 保留導覽列但簡化 */
body.presenter-mode .navbar {
    background: rgba(45, 74, 62, 0.95);
    backdrop-filter: blur(10px);
}

/* 展演模式 - 隱藏不必要的導覽列元素，只保留返回按鈕 */
body.presenter-mode .navbar-brand,
body.presenter-mode .year-selector,
body.presenter-mode .mode-switch,
body.presenter-mode .nav-btn:not(#presenterBtn) {
    display: none !important;
}

/* 展演模式 - 返回按鈕放大 */
body.presenter-mode #presenterBtn {
    font-size: 1.2rem;
    padding: 0.75rem 1.5rem;
}

body.presenter-mode .main-container {
    grid-template-columns: 1fr !important; /* 變成單欄 */
    padding: 0 !important;
    max-width: 100%;
    height: auto;  /* 改為自動高度 */
}

/* 隱藏第一個面板 (題目列表) */
body.presenter-mode .main-container > .panel:first-child { display: none !important; }

/* 放大右側面板 (詳情區) */
body.presenter-mode .main-container > .panel:last-child {
    border-radius: 0;
    box-shadow: none;
    height: auto;  /* 改為自動高度，允許滾動 */
    min-height: 100vh;  /* 最小高度保持全螢幕 */
}

/* 確保面板內容可以滾動 */
body.presenter-mode .panel-body {
    overflow-y: auto;
    max-height: none;
}

/* 放大文字便於投影 */
body.presenter-mode .question-text,
body.presenter-mode .passage-box {
    font-size: 1.5rem !important;
    line-height: 2 !important;
    padding: 30px !important;
}

/* 退出按鈕 (僅在展演模式顯示) */
.presenter-exit-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    padding: 10px 20px;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    display: none; /* 預設隱藏 */
}
body.presenter-mode .presenter-exit-btn { display: block; }

/* 🛠️ 工具箱按鈕列 */
.action-bar {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}
.action-btn-sm {
    padding: 6px 12px;
    background: var(--forest-pale);
    color: var(--forest-deep);
    border: 1px solid var(--forest-light);
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}
.action-btn-sm:hover {
    background: var(--forest-main);
    color: white;
}

/* 🎭 遮幕效果 (Spoiler) */
.spoiler-wrapper {
    position: relative;
    cursor: pointer;
    transition: all 0.3s;
}

.spoiler-wrapper:not(.revealed) .spoiler-overlay {
    display: flex;
}

.spoiler-wrapper:not(.revealed) .options-visual-simple,
.spoiler-wrapper:not(.revealed) .analysis-box {
    filter: blur(8px);
    user-select: none;
    pointer-events: none;
}

.spoiler-overlay {
    position: absolute;
    inset: 0;
    background: rgba(74, 102, 85, 0.85);
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 600;
    z-index: 10;
    border-radius: 10px;
    backdrop-filter: blur(2px);
    transition: all 0.3s;
}

.spoiler-wrapper.revealed .spoiler-overlay {
    display: none;
}

.spoiler-wrapper:hover:not(.revealed) .spoiler-overlay {
    background: rgba(212, 132, 90, 0.9);
}

/* 🎨 美化輸入框和按鈕 */
.input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--forest-pale);
    border-radius: 10px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s;
    margin-bottom: 12px;
}

.input:focus {
    outline: none;
    border-color: var(--forest-main);
    box-shadow: 0 0 0 3px rgba(74, 102, 85, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--forest-main), var(--forest-light));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(74, 102, 85, 0.2);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--forest-deep), var(--forest-main));
    box-shadow: 0 6px 20px rgba(74, 102, 85, 0.3);
    transform: translateY(-2px);
}

.btn-primary:active {
    transform: translateY(0);
}

.link {
    display: inline-block;
    padding: 8px 16px;
    color: var(--forest-main);
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 6px;
}

.link:hover {
    background: var(--forest-pale);
}

.link.danger {
    color: var(--wrong);
    padding: 10px 20px;
    border: 2px solid var(--wrong);
    border-radius: 10px;
    font-weight: 600;
    transition: all 0.3s;
}

.link.danger:hover {
    background: var(--wrong);
    color: white;
}

/* 提示文字 */
.hint {
    color: #666;
    font-size: 0.85rem;
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--forest-pale);
    border-radius: 6px;
    border-left: 3px solid var(--forest-main);
}

/* 指引區塊 */
.guide {
    margin-top: 16px;
    padding: 12px;
    background: #FAFAFA;
    border-radius: 8px;
    font-size: 0.9rem;
}

.guide summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--forest-main);
    padding: 4px 0;
}

.guide summary:hover {
    color: var(--peach-deep);
}

.guide ol, .guide ul {
    margin-top: 12px;
    padding-left: 24px;
}

.guide li {
    margin-bottom: 8px;
    line-height: 1.6;
}

.guide code {
    background: var(--forest-pale);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

/* 🦶 Footer 簽名區 */
.footer-signature {
    text-align: center;
    font-size: 0.85rem;
    opacity: 0.8;
    font-style: italic;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    width: 100%;
}

/* Footer 手機版優化 */
@media (max-width: 768px) {
    .footer > div:first-child {
        gap: 8px !important;
        line-height: 1.6;
    }

    .footer-signature {
        font-size: 0.75rem;
        margin-top: 8px;
        padding-top: 8px;
    }
}

/* 修復：移除工具箱下方的多餘空白 */
.detail-section.no-margin-bottom {
    margin-bottom: 0;
    padding-bottom: 16px;  /* 加回適當的內距 */
    border-bottom: none;
}

/* 手機版遮幕優化 */
@media (max-width: 768px) {
    .spoiler-overlay {
        font-size: 0.95rem;
    }
    
    .export-buttons {
        flex-direction: column;
        gap: 8px;
    }
    
    .btn-export {
        width: 100%;
        padding: 12px;
    }
}
/* ═══════════════════════════════════════════════════════════════
   🆕 v26 升級樣式 - 保留森林蜜桃設計
   ═══════════════════════════════════════════════════════════════ */

/* ─── 五種 AI 模式卡片（森林蜜桃風格）─── */
.ai-modes-container {
    margin-bottom: 1.5rem;
}

.ai-modes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.ai-mode-card {
    background: white;
    border: 2px solid var(--forest-pale);
    border-radius: 12px;
    padding: 0.6rem 0.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    text-align: center;
    position: relative;
    overflow: hidden;
}

.ai-mode-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--forest-pale), var(--peach-pale));
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 0;
}

.ai-mode-card:hover::before {
    opacity: 1;
}

.ai-mode-card:hover {
    border-color: var(--peach-main);
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 8px 24px rgba(232, 168, 124, 0.3);
}

.ai-mode-card.active {
    border-color: var(--forest-main);
    background: linear-gradient(135deg, var(--forest-pale), var(--peach-pale));
    box-shadow: 0 8px 24px rgba(74, 102, 85, 0.25);
}

.ai-mode-card.active::after {
    content: '✓';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    background: var(--forest-main);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    z-index: 1;
}

.mode-icon {
    font-size: 1.5rem;
    margin-bottom: 0.2rem;
    position: relative;
    z-index: 1;
    line-height: 1;
}

.mode-title {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--forest-deep);
    margin-bottom: 0.15rem;
    position: relative;
    z-index: 1;
}

.mode-desc {
    font-size: 0.72rem;
    color: var(--forest-light);
    line-height: 1.25;
    position: relative;
    z-index: 1;
}

/* ─── 錯誤選項選擇器（森林蜜桃風格）─── */
.wrong-option-selector {
    background: var(--peach-pale);
    border: 2px dashed var(--peach-main);
    border-radius: 12px;
    padding: 1rem;
    margin-top: 1rem;
}

.selector-label {
    display: block;
    font-weight: 600;
    color: var(--forest-deep);
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.option-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.option-btn {
    background: white;
    border: 2px solid var(--forest-light);
    padding: 0.65rem 1.25rem;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--forest-deep);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 55px;
}

.option-btn:hover {
    border-color: var(--peach-main);
    background: var(--peach-pale);
    transform: translateY(-2px);
}

.option-btn.active {
    background: var(--peach-main);
    border-color: var(--peach-deep);
    color: white;
    box-shadow: 0 4px 12px rgba(212, 132, 90, 0.3);
}

/* 正確答案不可選（防呆） */
.option-btn.disabled,
.option-btn:disabled {
    background: #f5f5f5;
    border-color: #d1d5db;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.option-btn.disabled:hover,
.option-btn:disabled:hover {
    transform: none;
    border-color: #d1d5db;
    background: #f5f5f5;
}

/* ─── 取消按鈕 ─── */
.ai-cancel-btn {
    width: 100%;
    background: linear-gradient(135deg, #EF4444, #DC2626);
    color: white;
    border: none;
    padding: 0.875rem 2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.ai-cancel-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.3);
}

/* ─── Footer 一行版（森林蜜桃風格）─── */
.footer {
    background: linear-gradient(135deg, var(--forest-deep), var(--forest-main));
    color: rgba(255, 255, 255, 0.9);
    padding: 0.75rem 2rem;
    text-align: center;
    font-size: 0.8rem;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.footer .separator {
    color: var(--peach-light);
    font-weight: 700;
    opacity: 0.6;
}

/* ─── 手機版適配 ─── */
@media (max-width: 768px) {
    .ai-modes-grid {
        grid-template-columns: 1fr;
    }
    
    .footer {
        font-size: 0.7rem;
        padding: 0.65rem 1rem;
        gap: 0.5rem;
    }
}


/* ═══════════════════════════════════════════════════════════════
   📜 歷史記錄美化樣式
   ═══════════════════════════════════════════════════════════════ */

.history-item {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    border: 2px solid var(--forest-pale);
    transition: all 0.3s;
    cursor: default;
}

.history-item:hover {
    border-color: var(--peach-main);
    box-shadow: 0 4px 12px rgba(212, 132, 90, 0.15);
    transform: translateY(-2px);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.history-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--forest-deep);
}

.history-date {
    font-size: 0.85rem;
    color: var(--forest-light);
}

.history-meta {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.badge {
    background: var(--peach-pale);
    color: var(--peach-deep);
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge.secondary {
    background: var(--forest-pale);
    color: var(--forest-main);
}

.history-preview {
    color: var(--forest-light);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--forest-pale);
    border-radius: 8px;
    cursor: pointer;
    position: relative;
    transition: background 0.18s, box-shadow 0.18s;
}

/* E19：hover 顯示可編輯提示 */
.history-preview:hover {
    background: #e8f0e8;
    box-shadow: inset 0 0 0 1.5px #8fbc8f;
}

.history-preview .preview-edit-hint {
    display: none;
    position: absolute;
    top: 6px;
    right: 8px;
    font-size: 0.75rem;
    color: #5c6bc0;
    font-weight: 600;
    background: white;
    border: 1px solid #c5cae9;
    border-radius: 4px;
    padding: 1px 6px;
    pointer-events: none;
}

.history-preview:hover .preview-edit-hint {
    display: inline;
}

.history-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-small {
    background: white;
    border: 2px solid var(--forest-main);
    color: var(--forest-main);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-small:hover {
    background: var(--forest-main);
    color: white;
    transform: translateY(-2px);
}

.btn-small.danger {
    border-color: var(--wrong);
    color: var(--wrong);
}

.btn-small.danger:hover {
    background: var(--wrong);
    color: white;
}


/* 指標等級 - 新增低優先和無指標 */
.q-index.low {
    background: linear-gradient(135deg, #E8F5E9, #C8E6C9);
    color: #2E7D32;
}

.q-index.none {
    background: #F5F5F5;
    color: #9E9E9E;
    font-weight: 400;
}

/* ═══════════════════════════════════════════════════════════════
   🎨 AI 輸出內容美化樣式（表格、螢光筆、強調）
   ═══════════════════════════════════════════════════════════════ */

.ai-result-content.markdown-body,
.ai-result-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    margin-bottom: 24px;
    line-height: 1.8;
    font-size: 1.05rem;
    color: #333;
    width: 100%;
    max-width: 100%;
    overflow-wrap: break-word;
    word-wrap: break-word;
    word-break: break-word;
}

/* Markdown 標題美化 */
.ai-result-content h1 {
    color: var(--forest-deep);
    font-family: "Noto Serif TC", serif;
    font-size: 1.8rem;
    font-weight: 800;
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    border-bottom: 3px solid var(--peach-main);
    padding-bottom: 12px;
}

.ai-result-content h2 {
    color: var(--forest-main);
    font-family: "Noto Serif TC", serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 1.5em;
    margin-bottom: 0.8em;
    border-bottom: 2px solid var(--peach-light);
    padding-bottom: 8px;
}

.ai-result-content h3 {
    font-size: 1.2rem;
    color: var(--peach-deep);
    background: var(--peach-pale);
    padding: 10px 15px;
    border-radius: 8px;
    border-left: 5px solid var(--peach-main);
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 700;
}

.ai-result-content h4 {
    font-size: 1.1rem;
    color: var(--forest-main);
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

/* 段落與文字 */
.ai-result-content p {
    margin-bottom: 1em;
    text-align: justify;
}

/* 強調文字 - 螢光筆效果（底部塗色，像真正的螢光筆） */
.ai-result-content strong,
.ai-result-content b {
    color: #1a1a1a;
    font-weight: 700;
    background: linear-gradient(to top, var(--peach-light) 35%, transparent 35%);
    padding: 1px 2px;
    border-radius: 2px;
}

/* 斜體 */
.ai-result-content em,
.ai-result-content i {
    color: var(--peach-deep);
    font-style: italic;
}

/* 引用區塊 */
.ai-result-content blockquote {
    background-color: var(--forest-pale);
    border: 2px solid var(--forest-light);
    border-radius: 12px;
    padding: 20px 24px;
    margin: 20px 0;
    color: var(--forest-deep);
    font-style: italic;
    box-shadow: 0 2px 8px rgba(74, 102, 85, 0.1);
}

.ai-result-content blockquote p {
    margin: 0;
}

/* 列表美化 */
.ai-result-content ul,
.ai-result-content ol {
    margin-bottom: 1.2em;
    padding-left: 2em;
}

.ai-result-content li {
    margin-bottom: 0.6em;
    line-height: 1.8;
}

.ai-result-content ul li::marker {
    color: var(--peach-main);
    font-size: 1.2em;
}

.ai-result-content ol li::marker {
    color: var(--forest-main);
    font-weight: 700;
}

/* 表格美化 (自動欄寬 + 防爆換行) */
.ai-result-content table {
    width: 100% !important;
    table-layout: auto !important;
    border-collapse: collapse;
    margin: 20px 0;
    border: 2px solid var(--forest-pale);
    background: white;
}

.ai-result-content th,
.ai-result-content td {
    border: 1px solid #eee;
    padding: 12px;
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ai-result-content th {
    background-color: var(--forest-pale);
    color: var(--forest-deep);
    font-weight: bold;
    white-space: normal !important;
}

.ai-result-content tr:nth-child(even) {
    background-color: #f9faf9;
}

.ai-result-content tr:hover {
    background-color: var(--forest-pale);
    transition: background-color 0.2s;
}

.ai-result-content tbody tr:last-child td {
    border-bottom: none;
}

/* 程式碼區塊 (含防爆換行) */
.ai-result-content code {
    background: #f5f5f5;
    color: #d63384;
    padding: 3px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    white-space: pre-wrap;
    word-break: break-all;
}

.ai-result-content pre {
    background: var(--forest-deep);
    color: var(--peach-pale);
    padding: 20px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 20px 0;
    white-space: pre-wrap;
    word-break: break-all;
}

.ai-result-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    border: none;
}

/* 水平線 */
.ai-result-content hr {
    border: none;
    border-top: 2px dashed var(--forest-light);
    margin: 2em 0;
}

/* 連結 */
.ai-result-content a {
    color: var(--peach-deep);
    text-decoration: underline;
    transition: color 0.2s;
}

.ai-result-content a:hover {
    color: var(--peach-main);
}

/* 特殊標記 - 提示框 */
.ai-result-content .note,
.ai-result-content .tip {
    background: linear-gradient(135deg, #E8F5E9, #C8E6C9);
    border-left: 5px solid #4CAF50;
    padding: 15px 20px;
    margin: 20px 0;
    border-radius: 8px;
}

.ai-result-content .warning {
    background: linear-gradient(135deg, #FFF3E0, #FFE0B2);
    border-left: 5px solid #FF9800;
    padding: 15px 20px;
    margin: 20px 0;
    border-radius: 8px;
}

/* 淡入動畫 */
.ai-result-content.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.btn-export {
    background: linear-gradient(135deg, var(--forest-main), var(--forest-deep));
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(74, 102, 85, 0.2);
}

.btn-export:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(74, 102, 85, 0.3);
    background: linear-gradient(135deg, var(--forest-deep), #2d4a3e);
}

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

/* ═══════════════════════════════════════════════════════════════
   ✨ 歷史紀錄 Footer 美化 (v26 Pro Plus 修正版)
   修復：按鈕過寬導致溢出的問題
   ═══════════════════════════════════════════════════════════════ */

/* Footer 容器 */
.modal-footer {
    padding: 12px 16px !important; /* 縮小內距，增加空間 */
    background: #F8FAFB !important;
    border-top: 1px solid #EAEAEA !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 8px; /* 縮小間距 */
    flex-wrap: wrap; /* 關鍵：允許換行，避免擠出視窗 */
}

/* 按鈕群組 */
.footer-group {
    display: flex;
    gap: 6px; /* 群組內間距縮小 */
    align-items: center;
    flex-wrap: wrap; /* 群組內也允許換行 */
}

/* 統一按鈕基礎樣式 (更緊湊版) */
.btn-tool {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px; /* 圖標文字間距縮小 */
    padding: 6px 12px; /* 瘦身：左右內距縮小 */
    border-radius: 8px;
    font-size: 0.85rem; /* 字體微縮 */
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    height: 34px; /* 高度微縮 (原本38) */
    white-space: nowrap;
    border: 1px solid transparent;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.btn-tool .icon {
    font-size: 1.1em;
}

/* 點擊效果 */
.btn-tool:active {
    transform: translateY(1px);
    box-shadow: none;
}

/* ⚪ 次要按鈕 (全選/反選) */
.btn-tool.secondary {
    background: white;
    border-color: #E0E0E0;
    color: #666;
}
.btn-tool.secondary:hover {
    border-color: var(--forest-main);
    color: var(--forest-main);
    background: #F4F9F6;
}

/* 🟢 主要按鈕 (合併匯出) */
.btn-tool.primary {
    background: linear-gradient(135deg, var(--forest-main), var(--forest-deep));
    color: white;
    border: none;
    box-shadow: 0 2px 6px rgba(74, 102, 85, 0.2);
}
.btn-tool.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(74, 102, 85, 0.3);
}

/* 🔴 危險按鈕 (清空) */
.btn-tool.danger {
    background: #FFF5F5;
    border: 1px solid #FED7D7;
    color: #C53030;
    box-shadow: none;
}
.btn-tool.danger:hover {
    background: #C53030;
    color: white;
    border-color: #C53030;
}

/* 手機版/極窄螢幕優化 */
@media (max-width: 480px) {
    .modal-footer {
        padding: 12px !important;
        justify-content: center !important; /* 置中對齊 */
    }
    .footer-group {
        width: 100%;
        justify-content: center;
    }
    .btn-tool {
        flex: 1;
        min-width: 80px; /* 防止按鈕縮太小 */
        padding: 6px 4px; /* 極限縮小內距 */
    }
}
/* 分類標題樣式 */
.list-group-header {
    background-color: #f0f4f8; /* 淺灰藍底 */
    color: var(--forest-main);
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: bold;
    border-left: 4px solid var(--forest-main);
    margin: 10px 0 5px 0;
    position: sticky;
    top: 0;
    z-index: 5; /* 讓標題在捲動時稍微浮起 */
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* 讓列表的第一個元素不要有 margin-top */
.question-list .list-group-header:first-child {
    margin-top: 0;
}
/* AI 輸出區文字強調 */
.ai-output strong,
.ai-output b {
    color: #1a1a1a;
    font-weight: 700;
    background: linear-gradient(to top, var(--peach-light) 35%, transparent 35%);
    padding: 1px 2px;
    border-radius: 2px;
}

/* ════════════════════════════════════════════
   📊 AI 輸出區表格專用樣式 (手機版修復)
   ════════════════════════════════════════════ */

/* 1. 表格整體設定 */
.ai-output table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 0.95rem; /* 字體稍微調大一點點，手機好讀 */
    background-color: #ffffff; /* ✅ 強制背景白色，解決綠底問題 */
    border-radius: 8px; /* 圓角設計 */
    overflow: hidden; /* 確保圓角不被切掉 */
    box-shadow: 0 0 0 1px #eee; /* 輕微邊框 */
}

/* 2. 表頭 (Header)：綠底 + 白字 */
.ai-output th {
    background-color: var(--forest-main);
    color: #ffffff !important; /* ✅ 強制白字 (關鍵！解決深色字看不清) */
    padding: 12px 15px;
    text-align: left;
    font-weight: bold;
    border-bottom: 2px solid #3d5546;
    white-space: nowrap; /* 手機上表頭不換行，保持整齊 */
}

/* 3. 內容儲存格 (Cells)：白底 + 深灰字 */
.ai-output td {
    padding: 12px 15px;
    color: #333333; /* ✅ 深灰色文字，閱讀舒適 */
    background-color: #ffffff; /* ✅ 強制白底 */
    border-bottom: 1px solid #eeeeee;
    line-height: 1.6;
}

/* 4. 雙色條紋 (Zebra Striping)：讓閱讀不疲勞 */
.ai-output tr:nth-child(even) td {
    background-color: #f8fafc; /* 極淺的灰藍色 (比綠色好讀) */
}


/* ════════════════════════════════════════════
   📱 RWD 表格智慧欄寬 (全裝置自適應)
   ════════════════════════════════════════════ */

/*
 * 核心策略：table-layout: auto + word-wrap: break-word
 * - 第一欄用 width:1px + white-space:nowrap → 自動縮到剛好包住文字
 * - 內容欄用 width:auto → 吃掉剩餘空間
 * - word-wrap:break-word 在 th/td 上 → 防止超長內容撐破表格
 * - 桌面/手機統一邏輯，不再分 fixed/auto
 */

/* 全裝置：第一欄自動縮放 */
.ai-output th:first-child,
.ai-output td:first-child,
.ai-result-content th:first-child,
.ai-result-content td:first-child {
    width: 1px;              /* 縮到最小，讓瀏覽器自動撐到文字寬度 */
    white-space: nowrap;     /* 不換行：保證標題完整顯示 */
    text-align: center;
}

/* 手機微調 */
@media (max-width: 768px) {
    .ai-output th:first-child,
    .ai-output td:first-child,
    .ai-result-content th:first-child,
    .ai-result-content td:first-child {
        padding: 10px 8px;   /* 手機稍微縮小間距 */
    }

    .ai-output td:nth-child(2),
    .ai-result-content td:nth-child(2) {
        font-size: 0.95rem;
    }
}
/* ════════════════════════════════════════════
   ⬆️ 回到頂端按鈕 (浮動式)
   ════════════════════════════════════════════ */
#scrollTopBtn {
    display: none; /* 預設隱藏，滑動後才出現 */
    position: fixed;
    bottom: 30px; /* 距離底部 */
    right: 30px;  /* 距離右邊 */
    z-index: 9999; /* 確保在最上層 */
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%; /* 圓形 */
    background: linear-gradient(135deg, var(--forest-main), var(--forest-deep)); /* 配合您的森林主題 */
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2); /* 陰影讓它浮起來 */
    transition: all 0.3s;
    align-items: center;
    justify-content: center;
}

#scrollTopBtn:hover {
    background: var(--peach-deep); /* 滑鼠碰到變蜜桃色 */
    transform: translateY(-5px) scale(1.1); /* 微微上浮放大 */
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

/* 手機版稍微縮小一點，避免擋路 */
@media (max-width: 768px) {
    #scrollTopBtn {
        width: 40px;
        height: 40px;
        bottom: 20px;
        right: 20px;
        font-size: 1.2rem;
    }
}
/* ═══════════════════════════════════════════════════════════════
   歷史紀錄面板：Flex Column 確保 Footer 不被裁切
   ═══════════════════════════════════════════════════════════════ */

/* modal-card 改為 flex 直排，並固定高度讓子元素有明確尺寸可參考 */
#modal-history .modal-card {
    display: flex;
    flex-direction: column;
    height: 90vh;
    max-height: 90vh;
    overflow-y: hidden;    /* 內部由 flex 子元素各自捲動 */
}

/* historyContent：flex column 容器，不自己捲動，交給 .history-list */
#historyContent {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;       /* 不在這裡捲動，防止雙層捲軸 */
    display: flex;
    flex-direction: column;
    max-height: none !important;
    padding: 0;
}

/* ═══════════════════════════════════════════════════════════════
   歷史紀錄篩選標籤列 (Filter Bar)
   ═══════════════════════════════════════════════════════════════ */

.history-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 16px 8px;
    background: #fff;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;         /* 不壓縮，永遠顯示在頂部 */
}

.history-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1.5px solid #d1d5db;
    background: #f3f4f6;
    color: #4b5563;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.18s, color 0.18s, border-color 0.18s;
}

.history-filter-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.history-filter-btn.active {
    background: #2d6a4f;
    border-color: #2d6a4f;
    color: #ffffff;
    font-weight: 700;
}

/* 每筆紀錄的包裝層（預設顯示） */
.history-item-wrap {
    display: block;
}

/* ═══════════════════════════════════════════════════════════════
   🎒 魔法背包 + NPC 咒語精靈 styles
   ═══════════════════════════════════════════════════════════════ */

/* ── 咒語卡片 ─────────────────────────────────────────────── */
.spell-card {
    background: white;
    border: 1.5px solid #e8eaf6;
    border-radius: 10px;
    padding: 11px 13px;
    transition: box-shadow .15s, border-color .15s;
}
.spell-card:hover {
    border-color: #9fa8da;
    box-shadow: 0 2px 10px rgba(102,126,234,.12);
}

.spell-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 8px;
}

/* 六碼 ID 徽章 */
.spell-id-badge {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: .08em;
    color: #667eea;
    background: #f0f3ff;
    border: 1px solid #c5cae9;
    border-radius: 5px;
    padding: 2px 7px;
    font-family: monospace;
    white-space: nowrap;
    cursor: default;
    user-select: all;
}

.spell-actions { display: flex; gap: 5px; }

.spell-btn {
    padding: 3px 9px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    font-weight: 600;
    transition: opacity .15s;
}
.spell-btn:hover { opacity: .75; }
.spell-btn--use   { background: #e8f5e9; color: #2e7d32; }
.spell-btn--share { background: #e3f2fd; color: #1565c0; }
.spell-btn--del   { background: #fbe9e7; color: #c62828; }

/* 咒語文字（可雙擊編輯） */
.spell-text {
    font-size: 0.84rem;
    color: #333;
    line-height: 1.55;
    word-break: break-all;
    cursor: text;
    padding: 4px 2px;
    border-radius: 4px;
    transition: background .15s;
}
.spell-text:hover { background: #f5f5f5; }

/* U34: 原地重命名 textarea */
.rename-ta {
    width: 100%;
    min-height: 64px;
    padding: 7px;
    border: 1.5px solid #667eea;
    border-radius: 7px;
    font-size: 0.83rem;
    font-family: inherit;
    line-height: 1.55;
    resize: vertical;
    box-sizing: border-box;
    outline: none;
}

.spell-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 6px;
    gap: 8px;
    flex-wrap: wrap;
}

.spell-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex: 1;
}

.spell-tag {
    display: inline-block;
    padding: 2px 8px;
    background: #e8eaf6;
    color: #3949ab;
    border-radius: 10px;
    font-size: 0.71rem;
    font-weight: 600;
}

.spell-tag-add {
    padding: 1px 7px;
    background: #f5f5f5;
    color: #999;
    border: 1px dashed #ccc;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.71rem;
}
.spell-tag-add:hover { background: #e8eaf6; color: #667eea; }

.spell-meta {
    font-size: 0.69rem;
    color: #bbb;
    white-space: nowrap;
    flex-shrink: 0;
    padding-top: 2px;
}

/* ── U24: 標籤選擇器 ──────────────────────────────────────── */
.tag-picker-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 10px;
    background: #f8f9ff;
    border: 1.5px solid #c5cae9;
    border-radius: 8px;
    margin-top: 6px;
}

.tag-picker-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    background: white;
    border: 1.5px solid #e0e0e0;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.74rem;
    color: #666;
    transition: all .15s;
    user-select: none;
}
.tag-picker-chip:hover { border-color: #9fa8da; color: #3949ab; }
.tag-picker-chip--on {
    background: #e8eaf6;
    border-color: #9fa8da;
    color: #3949ab;
    font-weight: 700;
}

.tag-picker-input {
    border: 1.5px dashed #c5cae9;
    border-radius: 12px;
    padding: 3px 8px;
    font-size: 0.74rem;
    width: 80px;
    outline: none;
    background: white;
}

/* ── 斷捨離清理面板 ────────────────────────────────────────── */
.cleanup-box {
    background: #fff8e1;
    border: 1.5px solid #ffc107;
    border-radius: 10px;
    padding: 14px 16px;
}
.cleanup-title {
    font-weight: 700;
    color: #e65100;
    margin-bottom: 10px;
    font-size: 0.9rem;
}
.cleanup-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 2px;
}
.cleanup-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    cursor: pointer;
    padding: 7px 9px;
    background: white;
    border-radius: 8px;
    border: 1px solid #ffe082;
    font-size: 0.82rem;
}
.cleanup-item-info { flex: 1; min-width: 0; }
.cleanup-item-text { color: #333; word-break: break-all; line-height: 1.4; }
.cleanup-item-meta { font-size: 0.72rem; color: #aaa; margin-top: 2px; }
.cleanup-empty {
    text-align: center;
    padding: 14px;
    color: #4caf50;
    font-size: 0.88rem;
    background: #e8f5e9;
    border-radius: 8px;
}

/* ── NPC 卡片 ─────────────────────────────────────────────── */
.npc-card {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1.5px solid;
}
.npc-card--pre {
    background: linear-gradient(135deg, #f0f3ff 0%, #f7f0ff 100%);
    border-color: #c5cae9;
}
.npc-card--post {
    background: linear-gradient(135deg, #e8f5e9 0%, #f0fff4 100%);
    border-color: #a5d6a7;
}

.npc-avatar {
    font-size: 1.8rem;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 2px;
}

.npc-bubble { flex: 1; min-width: 0; }

.npc-name {
    font-size: 0.72rem;
    font-weight: 800;
    color: #667eea;
    letter-spacing: .04em;
    margin-bottom: 3px;
}
.npc-card--post .npc-name { color: #2e7d32; }

.npc-text {
    font-size: 0.84rem;
    color: #444;
    line-height: 1.55;
    margin-bottom: 2px;
}

.npc-suggestion {
    font-size: 0.82rem;
    color: #3a4a6b;
    line-height: 1.55;
    padding: 5px 8px;
    background: rgba(255,255,255,0.7);
    border-radius: 7px;
    margin-top: 5px;
    border-left: 3px solid #9fa8da;
}

.npc-improved-box {
    margin-top: 10px;
    background: rgba(255,255,255,0.85);
    border-radius: 8px;
    padding: 10px 12px;
    border-left: 3px solid #667eea;
}

/* ═══════════════════════════════════════════════════════════════
   🌙 深色模式
   ═══════════════════════════════════════════════════════════════ */
body.dark-mode {
    --forest-pale: #1a1a2e;
    --peach-pale: #16213e;
    --forest-deep: #e0e0e0;
    color: #d4d4d8;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
}
body.dark-mode .navbar {
    background: linear-gradient(135deg, #0f172a, #1e293b);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
body.dark-mode .nav-btn,
body.dark-mode .mode-btn {
    color: #cbd5e1;
}
body.dark-mode .nav-btn:hover,
body.dark-mode .mode-btn:hover {
    background: rgba(255,255,255,0.12);
}
body.dark-mode #generatorPanel,
body.dark-mode #writingPanel {
    color: #d4d4d8;
}
body.dark-mode textarea,
body.dark-mode input[type="text"],
body.dark-mode input[type="url"],
body.dark-mode select {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #334155;
}
body.dark-mode textarea:focus,
body.dark-mode input:focus,
body.dark-mode select:focus {
    border-color: #667eea;
}
/* 題目卡片 */
body.dark-mode [style*="background:white"],
body.dark-mode [style*="background: white"] {
    background: #1e293b !important;
    border-color: #334155 !important;
}
/* Modal */
body.dark-mode .modal-content {
    background: #1e293b;
    color: #d4d4d8;
    border-color: #334155;
}
body.dark-mode .modal-header {
    background: #0f172a;
    border-color: #334155;
}
/* 分析面板 */
body.dark-mode .question-item {
    background: #1e293b;
    border-color: #334155;
    color: #d4d4d8;
}
body.dark-mode .question-item:hover {
    background: #263048;
}
body.dark-mode .question-item.active {
    background: #1e3a5f;
    border-color: #3b82f6;
}
body.dark-mode .detail-panel {
    background: #1e293b;
    border-color: #334155;
}
body.dark-mode .ai-panel {
    background: #1e293b;
    border-color: #334155;
}
/* Tab 切換列 */
body.dark-mode [style*="background:white"][style*="border-bottom"] {
    background: #0f172a !important;
}
/* 選項/標籤 */
body.dark-mode .option-bar {
    background: #263048;
}
/* 圖表面板 */
body.dark-mode .chart-panel {
    background: #1e293b;
}
/* 滾動條 */
body.dark-mode ::-webkit-scrollbar-track {
    background: #1e293b;
}
body.dark-mode ::-webkit-scrollbar-thumb {
    background: #475569;
}
body.dark-mode ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

