/* ===== SYSADMIN DEFENSE: KERNEL PANIC v6.0 - MOBILE-FIRST STYLESHEET ===== */

/* ========================================================================
   APPROACH: Mobile-first — base styles target small screens.
   Larger screens override via @media (min-width: ...) breakpoints.
   Breakpoints: 480px (small phone→large phone), 768px (tablet), 1024px (desktop)
   ======================================================================== */

/* --- CSS Variables --- */
:root {
    /* Core palette */
    --bg-primary: #0a0a0a;
    --bg-secondary: #121212;
    --bg-tertiary: #1e1e1e;
    --bg-card: #1a1a2e;
    --border-color: #333;
    --border-glow: #00ff41;

    /* Text */
    --text-primary: #00ff41;
    --text-secondary: #00cc33;
    --text-muted: #668866;
    --text-white: #e0e0e0;

    /* Accents */
    --accent-red: #ff4444;
    --accent-yellow: #ffcc00;
    --accent-blue: #4488ff;
    --accent-purple: #aa44ff;
    --accent-cyan: #00ffaa;
    --accent-pink: #ff4488;

    /* Semantic */
    --danger: #ff2222;
    --success: #00ff41;
    --warning: #ffcc00;

    /* Typography */
    --font-mono: 'Courier New', Courier, monospace;
    --font-size-xs: 11px;
    --font-size-sm: 13px;
    --font-size-md: 15px;
    --font-size-lg: 18px;
    --font-size-xl: 24px;
    --font-size-xxl: 36px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Shadows */
    --shadow-glow: 0 0 20px rgba(0, 255, 65, 0.1);
    --shadow-glow-strong: 0 0 30px rgba(0, 255, 65, 0.25);

    /* Mobile-specific */
    --tap-target-min: 44px;
    --mobile-toolbar-height: 56px;
    --mobile-tower-strip-height: 72px;
    --side-panel-mobile-height: 55vh;
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --panel-transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow-x: hidden; }

body {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);      /* smaller base for mobile */
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: calc(var(--mobile-toolbar-height) + var(--safe-area-bottom) + 8px);
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-cyan); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--text-primary); text-decoration: underline; }
a:active { opacity: 0.7; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- CRT Scanline Overlay --- */
.crt-overlay {
    pointer-events: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    background: repeating-linear-gradient(
        0deg,
        rgba(0,0,0,0.03) 0px,
        rgba(0,0,0,0.03) 1px,
        transparent 1px,
        transparent 2px
    );
}

/* --- Animations --- */
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }
@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px var(--border-glow); }
    50%  { box-shadow: 0 0 20px var(--border-glow), 0 0 40px rgba(0,255,65,0.2); }
}
@keyframes slideDown { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideUp   { from { transform: translateY(20px);  opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn    { from { opacity: 0; } to { opacity: 1; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); } 20%, 40%, 60%, 80% { transform: translateX(4px); } }
@keyframes floatUp { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-40px); opacity: 0; } }
@keyframes achievementSlide { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes warningFlash { 0%, 100% { opacity: 0; } 10%, 30% { opacity: 1; } 20% { opacity: 0.5; } }
@keyframes comboPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.2); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slidePanelUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* --- Auth Page --- */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 16px;
    animation: fadeIn 0.5s ease;
}
.auth-box {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-glow);
    position: relative;
    overflow: hidden;
}
.auth-box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--text-primary), var(--accent-cyan), var(--text-primary));
    animation: glow 2s ease-in-out infinite;
}
.auth-title { text-align: center; font-size: var(--font-size-lg); color: var(--text-primary); margin-bottom: 8px; text-shadow: 0 0 10px rgba(0,255,65,0.5); }
.auth-subtitle { text-align: center; color: var(--text-muted); font-size: var(--font-size-sm); margin-bottom: 24px; }
.auth-tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid var(--border-color); }
.auth-tab {
    flex: 1;
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    color: var(--text-muted);
    background: transparent;
    border: none;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    transition: all var(--transition-fast);
    border-bottom: 2px solid transparent;
    min-height: var(--tap-target-min);
}
.auth-tab:hover { color: var(--text-primary); }
.auth-tab.active { color: var(--text-primary); border-bottom-color: var(--text-primary); background: rgba(0,255,65,0.05); }
.auth-form { display: none; }
.auth-form.active { display: block; animation: slideDown 0.3s ease; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; color: var(--text-secondary); font-size: var(--font-size-sm); }
.form-group input {
    width: 100%;
    padding: 14px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 16px;  /* prevent iOS zoom on focus */
    transition: border-color var(--transition-fast);
    min-height: var(--tap-target-min);
}
.form-group input:focus { outline: none; border-color: var(--text-primary); box-shadow: 0 0 10px rgba(0,255,65,0.15); }
.form-group input::placeholder { color: var(--text-muted); }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: 2px solid var(--text-primary);
    border-radius: 4px;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--font-size-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-transform: uppercase;
    letter-spacing: 1px;
    min-height: var(--tap-target-min);
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}
.btn:hover { background: var(--text-primary); color: var(--bg-primary); box-shadow: var(--shadow-glow-strong); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: transparent; color: var(--text-primary); box-shadow: none; }
.btn-primary { width: 100%; padding: 14px; font-size: var(--font-size-lg); font-weight: bold; }
.btn-danger { border-color: var(--accent-red); color: var(--accent-red); }
.btn-danger:hover { background: var(--accent-red); color: var(--bg-primary); }

.auth-message { padding: 10px 14px; border-radius: 4px; margin-bottom: 15px; font-size: var(--font-size-sm); display: none; }
.auth-message.error   { display: block; background: rgba(255,68,68,0.1);  border: 1px solid var(--accent-red);    color: var(--accent-red); }
.auth-message.success { display: block; background: rgba(0,255,65,0.1);   border: 1px solid var(--text-primary); color: var(--text-primary); }
.auth-footer { text-align: center; margin-top: 20px; font-size: var(--font-size-sm); color: var(--text-muted); }

/* --- Navigation Bar --- */
.nav-bar {
    width: 100%;
    max-width: 1200px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    padding-top: calc(8px + var(--safe-area-top));
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
    font-size: var(--font-size-sm);
    position: relative;
}
.nav-brand { font-weight: bold; font-size: var(--font-size-md); color: var(--text-primary); text-shadow: 0 0 8px rgba(0,255,65,0.4); white-space: nowrap; }

