/* ... (previous styles remain) ... */

:root {
    --bg-color: #0a0a0a;
    --text-color: #e0e0e0;
    --accent-color: #ff0055;
    --secondary-color: #00f3ff;
    --panel-bg: #151515;
    --gradient-primary: linear-gradient(135deg, #bc13fe 0%, #ff0055 100%);
}

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

html,
body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0a0a0a;
}

::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 4px;
    border: 1px solid #444;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

/* New Game Styles */
.game-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    justify-content: center;
    z-index: 10;
    padding-top: 60px;
}

/* Hide original game controls container */
.game-controls {
    display: none;
}

/* Timer Fixed Top Left - Higher Z-Index */
.timer-display {
    position: fixed;
    top: 20px;
    left: 20px;
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    color: var(--secondary-color);
    text-shadow: 2px 2px 4px #000;
    z-index: 2100;
    /* Ensure strictly above fullscreen overlay (2000) */
}

/* Volume Control Fixed Bottom Left - Higher Z-Index */
.volume-container-fixed {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 2100;
    /* Ensure strictly above fullscreen overlay (2000) */
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-btn-small {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--secondary-color);
    color: var(--secondary-color);
    padding: 8px;
    border-radius: 50%;
    /* Rounded */
    cursor: pointer;
    font-family: 'Orbitron', sans-serif;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.control-btn-small:hover {
    background: var(--secondary-color);
    color: #000;
    box-shadow: 0 0 15px var(--secondary-color);
}

.control-btn-small.paused {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.volume-control-fixed {
    background: rgba(0, 0, 0, 0.7);
    padding: 10px;
    border-radius: 15px;
    border: 1px solid #333;
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: #fff;
    backdrop-filter: blur(5px);
}

.volume-control-fixed label {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
}

/* Cards Container */
.cards-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4rem;
    perspective: 2000px;
    width: 100%;
    height: 80%;
    max-width: 100vw;
}

.card-wrapper {
    /* Responsive width/height */
    width: 35vw;
    max-width: 540px;
    aspect-ratio: 540 / 765;
    height: auto;
    position: relative;
    max-height: 75vh;
}

.card {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    cursor: pointer;
    border-radius: 20px;
    /* More rounded */
    box-shadow: 0 0 25px rgba(0, 0, 0, 0.7);
}

.card[data-state="revealed"] {
    transform: rotateY(180deg);
}

.card-front,
.card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    border: 3px solid #444;
    overflow: hidden;
}

.card-front {
    background: linear-gradient(135deg, #111, #222);
    font-size: 8rem;
    color: #444;
    font-family: 'Orbitron', sans-serif;
    text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.card-back {
    background: #000;
    transform: rotateY(180deg);
}

.card-back img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Autoplay Button Styling */
.autoplay-container {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
}

.game-btn {
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid var(--accent-color);
    color: var(--text-color);
    padding: 12px 30px;
    font-size: 1.2rem;
    font-family: 'Orbitron', sans-serif;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    border-radius: 50px;
    font-weight: bold;
}

.game-btn:hover,
.game-btn.active {
    background: var(--gradient-primary);
    border-color: transparent;
    box-shadow: 0 0 20px var(--accent-color);
}

.game-btn.small {
    padding: 6px 15px;
    font-size: 0.9rem;
    margin-top: 10px;
}

/* Fullscreen Overlay */
#fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}

#fullscreen-overlay.active {
    display: flex;
    opacity: 1;
}

#fullscreen-img {
    width: 95vw;
    height: 95vh;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.6s ease-in-out;
}

#fullscreen-overlay.active #fullscreen-img {
    opacity: 1;
}

/* Header Fade Out Animation */
body.game-active header {
    transition: transform 0.8s ease, opacity 0.8s ease;
    transform: translateY(-100%);
    opacity: 0;
    pointer-events: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
}

/* Nav Move Up Animation */
.game-nav {
    transition: transform 0.8s ease, opacity 0.3s ease;
    z-index: 2100;
    position: relative;
}

/* When game active, move nav up */
body.game-active .game-nav {
    transform: translateY(-140px);
    padding-top: 10px;
    position: fixed;
    top: 140px;
    left: 0;
    width: 100%;
    background: transparent;
    display: flex;
    justify-content: center;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 3000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--secondary-color);
    font-family: 'Orbitron', sans-serif;
}

