/* Mobile-First Responsive Styles for C or B Game */

/* Base Mobile Styles (320px and up) */
@media screen and (max-width: 768px) {

    /* Override main container height for mobile */
    body .game-container {
        height: auto !important;
        min-height: 100vh;
        /* Additional overscroll prevention for game container */
        overscroll-behavior: none;
        touch-action: pan-x pan-y;
    }

    /* Create room container mobile fixes */
    .create-room-container {
        width: 95%;
        max-width: 500px;
        max-height: 90vh;
        overflow-y: auto;
        overscroll-behavior: none;
        touch-action: pan-x pan-y;
    }

    .create-room-container .retro-border {
        padding: 12px;
        margin: 8px 0;
    }

    /* Picture preview adjustments */
    .picture-preview .preview-image {
        max-height: 200px;
        width: auto;
        object-fit: contain;
    }
    
    /* Typography Adjustments */
    .game-title {
        font-size: 2.2rem;
        letter-spacing: 2px;
    }
    
    .retro-border {
        padding: 16px;
        border-width: 2px;
        margin: 8px;
    }
    
    /* Touch-Friendly Inputs */
    .retro-input {
        padding: 16px;
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px;
    }
    
    .retro-button {
        min-height: 48px;
        padding: 16px 20px;
        font-size: 0.9rem;
    }
    
    /* Stack buttons vertically on mobile */
    .button-group {
        gap: 16px;
    }
    
    /* Upload Form Mobile Layout */
    .options-input {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .timer-options {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    .answer-buttons {
        gap: 20px;
    }
    
    .answer-btn {
        width: 80px;
        height: 80px;
        font-size: 2.2rem;
    }
    
    /* Voting Layout */
    .voting-options {
        grid-template-columns: 1fr;
        gap: 16px;
        transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
        max-height: 300px;
        overflow: hidden;
    }

    /* Hide voting buttons after voting to save space */
    .voting-options.voted-hidden {
        display: none !important;
        max-height: 0;
        opacity: 0;
        margin: 0;
        padding: 0;
        pointer-events: none;
    }

    .vote-btn {
        min-height: 80px;
        padding: 16px;
    }

    .vote-letter {
        font-size: 2.4rem;
    }
    
    /* Game Container Mobile Grid */
    .game-container {
        padding: 12px;
        gap: 12px;
        grid-template-rows: auto auto 1fr;
        min-height: 100vh;
        height: auto;
    }
    
    /* Room Header Mobile - Compact for viewport fit */
    .room-header {
        padding: 12px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
        min-height: auto;
    }

    .room-name-large {
        font-size: 16px;
        letter-spacing: 0.5px;
    }

    .room-actions {
        display: flex;
        gap: 8px;
    }

    .room-actions .retro-button {
        min-height: 36px;
        padding: 8px 12px;
        font-size: 0.75rem;
    }
    
    /* Timer Display Mobile - Compact */
    .round-header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .timer-display {
        text-align: center;
        min-width: auto;
    }

    .timer-bar {
        width: 100%;
        max-width: 250px;
        margin: 0 auto 6px auto;
        height: 6px;
    }

    #time-remaining {
        font-size: 0.9rem;
    }
    
    /* Image Container Mobile - Better sizing for mobile viewport */
    .image-container {
        margin-bottom: 16px;
        flex-shrink: 0; /* Prevent image from shrinking */
    }

    .round-image {
        max-height: 250px; /* Increased from 200px for better visibility */
        width: 100%;
        object-fit: contain;
        display: block; /* Remove inline spacing */
    }

    /* Active Round Section Mobile - Improved scrolling layout */
    .active-round-section {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 20px;
        /* Allow natural content height - no max-height restriction */
        height: auto;
        -webkit-overflow-scrolling: touch; /* Smooth iOS scrolling */
    }

    .active-round-section .retro-border {
        padding: 12px;
        /* Ensure content doesn't overflow */
        overflow: visible;
    }

    .round-header {
        margin-bottom: 12px;
        flex-shrink: 0; /* Prevent header from shrinking */
    }

    .round-header h4 {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }

    /* Admin Dashboard Section Mobile - Fix viewport overflow */
    .admin-dashboard-section {
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        padding-bottom: 20px;
        /* Use more dynamic height calculation that accounts for header + status bar */
        max-height: calc(100vh - 100px);
        height: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .admin-dashboard-section .retro-border {
        display: flex;
        flex-direction: column;
        min-height: 0;
        flex: 1;
        overflow-y: auto;
    }

    /* Ensure admin dashboard children don't overflow */
    .admin-dashboard-section .voting-progress-table,
    .admin-dashboard-section .vote-status,
    .admin-dashboard-section .admin-controls {
        flex-shrink: 0;
        margin-bottom: 12px;
    }

    /* Ensure voting buttons stay visible */
    .voting-options {
        margin-top: auto;
        padding-top: 16px;
        background: inherit;
        position: relative;
        z-index: 10;
    }
    
    /* Players Sidebar - Hide on Mobile */
    .players-sidebar {
        display: none;
    }

    /* Voting Progress Table - Show on Mobile ONLY after voting */
    .voting-progress-table {
        margin-top: 16px;
        width: 100%;
        display: none; /* Hidden by default - shown after voting via JS */
        flex-shrink: 0; /* Prevent table from shrinking */
    }

    .voting-progress-table h5 {
        color: var(--c64-yellow);
        font-size: 1rem;
        margin-bottom: 12px;
        text-align: center;
        letter-spacing: 1px;
        text-transform: uppercase;
    }

    .voting-table-container {
        overflow-x: auto;
        max-height: 300px;
        border: 3px solid var(--c64-cyan);
        border-radius: var(--corner-radius);
        background: rgba(0, 0, 128, 0.8);
        box-shadow: 0 0 15px rgba(0, 255, 255, 0.3);
    }

    .voting-table {
        width: 100%;
        border-collapse: collapse;
        font-size: 0.85rem;
    }

    .voting-table thead {
        background: rgba(0, 128, 255, 0.3);
        border-bottom: 2px solid var(--c64-cyan);
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .voting-table th {
        padding: 10px 8px;
        text-align: left;
        color: var(--c64-yellow);
        font-weight: bold;
        border-right: 1px solid var(--c64-cyan);
        font-size: 0.85rem;
    }

    .voting-table th:last-child {
        border-right: none;
    }

    .voting-table tbody tr {
        border-bottom: 1px solid rgba(0, 255, 255, 0.3);
    }

    .voting-table tbody tr:last-child {
        border-bottom: none;
    }

    .voting-table td {
        padding: 10px 8px;
        color: var(--c64-white);
        border-right: 1px solid rgba(0, 255, 255, 0.2);
        font-size: 0.85rem;
    }

    .voting-table td:last-child {
        border-right: none;
    }

    /* Status column styling */
    .voting-table .vote-status-not-voted {
        color: #FFD700;
    }

    .voting-table .vote-status-c {
        color: #00FF00;
        font-weight: bold;
    }

    .voting-table .vote-status-b {
        color: #FF1493;
        font-weight: bold;
    }

    /* Timestamp styling - More compact */
    .voting-table .vote-time {
        font-size: 0.7rem;
        color: rgba(255, 255, 255, 0.7);
    }

    /* Vote status styling - Compact */
    .vote-status {
        margin-top: 12px;
    }

    .vote-counts {
        display: flex;
        justify-content: center;
        gap: 24px;
        padding: 8px;
        font-size: 0.9rem;
    }

    /* Current user highlight */
    .voting-table .current-user {
        background: rgba(255, 255, 0, 0.15);
    }

    .voting-table .current-user td {
        color: var(--c64-yellow);
        font-weight: bold;
    }
    
    /* Room List Mobile */
    .rooms-grid {
        max-height: 50vh;
    }
    
    .room-card {
        padding: 12px;
    }
    
    .room-card-header {
        flex-direction: column;
        text-align: center;
        gap: 4px;
    }
    
    /* Screen Headers */
    .screen-header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }
    
    .screen-header h2 {
        font-size: 1.3rem;
    }
    
    /* Modal Mobile */
    .modal-content {
        margin: 16px;
        min-width: auto;
        max-width: calc(100vw - 32px);
    }
    
    /* Toast Mobile */
    .toast-notification {
        bottom: 16px;
        left: 16px;
        right: 16px;
        transform: translateY(100px);
        max-width: calc(100vw - 32px);
        margin: 0 auto;
    }
    
    .toast-notification.show {
        transform: translateY(0);
    }
}

/* Small Mobile (320px - 480px) */
@media screen and (max-width: 480px) {
    
    .game-title {
        font-size: 1.8rem;
        letter-spacing: 1px;
    }
    
    .retro-border {
        padding: 12px;
    }
    
    .retro-button {
        font-size: 0.8rem;
        padding: 14px 16px;
    }
    
    .timer-options {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .timer-btn {
        padding: 16px 12px;
        font-size: 0.8rem;
    }
    
    .answer-btn {
        width: 70px;
        height: 70px;
        font-size: 2rem;
    }
    
    .vote-letter {
        font-size: 2.4rem;
    }

    /* Adjust active round section for small mobile */
    .active-round-section {
        max-height: calc(100vh - 140px);
        padding-bottom: 16px;
    }

    /* Ensure voting buttons have minimum spacing */
    .voting-options {
        gap: 12px;
        margin-bottom: 16px;
    }

    .vote-btn {
        min-height: 70px;
        padding: 16px 12px;
    }
}

/* Large Mobile / Small Tablet (481px - 768px) */
@media screen and (min-width: 481px) and (max-width: 768px) {
    
    .options-input {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    .voting-options {
        grid-template-columns: 1fr 1fr;
        gap: 16px;
    }
    
    .timer-options {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Tablet Landscape (769px - 1024px) */
@media screen and (min-width: 769px) and (max-width: 1024px) {

    .game-container {
        grid-template-columns: 1fr 200px;
        grid-template-areas:
            "header sidebar"
            "status sidebar"
            "content sidebar";
        max-width: 900px;
    }

    .room-header {
        grid-area: header;
    }

    .game-status {
        grid-area: status;
    }

    .upload-section,
    .active-round-section,
    .admin-dashboard-section,
    .results-section {
        grid-area: content;
    }

    .players-sidebar {
        grid-area: sidebar;
        display: block;
        border: 2px solid var(--c64-cyan);
        background: rgba(0, 0, 128, 0.6);
        border-radius: var(--corner-radius);
        padding: 16px;
        max-height: 400px;
        overflow-y: auto;
    }

    .players-sidebar h4 {
        color: var(--c64-yellow);
        font-size: 1rem;
        margin-bottom: 12px;
        text-align: center;
    }

    .players-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .player-item {
        background: rgba(0, 255, 255, 0.1);
        border: 1px solid var(--c64-cyan);
        padding: 8px;
        border-radius: var(--corner-radius);
        font-size: 0.8rem;
        text-align: center;
    }

    .player-item.current {
        background: rgba(255, 255, 0, 0.2);
        border-color: var(--c64-yellow);
        color: var(--c64-yellow);
    }
}

/* Desktop (1025px and up) */
@media screen and (min-width: 1025px) {

    .game-container {
        grid-template-columns: 1fr 250px;
        grid-template-areas:
            "header sidebar"
            "status sidebar"
            "content sidebar";
        gap: 24px;
        padding: 24px;
        max-width: 1400px;
        margin: 0 auto;
    }

    .room-header {
        grid-area: header;
    }

    .game-status {
        grid-area: status;
    }

    .upload-section,
    .active-round-section,
    .admin-dashboard-section,
    .results-section {
        grid-area: content;
    }

    .players-sidebar {
        grid-area: sidebar;
        display: block;
        border: 3px solid var(--c64-cyan);
        background: rgba(0, 0, 128, 0.7);
        border-radius: var(--corner-radius);
        padding: 20px;
        max-height: 600px;
        overflow-y: auto;
        box-shadow: 0 0 20px rgba(0, 255, 255, 0.3);
    }

    .players-sidebar h4 {
        color: var(--c64-yellow);
        font-size: 1.1rem;
        margin-bottom: 16px;
        text-align: center;
        letter-spacing: 1px;
    }

    .players-list {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .player-item {
        background: rgba(0, 255, 255, 0.1);
        border: 2px solid var(--c64-cyan);
        padding: 12px;
        border-radius: var(--corner-radius);
        font-size: 0.9rem;
        text-align: center;
        transition: all 0.2s ease;
    }

    .player-item:hover {
        background: rgba(0, 255, 255, 0.2);
        box-shadow: 0 0 10px rgba(0, 255, 255, 0.4);
    }

    .player-item.current {
        background: rgba(255, 255, 0, 0.25);
        border-color: var(--c64-yellow);
        color: var(--c64-yellow);
        font-weight: bold;
        box-shadow: 0 0 15px rgba(255, 255, 0, 0.3);
    }

    /* Larger buttons for desktop */
    .retro-button {
        min-height: 52px;
        font-size: 1rem;
    }

    .vote-btn {
        min-height: 120px;
        padding: 24px;
    }

    /* Better timer display for desktop */
    .round-header {
        flex-direction: row;
    }

    .timer-display {
        text-align: right;
        min-width: 150px;
    }

    .timer-bar {
        width: 150px;
    }
}

/* High DPI Displays */
@media screen and (-webkit-min-device-pixel-ratio: 2),
       screen and (min-resolution: 192dpi) {
    
    /* Sharper borders and shadows for retina displays */
    .retro-border {
        box-shadow: 
            0 0 20px rgba(0, 255, 255, 0.4),
            inset 0 0 20px rgba(0, 255, 255, 0.15);
    }
    
    .game-title {
        text-shadow: 
            1px 1px 0px var(--c64-blue),
            2px 2px 4px rgba(0,0,0,0.8);
    }
    
    body {
        text-shadow: 0.5px 0.5px 0px rgba(0,0,0,0.8);
    }
}

/* Landscape Orientation Adjustments */
@media screen and (max-height: 500px) and (orientation: landscape) {
    
    .game-container {
        grid-template-rows: auto 1fr;
        padding: 8px;
    }
    
    .game-status {
        padding: 8px;
        font-size: 0.9rem;
    }
    
    .retro-border {
        padding: 8px;
    }
    
    .upload-section,
    .active-round-section {
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }
    
    .round-image {
        max-height: 150px;
    }
    
    .vote-btn {
        min-height: 60px;
        padding: 12px;
    }
    
    .vote-letter {
        font-size: 1.8rem;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    /* Already dark by default, but could adjust contrast */
    
    body {
        background: linear-gradient(45deg, #000040 0%, var(--c64-dark-blue) 50%, #000040 100%);
    }
    
    .retro-border {
        background: rgba(0, 0, 100, 0.95);
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    
    .screen {
        transition: opacity 0.1s ease;
        transform: none;
    }
    
    .screen.active {
        transform: none;
    }
    
    .retro-button:hover {
        transform: none;
    }
    
    .vote-btn:hover {
        transform: none;
    }
    
    .loading-progress {
        transition: width 0.1s ease;
    }
    
    .timer-progress {
        transition: none;
    }
    
    /* Remove scanline effect for reduced motion */
    body::after {
        display: none;
    }
}

/* High Contrast Support */
@media (prefers-color-scheme: dark) {
    
    :root {
        --c64-cyan: #00FFFF;
        --c64-yellow: #FFFF00;
        --c64-white: #FFFFFF;
        --c64-black: #000000;
    }
    
    .retro-border {
        border-width: 4px;
    }
    
    .retro-button {
        border-width: 3px;
    }
    
    .vote-btn {
        border-width: 4px;
    }
}

/* Print Styles (just in case) */
@media print {
    
    body {
        background: white;
        color: black;
    }
    
    .screen:not(.active) {
        display: none;
    }
    
    .retro-border {
        border: 2px solid black;
        background: white;
    }
    
    .retro-button {
        border: 1px solid black;
        background: white;
        color: black;
    }
}