/* ===== Tetris - Real Simulation ===== */

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: transparent;
    color: #e0e0e0;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Dark background behind rain */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0a14;
    z-index: -1;
}

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

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

/* Home Button (inside HUD bar) */
.home-btn {
    color: #e94560;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: bold;
    letter-spacing: 1.5px;
    padding: 4px 10px;
    border: 1px solid rgba(233, 69, 96, 0.3);
    border-radius: 6px;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.home-btn:hover {
    color: #ff6b81;
    border-color: rgba(233, 69, 96, 0.6);
    background: rgba(233, 69, 96, 0.1);
}

/* Top HUD (fixed) */
#hud-top {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: rgba(10, 10, 20, 0.85);
    border: 1px solid rgba(233, 69, 96, 0.3);
    border-radius: 8px;
    padding: 6px 16px;
    white-space: nowrap;
}

#level-display {
    font-size: 0.85rem;
    color: #e94560;
    font-weight: bold;
    letter-spacing: 2px;
}

#score-display {
    font-size: 0.75rem;
    color: #888;
    letter-spacing: 1px;
}

#score-value {
    color: #ffd700;
    font-weight: bold;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

/* Main Layout */
#main-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100dvh;
    padding-top: 56px; /* space for top HUD */
    padding-bottom: 110px; /* space for 2-row bottom bar */
    gap: 0;
    overflow: hidden;
}

/* Board Wrapper */
#board-wrapper {
    position: relative;
    border: 2px solid rgba(233, 69, 96, 0.5);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(233, 69, 96, 0.2);
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    max-width: 512px;
}

#game-board {
    display: block;
    image-rendering: pixelated;
    max-width: 100%;
    max-height: 100%;
}

/* Overlay (Game Over) */
#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 10;
}

#overlay-text {
    font-size: 2.5rem;
    font-weight: 900;
    color: #e94560;
    text-shadow: 0 0 20px rgba(233, 69, 96, 0.5);
    letter-spacing: 4px;
}

#final-score {
    font-size: 1.2rem;
    color: #ffd700;
}

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

#player-name {
    background: rgba(26, 26, 46, 0.9);
    border: 1px solid rgba(233, 69, 96, 0.5);
    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;
}

/* Desktop Controls Panel — hidden by default (mobile) */
#controls-panel {
    display: none;
    background: rgba(10, 10, 20, 0.85);
    border: 1px solid rgba(233, 69, 96, 0.3);
    border-radius: 12px;
    padding: 1rem 1.2rem;
    width: 160px;
    flex-shrink: 0;
    align-self: center;
}

.controls-title {
    font-size: 0.7rem;
    font-weight: 700;
    color: #e94560;
    letter-spacing: 2px;
    text-align: center;
    margin-bottom: 0.8rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(233, 69, 96, 0.2);
}

.control-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}

.control-row:last-child {
    margin-bottom: 0;
}

.key-cap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 28px;
    background: rgba(233, 69, 96, 0.15);
    border: 1px solid rgba(233, 69, 96, 0.4);
    border-radius: 5px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.key-cap.wide {
    width: 60px;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
}

.key-label {
    font-size: 0.75rem;
    color: #888;
    letter-spacing: 0.5px;
}

/* Start Overlay */
#start-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    z-index: 10;
}

#start-text {
    font-size: 4rem;
    font-weight: 900;
    color: #ffd700;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.5);
    letter-spacing: 8px;
}

#start-btn {
    padding: 1rem 3rem;
    font-size: 1.3rem;
    background: linear-gradient(135deg, #e94560, #ff6b81);
}

/* ===== Bottom Touch Controls ===== */
#touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20;
    background: linear-gradient(0deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.6) 80%, transparent 100%);
    padding: 4px 0 10px;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
}

.touch-row {
    display: flex;
    gap: 4px;
    justify-content: center;
    align-items: center;
    width: 100vw;
    padding: 0 4px;
    margin: 0;
    box-sizing: border-box;
}

.touch-btn {
    flex: 1;
    height: 44px;
    font-size: 1.1rem;
    background: rgba(233, 69, 96, 0.18);
    border: 1.5px solid rgba(233, 69, 96, 0.35);
    border-radius: 6px;
    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;
    min-width: 0;
}

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

/* Desktop: hide touch controls, show keyboard hint */
@media (min-width: 801px) {
    #touch-controls {
        display: none;
    }
    .controls-hint {
        display: block;
    }
    #controls-panel {
        display: flex;
        flex-direction: column;
    }
    #main-layout {
        flex-direction: row;
        height: auto;
        min-height: 100vh;
        padding-top: 90px;
        padding-bottom: 2rem;
        gap: 2rem;
        justify-content: center;
        max-width: 1200px;
        overflow: visible;
    }
    #board-wrapper {
        border: 2px solid rgba(233, 69, 96, 0.5);
        max-width: none;
    }
    #hud-top {
        top: 14px;
    }
}

/* Mobile */
@media (max-width: 800px) {
    .controls-hint {
        display: none;
    }
}
