/* ========================================
   基础样式和重置
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'STKaiti', 'KaiTi', 'FangSong', serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #0a0e27 0%, #1a0033 100%);
    color: #ffffff;
    -webkit-tap-highlight-color: transparent;
}

/* ========================================
   加载界面
   ======================================== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0e27 0%, #1a0033 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 1s ease-out;
}

.loader {
    text-align: center;
}

.loader-circle {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    border: 4px solid rgba(255, 215, 0, 0.2);
    border-top-color: #FFD700;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-text {
    color: #FFD700;
    font-size: 18px;
    letter-spacing: 2px;
}

/* ========================================
   主界面
   ======================================== */
.main-screen {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.particles-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.main-title {
    position: absolute;
    top: 2%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 36px;
    font-weight: normal;
    color: #FFD700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.6), 
                 0 0 40px rgba(255, 215, 0, 0.4);
    letter-spacing: 4px;
    z-index: 10;
    animation: titleGlow 3s ease-in-out infinite;
    padding: 0 20px;
    text-align: center;
    max-width: 90%;
}

@keyframes titleGlow {
    0%, 100% { text-shadow: 0 0 20px rgba(255, 215, 0, 0.6), 0 0 40px rgba(255, 215, 0, 0.4); }
    50% { text-shadow: 0 0 30px rgba(255, 215, 0, 0.8), 0 0 60px rgba(255, 215, 0, 0.6); }
}

.progress-display {
    position: absolute;
    top: 8%;
    left: 50%;
    transform: translateX(-50%);
    font-size: 16px;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

#completed-count {
    color: #FFD700;
    font-weight: bold;
}

/* ========================================
   时光之树
   ======================================== */
.tree-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 800px;
    height: 80%;
    z-index: 5;
}

.tree-svg {
    width: 100%;
    height: 100%;
}

.tree-trunk {
    fill: none;
    stroke: #FFD700;
    stroke-width: 30;
    stroke-linecap: round;
    filter: drop-shadow(0 0 20px #FFA500) drop-shadow(0 0 40px rgba(255, 165, 0, 0.4));
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    animation: drawTree 3s ease-out forwards, trunkGlow 4s ease-in-out infinite 3s;
    transition: all 0.5s ease;
}

@keyframes drawTree {
    to { stroke-dashoffset: 0; }
}

@keyframes trunkGlow {
    0%, 100% { 
        filter: drop-shadow(0 0 20px #FFA500) drop-shadow(0 0 40px rgba(255, 165, 0, 0.4));
        stroke-width: 30;
    }
    50% { 
        filter: drop-shadow(0 0 30px #FFD700) drop-shadow(0 0 60px rgba(255, 215, 0, 0.6));
        stroke-width: 32;
    }
}

/* 树枝样式 */
.tree-branch {
    fill: none;
    stroke: #FFD700;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 8px #FFA500);
    opacity: 0.9;
    transition: all 0.5s ease;
}

@media (hover: hover) and (pointer: fine) {
    .tree-branch:hover {
        stroke-width: 4;
        filter: drop-shadow(0 0 15px #FFD700);
    }
}

/* 胶囊样式 */
.capsule {
    cursor: pointer;
    transition: all 2s ease;
}

/* 只在非触摸设备上启用hover效果 */
@media (hover: hover) and (pointer: fine) {
    .capsule:hover {
        transform: scale(1.02);
    }
    
    .capsule:hover .capsule-bg {
        transform: scale(1.05);
    }
}

.capsule-bg {
    fill: rgba(255, 255, 255, 0.1);
    stroke: #888;
    stroke-width: 2;
    transition: all 2s ease;
}

.capsule.unlocked .capsule-bg {
    fill: rgba(255, 215, 0, 0.2);
    stroke: #FFD700;
    filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.6));
    animation: capsulePulse 2s ease-in-out infinite;
}

.capsule.completed .capsule-bg {
    fill: rgba(255, 215, 0, 0.3);
    stroke: #FFD700;
    stroke-width: 3;
    filter: drop-shadow(0 0 15px rgba(255, 215, 0, 0.8));
}

/* 触摸/点击激活状态 - 适用于所有设备 */
.capsule.active .capsule-bg {
    transform: scale(1.1);
    filter: drop-shadow(0 0 30px rgba(255, 215, 0, 1)) !important;
}

@keyframes capsulePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* 胶囊浮动动画 - 模拟挂在树枝上的摇晃 */
@keyframes capsuleFloat {
    0%, 100% { 
        transform: translateY(0) rotate(0deg);
    }
    25% { 
        transform: translateY(-2px) rotate(-0.5deg);
    }
    75% { 
        transform: translateY(2px) rotate(0.5deg);
    }
}

.capsule-image {
    opacity: 0.3;
    transition: opacity 0.3s ease;
}

.capsule.unlocked .capsule-image,
.capsule.completed .capsule-image {
    opacity: 1;
}

.capsule-icon {
    fill: #888;
    font-size: 24px;
}

.capsule.unlocked .capsule-icon {
    fill: #FFD700;
}

.capsule.completed .capsule-icon {
    fill: #4CAF50;
}

/* ========================================
   拼图游戏界面
   ======================================== */
.puzzle-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0e27 0%, #1a0033 100%);
    z-index: 100;
}

.puzzle-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.3);
}