.loader {
    border: 5px solid #333;
    border-top: 5px solid var(--secondary-color);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Builder Game Layout */
.builder-layout {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 20px;
    padding: 20px;
    padding-top: 140px;
    /* Add padding to clear fixed nav in game mode */
    box-sizing: border-box;
    position: relative;
    /* For absolute sidebar */
    /* Removed justify-content and align-items to let manual positioning work */
    /* animation: fadeIn 1s ease-in-out; REMOVED to prevent containing block issue for fixed sidebar */
}

.builder-sidebar {
    width: 250px;
    background: rgba(0, 0, 0, 0.8);
    border-right: 1px solid var(--accent-color);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    height: 70vh;
    /* Reduced height slightly */
    max-height: 70vh;
    border-radius: 10px;
    flex-shrink: 0;
    z-index: 10;
    /* Fixed position to not interfere with flex layout */
    position: fixed;
    left: 0;
    /* Docked to left edge */
    top: 50%;
    transform: translateY(-50%);
    border-radius: 0 10px 10px 0;
    /* Rounded only on right */
    animation: fadeInSidebar 1s ease-in-out;
    /* Animate sidebar with specific keyframe */
}

.builder-sidebar h3 {
    color: var(--secondary-color);
    margin-bottom: 10px;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
}

#builder-list {
    list-style: none;
    padding: 0;
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.9rem;
    color: #ddd;
}

#builder-list li {
    padding: 5px 0;
    border-bottom: 1px solid #333;
}

#builder-list li .item-number {
    color: var(--accent-color);
    margin-right: 5px;
    font-weight: bold;
}

.builder-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    animation: fadeIn 1s ease-in-out;
    /* Animate main area separately */
}

.hidden {
    display: none !important;
}

/* Builder Grid (2x2) */
.builder-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    width: 80vh;
    /* Restored to large size */
    height: 80vh;
    aspect-ratio: 1;
    /* Removed transform: scale to fix layout flow */
    margin: auto;
    /* Center in flex container */
}

.builder-card {
    perspective: 1000px;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.builder-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    border-radius: 15px;
}

.builder-card.revealed .builder-card-inner {
    transform: rotateY(180deg);
}

.builder-card-front,
.builder-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 15px;
    border: 2px solid var(--accent-color);
    background: #111;
    overflow: hidden;
}

.builder-card-front {
    font-size: 4rem;
    color: var(--secondary-color);
    background: linear-gradient(135deg, #1a1a1a, #000);
}

.builder-card-back {
    transform: rotateY(180deg);
    background: #000;
}

.builder-card-img {
    width: 100%;
    height: 100%;
    /* Full Square */
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

.builder-card-text {
    position: absolute;
    bottom: 10%;
    left: 5%;
    width: 90%;
    padding: 8px;
    /* Reduced padding */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
    /* Reduced by ~15% from 2rem */
    font-weight: bold;
    color: #fff;
    text-align: center;
    z-index: 2;
    background: rgba(0, 0, 0, 0.35);
    /* 20% opacity black background */
    text-shadow: 2px 2px 4px #000;
    border-radius: 10px;
    pointer-events: none;
    transform: scale(0.85);
    /* Reduce overall size by 15% */
}

/* Start View Container */
.start-view-container {
    width: 100%;
    height: 60vh;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -50px;
}

/* Start Screen Overlay (Legacy - Removed/Unused now) */
.start-screen-overlay {
    display: none;
}

.large-btn {
    font-size: 2rem;
    padding: 20px 60px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 0, 85, 0.7);
    }

    70% {
        transform: scale(1.05);
        box-shadow: 0 0 0 20px rgba(255, 0, 85, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 0, 85, 0);
    }
}

/* Builder Controls */
.builder-controls {
    position: absolute;
    inset: 0;
    /* Cover the entire builder-main area */
    z-index: 2000;
    /* Above cards */
    display: flex;
    align-items: center;
    /* Center vertically */
    justify-content: center;
    /* Center horizontally */
    pointer-events: none;
    /* Let clicks pass through wrapper */
}

/* Animation for when controls appear */
.builder-controls:not(.hidden) {
    animation: fadeIn 0.5s ease-out forwards;
}

.builder-controls button {
    pointer-events: auto;
    /* Re-enable clicks on button */
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    /* Strong shadow to pop over cards */
}

.fade-btn {
    animation: fadeInOut 2s infinite ease-in-out;
    transform-origin: center;
    font-size: 1.5rem;
    /* Increase base size */
    padding: 15px 40px;
}

