/* ============================================
   수학 성 수호자 V3 - Dark Cyber Theme (Polished)
   ============================================ */

/* === CSS Variables === */
:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.85);
    --bg-glass: rgba(15, 23, 42, 0.75);
    --border-glass: rgba(100, 200, 255, 0.15);
    --accent-cyan: #00e5ff;
    --accent-magenta: #ff00e5;
    --accent-gold: #ffd700;
    --accent-green: #00ff88;
    --accent-red: #ff3366;
    --accent-orange: #ff8c00;
    --accent-purple: #a855f7;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-dim: #475569;
    --glow-cyan: 0 0 20px rgba(0, 229, 255, 0.3);
    --glow-gold: 0 0 20px rgba(255, 215, 0, 0.3);
    --glow-magenta: 0 0 20px rgba(255, 0, 229, 0.3);
    --glow-green: 0 0 20px rgba(0, 255, 136, 0.3);
    --font-display: 'Orbitron', monospace;
    --font-body: 'Noto Sans KR', 'Do Hyeon', sans-serif;
    --font-game: 'Do Hyeon', sans-serif;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    /* Tier colors */
    --tier-common: #4ade80;
    --tier-rare: #60a5fa;
    --tier-epic: #c084fc;
    --tier-legendary: #fbbf24;
}

/* === Reset & Base === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    touch-action: manipulation;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    user-select: none;
    color: var(--text-primary);
}

#game-content {
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    position: relative;
}

/* === Main Menu === */
#difficultyModal {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(0, 229, 255, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(255, 0, 229, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(168, 85, 247, 0.05) 0%, transparent 60%),
        linear-gradient(160deg, #050816 0%, #0a0e1a 30%, #0d1525 60%, #06091a 100%);
    position: relative;
    overflow: hidden;
}

#difficultyModal::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(2px 2px at 20% 30%, rgba(0, 229, 255, 0.15), transparent),
        radial-gradient(2px 2px at 40% 70%, rgba(255, 0, 229, 0.12), transparent),
        radial-gradient(1px 1px at 60% 20%, rgba(255, 255, 255, 0.1), transparent),
        radial-gradient(1px 1px at 80% 60%, rgba(255, 215, 0, 0.08), transparent);
    background-size: 250px 250px, 300px 300px, 200px 200px, 350px 350px;
    animation: starfield 120s linear infinite;
    z-index: 0;
}

@keyframes starfield {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#menuParticleCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.menu-container {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 48px 40px;
    max-width: 560px;
    width: 92%;
    background: rgba(8, 12, 28, 0.55);
    backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(100, 200, 255, 0.08);
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.6),
        0 0 80px rgba(0, 229, 255, 0.03),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    animation: menuFadeIn 0.8s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes menuFadeIn {
    from { opacity: 0; transform: translateY(30px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.menu-logo {
    margin-bottom: 44px;
    position: relative;
}

.logo-castle {
    font-size: 80px;
    display: block;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
    filter: drop-shadow(0 0 40px rgba(255, 215, 0, 0.6)) drop-shadow(0 10px 30px rgba(0, 0, 0, 0.4));
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}

.brand-title {
    font-family: var(--font-display);
    font-size: 13px;
    letter-spacing: 10px;
    color: var(--accent-cyan);
    text-transform: uppercase;
    margin-bottom: 10px;
    text-shadow: var(--glow-cyan);
    opacity: 0.9;
}

.main-title {
    font-family: var(--font-game);
    font-size: 48px;
    background: linear-gradient(135deg, #ffd700 0%, #ffaa00 40%, #ffe066 60%, #ffd700 100%);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: goldShimmer 3s ease-in-out infinite;
    margin-bottom: 6px;
    line-height: 1.2;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

@keyframes goldShimmer {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.main-subtitle {
    font-family: var(--font-display);
    font-size: 10px;
    letter-spacing: 8px;
    color: var(--text-dim);
    text-transform: uppercase;
    opacity: 0.7;
}

.version-badge {
    display: inline-block;
    margin-top: 16px;
    padding: 4px 18px;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-magenta));
    border-radius: 20px;
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 700;
    color: white;
    letter-spacing: 3px;
    box-shadow: 0 4px 20px rgba(0, 229, 255, 0.25), 0 4px 20px rgba(255, 0, 229, 0.25);
}

.difficulty-section {
    margin-bottom: 36px;
}

.section-label {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-weight: 400;
    letter-spacing: 1px;
}

.difficulty-options {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
}

.difficulty-btn {
    width: 88px;
    height: 92px;
    border: 1.5px solid rgba(100, 200, 255, 0.12);
    border-radius: var(--radius-lg);
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.8), rgba(20, 30, 55, 0.6));
    backdrop-filter: blur(10px);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    position: relative;
    overflow: hidden;
}

.difficulty-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.15), rgba(255, 0, 229, 0.15));
    opacity: 0;
    transition: opacity 0.35s ease;
}

.difficulty-btn:hover::before, .difficulty-btn:active::before {
    opacity: 1;
}

.difficulty-btn:hover, .difficulty-btn:active {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 25px rgba(0, 229, 255, 0.2), 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 0 30px rgba(0, 229, 255, 0.03);
    transform: translateY(-5px) scale(1.04);
}

.diff-grade {
    font-family: var(--font-display);
    font-size: 32px;
    font-weight: 900;
    background: linear-gradient(135deg, #ffd700, #ffaa00);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 8px rgba(255, 215, 0, 0.3));
    position: relative;
    z-index: 1;
}

.diff-label {
    font-size: 12px;
    color: var(--text-secondary);
    position: relative;
    z-index: 1;
    letter-spacing: 1px;
}

.menu-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.menu-btn {
    padding: 11px 22px;
    border: 1px solid rgba(100, 200, 255, 0.1);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.7), rgba(20, 30, 55, 0.5));
    backdrop-filter: blur(10px);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
}

.menu-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.08), rgba(255, 0, 229, 0.08));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.menu-btn:hover:not(:disabled)::after {
    opacity: 1;
}

.menu-btn:hover:not(:disabled) {
    border-color: rgba(0, 229, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), 0 0 15px rgba(0, 229, 255, 0.1);
}

.menu-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-icon {
    font-size: 16px;
    position: relative;
    z-index: 1;
}

/* === Game Canvas === */
#gameCanvas {
    width: 100%;
    height: 100%;
    position: relative;
    background:
        radial-gradient(ellipse at 20% 80%, rgba(0, 229, 255, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(255, 0, 229, 0.03) 0%, transparent 50%),
        linear-gradient(180deg, #0d1117 0%, #111827 50%, #0f172a 100%);
    display: none;
    overflow: hidden;
    contain: layout style paint;
}

#gameCanvas::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image:
        radial-gradient(rgba(100, 200, 255, 0.04) 1px, transparent 1px);
    background-size: 30px 30px;
    pointer-events: none;
    z-index: 0;
}

#dynamicLayerCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 12;
}

#gameUI {
    display: none;
}

/* === Path & Tiles === */
.path {
    position: absolute;
    background: linear-gradient(180deg, rgba(30, 60, 100, 0.6), rgba(20, 40, 80, 0.8));
    border: 1px solid rgba(100, 200, 255, 0.15);
    box-shadow: inset 0 0 20px rgba(0, 100, 200, 0.2);
    z-index: 1;
    border-radius: 8px;
}

