/* Global Reset & Base Variables */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #0a0b10;
    --panel-bg: rgba(18, 20, 32, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    
    /* Neon glow colors */
    --neon-pink: #ff007f;
    --neon-cyan: #00f0ff;
    --neon-green: #39ff14;
    --neon-yellow: #fffb00;
    --neon-purple: #b026ff;
    --neon-orange: #ff6700;
    --neon-white: #ffffff;
    
    /* Touch UI button sizes with maximum bounds for tablet scaling */
    --btn-w-port: min(25vw, 120px);
    --btn-w-land: min(25vh, 120px);
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: #e2e8f0;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

/* Glassmorphism panel helper */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

/* Application Container */
#app-container {
    width: 95vw;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
}

/* Game Header */
#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

#game-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: 2.5rem;
    color: #ffffff;
    text-shadow: 0 0 10px var(--neon-cyan), 0 0 20px var(--neon-cyan);
    letter-spacing: 4px;
}

#header-stats {
    display: flex;
    gap: 25px;
    padding: 10px 20px;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 2px;
    border-color: rgba(0, 240, 255, 0.3);
    box-shadow: inset 0 0 10px rgba(0, 240, 255, 0.1);
}

.header-stat {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-stat .stat-label {
    color: #94a3b8;
}

.header-stat .stat-value {
    color: var(--neon-cyan);
    text-shadow: 0 0 8px var(--neon-cyan);
}

/* Main Layout Grid */
#main-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    height: 75vh;
    min-height: 500px;
}

/* Canvas Container */
#canvas-container {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: hidden;
    border-color: rgba(255, 255, 255, 0.05);
}

#game-canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    transition: transform 0.1s ease;
}

/* Game Over Overlay */
#game-over-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 11, 16, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

#pause-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0b10; /* Solid background to replace the board completely */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 30px;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
    text-align: center;
}

#game-over-overlay.hidden, #pause-overlay.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.pause-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.6rem, 3.8vh, 2.4rem);
    font-weight: 900;
    color: var(--neon-cyan);
    text-shadow: 0 0 10px var(--neon-cyan);
    letter-spacing: 4px;
    margin-bottom: 2vh;
    flex-shrink: 0;
}

.pause-description {
    font-family: 'Inter', sans-serif;
    color: #a0a5c0;
    font-size: clamp(0.72rem, 1.7vh, 0.95rem);
    line-height: 1.55;
    margin-bottom: 3vh;
    max-width: 460px;
    text-align: center;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    width: 100%;
    padding: 0 10px;
}

.pause-description::-webkit-scrollbar {
    width: 6px;
}
.pause-description::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 3px;
}
.pause-description::-webkit-scrollbar-thumb {
    background: rgba(0, 240, 255, 0.3);
    border-radius: 3px;
}
.pause-description::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 240, 255, 0.6);
}

.pause-description p {
    margin-bottom: 1.5vh;
}

.pause-description p:last-child {
    margin-bottom: 0;
}

.pause-description strong {
    color: #ffffff;
}

.resume-instruction {
    font-family: 'Orbitron', sans-serif;
    color: var(--neon-green) !important;
    text-shadow: 0 0 5px rgba(57, 255, 20, 0.3);
    margin-top: 2.5vh;
    font-weight: 700;
    letter-spacing: 1px;
}

#resume-button {
    background: transparent;
    border: 2px solid var(--neon-cyan);
    color: var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.1);
}

#resume-button:hover {
    background: var(--neon-cyan);
    color: #0a0b10;
    box-shadow: 0 0 15px var(--neon-cyan);
}

.overlay-content {
    padding: 40px;
    text-align: center;
    border-color: rgba(255, 0, 127, 0.3);
    box-shadow: 0 0 20px rgba(255, 0, 127, 0.2);
}

.overlay-content h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.2rem;
    font-weight: 900;
    margin-bottom: 25px;
    color: var(--neon-pink);
    text-shadow: 0 0 10px var(--neon-pink);
    letter-spacing: 3px;
}

/* Game Over Stats */
#game-over-stats {
    display: flex;
    gap: 30px;
    justify-content: center;
    margin-bottom: 20px;
}

.go-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.go-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75rem;
    color: #94a3b8;
    letter-spacing: 2px;
}

