/* ========================================
   TANK COMBAT - Retro Polished Aesthetic
   ======================================== */

:root {
    /* Core palette */
    --bg-dark: #0a0a12;
    --bg-grid: #12121f;
    --accent-cyan: #00f5ff;
    --accent-orange: #ff6b35;
    --accent-blue: #4a9eff;
    --accent-red: #ff4757;
    --accent-green: #2ed573;
    --accent-yellow: #ffd93d;
    --text-primary: #ffffff;
    --text-dim: #6b7280;
    --wall-color: #3d4466;
    --wall-highlight: #5a6080;
    
    /* Player colors */
    --player1-main: #4a9eff;
    --player1-glow: rgba(74, 158, 255, 0.5);
    --player2-main: #ff6b35;
    --player2-glow: rgba(255, 107, 53, 0.5);
    
    /* UI */
    --border-radius: 4px;
    --glow-spread: 0 0 20px;
}

* {
    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: 'Share Tech Mono', monospace;
    color: var(--text-primary);
    /* Safe area CSS variables */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

/* ========================================
   SCREENS
   ======================================== */

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    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: 30px 30px;
}

.screen.active {
    display: flex;
}

/* ========================================
   MAIN MENU
   ======================================== */

.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 20px;
    max-width: 400px;
    width: 100%;
}

.game-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 900;
    letter-spacing: 0.1em;
    text-shadow: 
        0 0 10px var(--accent-cyan),
        0 0 30px var(--accent-cyan),
        0 0 50px rgba(0, 245, 255, 0.3);
    animation: titlePulse 3s ease-in-out infinite;
}

.title-accent {
    color: var(--accent-orange);
    text-shadow: 
        0 0 10px var(--accent-orange),
        0 0 30px var(--accent-orange),
        0 0 50px rgba(255, 107, 53, 0.3);
}

.title-underline {
    width: 80%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent-cyan), var(--accent-orange), transparent);
    margin-bottom: 20px;
}

@keyframes titlePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

.player-setup {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.player-setup label {
    font-size: 0.8rem;
    color: var(--text-dim);
    letter-spacing: 0.2em;
}

.player-setup input {
    width: 100%;
    max-width: 280px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--accent-cyan);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    outline: none;
    transition: all 0.3s ease;
}

.player-setup input:focus {
    background: rgba(0, 245, 255, 0.1);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.3);
}

.player-setup input::placeholder {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    border: 2px solid;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transition: left 0.5s ease;
}

.btn:active::before {
    left: 100%;
}

.btn-primary {
    background: var(--accent-cyan);
    border-color: var(--accent-cyan);
    color: var(--bg-dark);
    box-shadow: 0 0 20px rgba(0, 245, 255, 0.4);
}

.btn-primary:active {
    transform: scale(0.98);
    box-shadow: 0 0 30px rgba(0, 245, 255, 0.6);
}

.btn-secondary {
    background: transparent;
    border-color: var(--accent-orange);
    color: var(--accent-orange);
}

.btn-secondary:active {
    background: rgba(255, 107, 53, 0.2);
}

.btn-tertiary {
    background: transparent;
    border-color: var(--text-dim);
    color: var(--text-dim);
}

.btn-tertiary:active {
    border-color: var(--accent-yellow);
    color: var(--accent-yellow);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.75rem;
}

.btn-icon {
    font-size: 1.2em;
}

/* Queue Status */
.queue-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: rgba(46, 213, 115, 0.1);
    border: 1px solid var(--accent-green);
    border-radius: var(--border-radius);
    color: var(--accent-green);
    font-size: 0.9rem;
}

.queue-status.hidden,
.searching-status.hidden {
    display: none;
}

.queue-pulse {
    width: 10px;
    height: 10px;
    background: var(--accent-green);
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.5; }
}

.searching-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    background: rgba(74, 158, 255, 0.1);
    border: 1px solid var(--accent-blue);
    border-radius: var(--border-radius);
    color: var(--accent-blue);
}

.searching-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(74, 158, 255, 0.3);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.menu-footer {
    position: absolute;
    bottom: 20px;
    color: var(--text-dim);
    font-size: 0.75rem;
}

/* ========================================
   LEADERBOARD
   ======================================== */

.leaderboard-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 20px;
    width: 100%;
    max-width: 400px;
}

.screen-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.8rem;
    color: var(--accent-yellow);
    text-shadow: 0 0 10px rgba(255, 217, 61, 0.5);
}

.leaderboard-tabs {
    display: flex;
    gap: 8px;
}

.tab {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--text-dim);
    border-radius: var(--border-radius);
    color: var(--text-dim);
    font-family: 'Share Tech Mono', monospace;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab.active {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: rgba(0, 245, 255, 0.1);
}

.leaderboard-list {
    width: 100%;
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.leaderboard-entry {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    gap: 12px;
}

.leaderboard-entry.top-3 {
    border-color: var(--accent-yellow);
    background: rgba(255, 217, 61, 0.05);
}

.leaderboard-rank {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    width: 30px;
    color: var(--text-dim);
}

.leaderboard-entry.top-3 .leaderboard-rank {
    color: var(--accent-yellow);
}

.leaderboard-name {
    flex: 1;
    font-size: 1rem;
}

.leaderboard-wins {
    font-family: 'Orbitron', sans-serif;
    color: var(--accent-green);
}

/* ========================================
   GAME SCREEN
   ======================================== */

#game-screen {
    flex-direction: column;
    padding: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    background: var(--bg-dark);
    position: relative;
}