.placement-tile {
    position: absolute;
    width: 40px;
    height: 40px;
    border: 1px dashed rgba(100, 200, 255, 0.2);
    border-radius: var(--radius-sm);
    pointer-events: auto;
    cursor: pointer;
    z-index: 2;
    transition: all 0.2s ease;
    background: rgba(0, 229, 255, 0.02);
}

.placement-tile:hover {
    background-color: rgba(0, 229, 255, 0.08);
    border-color: rgba(0, 229, 255, 0.4);
    box-shadow: inset 0 0 15px rgba(0, 229, 255, 0.1);
}

#rangeIndicator {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(0, 229, 255, 0.06);
    border: 1px dashed rgba(0, 229, 255, 0.3);
    pointer-events: none;
    display: none;
    z-index: 99;
    transform: translate(-50%, -50%);
}

/* === Castle (Canvas rendering - hitbox only) === */
.castle {
    position: absolute;
    width: 120px;
    height: 140px;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.castle-body {
    position: absolute;
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
}

.castle-body::before,
.castle-body::after {
    display: none;
}

.castle::before {
    display: none;
}

.castle::after {
    display: none;
}

.castle-health {
    position: absolute;
    bottom: -32px;
    width: 100px;
    background: linear-gradient(145deg, rgba(10, 14, 26, 0.9), rgba(20, 25, 45, 0.85));
    backdrop-filter: blur(10px);
    color: var(--accent-gold);
    padding: 5px 10px;
    border-radius: 20px;
    font-weight: bold;
    border: 1px solid rgba(255, 215, 0, 0.25);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.4);
    text-align: center;
    font-family: var(--font-display);
    font-size: 14px;
    z-index: 3;
}

/* === Wizard (Canvas sprite - hitbox only) === */
.wizard {
    position: absolute;
    width: 48px;
    height: 56px;
    background: transparent;
    border: none;
    border-radius: 0;
    cursor: pointer;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    box-shadow: none;
    animation: none;
}

.wizard::before { content: ''; }

.wizard.on-cooldown::after {
    content: '';
    position: absolute;
    top: -8px; right: -8px; bottom: -8px; left: -8px;
    border-radius: 50%;
    border: 2px solid var(--accent-cyan);
    animation: wizardCooldownSparkle 1.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes wizardCooldownSparkle {
    0% { transform: scale(1); opacity: 0.7; }
    50% { transform: scale(1.15); opacity: 0.3; }
    100% { transform: scale(1); opacity: 0.7; }
}

/* === Info Bar (Top HUD) === */
#info-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    background: linear-gradient(180deg, rgba(8, 10, 20, 0.97) 0%, rgba(10, 14, 26, 0.85) 100%);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-glass);
    z-index: 100;
    gap: 8px;
}

/* Wave progress bar under info bar */
.wave-progress-container {
    position: fixed;
    top: 44px;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.05);
    z-index: 100;
    overflow: hidden;
}

.wave-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-magenta), var(--accent-gold));
    background-size: 200% 100%;
    animation: progressShimmer 2s linear infinite;
    transition: width 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    border-radius: 0 2px 2px 0;
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}

@keyframes progressShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.info-left, .info-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 13px;
    transition: all 0.3s ease;
    position: relative;
}

.info-icon { font-size: 14px; }
.info-label { color: var(--text-dim); font-size: 11px; display: none; }
.info-value {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 14px;
    transition: transform 0.3s ease, color 0.3s ease;
}

.gold-info .info-value { color: var(--accent-gold); }
.score-info .info-value { color: var(--accent-cyan); }
.wave-info .info-value { color: var(--accent-magenta); }

/* Animated pulse on value change */
.info-value.value-up {
    animation: valueUp 0.5s ease-out;
}

.info-value.value-down {
    animation: valueDown 0.5s ease-out;
}

@keyframes valueUp {
    0% { transform: scale(1); }
    30% { transform: scale(1.3); color: var(--accent-green); }
    100% { transform: scale(1); }
}

@keyframes valueDown {
    0% { transform: scale(1); }
    30% { transform: scale(1.3); color: var(--accent-red); }
    100% { transform: scale(1); }
}

/* Gold pulse effect */
.gold-info.pulse {
    animation: goldPulse 0.6s ease-out;
}

@keyframes goldPulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.4); }
    50% { box-shadow: 0 0 12px 4px rgba(255, 215, 0, 0.2); }
    100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
}

.wizard-info {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-display);
    font-size: 13px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-size: 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    border-color: var(--accent-cyan);
    background: rgba(0, 229, 255, 0.1);
    transform: translateY(-1px);
}

.icon-btn:active {
    transform: translateY(0px) scale(0.95);
}

.icon-btn.upgrade-btn {
    border-color: rgba(0, 255, 136, 0.3);
}

.icon-btn.upgrade-btn:hover {
    border-color: var(--accent-green);
    background: rgba(0, 255, 136, 0.1);
    box-shadow: var(--glow-green);
}

/* === Combo Display === */
.combo-display {
    position: fixed;
    top: 55px;
    right: 16px;
    z-index: 100;
    text-align: center;
    animation: comboEntry 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}

.combo-display.hidden { display: none; }

.combo-count {
    font-family: var(--font-display);
    font-size: 52px;
    font-weight: 900;
    color: var(--accent-gold);
    text-shadow:
        0 0 30px rgba(255, 215, 0, 0.6),
        0 0 60px rgba(255, 140, 0, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.5);
    line-height: 1;
    animation: comboPulse 0.8s ease-in-out infinite;
}

.combo-label {
    font-family: var(--font-display);
    font-size: 13px;
    letter-spacing: 6px;
    color: var(--accent-cyan);
    text-shadow: var(--glow-cyan);
    text-transform: uppercase;
}

.combo-multiplier {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-magenta);
    text-shadow: var(--glow-magenta), 0 0 40px rgba(255, 0, 229, 0.2);
}

@keyframes comboEntry {
    0% { transform: scale(0.3) translateY(30px) rotate(-10deg); opacity: 0; }
    60% { transform: scale(1.15) translateY(-5px) rotate(2deg); opacity: 1; }
    100% { transform: scale(1) translateY(0) rotate(0deg); opacity: 1; }
}

@keyframes comboPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

/* Combo fire particles */
.combo-display::before,
.combo-display::after {
    content: '';
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
}

.combo-display::before {
    top: 10px;
    left: -5px;
    background: var(--accent-gold);
    box-shadow: 0 0 10px var(--accent-gold);
    animation: fireParticle1 1.2s ease-in-out infinite;
}

.combo-display::after {
    top: 15px;
    right: -5px;
    background: var(--accent-orange);
    box-shadow: 0 0 10px var(--accent-orange);
    animation: fireParticle2 1.5s ease-in-out infinite;
}

@keyframes fireParticle1 {
    0%, 100% { transform: translateY(0) scale(1); opacity: 0.8; }
    50% { transform: translateY(-20px) scale(0.3); opacity: 0; }
}

@keyframes fireParticle2 {
    0%, 100% { transform: translateY(0) scale(1); opacity: 0.7; }
    50% { transform: translateY(-25px) scale(0.2); opacity: 0; }
}

/* === Control Bar (Bottom) === */
#control-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: linear-gradient(0deg, rgba(8, 10, 20, 0.97) 0%, rgba(10, 14, 26, 0.85) 100%);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-glass);
    z-index: 100;
}

