/* ========================================
   REALITY ENGINE - CYBERPUNK AR FPS
   Neon / Futuristic HUD Styling
   ======================================== */

/* CSS Variables */
:root {
    --primary-cyan: #00f5ff;
    --primary-magenta: #ff00ff;
    --primary-yellow: #ffff00;
    --primary-green: #00ff88;
    --primary-red: #ff0044;
    --primary-orange: #ff8800;
    
    --bg-dark: #0a0a0f;
    --bg-darker: #050508;
    --bg-panel: rgba(10, 10, 20, 0.85);
    
    --glow-cyan: 0 0 10px #00f5ff, 0 0 20px #00f5ff, 0 0 40px #00f5ff;
    --glow-magenta: 0 0 10px #ff00ff, 0 0 20px #ff00ff, 0 0 40px #ff00ff;
    --glow-red: 0 0 10px #ff0044, 0 0 20px #ff0044;
    --glow-green: 0 0 10px #00ff88, 0 0 20px #00ff88;
    
    --font-mono: 'Courier New', monospace;
    --font-display: 'Segoe UI', system-ui, sans-serif;
    
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    font-family: var(--font-mono);
    color: var(--primary-cyan);
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* ========================================
   LOADING SCREEN
   ======================================== */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-darker);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loader-content {
    text-align: center;
    padding: 20px;
}

.cyber-loader {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 30px;
}

.loader-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 2px solid transparent;
    border-radius: 50%;
    animation: loader-spin 1.5s linear infinite;
}

.loader-ring:nth-child(1) {
    border-top-color: var(--primary-cyan);
    animation-duration: 1.5s;
}

.loader-ring:nth-child(2) {
    width: 80%;
    height: 80%;
    top: 10%;
    left: 10%;
    border-right-color: var(--primary-magenta);
    animation-duration: 1.2s;
    animation-direction: reverse;
}

.loader-core {
    position: absolute;
    width: 30%;
    height: 30%;
    top: 35%;
    left: 35%;
    background: var(--primary-cyan);
    border-radius: 50%;
    animation: loader-pulse 1s ease-in-out infinite;
    box-shadow: var(--glow-cyan);
}

@keyframes loader-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes loader-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

.loader-title {
    font-family: var(--font-display);
    font-size: clamp(24px, 6vw, 36px);
    font-weight: 300;
    letter-spacing: 8px;
    text-shadow: var(--glow-cyan);
    margin-bottom: 10px;
    animation: title-glitch 3s infinite;
}

@keyframes title-glitch {
    0%, 90%, 100% { 
        text-shadow: var(--glow-cyan);
        transform: translateX(0);
    }
    92% { 
        text-shadow: -2px 0 var(--primary-magenta), 2px 0 var(--primary-cyan);
        transform: translateX(-2px);
    }
    94% { 
        text-shadow: 2px 0 var(--primary-magenta), -2px 0 var(--primary-cyan);
        transform: translateX(2px);
    }
}

.loader-subtitle {
    font-size: 12px;
    letter-spacing: 3px;
    color: var(--primary-magenta);
    opacity: 0.8;
    margin-bottom: 30px;
}

.loader-progress {
    width: 200px;
    height: 2px;
    background: rgba(0, 245, 255, 0.2);
    margin: 0 auto 15px;
    position: relative;
    overflow: hidden;
}

.loader-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-cyan), var(--primary-magenta));
    box-shadow: 0 0 10px var(--primary-cyan);
    animation: loader-progress 2s ease-out forwards;
}

@keyframes loader-progress {
    0% { width: 0%; }
    50% { width: 60%; }
    100% { width: 100%; }
}

.loader-status {
    font-size: 10px;
    letter-spacing: 2px;
    opacity: 0.6;
}

/* ========================================
   GAME CONTAINER
   ======================================== */
.game-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
}

/* Camera Feed */
.camera-feed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Mirror for front camera feel */
}

/* Detection Canvas (Hidden) */
.detection-canvas {
    display: none;
}

/* Game Canvas */
.game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ========================================
   HUD OVERLAY
   ======================================== */
.hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

/* Top HUD Bar */
.hud-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: calc(var(--safe-area-top) + 10px) 15px 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.score-panel, .fps-panel, .wave-panel {
    background: var(--bg-panel);
    padding: 8px 15px;
    border: 1px solid rgba(0, 245, 255, 0.3);
    position: relative;
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 10px 100%, 0 calc(100% - 10px));
}

.score-panel::before, .fps-panel::before, .wave-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-cyan), transparent);
}

.score-label, .fps-label, .wave-label {
    display: block;
    font-size: 8px;
    letter-spacing: 2px;
    opacity: 0.6;
}

.score-value {
    font-size: clamp(20px, 5vw, 28px);
    font-weight: bold;
    text-shadow: var(--glow-cyan);
}

.fps-value {
    font-size: clamp(16px, 4vw, 22px);
    color: var(--primary-green);
}

