/* ==========================================================================
   倫敦塔益智盒 3D 模擬器 (Tower of London 3D Simulator) - 主樣式表
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Fira+Code:wght@400;600&display=swap');

:root {
    --bg-dark: #090d16;
    --bg-card: rgba(15, 23, 42, 0.85);
    --bg-card-hover: rgba(30, 41, 59, 0.9);
    --border-color: rgba(56, 189, 248, 0.2);
    --border-highlight: #38bdf8;

    --primary: #0284c7;
    --primary-hover: #0369a1;
    --primary-glow: rgba(56, 189, 248, 0.35);

    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-purple: #8b5cf6;

    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --text-dim: #64748b;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-subtle: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-glow: 0 0 20px rgba(56, 189, 248, 0.25);
    --glass-bg: rgba(15, 23, 42, 0.75);
    --glass-backdrop: blur(12px);
}

/* 基礎設定 */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 19px; /* Word 14號字 (14pt ≈ 18.67px)，全面清晰放大 */
    min-height: 100vh;
    line-height: 1.6;
    background-image:
        radial-gradient(circle at 15% 15%, rgba(56, 189, 248, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(139, 92, 246, 0.08) 0%, transparent 40%);
    background-attachment: fixed;
}

/* 滾動條樣式 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
}

::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

/* 頁首 Header */
.app-header {
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: var(--glass-backdrop);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #38bdf8, #8b5cf6);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    color: #fff;
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.app-title {
    font-size: 1.65rem;
    /* 放大從 1.35rem -> 1.65rem */
    font-weight: 800;
    background: linear-gradient(135deg, #38bdf8 0%, #a7f3d0 50%, #8b5cf6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.app-subtitle {
    font-size: 0.95rem;
    /* 放大從 0.8rem -> 0.95rem */
    color: var(--text-muted);
}

/* 模式選單 Tabs */
.mode-tabs {
    display: flex;
    background: rgba(30, 41, 59, 0.7);
    padding: 4px;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.05);
    gap: 4px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.7rem 1.3rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1.05rem;
    /* 放大從 0.85rem -> 1.05rem */
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 48px;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary), #0369a1);
    color: #ffffff;
    box-shadow: var(--shadow-glow);
}

/* 主佈局 Layout (雙欄標準架構：左為主視窗 Card，右為側邊資訊與操作 Panel) */
.main-container {
    max-width: 1720px;
    margin: 1.25rem auto;
    padding: 0 1.25rem;
    display: grid;
    grid-template-columns: 1fr 480px; /* 加寬側邊欄以完美適配 Word 14號大字體 */
    gap: 1.5rem;
    align-items: start;
    transition: all 0.3s ease;
}

/* 側邊欄通用容器 */
.sidebar-panel {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
}

.sidebar-panel.hidden,
.viewport-card.hidden,
.viewport-step3-container.hidden {
    display: none !important;
}

.viewport-step3-container {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    width: 100%;
}

/* 響應式：小螢幕轉單欄 */
@media (max-width: 1200px) {
    .main-container {
        grid-template-columns: 1fr;
    }
}

/* 3D 視窗 Card */
.viewport-card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-backdrop);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-subtle);
    display: flex;
    flex-direction: column;
}

#canvas-3d-wrapper {
    width: 100%;
    height: 540px;
    position: relative;
    cursor: grab;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    overflow: hidden;
}

#canvas-3d-wrapper:active {
    cursor: grabbing;
}

/* Three.js 產生的 canvas 必須為絕對定位，避免向下擠壓溢出蓋住控制按鈕 */
#canvas-3d-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 1;
    display: block;
}

/* Zoom 縮放按鈕列 (固定於 3D 視窗右下角) */
.zoom-controls {
    position: absolute;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 35;
}