.back-btn {
    padding: 10px 20px;
    background: rgba(255, 215, 0, 0.2);
    border: 2px solid #FFD700;
    border-radius: 25px;
    color: #FFD700;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

@media (hover: hover) and (pointer: fine) {
    .back-btn:hover {
        background: rgba(255, 215, 0, 0.4);
        transform: scale(1.05);
    }
}

.level-title {
    font-size: 24px;
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

.progress-bar-container {
    width: 200px;
    height: 10px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #FFA500);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
}

.puzzle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: calc(100% - 140px);
    padding: 20px;
}

.puzzle-grid {
    display: grid;
    gap: 2px;  /* 减小间隙 */
    background: rgba(0, 0, 0, 0.2);  /* 降低背景不透明度 */
    padding: 2px;  /* 减小内边距 */
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

.puzzle-grid.grid-3x3 {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
}

.puzzle-grid.grid-4x4 {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
}

.puzzle-piece {
    background-size: cover;
    background-position: center;
    cursor: pointer;
    transition: all 0.3s ease;
    /* 优化：减小边框宽度和透明度，减少视觉干扰 */
    border: 1px solid rgba(255, 215, 0, 0.15);
    border-radius: 2px;  /* 减小圆角 */
    position: relative;
    overflow: hidden;
    /* 提升图片渲染质量 */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.puzzle-piece::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* 移除内阴影，保持图片原始亮度 */
    background: transparent;  /* 确保无遮罩 */
    pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
    .puzzle-piece:hover {
        transform: scale(1.05);
        border-color: #FFD700;
        z-index: 10;
    }
}

.puzzle-piece.selected {
    border-color: #4CAF50;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.8);
}

.puzzle-hint {
    text-align: center;
    padding: 20px;
    font-size: 20px;
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
    letter-spacing: 2px;
}

/* ========================================
   完成动画界面
   ======================================== */
.completion-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 14, 39, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
}

.fireworks-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.completion-content {
    text-align: center;
    z-index: 201;
}

.completion-image {
    max-width: 80%;
    max-height: 60vh;
    border-radius: 20px;
    box-shadow: 0 0 50px rgba(255, 215, 0, 0.6);
    opacity: 0;
    animation: fadeInImage 2s ease-out 1s forwards;
}

@keyframes fadeInImage {
    from { opacity: 0; filter: blur(20px); }
    to { opacity: 1; filter: blur(0); }
}

.completion-poem {
    margin-top: 40px;
    font-size: 32px;
    color: #FFD700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    letter-spacing: 6px;
    opacity: 0;
    animation: floatUp 2s ease-out 2.5s forwards;
}

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

.continue-btn {
    margin-top: 40px;
    padding: 15px 50px;
    background: linear-gradient(135deg, #FFD700, #FFA500);
    border: none;
    border-radius: 30px;
    color: #1a0033;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

@media (hover: hover) and (pointer: fine) {
    .continue-btn:hover {
        transform: scale(1.1);
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.8);
    }
}

/* ========================================
   终章惊喜界面
   ======================================== */
.finale-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0e27 0%, #1a0033 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 300;
}

.finale-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.finale-content {
    text-align: center;
    z-index: 301;
}

.heart-photos {
    position: relative;
    width: 500px;
    height: 500px;
    margin: 0 auto;
}

.heart-photo {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    object-fit: cover;
    opacity: 0;
    animation: photoAppear 0.5s ease-out forwards;
}

@keyframes photoAppear {
    from { opacity: 0; transform: scale(0) rotate(0deg); }
    to { opacity: 1; transform: scale(1) rotate(var(--rotation)); }
}

.finale-message {
    margin-top: 60px;
}

.finale-text-line {
    font-size: 36px;
    color: #FFD700;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.9);
    letter-spacing: 8px;
    margin: 20px 0;
    opacity: 0;
    animation: textReveal 1s ease-out forwards;
}

.finale-text-line:nth-child(1) {
    animation-delay: 2s;
}

.finale-text-line:nth-child(2) {
    animation-delay: 2.5s;
}

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

.replay-btn {
    margin-top: 50px;
    padding: 15px 50px;
    background: linear-gradient(135deg, #FFD700, #FFA500);
    border: none;
    border-radius: 30px;
    color: #1a0033;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
}

@media (hover: hover) and (pointer: fine) {
    .replay-btn:hover {
        transform: scale(1.1);
        box-shadow: 0 0 30px rgba(255, 215, 0, 0.9);
    }
}

/* ========================================
   通用工具类
   ======================================== */
.hidden {
    display: none !important;
}

.fade-out {
    animation: fadeOut 1s ease-out forwards;
}

@keyframes fadeOut {
    to { opacity: 0; visibility: hidden; }
}

/* ========================================
   响应式设计
   ======================================== */

/* 平板端 */
@media (max-width: 1024px) {
    .main-title {
        font-size: 32px;
    }
    
    .tree-container {
        width: 95%;
        height: 75%;
    }
    
    .completion-poem {
        font-size: 26px;
    }
    
    .finale-text-line {
        font-size: 28px;
    }
    
    .heart-photos {
        width: 400px;
        height: 400px;
    }
    
    .heart-photo {
        width: 80px;
        height: 80px;
    }
}

/* 移动端 */
@media (max-width: 768px) {
    .main-title {
        font-size: 24px;
        top: 3%;
        letter-spacing: 2px;
    }
    
    .progress-display {
        font-size: 14px;
        top: 9%;
    }
    
    .tree-container {
        width: 100%;
        height: 70%;
    }
    
    .puzzle-header {
        flex-direction: column;
        gap: 10px;
        padding: 15px;
    }
    
    .back-btn {
        padding: 8px 16px;
        font-size: 14px;
    }
    
    .level-title {
        font-size: 20px;
    }
    
    .progress-bar-container {
        width: 150px;
    }
    
    .puzzle-hint {
        font-size: 16px;
        padding: 15px;
    }
    
    .completion-image {
        max-width: 90%;
    }
    
    .completion-poem {
        font-size: 20px;
        letter-spacing: 4px;
    }
    
    .continue-btn,
    .replay-btn {
        padding: 12px 40px;
        font-size: 16px;
    }
    
    .finale-text-line {
        font-size: 22px;
        letter-spacing: 4px;
    }
    
    .heart-photos {
        width: 300px;
        height: 300px;
    }
    
    .heart-photo {
        width: 60px;
        height: 60px;
    }
}

/* 小屏手机 */
@media (max-width: 480px) {
    .main-title {
        font-size: 24px;
        top: 3%;
        letter-spacing: 2px;
    }
    
    .progress-display {
        top: 10%;
        font-size: 14px;
    }
    
    .completion-poem {
        font-size: 18px;
    }
    
    .finale-text-line {
        font-size: 18px;
    }
}

/* 刘海屏适配 */
@supports (padding-top: env(safe-area-inset-top)) {
    .puzzle-header {
        padding-top: calc(20px + env(safe-area-inset-top));
    }
}
