/* =========================================
   1. 基础布局与手势锁定 (沉浸式体验)
   ========================================= */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior-x: none; /* 阻止侧滑返回 */
    touch-action: pan-y;         /* 禁止水平手势 */
    position: fixed;             /* 锁定视口 */
    background-color: #f0f9ff;
    font-family: "Microsoft YaHei", sans-serif;
}
/* 主内容区：也是 flex 列 */
.main-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;                 /* 撑满剩余空间 */
    min-height: 0;           /* 允许子元素收缩，防止溢出 */
    overflow: hidden;
}

/* =========================================
   2. 进度条与顶部提示
   ========================================= */
.progress-bar {
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.7);
    border-bottom: 2px solid #e1f5fe;
    z-index: 100;
}

.step {
    padding: 6px 18px;
    margin: 0 8px;
    background: #e0e0e0;
    border-radius: 20px;
    color: #757575;
    font-size: 14px;
    transition: all 0.3s;
}

.step.active {
    background: #ff9800;
    color: white;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(255, 152, 0, 0.3);
}

/* 核心提示文字：确保层级最高且不挡点击 */
#hint-text {
    z-index: 1000;
    position: absolute;
    bottom: -20px;
    left: 0;
    width: 100%;
    text-align: center;
    /* 确保文字本身可以响应点击 */
    pointer-events: auto; 
    font-size: 24px;
    font-weight: bold;
    color: #ff5722;
    /* 防止文字太长挡住视线，可以加个背景或阴影 */
    text-shadow: 0 0 5px #fff, 0 0 10px #fff;
}
/* =========================================
   3. 游戏舞台 (核心容器)
   ========================================= */
#game-stage {
    flex: 1;
    position: relative;
    max-width: 800px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.05);
    width: 100%;
    margin: 20px auto 2px;/*
    background: #ffffff;
    border: 6px solid #ffcc80;
    border-radius: 30px; */
    overflow: hidden; /* 严禁溢出 */
    display: flex;
    justify-content: center;
    align-items: center;
}

#play-content {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
}
/* =========================================
   4. 通用玩法盒子 (Play Box)
   ========================================= */
.play-box {
    position: relative;
    width: 320px;
    height: 320px;
    background: #fefefe;
    outline: 5px solid #ffcc80;
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 汉字书写容器层级 */
#writer-container {
    position: relative;
    z-index: 10;
}

/* 特效画布 */
#effect-canvas {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
}

/* =========================================
   5. 具体关卡元素样式
   ========================================= */

/* 擦一擦/聚光灯/吹气 */
#mask-canvas, #spotlight-canvas {
    position: absolute;
    inset: 0;
    z-index: 20;
    cursor: crosshair;
}

#dust-cloud {
    background-image: radial-gradient(circle, #d7ccc8 20%, #bcaaa4 80%);
    filter: blur(4px);
    transition: opacity 0.1s linear;
}

