* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1a2e 50%, #0f0f1a 100%);
    color: #fff;
    touch-action: manipulation;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.hidden {
    display: none !important;
}

/* ===== MENU SCREEN ===== */
#menu {
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a15 100%);
}

.menu-container {
    text-align: center;
    padding: 20px;
}

.title {
    font-size: clamp(2rem, 10vw, 4rem);
    font-weight: bold;
    margin-bottom: 40px;
    background: linear-gradient(45deg, #00ffff, #ff00ff, #00ffff);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 3s ease infinite;
    text-shadow: 0 0 30px rgba(0, 255, 255, 0.3);
}

@keyframes gradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.menu-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

#playerName {
    width: 280px;
    max-width: 90vw;
    padding: 15px 25px;
    font-size: 1.2rem;
    border: 2px solid #00ffff;
    border-radius: 12px;
    background: rgba(0, 255, 255, 0.1);
    color: #fff;
    outline: none;
    transition: all 0.3s;
    text-align: center;
}

#playerName:focus {
    border-color: #ff00ff;
    background: rgba(255, 0, 255, 0.1);
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.3);
}

#playerName::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.btn-play {
    padding: 15px 50px;
    font-size: 1.3rem;
    font-weight: bold;
    border: none;
    border-radius: 12px;
    background: linear-gradient(45deg, #00ffff, #0088ff);
    color: #fff;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.btn-play:hover {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(0, 255, 255, 0.5);
}

.btn-play:active {
    transform: scale(0.98);
}

.status-message {
    margin-top: 30px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #00ffff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.found-text {
    font-size: 1.3rem;
    color: #00ff00;
    margin-bottom: 10px;
}

.opponent-name {
    font-size: 1.1rem;
    color: #ff00ff;
    margin-bottom: 20px;
}

.countdown {
    font-size: 4rem;
    font-weight: bold;
    color: #00ffff;
    animation: pulse 0.5s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(1.2); opacity: 0.8; }
}

/* ===== GAME SCREEN ===== */
#gameScreen {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 10px;
    gap: 10px;
}

.game-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    padding: 10px;
    flex-shrink: 0;
}

.player-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: clamp(0.9rem, 3vw, 1.2rem);
    font-weight: bold;
}

.player1-header {
    color: #00ffff;
}

.player2-header {
    color: #ff00ff;
}

.player-indicator {
    animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.vs-text {
    font-size: 1rem;
    color: #666;
    font-weight: bold;
}

.game-area {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
    min-height: 0;
    padding: 0 5px;
}

.player-section {
    display: flex;
    gap: 8px;
    height: 100%;
    max-height: 100%;
}

.player1-section {
    flex-direction: row;
}

.player2-section {
    flex-direction: row-reverse;
}

.board-container {
    position: relative;
    border: 3px solid;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.5);
}

.player1-section .board-container {
    border-color: #00ffff;
    box-shadow: 0 0 20px rgba(0, 255, 255, 0.3), inset 0 0 30px rgba(0, 255, 255, 0.1);
}

.player2-section .board-container {
    border-color: #ff00ff;
    box-shadow: 0 0 20px rgba(255, 0, 255, 0.3), inset 0 0 30px rgba(255, 0, 255, 0.1);
}

.board-container canvas {
    display: block;
}

.player-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.5rem;
    font-weight: bold;
    padding: 10px 20px;
    border-radius: 8px;
    text-align: center;
    z-index: 10;
}

.stats-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    min-width: 70px;
}

.next-piece-container {
    text-align: center;
}

.next-piece-container canvas {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    margin-top: 5px;
}

.stat-item {
    text-align: center;
}

.label {
    font-size: 0.65rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.value {
    font-size: 1.1rem;
    font-weight: bold;
    color: #fff;
}

/* ===== MOBILE CONTROLS ===== */
.mobile-controls {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    margin-top: auto;
    flex-shrink: 0;
}

.controls-row {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.ctrl-btn {
    width: 60px;
    height: 50px;
    font-size: 1.5rem;
    border: 2px solid #444;
    border-radius: 10px;
    background: linear-gradient(180deg, #2a2a3a 0%, #1a1a2a 100%);
    color: #fff;
    cursor: pointer;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ctrl-btn:active {
    transform: scale(0.95);
    background: linear-gradient(180deg, #3a3a4a 0%, #2a2a3a 100%);
    border-color: #00ffff;
}

.ctrl-move {
    width: 70px;
}

.ctrl-down {
    width: 70px;
}

.ctrl-drop {
    width: 150px;
    font-size: 1rem;
    background: linear-gradient(180deg, #003333 0%, #002222 100%);
    border-color: #00ffff;
}

/* ===== OVERLAY ===== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.overlay-content {
    text-align: center;
    padding: 40px;
    background: linear-gradient(135deg, #1a1a2e 0%, #0f0f1a 100%);
    border-radius: 20px;
    border: 3px solid #00ffff;
    max-width: 90vw;
}

.overlay-content h2 {
    font-size: clamp(1.5rem, 6vw, 2.5rem);
    margin-bottom: 20px;
}

.final-stats {
    margin-bottom: 30px;
    font-size: 1rem;
    color: #aaa;
}

/* ===== CONTROLS HINT ===== */
.controls-hint {
    position: fixed;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: #555;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 15px;
    border-radius: 20px;
    white-space: nowrap;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .mobile-controls {
        display: flex;
    }
    
    .controls-hint {
        display: none;
    }
    
    .game-area {
        flex: 1;
        align-items: center;
    }
    
    .stats-panel {
        min-width: 60px;
        padding: 5px;
        gap: 8px;
    }
    
    .next-piece-container canvas {
        width: 60px;
        height: 60px;
    }
    
    .value {
        font-size: 1rem;
    }
    
    .label {
        font-size: 0.6rem;
    }
}

@media (max-width: 480px) {
    #gameScreen {
        padding: 5px;
        gap: 5px;
    }
    
    .game-header {
        padding: 5px;
        gap: 10px;
    }
    
    .game-area {
        gap: 5px;
    }
    
    .player-section {
        gap: 5px;
    }
    
    .stats-panel {
        min-width: 50px;
        padding: 4px;
        gap: 5px;
    }
    
    .next-piece-container canvas {
        width: 45px;
        height: 45px;
    }
    
    .value {
        font-size: 0.9rem;
    }
    
    .ctrl-btn {
        width: 55px;
        height: 45px;
        font-size: 1.3rem;
    }
    
    .ctrl-move, .ctrl-down {
        width: 60px;
    }
    
    .ctrl-drop {
        width: 130px;
        font-size: 0.9rem;
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .game-header {
        padding: 3px;
    }
    
    .mobile-controls {
        position: fixed;
        right: 10px;
        top: 50%;
        transform: translateY(-50%);
        flex-direction: column;
        padding: 5px;
        margin: 0;
    }
    
    .ctrl-btn {
        width: 45px;
        height: 40px;
        font-size: 1.1rem;
    }
    
    .ctrl-move, .ctrl-down {
        width: 50px;
    }
    
    .ctrl-drop {
        width: 100px;
        font-size: 0.8rem;
    }
}