/* ==========================================
   宝贝乐园 - 幼儿互动游戏 卡通风格样式
   ========================================== */

/* 基础重置 */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --color-bg: #FFF8E7;
    --color-primary: #FF6B6B;
    --color-secondary: #4ECDC4;
    --color-accent: #FFE66D;
    --color-purple: #A78BFA;
    --color-green: #6BCB77;
    --color-orange: #FF9F43;
    --color-blue: #54A0FF;
    --color-pink: #FF6B9D;
    --color-text: #2D3436;
    --color-text-light: #636E72;
    --color-white: #FFFFFF;
    --color-shadow: rgba(0, 0, 0, 0.1);
    --radius-round: 50%;
    --radius-card: 24px;
    --radius-btn: 20px;
    --radius-bubble: 50px;
    --font-main: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --transition-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    /* 安全区域 (iPad刘海/圆角) */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
    width: 100%;
    /* iOS Safari 100vh 修复: 使用 dvh 代替 vh */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    font-family: var(--font-main);
    background: var(--color-bg);
    color: var(--color-text);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    /* 禁止 iOS 长按弹出菜单 */
    -webkit-touch-callout: none;
}

#app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    overscroll-behavior: none;
    background: linear-gradient(180deg, #E8F8FF 0%, var(--color-bg) 30%, #FFF0DB 100%);
    /* 安全区域内边距 */
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

/* 隐藏工具类 */
.hidden { display: none !important; }

/* ==========================================
   顶部导航栏
   ========================================== */
#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--color-white);
    border-bottom: 3px solid var(--color-accent);
    box-shadow: 0 4px 12px var(--color-shadow);
    z-index: 100;
    flex-shrink: 0;
}

#header-title {
    font-size: 1.4rem;
    color: var(--color-primary);
    text-shadow: 2px 2px 0 var(--color-accent);
    letter-spacing: 2px;
}

.nav-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-round);
    border: 3px solid var(--color-secondary);
    background: var(--color-white);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.nav-btn:active {
    transform: scale(0.9);
    box-shadow: 0 2px 8px var(--color-shadow);
}

#star-display {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #FFF3CD, #FFE69C);
    padding: 6px 16px;
    border-radius: var(--radius-bubble);
    border: 2px solid var(--color-accent);
    font-size: 1.2rem;
    font-weight: bold;
    color: #E67E22;
}

.star-icon { font-size: 1.4rem; }

/* ==========================================
   页面容器
   ========================================== */
.page {
    display: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: auto;
    overscroll-behavior: none;
}

.page.active {
    display: flex;
    flex-direction: column;
}

/* ==========================================
   首页
   ========================================== */
#page-home {
    padding: 16px;
    align-items: center;
}

.welcome-banner {
    text-align: center;
    padding: 20px 0 10px;
    animation: fadeInUp 0.6s ease;
}

.welcome-sun {
    font-size: 4rem;
    animation: sunRotate 8s linear infinite;
    display: inline-block;
}

.welcome-text {
    font-size: 2rem;
    color: var(--color-primary);
    text-shadow: 2px 2px 0 var(--color-accent);
    margin: 8px 0;
}

.welcome-sub {
    font-size: 1.1rem;
    color: var(--color-text-light);
}

/* 年龄选择器 */
.age-selector {
    display: flex;
    gap: 10px;
    margin: 16px 0;
    animation: fadeInUp 0.6s ease 0.1s both;
}

.age-btn {
    padding: 10px 22px;
    border-radius: var(--radius-bubble);
    border: 3px solid #DDD;
    background: var(--color-white);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s var(--transition-bounce);
    color: var(--color-text-light);
}

.age-btn.active {
    border-color: var(--color-primary);
    background: linear-gradient(135deg, #FF6B6B, #FF8E8E);
    color: var(--color-white);
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
}

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

/* 游戏卡片网格 */
.game-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    width: 100%;
    max-width: 500px;
    padding: 8px 0;
}

.game-card {
    background: var(--color-white);
    border-radius: var(--radius-card);
    border: 3px solid transparent;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s var(--transition-bounce);
    box-shadow: 0 6px 20px var(--color-shadow);
    animation: fadeInUp 0.5s ease both;
}

.game-card:nth-child(1) { animation-delay: 0.15s; border-color: var(--color-primary); }
.game-card:nth-child(2) { animation-delay: 0.25s; border-color: var(--color-secondary); }
.game-card:nth-child(3) { animation-delay: 0.35s; border-color: var(--color-purple); }
.game-card:nth-child(4) { animation-delay: 0.45s; border-color: var(--color-orange); }

