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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: Arial, sans-serif;
    background-color: #1a1a1a;
}

#game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #1a1a1a;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #1a1a1a;
    position: relative;
    z-index: 0;
}

/* GIF 动画层 */
#gif-animation-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

#gif-animation-layer .gif-sprite {
    position: absolute;
    pointer-events: none;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
}

#resource-panel {
    display: flex;
    gap: 20px;
    padding: 10px;
    background-color: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 16px;
}

#gold-display {
    color: #ffd700;
}

#power-display {
    color: #00bfff;
}

#game-status {
    position: absolute;
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background-color: rgba(0,0,0,0.8);
    color: #fff;
    font-size: 18px;
    border-radius: 5px;
}

/* 游戏结算页面 */
.game-end-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.5s ease-out;
    pointer-events: auto;
}

.game-end-screen.hidden {
    display: none;
}

/* 背景幕布与特效层 */
.game-end-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
      radial-gradient(circle at center, rgba(255,255,255,0.06), transparent 60%),
      repeating-linear-gradient(90deg, rgba(255,255,255,0.03) 0 2px, rgba(0,0,0,0.03) 2px 8px);
    mix-blend-mode: overlay;
    animation: curtainSweep 12s linear infinite;
    z-index: 1;
}
.victory-effects, .defeat-effects { position: absolute; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.victory-effects .rays { position: absolute; inset: -10%; background: conic-gradient(from 0deg, rgba(255,215,0,0.18) 0 10deg, transparent 10deg 20deg); filter: blur(6px) saturate(120%); animation: raysSpin 20s linear infinite; }
.pulse-ring { position: absolute; left: 50%; top: 50%; width: 40vmin; height: 40vmin; transform: translate(-50%, -50%); border-radius: 50%; border: 2px solid rgba(255,215,0,0.6); animation: ringPulse 3.6s ease-out infinite; }
.pulse-ring.ring2 { width: 56vmin; height: 56vmin; animation-delay: 1.2s; opacity: 0.7; }
#victory-fx { position: absolute; inset: 0; width: 100%; height: 100%; }
.end-screen-content { position: relative; z-index: 2; }
.end-screen-content::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.22) 45%, transparent 60%); transform: translateX(-120%) skewX(-12deg); animation: shineSweep 4.8s ease-in-out 0.8s infinite; }
@keyframes curtainSweep { 0% { background-position: 0 0, 0 0; } 100% { background-position: 400px 0, 800px 0; } }
@keyframes raysSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes ringPulse { 0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0.9; } 70% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.15; } 100% { transform: translate(-50%, -50%) scale(1.35); opacity: 0; } }
@keyframes shineSweep { 0%, 20% { transform: translateX(-130%) skewX(-12deg); } 50% { transform: translateX(130%) skewX(-12deg); } 100% { transform: translateX(130%) skewX(-12deg); } }

#victory-screen {
    background: radial-gradient(ellipse at center, rgba(255, 215, 0, 0.3) 0%, rgba(0, 0, 0, 0.95) 70%);
}

#defeat-screen {
    background: radial-gradient(ellipse at center, rgba(139, 0, 0, 0.3) 0%, rgba(0, 0, 0, 0.95) 70%);
}

.end-screen-content {
    text-align: center;
    padding: 40px;
    border-radius: 20px;
    background: linear-gradient(145deg, rgba(50, 50, 50, 0.9), rgba(20, 20, 20, 0.95));
    border: 3px solid #ffd700;
    box-shadow: 0 0 50px rgba(255, 215, 0, 0.5), inset 0 0 30px rgba(255, 215, 0, 0.1);
    animation: popIn 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    max-width: 90%;
    width: 360px;
}

.end-screen-content.defeat {
    border-color: #8b0000;
    box-shadow: 0 0 50px rgba(139, 0, 0, 0.5), inset 0 0 30px rgba(139, 0, 0, 0.1);
}

.victory-title {
    font-size: 48px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 4px 8px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
    animation: glow 2s ease-in-out infinite alternate;
}