/* Hamburger toggle — hidden on desktop, shown on mobile */
.nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: var(--tap-target-min);
    height: var(--tap-target-min);
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    transition: border-color var(--transition-fast);
}
.nav-toggle:hover,
.nav-toggle:active { border-color: var(--text-primary); }
.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: all var(--transition-fast);
}
.nav-toggle.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.nav-toggle.active span:nth-child(2) { opacity: 0; }
.nav-toggle.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

.nav-links {
    display: none;                     /* hidden by default on mobile */
    flex-direction: column;
    position: absolute;
    top: 100%;
    left: 0; right: 0;
    background: var(--bg-tertiary);
    border-bottom: 2px solid var(--border-color);
    padding: 8px 12px;
    gap: 0;
    z-index: 500;
    animation: slideDown 0.25s ease;
}
.nav-links.mobile-open { display: flex; }
.nav-links a, .nav-links button {
    color: var(--text-secondary);
    background: none;
    border: none;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    cursor: pointer;
    padding: 12px 8px;
    transition: color var(--transition-fast);
    min-height: var(--tap-target-min);
    display: flex;
    align-items: center;
    width: 100%;
    text-align: left;
    border-bottom: 1px solid rgba(51,51,51,0.5);
}
.nav-links a:last-child, .nav-links button:last-child { border-bottom: none; }
.nav-links a:hover, .nav-links button:hover { color: var(--text-primary); text-decoration: none; }
.nav-user { color: var(--accent-cyan); font-weight: bold; }

/* --- Game Page --- */
.game-wrapper {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

/* Top HUD — mobile-first compact */
.hud-top {
    width: 100%;
    max-width: 900px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    padding-top: calc(6px + var(--safe-area-top));
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-bottom: none;
    font-size: var(--font-size-xs);
    flex-wrap: wrap;
    gap: 4px;
}
.hud-stat { display: flex; align-items: center; gap: 3px; white-space: nowrap; min-height: 28px; }
.hud-stat .label { color: var(--text-muted); }
.hud-stat .value { font-weight: bold; }
.hud-stat .value.red    { color: var(--accent-red); }
.hud-stat .value.yellow { color: var(--accent-yellow); }
.hud-stat .value.cyan   { color: var(--accent-cyan); }
.hud-stat .value.purple { color: var(--accent-purple); }

/* Mobile HUD — simplified */
.mobile-hud {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    padding: 4px 4px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: var(--font-size-xs);
    gap: 2px;
}
.mobile-hud .hud-stat { flex: 0 0 auto; }
.mobile-hud .hud-stat .label { display: none; }
.mobile-hud .hud-stat .value { font-size: var(--font-size-xs); }

/* HP & XP Bars */
.hp-bar-container { width: 100%; max-width: 900px; height: 8px; background: var(--bg-primary); border: 1px solid var(--border-color); }
.hp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-red), var(--accent-yellow), var(--text-primary)); transition: width 0.3s ease; }
.xp-bar-container { width: 100%; max-width: 900px; height: 6px; background: var(--bg-primary); border: 1px solid var(--border-color); border-top: none; }
.xp-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan)); transition: width 0.3s ease; }

/* Game Canvas — mobile: full width */
.game-canvas-container {
    position: relative;
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-glow);
    line-height: 0;
    max-width: 100%;
    overflow: hidden;
    width: 100%;
}
#gameCanvas { display: block; background-color: var(--bg-primary); cursor: crosshair; width: 100%; height: auto; }

/* Canvas wrapper — mobile: fullscreen */
.canvas-wrapper-mobile {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 100;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
}
.canvas-wrapper-mobile .game-canvas-container {
    flex: 1;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}
.canvas-wrapper-mobile #gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Side Panel — mobile: bottom sheet */
.game-layout { display: flex; flex-direction: column; gap: 0; max-width: 1200px; width: 100%; }

.side-panel {
    width: 100%;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-top: none;
    padding: 10px;
    padding-bottom: calc(10px + var(--safe-area-bottom));
    overflow-y: auto;
    max-height: var(--side-panel-mobile-height);
    font-size: var(--font-size-sm);
    /* Mobile: positioned as bottom sheet */
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 200;
    transform: translateY(calc(100% - 48px));
    transition: var(--panel-transition);
    border-radius: 16px 16px 0 0;
    border-top: 2px solid var(--border-color);
    border-left: none; border-right: none; border-bottom: none;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
}
.side-panel.mobile-open {
    transform: translateY(0);
}
.side-panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin: 0 auto 10px;
}

/* Panel toggle button (drag handle) */
.panel-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    padding: 0;
    margin-top: -6px;
    min-height: var(--tap-target-min);
    -webkit-user-select: none;
    user-select: none;
}
.panel-toggle-btn:hover { color: var(--text-primary); }
.panel-toggle-btn::after { content: '▲ TOWER PANEL'; letter-spacing: 1px; }
.side-panel.mobile-open .panel-toggle-btn::after { content: '▼ CLOSE PANEL'; }

.panel-section { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border-color); }
.panel-section:last-child { border-bottom: none; }
.panel-title { font-size: var(--font-size-sm); color: var(--accent-cyan); margin-bottom: 8px; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; }

/* Tower Grid — mobile: compact 3-column */
.tower-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tower-btn {
    padding: 8px 4px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: center;
    line-height: 1.3;
    position: relative;
    min-height: var(--tap-target-min);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}
.tower-btn:hover { border-color: var(--text-primary); color: var(--text-primary); background: rgba(0,255,65,0.05); }
.tower-btn:active { transform: scale(0.95); }
.tower-btn.selected { border-color: var(--text-primary); background: rgba(0,255,65,0.1); color: var(--text-primary); box-shadow: 0 0 8px rgba(0,255,65,0.2); }
.tower-btn.locked { opacity: 0.3; cursor: not-allowed; }
.tower-btn .tower-name { display: block; font-weight: bold; margin-bottom: 2px; }
.tower-btn .tower-cost { display: block; color: var(--accent-yellow); font-size: 10px; }