.go-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    color: var(--neon-cyan);
    text-shadow: 0 0 10px var(--neon-cyan);
}

#go-new-highscore {
    font-family: 'Orbitron', sans-serif;
    color: var(--neon-yellow);
    font-size: 1.1rem;
    font-weight: 900;
    text-shadow: 0 0 10px var(--neon-yellow);
    margin-bottom: 15px;
    animation: highscore-pulse 0.6s ease infinite alternate;
}

#go-new-highscore.hidden {
    display: none;
}

@keyframes highscore-pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.08); text-shadow: 0 0 15px var(--neon-yellow), 0 0 30px rgba(255, 251, 0, 0.3); }
}

.highscore-beat {
    animation: highscore-pulse 0.5s ease 3 !important;
    color: var(--neon-yellow) !important;
    text-shadow: 0 0 12px var(--neon-yellow) !important;
}

/* Mute Button */
.mute-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.6;
    transition: opacity 0.2s ease;
    line-height: 1;
}

.mute-btn:hover {
    opacity: 1;
}

button {
    font-family: 'Orbitron', sans-serif;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 12px 30px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

#restart-button {
    background: transparent;
    border: 2px solid var(--neon-pink);
    color: var(--neon-pink);
    box-shadow: 0 0 10px rgba(255, 0, 127, 0.1);
}

#restart-button:hover {
    background: var(--neon-pink);
    color: #ffffff;
    box-shadow: 0 0 15px var(--neon-pink);
}

/* Side controls Panel */
#controls-panel {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 25px;
    border-color: rgba(255, 255, 255, 0.05);
}

/* Next Piece Preview Styling */
#next-piece-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 20px;
    margin-bottom: 15px;
}

#next-piece-container h3 {
    border-bottom: none !important;
    padding-bottom: 0 !important;
    margin-bottom: 10px !important;
}

.next-canvas-wrapper {
    background: rgba(10, 11, 16, 0.5);
    border: 1.5px dashed rgba(0, 240, 255, 0.25);
    border-radius: 8px;
    padding: 6px;
    box-shadow: inset 0 0 12px rgba(0, 240, 255, 0.05);
}

#next-canvas {
    display: block;
    width: 100px;
    height: 100px;
}

#controls-panel h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 20px;
    color: #ffffff;
    text-align: center;
}



.game-status-btn-container {
    margin-top: auto;
}

#start-button {
    width: 100%;
    background: transparent;
    border: 2px solid var(--neon-green);
    color: var(--neon-green);
    box-shadow: 0 0 10px rgba(57, 255, 20, 0.1);
}

#start-button:hover {
    background: var(--neon-green);
    color: #0a0b10;
    box-shadow: 0 0 15px var(--neon-green);
}

/* Virtual Keypad Styling */
#virtual-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px 10px;
    margin: 20px 0;
}

.keypad-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.shortcut-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    display: block;
    height: 14px;
    line-height: 14px;
}



.keypad-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #ffffff;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.keypad-btn:hover {
    background: rgba(0, 240, 255, 0.15);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.keypad-btn:active {
    transform: scale(0.95);
}

/* Specific styling for action buttons */
.keypad-btn[data-control="hardDrop"] {
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.keypad-btn[data-control="hardDrop"]:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: #ffffff;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.4);
}

#level-up-notification {
    position: absolute;
    pointer-events: none;
    z-index: 90;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0);
    opacity: 0;
    transform: scale(0.5);
    transition: all 1.2s cubic-bezier(0.19, 1, 0.22, 1);
}

#level-up-notification.level-up-animate {
    opacity: 1;
    transform: scale(1.1) translateY(-30px);
    background: radial-gradient(circle, rgba(0, 240, 255, 0.15) 0%, rgba(0, 0, 0, 0) 70%);
}

#level-up-text {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: 4rem;
    color: #ffffff;
    text-shadow: 
        0 0 10px #ffffff,
        0 0 20px var(--neon-yellow),
        0 0 40px var(--neon-orange),
        0 0 80px #ff0000;
    letter-spacing: 6px;
    text-transform: uppercase;
    animation: neon-pulse 1.2s infinite alternate;
}