.control-left, .control-right {
    display: flex;
    gap: 8px;
}

.ctrl-btn {
    padding: 8px 16px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(20, 30, 55, 0.7), rgba(15, 23, 42, 0.5));
    backdrop-filter: blur(10px);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
}

.ctrl-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05), transparent 60%);
    pointer-events: none;
}

.ctrl-btn:hover {
    border-color: var(--accent-cyan);
    background: linear-gradient(145deg, rgba(0, 229, 255, 0.15), rgba(0, 229, 255, 0.05));
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 229, 255, 0.15);
}

.ctrl-btn:active {
    transform: translateY(0px) scale(0.97);
    box-shadow: none;
}

.ctrl-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.ctrl-btn.primary {
    border-color: var(--accent-green);
    background: linear-gradient(145deg, rgba(0, 255, 136, 0.15), rgba(0, 255, 136, 0.05));
    color: var(--accent-green);
    font-weight: 700;
}

.ctrl-btn.primary:hover {
    background: linear-gradient(145deg, rgba(0, 255, 136, 0.25), rgba(0, 255, 136, 0.1));
    box-shadow: 0 4px 20px rgba(0, 255, 136, 0.2), var(--glow-green);
}

/* Save button styling */
.ctrl-btn.save-btn {
    border-color: rgba(0, 229, 255, 0.3);
    color: var(--accent-cyan);
}

.ctrl-btn.save-btn:hover {
    border-color: var(--accent-cyan);
    box-shadow: 0 4px 16px rgba(0, 229, 255, 0.2);
}

/* Speed button styling */
.ctrl-btn.speed-btn {
    font-family: var(--font-display);
    font-size: 12px;
    font-weight: 700;
    min-width: 48px;
    text-align: center;
    border-color: rgba(255, 215, 0, 0.3);
    color: var(--accent-gold);
}

.ctrl-btn.speed-btn:hover {
    border-color: var(--accent-gold);
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.2);
}

.ctrl-btn.speed-btn.active {
    background: linear-gradient(145deg, rgba(255, 215, 0, 0.2), rgba(255, 215, 0, 0.08));
    border-color: var(--accent-gold);
    box-shadow: var(--glow-gold);
}

/* Keyboard shortcut hint */
.ctrl-btn .key-hint {
    display: inline-block;
    font-size: 9px;
    font-family: var(--font-display);
    color: var(--text-dim);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 3px;
    padding: 1px 4px;
    margin-left: 4px;
    vertical-align: middle;
    line-height: 1.2;
}

/* === Tower Base (V3 canvas rendering) === */
.tower {
    position: absolute;
    width: 40px;
    height: 40px;
    background: transparent !important;
    border: none !important;
    cursor: pointer;
    z-index: 5;
    clip-path: none !important;
    box-shadow: none !important;
}

.tower.disabled {
    filter: grayscale(100%) brightness(0.4);
    pointer-events: none;
}

.tower.disabled::after {
    content: '';
    position: absolute;
    font-size: 24px;
    color: red;
    text-shadow: 0 0 5px white;
    z-index: 6;
}

.tower.time-warped {
    filter: hue-rotate(180deg) brightness(0.7);
}

.tower:hover { }

.tower::before {
    display: none !important;
}