/* 砸蛋/浇水 */
#egg-shell, #seed {
    font-size: 100px;
    cursor: pointer;
    user-select: none;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.garden-bg {
    background: linear-gradient(#e3f2fd, #c8e6c9); /* 蓝天绿地感 */
    border-bottom: 40px solid #8d6e63; /* 泥土层 */
}

/* 喂食/拼图 */
.floating-food, .draggable-word {
    position: absolute;
    width: 70px;
    height: 70px;
    background: #fff;
    border: 3px solid #ffa000;
    border-radius: 50%;
    text-align: center;
    line-height: 65px;
    font-size: 35px;
    font-weight: bold;
    cursor: grab;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    z-index: 50;
    user-select: none;
}

.draggable-word:active {
    transform: scale(1.15);
    cursor: grabbing;
}

/* =========================================
   6. 动画特效
   ========================================= */
/* --- 基础状态类 --- */
/* 确保所有需要居中缩放的元素都有这个底子，防止动画时位置乱跳 */
.center-node {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

/* 1. 成功弹出 (Pop) - 适用于拼图归位、开花的一瞬间 */
.effect-pop {
    animation: anime-pop 0.5s ease-out forwards;
}

/* 2. 持续发光 (Shimmer) - 适用于狮子吃饱了、字选对了持续庆祝 */
.effect-shimmer {
    animation: anime-shimmer 1s infinite alternate;
}

/* 3. 错误抖动 (Shake) - 适用于选错字、喂错东西时的反馈 */
.effect-error {
    animation: anime-shake 0.4s focus-in;
}

/* --- 关键帧定义 --- */
@keyframes anime-pop {
    0% { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes anime-shimmer {
    from { filter: drop-shadow(0 0 5px gold) brightness(1); }
    to { filter: drop-shadow(0 0 15px orange) brightness(1.2); }
}

@keyframes anime-shake {
    0%, 100% { transform: translate(-50%, -50%) translateX(0); }
    25% { transform: translate(-50%, -50%) translateX(-5px); }
    75% { transform: translate(-50%, -50%) translateX(5px); }
}


/* =========================================
   7. 按钮与覆盖层
   ========================================= */
.controls {
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn-primary {
    padding: 12px 45px;
    font-size: 20px;
    background: linear-gradient(135deg, #ff5722, #f44336);
    color: white;
    border: none;
    border-radius: 50px;
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.4);
    cursor: pointer;
}

#start-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 999;
    display: flex; justify-content: center; align-items: center;
}

.start-card {
    background: white; padding: 40px; border-radius: 30px; text-align: center;
    max-width: 80%;
}

/* 玩法盒子：所有绝对定位的元素（如拖拽物）都相对于它 */
.play-box {
    position: relative;
    z-index: 5; /* 基础层级 */
    box-sizing: border-box;
}


/* 粒子层：在最下面，作为背景反馈 */
#effect-canvas {
    position: absolute;
    inset: 0;
    z-index: 1; /* 放在最底层 */
    pointer-events: none;
}

/* 汉字渲染层 */
#writer-container {
    z-index: 10;
}

/* 遮罩/聚光灯层：放在最上层，响应拖动 */
#mask-canvas, #spotlight-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20; 
}
/* 高清米字田字格 - 细虚线版 */
.tianzige-bg {
    background-color: #fff !important;
    position: relative;
    /* border: 3px solid #f44336 !important;  */
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}

/* 1. 绘制中心十字虚线 */
.tianzige-bg::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    /* 核心逻辑：利用两个重复渐变，一个横向一个纵向 */
    background-image: 
        linear-gradient(to right, rgba(244, 67, 54, 0.3) 50%, transparent 50%),
        linear-gradient(to bottom, rgba(244, 67, 54, 0.3) 50%, transparent 50%);
    background-size: 12px 1.5px, 1.5px 12px; /* 1.5px 的线宽，更显精致 */
    background-repeat: repeat-x, repeat-y;
    background-position: center;
}

.tianzige-bg::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background: 
        /* 左斜线 */
        linear-gradient(45deg, transparent 49.5%, rgba(244, 67, 54, 0.2) 49.5%, rgba(244, 67, 54, 0.2) 50.5%, transparent 50.5%),
        /* 右斜线 */
        linear-gradient(-45deg, transparent 49.5%, rgba(244, 67, 54, 0.2) 49.5%, rgba(244, 67, 54, 0.2) 50.5%, transparent 50.5%);
}

/* 确保汉字容器处于所有辅助线之上 */
#writer-container {
    position: relative;
    z-index: 10;
}

#practice-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 50;
    /* 禁止任何触摸默认行为，防止滑动干扰点击 */
    touch-action: none; 
}
/* 主容器：上下布局 */
.main-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
    z-index: 10;
}

/* 游戏容器：自动占据剩余空间，内部内容居中 */
.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    /* 移除 padding-bottom: 180px; */
    padding-bottom: 0;
    overflow-y: auto;        /* 如果内容过多可滚动，但一般不会 */
}

/* 底部火车区域：普通块级，不再 fixed */
.bottom-train-zone {
    /* 移除 position: fixed; bottom: 0; left: 0; */
    width: 100%;
    height: 180px;           /* 固定高度，可按需调整 */
    flex-shrink: 0;          /* 防止被压缩 */
    position: relative;      /* 内部绝对定位的画布可相对此区域定位 */
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    /* border-top: 4px solid #8BC34A; */
    overflow: hidden;
    z-index: 10;
}

