/* ═══════════════════════════════════════════════════════════
   TETRIS - RESPONSIVE GAME
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Inter:wght@400;600;700&display=swap');

:root {
    --primary-color: #961114;
    --secondary-color: #FFD700;
    --bg-dark: #070707;
    --bg-secondary: #1a1a1a;
    --text-color: #FCF7F8;
    --border-color: rgba(252, 247, 248, 0.1);
    --font-pixel: 'Press Start 2P', monospace;
    --font-body: 'Inter', sans-serif;
    
    /* Tetromino Colors */
    --tetro-i: #00F0F0; /* Cyan */
    --tetro-o: #F0F000; /* Yellow */
    --tetro-t: #A000F0; /* Purple */
    --tetro-s: #00F000; /* Green */
    --tetro-z: #F00000; /* Red */
    --tetro-j: #0000F0; /* Blue */
    --tetro-l: #F0A000; /* Orange */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background: var(--bg-dark);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ═══ NAVBAR ═══ */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: rgba(7, 7, 7, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--primary-color);
    z-index: 1000;
}

.navbar-container {
    max-width: 1920px;
    height: 100%;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-info {
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 0.9rem;
}

.nav-btn.secondary {
    background: transparent;
    border: 2px solid var(--secondary-color);
    color: var(--secondary-color);
}

.nav-btn.secondary:hover {
    background: var(--secondary-color);
    color: var(--bg-dark);
}

.logo {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-family: var(--font-pixel);
    font-size: 1.5rem;
    color: var(--primary-color);
}

.logo svg {
    stroke: var(--primary-color);
}

.nav-btn {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 0.5rem 1.5rem;
    font-family: var(--font-body);
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

.nav-btn:hover {
    background: var(--primary-color);
    color: white;
}

/* ═══ GAME CONTAINER ═══ */
.game-container {
    margin-top: 90px;
    padding: 2rem;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 2rem;
    align-items: start;
}

/* ═══ INFO PANEL ═══ */
.info-panel {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    position: sticky;
    top: 100px;
}

.info-box {
    background: rgba(150, 17, 20, 0.1);
    border: 1px solid var(--primary-color);
    border-radius: 6px;
    padding: 1rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.info-box h3 {
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.75rem;
    color: var(--primary-color);
}

.score-value,
.level-value,
.lines-value {
    font-family: var(--font-pixel);
    font-size: 2rem;
    color: var(--text-color);
}

.next-preview canvas {
    display: block;
    margin: 0 auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.game-btn {
    width: 100%;
    padding: 1rem;
    background: var(--primary-color);
    border: none;
    color: white;
    font-family: var(--font-pixel);
    font-size: 0.8rem;
    cursor: pointer;
    margin-bottom: 0.75rem;
    transition: all 0.3s;
    letter-spacing: 0.05em;
}

.game-btn:hover:not(:disabled) {
    background: #7a0d0f;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(150, 17, 20, 0.4);
}

.game-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.game-btn.secondary {
    background: var(--bg-secondary);
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.game-btn.secondary:hover:not(:disabled) {
    background: var(--primary-color);
    color: white;
}

/* ═══ GAME BOARD ═══ */
.game-board-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-secondary);
    border: 3px solid var(--primary-color);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 10px 40px rgba(150, 17, 20, 0.3);
}

#gameCanvas {
    display: block;
    background: #000;
    border: 2px solid rgba(150, 17, 20, 0.5);
    /* Size will be set by JS to maintain aspect ratio */
}

/* Game Over Overlay */
.game-over-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 8px;
}

.game-over-overlay.visible {
    display: flex;
}

.game-over-content {
    text-align: center;
    padding: 2rem;
}

.game-over-content h2 {
    font-family: var(--font-pixel);
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 2rem;
}

.final-score {
    margin-bottom: 2rem;
}

.final-score p {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    opacity: 0.7;
}

.final-score-value {
    font-family: var(--font-pixel);
    font-size: 3rem;
    color: var(--secondary-color);
}

/* ═══ MOBILE CONTROLS ═══ */
.mobile-controls {
    display: none;
    grid-column: 1 / -1;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    gap: 1rem;
    justify-content: center;
}

.controls-row {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.control-btn {
    width: 70px;
    height: 70px;
    background: rgba(150, 17, 20, 0.2);
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    color: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    background: var(--primary-color);
    color: white;
    transform: scale(0.95);
}

.control-btn.rotate {
    width: 150px;
}

.control-btn.drop {
    width: 150px;
}

.control-btn span {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.1em;
}

/* ═══ INSTRUCTIONS ═══ */
.instructions-panel {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    position: sticky;
    top: 100px;
}

.instructions-panel h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.instruction {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

kbd {
    background: rgba(150, 17, 20, 0.2);
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.8rem;
}

/* ═══ LEADERBOARD MODAL ═══ */
.leaderboard-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
}

.leaderboard-modal.visible {
    display: flex;
}

.leaderboard-container {
    background: var(--bg-secondary);
    border: 3px solid var(--secondary-color);
    border-radius: 12px;
    padding: 2.5rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(255, 215, 0, 0.3);
}

.close-modal {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    color: var(--secondary-color);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    width: 40px;
    height: 40px;
    transition: color 0.3s;
}

.close-modal:hover {
    color: white;
}

.leaderboard-container h2 {
    font-family: var(--font-pixel);
    font-size: 1.5rem;
    color: var(--secondary-color);
    margin-bottom: 2rem;
    text-align: center;
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: 50px 1fr 100px;
    align-items: center;
    background: rgba(255, 215, 0, 0.05);
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: 8px;
    padding: 1rem;
    transition: all 0.3s;
}

.leaderboard-item:hover {
    border-color: var(--secondary-color);
    background: rgba(255, 215, 0, 0.1);
}

.leaderboard-item.current-user {
    border-color: var(--primary-color);
    background: rgba(150, 17, 20, 0.1);
}

.rank {
    font-family: var(--font-pixel);
    font-size: 1.2rem;
    color: var(--secondary-color);
    text-align: center;
}

.rank.top-1 { color: #FFD700; }
.rank.top-2 { color: #C0C0C0; }
.rank.top-3 { color: #CD7F32; }

.username {
    font-weight: 600;
    font-size: 1rem;
}

.score {
    font-family: var(--font-pixel);
    font-size: 0.9rem;
    color: var(--secondary-color);
    text-align: right;
}

/* ═══ RESPONSIVE ═══ */

/* Tablet */
@media (max-width: 1024px) {
    .game-container {
        grid-template-columns: 240px 1fr 240px;
    }
    
    .info-panel,
    .instructions-panel {
        padding: 1rem;
    }
}

/* Mobile */
@media (max-width: 768px) {
    /* Navbar Mobile */
    .navbar {
        height: 65px;
    }
    
    .navbar-container {
        padding: 0 0.5rem;
    }
    
    .logo {
        font-size: 0.9rem;
    }
    
    .logo svg {
        width: 28px;
        height: 28px;
    }
    
    .nav-actions {
        gap: 0.4rem;
        flex-wrap: wrap;
    }
    
    .user-info {
        font-size: 0.75rem;
        order: 3;
        width: 100%;
        text-align: center;
        padding-top: 0.2rem;
    }
    
    .nav-btn {
        padding: 0.35rem 0.6rem;
        font-size: 0.65rem;
    }
    
    .nav-btn.secondary {
        padding: 0.35rem 0.5rem;
    }
    
    /* Game Container */
    body {
        overflow: hidden;
    }
    
    .game-container {
        grid-template-columns: 1fr 120px;
        grid-template-rows: 1fr auto;
        padding: 0.5rem;
        gap: 0.5rem;
        margin-top: 65px;
        height: calc(100vh - 65px);
    }
    
    /* Game Board - Left Side, Full Height */
    .game-board-wrapper {
        order: 1;
        grid-column: 1;
        grid-row: 1 / 3;
        padding: 0.25rem;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 0;
    }
    
    /* Info Panel - Right Side, Vertical Stack */
    .info-panel {
        order: 2;
        grid-column: 2;
        grid-row: 1;
        position: static;
        display: flex;
        flex-direction: column;
        gap: 0.4rem;
        padding: 0.5rem;
        overflow-y: auto;
    }
    
    .info-box {
        margin-bottom: 0;
        padding: 0.4rem;
        min-height: 0;
    }
    
    .info-box h3 {
        font-size: 0.5rem;
        margin-bottom: 0.2rem;
        letter-spacing: 0;
    }
    
    .score-value,
    .level-value,
    .lines-value {
        font-size: 0.9rem;
    }
    
    /* Next preview - compact */
    .next-preview {
        padding: 0.3rem;
    }
    
    .next-preview h3 {
        font-size: 0.45rem;
    }
    
    .next-preview canvas {
        width: 70px !important;
        height: 70px !important;
    }
    
    /* Buttons - vertical stack */
    .game-btn {
        padding: 0.4rem 0.2rem;
        font-size: 0.45rem;
        margin-bottom: 0.3rem;
        letter-spacing: 0;
    }
    
    /* Mobile Controls - Bottom Full Width */
    .mobile-controls {
        order: 3;
        grid-column: 1 / -1;
        grid-row: 2;
        display: grid;
        padding: 0.5rem;
        gap: 0.4rem;
        background: rgba(26, 26, 46, 0.5);
    }
    
    .controls-row {
        gap: 0.5rem;
    }
    
    .control-btn {
        width: 55px;
        height: 55px;
    }
    
    .control-btn.rotate {
        width: 120px;
    }
    
    .control-btn.drop {
        width: 120px;
    }
    
    .control-btn svg {
        width: 28px;
        height: 28px;
    }
    
    .instructions-panel {
        display: none;
    }
}

/* Mobile Small - Extra Compact */
@media (max-width: 480px) {
    .navbar {
        height: 60px;
    }
    
    .navbar-container {
        padding: 0 0.5rem;
    }
    
    .logo {
        font-size: 0.8rem;
    }
    
    .logo svg {
        width: 24px;
        height: 24px;
    }
    
    .nav-actions {
        gap: 0.3rem;
    }
    
    .user-info {
        font-size: 0.7rem;
    }
    
    .nav-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.6rem;
    }
    
    .game-container {
        margin-top: 60px;
        height: calc(100vh - 60px);
        padding: 0.3rem;
        gap: 0.3rem;
        grid-template-columns: 1fr 100px;
    }
    
    .game-board-wrapper {
        padding: 0.2rem;
    }
    
    .info-panel {
        padding: 0.3rem;
        gap: 0.3rem;
    }
    
    .info-box {
        padding: 0.3rem;
    }
    
    .info-box h3 {
        font-size: 0.4rem;
    }
    
    .score-value,
    .level-value,
    .lines-value {
        font-size: 0.8rem;
    }
    
    .next-preview canvas {
        width: 60px !important;
        height: 60px !important;
    }
    
    .game-btn {
        padding: 0.35rem 0.2rem;
        font-size: 0.4rem;
    }
    
    .mobile-controls {
        padding: 0.4rem;
    }
    
    .control-btn {
        width: 50px;
        height: 50px;
    }
    
    .control-btn.rotate,
    .control-btn.drop {
        width: 105px;
    }
    
    .control-btn svg {
        width: 24px;
        height: 24px;
    }
    
    .control-btn span {
        font-size: 0.55rem;
    }
}

/* Mobile Tiny (very small screens) */
@media (max-width: 380px) {
    .game-container {
        grid-template-columns: 1fr 90px;
    }
    
    .info-panel {
        padding: 0.25rem;
        gap: 0.25rem;
    }
    
    .info-box {
        padding: 0.25rem;
    }
    
    .info-box h3 {
        font-size: 0.35rem;
        margin-bottom: 0.1rem;
    }
    
    .score-value,
    .level-value,
    .lines-value {
        font-size: 0.7rem;
    }
    
    .next-preview canvas {
        width: 50px !important;
        height: 50px !important;
    }
    
    .game-btn {
        padding: 0.3rem 0.15rem;
        font-size: 0.35rem;
        margin-bottom: 0.2rem;
    }
    
    .control-btn {
        width: 45px;
        height: 45px;
    }
    
    .control-btn.rotate,
    .control-btn.drop {
        width: 95px;
    }
}

/* Touch Optimizations */
@media (hover: none) and (pointer: coarse) {
    .control-btn {
        min-height: 70px;
        min-width: 70px;
    }
}

/* Landscape Mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .game-container {
        grid-template-columns: 200px 1fr 200px;
        grid-template-rows: auto;
    }
    
    .mobile-controls {
        display: none; /* Hide in landscape for more space */
    }
}
