:root {
    --bg-dark: #0a0a0f;
    --primary-yellow: #ffcc00;
    --secondary-red: #e74c3c;
    --primary-blue: #0d47a1;
    --success-green: #2ecc71;
    --font-color: #f5f5f5;
    --score-size: 1.8em;
}

* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    background: linear-gradient(180deg, #0a0a0f 0%, #14141a 50%, #0a0a0f 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    color: var(--font-color);
    user-select: none;
    overflow-x: hidden;
}

/* --- Mobile Frame Simulation (Ensuring Full Screen Coverage) --- */
#mobile-frame {
    width: 100vw; 
    /* Use dynamic viewport height for better mobile browser support */
    height: 100dvh;
    max-width: 450px; /* Optional max width for wider screens */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: #111;
    /* Add padding for safe area insets on mobile devices */
    padding-bottom: env(safe-area-inset-bottom);
}

/* --- Player Containers --- */
.player-container {
    padding: 14px 16px;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0.7) 0%, rgba(20, 20, 20, 0.7) 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid var(--primary-yellow);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 204, 0, 0.1);
    backdrop-filter: blur(8px);
}
.player-container--compact {
    padding: 8px 15px; /* Reduced padding for mobile optimization */
    min-height: 60px; /* Reduced height to avoid URL bar overlap on mobile */
}
#player2-container {
    border-top: 3px solid var(--primary-yellow);
    border-bottom: none;
    /* Add extra padding for mobile browsers to keep buzzer above URL bar */
    padding-bottom: env(safe-area-inset-bottom, 8px);
}

h2 {
    font-size: 1.15em;
    margin: 0;
    color: var(--primary-yellow);
    font-weight: 700;
    letter-spacing: 0.03em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), 0 0 8px rgba(255, 204, 0, 0.3);
    display: inline-block;
}

.score-display {
    font-size: var(--score-size);
    font-weight: bold;
    margin: 0 10px;
    color: var(--success-green);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5), 0 0 10px rgba(46, 204, 113, 0.5);
}

/* Score update animation */
@keyframes scoreUpdate {
    0% {
        transform: scale(1);
    }
    25% {
        transform: scale(1.4) rotate(-5deg);
        color: #ffd700;
        text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5), 0 0 20px rgba(255, 215, 0, 0.8);
    }
    50% {
        transform: scale(1.4) rotate(5deg);
        color: #ffd700;
    }
    75% {
        transform: scale(1.2) rotate(-2deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
    }
}

