:root {
    --bg-color: #1a1a1a;
    --sidebar-bg: #252525;
    --text-color: #e0e0e0;
    --accent-color: #3b82f6;
    --danger-color: #ef4444;
    --success-color: #22c55e;
    --warning-color: #f59e0b;
    --court-color: #2a3341; /* Darker modern court option if SVG fill is removed */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background-color: var(--sidebar-bg);
    padding: 15px;
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

.sidebar h1 {
    font-size: 1.25rem;
    margin-bottom: 5px;
    color: var(--accent-color);
}

/* --- Buttons & Controls --- */
.control-group {
    background: #333;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-group h3 {
    margin-bottom: 2px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #888;
}

.buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1; /* Keep flex: 1 for sidebar buttons */
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    background-color: #444;
    color: white;
    transition: all 0.2s ease;
    line-height: 1;
}

button:hover, .btn:hover {
    background-color: #555;
    transform: translateY(-1px);
}

button:active, .btn:active {
    transform: translateY(0);
}

button:disabled, .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Modifiers */
.btn-primary { 
    background-color: var(--accent-color); 
    color: white;
}
.btn-primary:hover { 
    background-color: #2563eb; 
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-danger { 
    background-color: var(--danger-color); 
    color: white;
}
.btn-danger:hover { 
    background-color: #dc2626; 
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.btn-warning { 
    background-color: var(--warning-color); 
    color: #111; 
}
.btn-warning:hover { 
    background-color: #d97706; 
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

/* Empty State */
.empty-state-msg {
    color: #666;
    text-align: center;
    margin-top: 40px;
    font-size: 1.1rem;
    font-style: italic;
    border: 2px dashed #333;
    padding: 40px;
    border-radius: 8px;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
    flex: initial; /* Don't stretch small buttons */
}

.btn-block {
    width: 100%;
    display: flex;
}

/* Timeline/Scrubber */
.scrubber {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#timeline {
    width: 100%;
    cursor: pointer;
}

#frame-display {
    font-size: 0.8rem;
    text-align: right;
    color: #aaa;
}

/* Play List */
input[type="text"], 
input[type="date"],
select {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: #222;
    border: 1px solid #444;
    color: white;
    border-radius: 6px;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus, 
input[type="date"]:focus,
select:focus {
    border-color: var(--accent-color);
}

/* Timeline/Scrubber specific overrides */
.scrubber input[type="range"] {
    width: 100%;
    cursor: pointer;
    margin: 5px 0;
}

#saved-plays-list {
    list-style: none;
    margin-top: 10px;
    max-height: 150px;
    overflow-y: auto;
}

#saved-plays-list li {
    padding: 5px 8px;
    border-bottom: 1px solid #444;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#saved-plays-list li:hover {
    background-color: #444;
}

.delete-play-btn {
    background: transparent;
    color: #888;
    padding: 0;
    width: auto;
    flex: initial;
}

.delete-play-btn:hover {
    color: var(--danger-color);
    background: transparent;
}

/* Category Headers */
.category-header {
    background: #444;
    color: #fff;
    padding: 4px 8px;
    font-size: 0.8rem;
    font-weight: bold;
    margin-top: 8px;
    border-radius: 4px;
}

.instructions {
    font-size: 0.85rem;
    color: #bbb;
    line-height: 1.4;
}

.instructions ul {
    margin-left: 20px;
    margin-top: 5px;
}

/* Presentation Mode */
body.fullscreen .sidebar {
    display: none;
}

body.fullscreen .court-container {
    padding: 0;
    background-color: #000; /* Black outer background */
    width: 100vw;
    height: 100vh;
}

body.fullscreen .court-border {
    padding: 10px; /* The requested tiny border */
    /* Logic: Fill 98% of width, but never more than what fits in 98% of height */
    width: min(98vw, calc(98vh * 1000 / 564)); 
    height: auto;
    max-width: none;
    border-radius: 4px;
    box-shadow: 0 0 20px rgba(0,0,0,0.8);
}

body.fullscreen .court {
    width: 100%;
    height: auto;
    aspect-ratio: 1000 / 564;
}

/* Exit fullscreen button (floating) - hidden by default, visible in fullscreen */
#exit-fullscreen {
    display: none;
    position: fixed;
    top: max(15px, env(safe-area-inset-top) + 15px);
    right: max(15px, env(safe-area-inset-right) + 15px);
    z-index: 1000;
    background: rgba(0,0,0,0.6);
    color: white;
    padding: 8px 12px;
    font-size: 0.8rem;
    border-radius: 4px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
    border: 1px solid rgba(255,255,255,0.2);
}

#exit-fullscreen:hover {
    opacity: 1;
    background: rgba(0,0,0,0.8);
}

body.fullscreen #exit-fullscreen {
    display: block;
}

