/* =========================================
   1. RESET & BASE STYLES
   ========================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: #1a1a1a;
    color: #ffffff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
}

/* =========================================
   2. VIDEO CONTAINER
   ========================================= */
.video-wrapper {
    position: relative;
    width: 100vw;       
    height: 100vh;      
    background-color: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#local-video, #remote-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; 
    
    /* NEW: Custom Placeholder Styling */
    background-color: #1a1a1a; /* Deep dark gray to match the app theme */
    background-image: url('../img/silhouette.png'); /* Points to your new image */
    background-position: center;
    background-repeat: no-repeat;
    background-size: auto 40%; /* Scales the height to 40% of the screen so it isn't too huge */
    z-index: 1; 
}

/* Let's also hide the default browser video controls/styling just in case */
video::-webkit-media-controls {
    display: none !important;
}

/* =========================================
   3. MINIMALIST SCOREBOARD OVERLAY
   ========================================= */
.scoreboard-wrapper {
    position: absolute;
    /* Hugs the top edge instead of pushing 5% down */
    top: max(10px, env(safe-area-inset-top)); 
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px; 
    z-index: 10;
}

.scoreboard-overlay {
    display: flex;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
}

.team-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 16px; /* Dramatically shrunk padding */
    min-width: 80px;   /* Thinner blocks */
}

.team-name {
    font-size: 11px; /* Smaller text */
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: #a0a0a0;
    margin-bottom: 2px;
}

.team-score {
    font-size: 32px; /* Reduced from massive 48px */
    font-weight: bold;
}

.set-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    background-color: #0057ad;
}

#set-number {
    font-size: 18px !important; /* Shrunk the set number font */
}

/* NEW: Past Set History Styling */
.set-history {
    display: flex;
    flex-direction: column; /* This forces the scores to stack vertically */
    align-items: center;    /* Keeps them perfectly centered under the main board */
    gap: 8px;
}

.past-set {
    background: rgba(0, 0, 0, 0.75);
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 13px;
    display: flex;
    gap: 8px;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
}

.past-set .set-label {
    color: #a0a0a0;
    font-weight: bold;
    font-size: 11px;
    letter-spacing: 1px;
}

.past-set .past-scores {
    font-weight: bold;
    color: #ffffff;
}

/* =========================================
   4. FLOATING BROADCASTER DASHBOARD
   ========================================= */
.control-panel {
    position: absolute;
    bottom: 15px; 
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: rgba(0, 0, 0, 0.75); 
    padding: 15px 20px;
    border-radius: 12px;
    width: 95%;
    max-width: 500px;
    z-index: 100;
    backdrop-filter: blur(4px); 
}

.score-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.group-label {
    font-size: 11px;
    letter-spacing: 1.5px;
    color: #a0a0a0;
    font-weight: bold;
}

.group-buttons {
    display: flex;
    gap: 6px;
}

/* NEW: Unified Bottom Row Container */
.bottom-actions {
    display: flex;
    justify-content: space-between; /* Pushes icons to edges, settings to center */
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    width: 100%;
}

.match-settings {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

/* =========================================
   5. BUTTON STYLES & POSITIONING
   ========================================= */
button {
    background-color: #333;
    color: white;
    border: none;
    padding: 12px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    transition: background 0.2s;
    min-width: 50px;
}

button:hover {
    background-color: #0057ad;
}

/* Circular Icon Buttons */
.icon-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 44px; /* Made slightly larger for easier tapping */
    height: 44px;
    padding: 0;
    border-radius: 50%;
    min-width: unset; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.6); /* Helps them pop against the live video */
}

.btn-util { background-color: #555; }
.btn-danger { background-color: #8b0000; }

/* Absolute Positioning for Top Corners */
.top-left {
    position: absolute;
    /* Uses max() to respect the phone's physical notch/camera cutout */
    top: max(20px, env(safe-area-inset-top));
    left: max(20px, env(safe-area-inset-left));
    z-index: 100;
}

.top-right {
    position: absolute;
    top: max(20px, env(safe-area-inset-top));
    right: max(20px, env(safe-area-inset-right));
    z-index: 100;
}

/* NEW: Absolute Positioning for Bottom Corner */
.bottom-right {
    position: absolute;
    bottom: max(20px, env(safe-area-inset-bottom));
    right: max(20px, env(safe-area-inset-right));
    z-index: 100;
}

/* =========================================
   LIVE STREAM TOGGLE BUTTON
   ========================================= */
.btn-live {
    /* Perfectly centered by default */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    
    background-color: #0057ad; 
    color: white;
    padding: 12px 24px;
    border-radius: 30px; 
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 1px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.6);
    min-width: 160px;
    transition: all 0.4s ease; /* Adds a smooth glide animation */
}

/* When the stream starts, glide it to the top right, beside the Reset button */
.live-active {
    top: max(20px, env(safe-area-inset-top)) !important;
    
    /* Calculates screen width minus the Reset button width and a 12px gap */
    left: calc(100% - max(20px, env(safe-area-inset-right)) - 56px) !important;
    transform: translate(-100%, 0) !important; 
    
    background-color: #8b0000 !important;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(139, 0, 0, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(139, 0, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(139, 0, 0, 0); }
}

/* =========================================
   LOGOUT BUTTON & BOTTOM LEFT POSITIONING
   ========================================= */
.bottom-left {
    position: absolute;
    bottom: max(20px, env(safe-area-inset-bottom));
    left: max(20px, env(safe-area-inset-left));
    z-index: 100;
}

.btn-logout {
    background-color: rgba(0, 0, 0, 0.6);
    color: #a0a0a0;
    padding: 8px 16px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 12px;
    font-weight: bold;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    transition: all 0.2s ease;
}

.btn-logout:hover {
    background-color: #8b0000;
    color: white;
    border-color: #8b0000;
}

/* =========================================
   THE ULTIMATE MOBILE PSEUDO-FULLSCREEN FIX
   ========================================= */
body.ios-fullscreen-fix {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
}

body.ios-fullscreen-fix .video-wrapper,
body.ios-fullscreen-fix .viewer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh; /* 'dvh' automatically adjusts when the Safari URL bar hides! */
    z-index: 9999;
    background-color: #000;
}

/* Ensure the wrapper handles fullscreen background on Android */
.video-wrapper:fullscreen {
    background-color: #000;
    width: 100vw;
    height: 100vh;
}
.video-wrapper:-webkit-full-screen {
    background-color: #000;
}