/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
    --bg-primary: #080710;
    --bg-secondary: #0f0d2b;
    --panel-bg: rgba(255, 255, 255, 0.03);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-muted: #8b8a9f;
    --accent-neon: #00f0f0;
    
    /* Tetromino Colors (Neon) */
    --color-i: #00f0f0; /* Cyan */
    --color-o: #f0f000; /* Yellow */
    --color-t: #a000f0; /* Purple */
    --color-s: #00f000; /* Green */
    --color-z: #f00000; /* Red */
    --color-j: #0000f0; /* Blue */
    --color-l: #f0a000; /* Orange */
    
    --font-main: 'Outfit', sans-serif;
    --font-digital: 'Orbitron', sans-serif;
    --glow-shadow: 0 0 15px rgba(0, 240, 240, 0.3);
    --panel-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Reset and Core Layout */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(at 10% 20%, rgba(13, 11, 43, 1) 0px, transparent 50%),
        radial-gradient(at 90% 80%, rgba(31, 10, 54, 0.7) 0px, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-main);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

html {
    height: -webkit-fill-available;
}

#app-container {
    width: 100%;
    max-width: 480px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 10px 15px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    position: relative;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
#game-header {
    text-align: center;
    padding: 10px 0 5px 0;
}

#game-title {
    font-size: 1.8rem;
    font-weight: 900;
    letter-spacing: 4px;
    font-family: var(--font-digital);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.1), 0 0 20px rgba(0, 240, 240, 0.3);
}

#game-title .highlight {
    color: var(--accent-neon);
    text-shadow: 0 0 10px rgba(0, 240, 240, 0.6), 0 0 20px rgba(0, 240, 240, 0.3);
}

/* ==========================================================================
   MAIN LAYOUT (BOARDS AND PANELS)
   ========================================================================== */
#game-layout {
    display: grid;
    grid-template-columns: 80px 1fr 80px;
    gap: 12px;
    flex: 1;
    align-items: center;
    justify-content: center;
    max-height: 58vh; /* Keep space for controllers below */
}

/* Glassmorphism Panel Base */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    box-shadow: var(--panel-glow);
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.panel-title {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.canvas-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    overflow: hidden;
}

/* Canvas Configurations */
#game-board {
    display: block;
    width: 100%;
    height: auto;
    max-height: 50vh;
    border-radius: 12px;
    background-color: rgba(6, 5, 15, 0.85);
}

.main-board {
    padding: 4px;
    border: 1px solid rgba(0, 240, 240, 0.2);
    box-shadow: 0 0 20px rgba(0, 240, 240, 0.1);
}

#hold-canvas, #next-canvas {
    width: 100%;
    height: auto;
    aspect-ratio: 1/1;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
}

/* Side Panels specific layouts */
#hold-panel, #info-panel {
    align-self: stretch;
    justify-content: space-around;
}

.next-subpanel {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stats-subpanel {
    width: 100%;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-box {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    padding: 6px 4px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.stat-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 2px;
    letter-spacing: 0.5px;
}

.stat-value {
    font-family: var(--font-digital);
    font-size: 0.85rem;
    font-weight: 700;
    color: #00ffcc;
    text-shadow: 0 0 5px rgba(0, 255, 204, 0.3);
}

.max-score-box .stat-value {
    color: #ff0077;
    text-shadow: 0 0 5px rgba(255, 0, 119, 0.3);
}

/* ==========================================================================
   MOBILE CONTROLS (GAMEPAD)
   ========================================================================== */
#mobile-gamepad {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 10px 0;
    height: 26vh;
}

.d-pad {
    display: grid;
    grid-template-columns: 60px 60px 60px;
    grid-template-rows: 60px;
    align-items: center;
    gap: 8px;
}

.d-pad-vertical {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

/* Buttons Design */
.gamepad-btn {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.07) 0%, rgba(255, 255, 255, 0.02) 100%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.1s ease;
    touch-action: manipulation;
}

.gamepad-btn:active {
    transform: scale(0.92);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.05) 100%);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
}

.arrow-btn {
    width: 60px;
    height: 60px;
}

.arrow-btn svg {
    width: 26px;
    height: 26px;
    color: #e2e8f0;
}