/* Individual tower styles */
.tower-plus { border-color: rgba(76, 175, 80, 0.5); }
.tower-plus::before { content: '+'; color: #4CAF50; text-shadow: 0 0 10px rgba(76, 175, 80, 0.5); }
.tower-minus { border-color: rgba(255, 152, 0, 0.5); }
.tower-minus::before { content: '-'; color: #ff9800; text-shadow: 0 0 10px rgba(255, 152, 0, 0.5); }
.tower-multiply { border-color: rgba(156, 39, 176, 0.5); }
.tower-multiply::before { content: 'x'; color: #9c27b0; text-shadow: 0 0 10px rgba(156, 39, 176, 0.5); }
.tower-divide { border-color: rgba(244, 67, 54, 0.5); }
.tower-divide::before { content: '/'; color: #f44336; text-shadow: 0 0 10px rgba(244, 67, 54, 0.5); }
.tower-cannon::before { content: ''; }
.tower-skyDestroyer::before { content: ''; }
.tower-ice { border-color: rgba(0, 229, 255, 0.5); }
.tower-ice::before { content: ''; }
.tower-meteor::before { content: ''; }
.tower-poison { border-color: rgba(139, 195, 74, 0.5); }
.tower-poison::before { content: ''; }
.tower-stun { border-color: rgba(255, 235, 59, 0.5); }
.tower-stun::before { content: ''; }
.tower-net::before { content: ''; }
.tower-laser::before { content: ''; font-size: 24px; color: #f39c12; animation: laser-pulse 1s infinite; }
@keyframes laser-pulse { 50% { filter: drop-shadow(0 0 12px #f39c12); } }
.tower-multi-shot::before { content: ''; font-size: 24px; color: #3498db; }
.tower-goldMine { border-color: rgba(255, 215, 0, 0.5); }
.tower-goldMine::before { content: ''; }
.tower-shredder::before { content: ''; }
.tower-repairStation { border-color: rgba(0, 255, 136, 0.5); }
.tower-repairStation::before { content: ''; }

/* Random box towers */
.tower-random_cheap { border-color: rgba(255, 255, 255, 0.3); animation: randomBoxPulse 2s infinite; }
.tower-random_cheap::before { content: ''; }
.tower-random_medium { border-color: rgba(168, 85, 247, 0.5); animation: randomBoxPulse 1.5s infinite; }
.tower-random_medium::before { content: ''; }
.tower-random_expensive { border-color: rgba(255, 0, 229, 0.5); animation: randomBoxPulse 1s infinite; }
.tower-random_expensive::before { content: ''; }
@keyframes randomBoxPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(168, 85, 247, 0.3); }
    50% { box-shadow: 0 0 25px rgba(168, 85, 247, 0.6); }
}

/* V3 special towers - transparent hitbox */
.tower-ultimate { animation: none !important; }
.tower-ultimate::before { display: none !important; }
.tower-ultimate::after { display: none !important; }
@keyframes ultimate-rainbow { 0% { filter: hue-rotate(0deg); } 100% { filter: hue-rotate(360deg); } }
@keyframes ultimate-pulse {
    from { box-shadow: 0 0 15px var(--accent-magenta), 0 0 30px var(--accent-cyan); }
    to { box-shadow: 0 0 25px var(--accent-magenta), 0 0 50px var(--accent-cyan), 0 0 70px var(--accent-gold); }
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.tower-transcendent { animation: none !important; }
.tower-transcendent::before { display: none !important; }
.tower-transcendent::after { display: none !important; }
@keyframes transcendent-bg { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
@keyframes transcendent-pulse {
    from { box-shadow: 0 0 20px var(--accent-magenta), 0 0 40px var(--accent-cyan); transform: scale(1); }
    to { box-shadow: 0 0 40px var(--accent-magenta), 0 0 80px var(--accent-cyan), 0 0 120px var(--accent-gold); transform: scale(1.05); }
}
@keyframes transcendent-float {
    from { transform: translateY(-2px) scale(1); }
    to { transform: translateY(2px) scale(1.1); }
}

.tower-golden { animation: none !important; }
.tower-golden::before { display: none !important; }
@keyframes goldenGlow {
    from { box-shadow: 0 0 15px #ffc500, 0 0 30px #ff8c00; }
    to { box-shadow: 0 0 25px #ffc500, 0 0 50px #ff8c00; }
}

.tower-silver { animation: none !important; }
.tower-silver::before { display: none !important; }
@keyframes silverGlow {
    from { box-shadow: 0 0 10px #fff, 0 0 20px #c0c0c0; }
    to { box-shadow: 0 0 20px #fff, 0 0 35px #c0c0c0; }
}

.tower-copper { animation: none !important; }
.tower-copper::before { display: none !important; }
@keyframes copperGlow {
    from { box-shadow: 0 0 10px #cd853f, 0 0 15px #b87333; }
    to { box-shadow: 0 0 15px #cd853f, 0 0 25px #b87333; }
}

/* V3 tower level display hidden (canvas renders level rings) */
.tower-level {
    display: none !important;
}

/* === Monsters (Canvas rendering - hitbox only) === */
.monster {
    position: absolute;
    width: 30px; height: 30px;
    border: none;
    border-radius: 50%;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
    top: 0; left: 0;
    background: transparent;
}

.monster::before { display: none; }
.monster::after { display: none; }

.monster.slowed, .monster.frozen { }
.monster.poisoned { }
.monster.stunned { }
.monster.stealthed { opacity: 0.15; }
.monster.shielded { }
.monster.shredded { }

/* Individual monsters - transparent hitboxes */
.monster-normal { background: transparent; }
.monster-normal::before { display: none; }

.monster-tank { width: 45px; height: 45px; background: transparent; border: none; }
.monster-healer { background: transparent; border: none; }
.monster-speed { background: transparent; border: none; }
.monster-boss { width: 60px; height: 60px; background: transparent; border: none; }
.monster-finalBoss { width: 80px; height: 80px; background: transparent; border: none; }
.monster-archfiend { width: 65px; height: 65px; background: transparent; border: none; }
.monster-bat { background: transparent; border: none; z-index: 9; }
.monster-dragon { width: 50px; height: 50px; background: transparent; border: none; z-index: 9; }
.monster-shielder { background: transparent; border: none; }
.monster-teleporter { background: transparent; border: none; }
.monster-splitter { background: transparent; border: none; }
.monster-mini-splitter { width: 20px; height: 20px; background: transparent; border: none; }
.monster-ghost { background: transparent; border: none; }
.monster-mimic { background: transparent; border: none; }
.monster-summoner { background: transparent; border: none; }
.monster-general { width: 40px; height: 40px; background: transparent; border: none; }
.monster-plaguebearer { background: transparent; border: none; }
.monster-assassin { background: transparent; border: none; }
.monster-disruptor { background: transparent; border: none; }
.monster-chronomancer { background: transparent; border: none; }
.monster-golem { width: 48px; height: 48px; background: transparent; border: none; }
.monster-mirage { background: transparent; border: none; }
.monster-leech { background: transparent; border: none; z-index: 9; }
.monster-collector { background: transparent; border: none; }
.monster-ancientDragon { width: 70px; height: 70px; background: transparent; border: none; z-index: 9; }
.monster-voidLord { width: 65px; height: 65px; background: transparent; border: none; }
.monster-titanGolem { width: 75px; height: 75px; background: transparent; border: none; }

/* Monster health - hidden, canvas renders */
.monster-health { display: none; }
.monster-health-bar { display: none; }

/* === Laser Beam (canvas rendering) === */
.laser-beam {
    display: none !important;
}

/* === Effects === */
.magic-attack, .frost-nova, .chain-lightning, .teleport-effect, .black-hole, .plague-pool, .splash-damage-effect, .time-warp-effect, .damage-reflect-effect, .soul-drain-effect {
    position: absolute;
    pointer-events: none;
    z-index: 20;
    opacity: 0 !important;
}

.splash-damage-effect {
    width: 1px; height: 1px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: splash-animation 0.8s ease-out forwards;
}
.splash-damage-effect::before {
    content: ''; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); width: 100%; height: 100%; border-radius: 50%;
    background: radial-gradient(circle, rgba(255,82,82,0) 0%, rgba(255,50,50,0.6) 50%, transparent 70%);
    animation: splash-wave 0.8s ease-out forwards;
}
@keyframes splash-animation { from { width: 1px; height: 1px; } to { width: var(--effect-size, 120px); height: var(--effect-size, 120px); opacity: 0; } }
@keyframes splash-wave { 0% { transform: translate(-50%,-50%) scale(0.1); opacity: 1; } 100% { transform: translate(-50%,-50%) scale(1); opacity: 0; } }

.ultimate-splash-effect {
    width: 1px; height: 1px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: ultimate-splash 1.2s ease-out forwards;
    position: absolute; pointer-events: none; z-index: 25;
}
.ultimate-splash-effect::before {
    content: ''; position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%); width: 100%; height: 100%;
    background: conic-gradient(from 0deg, rgba(255,0,255,0.6), rgba(0,255,255,0.6), rgba(255,255,0,0.6), rgba(255,0,0,0.6), rgba(255,0,255,0.6));
    border-radius: 50%;
    animation: splash-wave 1.2s ease-out forwards;
}
@keyframes ultimate-splash { from { width: 1px; height: 1px; } to { width: var(--effect-size, 200px); height: var(--effect-size, 200px); opacity: 0; } }

.magic-attack { border-radius: 50%; background: radial-gradient(circle, rgba(255,100,0,0.8), transparent 70%); animation: magicBurst 0.5s ease-out forwards; }
.frost-nova { border-radius: 50%; background: radial-gradient(circle, rgba(0,229,255,0.6), transparent 70%); animation: magicBurst 0.5s ease-out forwards; }
@keyframes magicBurst { 0% { transform: translate(-50%,-50%) scale(0.3); opacity: 1; } 100% { transform: translate(-50%,-50%) scale(1); opacity: 0; } }

.chain-lightning { height: 3px; background: linear-gradient(90deg, transparent, var(--accent-cyan), #fff, var(--accent-cyan), transparent); box-shadow: 0 0 10px var(--accent-cyan); transform-origin: left center; }

.teleport-effect { border-radius: 50%; background: radial-gradient(circle, rgba(168,85,247,0.6), transparent 70%); animation: magicBurst 0.3s ease-out forwards; }
.black-hole { border-radius: 50%; background: radial-gradient(circle, #000 30%, rgba(100,0,200,0.5) 60%, transparent 80%); box-shadow: 0 0 30px rgba(100,0,200,0.5); animation: blackHoleSpin 1s linear infinite; }
@keyframes blackHoleSpin { from { transform: translate(-50%,-50%) rotate(0deg); } to { transform: translate(-50%,-50%) rotate(360deg); } }

.plague-pool { border-radius: 50%; background: radial-gradient(circle, rgba(76,175,80,0.5), transparent 70%); animation: plaguePoolPulse 1s ease-in-out infinite; }
@keyframes plaguePoolPulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 0.8; } }

.time-warp-effect { border-radius: 50%; background: radial-gradient(circle, rgba(124,77,255,0.4), transparent 70%); animation: magicBurst 1s ease-out forwards; }
.damage-reflect-effect { border-radius: 50%; background: radial-gradient(circle, rgba(255,0,0,0.5), transparent 70%); animation: magicBurst 0.3s ease-out forwards; }
.soul-drain-effect { border-radius: 50%; background: radial-gradient(circle, rgba(100,0,100,0.5), transparent 70%); animation: magicBurst 1.5s ease-out forwards; }

/* === Tower Selector (Upgraded with tier colors and cards) === */
.tower-selector {
    position: fixed;
    z-index: 200;
    display: none;
    background: linear-gradient(160deg, rgba(12, 18, 35, 0.95), rgba(8, 12, 28, 0.97));
    backdrop-filter: blur(20px);
    border: 1px solid rgba(100, 200, 255, 0.12);
    border-radius: var(--radius-lg);
    padding: 14px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(0, 229, 255, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    animation: selectorPopIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes selectorPopIn {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.tower-selector.show { display: block; }

.tower-options-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
    max-width: 420px;
    max-height: 260px;
    overflow-y: auto;
}

.tower-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px 6px;
    border: 1.5px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    min-width: 64px;
    position: relative;
    overflow: hidden;
}

/* Tier color coding for tower options */
.tower-option[data-tier="common"] {
    border-color: rgba(74, 222, 128, 0.25);
}
.tower-option[data-tier="common"]:hover {
    border-color: var(--tier-common);
    background: rgba(74, 222, 128, 0.08);
    box-shadow: 0 0 15px rgba(74, 222, 128, 0.15);
}

.tower-option[data-tier="rare"] {
    border-color: rgba(96, 165, 250, 0.25);
}
.tower-option[data-tier="rare"]:hover {
    border-color: var(--tier-rare);
    background: rgba(96, 165, 250, 0.08);
    box-shadow: 0 0 15px rgba(96, 165, 250, 0.15);
}

.tower-option[data-tier="epic"] {
    border-color: rgba(192, 132, 252, 0.25);
}
.tower-option[data-tier="epic"]:hover {
    border-color: var(--tier-epic);
    background: rgba(192, 132, 252, 0.08);
    box-shadow: 0 0 15px rgba(192, 132, 252, 0.15);
}

.tower-option[data-tier="legendary"] {
    border-color: rgba(251, 191, 36, 0.3);
    background: rgba(251, 191, 36, 0.04);
}
.tower-option[data-tier="legendary"]:hover {
    border-color: var(--tier-legendary);
    background: rgba(251, 191, 36, 0.1);
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.2);
}

.tower-option[data-tier="random"] {
    border-color: rgba(168, 85, 247, 0.3);
    animation: randomOptionPulse 2s ease-in-out infinite;
}

@keyframes randomOptionPulse {
    0%, 100% { border-color: rgba(168, 85, 247, 0.3); }
    50% { border-color: rgba(168, 85, 247, 0.6); }
}

.tower-option[data-tier="random"]:hover {
    border-color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.1);
    box-shadow: 0 0 18px rgba(168, 85, 247, 0.2);
}

.tower-option:hover {
    transform: translateY(-3px);
}

.tower-option:active {
    transform: translateY(0px) scale(0.95);
}

/* Tier dot indicator */
.tower-option-tier-dot {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.tower-option-symbol { font-size: 24px; margin-bottom: 2px; line-height: 1.2; }
.tower-option-name {
    font-size: 9px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60px;
    text-align: center;
}
.tower-option-cost { font-size: 11px; color: var(--accent-gold); font-family: var(--font-display); font-weight: 700; }
.tower-option-air-label { font-size: 10px; color: var(--accent-cyan); position: absolute; top: 2px; left: 3px; }

.cancel-build-btn {
    width: 100%;
    margin-top: 8px;
    padding: 7px;
    border: 1px solid var(--accent-red);
    border-radius: var(--radius-sm);
    background: rgba(255, 51, 102, 0.08);
    color: var(--accent-red);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.25s;
    font-family: var(--font-body);
}

.cancel-build-btn:hover {
    background: rgba(255, 51, 102, 0.18);
    box-shadow: 0 0 12px rgba(255, 51, 102, 0.15);
}

/* === Tower Upgrade Panel (Card-style with stat comparison) === */
.tower-upgrade-selector {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    background: linear-gradient(160deg, rgba(12, 18, 35, 0.97), rgba(8, 12, 28, 0.98));
    backdrop-filter: blur(20px);
    border: 1px solid rgba(100, 200, 255, 0.12);
    border-radius: var(--radius-lg);
    padding: 18px 22px;
    text-align: center;
    min-width: 300px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.6),
        0 0 40px rgba(0, 229, 255, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: none;
    animation: selectorPopIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.tower-upgrade-selector.show { display: block; }

.panel-title {
    color: var(--accent-gold);
    font-family: var(--font-game);
    font-size: 18px;
    margin-bottom: 14px;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.2);
}

.tower-detail-info {
    font-size: 13px;
    line-height: 1.8;
    margin-bottom: 14px;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    text-align: left;
}

.tower-detail-info b { color: var(--accent-gold); }

/* Stat comparison arrows */
.stat-arrow {
    color: var(--accent-green);
    font-weight: 700;
    font-size: 11px;
    margin: 0 4px;
}

.upgrade-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.action-btn {
    padding: 9px 18px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(20, 30, 55, 0.7), rgba(15, 23, 42, 0.5));
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    font-family: var(--font-body);
    position: relative;
    overflow: hidden;
}

.action-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 60%);
    pointer-events: none;
}

.action-btn.upgrade {
    border-color: var(--accent-green);
    color: var(--accent-green);
    background: linear-gradient(145deg, rgba(0, 255, 136, 0.1), rgba(0, 255, 136, 0.03));
}
.action-btn.upgrade:hover {
    background: linear-gradient(145deg, rgba(0, 255, 136, 0.2), rgba(0, 255, 136, 0.08));
    box-shadow: 0 4px 16px rgba(0, 255, 136, 0.15);
    transform: translateY(-2px);
}
.action-btn.upgrade:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.action-btn.sell {
    border-color: var(--accent-orange);
    color: var(--accent-orange);
    background: linear-gradient(145deg, rgba(255, 140, 0, 0.1), rgba(255, 140, 0, 0.03));
}
.action-btn.sell:hover {
    background: linear-gradient(145deg, rgba(255, 140, 0, 0.2), rgba(255, 140, 0, 0.08));
    box-shadow: 0 4px 16px rgba(255, 140, 0, 0.15);
    transform: translateY(-2px);
}

.action-btn.close {
    border-color: var(--text-dim);
    color: var(--text-dim);
}
.action-btn.close:hover {
    border-color: var(--text-secondary);
    color: var(--text-secondary);
    transform: translateY(-2px);
}

/* === Tooltip (Enhanced) === */
#tower-info-tooltip {
    position: fixed;
    display: none;
    background: linear-gradient(160deg, rgba(12, 18, 35, 0.97), rgba(8, 12, 28, 0.98));
    backdrop-filter: blur(20px);
    border: 1px solid rgba(100, 200, 255, 0.15);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-secondary);
    z-index: 300;
    max-width: 240px;
    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(0, 229, 255, 0.03);
    animation: tooltipFade 0.15s ease-out;
}

@keyframes tooltipFade {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

#tower-info-tooltip b { color: var(--accent-gold); font-size: 14px; }
#tower-info-tooltip .tooltip-stat { color: var(--accent-cyan); font-family: var(--font-display); font-size: 11px; }
#tower-info-tooltip .tooltip-special { color: var(--accent-purple); font-style: italic; }
#tower-info-tooltip .tooltip-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(100, 200, 255, 0.15), transparent);
    margin: 6px 0;
}

/* === Spell Selector (Enhanced bar) === */
#spellSelector {
    position: fixed;
    z-index: 200;
    display: none;
    background: linear-gradient(160deg, rgba(12, 18, 35, 0.95), rgba(8, 12, 28, 0.97));
    backdrop-filter: blur(20px);
    border: 1px solid rgba(168, 85, 247, 0.15);
    border-radius: var(--radius-lg);
    padding: 12px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.5),
        0 0 30px rgba(168, 85, 247, 0.05);
    animation: selectorPopIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#spellSelector.show { display: block; }

.spell-options-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.spell-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 14px;
    border: 1.5px solid rgba(168, 85, 247, 0.2);
    border-radius: var(--radius-md);
    background: rgba(168, 85, 247, 0.04);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
    min-width: 60px;
}

.spell-option:hover {
    border-color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.12);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.15);
}

.spell-option.active {
    border-color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.18);
    box-shadow: var(--glow-magenta), 0 0 30px rgba(168, 85, 247, 0.1);
}

/* Spell cooldown overlay */
.spell-option .spell-cooldown-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    height: 0%;
    transition: height 0.1s linear;
    pointer-events: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.spell-option.on-cooldown {
    opacity: 0.5;
    cursor: not-allowed;
}

.spell-option-symbol { font-size: 26px; line-height: 1.2; }
.spell-option-name { font-size: 9px; color: var(--text-dim); margin-top: 2px; }
.spell-option-cost { font-size: 11px; color: var(--text-secondary); margin-top: 3px; font-family: var(--font-display); }

/* === Modals === */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(16px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.modal.show { display: flex; }

.modal-content {
    background: linear-gradient(160deg, rgba(17, 24, 39, 0.98), rgba(10, 14, 26, 0.99));
    border: 1px solid rgba(100, 200, 255, 0.1);
    border-radius: var(--radius-xl);
    padding: 36px;
    max-width: 520px;
    width: 92%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.7),
        0 0 80px rgba(0, 229, 255, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    animation: modalEntry 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalEntry {
    from { transform: scale(0.88) translateY(30px); opacity: 0; filter: blur(4px); }
    to { transform: scale(1) translateY(0); opacity: 1; filter: blur(0); }
}

.modal-title {
    text-align: center;
    font-family: var(--font-game);
    font-size: 24px;
    color: var(--accent-gold);
    margin-bottom: 20px;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.2);
}

.modal-btn {
    display: inline-block;
    padding: 12px 28px;
    border: 1px solid rgba(100, 200, 255, 0.12);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(20, 30, 55, 0.8), rgba(15, 23, 42, 0.6));
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin: 4px;
    font-family: var(--font-body);
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

.modal-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent 60%);
    pointer-events: none;
}

.modal-btn:hover {
    border-color: rgba(0, 229, 255, 0.3);
    background: rgba(0, 229, 255, 0.08);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), 0 0 15px rgba(0, 229, 255, 0.08);
}

.modal-btn:active {
    transform: translateY(0) scale(0.97);
}

.modal-btn.primary {
    border-color: rgba(0, 255, 136, 0.3);
    color: var(--accent-green);
    font-weight: 700;
    background: linear-gradient(145deg, rgba(0, 255, 136, 0.1), rgba(0, 255, 136, 0.03));
}
.modal-btn.primary:hover {
    background: rgba(0, 255, 136, 0.15);
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.15), 0 6px 24px rgba(0, 0, 0, 0.3);
}

/* === Math Modal (Upgraded - more engaging) === */
.math-modal {
    text-align: center;
    max-width: 480px;
}

.math-modal .modal-header {
    margin-bottom: 24px;
    position: relative;
}

.math-modal .modal-header h2 {
    color: var(--accent-gold);
    font-family: var(--font-game);
    font-size: 26px;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
}

.combo-badge {
    display: inline-block;
    padding: 4px 16px;
    font-family: var(--font-display);
    font-size: 12px;
    border-radius: 20px;
    margin-top: 10px;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(255, 140, 0, 0.15));
    border: 1px solid rgba(255, 215, 0, 0.3);
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
    animation: comboBadgePulse 1.5s ease-in-out infinite;
}

@keyframes comboBadgePulse {
    0%, 100% { box-shadow: 0 0 8px rgba(255, 215, 0, 0.2); }
    50% { box-shadow: 0 0 24px rgba(255, 215, 0, 0.4); }
}

/* Math countdown timer */
.math-timer {
    position: relative;
    margin-bottom: 16px;
}

.math-timer-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 2px;
    overflow: hidden;
}