@keyframes neon-pulse {
    0% {
        transform: scale(1);
        text-shadow: 
            0 0 10px #ffffff,
            0 0 20px var(--neon-yellow),
            0 0 40px var(--neon-orange),
            0 0 80px #ff0000;
    }
    100% {
        transform: scale(1.06);
        text-shadow: 
            0 0 15px #ffffff,
            0 0 30px var(--neon-green),
            0 0 60px var(--neon-cyan),
            0 0 100px var(--neon-purple);
    }
}

/* Difficulty Selector & Info Styling */
#difficulty-container {
    margin-top: 15px;
    margin-bottom: 15px;
}

#difficulty-container h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem !important;
    letter-spacing: 2px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
    margin-bottom: 12px !important;
    color: #ffffff;
    text-align: center;
}

.difficulty-status-text {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.25rem;
    font-weight: 900;
    text-align: center;
    letter-spacing: 2px;
    padding: 8px 0;
    transition: all 0.25s ease;
}

.difficulty-status-text.easy {
    color: var(--neon-green);
    text-shadow: 0 0 8px var(--neon-green);
}

.difficulty-status-text.medium {
    color: var(--neon-yellow);
    text-shadow: 0 0 8px var(--neon-yellow);
}

.difficulty-status-text.hard {
    color: var(--neon-pink);
    text-shadow: 0 0 8px var(--neon-pink);
}

/* Start Menu / Difficulty Selection Overlay */
#difficulty-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 11, 16, 0.95); /* Solid dark mask over empty board */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 30px;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
    text-align: center;
}

#difficulty-overlay.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.menu-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.4rem, 3.5vh, 2.2rem);
    font-weight: 900;
    color: #ffffff;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
    letter-spacing: 4px;
    margin-bottom: 2vh;
    text-transform: uppercase;
}

.menu-tagline {
    font-family: 'Inter', sans-serif;
    color: #64748b;
    font-size: clamp(0.65rem, 1.4vh, 0.85rem);
    max-width: 280px;
    line-height: 1.5;
    margin-bottom: 3vh;
    text-align: center;
}

.menu-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 280px;
    margin-bottom: 4vh;
}

.menu-opt-btn {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.9rem, 2vh, 1.2rem);
    font-weight: 700;
    padding: 14px 20px;
    border-radius: 8px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    background: rgba(18, 20, 32, 0.75);
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 2px;
    width: 100%;
    text-transform: uppercase;
}

/* Hover styles */
.menu-opt-btn:hover {
    color: #ffffff;
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.05);
}

/* Active/Selected styles for keyboard/click navigation */
.menu-opt-btn.easy.active {
    border-color: var(--neon-green);
    color: var(--neon-green);
    background: rgba(57, 255, 20, 0.1);
    box-shadow: 0 0 15px var(--neon-green);
}

.menu-opt-btn.medium.active {
    border-color: var(--neon-yellow);
    color: var(--neon-yellow);
    background: rgba(255, 251, 0, 0.1);
    box-shadow: 0 0 15px var(--neon-yellow);
}

.menu-opt-btn.hard.active {
    border-color: var(--neon-pink);
    color: var(--neon-pink);
    background: rgba(255, 0, 127, 0.1);
    box-shadow: 0 0 15px var(--neon-pink);
}

.menu-instruction {
    font-family: 'Inter', sans-serif;
    color: #64748b;
    font-size: clamp(0.7rem, 1.6vh, 0.95rem);
    letter-spacing: 0.5px;
}

/* Level Selector Container */
.menu-level-selector-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 4vh;
    width: 100%;
    max-width: 280px;
}

.level-selector-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(0.75rem, 1.6vh, 0.95rem);
    color: var(--neon-cyan);
    text-shadow: 0 0 5px rgba(0, 240, 255, 0.3);
    letter-spacing: 2px;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.level-selector-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: rgba(18, 20, 32, 0.75);
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 12px;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.5);
    transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.level-selector-row:hover {
    border-color: rgba(0, 240, 255, 0.3);
    box-shadow: 0 0 12px rgba(0, 240, 255, 0.1), inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.level-selector-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.6rem;
    font-weight: 700;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    user-select: none;
}

.level-selector-btn:hover {
    color: var(--neon-cyan);
    text-shadow: 0 0 8px var(--neon-cyan);
    background: rgba(255, 255, 255, 0.05);
}

.level-selector-btn:active {
    transform: scale(0.9);
}

.level-glow-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

