/* ============================================
   画画乐园 - 幼儿画图应用样式
   设计方向：温暖、圆润、充满童趣的玩具感
   ============================================ */

/* === CSS 变量 === */
:root {
    --font-display: 'ZCOOL KuaiLe', 'PingFang SC', cursive;
    --font-body: 'ZCOOL KuaiLe', -apple-system, sans-serif;

    /* 糖果色系 */
    --candy-red: #FF6B6B;
    --candy-orange: #FFA36C;
    --candy-yellow: #FFD93D;
    --candy-green: #6BCB77;
    --candy-blue: #74B9FF;
    --candy-purple: #A29BFE;
    --candy-pink: #FD79A8;
    --candy-mint: #55EFC4;

    /* 暖底色 */
    --bg-cream: #FFF8E7;
    --bg-warm: #FFF3D6;
    --toolbar-bg: #FFFBF0;

    /* 阴影 */
    --shadow-soft: 0 4px 20px rgba(0,0,0,0.08);
    --shadow-bubble: 0 6px 24px rgba(0,0,0,0.12);
    --shadow-inset: inset 0 2px 4px rgba(0,0,0,0.06);
}

/* === 全局重置 === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    font-family: var(--font-body);
    background: var(--bg-cream);
    -webkit-tap-highlight-color: transparent;
}

/* === 场景切换 === */
.scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.scene.active {
    display: flex;
    flex-direction: column;
    opacity: 1;
}

/* ============================================
   首页 - 温暖的玩具盒
   ============================================ */
#home {
    justify-content: center;
    align-items: center;
    background: linear-gradient(170deg, #FFF8E7 0%, #FFECD2 40%, #FCE4EC 100%);
    overflow: hidden;
}

/* 首页背景装饰：柔和的色块 */
.home-bg {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.home-bg::before,
.home-bg::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
}

.home-bg::before {
    width: 50vw;
    height: 50vw;
    background: var(--candy-pink);
    top: -15vw;
    right: -10vw;
}

.home-bg::after {
    width: 45vw;
    height: 45vw;
    background: var(--candy-blue);
    bottom: -10vw;
    left: -8vw;
}

.home-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

/* === 首页标题 === */
.home-title {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.title-text {
    font-family: var(--font-display);
    font-size: clamp(2.5rem, 8vw, 4.5rem);
    color: #FF6B6B;
    text-shadow:
        0 3px 0 #E55A5A,
        0 6px 12px rgba(255,107,107,0.3);
    letter-spacing: 0.15em;
    position: relative;
}

.title-deco {
    font-size: clamp(1.8rem, 5vw, 3rem);
    animation: deco-bounce 2s ease-in-out infinite;
}

.title-deco-left { animation-delay: 0s; }
.title-deco-right { animation-delay: 0.5s; }

@keyframes deco-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.home-subtitle {
    font-family: var(--font-display);
    font-size: clamp(1.2rem, 3.5vw, 1.8rem);
    color: #B08968;
    margin-top: -0.5rem;
    opacity: 0.85;
}

/* === 首页卡片 === */
.home-cards {
    display: flex;
    gap: clamp(1.5rem, 4vw, 3rem);
    margin-top: 1rem;
}

.home-card {
    width: clamp(200px, 35vw, 300px);
    height: clamp(220px, 38vw, 320px);
    border-radius: 36px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.8rem;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
    position: relative;
    overflow: hidden;
}

.home-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 36px;
    border: 4px solid rgba(255,255,255,0.5);
    pointer-events: none;
}

/* 描边填色卡片 - 暖珊瑚色 */
#btn-tracing {
    background: linear-gradient(145deg, #FF8A80 0%, #FF6B6B 50%, #EE5A5A 100%);
    box-shadow:
        0 8px 32px rgba(255,107,107,0.35),
        0 2px 8px rgba(0,0,0,0.06),
        inset 0 2px 0 rgba(255,255,255,0.3);
}

/* 自由画布卡片 - 阳光黄色 */
#btn-freecanvas {
    background: linear-gradient(145deg, #FFE066 0%, #FFD93D 50%, #F0C929 100%);
    box-shadow:
        0 8px 32px rgba(255,217,61,0.35),
        0 2px 8px rgba(0,0,0,0.06),
        inset 0 2px 0 rgba(255,255,255,0.4);
}