.math-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-gold), var(--accent-red));
    border-radius: 2px;
    transition: width 0.1s linear;
    box-shadow: 0 0 8px rgba(0, 255, 136, 0.4);
}

.math-timer-fill.warning {
    animation: timerWarning 0.5s ease-in-out infinite;
}

@keyframes timerWarning {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.math-question {
    font-size: 28px;
    font-weight: 900;
    color: var(--text-primary);
    padding: 28px 24px;
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.5), rgba(10, 15, 30, 0.6));
    border-radius: var(--radius-lg);
    margin-bottom: 24px;
    border: 1px solid rgba(100, 200, 255, 0.1);
    box-shadow: inset 0 0 40px rgba(0, 229, 255, 0.03);
    font-family: var(--font-game);
    letter-spacing: 2px;
    position: relative;
    overflow: hidden;
}

.math-question::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg at 50% 50%, transparent 0%, rgba(0, 229, 255, 0.03) 25%, transparent 50%, rgba(255, 0, 229, 0.03) 75%, transparent 100%);
    animation: questionShine 6s linear infinite;
    pointer-events: none;
}

@keyframes questionShine {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.math-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.math-option {
    padding: 18px;
    border: 2px solid rgba(100, 200, 255, 0.12);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.7), rgba(20, 30, 55, 0.5));
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    font-family: var(--font-game);
    position: relative;
    overflow: hidden;
}