/* Ability List */
.ability-list { display: flex; flex-direction: column; gap: 6px; }
.ability-btn {
    padding: 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    position: relative;
    min-height: var(--tap-target-min);
    display: flex;
    align-items: center;
    touch-action: manipulation;
}
.ability-btn:hover:not(.locked):not(.on-cooldown) { border-color: var(--accent-cyan); color: var(--accent-cyan); }
.ability-btn:active:not(.locked):not(.on-cooldown) { transform: scale(0.97); }
.ability-btn.locked { opacity: 0.3; cursor: not-allowed; }
.ability-btn.on-cooldown { opacity: 0.5; cursor: not-allowed; }
.ability-btn .ability-name { font-weight: bold; display: block; }
.ability-btn .ability-info { color: var(--text-muted); font-size: 10px; }
.ability-btn .cooldown-overlay { position: absolute; bottom: 0; left: 0; height: 3px; background: var(--accent-cyan); transition: width 0.1s linear; }

/* Control Buttons */
.game-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.ctrl-btn {
    padding: 8px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex: 1;
    text-align: center;
    min-height: var(--tap-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.ctrl-btn:hover { border-color: var(--text-primary); color: var(--text-primary); }
.ctrl-btn:active { transform: scale(0.95); }
.ctrl-btn.active { background: rgba(0,255,65,0.1); border-color: var(--text-primary); color: var(--text-primary); }

/* ===== v3.0+ STYLES ===== */

/* Speed Controls */
.speed-controls { display: none; gap: 2px; margin-left: 4px; }   /* hidden on mobile by default */
.speed-btn {
    padding: 4px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: var(--tap-target-min);
    min-width: var(--tap-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.speed-btn:hover { border-color: var(--accent-yellow); color: var(--accent-yellow); }
.speed-btn.active { background: rgba(255,204,0,0.15); border-color: var(--accent-yellow); color: var(--accent-yellow); }

/* Mute Button */
.mute-btn {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 14px;
    cursor: pointer;
    padding: 4px 10px;
    transition: all var(--transition-fast);
    line-height: 1;
    min-height: var(--tap-target-min);
    min-width: var(--tap-target-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}
.mute-btn:hover { border-color: var(--text-primary); color: var(--text-primary); }
.mute-btn.muted { color: var(--accent-red); border-color: var(--accent-red); opacity: 0.6; }

/* Wave Preview */
.wave-preview { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-height: 20px; }
.wave-preview .preview-enemy { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3); }
.wave-preview .preview-boss  { width: 16px; height: 16px; border-radius: 0; transform: rotate(45deg); border: 1px solid #ffffff; }
.wave-preview .preview-label { font-size: 10px; color: var(--text-muted); margin-right: 4px; }

/* Selected Tower Panel */
.tower-action-buttons { display: flex; gap: 6px; margin-top: 8px; }
.tower-action-buttons .ctrl-btn { flex: 1; }
.upgrade-btn { border-color: var(--accent-cyan) !important; color: var(--accent-cyan) !important; }
.upgrade-btn:hover { background: rgba(0,255,170,0.1) !important; }
.upgrade-btn:disabled { opacity: 0.3 !important; cursor: not-allowed !important; border-color: var(--border-color) !important; color: var(--text-muted) !important; }
.sell-btn { border-color: var(--accent-red) !important; color: var(--accent-red) !important; }
.sell-btn:hover { background: rgba(255,68,68,0.1) !important; }

/* Synergy List */
.synergy-list { display: flex; flex-direction: column; gap: 4px; }
.synergy-item { padding: 4px 8px; background: rgba(255,68,136,0.08); border: 1px solid rgba(255,68,136,0.3); border-radius: 3px; font-size: 10px; color: var(--accent-pink); }
.synergy-item .synergy-name { font-weight: bold; }
.synergy-item .synergy-bonus { color: var(--text-muted); margin-left: 4px; }

/* Disguised Enemy Warning */
.disguised-warning {
    position: absolute;
    top: 10px; left: 50%;
    transform: translateX(-50%);
    background: rgba(255,68,68,0.9);
    color: #fff;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: bold;
    padding: 6px 14px;
    border-radius: 4px;
    z-index: 60;
    pointer-events: none;
    opacity: 0;
    display: none;
    text-shadow: 0 0 5px rgba(0,0,0,0.5);
    white-space: nowrap;
}
.disguised-warning.visible { display: block; animation: warningFlash 2s ease forwards; }

/* Endless Mode Indicator */
.endless-indicator {
    position: absolute;
    top: 40px; left: 10px;
    background: rgba(170,68,255,0.8);
    color: #fff;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: bold;
    padding: 3px 10px;
    border-radius: 3px;
    z-index: 60;
    pointer-events: none;
    animation: pulse 2s ease-in-out infinite;
}

/* Daily & Endless buttons */
.daily-btn { border-color: var(--accent-yellow) !important; color: var(--accent-yellow) !important; }
.daily-btn:hover { background: rgba(255,204,0,0.1) !important; }
.endless-btn { border-color: var(--accent-purple) !important; color: var(--accent-purple) !important; display: block !important; }
.endless-btn:hover { background: rgba(170,68,255,0.15) !important; box-shadow: 0 0 10px rgba(170,68,255,0.3); }

/* Combo Counter in HUD */
#hud-combo { font-weight: bold; animation: comboPulse 0.3s ease; }

/* Achievement Popup */
.achievement-popup-container {
    position: fixed;
    bottom: calc(80px + var(--safe-area-bottom));
    right: 8px;
    left: 8px;
    z-index: 10001;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}
.achievement-popup {
    padding: 12px 14px;
    background: var(--bg-tertiary);
    border: 2px solid var(--accent-yellow);
    border-radius: 6px;
    box-shadow: 0 0 20px rgba(255,204,0,0.3);
    animation: achievementSlide 0.5s ease forwards;
    max-width: 300px;
    pointer-events: auto;
    margin-left: auto;
}
.achievement-popup .ach-title { color: var(--accent-yellow); font-weight: bold; font-size: var(--font-size-sm); margin-bottom: 2px; text-transform: uppercase; letter-spacing: 1px; }
.achievement-popup .ach-name  { color: var(--text-white); font-size: var(--font-size-md); font-weight: bold; }
.achievement-popup .ach-desc  { color: var(--text-muted); font-size: var(--font-size-xs); margin-top: 2px; }
.achievement-popup .ach-xp    { color: var(--accent-cyan); font-size: 10px; margin-top: 4px; }

/* Tower Tooltip */
.tooltip {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--text-primary);
    border-radius: 4px;
    padding: 10px 14px;
    font-size: var(--font-size-xs);
    color: var(--text-white);
    z-index: 200;
    pointer-events: none;
    max-width: 220px;
    box-shadow: var(--shadow-glow);
    display: none;
}
.tooltip.visible { display: block; }
.tooltip .tip-title  { color: var(--text-primary); font-weight: bold; margin-bottom: 4px; font-size: var(--font-size-sm); }
.tooltip .tip-desc   { color: var(--text-muted); line-height: 1.4; margin-bottom: 4px; }
.tooltip .tip-stats  { color: var(--accent-cyan); line-height: 1.5; }
.tooltip .tip-stats span { color: var(--accent-yellow); font-weight: bold; }
.tooltip .tip-synergy { color: var(--accent-pink); margin-top: 4px; font-style: italic; }

/* --- Floating Damage Text --- */
.float-text { position: absolute; pointer-events: none; font-family: var(--font-mono); font-weight: bold; animation: floatUp 0.8s ease forwards; text-shadow: 0 0 4px rgba(0,0,0,0.8); z-index: 100; }

/* --- Game Over / Level Complete Overlay --- */
.game-overlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.9);
    z-index: 50;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-align: center;
    animation: fadeIn 0.5s ease;
    padding: 20px;
}
.game-overlay.visible { display: flex; }
.overlay-title { font-size: var(--font-size-xl); margin-bottom: 10px; text-shadow: 0 0 20px currentColor; }
.overlay-title.red  { color: var(--accent-red); }
.overlay-title.green { color: var(--text-primary); }
.overlay-stats { margin: 15px 0; font-size: var(--font-size-sm); color: var(--text-white); line-height: 2; }
.overlay-buttons { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; justify-content: center; }

/* --- Wave Announcement --- */
.wave-announce {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--font-size-xl);
    color: var(--text-primary);
    text-shadow: 0 0 30px var(--text-primary);
    z-index: 40;
    pointer-events: none;
    animation: fadeIn 0.3s ease;
    opacity: 0;
    transition: opacity 0.5s ease;
    white-space: nowrap;
}
.wave-announce.visible { opacity: 1; }

/* --- Level Select --- */
.level-select-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 10px 0; }
.level-cell {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-muted);
    min-height: var(--tap-target-min);
    touch-action: manipulation;
}
.level-cell:hover { border-color: var(--text-primary); color: var(--text-primary); }
.level-cell.completed { background: rgba(0,255,65,0.1); border-color: var(--text-primary); color: var(--text-primary); }
.level-cell.current   { background: rgba(0,255,170,0.15); border-color: var(--accent-cyan); color: var(--accent-cyan); animation: pulse 1.5s infinite; }
.level-cell.locked    { opacity: 0.25; cursor: not-allowed; }
.level-cell.boss      { border-color: var(--accent-purple); }
.level-cell.boss.completed { border-color: var(--accent-purple); color: var(--accent-purple); background: rgba(170,68,255,0.1); }