@keyframes fadeInOut {
    0% {
        opacity: 0.5;
        transform: scale(1.8);
    }

    50% {
        opacity: 1;
        transform: scale(1.9);
    }

    /* Reach 100% opacity */
    100% {
        opacity: 0.5;
        transform: scale(1.8);
    }
}

/* Disable scroll when game is active */
/* Disable scroll when game is active */
body.game-active {
    overflow: hidden;
    height: 100vh;
    /* Removed position: fixed and width: 100vw to fix centering issues */
}

@keyframes fadeInSidebar {
    from {
        opacity: 0;
        transform: translateY(-50%);
    }

    to {
        opacity: 1;
        transform: translateY(-50%);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Game Play Area */
#builder-timer-display {
    font-family: 'Orbitron', sans-serif;
    font-size: 5rem;
    color: var(--secondary-color);
    text-shadow: 0 0 20px var(--accent-color);
    margin-bottom: 40px;
}

#next-actions-container {
    background: rgba(0, 0, 0, 0.8);
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 600px;
}

.next-action {
    font-size: 1.2rem;
    color: #aaa;
    margin: 10px 0;
    padding: 10px;
    border-left: 3px solid #444;
    background: rgba(255, 255, 255, 0.05);
}

/* Overlays */
#countdown-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

#command-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50vh;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.71) 0%, rgba(0, 0, 0, 0.53) 70%, transparent 100%);
    padding-top: 8vh;
    /* Lower the text position */
}

#countdown-overlay.active,
#command-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

#countdown-overlay.active {
    background: rgba(0, 0, 0, 0.9);
}

#countdown-number {
    font-size: 15rem;
    color: var(--secondary-color);
    font-family: 'Orbitron', sans-serif;
}

#command-text {
    font-size: 4rem;
    color: var(--accent-color);
    font-family: 'Orbitron', sans-serif;
    text-align: center;
    padding: 20px;
}

#game-image-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2500;
    /* Below command overlay */
    background: black;
    display: none;
    /* Hidden by default */
}

#game-image-overlay.active {
    display: block;
}

.image-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    flex-wrap: wrap;
}

#game-display-image,
.split-img,
.split4-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    position: absolute;
    top: 0;
    left: 0;
}

/* Hide split images initially to prevent alt text from showing */
#game-display-image-2,
#game-display-image-3,
#game-display-image-4 {
    display: none;
}

/* Split Screen Modes */
#game-image-overlay.split-mode #game-display-image {
    width: 50%;
    height: 100%;
    left: 0;
    object-fit: cover;
}

#game-image-overlay.split-mode #game-display-image-2 {
    width: 50%;
    height: 100%;
    left: 50%;
    display: block !important;
    object-fit: cover;
}

#game-image-overlay.split4-mode #game-display-image {
    width: 50%;
    height: 50%;
    top: 0;
    left: 0;
    object-fit: cover;
    object-position: center center;
}

#game-image-overlay.split4-mode #game-display-image-2 {
    width: 50%;
    height: 50%;
    top: 0;
    left: 50%;
    display: block !important;
    object-fit: cover;
    object-position: center center;
}

#game-image-overlay.split4-mode #game-display-image-3 {
    width: 50%;
    height: 50%;
    top: 50%;
    left: 0;
    display: block !important;
    object-fit: cover;
    object-position: center center;
}

#game-image-overlay.split4-mode #game-display-image-4 {
    width: 50%;
    height: 50%;
    top: 50%;
    left: 50%;
    display: block !important;
    object-fit: cover;
    object-position: center center;
}

