/* 像素风格基础 */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Press Start 2P', 'Courier New', monospace;
    background: #1a1a2e;
    color: #fff;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    user-select: none;
    -webkit-user-select: none;
}

/* 欢迎界面 */
#welcomeScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

#starCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.welcome-content {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 20px;
}

.pixel-title {
    font-size: 2.5em;
    color: #ffd700;
    text-shadow: 
        4px 4px 0 #ff6b6b,
        8px 8px 0 rgba(0,0,0,0.3);
    margin-bottom: 10px;
    animation: titleGlow 2s ease-in-out infinite;
    letter-spacing: 4px;
}

.pixel-subtitle {
    font-size: 1.2em;
    color: #00ff88;
    text-shadow: 2px 2px 0 #006644;
    margin-bottom: 30px;
    animation: subtitleBounce 2s ease-in-out infinite;
}

.pixel-decorations {
    margin: 20px 0;
}

.pixel-star {
    font-size: 1.5em;
    color: #ffd700;
    margin: 0 10px;
    animation: starSpin 3s linear infinite;
    display: inline-block;
}

.pixel-star:nth-child(2) {
    animation-delay: 0.5s;
}

.pixel-star:nth-child(3) {
    animation-delay: 1s;
}

.pixel-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 1em;
    padding: 15px 40px;
    background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 50%, #ff6b6b 100%);
    background-size: 200% 200%;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 4px 15px rgba(255, 107, 107, 0.4),
        0 0 20px rgba(255, 107, 107, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
    position: relative;
    touch-action: manipulation;
    overflow: hidden;
}

.pixel-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transition: left 0.5s ease;
}

.pixel-btn:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 8px 25px rgba(255, 107, 107, 0.5),
        0 0 30px rgba(255, 107, 107, 0.2);
    background-position: 100% 0;
}

.pixel-btn:hover::before {
    left: 100%;
}

.pixel-btn:active {
    transform: translateY(1px);
    box-shadow: 
        0 2px 8px rgba(255, 107, 107, 0.3),
        0 0 10px rgba(255, 107, 107, 0.1);
}

.pixel-btn.small {
    font-size: 0.6em;
    padding: 10px 18px;
    border-radius: 6px;
}