/* --- Ranking Page --- */
.ranking-container { width: 100%; max-width: 900px; padding: 16px; animation: fadeIn 0.5s ease; }
.ranking-header { text-align: center; margin-bottom: 20px; }
.ranking-header h1 { font-size: var(--font-size-xl); color: var(--text-primary); text-shadow: 0 0 15px rgba(0,255,65,0.5); margin-bottom: 8px; }
.ranking-controls { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.sort-btn {
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: var(--tap-target-min);
    touch-action: manipulation;
}
.sort-btn:hover, .sort-btn.active { border-color: var(--text-primary); color: var(--text-primary); background: rgba(0,255,65,0.05); }
.ranking-table { width: 100%; border-collapse: collapse; font-size: var(--font-size-xs); }
.ranking-table th { padding: 10px 8px; text-align: left; color: var(--text-secondary); border-bottom: 2px solid var(--border-color); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.ranking-table td { padding: 8px 6px; border-bottom: 1px solid rgba(51,51,51,0.5); color: var(--text-white); }
.ranking-table tr:hover { background: rgba(0,255,65,0.03); }
.ranking-table .rank-top td { color: var(--accent-yellow); font-weight: bold; }
.ranking-table .rank-top:hover { background: rgba(255,204,0,0.05); }
.your-row td { background: rgba(0,255,65,0.05) !important; color: var(--text-primary) !important; }

/* --- Profile Page --- */
.profile-container { width: 100%; max-width: 900px; padding: 16px; padding-bottom: calc(60px + var(--safe-area-bottom)); animation: fadeIn 0.5s ease; }
.profile-header { text-align: center; margin-bottom: 16px; }
.profile-header h1 { color: var(--text-primary); font-size: var(--font-size-xl); text-shadow: 0 0 15px rgba(0,255,65,0.5); }
.profile-section { margin-bottom: 20px; }
.profile-section h2 { color: var(--accent-cyan); border-bottom: 1px solid var(--border-color); padding-bottom: 6px; margin-bottom: 10px; font-size: var(--font-size-md); }
.profile-stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
.profile-stat-card { background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 6px; padding: 12px 8px; text-align: center; }
.profile-stat-card .stat-value { font-size: var(--font-size-lg); font-weight: bold; display: block; margin-bottom: 4px; }
.profile-stat-card .stat-value.cyan   { color: var(--accent-cyan); }
.profile-stat-card .stat-value.purple { color: var(--accent-purple); }
.profile-stat-card .stat-value.yellow { color: var(--accent-yellow); }
.profile-stat-card .stat-value.green  { color: var(--text-primary); }
.profile-stat-card .stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.profile-detail-grid { display: grid; grid-template-columns: 1fr; gap: 0 20px; }
.achievement-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.achievement-card { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--bg-tertiary); border: 1px solid var(--border-color); border-radius: 4px; transition: all var(--transition-fast); }
.achievement-card.unlocked { border-color: var(--accent-yellow); background: rgba(255,204,0,0.05); }
.achievement-card.locked   { opacity: 0.4; }
.achievement-card .ach-icon { font-size: 20px; width: 30px; text-align: center; flex-shrink: 0; }
.achievement-card .ach-info { flex: 1; min-width: 0; }
.achievement-card .ach-name { font-weight: bold; font-size: var(--font-size-sm); color: var(--text-white); }
.achievement-card.unlocked .ach-name { color: var(--accent-yellow); }
.achievement-card .ach-desc { font-size: 10px; color: var(--text-muted); }
.achievement-card .ach-xp   { font-size: 10px; color: var(--accent-cyan); white-space: nowrap; }

/* --- Loading Spinner --- */
.spinner { width: 30px; height: 30px; border: 3px solid var(--border-color); border-top-color: var(--text-primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 20px auto; }

/* --- Notification Toast --- */
.toast-container {
    position: fixed;
    top: calc(12px + var(--safe-area-top));
    left: 8px; right: 8px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.toast {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    box-shadow: var(--shadow-glow);
    animation: slideDown 0.3s ease;
    max-width: 100%;
    pointer-events: auto;
}
.toast.error      { border-color: var(--accent-red);    color: var(--accent-red); }
.toast.success    { border-color: var(--text-primary); }
.toast.warning    { border-color: var(--accent-yellow); color: var(--accent-yellow); }
.toast.fade-out   { opacity: 0; transition: opacity 0.5s ease; }
.toast.info       { border-color: var(--accent-cyan);   color: var(--accent-cyan); }
.toast.achievement { border-color: var(--accent-yellow); color: var(--accent-yellow); background: rgba(255,204,0,0.05); }

/* --- Info/Detail panels --- */
.info-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: var(--font-size-xs); }
.info-row .info-label { color: var(--text-muted); }
.info-row .info-value { color: var(--text-white); font-weight: bold; }

/* --- Footer Banner --- */
.site-footer {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    z-index: 9998;
    padding: 8px 12px;
    padding-bottom: calc(8px + var(--safe-area-bottom));
    background: var(--bg-tertiary);
    border-top: 2px solid var(--border-color);
    text-align: center;
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.6;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.5);
}
.footer-inner { max-width: 1200px; margin: 0 auto; display: flex; justify-content: center; align-items: center; gap: 6px; flex-wrap: wrap; }
.footer-inner strong { color: var(--text-secondary); }
.footer-inner a { color: var(--accent-cyan); transition: color var(--transition-fast); }
.footer-inner a:hover { color: var(--text-primary); text-decoration: underline; }
.footer-sep { color: var(--border-color); margin: 0 4px; }

/* --- Guide Page --- */
.guide-container { width: 100%; max-width: 900px; padding: 16px; padding-bottom: calc(40px + var(--safe-area-bottom)); animation: fadeIn 0.5s ease; }
.guide-container h1 { text-align: center; color: var(--text-primary); text-shadow: 0 0 15px rgba(0,255,65,0.5); margin-bottom: 5px; font-size: var(--font-size-xl); }
.guide-container h2 { color: var(--accent-cyan); border-bottom: 1px solid var(--border-color); padding-bottom: 6px; margin-top: 24px; margin-bottom: 10px; font-size: var(--font-size-md); }
.guide-container h3 { color: var(--accent-yellow); margin-top: 14px; margin-bottom: 6px; font-size: var(--font-size-sm); }
.guide-container p  { color: var(--text-white); line-height: 1.7; margin-bottom: 10px; font-size: var(--font-size-sm); }
.guide-container ul { list-style: none; padding-left: 0; margin-bottom: 12px; }
.guide-container ul li { color: var(--text-white); font-size: var(--font-size-sm); line-height: 1.7; padding-left: 18px; position: relative; margin-bottom: 4px; }
.guide-container ul li::before { content: '>'; position: absolute; left: 0; color: var(--text-primary); font-weight: bold; }
.guide-table { width: 100%; border-collapse: collapse; margin: 12px 0 18px; font-size: var(--font-size-xs); display: block; overflow-x: auto; }
.guide-table th { background: var(--bg-tertiary); color: var(--accent-cyan); padding: 8px 8px; text-align: left; border: 1px solid var(--border-color); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; }
.guide-table td { padding: 6px 8px; border: 1px solid var(--border-color); color: var(--text-white); vertical-align: top; }
.guide-table tr:hover td { background: rgba(0,255,65,0.03); }
.color-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.key-badge { display: inline-block; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: 3px; padding: 1px 6px; font-size: 11px; color: var(--text-primary); font-family: var(--font-mono); }
.tip-box { background: rgba(0,255,65,0.05); border: 1px solid var(--text-primary); border-radius: 4px; padding: 12px 14px; margin: 12px 0; font-size: var(--font-size-sm); color: var(--text-white); }
.tip-box strong { color: var(--accent-yellow); }

/* ===== v4.0+ STYLES ===== */

/* Wave Progress Bar */
.wave-progress-container { width: 100%; max-width: 900px; height: 5px; background: var(--bg-primary); border: 1px solid var(--border-color); border-top: none; position: relative; }
.wave-progress-fill { height: 100%; background: linear-gradient(90deg, var(--accent-purple), var(--accent-pink)); transition: width 0.3s ease; }
.wave-progress-text { position: absolute; right: 6px; top: -1px; font-size: 9px; color: var(--text-muted); line-height: 5px; }

/* Start Wave Button */
.start-wave-btn {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    padding: 14px 28px;
    background: rgba(0, 255, 170, 0.15);
    border: 2px solid var(--accent-cyan);
    border-radius: 6px;
    color: var(--accent-cyan);
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    z-index: 55;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: all var(--transition-fast);
    animation: pulse 1.5s ease-in-out infinite;
    min-height: var(--tap-target-min);
    touch-action: manipulation;
}
.start-wave-btn:hover { background: rgba(0, 255, 170, 0.3); box-shadow: 0 0 20px rgba(0, 255, 170, 0.4); }

/* =====================================================================
   MOBILE-SPECIFIC NEW COMPONENTS
   ===================================================================== */

/* --- Mobile Bottom Toolbar --- */
.mobile-toolbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--mobile-toolbar-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: var(--bg-tertiary);
    border-top: 2px solid var(--border-color);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.5);
    z-index: 300;
    align-items: center;
    justify-content: space-around;
    gap: 2px;
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}
.mobile-toolbar-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    min-height: var(--tap-target-min);
    max-width: 80px;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 9px;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 4px 2px;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}
