* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    overflow: hidden; /* Prevent scrolling */
}

.canvas-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.webgl {
    position: absolute;
    top: 0;
    left: 0;
    outline: none;
    width: 100%;
    height: 100%;
}

/* Base panel styles */
.panel {
    position: absolute;
    z-index: 1;
    background: rgba(255,255,255,0.95);
    border-radius: 8px;
    font-family: Arial, sans-serif;
    backdrop-filter: blur(5px);
}

/* Desktop styles */
@media (min-width: 769px) {
    .scoring-panel {
        top: 10px;
        right: 10px;
        padding: 15px;
        min-width: 300px;
        max-width: 350px;
    }
    
    .history-panel {
        bottom: 10px;
        right: 10px;
        padding: 15px;
        max-width: 400px;
        max-height: 330px;
        overflow-y: auto;
    }
    
    .coords-display {
        position: absolute;
        bottom: 10px;
        left: 10px;
        color: white;
        background: rgba(0,0,0,0.5);
        padding: 5px;
        font-size: 12px;
        z-index: 1;
        border-radius: 4px;
    }
}

/* Mobile styles - more specific */
@media (max-width: 768px) {
    body .scoring-panel {
        position: absolute !important;
        top: 5px !important;
        left: 5px !important;
        right: 5px !important;
        padding: 5px !important;
        max-height: 31.5vh !important;
        overflow-y: auto !important;
        font-size: 14px !important;
        z-index: 10 !important;
        background: rgba(255,255,255,0.95) !important;
        backdrop-filter: blur(5px) !important;
    }
    
    body .history-panel {
        position: absolute !important;
        bottom: 5px !important;
        left: 5px !important;
        right: 5px !important;
        padding: 5px !important;
        max-height: 20vh !important;
        min-height: 12vh !important;
        height: 20vh !important;
        overflow-y: auto !important;
        font-size: 12px !important;
        z-index: 10 !important;
        background: rgba(255,255,255,0.95) !important;
        backdrop-filter: blur(5px) !important;
    }
    
    body .coords-display {
        display: none !important;
    }
    
    /* Canvas wrapper now uses full screen */
    body .canvas-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100vh !important;
        z-index: 0 !important;
    }
    
    body .webgl {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }
}

/* Button styles */
.rally-controls {
    margin: 15px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.rally-btn {
    flex: 1;
    min-width: 120px;
    padding: 10px 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
}

#playRally {
    background: #28a745;
    color: white;
}

.quiz-input-container {
    display: flex;
    align-items: center;
}

#quizAnswer {
    width: auto;
    flex-grow: 1;
    margin-right: 10px;
}

.quiz-input-container {
    display: flex;
    align-items: center;
}

#quizAnswer {
    width: auto;
    flex-grow: 1;
    margin-right: 10px;
}

.quiz-input-container {
    display: flex;
    align-items: center;
}

#quizAnswer {
    width: auto;
    flex-grow: 1;
    margin-right: 10px;
}

#startGame {
    background: #007bff;
    color: white;
}

.game-controls {
    margin: 5px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.control-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    background: #6c757d;
    color: white;
}

.auto-btn {
    background: #ffc107;
    color: black;
}

/* Voice input (speak the score) — sits full-width under the quiz input row. */
.voice-btn {
    width: 100%;
    margin: 6px 0 0 0;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    background: #17a2b8;
    color: white;
}

.voice-btn.is-listening {
    background: #dc3545;
    animation: voicePulse 1s ease-in-out infinite;
}

@keyframes voicePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.65; }
}

/* Mobile button adjustments */
@media (max-width: 768px) {
    .rally-btn, .control-btn {
        font-size: 16px; /* Larger touch targets */
        padding: 12px 8px;
        min-height: 44px; /* iOS recommended touch target */
    }
    
    .scoring-panel h3 {
        font-size: 18px;
        margin: 0 0 8px 0;
    }
    
    #currentScore {
        font-size: 20px !important;
        padding: 8px !important;
        margin: 8px 0 !important;
    }
    
    #gameStatus {
        font-size: 14px;
        margin: 8px 0 !important;
    }
    
    .history-panel h4 {
        font-size: 16px;
        margin: 0 0 8px 0;
    }
}

/* Very small mobile screens */
@media (max-width: 480px) {
    body .scoring-panel {
        max-height: 40vh !important;
    }
    
    body .history-panel {
        max-height: 15vh !important;
        min-height: 12vh !important;
        height: 15vh !important;
    }
    
    /* Canvas still uses full screen on very small devices */
    body .canvas-wrapper {
        top: 0 !important;
        height: 100vh !important;
    }
    
    .rally-controls {
        flex-direction: column;
    }
    
    .rally-btn {
        min-width: 100%;
    }
}

/* Force rally history panel height - most specific selector */
@media (max-width: 768px) {
    body div#rallyHistory.panel.history-panel {
        height: 15vh !important;
        max-height: 15vh !important;
        min-height: 12vh !important;
    }
}

@media (max-width: 480px) {
    body div#rallyHistory.panel.history-panel {
        height: 15vh !important;
        max-height: 12vh !important;
        min-height: 12vh !important;
    }
}

/* Busy / disabled state for the Play Rally button while a rally animates.
   This is the visible half of the desync fix: the button locks out until the
   sequence settles, so rapid clicks can no longer overlap and scramble positions. */
.rally-btn:disabled,
.rally-btn.is-busy {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Loading overlay shown until court + players are in the scene (~6.8MB of GLBs). */
#loadingOverlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #333;
    color: #fff;
    font-family: Arial, sans-serif;
    transition: opacity 0.4s ease;
}

#loadingOverlay.is-hidden {
    opacity: 0;
    pointer-events: none;
}

#loadingOverlay .loading-inner {
    text-align: center;
    font-size: 15px;
    letter-spacing: 0.3px;
}

#loadingOverlay .spinner {
    width: 42px;
    height: 42px;
    margin: 0 auto 14px;
    border: 4px solid rgba(255, 255, 255, 0.25);
    border-top-color: #28a745;
    border-radius: 50%;
    animation: pb-spin 0.9s linear infinite;
}

@keyframes pb-spin {
    to { transform: rotate(360deg); }
}