/* Mobile Media Queries for Game */
@media (max-width: 768px) {
    .cards-container {
        gap: 1rem;
        flex-direction: column;
        height: auto;
        margin-top: 60px;
        padding-bottom: 100px;
        /* Space for controls */
        overflow-y: auto;
    }

    .card-wrapper {
        width: 80vw;
        max-width: 300px;
    }

    .timer-display {
        font-size: 1.5rem;
        top: 10px;
        left: 10px;
    }

    .volume-container-fixed {
        bottom: 10px;
        left: 10px;
        transform: scale(0.8);
        transform-origin: bottom left;
    }

    .autoplay-container {
        bottom: 20px;
    }

    .game-layout {
        height: auto;
        min-height: 100vh;
        padding-top: 40px;
        position: relative;
        display: block;
        /* Scrollable */
    }

    /* Adjust fullscreen image for mobile */
    #fullscreen-img {
        width: 100vw;
        height: auto;
        max-height: 90vh;
    }

    /* Builder Mobile */
    .builder-layout {
        flex-direction: column;
        padding-top: 80px;
    }

    .builder-sidebar {
        width: 100%;
        height: 200px;
        order: 2;
    }

    .builder-grid {
        width: 95%;
        gap: 10px;
    }

    /* Make card captions 40% smaller on mobile, then 20% bigger */
    .builder-card-text {
        font-size: 1.224rem !important;
        /* 1.02rem * 1.2 = 1.224rem */
        padding: 5.76px !important;
        /* 4.8px * 1.2 = 5.76px */
        width: 90% !important;
        transform: scale(0.612) !important;
        /* 0.51 * 1.2 = 0.612 */
        border-radius: 7.2px !important;
        /* 6px * 1.2 = 7.2px */
        bottom: 5% !important;
        /* Move down from 10% to 5% */
    }
}

/* ===== GAME UI REDESIGN ===== */

/* Hide sidebar during actual gameplay (not during building phase) */
body.game-active .builder-sidebar {
    display: none;
}

/* But show it during building phase */
#builder-selection-area:not(.hidden)~.builder-sidebar,
.builder-layout:has(#builder-selection-area:not(.hidden)) .builder-sidebar {
    display: flex !important;
}

/* Timer - top left, always visible */
body.game-active #builder-timer-display {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 3000;
    font-size: 3rem;
    margin-bottom: 0;
}

/* Next Actions - under timer, always visible */
body.game-active #next-actions-container {
    position: fixed;
    top: 100px;
    left: 20px;
    z-index: 3000;
    background: rgba(0, 0, 0, 0.9);
    padding: 15px;
    border-radius: 10px;
    max-width: 300px;
    border: 1px solid var(--secondary-color);
}

body.game-active #next-actions-container h4 {
    color: var(--secondary-color);
    font-family: 'Orbitron', sans-serif;
    margin-bottom: 10px;
    font-size: 1rem;
}

/* Images - 90% of screen normally, 100% for split modes */
#game-image-overlay.active {
    position: fixed;
    top: 5vh;
    left: 5vw;
    width: 90vw;
    height: 90vh;
    z-index: 2500;
    background: black;
}

/* Split modes use 100% of screen */
#game-image-overlay.split-mode,
#game-image-overlay.split4-mode {
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
}

#game-image-overlay .image-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-display-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Command overlay - bottom half only */
#command-overlay.active {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 50vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.7) 70%, transparent 100%);
    z-index: 2800;
    opacity: 1;
    pointer-events: auto;
}

#command-text {
    font-size: 3.5rem;
    color: var(--accent-color);
    text-align: center;
    padding: 20px;
    font-family: 'Orbitron', sans-serif;
    text-shadow: 0 0 20px var(--accent-color);
}

/* Test controls - bottom left */
.test-controls {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 3000;
    background: rgba(0, 0, 0, 0.95);
    padding: 12px;
    border-radius: 10px;
    display: none;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--secondary-color);
}

body.game-active .test-controls {
    display: flex;
}

.speed-test-buttons,
.image-test-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.speed-test-btn,
.image-test-btn {
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--secondary-color);
    color: var(--text-color);
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.75rem;
    font-family: 'Orbitron', sans-serif;
    transition: all 0.3s;
    white-space: nowrap;
}

.speed-test-btn:hover,
.image-test-btn:hover {
    background: var(--secondary-color);
    color: #000;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px var(--secondary-color);
}

.speed-test-btn:active,
.image-test-btn:active {
    transform: translateY(0);
}

/* Volume Control - Bottom Left */
.volume-control-container {
    position: fixed;
    bottom: 30px;
    left: 30px;
    z-index: 3000;
    display: none;
    /* Hidden by default, shown when game active */
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.7);
    padding: 12px 18px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(5px);
    transition: opacity 0.3s;
    transform: scale(1.2);
    /* Overall scale up */
    transform-origin: bottom left;
}

body.game-active .volume-control-container {
    display: flex;
}

.volume-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.volume-btn:hover {
    transform: scale(1.1);
}

#volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 140px;
    height: 6px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    /* Make entire slider clickable */
}

#volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--secondary-color);
    cursor: pointer;
    transition: transform 0.2s;
}

#volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

/* Mobile-specific volume slider enhancements */
@media (max-width: 768px) {
    #volume-slider {
        height: 12px;
        /* Taller track for easier touch */
        padding: 8px 0;
        /* Increase touch area */
        margin: -8px 0;
        /* Compensate for padding */
    }

    #volume-slider::-webkit-slider-thumb {
        width: 24px;
        /* Larger thumb for mobile */
        height: 24px;
    }

    #volume-slider::-moz-range-thumb {
        width: 24px;
        height: 24px;
        border-radius: 50%;
        background: var(--secondary-color);
        cursor: pointer;
        border: none;
    }
}

/* START GAME button - 2x bigger than NEXT ROUND */
.finalize-btn {
    font-size: 3rem !important;
    padding: 30px 60px !important;
    margin-top: 30px;
    transform: scale(1);
}

.finalize-btn:hover {
    transform: scale(1.05);
}

/* Tutorial Button */
.tutorial-btn {
    margin-top: 20px;
    padding: 10px 24px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: 'Orbitron', sans-serif;
    transition: all 0.3s;
    text-transform: none;
}

.tutorial-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border-color: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 245, 212, 0.2);
}

/* Tutorial Modal */
.tutorial-modal-content {
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 30px;
}

.tutorial-content h3 {
    color: var(--secondary-color);
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

.tutorial-content h4 {
    color: var(--text-color);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

.tutorial-content p {
    line-height: 1.6;
    margin-bottom: 15px;
    color: rgba(255, 255, 255, 0.9);
}

.tutorial-content ul {
    margin: 10px 0 20px 0;
    padding-left: 25px;
}

.tutorial-content li {
    margin-bottom: 8px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.85);
}

.tutorial-content strong {
    color: var(--secondary-color);
}

.tutorial-content em {
    color: var(--secondary-color);
    font-style: italic;
}

/* Large START GAME button when all cards selected */
.builder-controls.final-button #builder-start-game-btn,
.builder-controls.final-button #builder-next-btn {
    transform: scale(2);
    margin-top: 60px;
    /* Extra space due to larger size */
    margin-bottom: 60px;
}

/* =========================================
   MOBILE OPTIMIZATION (PHONE USAGE)
   ========================================= */

