/* ===========================
   CSS 變數與基礎設定
   =========================== */
:root {
    /* 主色調 */
    --primary: #f43f5e;
    /* Rose for Overfitting context */
    --primary-light: #fb7185;
    --primary-dark: #e11d48;

    /* 狀態顏色 */
    --status-underfit: #f59e0b;
    /* Amber */
    --status-optimal: #22c55e;
    /* Green */
    --status-overfit: #f43f5e;
    /* Rose */

    /* 背景與表面 */
    --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;

    /* 其他 */
    --radius: 16px;
    --radius-sm: 8px;
    --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --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: 1400px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===========================
   頁首
   =========================== */
.header {
    text-align: center;
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--glass);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fb923c, #ec4899);
    /* Orange to Pink */
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* ===========================
   主要內容區
   =========================== */
.main-content {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 2rem;
}

/* ===========================
   視覺化區域
   =========================== */
.visualization-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.canvas-container {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    height: 100%;
    min-height: 500px;
}

canvas {
    width: 100%;
    height: 100%;
}

/* ===========================
   互動概念區 (上方)
   =========================== */
.concept-area {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 0;
}

.concept-card {
    background: var(--glass);
    padding: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.concept-card:hover {
    background: var(--surface-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.concept-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.concept-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.concept-card.active {
    background: var(--surface-light);
    border-color: var(--primary-light);
}

/* ===========================
   右側控制面板區域
   =========================== */
.control-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

.card h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* 滑桿樣式 */
.slider-container {
    margin-bottom: 1.5rem;
}

.slider-container label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.value-display {
    color: var(--primary-light);
    font-family: monospace;
    font-weight: bold;
    font-size: 1.1rem;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--surface-light);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 0 10px rgba(244, 63, 94, 0.4);
    transition: var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.btn-primary {
    width: 100%;
    padding: 0.75rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(244, 63, 94, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(244, 63, 94, 0.5);
}

/* 誤差指標 */
.metrics-box {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.metric-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
}

.metric-item span:first-child {
    color: var(--text-secondary);
}

/* 開關樣式 */
.toggle-container {
    margin-bottom: 1.5rem;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--surface-light);
    border-radius: 12px;
    transition: var(--transition);
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-label input:checked+.toggle-slider {
    background: var(--status-optimal);
}

.toggle-label input:checked+.toggle-slider::after {
    transform: translateX(20px);
}

/* 過擬合警示區 */
.overfit-warning {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    background: rgba(244, 63, 94, 0.15);
    border: 1px solid rgba(244, 63, 94, 0.4);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin-top: 1rem;
    animation: pulse-warning 1.5s ease-in-out infinite;
}

@keyframes pulse-warning {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.overfit-warning .warning-icon {
    font-size: 1.5rem;
}

.overfit-warning .warning-text strong {
    color: var(--status-overfit);
    display: block;
    margin-bottom: 0.25rem;
}

.overfit-warning .warning-text p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}

/* 欠擬合警示區 */
.underfit-warning {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.4);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    margin-top: 1rem;
}

.underfit-warning .warning-icon {
    font-size: 1.5rem;
}

.underfit-warning .warning-text strong {
    color: var(--status-underfit);
    display: block;
    margin-bottom: 0.25rem;
}

.underfit-warning .warning-text p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0;
}

/* ===========================
   下方教學說明區域
   =========================== */
.info-section {
    margin-top: 2rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.25rem;
}

/* 步驟列表 */
.steps-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.steps-list li {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 50%;
    flex-shrink: 0;
}

/* 公式卡片 */
.formula {
    background: var(--glass);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: var(--primary-light);
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
}

.formula-desc {
    text-align: center;
    font-size: 0.8rem !important;
    color: var(--text-muted) !important;
}

/* 提示列表 */
.tips-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.tips-list li {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding-left: 1rem;
    position: relative;
}

.tips-list li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--primary-light);
}

@media (max-width: 1200px) {
    .info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .info-grid {
        grid-template-columns: 1fr;
    }
}

/* ===========================
   頁尾
   =========================== */
.footer {
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-top: 1px solid var(--glass-border);
}

.back-home {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.6rem 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    text-decoration: none;
    border-radius: 50px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: var(--transition);
    box-shadow: 0 4px 15px rgba(244, 63, 94, 0.3);
}

.back-home:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 25px rgba(244, 63, 94, 0.5);
}

/* 響應式 */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .control-section {
        display: grid;
        grid-template-columns: 1fr;
    }

    .concept-area {
        margin-bottom: 2rem;
    }
}

@media (max-width: 600px) {
    .concept-area {
        grid-template-columns: 1fr;
    }
}