/* ===== King's Defense - Style ===== */
:root {
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --text-primary: #ffffff;
    --accent: #a855f7;
    --accent-gold: #ffd700;
    --accent-cyan: #00d4ff;
    --accent-pink: #ff6b9d;
    --accent-orange: #ff8c00;
    --accent-green: #22c55e;
    --accent-red: #ef4444;
}

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

body {
    font-family: 'Noto Sans KR', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: 80px;
}

/* ===== Background Effects ===== */
.bg-effects { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; overflow: hidden; }
.bg-orb { position: absolute; border-radius: 50%; filter: blur(100px); opacity: 0.3; }
.bg-orb:nth-child(1) { width: 300px; height: 300px; background: #a855f7; top: -100px; right: -100px; animation: float 15s ease-in-out infinite; }
.bg-orb:nth-child(2) { width: 250px; height: 250px; background: #00d4ff; bottom: -80px; left: -80px; animation: float 18s ease-in-out infinite reverse; }

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -30px) scale(1.05); }
    66% { transform: translate(-20px, 20px) scale(0.95); }
}

/* ===== Container ===== */
.container { position: relative; z-index: 1; max-width: 900px; margin: 0 auto; padding: 12px; }

/* ===== Header ===== */
header { text-align: center; margin-bottom: 12px; }
.header-top { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 4px; }
.back-btn { display: flex; align-items: center; gap: 4px; color: var(--accent-cyan); text-decoration: none; font-family: 'Jua', sans-serif; font-size: 0.9rem; position: absolute; left: 12px; transition: opacity 0.3s; }
.back-btn:hover { opacity: 0.7; }
.back-btn svg { width: 20px; height: 20px; }
h1 { font-family: 'Black Han Sans', sans-serif; font-size: 1.8rem; background: linear-gradient(135deg, var(--accent-gold), var(--accent-orange)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.subtitle { font-family: 'Jua', sans-serif; color: #94a3b8; font-size: 0.9rem; }

/* ===== Game Container ===== */
.game-container { width: 100%; margin: 0 auto; position: relative; }
#gameWrapper { position: relative; width: 100%; aspect-ratio: 16/10; background: #0f0f2a; border-radius: 8px; overflow: hidden; border: 1px solid rgba(168, 85, 247, 0.2); }
#gameCanvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }

/* ===== HUD ===== */
.hud { position: absolute; top: 0; left: 0; right: 0; pointer-events: none; z-index: 10; }
.hud-top { display: flex; justify-content: space-around; padding: 6px 8px; background: rgba(10, 10, 26, 0.85); border-bottom: 1px solid rgba(255, 255, 255, 0.1); pointer-events: auto; }
.hud-stat { display: flex; align-items: center; gap: 4px; font-family: 'Jua', sans-serif; font-size: 0.85rem; }
.hud-icon { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 4px; font-size: 0.7rem; font-weight: bold; }
.gold-icon { background: linear-gradient(135deg, #ffd700, #ff8c00); color: #0a0a1a; }
.life-icon { background: linear-gradient(135deg, #ef4444, #ff6b9d); color: #fff; font-size: 0.6rem; }
.wave-icon { background: linear-gradient(135deg, #a855f7, #c084fc); color: #fff; }
.score-icon { background: linear-gradient(135deg, #00d4ff, #7dd3fc); color: #0a0a1a; }

.hud-prepare { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 4px 8px; background: rgba(10, 10, 26, 0.85); border-bottom: 1px solid rgba(255, 255, 255, 0.1); font-family: 'Jua', sans-serif; font-size: 0.85rem; pointer-events: auto; }
.wave-btn { background: linear-gradient(135deg, var(--accent-green), #16a34a); color: #fff; border: none; padding: 4px 12px; border-radius: 6px; font-family: 'Jua', sans-serif; font-size: 0.8rem; cursor: pointer; transition: all 0.3s; min-height: 32px; }
.wave-btn:hover { transform: scale(1.05); box-shadow: 0 0 12px rgba(34, 197, 94, 0.4); }

/* ===== Tower Panel ===== */
.tower-panel {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    background: rgba(10, 10, 26, 0.95);
    border-top: 1px solid rgba(168, 85, 247, 0.3);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tower-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 56px;
    min-height: 52px;
    padding: 4px;
    background: rgba(30, 30, 60, 0.8);
    border: 2px solid rgba(100, 100, 150, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    color: #fff;
}
.tower-btn:hover, .tower-btn.selected { border-color: var(--accent-cyan); box-shadow: 0 0 10px rgba(0, 212, 255, 0.3); }
.tower-btn.disabled { opacity: 0.4; cursor: not-allowed; }
.tower-preview { image-rendering: pixelated; }
.tower-name { font-family: 'Jua', sans-serif; font-size: 0.6rem; color: #e2e8f0; line-height: 1; }
.tower-cost { font-family: 'Jua', sans-serif; font-size: 0.7rem; color: var(--accent-gold); }
.tower-desc { font-family: 'Noto Sans KR', sans-serif; font-size: 0.5rem; color: #94a3b8; line-height: 1.1; text-align: center; max-width: 64px; }

/* Hero Abilities */
.hero-abilities { display: flex; gap: 4px; margin-left: auto; }
.ability-btn {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(30, 30, 60, 0.8);
    border: 2px solid rgba(168, 85, 247, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    overflow: hidden;
    flex-shrink: 0;
}
.ability-btn:hover { border-color: var(--accent-gold); box-shadow: 0 0 10px rgba(255, 215, 0, 0.3); }
.ability-btn.on-cooldown { opacity: 0.5; cursor: not-allowed; }
.ability-btn.active-targeting { border-color: var(--accent-gold); box-shadow: 0 0 15px rgba(255, 215, 0, 0.5); animation: pulse 0.8s ease-in-out infinite; }
.ability-icon { font-size: 1.1rem; z-index: 1; }
.ability-cd {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    height: 0%;
    transition: height 0.1s linear;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 10px rgba(255, 215, 0, 0.3); }
    50% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.6); }
}

/* ===== Tower Popup ===== */
.tower-popup {
    position: absolute;
    z-index: 100;
    background: rgba(18, 18, 42, 0.95);
    border: 1px solid rgba(168, 85, 247, 0.4);
    border-radius: 8px;
    padding: 8px;
    min-width: 160px;
    backdrop-filter: blur(8px);
    pointer-events: auto;
}
.popup-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-family: 'Jua', sans-serif; }
#popupName { color: var(--accent-cyan); font-size: 0.9rem; }
#popupLevel { color: var(--accent-gold); font-size: 0.8rem; }
.popup-stats { margin-bottom: 6px; }
.popup-stat { display: flex; justify-content: space-between; font-size: 0.75rem; padding: 2px 0; color: #94a3b8; }
.popup-stat span:last-child { color: #fff; }
.popup-buttons { display: flex; gap: 4px; }
.popup-btn {
    flex: 1;
    padding: 4px 6px;
    border: none;
    border-radius: 6px;
    font-family: 'Jua', sans-serif;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 36px;
    justify-content: center;
}
.upgrade-btn { background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff; }
.upgrade-btn:hover { transform: scale(1.05); }
.upgrade-btn.max-level { background: #475569; cursor: not-allowed; }
.sell-btn { background: linear-gradient(135deg, var(--accent-red), #b91c1c); color: #fff; }
.sell-btn:hover { transform: scale(1.05); }

/* ===== Overlay Screens ===== */
.overlay-screen {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 26, 0.92);
    z-index: 50;
    backdrop-filter: blur(4px);
}
.hidden { display: none !important; }

.start-content, .gameover-content { text-align: center; padding: 20px; }
.game-logo {
    font-family: 'Black Han Sans', sans-serif;
    font-size: 2.5rem;
    line-height: 1.1;
    background: linear-gradient(135deg, var(--accent-gold), var(--accent-orange), var(--accent-gold));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: none;
    margin-bottom: 8px;
    animation: shimmer 3s ease-in-out infinite;
}
@keyframes shimmer {
    0%, 100% { filter: brightness(1); }
    50% { filter: brightness(1.3); }
}
.start-sub { font-family: 'Jua', sans-serif; color: #94a3b8; margin-bottom: 16px; }

/* Map Select */
.map-select { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.map-card {
    width: 100px;
    padding: 10px 8px;
    background: rgba(30, 30, 60, 0.8);
    border: 2px solid rgba(100, 100, 150, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}
.map-card:hover, .map-card.selected { border-color: var(--accent-gold); box-shadow: 0 0 12px rgba(255, 215, 0, 0.3); transform: translateY(-2px); }
.map-card.locked { opacity: 0.4; cursor: not-allowed; }
.map-name { font-family: 'Jua', sans-serif; font-size: 0.8rem; color: var(--accent-cyan); margin-bottom: 4px; }
.map-diff { font-size: 0.65rem; color: #94a3b8; }
.map-stars { color: var(--accent-gold); font-size: 0.7rem; margin-top: 4px; }
.map-lock { font-size: 1.5rem; }

.start-btn {
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: #fff;
    border: none;
    padding: 10px 32px;
    border-radius: 8px;
    font-family: 'Jua', sans-serif;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s;
    min-height: 44px;
}
.start-btn:hover { transform: scale(1.05); box-shadow: 0 0 20px rgba(168, 85, 247, 0.4); }

/* Game Over / Victory */
.gameover-title { font-family: 'Black Han Sans', sans-serif; font-size: 2rem; color: var(--accent-red); margin-bottom: 12px; }
.victory-title { color: var(--accent-gold) !important; }
.gameover-stats { margin-bottom: 12px; }
.stat-row { display: flex; justify-content: space-between; padding: 4px 16px; font-family: 'Jua', sans-serif; font-size: 0.9rem; color: #94a3b8; }
.stat-row span:last-child { color: #fff; }
.gameover-score { font-family: 'Black Han Sans', sans-serif; font-size: 1.5rem; color: var(--accent-gold); margin-bottom: 16px; }
.gameover-score span:last-child { margin-left: 8px; }

.star-rating { font-size: 2rem; margin-bottom: 8px; letter-spacing: 4px; }

/* ===== Article ===== */
.game-content { background: var(--bg-secondary); border-radius: 12px; padding: 20px; margin-top: 16px; border: 1px solid rgba(255, 255, 255, 0.05); }
.game-content h2 { font-family: 'Black Han Sans', sans-serif; color: var(--accent-cyan); margin-bottom: 8px; font-size: 1.1rem; }
.game-content p { color: #94a3b8; line-height: 1.6; font-size: 0.85rem; margin-bottom: 8px; }
.tip-box { background: rgba(168, 85, 247, 0.1); border-left: 3px solid var(--accent); padding: 12px; border-radius: 0 8px 8px 0; }
.tip-box p { margin-bottom: 4px; }

/* ===== Footer ===== */
footer { text-align: center; padding: 16px; color: #475569; font-size: 0.8rem; margin-top: 16px; }
footer a { color: var(--accent-cyan); text-decoration: none; }

/* ===== Mobile ===== */
@media (max-width: 600px) {
    .container { padding: 8px; }
    header { margin-bottom: 8px; }
    h1 { font-size: 1.4rem; }
    .subtitle { font-size: 0.8rem; }
    #gameWrapper { aspect-ratio: 4/3; border-radius: 4px; }
    .game-logo { font-size: 1.8rem; }
    .map-card { width: 80px; padding: 8px 6px; }
    .map-name { font-size: 0.7rem; }
    .hud-stat { font-size: 0.75rem; }
    .hud-icon { width: 16px; height: 16px; font-size: 0.6rem; }
    .tower-btn { min-width: 48px; min-height: 48px; }
    .tower-cost { font-size: 0.6rem; }
    .ability-btn { width: 40px; height: 40px; }
    .instructions, .game-content, footer { display: none; }
    body { padding-bottom: 66px; }
}

@media (max-width: 400px) {
    .tower-btn { min-width: 42px; min-height: 44px; padding: 2px; }
    .tower-preview { width: 28px !important; height: 28px !important; }
    .ability-btn { width: 36px; height: 36px; }
}

/* ===== Fullscreen ===== */
body.fullscreen-active header,
body.fullscreen-active .game-content,
body.fullscreen-active footer,
body.fullscreen-active .subtitle { display: none; }
body.fullscreen-active .container { max-width: 100%; padding: 0; }
body.fullscreen-active #gameWrapper { aspect-ratio: auto; width: 100vw; height: 100vh; border-radius: 0; }