.mobile-toolbar-btn .btn-icon {
    font-size: 20px;
    line-height: 1;
}
.mobile-toolbar-btn .btn-label {
    font-size: 9px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}
.mobile-toolbar-btn:active {
    background: rgba(0,255,65,0.1);
    border-color: var(--text-primary);
    color: var(--text-primary);
    transform: scale(0.93);
}
.mobile-toolbar-btn.active {
    color: var(--text-primary);
    border-color: var(--border-glow);
    background: rgba(0,255,65,0.08);
}
.mobile-toolbar-btn.btn-pause .btn-icon { color: var(--accent-yellow); }
.mobile-toolbar-btn.btn-speed .btn-icon { color: var(--accent-cyan); }
.mobile-toolbar-btn.btn-wave .btn-icon  { color: var(--accent-pink); }

/* --- Mobile Tower Strip --- */
.mobile-tower-strip {
    display: flex;
    position: fixed;
    bottom: calc(var(--mobile-toolbar-height) + var(--safe-area-bottom));
    left: 0; right: 0;
    height: var(--mobile-tower-strip-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    box-shadow: 0 -1px 8px rgba(0,0,0,0.4);
    z-index: 290;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    gap: 6px;
    padding: 6px 8px;
    padding-left: calc(8px + var(--safe-area-left));
    padding-right: calc(8px + var(--safe-area-right));
    scrollbar-width: none;
}
.mobile-tower-strip::-webkit-scrollbar { display: none; }
.mobile-tower-strip .tower-btn {
    flex: 0 0 60px;
    scroll-snap-align: start;
    min-height: 60px;
    min-width: 60px;
    padding: 6px 4px;
    border-radius: 8px;
    font-size: 10px;
}
.mobile-tower-strip .tower-btn .tower-name { font-size: 9px; margin-bottom: 1px; }
.mobile-tower-strip .tower-btn .tower-cost { font-size: 8px; }

/* --- Mobile Ability Bar --- */
.mobile-ability-bar {
    display: none;
    position: fixed;
    bottom: calc(var(--mobile-toolbar-height) + var(--mobile-tower-strip-height) + var(--safe-area-bottom) + 4px);
    left: var(--safe-area-left);
    right: var(--safe-area-right);
    z-index: 285;
    gap: 6px;
    padding: 4px 8px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.mobile-ability-bar::-webkit-scrollbar { display: none; }
.mobile-ability-bar .ability-btn {
    flex: 0 0 auto;
    min-width: 80px;
    min-height: 40px;
    padding: 6px 10px;
    font-size: 10px;
    white-space: nowrap;
    border-radius: 6px;
}

/* --- Mobile Wave Start Button --- */
.mobile-wave-btn {
    display: none;
    position: fixed;
    bottom: calc(var(--mobile-toolbar-height) + var(--mobile-tower-strip-height) + var(--safe-area-bottom) + 12px);
    left: 50%;
    transform: translateX(-50%);
    padding: 14px 32px;
    background: rgba(0, 255, 170, 0.2);
    border: 2px solid var(--accent-cyan);
    border-radius: 30px;
    color: var(--accent-cyan);
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    z-index: 55;
    text-transform: uppercase;
    letter-spacing: 2px;
    animation: pulse 1.5s ease-in-out infinite;
    min-height: 52px;
    min-width: 160px;
    touch-action: manipulation;
    box-shadow: 0 0 20px rgba(0, 255, 170, 0.3);
}
.mobile-wave-btn:active {
    transform: translateX(-50%) scale(0.95);
    background: rgba(0, 255, 170, 0.4);
}

/* --- Mobile Overlay (full-screen variant) --- */
.mobile-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.95);
    z-index: 400;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: calc(16px + var(--safe-area-top)) 16px calc(16px + var(--safe-area-bottom));
    animation: fadeIn 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.mobile-overlay .overlay-title { font-size: var(--font-size-xl); margin-bottom: 16px; }
.mobile-overlay .overlay-stats { font-size: var(--font-size-sm); line-height: 2.2; }
.mobile-overlay .overlay-buttons { flex-direction: column; width: 100%; max-width: 320px; gap: 12px; margin-top: 24px; }
.mobile-overlay .overlay-buttons .btn { width: 100%; }

/* =====================================================================
   RESPONSIVE BREAKPOINTS — Mobile First (min-width)
   ===================================================================== */

/* ---- Small phone (≥480px) ---- */
@media (min-width: 480px) {
    body { font-size: var(--font-size-md); }

    .hud-top { font-size: var(--font-size-sm); padding: 8px 12px; }

    .level-select-grid { grid-template-columns: repeat(7, 1fr); }
    .tower-grid { grid-template-columns: repeat(4, 1fr); }

    .auth-box { padding: 30px; }
    .auth-title { font-size: var(--font-size-xl); }

    .overlay-title { font-size: var(--font-size-xxl); }

    .mobile-tower-strip .tower-btn {
        flex: 0 0 68px;
        min-height: 64px;
        min-width: 68px;
    }

    .achievement-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
}

/* ---- Tablet (≥768px) ---- */
@media (min-width: 768px) {
    /* Navigation restores to horizontal */
    .nav-toggle { display: none; }
    .nav-links {
        display: flex;
        flex-direction: row;
        position: static;
        background: none;
        border: none;
        padding: 0;
        gap: 20px;
    }
    .nav-links a, .nav-links button {
        padding: 4px 8px;
        min-height: auto;
        width: auto;
        border-bottom: none;
        font-size: var(--font-size-sm);
    }

    /* HUD larger */
    .hud-top { font-size: var(--font-size-sm); padding: 8px 14px; }

    /* Game layout side-by-side */
    .game-layout { flex-direction: row; align-items: flex-start; }

    /* Side panel becomes sidebar */
    .side-panel {
        position: static;
        transform: none;
        width: 280px;
        min-width: 280px;
        max-height: 604px;
        border-radius: 0;
        border: 2px solid var(--border-color);
        border-left: none;
        border-top: 2px solid var(--border-color);
        box-shadow: none;
        padding-bottom: 10px;
        transition: none;
    }
    .side-panel::before { display: none; }
    .side-panel.mobile-open { transform: none; }
    .panel-toggle-btn { display: none; }

    /* Tower grid wider */
    .tower-grid { grid-template-columns: repeat(4, 1fr); }

    /* Canvas not full width */
    #gameCanvas { width: auto; max-width: 100%; }

    /* Hide mobile-specific components on tablet+ */
    .mobile-toolbar { display: none; }
    .mobile-tower-strip { display: none; }
    .mobile-ability-bar { display: none; }
    .mobile-wave-btn { display: none; }
    .mobile-hud { display: none; }
    .canvas-wrapper-mobile { position: static; background: none; }

    /* Show speed controls */
    .speed-controls { display: flex; }

    /* Restore body padding */
    body { padding-bottom: 48px; font-size: var(--font-size-md); }

    /* Overlays */
    .game-overlay { padding: 20px; }
    .overlay-title { font-size: var(--font-size-xxl); }

    /* Level select wider */
    .level-select-grid { grid-template-columns: repeat(10, 1fr); }

    /* Profile */
    .profile-stats-grid { grid-template-columns: repeat(4, 1fr); }
    .profile-detail-grid { grid-template-columns: 1fr 1fr; }
    .profile-header h1 { font-size: var(--font-size-xxl); }
    .profile-container { padding: 20px 25px 60px; }

    /* Ranking */
    .ranking-container { padding: 20px; }
    .ranking-header h1 { font-size: var(--font-size-xxl); }
    .ranking-table { font-size: var(--font-size-sm); }

    /* Guide */
    .guide-container { padding: 20px 25px 40px; }
    .guide-container h1 { font-size: var(--font-size-xxl); }
    .guide-container h2 { font-size: var(--font-size-lg); margin-top: 30px; }
    .guide-table { display: table; }

    /* Achievement popups */
    .achievement-popup-container { left: auto; right: 20px; bottom: 60px; }

    /* Toast */
    .toast-container { left: auto; right: 20px; }

    /* Auth */
    .auth-title { font-size: var(--font-size-xl); }
    .auth-subtitle { margin-bottom: 30px; }

    /* Disguised warning */
    .disguised-warning { font-size: 14px; padding: 8px 20px; }

    /* Endless indicator */
    .endless-indicator { font-size: 12px; padding: 4px 12px; }

    /* Panel title */
    .panel-title { font-size: var(--font-size-md); }

    /* Wave announce */
    .wave-announce { font-size: var(--font-size-xxl); }

    /* Start wave btn */
    .start-wave-btn { font-size: 16px; padding: 12px 30px; }

    /* Sort buttons */
    .sort-btn { padding: 8px 16px; font-size: var(--font-size-sm); }

    /* Ranking table */
    .ranking-table th { padding: 12px 10px; }
    .ranking-table td { padding: 10px; }
}

/* ---- Desktop (≥1024px) ---- */
@media (min-width: 1024px) {
    .nav-bar { padding: 8px 16px; }
    .nav-brand { font-size: var(--font-size-lg); }

    .hud-top { max-width: 900px; }
    .hp-bar-container, .xp-bar-container, .wave-progress-container { max-width: 900px; }

    .tower-grid { grid-template-columns: repeat(5, 1fr); }

    .side-panel { max-height: 604px; }

    /* Tower button sizes back to normal */
    .tower-btn { padding: 8px 6px; min-height: auto; font-size: var(--font-size-xs); }
    .ctrl-btn { padding: 6px 12px; min-height: auto; font-size: var(--font-size-xs); }
    .speed-btn { padding: 2px 8px; min-height: auto; min-width: auto; }
    .mute-btn { padding: 2px 8px; min-height: auto; min-width: auto; }
    .ability-btn { padding: 8px 10px; min-height: auto; }

    .level-cell { min-height: auto; }

    /* Form inputs */
    .form-group input { font-size: var(--font-size-md); padding: 12px 14px; min-height: auto; }
}

/* =====================================================================
   LANDSCAPE MODE FOR MOBILE PHONES
   ===================================================================== */
@media (max-width: 1023px) and (orientation: landscape) {
    .mobile-toolbar {
        height: calc(44px + var(--safe-area-bottom));
        flex-direction: row;
    }
    .mobile-toolbar-btn {
        flex-direction: row;
        gap: 4px;
        min-height: 40px;
    }
    .mobile-toolbar-btn .btn-label { font-size: 8px; }

    .mobile-tower-strip {
        height: 54px;
        bottom: calc(44px + var(--safe-area-bottom));
    }
    .mobile-tower-strip .tower-btn {
        flex: 0 0 50px;
        min-height: 44px;
        min-width: 50px;
    }

    .mobile-ability-bar {
        bottom: calc(44px + 54px + var(--safe-area-bottom) + 4px);
    }

    .mobile-wave-btn {
        bottom: calc(44px + 54px + var(--safe-area-bottom) + 8px);
        padding: 10px 24px;
        font-size: 12px;
        min-height: 44px;
        min-width: 120px;
    }

    /* Side panel in landscape is a compact drawer */
    .side-panel {
        max-height: 80vh;
        border-radius: 12px 12px 0 0;
    }

    /* Compact HUD in landscape */
    .hud-top { padding: 4px 8px; font-size: 10px; }

    body { padding-bottom: calc(44px + var(--safe-area-bottom) + 4px); }

    .site-footer { display: none; }
}

/* =====================================================================
   SAFE AREA / NOTCH SUPPORT
   ===================================================================== */
@supports (padding: env(safe-area-inset-top)) {
    .nav-bar {
        padding-top: calc(8px + env(safe-area-inset-top));
    }
    .hud-top {
        padding-top: calc(6px + env(safe-area-inset-top));
    }
    .mobile-toolbar {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .mobile-tower-strip {
        bottom: calc(var(--mobile-toolbar-height) + env(safe-area-inset-bottom));
        padding-left: calc(8px + env(safe-area-inset-left));
        padding-right: calc(8px + env(safe-area-inset-right));
    }
    .mobile-ability-bar {
        bottom: calc(var(--mobile-toolbar-height) + var(--mobile-tower-strip-height) + env(safe-area-inset-bottom) + 4px);
        left: env(safe-area-inset-left);
        right: env(safe-area-inset-right);
    }
    .mobile-wave-btn {
        bottom: calc(var(--mobile-toolbar-height) + var(--mobile-tower-strip-height) + env(safe-area-inset-bottom) + 12px);
    }
    .site-footer {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
    .game-overlay {
        padding-top: calc(16px + env(safe-area-inset-top));
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
        padding-left: calc(16px + env(safe-area-inset-left));
        padding-right: calc(16px + env(safe-area-inset-right));
    }
    .toast-container {
        top: calc(12px + env(safe-area-inset-top));
        left: calc(8px + env(safe-area-inset-left));
        right: calc(8px + env(safe-area-inset-right));
    }
    .mobile-overlay {
        padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-left)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-right));
    }
}

