/* ===== CSS Variables & Reset ===== */
:root {
    --primary-color: #ff6b9d;
    --secondary-color: #c44569;
    --accent-color: #ffd93d;
    --text-light: rgba(255, 255, 255, 0.95);
    --text-muted: rgba(255, 255, 255, 0.75);
    --card-bg: rgba(255, 255, 255, 0.12);
    --card-hover: rgba(255, 255, 255, 0.22);
    --card-border: rgba(255, 255, 255, 0.18);
    --card-border-hover: rgba(255, 255, 255, 0.45);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 12px;
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: "Noto Sans CJK SC", "Microsoft YaHei", -apple-system, sans-serif;
    overflow-x: hidden;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-light);
    line-height: 1.6;
    /* 禁止横向滚动 */
    overflow-x: hidden;
}

/* ===== Background Containers ===== */
#canvas-container, #particle-wind-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
}
#canvas-container { z-index: -1; }
#canvas-container canvas { display: block; }

/* 粒子风容器 - 需要更高 z-index 以显示设置面板 */
#particle-wind-container {
    z-index: 50;
    pointer-events: auto;
    /* 使用相对定位让内容可以完整显示 */
    position: relative;
    min-height: 100vh;
    overflow: visible;
}
#particle-wind-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    /* 移除固定定位，让内容自然流动 */
    position: absolute;
    top: 0;
    left: 0;
}

/* 粒子风模式 - 允许页面滚动 */
body.particle-wind-mode {
    overflow-y: auto;
    overflow-x: hidden;
}

/* ===== Effect Switcher - 调整位置和大小 ===== */
.effect-switcher {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 200;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    max-width: calc(100vw - 32px);
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.15);
    /* 手机上自动隐藏，触摸顶部显示 */
    touch-action: manipulation;
}

.effect-btn {
    padding: 6px 12px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-light);
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    transition: background var(--transition-fast), 
                border-color var(--transition-fast),
                transform var(--transition-fast);
    text-align: center;
    white-space: nowrap;
    /* 触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.effect-btn:hover {
    background: var(--card-hover);
    transform: translateY(-1px);
}

.effect-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 1px;
}

.effect-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(255, 107, 157, 0.4);
}

/* ===== Back Button ===== */
.back-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.35);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    z-index: 100;
    display: none;
    transition: background var(--transition-fast), 
                transform var(--transition-fast),
                border-color var(--transition-fast);
    backdrop-filter: blur(10px);
    /* 触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.back-btn:hover {
    background: rgba(0, 0, 0, 0.5);
    transform: translateY(-1px);
}

.back-btn:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* ===== Heart Animation Container ===== */
.heart-container {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1000;
    display: none;
    overflow: hidden;
}

/* ===== Page Containers ===== */
#home-page, #timeline-page, #game-page {
    min-height: 100vh;
    padding: 70px 16px 40px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* ===== Home Page ===== */
#home-page {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.main-title {
    color: white;
    font-size: clamp(28px, 7vw, 48px);
    font-weight: 700;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    margin-bottom: 12px;
    text-align: center;
    letter-spacing: 1px;
    padding: 0 10px;
}

.subtitle { 
    color: var(--text-muted); 
    font-size: clamp(14px, 3.5vw, 18px);
    margin-bottom: 30px; 
    text-align: center;
    padding: 0 10px;
}

.card-container {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 100%;
    width: 100%;
    padding: 0 10px;
}

.card {
    width: 140px;
    min-height: 160px;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px 12px;
    cursor: pointer;
    transition: transform var(--transition-normal), 
                background var(--transition-normal),
                box-shadow var(--transition-normal),
                border-color var(--transition-normal);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow);
    /* 触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.card:hover {
    transform: translateY(-4px) scale(1.02);
    background: var(--card-hover);
    border-color: var(--card-border-hover);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.3);
}

.card:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.card-icon { 
    font-size: 40px; 
    margin-bottom: 10px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.card-title { 
    color: white; 
    font-size: 16px; 
    font-weight: 600;
    margin-bottom: 6px;
    text-align: center;
}

.card-desc { 
    color: var(--text-muted); 
    font-size: 11px; 
    text-align: center;
    line-height: 1.4;
}

/* ===== Timeline Page ===== */
#timeline-page {
    display: none;
    padding-top: 60px;
}

