/* ===== Tetris – Matching Original Pygame Style + Leaderboard ===== */

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

body {
    background: #0a0a0a;
    color: #e0e0e0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    overflow: hidden;
    touch-action: none;
}

/* Background Canvas */
#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    height: 100vh;
    height: 100dvh;
    z-index: 1;
    overflow: hidden;
}

.back-btn {
    position: absolute;
    top: 10px;
    left: 10px;
    color: #e94560;
    text-decoration: none;
    font-size: 1rem;
    z-index: 10;
}

.back-btn:hover {
    color: #ff6b81;
}

/* Main Layout */
#main-layout {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    flex: 1;
    min-height: 0;
    padding: 1rem;
    padding-top: 0.5rem;
}

/* Leaderboard Panel */
#leaderboard-panel {
    width: 200px;
    flex-shrink: 0;
    background: #111118;
    border: 2px solid #2a2a3a;
    border-radius: 8px;
    padding: 1rem;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

#leaderboard-panel h2 {
    font-size: 1rem;
    color: #ffd700;
    text-align: center;
    margin-bottom: 0.8rem;
    letter-spacing: 1px;
    border-bottom: 1px solid #2a2a3a;
    padding-bottom: 0.5rem;
}

#leaderboard-list {
    list-style: none;
}

.lb-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0.3rem;
    border-bottom: 1px solid #1a1a2a;
    font-size: 0.85rem;
}

.lb-entry:nth-child(1) .lb-rank { color: #ffd700; font-weight: bold; }
.lb-entry:nth-child(2) .lb-rank { color: #c0c0c0; font-weight: bold; }
.lb-entry:nth-child(3) .lb-rank { color: #cd7f32; font-weight: bold; }

.lb-rank {
    color: #666;
    font-weight: bold;
    min-width: 24px;
}

.lb-name {
    flex: 1;
    color: #ccc;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 0.3rem;
}

.lb-score {
    color: #ffd700;
    font-weight: bold;
    min-width: 50px;
    text-align: right;
}

.lb-empty {
    text-align: center;
    color: #555;
    font-size: 0.85rem;
    padding: 2rem 0;
}

.small-btn {
    width: 100%;
    margin-top: 0.8rem;
    padding: 0.4rem;
    font-size: 0.75rem;
    background: #333;
    color: #888;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
}

.small-btn:hover {
    background: #444;
    color: #aaa;
}

/* Board */
#board-wrapper {
    position: relative;
    border: 2px solid #333;
    line-height: 0;
}

#game-board {
    display: block;
}

/* HUD Display (during game) */
#hud-display {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid #444;
    border-radius: 6px;
    padding: 0.5rem 0.8rem;
    z-index: 3;
    text-align: right;
    min-width: 120px;
}

#level-display {
    font-family: 'Impact', 'Arial Black', sans-serif;
    font-size: 1.3rem;
    color: #e94560;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-bottom: 0.6rem;
    text-shadow: 0 0 10px rgba(233, 69, 96, 0.5);
}

#score-display {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    border-top: 1px solid #333;
    padding-top: 0.4rem;
}

#score-label {
    font-size: 0.7rem;
    color: #888;
    letter-spacing: 2px;
    text-transform: uppercase;
    white-space: nowrap;
}

#score-value {
    color: #ffd700;
    font-size: 1.3rem;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    min-width: 60px;
}

/* HUD Pause Button */
.hud-btn {
    background: rgba(60, 60, 80, 0.9);
    color: #ccc;
    border: 1px solid #555;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 0.5rem;
    width: 100%;
    transition: background 0.2s;
}

.hud-btn:hover {
    background: rgba(80, 80, 100, 0.9);
    color: #fff;
}

/* Overlays */
#overlay, #start-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.88);
    z-index: 5;
}

#overlay-text {
    font-size: 2rem;
    font-weight: bold;
    color: #ff0000;
    margin-bottom: 0.5rem;
    letter-spacing: 3px;
}

#final-score {
    font-size: 1.2rem;
    color: #ffd700;
    margin-bottom: 1rem;
    font-family: 'Courier New', monospace;
}

#start-text {
    font-size: 2.5rem;
    font-weight: bold;
    color: #ffff00;
    margin-bottom: 1.5rem;
    letter-spacing: 4px;
}

/* Name Entry Form */
#name-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#player-name {
    background: #1a1a2e;
    border: 2px solid #444;
    color: #fff;
    padding: 0.6rem 1rem;
    font-size: 1rem;
    border-radius: 6px;
    text-align: center;
    width: 220px;
    outline: none;
}

#player-name:focus {
    border-color: #e94560;
}

#player-name::placeholder {
    color: #666;
}

/* Buttons */
button {
    background: #e94560;
    color: white;
    border: none;
    padding: 0.8rem 2rem;
    font-size: 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

button:hover {
    background: #ff6b81;
}

.secondary-btn {
    background: #444 !important;
    font-size: 0.9rem !important;
    padding: 0.5rem 1.5rem !important;
}

.secondary-btn:hover {
    background: #666 !important;
}

.controls-hint {
    margin-top: 1rem;
    color: #666;
    font-size: 0.85rem;
}

.hidden {
    display: none !important;
}

/* Touch Controls - hidden on desktop */
#touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px;
    padding-bottom: 16px;
    z-index: 20;
    user-select: none;
    -webkit-user-select: none;
    background: linear-gradient(0deg, rgba(0,0,0,0.6) 0%, transparent 100%);
}

@media (min-width: 801px) {
    #touch-controls {
        display: none !important;
    }
}

.touch-row {
    display: flex;
    gap: 6px;
    justify-content: center;
}

.touch-btn {
    width: 48px;
    height: 48px;
    font-size: 1.3rem;
    background: rgba(233, 69, 96, 0.18);
    border: 1.5px solid rgba(233, 69, 96, 0.35);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.touch-btn:active {
    background: rgba(233, 69, 96, 0.45);
    color: #fff;
}

.touch-btn-wide {
    width: 100%;
    max-width: 240px;
    height: 40px;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

/* Mobile */
@media (max-width: 800px) {
    #app {
        height: 100vh;
        height: 100dvh;
    }

    #main-layout {
        flex-direction: column;
        align-items: center;
        padding: 0;
        gap: 0;
        overflow: hidden;
    }

    .back-btn {
        position: fixed;
        top: 10px;
        left: 10px;
        z-index: 30;
    }

    #leaderboard-panel {
        display: none;
    }

    #board-wrapper {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100%;
        max-height: calc(100vh - 220px);
    }

    #game-board {
        max-width: 100vw;
        max-height: calc(100vh - 220px);
        width: auto;
        height: auto;
    }

    #touch-controls {
        display: flex;
    }

    .controls-hint {
        display: none;
    }

    #hud-display {
        top: 50px;
        right: 5px;
        padding: 0.3rem 0.5rem;
        min-width: 90px;
    }

    #level-display {
        font-size: 0.9rem;
    }

    #score-value {
        font-size: 1rem;
    }
}