.wave-value {
    font-size: clamp(16px, 4vw, 22px);
    color: var(--primary-magenta);
}

/* Bottom HUD */
.hud-bottom {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 10px 15px calc(var(--safe-area-bottom) + 10px);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Health Bar */
.health-container, .energy-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.health-bar, .energy-bar {
    flex: 1;
    height: 8px;
    background: rgba(255, 0, 68, 0.2);
    border: 1px solid rgba(255, 0, 68, 0.5);
    position: relative;
    overflow: hidden;
}

.energy-bar {
    background: rgba(0, 245, 255, 0.2);
    border-color: rgba(0, 245, 255, 0.5);
}

.health-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--primary-red), var(--primary-orange));
    transition: width 0.3s ease;
    position: relative;
}

.energy-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--primary-cyan), var(--primary-green));
    transition: width 0.3s ease;
}

.health-glow, .energy-glow {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: bar-shine 2s infinite;
}

@keyframes bar-shine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.health-text, .energy-text {
    font-size: 12px;
    min-width: 40px;
    text-align: right;
}

.health-text {
    color: var(--primary-red);
    text-shadow: var(--glow-red);
}

.energy-text {
    color: var(--primary-cyan);
    font-size: 10px;
    letter-spacing: 1px;
}

/* ========================================
   CROSSHAIR
   ======================================== */
.crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    pointer-events: none;
}

.crosshair-line {
    position: absolute;
    background: var(--primary-cyan);
    box-shadow: var(--glow-cyan);
}

.crosshair-line.top {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 20px;
}

.crosshair-line.bottom {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 20px;
}

.crosshair-line.left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 2px;
}

.crosshair-line.right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 2px;
}

.crosshair-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 6px;
    height: 6px;
    background: var(--primary-cyan);
    border-radius: 50%;
    box-shadow: var(--glow-cyan);
}

.crosshair-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 1px solid rgba(0, 245, 255, 0.5);
    border-radius: 50%;
    animation: crosshair-pulse 2s ease-in-out infinite;
}

@keyframes crosshair-pulse {
    0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.5; }
    50% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
}

/* Crosshair Hit Animation */
.crosshair.hit .crosshair-center {
    background: var(--primary-red);
    box-shadow: var(--glow-red);
}

.crosshair.hit .crosshair-ring {
    border-color: var(--primary-red);
    animation: crosshair-hit 0.2s ease-out;
}

@keyframes crosshair-hit {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.5); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* ========================================
   MODE INDICATOR
   ======================================== */
.mode-indicator {
    position: absolute;
    bottom: calc(var(--safe-area-bottom) + 80px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    padding: 5px 15px;
    border: 1px solid rgba(255, 0, 255, 0.3);
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 10px;
    letter-spacing: 1px;
    opacity: 0.8;
}

.mode-label {
    color: rgba(255, 255, 255, 0.5);
}

.mode-value {
    color: var(--primary-magenta);
    text-shadow: var(--glow-magenta);
}

/* ========================================
   KILL FEED
   ======================================== */
.kill-feed {
    position: absolute;
    top: calc(var(--safe-area-top) + 80px);
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-width: 200px;
}

.kill-feed-item {
    background: var(--bg-panel);
    padding: 5px 10px;
    font-size: 10px;
    letter-spacing: 1px;
    border-left: 2px solid var(--primary-green);
    animation: kill-feed-in 0.3s ease-out, kill-feed-out 0.3s ease-in 2.7s forwards;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes kill-feed-in {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes kill-feed-out {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ========================================
   COMBO COUNTER
   ======================================== */
.combo-container {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    text-align: right;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.combo-container.active {
    opacity: 1;
}

.combo-value {
    display: block;
    font-size: clamp(32px, 8vw, 48px);
    font-weight: bold;
    color: var(--primary-yellow);
    text-shadow: 0 0 10px var(--primary-yellow), 0 0 20px var(--primary-orange);
    animation: combo-pulse 0.5s ease-out;
}

@keyframes combo-pulse {
    0% { transform: scale(1.5); }
    100% { transform: scale(1); }
}

.combo-label {
    font-size: 10px;
    letter-spacing: 3px;
    color: var(--primary-yellow);
    opacity: 0.8;
}

/* ========================================
   SCAN LINES EFFECT
   ======================================== */
.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.1) 0px,
        rgba(0, 0, 0, 0.1) 1px,
        transparent 1px,
        transparent 3px
    );
    z-index: 200;
    animation: scanline-scroll 10s linear infinite;
}

@keyframes scanline-scroll {
    0% { background-position: 0 0; }
    100% { background-position: 0 100%; }
}

/* ========================================
   VIGNETTE EFFECT
   ======================================== */
.vignette {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.6) 100%);
    z-index: 150;
}