.defeat-title {
    font-size: 48px;
    font-weight: bold;
    color: #ff4444;
    text-shadow: 0 0 20px rgba(255, 68, 68, 0.8), 0 4px 8px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
}

.victory-subtitle, .defeat-subtitle {
    font-size: 18px;
    color: #ccc;
    margin-bottom: 30px;
}

.victory-message {
    font-size: 22px;
    color: #fff;
    padding: 20px;
    margin: 20px 0;
    background: rgba(255, 215, 0, 0.15);
    border-radius: 10px;
    border-left: 4px solid #ffd700;
    line-height: 1.5;
    animation: slideIn 0.8s ease-out 0.3s both;
}

.defeat-message {
    font-size: 18px;
    color: #aaa;
    padding: 15px;
    margin: 20px 0;
}

.restart-btn {
    padding: 15px 50px;
    font-size: 20px;
    font-weight: bold;
    color: #fff;
    background: linear-gradient(145deg, #4a9eff, #2563eb);
    border: none;
    border-radius: 30px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
    margin-top: 10px;
}

.restart-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.6);
    background: linear-gradient(145deg, #5aa9ff, #3b7cf5);
}

.restart-btn:active {
    transform: translateY(0);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes glow {
    from { text-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 4px 8px rgba(0, 0, 0, 0.5); }
    to { text-shadow: 0 0 40px rgba(255, 215, 0, 1), 0 0 60px rgba(255, 215, 0, 0.6), 0 4px 8px rgba(0, 0, 0, 0.5); }
}

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

/* ============ 加载画面 ============ */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center bottom, #1a1035 0%, #0a0a18 70%);
    transition: opacity 0.6s ease;
}
#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}
.loading-title {
    font-size: clamp(36px, 8vw, 64px);
    font-weight: bold;
    color: #c8a0ff;
    text-shadow: 0 0 30px rgba(160,100,255,0.6), 0 0 60px rgba(120,60,220,0.3);
    margin-bottom: 4px;
    letter-spacing: 8px;
}
.loading-subtitle {
    font-size: clamp(14px, 3vw, 18px);
    color: #8a7aaa;
    margin-bottom: 30px;
    animation: loadPulse 2s ease-in-out infinite;
}
@keyframes loadPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}
#loading-characters {
    display: flex;
    gap: clamp(6px, 1.5vw, 14px);
    margin-bottom: 30px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 0 10px;
}
.load-char {
    width: clamp(60px, 10vw, 90px);
    height: clamp(80px, 14vw, 120px);
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    border: 2px solid rgba(160,100,255,0.2);
    overflow: hidden;
    position: relative;
    transition: border-color 0.4s, box-shadow 0.4s;
}
.load-char.loaded {
    border-color: rgba(160,100,255,0.7);
    box-shadow: 0 0 12px rgba(160,100,255,0.3);
}
.load-char.nightmare {
    border-color: rgba(255,60,60,0.2);
}
.load-char.nightmare.loaded {
    border-color: rgba(255,60,60,0.7);
    box-shadow: 0 0 12px rgba(255,60,60,0.3);
}
.load-char img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 20%;
    opacity: 0;
    transition: opacity 0.4s;
}
.load-char.loaded img {
    opacity: 1;
}
.load-char .load-spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.load-char .load-spinner::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid rgba(160,100,255,0.3);
    border-top-color: #c8a0ff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.load-char.nightmare .load-spinner::after {
    border-color: rgba(255,60,60,0.3);
    border-top-color: #ff6060;
}
.load-char.loaded .load-spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.load-char-label {
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 10px;
    color: rgba(255,255,255,0.5);
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.loading-bar-wrap {
    width: min(80%, 500px);
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 16px;
}
.loading-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #7c4dff, #c8a0ff);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.loading-tip {
    font-size: clamp(12px, 2.5vw, 14px);
    color: #6a5a8a;
    max-width: 80%;
    text-align: center;
}