#menu-level-display {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.8rem;
    font-weight: 900;
    color: #ffffff;
    text-shadow: 0 0 10px #ffffff;
    transition: all 0.15s ease;
    user-select: none;
}

/* Pulsing highlight when level changes */
.level-changed-pulse {
    animation: level-change-anim 0.25s ease;
}

@keyframes level-change-anim {
    0% { transform: scale(1); text-shadow: 0 0 10px #ffffff; }
    50% { transform: scale(1.3); text-shadow: 0 0 20px var(--neon-cyan), 0 0 35px var(--neon-cyan); color: var(--neon-cyan); }
    100% { transform: scale(1); text-shadow: 0 0 10px #ffffff; }
}


/* System Action Buttons (Pause, Mute & Restart) */
.system-buttons {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: end;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px dashed rgba(255, 255, 255, 0.1);
}

.sys-mute-cell {
    display: flex;
    align-items: flex-end;
}

.sys-mute-cell .mute-btn {
    font-size: 1.4rem;
    padding: 10px 6px;
    opacity: 0.5;
}

.sys-btn-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.sys-shortcut-label {
    font-family: 'Inter', sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.sys-action-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #ffffff;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    letter-spacing: 1px;
}

.sys-action-btn:hover {
    background: rgba(0, 240, 255, 0.15);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.4);
}

.sys-action-btn:active {
    transform: scale(0.95);
}

/* Mobile elements default hide */
#mobile-hud, #mobile-next-preview, #mobile-buttons-bar, #mobile-pause-hint, #mobile-mute-btn {
    display: none !important;
}

/* Pause actions button row */
.pause-actions {
    display: flex;
    gap: 15px;
    margin-top: 20px;
    width: 100%;
    max-width: 320px;
    flex-shrink: 0;
}

.pause-actions button {
    flex: 1;
    font-size: 0.85rem;
    padding: 12px 10px;
}

#pause-restart-button {
    background: transparent;
    border: 2px solid var(--neon-pink);
    color: var(--neon-pink);
    box-shadow: 0 0 10px rgba(255, 0, 127, 0.1);
}

#pause-restart-button:hover {
    background: var(--neon-pink);
    color: #ffffff;
    box-shadow: 0 0 15px var(--neon-pink);
}

/* Responsive visibility utilities */
.mobile-only {
    display: none !important;
}
.desktop-only {
    display: block;
}

.pause-rules p {
    margin-bottom: 1.5vh;
}

