/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    font-family: sans-serif;
    overflow-x: hidden;
    background-color: black;
    min-height: 100%;
    min-width: 100%;
    display: flex;
    flex-direction: row;
}

/* --- Main Content --- */
#main {
    flex: 1;
    position: relative;
    color: white;
    display: flex;
    flex-direction: column;
    /* Changed to column for header + content */
    flex-grow: 1;
    /* align-items: center;  Removed */
    /* justify-content: center; Removed */
    transition: margin-left 0.3s ease;
    height: 100vh;
    overflow: hidden;
}

#team-view-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    overflow: hidden;
    position: relative;
}

#main.team-view-active #team-view-content {
    display: flex;
    flex-direction: column;
    /* Grid container behavior */
    justify-content: flex-start;
    align-items: stretch;
}

#main .pwd-full {
    flex-grow: 1;
    flex-shrink: 1;
    max-width: 50%;
    height: auto;
}

#mode-island {
    /* ISLAND STYLE */
    position: static;
    transform: none;
    background-color: #ec4034;
    /* Red */
    color: white;
    padding: 0 15px;
    /* Adjust padding for flex alignment */
    border-radius: 8px;
    /* Match other island */
    z-index: 2000;
    font-weight: bold;
    text-transform: uppercase;
    box-shadow: none;
    display: none;
    /* Hidden by default */
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    height: 100%;
    /* Fill wrapper height */
}

#mode-island button {
    background: white;
    color: black;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.8rem;
}

#mode-island button:hover {
    background: #eee;
}

/* --- Dynamic Team View Styles --- */

#main.team-view-active {
    /* No longer need to change #main defaults significantly as it's already column */
    padding: 0;
    gap: 0;
}

/* 1. SLIM TOP HEADER WRAPPER */
.tv-header-wrapper {
    margin: 10px;
    margin-bottom: 0px;
    padding: 0 15px;
    height: 50px;
    display: flex;
    justify-content: flex-start;
    /* Align left */
    align-items: stretch;
    /* Stretch children to fill height if needed */
    gap: 15px;
    /* Separation between islands */
    flex-shrink: 0;
}

/* CONTENT ISLAND (Right side) */
.tv-header-content {
    background-color: #333;
    border-radius: 8px;
    padding: 0 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    flex: 1;
    /* Take up remaining space */
}

