/* ===========================
   CSS 變數與基礎設定
   =========================== */
:root {
    /* 主色調 - 藍紫色系（代表「降維」的科技感） */
    --primary: #818cf8;
    --primary-light: #a5b4fc;
    --primary-dark: #6366f1;

    /* 三種降維方法的代表顏色 */
    --color-pca: #60a5fa;
    /* 藍色 - PCA */
    --color-tsne: #f472b6;
    /* 粉紅色 - t-SNE */
    --color-lda: #a78bfa;
    /* 紫色 - LDA */

    /* 背景與表面 */
    --bg-gradient-start: #0f172a;
    --bg-gradient-end: #1e293b;
    --surface: rgba(30, 41, 59, 0.8);
    --surface-light: rgba(51, 65, 85, 0.6);
    --glass: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);

    /* 文字顏色 */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* 狀態顏色 */
    --success: #22c55e;
    --warning: #fbbf24;
    --error: #ef4444;

    /* 圓角與動畫 */
    --radius: 16px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start), var(--bg-gradient-end));
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem;
}

/* ===========================
   頁首
   =========================== */
.header {
    text-align: center;
    margin-bottom: 2.5rem;
    padding: 1.5rem;
    background: var(--glass);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
}

.header h1 {
    font-size: 1.9rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--color-tsne));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.3rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ===========================
   步驟區塊
   =========================== */
.step-section {
    margin-bottom: 2.5rem;
}

.step-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.step-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    font-weight: 700;
    font-size: 0.95rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.step-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

/* ===========================
   第一步：問題展示區
   =========================== */
.problem-showcase {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.problem-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.problem-card h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--primary-light);
}

.problem-card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.5rem;
}

.problem-visual {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dim-demo {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.dim-before,
.dim-after {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.dim-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
}

.dim-features {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: center;
    max-width: 200px;
}

.feat-badge {
    padding: 0.3rem 0.65rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(96, 165, 250, 0.2);
    border: 1px solid rgba(96, 165, 250, 0.4);
    color: var(--color-pca);
}

.feat-badge.feat-muted {
    background: rgba(100, 116, 139, 0.2);
    border-color: rgba(100, 116, 139, 0.3);
    color: var(--text-muted);
}

.feat-badge.feat-pca {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.5);
    color: var(--primary-light);
    font-size: 0.8rem;
    padding: 0.35rem 0.8rem;
}

.dim-arrow {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.arrow-icon {
    font-size: 1.5rem;
    color: var(--primary-light);
}

/* 使用場景卡片 */
.use-case-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.use-case-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 1.1rem;
    text-align: center;
}

.use-case-icon {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.use-case-card h4 {
    font-size: 0.9rem;
    margin-bottom: 0.4rem;
    color: var(--primary-light);
}

.use-case-card p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ===========================
   第二步：資料選擇區
   =========================== */
.data-area {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.data-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.func-select {
    padding: 0.6rem 1rem;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    font-family: inherit;
    flex: 1;
    min-width: 200px;
    transition: var(--transition);
}

.func-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.2);
}

.button-group {
    display: flex;
    gap: 0.75rem;
}

.btn-primary {
    padding: 0.6rem 1.4rem;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    font-family: inherit;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-reset {
    padding: 0.6rem 1.2rem;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-reset:hover {
    border-color: var(--error);
    color: var(--error);
}

.original-data-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.2rem 1.5rem;
}

.original-data-card h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.placeholder-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 1rem 0;
    text-align: center;
}

/* 資料集資訊 */
.dataset-info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.info-chip {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    text-align: center;
}

.info-chip .chip-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.2rem;
}

.info-chip .chip-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-light);
}

/* ===========================
   第三步：方法區塊
   =========================== */
.method-section {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.method-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
}

/* 各方法主題色 */
.method-header.pca-theme {
    background: rgba(96, 165, 250, 0.08);
    border-bottom: 2px solid var(--color-pca);
}

.method-header.tsne-theme {
    background: rgba(244, 114, 182, 0.08);
    border-bottom: 2px solid var(--color-tsne);
}

.method-header.lda-theme {
    background: rgba(167, 139, 250, 0.08);
    border-bottom: 2px solid var(--color-lda);
}

.method-badge {
    padding: 0.3rem 0.8rem;
    border-radius: 99px;
    font-size: 0.78rem;
    font-weight: 700;
    color: #0f172a;
    flex-shrink: 0;
}

.pca-bg {
    background: var(--color-pca);
}

.tsne-bg {
    background: var(--color-tsne);
}

.lda-bg {
    background: var(--color-lda);
}

.method-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.method-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
}