/* =====================================================================
   PRINT (hide game UI, show content only)
   ===================================================================== */
@media print {
    .mobile-toolbar, .mobile-tower-strip, .mobile-ability-bar,
    .mobile-wave-btn, .crt-overlay, .site-footer,
    .game-canvas-container, .side-panel { display: none !important; }
    body { padding: 0; background: #fff; color: #000; }
}

/* =====================================================================
   REDUCED MOTION PREFERENCE
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    .crt-overlay { display: none; }
}

/* =====================================================================
   HIGH CONTRAST PREFERENCE
   ===================================================================== */
@media (prefers-contrast: high) {
    :root {
        --border-color: #666;
        --text-muted: #999;
    }
    .tower-btn, .ability-btn, .ctrl-btn { border-width: 2px; }
}

/* ===== v5.0 NEW FEATURES STYLES ===== */

/* --- Prestige System --- */
.prestige-btn {
    border-color: var(--accent-pink) !important;
    color: var(--accent-pink) !important;
    display: none !important;
}
.prestige-btn:hover {
    background: rgba(255,68,136,0.15) !important;
    box-shadow: 0 0 10px rgba(255,68,136,0.3);
}
.prestige-indicator {
    font-size: 11px;
    color: var(--accent-pink);
    font-weight: bold;
}
#hud-prestige {
    font-weight: bold;
    animation: pulse 2s ease-in-out infinite;
}