.game-card:active {
    transform: scale(0.93);
}

.game-card-icon {
    font-size: 3.5rem;
    margin-bottom: 10px;
    display: block;
}

.game-card-title {
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--color-text);
    margin-bottom: 4px;
}

.game-card-desc {
    font-size: 0.85rem;
    color: var(--color-text-light);
}

.game-card-coming {
    opacity: 0.5;
    pointer-events: none;
}

.game-card-coming .game-card-title::after {
    content: ' (敬请期待)';
    font-size: 0.75rem;
    color: var(--color-text-light);
}

/* ==========================================
   游戏页面
   ========================================== */
#page-game {
    padding: 0;
}

#game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

/* 数学游戏样式 */
.math-question-area {
    text-align: center;
    margin-bottom: 20px;
    animation: fadeInUp 0.5s ease;
}

.math-question-visual {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
    min-height: 80px;
}

.math-item-group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    border: 2px dashed #DDD;
}

.math-operator {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--color-primary);
    padding: 0 10px;
}

.math-equals {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--color-secondary);
}

.math-emoji {
    font-size: 2.2rem;
    display: inline-block;
    animation: popIn 0.3s var(--transition-bounce) both;
}

.math-question-text {
    font-size: 2rem;
    font-weight: bold;
    color: var(--color-text);
    margin: 8px 0;
}