.tv-header-left {
    font-size: 1.1rem;
    font-weight: bold;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tv-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tv-brand-text {
    font-size: 0.9rem;
    font-weight: 600;
}

.tv-header-logo {
    height: 30px;
    /* Small logo */
    width: auto;
    object-fit: contain;
}

/* 2. MIDDLE VIDEO GRID */
.tv-grid {
    flex: 1;
    display: flex;
    gap: 10px;
    padding: 10px;
    min-height: 0;
    /* Crucial for nested flex scrolling */
}

/* Left side (Desktop Stream) */
.tv-main-video {
    flex: 2;
    /* Takes 2/3rds of width */
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid #333;
}

/* Right side container */
.tv-side-stack {
    flex: 1;
    /* Takes 1/3rd of width */
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    /* Prevent flex overflow */
}

.tv-side-item {
    flex: 1;
    /* Split height equally */
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid #333;
    /* Default centering for video/image boxes */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Specific styling for the Info/Stats/Buttons Panel */
.tv-side-item.info-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    /* Stretch content width */
    justify-content: flex-start;
    /* Start from top */
    padding: 15px;
    gap: 5px;
    overflow-y: auto;
    /* Scroll if buttons overflow */
}

/* Team Info inside Side Panel */
.tv-info-compact {
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

.tv-name {
    font-size: 1.4rem;
    /* Slightly smaller than before to fit */
    font-weight: bold;
    color: #6bbd45;
    margin: 0 0 4px 0;
    line-height: 1.2;
}

.tv-sub {
    font-size: 0.85rem;
    color: #aaa;
}

/* Stats Row inside Side Panel */
.tv-stats-compact {
    margin-top: 5px;
    margin-bottom: -5px;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.stat-box {
    background: #222;
    padding: 8px;
    border-radius: 4px;
    flex: 1;
    /* Distribute space equally */
    text-align: center;
    border: 1px solid #333;
}

.stat-label {
    font-size: 0.65rem;
    color: #888;
    text-transform: uppercase;
    margin-bottom: 2px;
}

.stat-value {
    font-size: 1rem;
    font-weight: bold;
    color: white;
}

/* Problem Buttons Container (Moved here) */
#problem-list-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    padding-top: 5px;
    gap: 0;
}

.live-controls {
    display: flex;
    gap: 5px;
    width: 100%;
    margin-top: 10px;
    margin-bottom: 10px;
}

.prob-btn-live {
    flex: 1;
    background: #3a55a5;
    color: white;
    border: 1px solid #3a55a5;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.2s;
    text-align: center;
}

.prob-btn-live:hover {
    background: #5c7dd6;
    border-color: #5c7dd6;
}

.prob-btn-replay {
    flex: 1;
    background: #ec4034;
    color: white;
    border: 1px solid #ec4034;
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    transition: all 0.2s;
    text-align: center;
}

.prob-btn-replay:hover {
    background: #ff5e52;
    border-color: #ff5e52;
}

.prob-btn-replay:disabled {
    background: #555;
    border-color: #555;
    color: #888;
    cursor: not-allowed;
}

.prob-divider {
    height: 1px;
    background-color: #888;
    margin: 10px 0;
    width: 100%;
}

.prob-header {
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    margin-bottom: 8px;
    white-space: pre-wrap;
    line-height: 1.3;
}

.prob-header-solved {
    color: #6bbd45;
}

.prob-header-failed {
    color: #ec4034;
}

.prob-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 5px;
}

.prob-btn-round {
    background: #222;
    color: black;
    border: none;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-align: center;
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.prob-btn-solved {
    background-color: #6bbd45;
}

.prob-btn-solved:hover {
    background: #3a55a5;
    color: white;
}

.prob-btn-failed {
    background-color: #ec4034;
}

.prob-btn-failed:hover {
    background: #3a55a5;
    color: white;
}

.prob-btn-round.active {
    border: 2px solid white;
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

/* Video Elements */
video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.vid-label {
    position: absolute;
    top: 5px;
    left: 5px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 2px 6px;
    font-size: 0.75rem;
    border-radius: 4px;
    pointer-events: none;
    z-index: 10;
}

/* Fullscreen Button */
.fullscreen-toggle {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 20;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: background 0.2s;
}

.fullscreen-toggle:hover {
    background: rgba(0, 0, 0, 0.8);
}

.tv-main-video:fullscreen video,
.tv-side-item:fullscreen video {
    object-fit: contain;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #main.team-view-active {
        display: block;
        overflow-y: auto;
        /* Allow window scroll on mobile */
        height: auto;
    }

    .tv-grid {
        flex-direction: column-reverse;
        padding: 10px;
    }

    .tv-main-video {
        height: 250px;
        flex: none;
    }

    .tv-side-stack {
        flex: none;
        gap: 15px;
    }

    .tv-side-item {
        height: 250px;
        /* Give side items fixed height on mobile */
    }

    .tv-side-item.info-panel {
        height: auto;
        /* Let info panel grow */
        max-height: 300px;
    }
}

/* --- Navigation & Stream Controls --- */

.team-card.active {
    background-color: #2a2a2a;
    /* Slightly lighter bg */
    border-left: 4px solid #6bbd45;
}

.nav-controls {
    display: flex;
    gap: 5px;
    margin-top: 5px;
    width: 100%;
}

.nav-btn {
    flex: 1;
    background: transparent;
    border: 1px solid #ec4034;
    /* Red border */
    color: #ec4034;
    padding: 6px;
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    border-radius: 3px;
    transition: all 0.2s;
}

.nav-btn:hover {
    background: rgba(236, 64, 52, 0.2);
}

.nav-btn.selected {
    background: #ec4034;
    /* Full background */
    color: white;
}