@media (max-width: 768px) {

    /* 1. Test Your Luck - Shrink Tabs & Move to Top */
    body.game-active .game-nav {
        transform: translateY(-140px) scale(0.5);
        transform-origin: top center;
        top: 10px;
        /* Move to very top */
        width: 100%;
        padding-top: 0;
        position: fixed;
        z-index: 4000;
        /* Highest priority */
    }

    /* 2. Your Orders Modal - Retractable Sidebar (Fixed Left) */
    .builder-sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 160px !important;
        /* Below the top nav */
        width: 240px !important;
        height: auto !important;
        max-height: 60vh;
        z-index: 3500;
        border-radius: 0 10px 10px 0;
        transition: transform 0.3s ease-in-out;
        transform: translateX(0);
        order: unset;
        /* Remove order: 2 */
        display: flex !important;
        flex-direction: column;
        background: rgba(0, 0, 0, 0.9);
        border-left: none;
    }

    .builder-sidebar.retracted {
        transform: translateX(calc(-100% + 40px));
        /* Leave 40px visible */
        height: auto !important;
        overflow: visible;
        /* Allow button to be seen */
        padding: 10px 0;
        /* Remove side padding to fit button */
    }

    .builder-sidebar.retracted h3,
    .builder-sidebar.retracted ul,
    .builder-sidebar.retracted .game-btn,
    .builder-sidebar.retracted #builder-count {
        opacity: 0;
        /* Hide content but keep layout or just hide */
        display: none !important;
    }

    #sidebar-toggle-btn {
        display: block !important;
        position: absolute;
        right: 0;
        top: 0;
        width: 35px;
        /* Width of the visible handle - made shorter */
        height: 100%;
        min-height: 80px;
        /* Make it taller */
        background: var(--accent-color);
        border: none;
        color: white;
        font-family: 'Orbitron', sans-serif;
        cursor: pointer;
        writing-mode: vertical-rl;
        /* Vertical text */
        text-orientation: mixed;
        padding: 10px 0;
        border-radius: 0 10px 10px 0;
        z-index: 3600;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0;
        font-size: 1.2rem;
    }

    /* Hide sidebar and toggle button when game is active */
    body.game-active .builder-sidebar {
        display: none !important;
    }

    /* 3. Up Next Modal - 2x Smaller */
    body.game-active #next-actions-container {
        transform: scale(0.5);
        transform-origin: top left;
        top: 60px;
        /* Adjust position since it's smaller */
        left: 10px;
        width: auto;
        max-width: 80vw;
    }

    /* Hide Up Next modal during split modes on mobile */
    body.split-image-mode #next-actions-container {
        display: none !important;
    }

    /* 4. Volume Modal - 2x Smaller */
    .volume-control-container {
        transform: scale(0.6);
        /* 1.2 -> 0.6 is 2x smaller */
        transform-origin: bottom left;
        bottom: 10px;
        left: 10px;
    }

    /* 5. Timer and Command Text - 2x Smaller */
    body.game-active #builder-timer-display {
        font-size: 1.5rem;
        /* 3rem -> 1.5rem */
        top: 10px;
        left: 10px;
    }

    #command-text {
        font-size: 1.75rem;
        /* 3.5rem -> 1.75rem */
    }

    /* 6. Display Images Fullscreen & Allow Scroll */
    #game-image-overlay.active {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 2500;
        background: black;
        overflow-y: auto;
        /* Allow scrolling */
        display: block;
        /* Change from flex to block for scrolling */
    }

    #game-image-overlay .image-container {
        display: block;
        /* Allow natural flow for scrolling */
        width: 100%;
        min-height: 100%;
        /* Ensure it fills at least the screen */
        height: auto;
        /* Allow it to grow */
        position: relative;
    }

    #game-display-image {
        width: 100%;
        height: auto;
        /* Maintain aspect ratio */
        min-height: 100vh;
        /* Ensure it covers screen */
        object-fit: contain;
        /* Show full image */
        position: relative;
        /* Reset absolute positioning */
    }

    /* Ensure body scrolls if needed (though overlay handles it) */
    body.game-active {
        overflow-y: auto !important;
        /* Allow vertical scroll on mobile */
        height: auto !important;
        /* Allow height to grow */
        position: relative !important;
    }

    .builder-layout {
        height: auto !important;
        padding-bottom: 100px;
        /* Add space at bottom for scrolling */
    }
}

/* Toggle Button Style (Default Hidden) */
#sidebar-toggle-btn {
    display: none;
}

/* =========================================
   LANDSCAPE MODE OPTIMIZATION (PHONE)
   ========================================= */

@media (max-width: 768px) and (orientation: landscape) {

    /* Make images fill the full viewport height in landscape */
    #game-image-overlay.active {
        overflow-y: auto;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    .image-container {
        height: 100vh !important;
        min-height: 100vh !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #game-display-image {
        width: auto !important;
        height: 100vh !important;
        min-height: 100vh !important;
        max-height: 100vh !important;
        object-fit: contain !important;
        position: relative;
    }

    /* For split mode images */
    #game-image-overlay.split-mode .image-container {
        display: block !important;
        /* Override flexbox for split mode */
    }

    #game-image-overlay.split-mode #game-display-image,
    #game-image-overlay.split-mode #game-display-image-2 {
        height: 100vh !important;
        object-fit: cover !important;
    }

    /* For split4 mode images */
    #game-image-overlay.split4-mode .image-container {
        display: block !important;
        /* Override flexbox for split4 mode */
    }

    #game-image-overlay.split4-mode #game-display-image,
    #game-image-overlay.split4-mode #game-display-image-2,
    #game-image-overlay.split4-mode #game-display-image-3,
    #game-image-overlay.split4-mode #game-display-image-4 {
        width: 50% !important;
        height: 50vh !important;
        object-fit: cover !important;
        object-position: center center !important;
        position: absolute !important;
    }

    #game-image-overlay.split4-mode #game-display-image {
        top: 0 !important;
        left: 0 !important;
    }

    #game-image-overlay.split4-mode #game-display-image-2 {
        top: 0 !important;
        left: 50% !important;
    }

    #game-image-overlay.split4-mode #game-display-image-3 {
        top: 50% !important;
        left: 0 !important;
    }

    #game-image-overlay.split4-mode #game-display-image-4 {
        top: 50% !important;
        left: 50% !important;
    }

    /* Make builder cards 10% taller in landscape */
    .builder-grid {
        height: 88vh !important;
        /* 80vh * 1.1 = 88vh */
    }
}