.pixel-btn.btn-secondary {
    background: linear-gradient(135deg, #6c5ce7 0%, #a855f7 50%, #6c5ce7 100%);
    background-size: 200% 200%;
    box-shadow: 
        0 4px 15px rgba(108, 92, 231, 0.4),
        0 0 20px rgba(108, 92, 231, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.pixel-btn.btn-secondary:hover {
    box-shadow: 
        0 8px 25px rgba(108, 92, 231, 0.5),
        0 0 30px rgba(108, 92, 231, 0.2);
}

.pixel-btn.btn-cyan {
    background: linear-gradient(135deg, #00b4d8 0%, #0096c7 100%);
    box-shadow: 
        0 4px 15px rgba(0, 180, 216, 0.4),
        0 0 20px rgba(0, 180, 216, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.pixel-btn.btn-cyan:hover {
    box-shadow: 
        0 8px 25px rgba(0, 180, 216, 0.5),
        0 0 30px rgba(0, 180, 216, 0.2);
}

.pixel-btn.btn-orange {
    background: linear-gradient(135deg, #f77f00 0%, #e36414 100%);
    box-shadow: 
        0 4px 15px rgba(247, 127, 0, 0.4),
        0 0 20px rgba(247, 127, 0, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.pixel-btn.btn-orange:hover {
    box-shadow: 
        0 8px 25px rgba(247, 127, 0, 0.5),
        0 0 30px rgba(247, 127, 0, 0.2);
}

.pixel-btn.btn-green {
    background: linear-gradient(135deg, #00f5a0 0%, #00d9f5 100%);
    box-shadow: 
        0 4px 15px rgba(0, 245, 160, 0.4),
        0 0 20px rgba(0, 245, 160, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.pixel-btn.btn-green:hover {
    box-shadow: 
        0 8px 25px rgba(0, 245, 160, 0.5),
        0 0 30px rgba(0, 245, 160, 0.2);
}

.pixel-btn.btn-purple {
    background: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
    box-shadow: 
        0 4px 15px rgba(168, 85, 247, 0.4),
        0 0 20px rgba(168, 85, 247, 0.15),
        inset 0 1px 0 rgba(255,255,255,0.2);
}

.pixel-btn.btn-purple:hover {
    box-shadow: 
        0 8px 25px rgba(168, 85, 247, 0.5),
        0 0 30px rgba(168, 85, 247, 0.2);
}

.welcome-btn-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}

.version-text {
    margin-top: 30px;
    font-size: 0.5em;
    color: #666;
}

/* 游戏界面 */
#gameScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(180deg, #1a1a2e 0%, #16213e 100%),
        repeating-linear-gradient(0deg, transparent, transparent 31px, rgba(255,215,0,0.03) 31px, rgba(255,215,0,0.03) 32px),
        repeating-linear-gradient(90deg, transparent, transparent 31px, rgba(255,215,0,0.03) 31px, rgba(255,215,0,0.03) 32px);
}

#gameBgCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.game-header {
    padding: 10px 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    background: rgba(0,0,0,0.5);
    border-bottom: 3px solid #ffd700;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.game-header::after {
    content: '';
    position: absolute;
    bottom: -3px;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, #ffd700, #ff6b6b, #ffd700, transparent);
    animation: headerGlow 3s ease-in-out infinite;
}

.header-info {
    display: flex;
    gap: 20px;
    align-items: center;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: linear-gradient(180deg, #2a2a4a 0%, #1a1a2e 100%);
    border: 3px solid;
    position: relative;
    image-rendering: pixelated;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    border: 1px solid rgba(255,255,255,0.1);
    pointer-events: none;
}

.stat-level {
    border-color: #ffd700;
    box-shadow:
        0 3px 0 #b8860b,
        0 0 12px rgba(255,215,0,0.3),
        inset 0 0 8px rgba(255,215,0,0.08);
}

.stat-moves {
    border-color: #00ff88;
    box-shadow:
        0 3px 0 #009955,
        0 0 12px rgba(0,255,136,0.3),
        inset 0 0 8px rgba(0,255,136,0.08);
}

.stat-icon {
    font-size: 1.4em;
    line-height: 1;
    filter: drop-shadow(0 0 4px rgba(255,215,0,0.5));
}

.stat-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-label {
    font-size: 0.45em;
    color: rgba(255,255,255,0.5);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.stat-value {
    font-size: 0.9em;
    font-weight: bold;
    letter-spacing: 1px;
    min-width: 2ch;
}

.stat-level .stat-value {
    color: #ffd700;
    text-shadow: 0 0 8px rgba(255,215,0,0.6);
}

.stat-moves .stat-value {
    color: #00ff88;
    text-shadow: 0 0 8px rgba(0,255,136,0.6);
}

.stat-moves .stat-value.bump {
    animation: statBump 0.3s ease;
}

@keyframes statBump {
    0% { transform: scale(1); }
    40% { transform: scale(1.4); }
    100% { transform: scale(1); }
}

#puzzleContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

#cheerleaderCanvas {
    width: 100%;
    height: 130px;
    flex-shrink: 0;
    image-rendering: pixelated;
    z-index: 3;
}

.puzzle-frame {
    position: relative;
    padding: 8px;
    background: linear-gradient(135deg, #3a2a0a, #5a4a1a, #3a2a0a);
    border: 4px solid #ffd700;
    box-shadow:
        0 0 20px rgba(255, 215, 0, 0.4),
        0 0 40px rgba(255, 215, 0, 0.15),
        inset 0 0 15px rgba(255, 215, 0, 0.1),
        0 8px 32px rgba(0,0,0,0.6);
    animation: framePulse 4s ease-in-out infinite;
}

.frame-corner {
    position: absolute;
    width: 16px;
    height: 16px;
    z-index: 2;
}

.frame-corner-tl {
    top: -4px; left: -4px;
    border-top: 4px solid #ff6b6b;
    border-left: 4px solid #ff6b6b;
}
.frame-corner-tr {
    top: -4px; right: -4px;
    border-top: 4px solid #00ff88;
    border-right: 4px solid #00ff88;
}
.frame-corner-bl {
    bottom: -4px; left: -4px;
    border-bottom: 4px solid #00bfff;
    border-left: 4px solid #00bfff;
}
.frame-corner-br {
    bottom: -4px; right: -4px;
    border-bottom: 4px solid #ff69b4;
    border-right: 4px solid #ff69b4;
}

#puzzleBoard {
    display: grid;
    gap: 2px;
    background: #2a2a4a;
    border: 2px solid #b8860b;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1;
    image-rendering: pixelated;
}

.game-actions {
    display: flex;
    gap: 16px;
    margin-top: 16px;
    justify-content: center;
}

.puzzle-piece {
    background-size: cover;
    background-position: center;
    cursor: pointer;
    transition: transform 0.1s ease;
    position: relative;
    border: 1px solid rgba(255,255,255,0.1);
}

.puzzle-piece:hover {
    transform: scale(1.05);
    z-index: 1;
    border-color: #ffd700;
}

.puzzle-piece.empty {
    background: #1a1a2e !important;
    border-color: transparent;
    cursor: default;
}

.puzzle-piece.empty:hover {
    transform: none;
    border-color: transparent;
}

/* 鼓励话语 - 横向漂浮闪烁 */
.encouragement {
    position: fixed;
    font-size: 1em;
    color: #ffd700;
    text-shadow:
        0 0 10px #ffd700,
        0 0 20px #ff6b6b,
        2px 2px 0 #ff6b6b;
    pointer-events: none;
    z-index: 100;
    white-space: nowrap;
    animation: floatAcross 3.5s linear forwards;
}

.encouragement.from-right {
    animation: floatAcrossRight 3.5s linear forwards;
}

/* 过关弹窗 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: linear-gradient(180deg, #2a2a4a 0%, #1a1a2e 100%);
    border: 4px solid #ffd700;
    padding: 30px;
    text-align: center;
    max-width: 90%;
    max-height: 90%;
    overflow-y: auto;
    box-shadow: 0 0 50px rgba(255, 215, 0, 0.5);
}

.modal-content .pixel-title {
    font-size: 1.5em;
    margin-bottom: 20px;
}

#originalImageContainer {
    width: 200px;
    height: 200px;
    margin: 0 auto 20px;
    border: 3px solid #ffd700;
    overflow: hidden;
}

#originalImageContainer img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.complete-text {
    font-size: 0.7em;
    color: #00ff88;
    margin-bottom: 20px;
    line-height: 1.8;
}

/* 烟花画布 */
#fireworksCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3000;
}

/* 动画 */
@keyframes titleGlow {
    0%, 100% { text-shadow: 4px 4px 0 #ff6b6b, 8px 8px 0 rgba(0,0,0,0.3); }
    50% { text-shadow: 4px 4px 0 #ff6b6b, 8px 8px 0 rgba(0,0,0,0.3), 0 0 20px #ffd700; }
}

@keyframes subtitleBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

@keyframes starSpin {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.2); }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes floatAcross {
    0% {
        transform: translateX(-100%);
        opacity: 0;
    }
    5% { opacity: 1; }
    10% { opacity: 0.3; }
    15% { opacity: 1; }
    20% { opacity: 0.3; }
    25% { opacity: 1; }
    30% { opacity: 0.5; }
    40% { opacity: 1; }
    50% { opacity: 0.4; }
    60% { opacity: 1; }
    70% { opacity: 0.5; }
    80% { opacity: 1; }
    90% { opacity: 0.4; }
    95% { opacity: 1; }
    100% {
        transform: translateX(100vw);
        opacity: 0;
    }
}

@keyframes floatAcrossRight {
    0% {
        transform: translateX(100vw);
        opacity: 0;
    }
    5% { opacity: 1; }
    10% { opacity: 0.3; }
    15% { opacity: 1; }
    20% { opacity: 0.3; }
    25% { opacity: 1; }
    30% { opacity: 0.5; }
    40% { opacity: 1; }
    50% { opacity: 0.4; }
    60% { opacity: 1; }
    70% { opacity: 0.5; }
    80% { opacity: 1; }
    90% { opacity: 0.4; }
    95% { opacity: 1; }
    100% {
        transform: translateX(-100%);
        opacity: 0;
    }
}

@keyframes framePulse {
    0%, 100% { box-shadow: 0 0 20px rgba(255,215,0,0.4), 0 0 40px rgba(255,215,0,0.15), inset 0 0 15px rgba(255,215,0,0.1), 0 8px 32px rgba(0,0,0,0.6); }
    50% { box-shadow: 0 0 30px rgba(255,215,0,0.6), 0 0 60px rgba(255,215,0,0.25), inset 0 0 20px rgba(255,215,0,0.15), 0 8px 32px rgba(0,0,0,0.6); }
}

@keyframes headerGlow {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.music-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 5px 14px;
    background: linear-gradient(180deg, rgba(15,12,41,0.92) 0%, rgba(48,43,99,0.92) 50%, rgba(36,36,62,0.92) 100%);
    border: 2px solid #ffd700;
    border-radius: 8px;
    box-shadow: 0 0 12px rgba(255,215,0,0.25), inset 0 1px 0 rgba(255,255,255,0.1);
    z-index: 4;
}

.music-ctrl-btn {
    font-size: 0.9em;
    min-width: 36px;
    height: 36px;
    background: linear-gradient(180deg, #ffd700 0%, #ff8c00 100%);
    border: 2px solid #fff;
    border-radius: 6px;
    color: #1a1a2e;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 0 3px 0 #b8860b, 0 4px 8px rgba(0,0,0,0.3);
    transition: all 0.1s ease;
    flex-shrink: 0;
    touch-action: manipulation;
    padding: 0 6px;
    position: relative;
    text-shadow: 0 1px 0 rgba(255,255,255,0.3);
}

.music-ctrl-btn:hover {
    background: linear-gradient(180deg, #ffe44d 0%, #ffa500 100%);
    box-shadow: 0 3px 0 #b8860b, 0 0 16px rgba(255,215,0,0.5);
    transform: translateY(-1px);
}

.music-ctrl-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #b8860b;
}

.music-ctrl-btn .btn-icon {
    font-size: 1.1em;
    line-height: 1;
}

.track-name {
    color: #ffd700;
    font-size: 0.7em;
    font-family: 'Press Start 2P', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    text-shadow: 0 0 8px rgba(255,215,0,0.5), 0 0 2px #000;
    padding: 0 4px;
}

/* Toast 提示 */
.game-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7em;
    padding: 20px 30px;
    background: rgba(20, 20, 40, 0.95);
    border: 2px solid #ffd700;
    border-radius: 12px;
    color: #fff;
    text-align: center;
    line-height: 2;
    z-index: 5000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.3), 0 8px 32px rgba(0,0,0,0.6);
    pointer-events: none;
    white-space: pre-line;
}

.game-toast.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

/* 响应式 */
@media (max-width: 480px) {
    .pixel-title {
        font-size: 1.8em;
    }
    
    .pixel-subtitle {
        font-size: 0.9em;
    }
    
    .pixel-btn {
        font-size: 0.8em;
        padding: 12px 30px;
    }
    
    .pixel-btn.small {
        font-size: 0.5em;
        padding: 8px 14px;
    }
    
    .welcome-btn-group {
        gap: 10px;
    }
    
    .stat-card {
        padding: 6px 10px;
        gap: 6px;
    }
    
    .stat-icon {
        font-size: 1.1em;
    }
    
    .stat-label {
        font-size: 0.38em;
    }
    
    .stat-value {
        font-size: 0.75em;
    }
    
    .modal-content {
        padding: 20px;
    }
    
    .modal-content .pixel-title {
        font-size: 1.2em;
    }
    
    #originalImageContainer {
        width: 150px;
        height: 150px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .pixel-title {
        font-size: 2em;
    }
}