.math-option::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0, 229, 255, 0.1), rgba(255, 0, 229, 0.1));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.math-option:hover::before { opacity: 1; }

.math-option:hover {
    border-color: var(--accent-cyan);
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3), 0 0 20px rgba(0, 229, 255, 0.12);
}

.math-option:active {
    transform: translateY(0) scale(0.98);
}

.math-option.correct {
    border-color: var(--accent-green);
    background: rgba(0, 255, 136, 0.15);
    color: var(--accent-green);
    box-shadow: 0 0 30px rgba(0, 255, 136, 0.25), inset 0 0 25px rgba(0, 255, 136, 0.06);
    animation: correctPulse 0.5s ease-out;
}

@keyframes correctPulse {
    0% { transform: scale(1); }
    30% { transform: scale(1.08); }
    100% { transform: scale(1); }
}

.math-option.incorrect {
    border-color: var(--accent-red);
    background: rgba(255, 51, 102, 0.15);
    color: var(--accent-red);
    box-shadow: 0 0 20px rgba(255, 51, 102, 0.15);
    animation: incorrectShake 0.4s ease-out;
}

@keyframes incorrectShake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.math-option.faded { opacity: 0.2; pointer-events: none; }
.math-option:disabled { cursor: not-allowed; }

.math-result {
    font-size: 18px;
    font-weight: 700;
    padding: 10px;
    min-height: 36px;
    font-family: var(--font-game);
}