.method-explain {
    padding: 1.25rem 1.5rem;
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.method-idea {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.idea-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    margin-top: 0.1rem;
}

.method-idea strong {
    display: block;
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.method-idea p {
    font-size: 0.88rem;
    color: var(--text-primary);
    line-height: 1.6;
}

/* 公式 / 範例框 */
.method-example-box {
    background: var(--glass);
    border-left: 3px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 0.9rem;
}

.method-example-box.pca-border {
    border-left-color: var(--color-pca);
}

.method-example-box.tsne-border {
    border-left-color: var(--color-tsne);
}

.method-example-box.lda-border {
    border-left-color: var(--color-lda);
}

.example-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* PCA 公式步驟 */
.pca-formula-visual {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.formula-step {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.step-tag {
    padding: 0.2rem 0.6rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    flex-shrink: 0;
}

.pca-tag {
    background: var(--color-pca);
}

.tsne-tag {
    background: var(--color-tsne);
}

.lda-tag {
    background: var(--color-lda);
}

.formula-text {
    font-size: 0.88rem;
    font-family: 'Courier New', monospace;
    color: var(--text-primary);
}

/* t-SNE 步驟 */
.tsne-steps {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tsne-step {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.85rem;
}

.tsne-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--color-tsne);
    color: #0f172a;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}

/* LDA 比較表格 */
.compare-table {
    width: 100%;
    font-size: 0.82rem;
}

.mini-table {
    border-collapse: collapse;
    width: 100%;
}

.mini-table th,
.mini-table td {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--glass-border);
    text-align: center;
    font-size: 0.82rem;
}

.mini-table th {
    background: var(--glass);
    color: var(--text-secondary);
    font-weight: 700;
}

.mini-table td {
    color: var(--text-secondary);
}

.lda-highlight {
    color: var(--color-lda) !important;
    font-weight: 700;
}

/* 優缺點 */
.method-pros-cons {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.pros,
.cons {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.85rem;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
}

.pros {
    background: rgba(34, 197, 94, 0.08);
    color: #4ade80;
}

.cons {
    background: rgba(251, 191, 36, 0.08);
    color: #fbbf24;
}

/* 方法右側：Canvas */
.method-result {
    padding: 1.25rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.method-result h4 {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.result-canvas {
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--glass-border);
    width: 100%;
    height: auto;
}

.result-info {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ===========================
   第四步：速查表
   =========================== */
.decision-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.decision-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-top: 4px solid;
    border-radius: var(--radius-sm);
    padding: 1.1rem;
}

.decision-card.pca-border {
    border-top-color: var(--color-pca);
}

.decision-card.tsne-border {
    border-top-color: var(--color-tsne);
}

.decision-card.lda-border {
    border-top-color: var(--color-lda);
}

.decision-icon {
    font-size: 1.6rem;
    margin-bottom: 0.4rem;
}

.decision-card h3 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
}

.decision-when {
    font-size: 0.82rem;
    margin-bottom: 0.75rem;
}

.decision-when strong,
.decision-avoid strong {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.82rem;
}

.decision-when ul,
.decision-avoid ul {
    padding-left: 1.1rem;
    color: var(--text-secondary);
}

.decision-when ul li,
.decision-avoid ul li {
    margin-bottom: 0.2rem;
    font-size: 0.8rem;
}

.decision-avoid {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* 流程圖 */
.flowchart-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.flowchart-card h3 {
    font-size: 0.95rem;
    margin-bottom: 1.2rem;
    color: var(--text-secondary);
}

.flowchart {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.fc-node {
    padding: 0.55rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 600;
    text-align: center;
}

.fc-question {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.4);
    color: var(--primary-light);
}

.fc-answer {
    font-size: 0.85rem;
    font-weight: 700;
    color: #0f172a;
}

.pca-answer {
    background: var(--color-pca);
}

.tsne-answer {
    background: var(--color-tsne);
}

.lda-answer {
    background: var(--color-lda);
}

.fc-branches-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    width: 100%;
}

.fc-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
}

.fc-label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: center;
}

.fc-arrow {
    color: var(--text-muted);
    font-size: 1.1rem;
}

.goal-label {
    background: rgba(100, 116, 139, 0.1);
    border: 1px solid var(--glass-border);
    border-radius: 99px;
    padding: 0.25rem 0.75rem;
    font-size: 0.78rem;
    white-space: nowrap;
}

/* 解釋變異量 */
.variance-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}

.variance-card h3 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.variance-note {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}

#varianceCanvas {
    border-radius: var(--radius-sm);
    width: 100%;
    height: auto;
}

/* ===========================
   第五步：注意事項
   =========================== */
.tips-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.tip-card {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 1.1rem 1.3rem;
}

.tip-icon {
    font-size: 1.4rem;
    margin-bottom: 0.4rem;
}

.tip-card h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    color: var(--primary-light);
}

.tip-card p {
    font-size: 0.84rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.tip-card code {
    background: rgba(99, 102, 241, 0.15);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    font-size: 0.82rem;
    color: var(--primary-light);
}

/* ===========================
   頁尾
   =========================== */
.footer {
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
    color: var(--text-muted);
    font-size: 0.88rem;
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: center;
}

.back-home {
    display: inline-block;
    padding: 0.5rem 1.2rem;
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 99px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: var(--transition);
}

.back-home:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
    color: var(--primary-light);
}

/* ===========================
   RWD 響應式設計
   =========================== */
@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .problem-showcase {
        grid-template-columns: 1fr;
    }

    .use-case-grid {
        grid-template-columns: 1fr;
    }

    .method-body {
        grid-template-columns: 1fr;
    }

    .method-explain {
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
    }

    .decision-grid {
        grid-template-columns: 1fr;
    }

    .tips-grid {
        grid-template-columns: 1fr;
    }

    .fc-branches-3 {
        grid-template-columns: 1fr;
    }

    .data-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .dataset-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .dataset-info-grid {
        grid-template-columns: 1fr 1fr;
    }
}