/* Responsive Scaling for Mobile Screens */
@media (max-width: 1024px), (pointer: coarse) {
    /* Hide desktop elements */
    #game-header, #controls-panel {
        display: none !important;
    }
    
    body {
        align-items: stretch;
        justify-content: stretch;
        overflow: hidden;
    }

    #app-container {
        width: 100vw;
        height: 100dvh;
        max-width: 100vw;
        padding: 0;
        gap: 0;
    }

    #main-layout {
        grid-template-columns: 1fr;
        height: 100dvh;
        min-height: unset;
        gap: 0;
    }

    #canvas-container {
        height: calc(100dvh - 155px - calc(var(--btn-w-port) * 1.7692));
        width: 100vw;
        margin-top: 155px;
        padding: 0;
        border: none;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        position: relative;
        overflow: visible;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    #game-canvas {
        width: 100vw;
        height: 100%;
        touch-action: none;
    }

    /* Mobile HUD */
    #mobile-hud:not(.hidden) {
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
        position: absolute;
        top: -140px;
        left: 15px;
        width: calc(50% - 20px);
        height: 140px;
        padding: 16px 20px;
        z-index: 80;
        border-radius: 12px;
        border: 1px solid rgba(0, 240, 255, 0.25);
        box-shadow: inset 0 0 10px rgba(0, 240, 255, 0.05), 0 4px 20px rgba(0, 0, 0, 0.5);
        background: rgba(10, 11, 16, 0.85);
        gap: 12px;
        pointer-events: none; /* Disable interaction since pause button exists */
    }

    /* Mobile floating utility labels (pause hint + mute) — fixed bottom corners */
    #mobile-pause-hint.mobile-float-label:not(.hidden),
    #mobile-mute-btn.mobile-float-label:not(.hidden) {
        display: block !important;
        position: fixed;
        bottom: 8px;
        z-index: 200;
        font-family: 'Orbitron', sans-serif;
        font-size: 1.3rem;
        color: rgba(255, 255, 255, 0.4);
        pointer-events: auto;
        background: none;
        border: none;
        padding: 6px;
        cursor: pointer;
        opacity: 0.25; /* Pale/transparent buttons by default */
        transition: opacity 0.2s ease, transform 0.1s ease;
    }

    #mobile-pause-hint.mobile-float-label:not(.hidden):active,
    #mobile-mute-btn.mobile-float-label:not(.hidden):active {
        transform: scale(0.9);
        color: var(--neon-cyan);
        opacity: 0.8;
    }

    #mobile-pause-hint:not(.hidden) {
        left: 6px; /* Moved closer to the edge */
    }

    #mobile-mute-btn.mobile-float-label:not(.hidden) {
        right: 6px; /* Moved closer to the edge */
        left: auto;
    }

    .mobile-stat-row {
        display: flex;
        justify-content: space-between;
        width: 100%;
        align-items: center;
        font-family: 'Orbitron', sans-serif;
    }

    .mob-label {
        font-size: 0.95rem;
        color: #94a3b8;
        font-weight: 700;
        letter-spacing: 1px;
    }

    .mobile-stat-row span:not(.mob-label) {
        font-size: 1.4rem;
        font-weight: 900;
        color: var(--neon-cyan);
        text-shadow: 0 0 8px var(--neon-cyan);
    }

    /* Mobile Next Preview Repositioned */
    #mobile-next-preview:not(.hidden) {
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 6px;
        position: absolute;
        top: -140px;
        right: 15px;
        width: calc(50% - 20px);
        height: 140px;
        padding: 10px;
        z-index: 80;
        border-radius: 12px;
        border: 1px solid rgba(0, 240, 255, 0.25);
        box-shadow: inset 0 0 10px rgba(0, 240, 255, 0.05), 0 4px 20px rgba(0, 0, 0, 0.5);
        background: rgba(10, 11, 16, 0.85);
    }

    .mobile-next-canvas-wrapper {
        width: 90px;
        height: 90px;
        background: rgba(10, 11, 16, 0.5);
        border: 1px solid rgba(0, 240, 255, 0.15);
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #mobile-next-canvas {
        width: 86px;
        height: 86px;
    }

    /* Mobile Button Bar - Honeycomb Interlocking 2 Rows styling */
    #mobile-buttons-bar:not(.hidden) {
        display: block !important;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        height: calc(var(--btn-w-port) * 1.7692);
        z-index: 80;
        overflow: hidden;
        background: linear-gradient(to top, rgba(10, 11, 16, 0.95) 0%, rgba(10, 11, 16, 0.75) 50%, rgba(10, 11, 16, 0.0) 100%);
    }

    .mobile-btn {
        position: absolute;
        border: none;
        background: transparent;
        color: var(--btn-neon, var(--neon-cyan));
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        outline: none;
        transition: transform 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.1s ease;
        font-family: 'Orbitron', sans-serif;
        font-size: 2.2rem;
        font-weight: 900;
        padding: 0;
        z-index: 1;
        
        /* Neon filter drop shadow */
        filter: drop-shadow(0 0 5px rgba(0, 240, 255, 0.3));
    }

    /* Row 1 Positioning: Left, CW, Right (Same aspect ratio and width as Row 2 for perfect parallel nesting) */
    #mobile-btn-left {
        width: var(--btn-w-port);
        height: calc(var(--btn-w-port) * 1.1547);
        bottom: calc(var(--btn-w-port) * 0.6144);
        left: calc(50vw - (1.78 * var(--btn-w-port)));
        z-index: 10;
    }

    #mobile-btn-rotate {
        width: var(--btn-w-port);
        height: calc(var(--btn-w-port) * 1.1547);
        bottom: calc(var(--btn-w-port) * 0.6144);
        left: calc(50vw - (0.5 * var(--btn-w-port)));
        z-index: 10;
    }

    #mobile-btn-right {
        width: var(--btn-w-port);
        height: calc(var(--btn-w-port) * 1.1547);
        bottom: calc(var(--btn-w-port) * 0.6144);
        left: calc(50vw + (0.78 * var(--btn-w-port)));
        z-index: 10;
    }

    /* Row 2 Positioning (perfect offset downward/horizontally to interlock parallel borders): CCW, Down */
    #mobile-btn-rotccw {
        width: var(--btn-w-port);
        height: calc(var(--btn-w-port) * 1.1547);
        bottom: calc(var(--btn-w-port) * -0.24);
        left: calc(50vw - (1.14 * var(--btn-w-port)));
        z-index: 5;
    }

    #mobile-btn-down {
        width: var(--btn-w-port);
        height: calc(var(--btn-w-port) * 1.1547);
        bottom: calc(var(--btn-w-port) * -0.24);
        left: calc(50vw + (0.14 * var(--btn-w-port)));
        z-index: 5;
    }

    /* Hexagonal border using pseudo-elements (All pointy-topped vertical hexagons) */
    .mobile-btn::before {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        background: var(--btn-neon, var(--neon-cyan));
        clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
        z-index: -2;
        transition: background 0.1s ease;
    }

    .mobile-btn::after {
        content: '';
        position: absolute;
        top: 3px; left: 3px; right: 3px; bottom: 3px;
        background: rgba(10, 11, 16, 0.9);
        clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
        z-index: -1;
        transition: background 0.1s ease;
    }

    /* Dominant CW Rotate center button styling */
    .mobile-btn.circular {
        --btn-neon: var(--neon-purple);
        font-size: 2.6rem;
        z-index: 85;
        filter: drop-shadow(0 0 6px rgba(176, 38, 255, 0.4));
    }

    /* Small buttons (Rotate CCW, Soft Drop) */
    .mobile-btn.small {
        font-size: 1.6rem;
    }

    #mobile-btn-rotccw {
        --btn-neon: var(--neon-yellow);
        filter: drop-shadow(0 0 4px rgba(255, 251, 0, 0.3));
    }

    #mobile-btn-down {
        --btn-neon: var(--neon-pink);
        filter: drop-shadow(0 0 4px rgba(255, 0, 127, 0.3));
    }

    /* Active click states and JS zone press mirrors */
    .mobile-btn:active, .mobile-btn.active-press {
        transform: scale(0.94);
        filter: drop-shadow(0 0 10px var(--btn-neon));
    }

    .mobile-btn:active::after, .mobile-btn.active-press::after {
        background: rgba(255, 255, 255, 0.12);
    }

    .mobile-only {
        display: block !important;
    }
    .desktop-only {
        display: none !important;
    }

    /* Style touch controls list inside pause menu */
    .touch-controls-list {
        list-style: none;
        margin-top: 1.5vh;
        padding: 0;
        text-align: left;
        display: inline-block;
        max-width: 320px;
    }

    .touch-controls-list li {
        margin-bottom: 1vh;
        font-size: clamp(0.7rem, 1.6vh, 0.85rem);
        position: relative;
        padding-left: 20px;
        color: #a0a5c0;
        line-height: 1.4;
    }

    .touch-controls-list li::before {
        content: '▪';
        position: absolute;
        left: 0;
        top: 0;
        color: var(--neon-cyan);
        text-shadow: 0 0 5px var(--neon-cyan);
        font-size: 1rem;
    }

    /* Mobile/Touch Pause Overlay positioning and style */
    #pause-overlay {
        position: absolute;
        top: -155px; /* Offset the margin-top of #canvas-container to align with the viewport top */
        left: 0;
        width: 100vw;
        height: 100dvh;
        z-index: 150;
        background: #0a0b10;
        overflow: hidden; /* Disable scrolling on overlay background */
        padding: 30px 20px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        box-sizing: border-box;
    }
}