.score-update {
    animation: scoreUpdate 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* * --- Player 1 Inversion (180° Rotation) --- 
 * The text for Player 1 is inverted (rotated 180°) so it's readable
 * when viewing the device upside down from the opposite side of the table.
 * The container itself is NOT rotated - only the text content is inverted.
 */
.inverted-view h2,
.inverted-view .score-display {
    /* Rotate text 180 degrees to be readable upside down */
    transform: rotate(180deg);
    display: inline-block;
}

/* Rotate the buzzer button for Player 1 as well */
.inverted-view .buzzer-btn {
    transform: rotate(180deg);
}


/* --- Buzzer Buttons (Circular) --- */
.buzzer-btn {
    width: 85px;
    height: 85px; 
    min-width: 85px; 
    min-height: 85px;
    border-radius: 50%;
    font-size: 0.9em;
    font-weight: 800;
    letter-spacing: 0.02em;
    cursor: pointer;
    background: radial-gradient(circle at 30% 30%, #ff7b7b, var(--secondary-red));
    color: white;
    border: 5px solid var(--primary-yellow);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 6px 18px rgba(255, 0, 0, 0.6), inset 0 -3px 8px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(255, 204, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    line-height: 1;
    text-align: center;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    position: relative;
}

.buzzer-btn:disabled {
    background: linear-gradient(135deg, #555, #444);
    border-color: #666;
    cursor: not-allowed;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
    opacity: 0.6;
}

.buzzer-btn:not(:disabled):hover {
    background: radial-gradient(circle at 30% 30%, #ff8787, #e74c3c);
    box-shadow: 0 8px 30px rgba(255, 0, 0, 0.9), inset 0 -3px 8px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(255, 204, 0, 0.3);
    transform: scale(1.1) translateY(-3px);
    border-width: 6px;
}

.buzzer-btn:not(:disabled):active {
    background: radial-gradient(circle at 50% 50%, #c0392b, #a53226);
    box-shadow: 0 2px 10px rgba(255, 0, 0, 0.8), inset 0 3px 8px rgba(0, 0, 0, 0.5);
    transform: scale(0.95) translateY(1px);
}

/* Pulse animation when buzzer is unlocked */
@keyframes buzzer-pulse {
    0%, 100% {
        box-shadow: 0 4px 15px rgba(255, 0, 0, 0.5), inset 0 -3px 8px rgba(0, 0, 0, 0.3);
    }
    50% {
        box-shadow: 0 4px 30px rgba(255, 0, 0, 0.9), 0 0 20px rgba(255, 204, 0, 0.6), inset 0 -3px 8px rgba(0, 0, 0, 0.3);
    }
}

.buzzer-btn:not(:disabled) {
    animation: buzzer-pulse 1.5s ease-in-out infinite;
}

/* --- Game Center (Question/Judge) --- */
#game-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 8px;
    position: relative;
    /* Enhanced circuit board background */
    background-color: #0d0d0d;
    background-image: 
        radial-gradient(circle at 25% 25%, rgba(255, 204, 0, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 75% 75%, rgba(46, 204, 113, 0.05) 0%, transparent 50%),
        radial-gradient(#1e1e1e 1px, transparent 0), 
        radial-gradient(#1e1e1e 1px, transparent 0);
    background-size: 100% 100%, 100% 100%, 40px 40px, 40px 40px;
    background-position: 0 0, 0 0, 0 0, 20px 20px;
}

#status-area {
    padding: 8px;
    width: 100%;
    text-align: center;
    min-height: 30px;
    background: rgba(255, 204, 0, 0.1);
    border-radius: 5px;
}

#status-message {
    font-size: 1.1em;
    font-weight: bold;
    color: var(--primary-yellow);
    transition: all 0.3s ease;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* Animation applied via JavaScript for better control */
#status-message.status-update {
    animation: statusPulse 0.5s ease-out;
}

@keyframes statusPulse {
    0% {
        opacity: 0;
        transform: scale(0.95);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

#question-area {
    width: 98%;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 0;
}

.question-text {
    width: 95%;
    margin: 8px auto;
    padding: 12px;
    border: 3px solid var(--primary-yellow);
    background-color: #222;
    text-align: center;
    font-size: 1.2em;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(255, 204, 0, 0.5);
    line-height: 1.4;
    display: block; /* Always visible by default */
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    border-radius: 8px;
    background: linear-gradient(135deg, #222 0%, #2a2a2a 100%);
}

/* Hidden state */
.question-text.hidden {
    display: none !important;
}

/* Fade in animation for questions */
.question-text:not(.hidden) {
    animation: fadeInScale 0.5s ease-out forwards;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Inverted text styling for Player 1 - uses separate animation to preserve rotation */
.inverted-content {
    transform: rotate(180deg);
}

/* Animation for inverted content that preserves rotation */
.question-text.inverted-content:not(.hidden) {
    animation: fadeInScaleInverted 0.5s ease-out forwards;
}

@keyframes fadeInScaleInverted {
    from {
        opacity: 0;
        transform: rotate(180deg) scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: rotate(180deg) scale(1) translateY(0);
    }
}

/* --- Answer Reveal and Moderator Controls --- */
#answer-reveal-area {
    width: 95%;
    padding: 12px;
    background: linear-gradient(135deg, #2a3a2a 0%, #1f2f1f 100%);
    border-radius: 8px;
    margin: 10px 0;
    border: 2px solid var(--success-green);
    text-align: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
    box-shadow: 0 4px 10px rgba(46, 204, 113, 0.2);
}

/* Inverted orientation for answer reveal area when Player 1 is judge */
#answer-reveal-area.inverted-judge {
    transform: rotate(180deg);
}

#answer-text {
    font-size: 1.2em;
    color: var(--success-green);
    font-weight: bold;
    margin: 8px 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    animation: answerReveal 0.5s ease-out;
}

@keyframes answerReveal {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

#moderator-controls {
    margin-top: 8px;
    padding: 15px;
    width: 95%;
    border: 2px dashed var(--primary-yellow);
    background: linear-gradient(135deg, #2a2a1a 0%, #1a1a0a 100%);
    border-radius: 8px;
    text-align: center;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

/* Inverted orientation for moderator controls when Player 1 is judge */
#moderator-controls.inverted-judge {
    transform: rotate(180deg);
}

#moderator-controls h4 {
    color: var(--primary-yellow);
    margin: 0 0 10px 0;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.control-btn {
    padding: 12px 20px;
    margin: 6px 4px;
    border: none;
    border-radius: 25px;
    font-weight: bold;
    cursor: pointer;
    font-size: 0.95em;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    position: relative;
    overflow: hidden;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.control-btn:hover::before {
    width: max(300px, 200%);
    height: max(300px, 200%);
}

.control-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.control-btn:active {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.approve {
    background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%);
    color: white;
}

.approve:hover {
    background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
}

.reject {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
}

.reject:hover {
    background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
}

#show-answer-btn {
    background: linear-gradient(135deg, var(--primary-blue) 0%, #0b3d91 100%);
    color: white;
    width: 100%;
    margin: 8px 0;
    font-size: 1em;
}

#show-answer-btn:hover {
    background: linear-gradient(135deg, #0b3d91 0%, #082d6f 100%);
}

/* --- Game Board --- */
#game-board {
    width: 95%;
    margin: 10px auto;
    padding: 10px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    border-radius: 8px;
    border: 3px solid var(--primary-yellow);
    box-shadow: 0 4px 15px rgba(255, 204, 0, 0.3);
}

.category-column {
    margin-bottom: 8px;
}

.category-header {
    background: linear-gradient(135deg, var(--primary-yellow) 0%, #ffd700 100%);
    color: #000;
    padding: 8px;
    font-size: 0.9em;
    font-weight: bold;
    text-align: center;
    border-radius: 5px 5px 0 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.question-tiles {
    display: flex;
    gap: 5px;
    padding: 5px 0;
}

.question-tile {
    flex: 1;
    padding: 15px 8px;
    background: linear-gradient(135deg, var(--primary-blue) 0%, #1565c0 100%);
    color: white;
    border: 2px solid var(--primary-yellow);
    border-radius: 5px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
    position: relative;
}

.question-tile:hover:not(.used) {
    background: linear-gradient(135deg, #1565c0 0%, #1976d2 100%);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 15px rgba(255, 204, 0, 0.5);
    border-width: 3px;
}

.question-tile:active:not(.used) {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.question-tile.used {
    background: linear-gradient(135deg, #333 0%, #444 100%);
    color: #888;
    border-color: #555;
    cursor: not-allowed;
    opacity: 0.5;
}

.question-tile.selected {
    background: linear-gradient(135deg, var(--success-green) 0%, #27ae60 100%);
    border-color: #fff;
    animation: tileSelect 0.4s ease-out;
}

@keyframes tileSelect {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 20px rgba(46, 204, 113, 0.8);
    }
    100% {
        transform: scale(1);
    }
}

.hidden {
    display: none !important;
}

/* Smooth fade in for answer reveal */
#answer-reveal-area {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Start Round Button in the center */
.center-control {
    padding: 22px 45px;
    font-size: 1.5em;
    background: linear-gradient(135deg, var(--primary-yellow) 0%, #ffd700 100%);
    color: #000;
    border: 4px solid var(--primary-yellow);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 800;
    letter-spacing: 0.03em;
    box-shadow: 0 8px 24px rgba(255, 204, 0, 0.6), inset 0 -2px 0 rgba(0, 0, 0, 0.2), 0 0 0 2px rgba(255, 204, 0, 0.2);
    margin: 20px auto;
    display: block;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
    position: relative;
    overflow: hidden;
}

.center-control::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: left 0.5s;
}

.center-control:hover::before {
    left: 100%;
}

.center-control:hover {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    box-shadow: 0 10px 30px rgba(255, 204, 0, 0.8), inset 0 -2px 0 rgba(0, 0, 0, 0.2), 0 0 0 3px rgba(255, 204, 0, 0.3);
    transform: translateY(-4px) scale(1.03);
}

.center-control:active {
    background: linear-gradient(135deg, #e6b800 0%, #d4a800 100%);
    transform: translateY(-1px) scale(1);
    box-shadow: 0 4px 12px rgba(255, 204, 0, 0.5), inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* --- Responsive Design --- */
@media (max-width: 450px) {
    .buzzer-btn {
        width: 70px;
        height: 70px;
        min-width: 70px;
        min-height: 70px;
        font-size: 0.75em;
    }
    
    .question-text {
        font-size: 1em;
        padding: 12px;
    }
    
    .center-control {
        padding: 16px 32px;
        font-size: 1.2em;
    }
    
    h2 {
        font-size: 1em;
    }
    
    .score-display {
        font-size: 1.5em;
    }
    
    .control-btn {
        padding: 10px 16px;
        font-size: 0.85em;
        margin: 4px 2px;
    }
}

@media (max-width: 350px) {
    .buzzer-btn {
        width: 60px;
        height: 60px;
        min-width: 60px;
        min-height: 60px;
        font-size: 0.7em;
    }
    
    .question-text {
        font-size: 0.9em;
        padding: 10px;
    }
    
    .center-control {
        padding: 14px 28px;
        font-size: 1.1em;
    }
}

/* --- Accessibility Improvements --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
button:focus-visible {
    outline: 3px solid var(--primary-yellow);
    outline-offset: 3px;
}

.buzzer-btn:focus-visible {
    outline: 4px solid var(--primary-yellow);
    outline-offset: 4px;
}

.center-control:disabled {
    background: linear-gradient(135deg, #555 0%, #444 100%);
    color: #888;
    border-color: #555;
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.6;
}

/* --- Win Screen --- */
#win-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    animation: fadeIn 0.5s ease-out;
}

#win-screen-content {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    padding: 40px 30px;
    border-radius: 20px;
    border: 5px solid var(--primary-yellow);
    box-shadow: 0 0 40px rgba(255, 204, 0, 0.8), 0 0 80px rgba(255, 204, 0, 0.4);
    text-align: center;
    max-width: 90%;
    animation: winScreenSlide 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes winScreenSlide {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(-30px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

#winner-announcement {
    font-size: 2.5em;
    color: var(--primary-yellow);
    margin: 0 0 20px 0;
    text-shadow: 0 4px 10px rgba(255, 204, 0, 0.8), 0 0 20px rgba(255, 204, 0, 0.5);
    animation: winnerPulse 2s ease-in-out infinite;
}

@keyframes winnerPulse {
    0%, 100% {
        transform: scale(1);
        text-shadow: 0 4px 10px rgba(255, 204, 0, 0.8), 0 0 20px rgba(255, 204, 0, 0.5);
    }
    50% {
        transform: scale(1.05);
        text-shadow: 0 6px 15px rgba(255, 204, 0, 1), 0 0 30px rgba(255, 204, 0, 0.8);
    }
}

#winner-details {
    margin: 30px 0;
    padding: 20px;
    background: rgba(46, 204, 113, 0.15);
    border-radius: 15px;
    border: 3px solid var(--success-green);
}

#winner-name {
    font-size: 2.2em;
    color: var(--success-green);
    margin: 0 0 10px 0;
    font-weight: bold;
    text-shadow: 0 3px 8px rgba(46, 204, 113, 0.6), 0 0 15px rgba(46, 204, 113, 0.4);
}

#winner-score {
    font-size: 1.8em;
    color: var(--primary-yellow);
    margin: 0;
    font-weight: bold;
    text-shadow: 0 2px 6px rgba(255, 204, 0, 0.6);
}

#congratulations-message {
    font-size: 1.3em;
    color: var(--font-color);
    margin: 20px 0 30px 0;
    font-style: italic;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#play-again-btn {
    font-size: 1.3em;
    padding: 18px 45px;
    margin-top: 10px;
}

/* Responsive adjustments for win screen */
@media (max-width: 450px) {
    #win-screen-content {
        padding: 30px 20px;
    }
    
    #winner-announcement {
        font-size: 2em;
    }
    
    #winner-name {
        font-size: 1.8em;
    }
    
    #winner-score {
        font-size: 1.5em;
    }
    
    #congratulations-message {
        font-size: 1.1em;
    }
    
    #play-again-btn {
        font-size: 1.1em;
        padding: 15px 35px;
    }
}

@media (max-width: 350px) {
    #winner-announcement {
        font-size: 1.6em;
    }
    
    #winner-name {
        font-size: 1.5em;
    }
    
    #winner-score {
        font-size: 1.3em;
    }
    
    #congratulations-message {
        font-size: 1em;
    }
}