.btn-zoom {
    width: 36px;
    height: 36px;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.btn-zoom:hover {
    background: rgba(56, 189, 248, 0.6);
    border-color: #38bdf8;
    transform: scale(1.08);
}

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


.section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--border-highlight);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.canvas-2d {
    width: 100%;
    max-width: 320px;
    height: 260px;
    background: #020617;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Overlay Elements on 3D Viewport */
.viewport-overlay {
    position: absolute;
    top: 1rem;
    left: 1rem;
    pointer-events: none;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.overlay-badge {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(56, 189, 248, 0.3);
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    /* 放大從 0.8rem -> 0.95rem */
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    backdrop-filter: blur(8px);
}

.overlay-badge .badge-val {
    color: #facc15;
    font-family: 'Fira Code', monospace;
    font-weight: 700;
}

/* 控制列 Action Bar Below Viewport (z-index 提高確保絕對可點擊) */
.viewport-controls {
    background: rgba(15, 23, 42, 0.95);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    position: relative;
    z-index: 50;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.btn {
    background: #1e293b;
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.65rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 1.05rem; /* 放大至 20px (Word 14pt+) */
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 48px;
}

.btn:hover {
    background: #334155;
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #0369a1);
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0284c7, #075985);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.6);
}

.btn-accent {
    background: linear-gradient(135deg, #059669, #047857);
    border-color: transparent;
}

.btn-accent:hover {
    background: linear-gradient(135deg, #10b981, #059669);
}

.btn-amber {
    background: linear-gradient(135deg, #d97706, #b45309);
    border-color: transparent;
}

.btn-amber:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

/* 右側邊欄 Control & Info Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-backdrop);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    box-shadow: var(--shadow-subtle);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.card-title {
    font-size: 1.35rem; /* 放大至 25.6px */
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* 參數滑桿 Parameter Controls */
.control-group {
    margin-bottom: 1.25rem;
}

.control-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.05rem; /* 20px */
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.control-value {
    color: var(--border-highlight);
    font-family: 'Fira Code', monospace;
    font-weight: 700;
    font-size: 1.25rem; /* 23.8px */
}

.slider-input {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #1e293b;
    outline: none;
    accent-color: var(--border-highlight);
    cursor: pointer;
}

.slider-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.slider-meta {
    display: flex;
    justify-content: space-between;
    font-size: 1.0rem; /* 19px (Word 14pt) */
    color: var(--text-dim);
    margin-top: 0.35rem;
}

/* 狀態觀察儀表板 Status Readout */
.status-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.85rem;
}

.status-box {
    background: rgba(2, 6, 23, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    padding: 0.85rem;
    border-radius: var(--radius-sm);
}

.status-box-title {
    font-size: 1.05rem; /* 20px */
    color: var(--text-dim);
    margin-bottom: 0.35rem;
}

.status-box-value {
    font-family: 'Fira Code', monospace;
    font-weight: 700;
    font-size: 1.55rem; /* 29.5px */
    color: #facc15;
}

.status-box-desc {
    font-size: 1.0rem; /* 19px (Word 14pt) */
    color: var(--text-muted);
    margin-top: 0.3rem;
}

/* 研習引導說明 Workshop Steps Accordion / Content */
.workshop-step-badge {
    background: rgba(56, 189, 248, 0.15);
    color: var(--border-highlight);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 1.0rem;
    font-weight: 700;
}

.workshop-content {
    font-size: 1.05rem; /* 20px */
    color: var(--text-muted);
    line-height: 1.6;
}

.math-formula-box {
    background: rgba(2, 6, 23, 0.8);
    border-left: 3px solid var(--border-highlight);
    padding: 0.85rem 1.1rem;
    margin: 0.85rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    overflow-x: auto;
}

/* Notice Alerts */
.alert-box {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.35);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    font-size: 1.05rem; /* 20px */
    color: #fef08a;
    margin-top: 0.85rem;
}

/* 3D 浮動標籤 Floating Math Labels */
.math-label-3d {
    position: absolute;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border-highlight);
    color: #ffffff;
    padding: 4px 8px;
    border-radius: 6px;
    font-family: 'Fira Code', monospace;
    font-size: 12px;
    font-weight: 600;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s ease;
    z-index: 20;
}

.math-label-3d.hidden {
    opacity: 0;
}

.math-label-3d span {
    color: #facc15;
}

/* 手動牽引提示 Traversal Toast */
.toast-msg {
    position: absolute;
    bottom: 4rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid var(--border-highlight);
    color: var(--text-main);
    padding: 0.5rem 1.25rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 30;
}

.toast-msg.show {
    opacity: 1;
    transform: translateX(-50%) translateY(-10px);
}

/* ==========================================================================
   第三步：2D 俯視幾何投影模擬器與動態公式推導專屬樣式
   ========================================================================== */

/* 2D 畫布容器 */
.canvas-2d-wrapper {
    width: 100%;
    height: 540px;
    position: relative;
    cursor: grab;
    background: radial-gradient(circle at center, #111827 0%, #030712 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.canvas-2d-wrapper:active {
    cursor: grabbing;
}

#canvas-interactive-2d {
    width: 540px;
    height: 540px;
    max-width: 100%;
    max-height: 540px;
    aspect-ratio: 1 / 1;
    object-fit: contain;
    display: block;
}

/* ==========================================================================
   第一步專屬：堆疊方式闖關提問卡片樣式
   ========================================================================== */
.quiz-question-title {
    font-size: 1.25rem; /* 23.8px */
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.5;
    margin-bottom: 0.85rem;
}

.quiz-options-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.quiz-option-btn {
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    padding: 0.95rem 1.25rem;
    color: var(--text-main);
    font-size: 1.1rem; /* 21px */
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 56px;
}

.quiz-option-btn:hover {
    background: rgba(51, 65, 85, 0.85);
    border-color: var(--border-highlight);
    transform: translateX(4px);
}

.quiz-option-btn.selected-wrong {
    background: rgba(244, 63, 94, 0.2) !important;
    border-color: #f43f5e !important;
    color: #fecdd3 !important;
    animation: shake 0.4s ease;
}

.quiz-option-btn.selected-correct {
    background: rgba(16, 185, 129, 0.25) !important;
    border-color: #10b981 !important;
    color: #a7f3d0 !important;
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

@keyframes quizHighlightPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.8), 0 4px 20px rgba(0, 0, 0, 0.5);
        border-color: rgba(250, 204, 21, 0.9);
        transform: scale(1);
    }
    30% {
        box-shadow: 0 0 30px 6px rgba(250, 204, 21, 0.95), 0 8px 30px rgba(0, 0, 0, 0.6);
        border-color: #facc15;
        transform: scale(1.025);
    }
    60% {
        box-shadow: 0 0 18px 3px rgba(250, 204, 21, 0.6);
        border-color: rgba(250, 204, 21, 0.8);
        transform: scale(1.01);
    }
    100% {
        box-shadow: none;
        transform: scale(1);
    }
}

.quiz-highlight-pulse {
    animation: quizHighlightPulse 1.6s ease-in-out !important;
    border-color: #facc15 !important;
    scroll-margin-top: 80px;
    scroll-margin-bottom: 80px;
}

.quiz-feedback-box {
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    font-size: 1.05rem; /* 20px (Word 14pt+) */
    line-height: 1.6;
    margin-top: 0.75rem;
    display: none;
    transition: all 0.3s ease;
}

.quiz-feedback-box.error {
    display: block;
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.4);
    color: #fecdd3;
}

.quiz-feedback-box.success {
    display: block;
    background: rgba(16, 185, 129, 0.15);
    border: 1px solid rgba(16, 185, 129, 0.4);
    color: #a7f3d0;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
}

.btn-unlock-step2 {
    width: 100%;
    margin-top: 0.85rem;
    padding: 0.85rem 1.35rem;
    font-size: 1.15rem; /* 22px */
    font-weight: 700;
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
    transition: all 0.2s ease;
}

.btn-unlock-step2:hover {
    background: linear-gradient(135deg, #34d399, #10b981);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.6);
}


/* 勾選按鈕 / Switch 元件 */
.checkbox-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.05rem; /* 20px (Word 14pt+) */
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
    user-select: none;
    min-height: 44px;
}

.checkbox-toggle-label:hover {
    border-color: var(--border-highlight);
    color: var(--text-main);
    background: #334155;
    transform: translateY(-1px);
}

.checkbox-toggle-label input[type="checkbox"] {
    accent-color: #f59e0b;
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* 動態數學公式推導清單與卡片 */
.formula-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.formula-item {
    background: rgba(2, 6, 23, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 0.75rem 0.9rem;
    transition: all 0.2s ease;
}

.formula-item:hover {
    background: rgba(2, 6, 23, 0.85);
    border-color: rgba(56, 189, 248, 0.25);
    border-left-color: var(--border-highlight);
    transform: translateY(-1px);
}

.formula-item.green-border { border-left-color: #10b981; }
.formula-item.red-border { border-left-color: #ef4444; }
.formula-item.amber-border { border-left-color: #f59e0b; }
.formula-item.purple-border { border-left-color: #a855f7; }

.formula-header {
    font-size: 1.05rem; /* 放大到 20px */
    font-weight: 700;
    color: #f8fafc;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.formula-math-line {
    font-size: 1.05rem; /* 放大到 20px */
    color: #38bdf8;
    overflow-x: auto;
    padding: 0.2rem 0;
    line-height: 1.5;
}

.formula-eval-line {
    font-size: 1.0rem; /* 放大到 19px */
    color: #94a3b8;
    margin-top: 0.25rem;
    overflow-x: auto;
    line-height: 1.5;
}

/* KaTeX 深色模式色彩優化 */
.katex {
    color: #e2e8f0 !important;
    font-size: 1.15em !important;
}

.katex .mord.text {
    color: #94a3b8 !important;
}

.katex .mord.mathnormal {
    color: #38bdf8 !important;
}

.katex .mbin,
.katex .mrel {
    color: #facc15 !important;
}

.katex-html {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 2px 0;
}

/* --------------------------------------------------------------------------
   第二步填空題樣式
   -------------------------------------------------------------------------- */
.quiz-fill-input {
    transition: all 0.25s ease;
}
.quiz-fill-input:focus {
    border-color: #38bdf8 !important;
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.45) !important;
}

/* --------------------------------------------------------------------------
   第三步拖拉方塊 (Drag & Drop) 互動題樣式
   -------------------------------------------------------------------------- */
.drag-chips-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.drag-chip {
    background: rgba(30, 41, 59, 0.9);
    border: 2px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    font-size: 1.05rem; /* 20px */
    font-weight: 600;
    color: #f8fafc;
    cursor: grab;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.drag-chip:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
    background: rgba(51, 65, 85, 0.98);
}

.drag-chip:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.drag-chip.dragging {
    opacity: 0.35;
    border-style: dashed;
}

.drag-chip.placed {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(0.6);
}

.chip-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* 判據等式放置槽區 */
.formula-slots-wrapper {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.75rem;
    background: rgba(15, 23, 42, 0.75);
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px dashed rgba(56, 189, 248, 0.35);
}

.drop-slot {
    flex: 1;
    min-height: 64px;
    background: rgba(2, 6, 23, 0.8);
    border: 2px dashed rgba(255, 255, 255, 0.25);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.75rem;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
}

.drop-slot.drag-over {
    border-color: #38bdf8;
    background: rgba(56, 189, 248, 0.18);
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.4);
}

.drop-slot.filled {
    border-style: solid;
    border-color: rgba(56, 189, 248, 0.8);
    background: rgba(15, 23, 42, 0.98);
    box-shadow: 0 0 12px rgba(56, 189, 248, 0.25);
}

.slot-placeholder {
    font-size: 1.0rem;
    color: var(--text-dim);
    text-align: center;
    pointer-events: none;
}

.slot-filled-card {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    justify-content: space-between;
}

.btn-remove-slot {
    background: rgba(244, 63, 94, 0.25);
    color: #f43f5e;
    border: 1px solid rgba(244, 63, 94, 0.4);
    border-radius: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    line-height: 1;
    transition: all 0.2s;
}

.btn-remove-slot:hover {
    background: #f43f5e;
    color: #fff;
}

.operator-select-container {
    flex-shrink: 0;
}

.operator-select {
    background: rgba(30, 41, 59, 0.95);
    border: 2px solid #38bdf8;
    border-radius: var(--radius-sm);
    color: #facc15;
    font-size: 1.2rem;
    font-weight: 800;
    padding: 0.7rem 0.85rem;
    cursor: pointer;
    outline: none;
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.3);
    transition: all 0.2s ease;
}

.operator-select:hover, .operator-select:focus {
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.6);
    border-color: #7dd3fc;
}

/* 3D 空間子母畫面 (Picture-in-Picture) 懸浮視窗 (可拖曳移動與邊緣縮放) */
.pip-3d-container {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 260px;
    min-width: 190px;
    min-height: 38px;
    max-width: 95%;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(56, 189, 248, 0.45);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.65), 0 0 16px rgba(56, 189, 248, 0.25);
    z-index: 25;
    overflow: hidden;
    user-select: none;
    touch-action: none;
}

.pip-3d-container.dragging {
    opacity: 0.92;
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.85), 0 0 24px rgba(56, 189, 248, 0.5);
    border-color: #38bdf8;
    cursor: grabbing !important;
    transition: none !important;
}

.pip-3d-container.resizing {
    transition: none !important;
    border-color: #38bdf8;
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.85), 0 0 24px rgba(56, 189, 248, 0.5);
}