/* Responsive Overrides for Touch Landscape Screens (Mobile/Tablet landscape) */
@media (max-width: 1024px) and (orientation: landscape), (pointer: coarse) and (orientation: landscape) {
    #canvas-container {
        height: 100dvh !important;
        margin-top: 0 !important;
    }

    #game-canvas {
        height: 100% !important;
    }

    .mobile-btn {
        font-size: calc(var(--btn-w-land) * 0.36) !important;
    }

    /* Top Panels layout: floating on the sides */
    #mobile-hud:not(.hidden) {
        top: 15px !important;
        left: 15px !important;
        right: auto !important;
        width: 160px !important;
        height: 120px !important;
        padding: 12px 15px !important;
        gap: 6px !important;
    }

    /* Landscape floating labels — same fixed bottom corners */
    #mobile-pause-hint:not(.hidden) {
        bottom: 8px !important;
        left: 6px !important;
    }

    #mobile-mute-btn.mobile-float-label:not(.hidden) {
        bottom: 8px !important;
        right: 6px !important;
        left: auto !important;
    }

    .mobile-stat-row span:not(.mob-label) {
        font-size: 1.1rem !important;
    }

    #mobile-next-preview:not(.hidden) {
        top: 15px !important;
        right: 15px !important;
        left: auto !important;
        width: 120px !important;
        height: 120px !important;
    }

    .mobile-next-canvas-wrapper {
        width: 70px !important;
        height: 70px !important;
    }

    #mobile-next-canvas {
        width: 66px !important;
        height: 66px !important;
    }

    /* Bottom Button Bar override */
    #mobile-buttons-bar:not(.hidden) {
        top: auto !important;
        bottom: 0 !important;
        height: calc(var(--btn-w-land) * 1.923) !important;
        background: transparent !important;
        overflow: visible !important;
    }

    /* Honeycomb Split controller positioning using capped landscape button width var */
    #mobile-btn-left {
        width: var(--btn-w-land) !important;
        height: calc(var(--btn-w-land) * 1.1547) !important;
        bottom: calc(var(--btn-w-land) * 0.641) !important;
        left: calc(var(--btn-w-land) * 0.25) !important;
        right: auto !important;
        top: auto !important;
        z-index: 10 !important;
    }

    #mobile-btn-rotate {
        width: var(--btn-w-land) !important;
        height: calc(var(--btn-w-land) * 1.1547) !important;
        bottom: calc(var(--btn-w-land) * 0.641) !important;
        right: calc(var(--btn-w-land) * 1.66) !important;
        left: auto !important;
        top: auto !important;
        z-index: 10 !important;
    }

    #mobile-btn-right {
        width: var(--btn-w-land) !important;
        height: calc(var(--btn-w-land) * 1.1547) !important;
        bottom: calc(var(--btn-w-land) * 0.641) !important;
        right: calc(var(--btn-w-land) * 0.25) !important;
        left: auto !important;
        top: auto !important;
        z-index: 10 !important;
    }

    #mobile-btn-rotccw {
        width: var(--btn-w-land) !important;
        height: calc(var(--btn-w-land) * 1.1547) !important;
        bottom: calc(var(--btn-w-land) * -0.15) !important;
        left: calc(var(--btn-w-land) * 0.96) !important;
        right: auto !important;
        top: auto !important;
        z-index: 5 !important;
    }

    #mobile-btn-down {
        width: var(--btn-w-land) !important;
        height: calc(var(--btn-w-land) * 1.1547) !important;
        bottom: calc(var(--btn-w-land) * -0.15) !important;
        right: calc(var(--btn-w-land) * 0.96) !important;
        left: auto !important;
        top: auto !important;
        z-index: 5 !important;
    }

    /* Border inset override for smaller buttons in landscape */
    .mobile-btn::after {
        top: 2px !important;
        left: 2px !important;
        right: 2px !important;
        bottom: 2px !important;
    }

    /* Landscape adjustments for Pause Overlay to fit vertically */
    #pause-overlay {
        padding: 20px 24px !important;
    }

    #pause-overlay .pause-title {
        margin-bottom: 1.5vh !important;
    }

    #pause-overlay .pause-description {
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        align-items: flex-start !important;
        gap: 30px !important;
        max-width: 800px !important;
        margin-bottom: 2vh !important;
        text-align: left !important;
    }

    #pause-overlay .pause-rules, 
    #pause-overlay .pause-mobile-notes {
        flex: 1 !important;
        margin-bottom: 0 !important;
    }

    #pause-overlay .pause-actions {
        margin-top: 10px !important;
    }
}

.v1-history-link {
    position: absolute;
    bottom: 12px;
    right: 12px;
    font-size: 11px;
    color: #555566;
    font-family: 'Outfit', sans-serif;
    text-align: right;
    line-height: 1.4;
}

.v1-history-link a {
    color: #555566;
    text-decoration: none;
    transition: color 0.2s ease;
}

.v1-history-link a:hover {
    color: #888899;
    text-decoration: underline;
}

.v1-history-link strong {
    color: #777788;
}