/* 画布和滚动层保持相对/绝对定位不变，但父级不再是 fixed */
#landscape-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

#train-scroller {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}


.train-scroll-wrapper {
    position: relative;
    height: 100%;
    /* width 会在 JS 中动态设置 */
}

#svg-track {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}

/* 车厢样式：缩小一点适配底部 */
.word-card {
    position: absolute;
    width: 50px;
    height: 50px;
    background: #FFEB3B;
    border: 3px solid #FF9800;
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    transform: translate(-50%, -50%);
    z-index: 20;
    box-shadow: 0 3px 0 #F57C00;
    flex: 0 0 70px;
    font-weight: bold;
    color: #333;
    cursor: pointer;
    transition: filter 0.5s ease, opacity 0.5s ease, background-color 0.5s ease;
}
/* 外层滑动容器 */
.train-container {
    width: 100%;
    overflow-x: auto;
    padding: 20px 10px;
    -webkit-overflow-scrolling: touch; /* iOS 滑动优化 */
}

/* 火车长龙 */
.word-train {
    display: flex;
    gap: 20px;
    align-items: center;
    padding-left: 20px;
}

/* 未解锁状态 */
.word-card.locked {
    background: #eee;
    border-color: #bbb;
    color: #999;
    box-shadow: 0 4px 0 #999;
    cursor: not-allowed;
    filter: grayscale(1);
}
.word-card.locked {
    filter: grayscale(100%) brightness(0.8);
    opacity: 0.7;
    cursor: not-allowed;
    background-color: #e0e0e0 !important; /* 锁定状态通常是灰色 */
}
/* 1. 解锁核心动画 */
@keyframes unlock-bounce {
    0% {
        transform: scale(1);
        filter: grayscale(100%);
    }
    30% {
        transform: scale(1.4); /* 向上弹起放大 */
        filter: grayscale(0%);  /* 瞬间恢复彩色 */
        box-shadow: 0 0 30px #ffeb3b; /* 发出金光 */
    }
    60% {
        transform: scale(0.9); /* 稍微回弹 */
    }
    100% {
        transform: scale(1);
        filter: grayscale(0%);
        box-shadow: 0 4px 8px rgba(0,0,0,0.2); /* 回到正常阴影 */
    }
}

/* 2. 定义动画类 */
.unlock-animation {
    animation: unlock-bounce 0.8s ease-out forwards;
    z-index: 100; /* 确保弹出时在最前面 */
}


.word-card:active:not(.locked) {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #fb8c00;
}
/* 正在学习/复习的字在轨道上的样式 */
.word-card.active-on-train {
    border: 3px solid #FFEB3B;
    box-shadow: 0 0 15px #FFEB3B;
    transform: scale(1.2) translateY(-5px); /* 稍微放大并跳起 */
    z-index: 100;
    transition: all 0.3s ease;
}
.tool-btn {
    background: #fff;
    border: 3px solid #ff9800;
    border-radius: 50%;
    width: 65px;
    height: 65px;
    cursor: pointer;
    box-shadow: 0 4px 0 #e68a00;
    transition: all 0.1s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #ff9800;
    outline: none;
}

.tool-btn:active {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #e68a00;
}

.floating-food, .word-card-static {
    position: absolute;
    z-index: 10;
    touch-action: none; /* 防止移动端拖拽时页面抖动 */
}
/* =========================================
   8. 响应式适配
   ========================================= */
@media (max-width: 480px) {
    .play-box { width: 280px; height: 280px; }
    #hint-text { font-size: 18px; }
    .mascot { font-size: 60px; }
}

@media (min-width: 768px) {
    #game-stage { height: 500px; }
    .play-box { width: 380px; height: 380px; }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake-effect {
    animation: shake 0.2s ease-in-out 2;
}
/* PC端适配 */
@media (min-width: 1024px) {
    .game-container {
        max-height: calc(100vh - 220px); /* 屏幕总高度减去底部区域高度 */
        margin-bottom: 20px;
    }
    
    .main-wrapper {
        justify-content: flex-start; /* 防止垂直居中导致两头挤 */
    }
}