/* HUD */
.game-hud {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    background: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
    height: 80px;
}

.hud-left, .hud-right {
    flex: 1;
}

.hud-right {
    text-align: right;
}

.hud-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.player-score {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.player-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    letter-spacing: 0.1em;
}

.player1 .score {
    color: var(--player1-main);
    text-shadow: 0 0 10px var(--player1-glow);
}

.player2 .score {
    color: var(--player2-main);
    text-shadow: 0 0 10px var(--player2-glow);
}

.score {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 900;
}

.round-info {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#round-display {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    color: var(--text-dim);
    letter-spacing: 0.15em;
}

.timer {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-cyan);
}

.timer.warning {
    color: var(--accent-yellow);
    animation: timerPulse 0.5s ease-in-out infinite;
}

.timer.danger {
    color: var(--accent-red);
    animation: timerPulse 0.3s ease-in-out infinite;
}

@keyframes timerPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.match-score {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.match-pip {
    width: 12px;
    height: 12px;
    border: 2px solid var(--text-dim);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.match-pip.won-p1 {
    background: var(--player1-main);
    border-color: var(--player1-main);
    box-shadow: 0 0 8px var(--player1-glow);
}

.match-pip.won-p2 {
    background: var(--player2-main);
    border-color: var(--player2-main);
    box-shadow: 0 0 8px var(--player2-glow);
}

.match-pip.draw {
    background: var(--text-dim);
    border-color: var(--text-dim);
}

/* Canvas */
#game-canvas {
    flex: 1;
    width: 100%;
    touch-action: none;
    display: block;
}

/* Controls */
.game-controls {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 10px 20px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    flex-shrink: 0;
    height: 140px;
    background: linear-gradient(to top, rgba(0,0,0,0.5), transparent);
}

.joystick-zone {
    width: 120px;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
}

.joystick-base {
    width: 100px;
    height: 100px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.joystick-stick {
    width: 45px;
    height: 45px;
    background: radial-gradient(circle at 30% 30%, var(--player1-main), #2a5a9e);
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    box-shadow: 
        0 0 15px var(--player1-glow),
        inset 0 2px 4px rgba(255, 255, 255, 0.3);
    position: absolute;
    transition: transform 0.05s ease-out;
}

.fire-zone {
    touch-action: none;
}

.fire-btn {
    width: 100px;
    height: 100px;
    background: radial-gradient(circle at 30% 30%, var(--accent-red), #a02030);
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 0 20px rgba(255, 71, 87, 0.5),
        inset 0 2px 6px rgba(255, 255, 255, 0.3);
    transition: transform 0.1s ease;
}

.fire-btn:active {
    transform: scale(0.95);
}

.fire-btn.on-cooldown {
    background: radial-gradient(circle at 30% 30%, #555, #333);
    box-shadow: none;
}

.fire-icon {
    font-size: 2rem;
    color: white;
    text-shadow: 0 0 10px rgba(255,255,255,0.5);
}

.cooldown-ring {
    position: absolute;
    top: -4px;
    left: -4px;
    width: calc(100% + 8px);
    height: calc(100% + 8px);
    transform: rotate(-90deg);
}

.cooldown-bg {
    fill: none;
    stroke: rgba(255, 255, 255, 0.1);
    stroke-width: 4;
}

.cooldown-progress {
    fill: none;
    stroke: var(--accent-cyan);
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 0.1s linear;
}

/* ========================================
   OVERLAYS
   ======================================== */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 10, 18, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

.overlay.hidden {
    display: none;
}

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

.result-content {
    text-align: center;
    padding: 30px;
}

.result-content h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--accent-cyan);
    text-shadow: 0 0 20px var(--accent-cyan);
}

.result-content p {
    color: var(--text-dim);
    margin-bottom: 20px;
}

.result-scores {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    margin: 20px 0;
}

#result-p1, #final-p1 {
    color: var(--player1-main);
    text-shadow: 0 0 15px var(--player1-glow);
}

#result-p2, #final-p2 {
    color: var(--player2-main);
    text-shadow: 0 0 15px var(--player2-glow);
}

.result-vs {
    color: var(--text-dim);
    font-size: 2rem;
}

.match-final h2 {
    font-size: 3rem;
    animation: victoryPulse 1s ease-in-out infinite;
}

@keyframes victoryPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.match-final.defeat h2 {
    color: var(--accent-red);
    text-shadow: 0 0 20px var(--accent-red);
}

.final-score {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 30px;
    font-family: 'Orbitron', sans-serif;
    font-size: 4rem;
    font-weight: 900;
    margin: 30px 0;
}

.match-buttons {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 30px;
}

/* ========================================
   UTILITIES
   ======================================== */

.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

::-webkit-scrollbar-thumb {
    background: var(--accent-cyan);
    border-radius: 3px;
}

/* Prevent text selection during gameplay */
#game-screen {
    user-select: none;
    -webkit-user-select: none;
}
