/* ===== 基礎重置與變數 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --secondary-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --bg-gradient: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    --card-bg: rgba(255, 255, 255, 0.95);
    --shadow-soft: 0 8px 32px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.15);
    --border-radius: 20px;
    --border-radius-sm: 12px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Noto Sans TC', system-ui, -apple-system, sans-serif;
}

body {
    background: var(--bg-gradient);
    background-attachment: fixed;
}

/* ===== 主容器 ===== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 16px;
    gap: 16px;
}

/* ===== 頂部標題 ===== */
.header {
    background: var(--primary-gradient);
    padding: 16px 32px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-soft);
    text-align: center;
}

.header h1 {
    color: white;
    font-size: 2rem;
    font-weight: 900;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    letter-spacing: 4px;
    animation: bounceIn 0.8s ease-out;
}

@keyframes bounceIn {
    0% { transform: scale(0.5); opacity: 0; }
    60% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* ===== 主要內容區 ===== */
.main-content {
    display: flex;
    flex: 1;
    gap: 16px;
    min-height: 0;
}

/* ===== 工具列 ===== */
.toolbar {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-soft);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 180px;
    overflow-y: auto;
}

.tool-section h3 {
    font-size: 0.9rem;
    color: #667eea;
    margin-bottom: 12px;
    font-weight: 700;
}

/* 工具按鈕 */
.tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 2px solid transparent;
    border-radius: var(--border-radius-sm);
    background: linear-gradient(145deg, #f0f0f0, #ffffff);
    cursor: pointer;
    transition: var(--transition);
    font-size: 1rem;
    font-weight: 600;
    color: #555;
}

.tool-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.tool-btn.active {
    background: var(--primary-gradient);
    color: white;
    border-color: #667eea;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
}

.tool-icon {
    font-size: 1.3rem;
}

/* 筆刷大小 */
.brush-sizes {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.size-btn {
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: var(--border-radius-sm);
    background: white;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 600;
    color: #666;
}

.size-btn:hover {
    border-color: #667eea;
    color: #667eea;
}

.size-btn.active {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
}

/* 顏色調色盤 */
.color-palette {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.color-btn {
    width: 100%;
    aspect-ratio: 1;
    border: 3px solid white;
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.color-btn:hover {
    transform: scale(1.15);
}

.color-btn.active {
    border-color: #2C3E50;
    transform: scale(1.2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* 功能按鈕 */
.actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-btn {
    padding: 12px 16px;
    border: none;
    border-radius: var(--border-radius-sm);
    background: linear-gradient(145deg, #f0f0f0, #ffffff);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.95rem;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    gap: 8px;
}

.action-btn:hover {
    background: var(--secondary-gradient);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(245, 87, 108, 0.4);
}

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

/* ===== 畫布區域 ===== */
.canvas-wrapper {
    flex: 1;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

#drawingCanvas {
    background: #FFFEF7;
    cursor: crosshair;
    touch-action: none;
    border-radius: 8px;
}

/* ===== 圖案選擇面板 ===== */
.pattern-panel {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-soft);
    padding: 20px;
    width: 140px;
    overflow-y: auto;
}

.pattern-panel h3 {
    font-size: 0.9rem;
    color: #667eea;
    margin-bottom: 16px;
    font-weight: 700;
    text-align: center;
}

.pattern-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pattern-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 10px;
    border: 2px solid transparent;
    border-radius: var(--border-radius-sm);
    background: linear-gradient(145deg, #f5f5f5, #ffffff);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
}

.pattern-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.pattern-btn.active {
    background: var(--secondary-gradient);
    color: white;
    border-color: #f5576c;
    box-shadow: 0 4px 16px rgba(245, 87, 108, 0.4);
}

.pattern-icon {
    font-size: 1.8rem;
}

/* ===== 響應式設計 ===== */
@media (max-width: 900px) {
    .app-container {
        padding: 10px;
        gap: 10px;
    }

    .header {
        padding: 12px 20px;
    }

    .header h1 {
        font-size: 1.5rem;
        letter-spacing: 2px;
    }

    .toolbar {
        width: 140px;
        padding: 14px;
        gap: 14px;
    }

    .pattern-panel {
        width: 100px;
        padding: 14px;
    }

    .tool-btn {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .tool-label {
        display: none;
    }

    .tool-icon {
        font-size: 1.5rem;
    }

    .pattern-btn span:not(.pattern-icon) {
        font-size: 0.75rem;
    }
}

@media (max-width: 600px) {
    .main-content {
        flex-direction: column;
    }

    .toolbar {
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        order: 1;
    }

    .tool-section {
        flex: 1;
        min-width: 45%;
    }

    .canvas-wrapper {
        order: 0;
        flex: none;
        height: 50vh;
    }

    .pattern-panel {
        width: 100%;
        order: 2;
    }

    .pattern-list {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .pattern-btn {
        padding: 10px 14px;
    }
}

/* ===== 觸控優化 ===== */
@media (hover: none) and (pointer: coarse) {
    .tool-btn,
    .size-btn,
    .action-btn,
    .pattern-btn {
        min-height: 48px;
    }

    .color-btn {
        min-width: 36px;
        min-height: 36px;
    }
}

/* ===== 載入動畫 ===== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.toolbar,
.canvas-wrapper,
.pattern-panel {
    animation: fadeInUp 0.6s ease-out backwards;
}

.toolbar { animation-delay: 0.1s; }
.canvas-wrapper { animation-delay: 0.2s; }
.pattern-panel { animation-delay: 0.3s; }