.action-sub-btn {
    width: 55px;
    height: 32px;
    border-radius: 16px;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 1px;
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.action-buttons {
    display: flex;
    gap: 15px;
    align-items: center;
}

.action-main-btn {
    width: 76px;
    height: 76px;
    font-family: var(--font-main);
    font-weight: 800;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.rotate-btn {
    background: linear-gradient(135deg, rgba(160, 0, 240, 0.35) 0%, rgba(160, 0, 240, 0.1) 100%);
    border-color: rgba(160, 0, 240, 0.4);
    color: #e0b0ff;
    box-shadow: 0 4px 15px rgba(160, 0, 240, 0.2);
}

.rotate-btn:active {
    background: linear-gradient(135deg, rgba(160, 0, 240, 0.6) 0%, rgba(160, 0, 240, 0.2) 100%);
    border-color: rgba(160, 0, 240, 0.7);
    box-shadow: 0 0 15px rgba(160, 0, 240, 0.4);
}

.drop-btn {
    background: linear-gradient(135deg, rgba(0, 240, 240, 0.3) 0%, rgba(0, 240, 240, 0.05) 100%);
    border-color: rgba(0, 240, 240, 0.3);
    color: #b0ffff;
    box-shadow: 0 4px 15px rgba(0, 240, 240, 0.15);
}

.drop-btn:active {
    background: linear-gradient(135deg, rgba(0, 240, 240, 0.5) 0%, rgba(0, 240, 240, 0.15) 100%);
    border-color: rgba(0, 240, 240, 0.6);
    box-shadow: 0 0 15px rgba(0, 240, 240, 0.3);
}

/* ==========================================================================
   FOOTER CONTROLS BAR
   ========================================================================== */
#game-controls-bar {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 5px 0;
    height: 5vh;
    min-height: 35px;
}

.control-bar-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--panel-border);
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.control-bar-btn:hover, .control-bar-btn:active {
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
}

/* ==========================================================================
   OVERLAYS (MENU, GAMEOVER, PAUSE)
   ========================================================================== */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(8, 7, 16, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
    border-radius: 20px;
    padding: 20px;
}

.overlay.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.overlay-content {
    background: linear-gradient(135deg, rgba(20, 15, 48, 0.9) 0%, rgba(10, 5, 25, 0.95) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 30px 20px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(0, 240, 240, 0.1);
}

.overlay-title {
    font-family: var(--font-digital);
    font-size: 2.2rem;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: 2px;
    margin-bottom: 8px;
    text-shadow: 0 0 10px rgba(0, 240, 240, 0.5);
}

.game-over-title {
    color: #ff0055;
    text-shadow: 0 0 15px rgba(255, 0, 85, 0.5);
}

.overlay-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.overlay-btn {
    width: 100%;
    padding: 14px 20px;
    font-family: var(--font-main);
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 2px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.primary-btn {
    background: linear-gradient(90deg, #00f0f0 0%, #00a0f0 100%);
    color: #000;
    box-shadow: 0 4px 15px rgba(0, 240, 240, 0.4);
}

.primary-btn:active {
    transform: scale(0.97);
    box-shadow: 0 2px 5px rgba(0, 240, 240, 0.2);
}

/* Instructions */
.instructions-box {
    margin-top: 25px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 12px;
}

.instructions-box h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.instructions-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 15px;
    font-size: 0.75rem;
    text-align: left;
    color: #cbd5e1;
}

.instructions-grid kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    padding: 2px 5px;
    font-family: sans-serif;
    font-size: 0.65rem;
}

/* Final Score box */
.final-score-container {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 25px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.final-score-container p {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.final-score-container h3 {
    font-family: var(--font-digital);
    font-size: 2rem;
    color: #00ffcc;
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.4);
}

#new-high-score-tag {
    display: inline-block;
    background: #ff0077;
    color: white;
    font-size: 0.65rem;
    font-weight: 900;
    padding: 3px 8px;
    border-radius: 10px;
    margin-top: 8px;
    letter-spacing: 1px;
    animation: pulse 1.2s infinite;
}

.hidden-element {
    display: none !important;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 0, 119, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 6px rgba(255, 0, 119, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 0, 119, 0); }
}

/* ==========================================================================
   MEDIA QUERIES (DESKTOP AND SMALL SCREEN SCALING)
   ========================================================================== */

/* Disable mobile controls on desktop (but allow touch devices of any size) */
@media (min-width: 600px) {
    #app-container {
        max-width: 580px;
    }
    
    #game-layout {
        grid-template-columns: 100px 1fr 100px;
        gap: 15px;
        max-height: 70vh;
    }
    
    .panel-title {
        font-size: 0.75rem;
    }
    
    .stat-value {
        font-size: 1rem;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    /* Hide gamepad on desktop since keyboard is easier */
    #mobile-gamepad {
        display: none;
    }
    
    #game-controls-bar {
        height: 6vh;
    }
}

/* Adjust sizes for very short mobile screens */
@media (max-height: 680px) and (max-width: 600px) {
    #game-title {
        font-size: 1.4rem;
    }
    
    #game-layout {
        gap: 8px;
        max-height: 52vh;
    }
    
    .glass-panel {
        padding: 5px;
        border-radius: 12px;
    }
    
    #mobile-gamepad {
        height: 25vh;
        padding: 5px 0;
    }
    
    .arrow-btn {
        width: 48px;
        height: 48px;
    }
    
    .arrow-btn svg {
        width: 20px;
        height: 20px;
    }
    
    .d-pad {
        grid-template-columns: 48px 48px 48px;
        gap: 5px;
    }
    
    .action-sub-btn {
        width: 45px;
        height: 26px;
        font-size: 0.55rem;
    }
    
    .action-main-btn {
        width: 62px;
        height: 62px;
        font-size: 0.75rem;
    }
    
    .stat-value {
        font-size: 0.75rem;
    }
}

/* Support for notch/home indicator in modern phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #app-container {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        padding-left: calc(15px + env(safe-area-inset-left));
        padding-right: calc(15px + env(safe-area-inset-right));
    }
}