.timeline-title {
    text-align: center;
    color: white;
    font-size: clamp(22px, 5vw, 36px);
    font-weight: 700;
    margin-bottom: 30px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.timeline {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
    position: relative;
    padding: 10px 0;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: calc(100% - 20px);
    background: linear-gradient(to bottom, 
        rgba(255,255,255,0.1) 0%, 
        rgba(255,255,255,0.4) 50%, 
        rgba(255,255,255,0.1) 100%);
    border-radius: 1px;
}

.timeline-item {
    display: flex;
    margin-bottom: 24px;
    align-items: stretch;
}

.timeline-item:nth-child(odd) { flex-direction: row; }
.timeline-item:nth-child(even) { flex-direction: row-reverse; }

.timeline-content {
    width: 46%;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
}

.timeline-content:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.timeline-photo {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.timeline-date { 
    color: var(--secondary-color); 
    font-weight: 700; 
    font-size: 13px; 
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.timeline-date::before {
    content: '💕';
    font-size: 12px;
}

.timeline-text { 
    color: #444; 
    line-height: 1.5;
    font-size: 13px;
}

/* ===== Game Page ===== */
#game-page {
    display: none;
    padding-top: 60px;
    justify-content: flex-start;
    align-items: center;
}

.game-title {
    text-align: center;
    color: white;
    font-size: clamp(22px, 5vw, 36px);
    font-weight: 700;
    margin-bottom: 8px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.game-desc { 
    color: var(--text-muted); 
    font-size: 14px; 
    margin-bottom: 12px; 
    text-align: center;
}

.game-actions {
    margin-bottom: 16px;
}

.change-img-btn {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition-fast);
    -webkit-tap-highlight-color: transparent;
}

.change-img-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.move-count {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 8px;
}

#puzzle-container { 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    gap: 16px;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

#puzzle-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
    background: rgba(0, 0, 0, 0.25);
    padding: 8px;
    border-radius: var(--radius-sm);
    backdrop-filter: blur(10px);
    /* 响应式尺寸 */
    width: min(90vw, 320px);
    aspect-ratio: 1 / 1;
    max-width: 100%;
}

.puzzle-piece {
    aspect-ratio: 1 / 1;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 6px;
    transition: transform 0.15s ease, 
                box-shadow 0.15s ease,
                border-color 0.15s ease;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.15);
    /* 触摸优化 */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

/* 选中状态 */
.puzzle-piece.selected {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    transform: scale(0.95);
    box-shadow: 0 0 15px rgba(255, 217, 61, 0.6);
}

.puzzle-piece:hover:not(.empty):not(.selected) {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.puzzle-piece:focus-visible {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.puzzle-piece.empty { 
    background: rgba(255, 255, 255, 0.08) !important;
    cursor: default;
}

.puzzle-piece.empty:hover { transform: none; }
.puzzle-piece.empty.selected { outline: none; }

.puzzle-piece.movable {
    cursor: pointer;
}

.puzzle-piece.movable:hover {
    box-shadow: 0 0 0 3px rgba(255, 200, 200, 0.6);
}

/* Win Message */
#win-message {
    display: none;
    color: #51cf66;
    font-size: clamp(18px, 4vw, 28px);
    font-weight: 600;
    margin-top: 20px;
    text-align: center;
    animation: pulse 1s ease-in-out infinite;
    text-shadow: 0 2px 10px rgba(81, 207, 102, 0.4);
    padding: 0 10px;
}

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

/* ===== Responsive - 手机竖屏 ===== */
@media (max-width: 480px) {
    .card-container {
        gap: 12px;
    }
    .card {
        width: 130px;
        min-height: 140px;
        padding: 16px 10px;
    }
    .card-icon { font-size: 32px; }
    .card-title { font-size: 14px; }
    .card-desc { font-size: 10px; }
    
    .timeline-photo { height: 100px; }
    .timeline-content { padding: 10px; }
    
    #puzzle-board {
        width: 85vw;
        max-width: 280px;
    }
}

/* ===== Responsive - 手机横屏 ===== */
@media (max-height: 500px) and (orientation: landscape) {
    #home-page {
        flex-direction: row;
        gap: 20px;
        padding: 50px 20px 20px;
    }
    .main-title {
        font-size: clamp(20px, 5vw, 32px);
        margin-bottom: 0;
    }
    .subtitle { display: none; }
    .card-container {
        flex-direction: row;
        gap: 16px;
        margin-bottom: 0;
    }
    .card {
        width: 120px;
        min-height: 120px;
        padding: 12px;
    }
    .card-icon { font-size: 28px; margin-bottom: 6px; }
    .card-title { font-size: 13px; }
    .card-desc { font-size: 9px; }
    
    #game-page {
        padding-top: 50px;
        flex-direction: column;
    }
    .game-title { margin-bottom: 6px; }
    .game-desc { margin-bottom: 12px; font-size: 12px; }
    #puzzle-container { gap: 10px; }
    #puzzle-board {
        width: min(40vh, 240px);
    }
    
    .timeline-title { margin-bottom: 16px; }
    .timeline-item { margin-bottom: 16px; }
    .timeline-photo { aspect-ratio: 16 / 9; height: auto; }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}