/* 拖拽放置区 */
.drop-zone {
    width: 120px;
    height: 120px;
    border: 4px dashed var(--color-secondary);
    border-radius: var(--radius-card);
    background: rgba(78, 205, 196, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    margin: 16px auto;
    transition: all 0.3s ease;
    position: relative;
    touch-action: none;
    -webkit-touch-callout: none;
}

.drop-zone-text {
    font-size: 1rem;
    color: var(--color-text-light);
    text-align: center;
}

.drop-zone.hover {
    border-color: var(--color-primary);
    background: rgba(255, 107, 107, 0.15);
    transform: scale(1.08);
    box-shadow: 0 0 20px rgba(255, 107, 107, 0.3);
}

.drop-zone.correct {
    border-color: var(--color-green);
    background: rgba(107, 203, 119, 0.2);
    animation: correctPulse 0.5s ease;
}

.drop-zone.wrong {
    border-color: var(--color-primary);
    background: rgba(255, 107, 107, 0.2);
    animation: shake 0.5s ease;
}

/* 选项区域 */
.options-area {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
    width: 100%;
    max-width: 400px;
}

.option-item {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: bold;
    cursor: grab;
    transition: all 0.3s var(--transition-bounce);
    box-shadow: 0 6px 16px var(--color-shadow);
    border: 3px solid rgba(255, 255, 255, 0.8);
    position: relative;
    animation: popIn 0.4s var(--transition-bounce) both;
    touch-action: none;
    -webkit-touch-callout: none;
}

.option-item:nth-child(1) {
    background: linear-gradient(135deg, #FF6B9D, #FF8EB5);
    animation-delay: 0.1s;
}
.option-item:nth-child(2) {
    background: linear-gradient(135deg, #54A0FF, #7BB8FF);
    animation-delay: 0.2s;
}
.option-item:nth-child(3) {
    background: linear-gradient(135deg, #FFE66D, #FFEE99);
    color: #B7950B;
    animation-delay: 0.3s;
}
.option-item:nth-child(4) {
    background: linear-gradient(135deg, #6BCB77, #8FD99A);
    animation-delay: 0.4s;
}

.option-item:active {
    cursor: grabbing;
}

.option-item.dragging {
    opacity: 0.6;
    transform: scale(1.15);
    z-index: 1000;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

/* 拖拽克隆体 */
.drag-clone {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    touch-action: none;
    transition: none;
    transform: scale(1.2);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}

/* 进度条 */
.progress-bar {
    width: 100%;
    max-width: 400px;
    height: 16px;
    background: #E0E0E0;
    border-radius: 10px;
    margin: 12px auto;
    overflow: hidden;
    border: 2px solid #D0D0D0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-secondary), var(--color-green));
    border-radius: 10px;
    transition: width 0.5s ease;
    position: relative;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px 10px 0 0;
}

.progress-text {
    text-align: center;
    font-size: 0.9rem;
    color: var(--color-text-light);
    margin: 4px 0;
}

/* 题目计数器 */
.question-counter {
    font-size: 1rem;
    color: var(--color-text-light);
    text-align: center;
    margin-bottom: 8px;
}

/* ==========================================
   庆祝动画
   ========================================== */
#celebration-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    animation: fadeIn 0.3s ease;
}

.celebration-content {
    background: var(--color-white);
    border-radius: 32px;
    padding: 40px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: celebrateIn 0.5s var(--transition-bounce);
    max-width: 320px;
    width: 90%;
}

.celebration-emoji {
    font-size: 5rem;
    animation: bounce 0.8s ease infinite;
}

.celebration-text {
    font-size: 2rem;
    color: var(--color-primary);
    margin: 12px 0;
    text-shadow: 2px 2px 0 var(--color-accent);
}

.celebration-stars {
    font-size: 2rem;
    margin: 8px 0;
    letter-spacing: 4px;
}

.celebration-btn {
    margin-top: 16px;
    padding: 14px 40px;
    border-radius: var(--radius-bubble);
    border: none;
    background: linear-gradient(135deg, var(--color-secondary), #6BCB77);
    color: var(--color-white);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(78, 205, 196, 0.4);
    transition: transform 0.2s;
}

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

/* 鼓励提示 */
#encourage-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    animation: fadeIn 0.3s ease;
}

.encourage-content {
    background: var(--color-white);
    border-radius: 32px;
    padding: 36px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: celebrateIn 0.5s var(--transition-bounce);
    max-width: 280px;
    width: 85%;
}

.encourage-emoji {
    font-size: 4rem;
    animation: wiggle 0.5s ease;
}

.encourage-text {
    font-size: 1.4rem;
    color: var(--color-orange);
    margin: 12px 0;
}

.encourage-btn {
    padding: 12px 32px;
    border-radius: var(--radius-bubble);
    border: none;
    background: linear-gradient(135deg, var(--color-orange), #FFB84D);
    color: var(--color-white);
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(255, 159, 67, 0.4);
    transition: transform 0.2s;
}

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

/* 粒子特效容器 */
.particle-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5001;
    overflow: hidden;
}

.particle {
    position: absolute;
    font-size: 2rem;
    animation: particleFall 1.5s ease-in forwards;
    pointer-events: none;
}

/* 正确答案闪光 */
.flash-correct {
    animation: flashGreen 0.3s ease;
}

/* ==========================================
   游戏内按钮
   ========================================== */
.btn-next {
    padding: 14px 36px;
    border-radius: var(--radius-bubble);
    border: none;
    background: linear-gradient(135deg, var(--color-blue), #7BB8FF);
    color: var(--color-white);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(84, 160, 255, 0.4);
    margin-top: 16px;
    transition: transform 0.2s;
}

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

/* ==========================================
   动画定义
   ========================================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.3);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

@keyframes sunRotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes celebrateIn {
    from {
        opacity: 0;
        transform: scale(0.5) rotate(-10deg);
    }
    to {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-12px); }
    40% { transform: translateX(12px); }
    60% { transform: translateX(-8px); }
    80% { transform: translateX(8px); }
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes flashGreen {
    0% { background: rgba(107, 203, 119, 0.5); }
    100% { background: transparent; }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

@keyframes particleFall {
    0% {
        transform: translateY(-20px) rotate(0deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg) scale(0.5);
        opacity: 0;
    }
}

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

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* 浮动提示 */
.float-hint {
    position: absolute;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--color-green);
    animation: floatUp 1s ease forwards;
    pointer-events: none;
    z-index: 100;
}

@keyframes floatUp {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-60px) scale(1.5);
    }
}

/* ==========================================
   响应式适配
   ========================================== */
@media (max-width: 360px) {
    .game-grid { grid-template-columns: 1fr; }
    .welcome-text { font-size: 1.6rem; }
    .option-item { width: 68px; height: 68px; font-size: 2rem; }
    .drop-zone { width: 100px; height: 100px; }
}

@media (min-width: 768px) {
    .game-grid { max-width: 600px; grid-template-columns: repeat(3, 1fr); }
    .option-item { width: 90px; height: 90px; font-size: 2.8rem; }
    .drop-zone { width: 140px; height: 140px; font-size: 3.5rem; }
}

/* 横屏优化 */
@media (max-height: 500px) {
    #header { padding: 6px 16px; }
    #header-title { font-size: 1.1rem; }
    .welcome-banner { padding: 8px 0; }
    .welcome-sun { font-size: 2.5rem; }
    .welcome-text { font-size: 1.4rem; }
    .math-question-area { margin-bottom: 8px; }
    .math-question-visual { min-height: 50px; margin: 6px 0; }
    .math-emoji { font-size: 1.8rem; }
    .drop-zone { width: 90px; height: 90px; margin: 8px auto; }
    .option-item { width: 65px; height: 65px; font-size: 2rem; }
    .options-area { gap: 10px; margin-top: 10px; }
}