.home-card:active {
    transform: scale(0.93);
    box-shadow:
        0 4px 16px rgba(0,0,0,0.15),
        inset 0 2px 4px rgba(0,0,0,0.1);
}

.card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.card-label {
    font-family: var(--font-display);
    font-size: clamp(1.6rem, 4.5vw, 2.4rem);
    color: #fff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

#btn-freecanvas .card-label {
    color: #7B5E00;
    text-shadow: none;
}

.card-hint {
    font-family: var(--font-display);
    font-size: clamp(0.9rem, 2.5vw, 1.2rem);
    color: rgba(255,255,255,0.85);
    margin-top: -0.3rem;
}

#btn-freecanvas .card-hint {
    color: rgba(123,94,0,0.65);
}

/* === 浮动装饰 === */
.floating-shapes {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
}

.float-shape {
    position: absolute;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    opacity: 0.6;
    animation: float-drift 12s ease-in-out infinite;
}

.shape-1 { top: 8%; left: 5%; animation-delay: 0s; animation-duration: 10s; }
.shape-2 { top: 15%; right: 8%; animation-delay: 2s; animation-duration: 13s; }
.shape-3 { bottom: 25%; left: 8%; animation-delay: 4s; animation-duration: 11s; }
.shape-4 { bottom: 10%; right: 12%; animation-delay: 1s; animation-duration: 14s; }
.shape-5 { top: 40%; left: 2%; animation-delay: 3s; animation-duration: 12s; }
.shape-6 { top: 60%; right: 3%; animation-delay: 5s; animation-duration: 10s; }

@keyframes float-drift {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-15px) rotate(5deg); }
    75% { transform: translateY(10px) rotate(-3deg); }
}

/* ============================================
   场景头部
   ============================================ */
.scene-header {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    background: var(--toolbar-bg);
    border-bottom: 2px solid rgba(0,0,0,0.04);
    z-index: 10;
    flex-shrink: 0;
}

.tracing-info {
    flex: 1;
    text-align: center;
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: #6D4C41;
}

/* === 通用按钮 === */
.btn-icon, .btn-action {
    min-width: 52px;
    min-height: 44px;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
}

.btn-icon {
    background: #F0E6D6;
    color: #8D6E63;
    padding: 8px;
}

.btn-icon:active {
    background: #E0D0BC;
    transform: scale(0.92);
}

.btn-action {
    background: #F0E6D6;
    color: #8D6E63;
    padding: 10px;
    border-radius: 14px;
}

.btn-action:active {
    background: #E0D0BC;
    transform: scale(0.92);
}

.btn-action.btn-clear {
    background: #FFE0E0;
    color: #E57373;
}

.btn-action.btn-clear:active {
    background: #FFCDD2;
}

/* === Canvas === */
#tracing-canvas, #freecanvas-canvas {
    flex: 1;
    width: 100%;
    background: #fff;
    touch-action: none;
}

/* ============================================
   颜色选择器 - 蜡笔圆点
   ============================================ */
.color-picker {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    max-width: 260px;
}

.color-dot {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
    box-shadow:
        0 2px 6px rgba(0,0,0,0.12),
        inset 0 -2px 3px rgba(0,0,0,0.1),
        inset 0 2px 3px rgba(255,255,255,0.4);
}

.color-dot:active {
    transform: scale(0.9);
}

.color-dot.active {
    border-color: #5D4037;
    transform: scale(1.25);
    box-shadow:
        0 3px 10px rgba(0,0,0,0.2),
        inset 0 -2px 3px rgba(0,0,0,0.1),
        inset 0 2px 3px rgba(255,255,255,0.4);
}

/* ============================================
   描边工具栏
   ============================================ */
.tracing-toolbar {
    height: 72px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    background: var(--toolbar-bg);
    border-top: 2px solid rgba(0,0,0,0.04);
    z-index: 10;
    flex-shrink: 0;
}

.tracing-toolbar.visible {
    display: flex;
}

/* ============================================
   自由画布工具栏
   ============================================ */