/* --- Auto-Battle --- */
.auto-btn {
    border-color: var(--accent-cyan) !important;
    color: var(--accent-cyan) !important;
}
.auto-btn:hover {
    background: rgba(0,255,170,0.15) !important;
}
.auto-btn.active {
    background: rgba(0,255,170,0.2) !important;
    border-color: var(--accent-cyan) !important;
    box-shadow: 0 0 8px rgba(0,255,170,0.3);
}
#mobileAutoBtn.active {
    background: #003300;
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

/* --- Story Overlay --- */
.story-overlay {
    display: none;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.95);
    z-index: 70;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    text-align: center;
    animation: fadeIn 0.8s ease;
    padding: 30px;
}
.story-overlay.visible { display: flex; }
.story-overlay .story-title {
    color: var(--accent-cyan);
    font-size: var(--font-size-xl);
    margin-bottom: 15px;
    text-shadow: 0 0 20px rgba(0,255,170,0.5);
    font-family: var(--font-mono);
    letter-spacing: 2px;
}
.story-overlay .story-text {
    color: var(--text-white);
    font-size: var(--font-size-sm);
    line-height: 2;
    max-width: 500px;
    margin-bottom: 25px;
    font-family: var(--font-mono);
}
.story-overlay .story-chapter {
    color: var(--text-muted);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 3px;
    margin-bottom: 10px;
}

