/* ===========================
   CSS 變數與基礎設定 (保持一致性)
   =========================== */
:root {
    /* 主色調 */
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-dark: #4f46e5;

    /* 功能色 */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* K-Means 群集顏色 (最多 6 群) */
    --cluster-1: #f43f5e;
    /* Red */
    --cluster-2: #06b6d4;
    /* Cyan */
    --cluster-3: #10b981;
    /* Green */
    --cluster-4: #f59e0b;
    /* Amber */
    --cluster-5: #8b5cf6;
    /* Violet */
    --cluster-6: #ec4899;
    /* Pink */

    /* 區域顏色 (透明度版) */
    --region-1: rgba(244, 63, 94, 0.15);
    --region-2: rgba(6, 182, 212, 0.15);
    --region-3: rgba(16, 185, 129, 0.15);
    --region-4: rgba(245, 158, 11, 0.15);
    --region-5: rgba(139, 92, 246, 0.15);
    --region-6: rgba(236, 72, 153, 0.15);

    /* 背景與表面 */
    --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;
    /* K-Means 專屬漸層 */
    background: linear-gradient(135deg, #f59e0b, #ec4899);
    -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: 1rem;
}

.canvas-container {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

#kmeansCanvas {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 350px;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.canvas-hint {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--glass);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    pointer-events: none;
    white-space: nowrap;
}

/* 狀態顯示條 */
.status-bar {
    display: flex;
    justify-content: space-between;
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.status-value {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.status-highlight {
    color: var(--primary-light);
}

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

/* 參數設定 */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.slider-container {
    width: 100%;
}

.slider-container label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.label-text {
    font-weight: 500;
    color: var(--text-secondary);
}

.k-value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 50%;
}

/* 按鈕群組 */
.control-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.button-row {
    display: flex;
    gap: 0.75rem;
}

button {
    flex: 1;
    padding: 0.75rem 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-success {
    background: linear-gradient(135deg, var(--success), #059669);
    color: white;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

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

.step-item {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: var(--transition);
    border: 1px solid transparent;
}

.step-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    color: var(--text-primary);
    transform: translateX(5px);
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--surface-light);
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 50%;
    flex-shrink: 0;
    transition: var(--transition);
}

.step-item.active .step-num {
    background: var(--primary);
    color: white;
}

/* ===========================
   卡片通用樣式
   =========================== */
.card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
}

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

.card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

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

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

.tips-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

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

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

/* ===========================
   頁尾
   =========================== */
.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(99, 102, 241, 0.3);
}

.back-home:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

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

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border-radius: 50%;
    cursor: grab;
    transition: var(--transition);
}

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

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .button-row {
        flex-direction: column;
    }
}