/* Fullscreen Playback Controls */
#fullscreen-controls {
    display: none;
    position: fixed;
    bottom: 20px; /* Lowered slightly */
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    gap: 15px;
    background: rgba(0, 0, 0, 0.4);
    padding: 10px 20px;
    border-radius: 50px;
    backdrop-filter: blur(8px);
    opacity: 0.5;
    transition: all 0.3s ease;
    border: 1px solid rgba(255,255,255,0.1);
}

#fullscreen-controls:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.7);
    transform: translateX(-50%) translateY(-5px);
}

body.fullscreen #fullscreen-controls {
    display: flex;
}

#fullscreen-controls button {
    width: 45px; /* Slightly smaller */
    height: 45px;
    border-radius: 50%;
    font-size: 1.1rem;
    flex: initial;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

/* Main Court Area */
.court-container {
    flex: 1;
    background-color: #111;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 20px; /* Reduced padding to accommodate the border */
    overflow: hidden; /* Prevent scrollbars if dragging near edge */
}

.court-border {
    background-color: #001540; /* Dark Navy Blue */
    padding: 2.5%; /* Half thick (approx 5% total width) */
    width: 100%;
    max-width: 1200px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.court {
    position: relative;
    width: 100%;
    /* max-width removed here, controlled by wrapper */
    aspect-ratio: 1000 / 564;
}

.court-svg {
    width: 100%;
    height: 100%;
    display: block;
    /* Background handled by SVG pattern now */
    border-radius: 2px;
    /* box-shadow removed as wrapper has it */
}

/* Tokens */
#tokens-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let SVG clicks pass through if needed, but we need tokens clickable */
}

.token {
    position: absolute;
    width: var(--token-size, 40px);
    height: var(--token-size, 40px);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 1.1rem;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none; /* Safari/Chrome prefix */
    touch-action: none; /* CRITICAL: Prevents browser scrolling while dragging */
    pointer-events: auto; /* Re-enable pointer events for tokens */
    transform: translate(-50%, -50%); /* Center on coordinates */
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    transition: transform 0.1s; /* Smooth dragging feedback */
}

.token:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.1);
    z-index: 100;
}

.token.home {
    background-color: #2563eb; /* Blue */
    color: white;
    border: 2px solid white;
}

.token.away {
    background-color: #dc2626; /* Red */
    color: white;
    border: 2px solid white;
}

.token.ball {
    background-color: #f97316; /* Orange */
    font-size: 1.5rem;
    border: 2px solid #fff;
    width: calc(var(--token-size, 40px) * 0.75);
    height: calc(var(--token-size, 40px) * 0.75);
    z-index: 10;
}

.token.screen {
    background-color: #555;
    color: white;
    border: 2px solid #aaa;
    border-radius: 4px; /* Square/Rect for screens */
    font-size: 0.9rem;
    padding: 0; /* Remove padding to make them smaller/tighter around the T */
    width: calc(var(--token-size, 40px) * 0.8); /* Slightly smaller than regular tokens */
    height: calc(var(--token-size, 40px) * 0.8);
}

.token.cone {
    background-color: #f59e0b;
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
    border-radius: 0;
    width: calc(var(--token-size, 40px) * 0.75);
    height: calc(var(--token-size, 40px) * 0.75);
    /* clip-path hides borders, so we use multiple drop-shadow filters for a thicker "outline" effect */
    filter: drop-shadow(0 0 1.5px black) drop-shadow(0 0 1px black);
}

/* Ghost Token Styling overrides */
.token.ghost {
    border-style: dashed !important;
    box-shadow: none !important;
    background-image: none !important; /* Remove any pattern if added later */
}

/* Toast Notification */
#toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background-color: #333;
    color: #fff;
    padding: 10px 20px;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    font-size: 0.9rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    border-left: 4px solid var(--accent-color);
}

/* Modal Styling */

.modal {

    display: none; 

    position: fixed; 

    z-index: 3000; 

    left: 0;

    top: 0;

    width: 100%; 

    height: 100%; 

    overflow: auto; 

    background-color: rgba(0,0,0,0.8); 

    backdrop-filter: blur(5px);

}



/* Roster Page Styling */
#roster-view {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-color);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.roster-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #333;
}

.roster-header h1 {
    grid-column: 2;
    font-size: 1.5rem;
}

.roster-header button {
    justify-self: start;
    flex: initial;
}

.roster-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