/* --- Tutorial Overlay --- */
.tutorial-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10006;
    background: rgba(0,0,0,0.6);
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tutorial-box {
    background: var(--bg-primary);
    border: 2px solid var(--text-primary);
    border-radius: 8px;
    padding: 20px 24px;
    max-width: 320px;
    width: 90%;
    box-shadow: 0 0 30px rgba(0,255,65,0.3);
    animation: slideDown 0.3s ease;
    text-align: center;
}
.tutorial-step {
    color: var(--text-primary);
    font-size: var(--font-size-xs);
    font-family: var(--font-mono);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.tutorial-text {
    color: var(--text-white);
    font-size: var(--font-size-sm);
    font-family: var(--font-mono);
    line-height: 1.6;
    margin-bottom: 16px;
}
.tutorial-next-btn {
    width: 100%;
    padding: 10px;
    font-size: var(--font-size-sm);
}

/* --- Event Notification Bar --- */
.event-bar {
    position: absolute;
    bottom: 12px; left: 50%;
    transform: translateX(-50%);
    background: rgba(10,10,10,0.95);
    border: 1px solid var(--accent-yellow);
    border-radius: 6px;
    padding: 6px 16px;
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    animation: slideUp 0.3s ease;
}
.event-bar .event-icon { font-size: 16px; }
.event-bar .event-name { color: var(--accent-yellow); font-weight: bold; }
.event-bar .event-timer { color: var(--text-muted); }

/* --- Power-Up Styles --- */
.powerup-legend {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 10px;
    color: var(--text-muted);
    padding: 4px 0;
}
.powerup-legend .pu-item {
    display: flex;
    align-items: center;
    gap: 3px;
}
.powerup-legend .pu-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
}

/* --- Environmental Zone Legend --- */
.zone-legend {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 10px;
    color: var(--text-muted);
    padding: 4px 0;
}
.zone-legend .zn-item {
    display: flex;
    align-items: center;
    gap: 3px;
}
.zone-legend .zn-box {
    width: 10px; height: 10px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.3);
}

/* --- Map Theme Indicator --- */
.map-theme-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-family: var(--font-mono);
    border: 1px solid;
    margin-left: 6px;
}

/* --- Mobile Event Bar --- */
@media (max-width: 768px) {
    .event-bar {
        font-size: 10px;
        padding: 4px 10px;
        bottom: 8px;
    }
    .tutorial-box {
        max-width: 280px;
        padding: 14px 16px;
    }
    .tutorial-text {
        font-size: var(--font-size-xs);
    }
    .story-overlay .story-text {
        font-size: var(--font-size-xs);
        line-height: 1.8;
    }
    .story-overlay .story-title {
        font-size: var(--font-size-lg);
    }
}

@media (max-width: 480px) {
    .event-bar {
        font-size: 9px;
        padding: 3px 8px;
    }
}