.pip-3d-container.collapsed {
    height: 38px !important;
}

.pip-3d-container.collapsed .pip-resize-handle,
.pip-3d-container.collapsed .pip-canvas-wrapper,
.pip-3d-container.collapsed .pip-footer {
    display: none !important;
}

.pip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 10px;
    background: rgba(30, 41, 59, 0.92);
    border-bottom: 1px solid rgba(56, 189, 248, 0.25);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.pip-header:active {
    cursor: grabbing;
}

.pip-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: #38bdf8;
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.pip-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    animation: pulseGlow 2s infinite ease-in-out;
}

@keyframes pulseGlow {
    0%, 100% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.25); }
}

.pip-btn-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-pip-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

.btn-pip-icon:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.1);
}

.btn-pip-icon:active {
    transform: scale(0.95);
}

.pip-canvas-wrapper {
    width: 100%;
    height: 160px;
    min-height: 100px;
    position: relative;
    cursor: grab;
    background: radial-gradient(circle at center, #1e293b 0%, #0b0f19 100%);
    touch-action: none;
}

.pip-canvas-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    display: block;
}

.pip-canvas-wrapper:active {
    cursor: grabbing;
}

.pip-footer {
    padding: 4px 8px;
    font-size: 0.78rem;
    color: var(--text-dim);
    text-align: center;
    background: rgba(15, 23, 42, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    pointer-events: none;
}

/* 右下角拉曳自由縮放手柄 */
.pip-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 24px;
    height: 24px;
    cursor: nwse-resize;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 3px;
    z-index: 35;
    touch-action: none;
    border-bottom-right-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.pip-resize-handle:hover {
    background: rgba(56, 189, 248, 0.25);
    transform: scale(1.15);
}

.pip-resize-handle:active {
    background: rgba(56, 189, 248, 0.4);
}

/* 幾何全攻略總結卡樣式 - 嚴格字級標準 (Word 18號置中、16號、14號) */
.recap-main-title {
    font-size: 24px !important; /* Word 18pt = 24px */
    text-align: center !important; /* 大標題嚴格置中 */
    font-weight: 800 !important;
    width: 100%;
    letter-spacing: -0.01em;
}

.recap-step-title {
    font-size: 21.5px !important; /* Word 16pt = 21.33px -> 21.5px */
    font-weight: 700 !important;
    letter-spacing: -0.01em;
}

.recap-step-content {
    font-size: 19px !important; /* Word 14pt = 18.67px -> 19px */
    line-height: 1.8 !important;
}

.recap-math-inline {
    display: inline-block;
    vertical-align: middle;
    padding: 0 4px;
}

.recap-step-item {
    transition: all 0.25s ease;
}

.recap-step-item:hover {
    transform: translateX(4px);
    background: rgba(30, 41, 59, 0.85) !important;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

/* 側邊欄 hover 聯動卡片反饋 */
.status-box {
    transition: all 0.2s ease;
}

.status-box:hover {
    border-color: rgba(56, 189, 248, 0.5);
    background: rgba(30, 41, 59, 0.85);
    box-shadow: 0 0 14px rgba(56, 189, 248, 0.2);
}

.formula-item {
    transition: all 0.2s ease;
}

.formula-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* ==========================================================================
   行動平板觸控手勢防誤觸鎖定 (Tablet/iPad Gesture Lock)
   在 2D 與 3D canvas 上嚴格綁定 touch-action: none 與防止頁面縮放誤觸
   ========================================================================== */
#canvas-3d-wrapper,
#canvas-3d-wrapper canvas,
.canvas-2d-wrapper,
#canvas-interactive-2d,
.pip-canvas-wrapper,
.pip-canvas-wrapper canvas,
.drag-chips-container,
.drag-chip,
.formula-slots-wrapper,
.drop-slot,
.btn,
.btn-zoom,
.btn-pip-toggle,
.tab-btn {
    touch-action: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
    overscroll-behavior: contain !important;
    -webkit-user-drag: none;
}

/* ==========================================================================
   手機與窄螢幕專屬響應式佈局 (Mobile Responsive Layout <= 768px)
   徹底解決手機上 3D 模擬小視窗遮擋 2D 畫布問題
   ========================================================================== */
@media (max-width: 768px) {
    /* 容器邊距收斂，預防內容溢出並保留適當呼吸空間 */
    .main-container {
        padding: 0 0.65rem !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
        margin: 0.75rem auto !important;
        gap: 1rem !important;
    }

    .card {
        padding: 1rem 0.75rem !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    .sidebar-panel,
    .viewport-step3-container,
    .viewport-card {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* 頁首標題與選單調整 */
    .app-header {
        padding: 0.75rem 0.75rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .header-container {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
    }

    .title-group {
        align-items: center;
    }

    .app-title {
        font-size: 1.3rem;
    }

    .mode-tabs {
        width: 100%;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 4px;
        padding: 4px;
        box-sizing: border-box;
    }

    .tab-btn {
        padding: 0.6rem 0.25rem;
        font-size: 0.88rem;
        justify-content: center;
        text-align: center;
        min-height: 52px;
        line-height: 1.3;
        min-width: 0;
    }

    /* 狀態觀察儀表板 (動態距離即時監控) 嚴格防溢出與自適應 */
    .status-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 0.5rem !important;
        width: 100% !important;
        min-width: 0 !important;
    }

    .status-box {
        min-width: 0 !important;
        padding: 0.65rem 0.55rem !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    .status-box-title {
        font-size: 0.85rem !important;
        line-height: 1.3 !important;
        white-space: normal !important;
        word-break: break-word !important;
    }

    .status-box-value {
        font-size: 1.35rem !important;
    }

    .status-box-desc {
        font-size: 0.8rem !important;
        line-height: 1.3 !important;
        word-break: break-word !important;
    }

    /* 數學公式推導列表與 KaTeX 橫向自適應滾動防撐爆 */
    .formula-list {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .formula-item {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        overflow: hidden !important;
        padding: 0.65rem 0.75rem !important;
        box-sizing: border-box !important;
    }

    .formula-header {
        font-size: 0.95rem !important;
        flex-wrap: wrap !important;
        word-break: break-word !important;
    }

    .formula-math-line,
    .formula-eval-line,
    .math-formula-box {
        font-size: 0.9rem !important;
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: nowrap !important;
        -webkit-overflow-scrolling: touch !important;
        display: block !important;
        padding: 0.35rem 0 !important;
        box-sizing: border-box !important;
    }

    .formula-item .katex {
        font-size: 0.88em !important;
        max-width: 100% !important;
    }

    .katex-html {
        max-width: 100% !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* 3D 視窗高度在手機上適度收斂 */
    #canvas-3d-wrapper {
        height: 360px;
    }

    /* 第三步：2D 畫布容器改為直向彈性流，完全解除覆蓋遮擋 */
    .canvas-2d-wrapper {
        height: auto !important;
        min-height: unset !important;
        padding: 0.85rem 0.5rem !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        overflow: visible !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* 浮動標籤改為頂部自適應排版，不再壓在畫布上 */
    .viewport-overlay {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        justify-content: flex-start !important;
        gap: 0.45rem !important;
        margin-bottom: 0.65rem !important;
        pointer-events: auto !important;
        order: -1 !important; /* 排在 2D 畫布本體之上 */
    }

    .overlay-badge {
        font-size: 0.82rem !important;
        padding: 0.35rem 0.6rem !important;
    }

    /* 2D 畫布：正方形自適應置中，無任何元件遮擋 */
    #canvas-interactive-2d {
        width: 100% !important;
        max-width: 380px !important;
        height: auto !important;
        aspect-ratio: 1 / 1 !important;
        margin: 0 auto !important;
        display: block !important;
    }

    /* 3D 子母畫面視窗：在手機上垂直排在 2D 畫布正下方，完全零遮擋 */
    .pip-3d-container {
        position: relative !important;
        top: auto !important;
        right: auto !important;
        left: auto !important;
        bottom: auto !important;
        width: 100% !important;
        max-width: 380px !important;
        margin: 0.85rem auto 0 auto !important;
        border-radius: var(--radius-sm) !important;
        box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5) !important;
        z-index: 15 !important;
        box-sizing: border-box !important;
    }

    .pip-canvas-wrapper {
        height: 180px !important;
        width: 100% !important;
    }

    /* 控制列按鈕在手機上全寬好點擊 */
    .viewport-controls {
        padding: 0.75rem 0.75rem;
    }

    .viewport-controls .btn-group {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .viewport-controls .btn {
        width: 100%;
        justify-content: center;
    }

    .checkbox-toggle-label {
        width: 100%;
        justify-content: center;
    }

    /* 第三步拖拉題在手機上自適應 */
    .drag-chips-container {
        grid-template-columns: 1fr !important;
    }

    .formula-slots-wrapper {
        flex-direction: column !important;
        gap: 0.65rem !important;
    }

    .operator-select-container {
        width: 100%;
        display: flex;
        justify-content: center;
    }

    .operator-select {
        width: 100%;
        text-align: center;
        text-align-last: center;
    }
}

/* 超窄螢幕手機 (<= 380px) 特化微調 */
@media (max-width: 380px) {
    .status-grid {
        grid-template-columns: 1fr !important;
    }
}

/* 列印樣式優化 */
@media print {
    body {
        background: #fff !important;
        color: #000 !important;
    }

    .app-header, .mode-tabs, .viewport-controls, .btn-group, #card-quiz-step1, #card-quiz-step2, #card-quiz-step3 {
        display: none !important;
    }

    #card-recap-summary {
        display: block !important;
        background: #fff !important;
        color: #000 !important;
        border: 2px solid #000 !important;
        box-shadow: none !important;
    }

    .recap-step-item {
        background: #f8fafc !important;
        color: #000 !important;
        border: 1px solid #cbd5e1 !important;
    }
}