/* === Game Over Modal (Epic presentation) === */
.gameover-modal {
    text-align: center;
    position: relative;
    overflow: hidden;
}

.gameover-modal::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg at 50% 50%, transparent, rgba(255, 51, 102, 0.04), transparent, rgba(255, 51, 102, 0.03), transparent);
    animation: gameoverGlow 10s linear infinite;
    pointer-events: none;
}

@keyframes gameoverGlow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.gameover-icon {
    font-size: 72px;
    margin-bottom: 8px;
    animation: gameoverIconEntry 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    z-index: 1;
}

@keyframes gameoverIconEntry {
    0% { transform: scale(0) rotate(-180deg); opacity: 0; }
    60% { transform: scale(1.2) rotate(10deg); opacity: 1; }
    100% { transform: scale(1) rotate(0deg); }
}

.gameover-title {
    font-family: var(--font-game);
    font-size: 32px;
    color: var(--accent-red);
    margin-bottom: 24px;
    text-shadow: 0 0 40px rgba(255, 51, 102, 0.5), 0 0 80px rgba(255, 51, 102, 0.2);
    position: relative;
    z-index: 1;
    animation: gameoverTitlePulse 2s ease-in-out infinite;
}

@keyframes gameoverTitlePulse {
    0%, 100% { text-shadow: 0 0 30px rgba(255, 51, 102, 0.4); }
    50% { text-shadow: 0 0 50px rgba(255, 51, 102, 0.6), 0 0 80px rgba(255, 51, 102, 0.2); }
}

.gameover-stats {
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.5), rgba(10, 15, 30, 0.6));
    border-radius: var(--radius-lg);
    padding: 22px;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 51, 102, 0.12);
    box-shadow: inset 0 0 30px rgba(255, 51, 102, 0.03);
    position: relative;
    z-index: 1;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: center;
}

.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-secondary); font-size: 14px; }
.stat-value {
    color: var(--accent-gold);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 18px;
}

/* Animated score counter */
.stat-value.counting {
    animation: countPulse 0.1s ease-out;
}

@keyframes countPulse {
    0% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.name-input {
    width: 100%;
    padding: 14px 18px;
    border: 1.5px solid rgba(100, 200, 255, 0.12);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.4), rgba(10, 15, 30, 0.5));
    color: var(--text-primary);
    font-size: 16px;
    text-align: center;
    margin-bottom: 20px;
    outline: none;
    font-family: var(--font-body);
    transition: all 0.3s ease;
    letter-spacing: 1px;
    position: relative;
    z-index: 1;
}

.name-input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 24px rgba(0, 229, 255, 0.15), inset 0 0 20px rgba(0, 229, 255, 0.03);
}

.name-input::placeholder {
    color: var(--text-dim);
    letter-spacing: 0;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    position: relative;
    z-index: 1;
}

/* === Ranking Modal (Enhanced with medals) === */
.ranking-modal {
    text-align: center;
    position: relative;
}

.hall-of-fame-container {
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.4), rgba(20, 15, 5, 0.3));
    border: 1px solid rgba(255, 215, 0, 0.18);
    border-radius: var(--radius-lg);
    padding: 22px;
    margin-bottom: 24px;
    box-shadow: inset 0 0 40px rgba(255, 215, 0, 0.02);
    position: relative;
    overflow: hidden;
}

.hall-of-fame-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg at 50% 50%, transparent, rgba(255, 215, 0, 0.03), transparent, rgba(255, 215, 0, 0.02), transparent);
    animation: hofShine 8s linear infinite;
    pointer-events: none;
}