.tab-btn {
    padding: 10px 30px;
    background: #333;
    border: 1px solid #555;
    color: #888;
    cursor: pointer;
    font-size: 1.1rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.roster-content {
    flex: 1;
    overflow-y: auto;
    max-width: 900px; /* Increased max-width */
    width: 100%;
    margin: 0 auto;
    background: #252525;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

/* Roster Editor Grid */
.roster-list-header {
    display: flex;
    gap: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #444;
    margin-bottom: 15px;
    font-weight: bold;
    color: #aaa;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
}

.roster-entry {
    display: flex;
    gap: 15px;
    margin-bottom: 10px;
    align-items: center;
}

.roster-entry input, 
.roster-entry select {
    background: #333;
    border: 1px solid transparent; /* Cleaner default look */
    color: white;
    padding: 10px;
    border-radius: 6px;
    transition: all 0.2s;
}

.roster-entry input:focus, 
.roster-entry select:focus {
    background: #222;
    border-color: var(--accent-color);
}

.roster-entry input:hover {
    background: #3a3a3a;
}

.roster-save-bar {
    margin-top: 25px;
    text-align: center;
    padding-top: 20px;
    border-top: 1px solid #333;
}

/* Roster Nav Pills */
.roster-view-nav {
    display: flex; 
    justify-content: center; 
    gap: 10px; 
    margin-bottom: 20px;
}

.nav-pill {
    background: transparent;
    border: 1px solid #555;
    color: #888;
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    font-weight: 600;
}

.nav-pill.active {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.nav-pill:hover {
    border-color: #777;
    color: #eee;
}

/* --- Games Manager UI --- */

/* Games List */
.game-item {
    background: #2a2a2a;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 5px solid var(--accent-color);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.2s, background 0.2s;
}

.game-item:hover {
    background: #333;
    transform: translateX(5px);
}

.game-info strong {
    display: block;
    font-size: 1.2rem;
    color: #fff;
    margin-bottom: 5px;
}

.game-date {
    font-size: 0.9rem;
    color: #999;
}

.game-actions {
    display: flex;
    gap: 10px;
}

/* Game Editor */
.editor-header {
    display: flex;
    gap: 20px;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #333;
}

.editor-header input {
    background: #1a1a1a;
    font-size: 1.1rem;
    padding: 12px;
}

.section-title {
    color: #888;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 15px;
    font-weight: bold;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}

/* New Lineup Cards Layout */
#starters-container {
    background: transparent;
    padding: 0;
    border: none;
    display: flex;
    flex-direction: row; /* Horizontal */
    gap: 15px;
    margin-bottom: 30px;
    overflow-x: auto; /* Allow scroll on small screens */
    padding-bottom: 10px; /* Space for scrollbar */
}

.lineup-card {
    flex: 1;
    min-width: 140px;
    background: #333;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.lineup-card:hover {
    border-color: var(--accent-color);
    background: #383838;
}

.card-label {
    font-size: 0.8rem;
    color: #888;
    font-weight: bold;
    text-transform: uppercase;
}

.card-select-wrapper {
    width: 100%;
}

.card-select-wrapper select {
    width: 100%;
    background: #222;
    border: 1px solid #555;
    padding: 8px;
    font-size: 0.9rem;
    text-align: center;
}

#bench-list {
    background: #1a1a1a;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
    min-height: 80px;
    max-height: 250px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}

.bench-player {
    background: #333;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.95rem;
    color: #ccc;
    border: 1px solid #444;
    text-align: center;
}

    border-color: #666;
    color: white;
}

/* --- Responsive Design (Mobile/Tablet) --- */
@media (max-width: 900px) {
    /* Stack Layout for Portrait/Small Screens */
    .app-container {
        flex-direction: column;
    }

    /* Move Sidebar to bottom */
    .sidebar {
        width: 100%;
        order: 2; /* Court first, controls second */
        height: 50vh; /* Take up bottom half */
        border-right: none;
        border-top: 1px solid #333;
        padding: 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom) + 20px); /* iOS Home Bar spacing */
    }

    .court-container {
        order: 1;
        height: 50vh; /* Top half */
        padding: 10px;
    }

    /* Adjust Roster View for Mobile */
    .roster-header {
        grid-template-columns: 1fr;
        gap: 10px;
        text-align: center;
    }

    .roster-header h1 {
        grid-column: 1;
        order: -1;
    }

    .roster-header button {
        justify-self: center;
        width: 100%;
    }

    /* Roster Entries wrapping */
    .roster-entry {
        flex-wrap: wrap;
        border-bottom: 1px solid #333;
        padding-bottom: 10px;
    }
    
    .roster-entry input[data-field="name"],
    .roster-entry input[data-field="notes"] {
        flex: 100%; /* Full width on mobile */
        margin-bottom: 5px;
    }
    
    .roster-list-header {
        display: none; /* Hide header labels on mobile, rely on placeholders */
    }

    /* Games List adjustments */
    #starters-container {
        flex-direction: column; /* Stack lineup cards */
        align-items: stretch;
    }
    
    .lineup-card {
        flex-direction: row;
        justify-content: space-between;
        padding: 10px;
    }
    
    .card-select-wrapper {
        width: 60%;
    }
}

/* Very Small Screens (e.g. landscape phones or short windows) */
@media (max-height: 500px) and (orientation: landscape) {
    .app-container {
        flex-direction: row; /* Keep side-by-side */
    }
    
    .sidebar {
        width: 200px;
        order: 0;
        height: 100%;
    }
    
    .court-container {
        height: 100%;
    }
}