.fc-toolbar {
    min-height: 80px;
    height: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    background: var(--toolbar-bg);
    border-top: 2px solid rgba(0,0,0,0.04);
    z-index: 10;
    flex-shrink: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.fc-toolbar::-webkit-scrollbar { display: none; }

.toolbar-divider {
    width: 1px;
    height: 32px;
    background: rgba(0,0,0,0.06);
    border-radius: 1px;
    flex-shrink: 0;
}

/* 工具模式切换 */
.tool-group, .brush-type-group, .shape-group, .size-group, .bg-group,
.shape-cat-group, .shape-size-group {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}

/* 通用工具/画笔/图形按钮 */
.tool-btn, .brush-type-btn, .shape-btn {
    min-width: 38px;
    min-height: 38px;
    border: 2px solid transparent;
    border-radius: 12px;
    color: #8D6E63;
    background: #F5EDE3;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s, transform 0.12s;
    padding: 5px;
}

/* 图形分类 tab */
.shape-cat-btn {
    min-height: 32px;
    padding: 4px 10px;
    border: none;
    border-radius: 10px;
    font-size: 0.8rem;
    font-family: var(--font-body);
    background: #F0E6D6;
    color: #8D6E63;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}
.shape-cat-btn.active {
    background: #5D4037;
    color: #fff;
}

/* 图形大小 */
.shape-size-btn {
    min-height: 32px;
    padding: 4px 8px;
    border: 2px solid transparent;
    border-radius: 10px;
    font-size: 0.8rem;
    font-family: var(--font-body);
    background: #F5EDE3;
    color: #8D6E63;
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
    white-space: nowrap;
}
.shape-size-btn.active {
    border-color: var(--candy-purple);
    background: #F3E5F5;
    color: #7B1FA2;
}

.tool-btn.active {
    border-color: var(--candy-blue);
    background: #E3F2FD;
    color: #1565C0;
}

.brush-type-btn.active {
    border-color: var(--candy-green);
    background: #E8F5E9;
    color: #2E7D32;
}

.shape-btn.active {
    border-color: var(--candy-pink);
    background: #FCE4EC;
    color: #C2185B;
}

.sticker-btn {
    min-width: 46px;
    min-height: 46px;
    padding: 3px;
    background: #fff;
}

.sticker-btn img {
    width: 38px;
    height: 38px;
    display: block;
    object-fit: contain;
    pointer-events: none;
}

.tool-btn:active, .brush-type-btn:active, .shape-btn:active {
    transform: scale(0.88);
}

/* 画笔大小 */
.size-btn {
    min-width: 34px;
    min-height: 40px;
    border: 2px solid transparent;
    border-radius: 10px;
    background: #F5EDE3;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.size-btn.active {
    border-color: var(--candy-orange);
    background: #FFF3E0;
}
.size-btn:active { transform: scale(0.88); }

.size-dot {
    display: block;
    border-radius: 50%;
    background: #8D6E63;
}

/* 底色选择 */
.bg-dot {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.bg-dot.active {
    border-color: #5D4037;
    transform: scale(1.15);
}

.action-tools {
    display: flex;
    gap: 5px;
    margin-left: auto;
    flex-shrink: 0;
}

.btn-action {
    min-width: 40px;
    min-height: 40px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.12s, background 0.12s;
    padding: 8px;
    background: #F0E6D6;
    color: #8D6E63;
}
.btn-action:active { transform: scale(0.88); }
.btn-action.btn-clear { background: #FFE0E0; color: #E57373; }
.btn-action.btn-clear:active { background: #FFCDD2; }

/* ============================================
   庆祝动画
   ============================================ */
.celebration {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    overflow: hidden;
}

.celebration.active {
    pointer-events: auto;
}

.star {
    position: absolute;
    animation: star-burst 2s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
    pointer-events: none;
}

@keyframes star-burst {
    0% {
        transform: translateY(0) rotate(0deg) scale(0);
        opacity: 1;
    }
    30% {
        transform: translateY(-20vh) rotate(180deg) scale(1.3);
        opacity: 1;
    }
    100% {
        transform: translateY(60vh) rotate(720deg) scale(0.3);
        opacity: 0;
    }
}

/* ============================================
   iPad 安全区域
   ============================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    .fc-toolbar {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(80px + env(safe-area-inset-bottom));
    }
    .tracing-toolbar {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(72px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   响应式 - iPad 横屏优化
   ============================================ */
@media (orientation: landscape) {
    .home-cards {
        gap: clamp(2rem, 5vw, 4rem);
    }

    .home-card {
        width: clamp(220px, 30vw, 320px);
        height: clamp(200px, 28vw, 280px);
    }
}

@media (orientation: portrait) {
    .home-card {
        width: clamp(200px, 55vw, 300px);
        height: clamp(180px, 30vw, 260px);
    }

    .home-cards {
        flex-direction: column;
        gap: 1.5rem;
    }
}