@keyframes hofShine {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.hof-title { color: var(--accent-gold); font-family: var(--font-game); margin-bottom: 14px; font-size: 17px; text-shadow: 0 0 20px rgba(255, 215, 0, 0.2); }

.hall-of-fame { text-align: left; }

.fame-entry {
    padding: 8px 8px;
    font-size: 14px;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.fame-entry:hover {
    background: rgba(255, 215, 0, 0.04);
    padding-left: 14px;
}

/* Medal effects for top 3 */
.fame-entry:nth-child(1) { color: #ffd700; font-weight: 700; text-shadow: 0 0 10px rgba(255, 215, 0, 0.3); }
.fame-entry:nth-child(2) { color: #c0c0c0; font-weight: 600; }
.fame-entry:nth-child(3) { color: #cd7f32; font-weight: 600; }

.ranking-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; }

.tab-btn {
    padding: 9px 22px;
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.25s;
    font-family: var(--font-body);
}

.tab-btn:hover {
    border-color: rgba(0, 229, 255, 0.3);
    color: var(--text-primary);
}

.tab-btn.active {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: rgba(0, 229, 255, 0.1);
    box-shadow: 0 0 15px rgba(0, 229, 255, 0.08);
}

.ranking-timer { font-size: 12px; color: var(--text-dim); margin-bottom: 12px; font-family: var(--font-display); }

.ranking-content { display: none; }
.ranking-content.active { display: block; }

.ranking-list {
    list-style: none;
    text-align: left;
    max-height: 250px;
    overflow-y: auto;
}

.ranking-list li {
    display: flex;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 13px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    border-radius: var(--radius-sm);
}

.ranking-list li:hover {
    background: rgba(0, 229, 255, 0.04);
    color: var(--text-primary);
}

/* Medal styling for ranking list top 3 */
.ranking-list li:nth-child(1) { color: #ffd700; font-weight: 700; background: rgba(255, 215, 0, 0.05); }
.ranking-list li:nth-child(2) { color: #c0c0c0; font-weight: 600; background: rgba(192, 192, 192, 0.03); }
.ranking-list li:nth-child(3) { color: #cd7f32; font-weight: 600; background: rgba(205, 127, 50, 0.03); }

/* Animated entry for ranking items */
.ranking-list li {
    animation: rankingSlideIn 0.3s ease-out backwards;
}

.ranking-list li:nth-child(1) { animation-delay: 0.05s; }
.ranking-list li:nth-child(2) { animation-delay: 0.1s; }
.ranking-list li:nth-child(3) { animation-delay: 0.15s; }
.ranking-list li:nth-child(4) { animation-delay: 0.2s; }
.ranking-list li:nth-child(5) { animation-delay: 0.25s; }

@keyframes rankingSlideIn {
    from { transform: translateX(-15px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* === Achievement Modal === */
.achievement-modal { text-align: center; }

.achievement-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
    text-align: left;
    max-height: 400px;
    overflow-y: auto;
}

.achievement-item {
    padding: 14px;
    border: 1px solid rgba(100, 200, 255, 0.06);
    border-radius: var(--radius-md);
    background: linear-gradient(145deg, rgba(0, 0, 0, 0.3), rgba(10, 15, 30, 0.4));
    transition: all 0.3s ease;
}

.achievement-item.unlocked {
    border-color: rgba(255, 215, 0, 0.25);
    background: linear-gradient(145deg, rgba(255, 215, 0, 0.06), rgba(255, 215, 0, 0.02));
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.05);
}

.achievement-item.locked { opacity: 0.35; filter: grayscale(0.5); }

.achievement-icon { font-size: 24px; margin-bottom: 4px; }
.achievement-name { font-size: 13px; font-weight: 700; color: var(--accent-gold); }
.achievement-desc { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* === Settings Modal (Modern sliders + toggles) === */
.settings-modal { text-align: center; max-width: 400px; }

.settings-group { margin-bottom: 24px; }

.setting-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 14px;
}

.volume-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: linear-gradient(90deg, rgba(0, 229, 255, 0.3), rgba(255, 0, 229, 0.3));
    border-radius: 3px;
    outline: none;
    transition: all 0.2s ease;
}

.volume-slider:hover {
    background: linear-gradient(90deg, rgba(0, 229, 255, 0.4), rgba(255, 0, 229, 0.4));
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px; height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-cyan), #0099cc);
    cursor: pointer;
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.volume-slider::-webkit-slider-thumb:hover {
    box-shadow: 0 0 24px rgba(0, 229, 255, 0.7), 0 2px 8px rgba(0, 0, 0, 0.4);
    transform: scale(1.15);
}

.volume-slider::-webkit-slider-thumb:active {
    transform: scale(0.95);
}

.volume-slider::-moz-range-thumb {
    width: 20px; height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-cyan), #0099cc);
    cursor: pointer;
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.volume-value { font-family: var(--font-display); font-size: 12px; color: var(--text-dim); min-width: 36px; text-align: right; }

/* === Wave Announce (Full-screen cinematic) === */
.wave-announce {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    background: radial-gradient(ellipse at 50% 50%, rgba(0, 0, 0, 0.4) 0%, transparent 70%);
    animation: waveAnnounceBg 2.5s ease-out forwards;
}

.wave-announce.hidden { display: none; }

.wave-announce-content {
    text-align: center;
    animation: waveAnnounceContent 2.5s ease-out forwards;
}

.wave-number {
    font-family: var(--font-display);
    font-size: 60px;
    font-weight: 900;
    color: var(--accent-gold);
    text-shadow:
        0 0 40px rgba(255, 215, 0, 0.6),
        0 0 80px rgba(255, 215, 0, 0.3),
        0 4px 8px rgba(0, 0, 0, 0.6);
    letter-spacing: 6px;
    text-transform: uppercase;
}

.wave-enemies {
    font-size: 15px;
    color: var(--text-secondary);
    margin-top: 10px;
    letter-spacing: 1px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

@keyframes waveAnnounceBg {
    0% { opacity: 0; }
    15% { opacity: 1; }
    75% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes waveAnnounceContent {
    0% { opacity: 0; transform: scale(0.4) translateY(20px); filter: blur(10px); }
    15% { opacity: 1; transform: scale(1.1) translateY(0); filter: blur(0); }
    25% { transform: scale(1); }
    75% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.95) translateY(-30px); filter: blur(4px); }
}

/* === Achievement Toast (Slide-in from right) === */
#achievement-toast-container {
    position: fixed;
    top: 60px;
    right: 16px;
    z-index: 400;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
}

.achievement-toast {
    padding: 12px 22px 12px 16px;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.15), rgba(17, 24, 39, 0.97));
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: var(--radius-lg);
    color: var(--accent-gold);
    font-size: 14px;
    font-weight: 700;
    animation: toastSlideIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), toastSlideOut 0.5s ease-in 2.5s forwards;
    box-shadow: 0 6px 24px rgba(255, 215, 0, 0.2), 0 0 40px rgba(255, 215, 0, 0.05);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
}

.achievement-toast .toast-icon {
    font-size: 22px;
    animation: toastIconBounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.3s backwards;
}

@keyframes toastSlideIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes toastSlideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(120%); opacity: 0; }
}

@keyframes toastIconBounce {
    0% { transform: scale(0) rotate(-45deg); }
    60% { transform: scale(1.3) rotate(10deg); }
    100% { transform: scale(1) rotate(0deg); }
}

/* === Message Popup === */
.message-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 14px 28px;
    background: linear-gradient(160deg, rgba(12, 18, 35, 0.95), rgba(8, 12, 28, 0.97));
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 700;
    z-index: 600;
    animation: msgPop 0.3s ease-out, msgFadeOut 0.4s ease-in 2.6s forwards;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

@keyframes msgPop {
    from { transform: translate(-50%, -50%) scale(0.8); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes msgFadeOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translate(-50%, -55%); }
}

.upgrade-notification {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.15), rgba(17, 24, 39, 0.95));
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 255, 136, 0.3);
    border-radius: var(--radius-lg);
    color: var(--accent-green);
    font-size: 14px;
    font-weight: 700;
    z-index: 600;
    animation: toastSlideIn 0.4s ease-out, toastSlideOut 0.4s ease-in 2.6s forwards;
    box-shadow: 0 4px 20px rgba(0, 255, 136, 0.2);
}

/* === Screen Shake === */
@keyframes shake {
    0%, 100% { transform: translate(0, 0); }
    10% { transform: translate(-5px, -3px); }
    20% { transform: translate(5px, 3px); }
    30% { transform: translate(-3px, 5px); }
    40% { transform: translate(3px, -5px); }
    50% { transform: translate(-5px, 3px); }
    60% { transform: translate(5px, -3px); }
    70% { transform: translate(-3px, -5px); }
    80% { transform: translate(3px, 5px); }
    90% { transform: translate(-5px, -3px); }
}

/* Heavy screen shake for big combos */
@keyframes heavyShake {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    10% { transform: translate(-8px, -5px) rotate(-0.5deg); }
    20% { transform: translate(8px, 5px) rotate(0.5deg); }
    30% { transform: translate(-5px, 8px) rotate(-0.3deg); }
    40% { transform: translate(5px, -8px) rotate(0.3deg); }
    50% { transform: translate(-8px, 5px) rotate(-0.5deg); }
    60% { transform: translate(8px, -5px) rotate(0.5deg); }
    70% { transform: translate(-5px, -8px) rotate(-0.3deg); }
    80% { transform: translate(5px, 8px) rotate(0.3deg); }
    90% { transform: translate(-8px, -5px) rotate(-0.5deg); }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, rgba(0, 229, 255, 0.3), rgba(255, 0, 229, 0.3)); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, rgba(0, 229, 255, 0.5), rgba(255, 0, 229, 0.5)); }

/* === Selection === */
::selection {
    background: rgba(0, 229, 255, 0.2);
    color: var(--accent-cyan);
}

/* === Utility animations === */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* === Mobile Responsive === */
@media (max-width: 768px) {
    .main-title { font-size: 36px; }
    .logo-castle { font-size: 64px; }
    .difficulty-btn { width: 74px; height: 78px; }
    .diff-grade { font-size: 26px; }
    .menu-container { padding: 36px 28px; }
    .info-item { padding: 3px 6px; font-size: 12px; }
    .info-value { font-size: 12px; }
    .math-question { font-size: 22px; padding: 20px; }
    .math-option { padding: 14px; font-size: 17px; }
    .wave-number { font-size: 42px; }
    .combo-count { font-size: 40px; }
    .modal-content { padding: 28px; }
    .ctrl-btn .key-hint { display: none; }
    .wave-progress-container { top: 40px; }
    .tower-options-container { grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); }
}

@media (max-width: 480px) {
    .main-title { font-size: 28px; }
    .logo-castle { font-size: 56px; }
    .menu-container { padding: 28px 20px; }
    .menu-actions { flex-direction: column; align-items: center; }
    .menu-btn { width: 100%; justify-content: center; }
    .difficulty-btn { width: 66px; height: 72px; }
    .diff-grade { font-size: 24px; }
    .wave-number { font-size: 32px; }
    .gameover-title { font-size: 26px; }
}