/* ========================================
   GRID OVERLAY
   ======================================== */
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image: 
        linear-gradient(rgba(0, 245, 255, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 245, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    z-index: 50;
    opacity: 0.5;
}

/* ========================================
   MENU OVERLAY
   ======================================== */
.menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 10, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.menu-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.menu-panel {
    background: var(--bg-panel);
    border: 1px solid rgba(0, 245, 255, 0.3);
    padding: 30px;
    max-width: 90%;
    width: 320px;
    text-align: center;
    position: relative;
    clip-path: polygon(0 0, calc(100% - 20px) 0, 100% 20px, 100% 100%, 20px 100%, 0 calc(100% - 20px));
}

.menu-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary-cyan), transparent);
}

.menu-title {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 300;
    letter-spacing: 6px;
    margin-bottom: 30px;
    text-shadow: var(--glow-cyan);
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.menu-btn {
    background: transparent;
    border: 1px solid rgba(0, 245, 255, 0.3);
    color: var(--primary-cyan);
    padding: 15px 20px;
    font-family: var(--font-mono);
    font-size: 14px;
    letter-spacing: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
    pointer-events: auto;
}

.menu-btn:active {
    background: rgba(0, 245, 255, 0.1);
    border-color: var(--primary-cyan);
    transform: scale(0.98);
}

.btn-icon {
    font-size: 16px;
    opacity: 0.6;
}

.menu-hint {
    margin-top: 20px;
    font-size: 10px;
    letter-spacing: 1px;
    opacity: 0.5;
}

/* ========================================
   GAME OVER SCREEN
   ======================================== */
.gameover-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 10, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 600;
    transition: opacity 0.3s ease;
}

.gameover-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.gameover-panel {
    background: var(--bg-panel);
    border: 1px solid rgba(255, 0, 68, 0.3);
    padding: 40px 30px;
    max-width: 90%;
    width: 320px;
    text-align: center;
    position: relative;
}

.gameover-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary-red), transparent);
}

.gameover-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 300;
    letter-spacing: 4px;
    color: var(--primary-red);
    text-shadow: var(--glow-red);
    margin-bottom: 30px;
    animation: glitch 0.5s infinite;
}

@keyframes glitch {
    0%, 90%, 100% { transform: translateX(0); }
    92% { transform: translateX(-3px); }
    94% { transform: translateX(3px); }
    96% { transform: translateX(-1px); }
    98% { transform: translateX(1px); }
}

.gameover-stats {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-label {
    font-size: 10px;
    letter-spacing: 2px;
    opacity: 0.6;
}

.stat-value {
    font-size: 20px;
    color: var(--primary-cyan);
    text-shadow: var(--glow-cyan);
}

.restart-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--primary-cyan), var(--primary-magenta));
    border: none;
    color: var(--bg-dark);
    padding: 15px 30px;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s ease;
    pointer-events: auto;
}

.restart-btn:active {
    transform: scale(0.98);
    box-shadow: var(--glow-cyan);
}

.leaderboard-entry {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

.leaderboard-entry input {
    flex: 1;
    background: transparent;
    border: 1px solid rgba(0, 245, 255, 0.3);
    color: var(--primary-cyan);
    padding: 10px;
    font-family: var(--font-mono);
    font-size: 14px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.leaderboard-entry input::placeholder {
    color: rgba(0, 245, 255, 0.3);
}

.leaderboard-entry button {
    background: var(--primary-cyan);
    border: none;
    color: var(--bg-dark);
    padding: 10px 15px;
    font-family: var(--font-mono);
    font-size: 12px;
    letter-spacing: 1px;
    cursor: pointer;
}

/* ========================================
   TOUCH INDICATOR
   ======================================== */
.touch-indicator {
    position: fixed;
    width: 60px;
    height: 60px;
    border: 2px solid var(--primary-cyan);
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0);
    transition: opacity 0.1s, transform 0.2s ease-out;
}

.touch-indicator.active {
    opacity: 0.5;
    transform: translate(-50%, -50%) scale(1);
    animation: touch-ripple 0.4s ease-out forwards;
}

@keyframes touch-ripple {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0.8; }
    100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */
.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

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

/* ========================================
   RESPONSIVE ADJUSTMENTS
   ======================================== */
@media (max-width: 360px) {
    .hud-top {
        padding: calc(var(--safe-area-top) + 5px) 10px 5px;
    }
    
    .score-panel, .fps-panel, .wave-panel {
        padding: 5px 10px;
    }
    
    .crosshair {
        width: 60px;
        height: 60px;
    }
}

@media (min-width: 768px) {
    .menu-panel {
        width: 400px;
    }
    
    .gameover-panel {
        width: 400px;
    }
}

/* ========================================
   NOISE EFFECT
   ======================================== */
.game-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.03;
    z-index: 250;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* ========================================
   HIGH SCORE NOTIFICATION
   ======================================== */
.high-score-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: var(--primary-yellow);
    color: var(--bg-dark);
    padding: 3px 8px;
    font-size: 8px;
    font-weight: bold;
    letter-spacing: 1px;
    animation: badge-pulse 1s infinite;
}

@keyframes badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
