/* =========================================
   VARIABLES & GLOBAL DESIGN TOKENS
   ========================================= */
:root {
    --bg-base: #000000;
    --bg-surface: #0a0a0a;
    --bg-surface-elevated: #121212;
    --bg-surface-hover: #1c1c1c;
    
    --border-subtle: #222222;
    --border-focus: #333333;
    
    --accent: #D9FD11; 
    --accent-hover: #e5ff4d;
    --accent-glow: rgba(217, 253, 17, 0.15);
    
    --danger: #ff3b30;
    --danger-bg: rgba(255, 59, 48, 0.1);
    
    --text-main: #f8f8f8;
    --text-dim: #8e8e93;
    
    --font-family: 'Poppins', sans-serif;
    
    /* HALVED BORDER RADIUS TOKENS */
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 4px;
    --shadow-card: 0 8px 30px rgba(0, 0, 0, 0.4);
    
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { 
    font-family: var(--font-family); 
    background-color: var(--bg-base); 
    color: var(--text-main); 
    display: flex; 
    flex-direction: column;
    height: 100vh; 
    overflow: hidden; 
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 800; letter-spacing: -0.02em; color: var(--text-main); }
.text-accent { color: var(--accent) !important; }
.text-danger { color: var(--danger) !important; }
.text-dim { color: var(--text-dim) !important; }
.text-center { text-align: center; }
.font-normal { font-weight: 400; }

.hidden { display: none !important; }
.desktop-only { display: block; }
.mobile-only { display: none; }
.mobile-header { display: none; }
.flex-row { display: flex; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.gap-10 { gap: 10px; }
.gap-15 { gap: 15px; }
.mt-10 { margin-top: 10px; }
.mt-15 { margin-top: 15px; }
.mt-20 { margin-top: 20px; }
.mt-25 { margin-top: 25px; }
.mb-10 { margin-bottom: 10px; }
.mb-15 { margin-bottom: 15px; }
.mb-20 { margin-bottom: 20px; }
.mb-25 { margin-bottom: 25px; }
.p-20 { padding: 20px; }
.align-center { align-items: center; }
.space-between { display: flex; justify-content: space-between; align-items: center; }
.no-padding { padding: 0 !important; }
.divider { border: 0; border-top: 1px solid var(--border-subtle); margin: 25px 0; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* AMBIENT BACKGROUND */
.ambient-background { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: -1; overflow: hidden; background: #000; }
.blob { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.5; animation: float 20s infinite ease-in-out alternate; }
.blob-1 { width: 50vw; height: 50vw; background: rgba(217, 253, 17, 0.05); top: -10%; left: -10%; }
.blob-2 { width: 40vw; height: 40vw; background: rgba(0, 229, 255, 0.05); bottom: -10%; right: -5%; animation-delay: -5s; }
.blob-3 { width: 30vw; height: 30vw; background: rgba(106, 0, 255, 0.05); top: 40%; left: 40%; animation-delay: -10s; }
@keyframes float { 0% { transform: translate(0, 0) scale(1); } 100% { transform: translate(50px, 50px) scale(1.1); } }

/* Gender Styling */
.gender-txt { font-weight: 800; font-size: 0.7rem; margin-right: 4px; }
.gender-M { color: #5ac8fa; }
.gender-F { color: #ff2d55; }

/* BUTTONS & INPUTS */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: var(--radius-sm); font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: all 0.2s ease; border: 1px solid transparent; }
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 24px; font-size: 1rem; font-weight: 700; border-radius: var(--radius-md); }
.btn-primary { background: var(--accent); color: #000; font-weight: 700; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--accent-glow); }
.btn-secondary { background: var(--bg-surface-elevated); color: var(--text-main); border-color: var(--border-subtle); }
.btn-secondary:hover { background: var(--border-subtle); }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border-subtle); }
.btn-ghost:hover { color: var(--text-main); background: var(--bg-surface-elevated); border-color: var(--text-dim); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border-color: rgba(255, 59, 48, 0.3); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-undo { background: rgba(255, 204, 0, 0.1); color: #ffcc00; }
.btn-undo:hover { background: #ffcc00; color: #000; }
.btn-tiny { background: var(--bg-surface-hover); color: var(--text-main); border: 1px solid var(--border-subtle); padding: 6px 10px; border-radius: 3px; font-size: 0.7rem; cursor: pointer; font-weight: 600; transition: 0.2s;}
.btn-tiny:hover { background: var(--border-focus); }
.btn-icon { background: var(--bg-surface-hover); color: var(--text-main); border: none; border-radius: 3px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-weight: 700;}
.btn-icon:hover { background: var(--border-focus); }

/* Password Toggle styling */
.password-wrapper { position: relative; width: 100%; }
.password-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
    transition: color 0.2s ease;
}
.password-toggle:hover { color: var(--text-main); }

/* Force inputs to 16px to prevent iOS Safari auto-zoom */
.input-group label { display: block; font-size: 0.75rem; color: var(--text-dim); margin-bottom: 8px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;}
.modal-input { width: 100%; background: var(--bg-base); border: 1px solid var(--border-subtle); color: var(--text-main); padding: 12px 16px; border-radius: var(--radius-sm); font-size: 16px; font-family: var(--font-family); transition: all 0.2s; appearance: none;}
.modal-input:focus { outline: none; border-color: var(--accent); background: var(--bg-surface); }
.modal-input::placeholder { color: #555; }
.select-wrapper { position: relative; }
.select-wrapper::after { content: '▼'; font-size: 0.7rem; color: var(--text-dim); position: absolute; right: 16px; top: 50%; transform: translateY(-50%); pointer-events: none; }

.badge { background: var(--bg-surface-hover); padding: 4px 10px; border-radius: 10px; font-size: 0.75rem; font-weight: 600; color: var(--text-dim); }
.rank-badge { font-size: 0.6rem; padding: 3px 6px; border-radius: 2px; font-weight: 800; color: #000; letter-spacing: 0.5px; }
.rank-BEG { background: #3498db; }
.rank-INT { background: #f1c40f; }
.rank-ADV { background: #e74c3c; }

/* APP LAYOUT & NAVIGATION */
.app-layout { display: flex; flex: 1; overflow: hidden; }
.sidebar { width: 250px; background: var(--bg-surface); border-right: 1px solid var(--border-subtle); display: flex; flex-direction: column; padding: 32px 0 24px 0; z-index: 10; }
.brand { font-size: 2rem; font-weight: 900; font-style: italic; letter-spacing: -1px; padding: 0 24px 32px; color: #fff;}
.brand span { color: var(--accent); }

.brand { font-size: 2rem; font-weight: 900; font-style: italic; letter-spacing: -1px; color: #fff; display: flex; align-items: center; }
.brand span { color: var(--accent); }

/* Desktop Sidebar Logo */
.sidebar .brand { padding: 0 24px 32px; justify-content: center; }
.sidebar .brand-logo { width: 100%; max-width: 180px; height: auto; object-fit: contain; display: block; margin: 0 auto; }

/* Mobile Header Logo */
.mobile-header .brand { justify-content: center; padding: 0; width: 100%; }
.mobile-header .brand-logo { height: 40px; width: auto; object-fit: contain; }

/* Login Screen Logo */
.splash-logo-img { height: 80px; width: auto; object-fit: contain; margin: 0 auto 15px; display: block; }

.brand-logo { height: 36px; width: auto; object-fit: contain; }
.splash-logo-img { height: 80px; width: auto; object-fit: contain; margin: 0 auto 15px; display: block; }

.nav-list { display: flex; flex-direction: column; gap: 4px; padding: 0 12px; }
.nav-item { padding: 12px 16px; display: flex; align-items: center; gap: 12px; color: var(--text-dim); cursor: pointer; font-size: 0.95rem; font-weight: 600; border-radius: var(--radius-sm); transition: all 0.2s ease;}
.nav-item:hover:not(.disabled) { color: var(--text-main); background: var(--bg-surface-hover); }
.nav-item.active { background: var(--border-subtle); color: var(--text-main); }
.nav-item.disabled { opacity: 0.5; cursor: not-allowed; }
.sidebar-bottom { margin-top: auto; padding: 0 12px; }
.nav-icon { font-size: 1.1rem; opacity: 0.8; }

.main-content { flex: 1; display: flex; flex-direction: column; padding: 0 40px 40px; overflow-y: auto; overflow-x: hidden; background: transparent; }
.view-section { display: flex; flex-direction: column; animation: fadeIn 0.3s ease-out forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.action-bar { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 24px 0; 
    margin-bottom: 24px; 
    border-bottom: 1px solid var(--border-subtle); 
    position: sticky; 
    top: 0; 
    background: rgba(0, 0, 0, 0.75); 
    backdrop-filter: blur(16px); 
    -webkit-backdrop-filter: blur(16px);
    z-index: 100;
    transition: all 0.3s ease;
}
.action-buttons { display: flex; gap: 12px; }

.global-timer-widget { display: flex; align-items: center; background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); padding: 6px 16px; gap: 16px; }
.gt-label { font-size: 0.7rem; font-weight: 700; color: var(--text-dim); letter-spacing: 1px; }
.gt-time { font-family: monospace; font-size: 1.4rem; font-weight: 800; color: var(--accent); min-width: 60px; text-align: center; }

.section-header { margin-bottom: 20px; }
.section-title { font-size: 1.5rem; color: #fff; }
.section-subtitle { font-size: 0.85rem; color: var(--text-dim); margin-top: 4px; }

/* PADDLE RACKS (QUEUE) */
.rack-container { display: flex; gap: 20px; height: 380px; margin-bottom: 32px; }
.rack { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; transition: border-color 0.2s; overflow: hidden; cursor: pointer;}
.rack.wide { flex: 1.5 1 0; }
.rack.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.rack-header { padding: 16px; border-bottom: 1px solid var(--border-subtle); display: flex; justify-content: space-between; align-items: center; background: var(--bg-surface-elevated);}
.rack-title { font-size: 0.95rem; font-weight: 700; color: #fff;}
.rack-subtitle { font-size: 0.7rem; color: var(--text-dim); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.rack-indicator { font-size: 0.65rem; font-weight: 800; background: var(--accent); color: #000; padding: 4px 8px; border-radius: 2px; }

.rack-body { flex: 1; display: flex; padding: 12px; background: var(--bg-base); overflow-y: auto; }
#rack-new { flex-direction: column; gap: 8px; }
.rack-column { flex: 1; border-right: 1px solid var(--border-subtle); padding: 0 8px; display: flex; flex-direction: column; min-width: 0; overflow-y: auto;}
.rack-column:last-child { border-right: none; }
.column-header { color: var(--text-dim); font-size: 0.7rem; font-weight: 700; margin-bottom: 12px; text-align: center; border-bottom: 1px solid var(--border-subtle); padding-bottom: 8px;}
.column-content { display: flex; flex-direction: column; gap: 8px; min-height: 100px; }

.player-pill { background: var(--bg-surface-elevated); border: 1px solid var(--border-subtle); padding: 10px 12px; border-radius: var(--radius-sm); border-left: 3px solid var(--border-focus); display: flex; justify-content: space-between; align-items: center; transition: all 0.2s;}
.player-pill:hover { background: var(--bg-surface-hover); border-color: var(--border-focus); }
.player-pill.on-deck { border-left-color: #555 !important; background: var(--bg-base); border-style: dashed; }
.player-pill.resting { opacity: 0.5; border-left-color: #555; background: repeating-linear-gradient(45deg, var(--bg-base), var(--bg-base) 10px, var(--bg-surface) 10px, var(--bg-surface) 20px); }
.player-list-row.resting { opacity: 0.6; }
.player-badge { font-size: 0.7rem; color: var(--text-dim); font-weight: 700; }

.drag-handle { 
    user-select: none; 
    color: #444; 
    cursor: grab; 
    font-size: 1.2rem; 
    padding: 10px; 
    margin-left: -10px; 
    margin-right: 2px;
    touch-action: none; /* Prevents the whole page from scrolling when you try to drag on mobile! */
}
.drag-handle:hover { color: #fff; }
.drag-handle:active { cursor: grabbing; }

/* The placeholder left behind while dragging */
.sortable-ghost { 
    opacity: 0.3 !important; 
    background: var(--bg-surface-elevated) !important; 
    border: 2px dashed var(--accent) !important; 
}

/* The actual card being dragged (Lifts it off the page) */
.sortable-drag { 
    cursor: grabbing !important; 
    box-shadow: 0 20px 40px rgba(0,0,0,0.8) !important; 
    transform: scale(1.03) rotate(1deg); 
    opacity: 1 !important; 
    z-index: 9999 !important;
    background: var(--bg-surface) !important;
    border-color: var(--border-focus) !important;
}

.sortable-swap-highlight { 
    background: rgba(217, 253, 17, 0.2) !important; 
    border: 2px solid var(--accent) !important; 
    transform: scale(1.02);
    transition: all 0.2s ease;
}

/* Dynamic Stale Indicators */
.wait-time-display { font-size: 0.65rem; font-weight: 600; color: var(--text-dim); background: var(--bg-base); padding: 2px 6px; border-radius: 2px; margin-left: 8px;}
.stale-glow { border-left-color: var(--danger) !important; background: var(--danger-bg); }
.stale-glow .wait-time-display { color: var(--danger); background: transparent; padding: 0;}

/* Queue Themes */
.theme-rotate #rack-card-winners, .theme-rotate #rack-card-losers { display: none !important; }
.theme-rotate #rack-card-new.active { border-color: #3b82f6; box-shadow: 0 0 0 1px #3b82f6;}
.theme-winners_stay #rack-card-losers { display: none !important; }

/* PREVIEW & COURTS */
.preview-box { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); overflow: hidden; margin-bottom: 32px; }
.preview-header { padding: 16px 20px; border-bottom: 1px solid var(--border-subtle); display: flex; justify-content: space-between; align-items: center; background: var(--bg-surface-elevated);}
.preview-title { font-weight: 700; color: #fff; }
.preview-actions { display: flex; gap: 12px; }
.preview-content { padding: 20px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; min-height: 90px; background: var(--bg-base);}

/* Sleek Live Court Cards */
.courts-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; padding-bottom: 32px;}
.court-card { background: linear-gradient(180deg, var(--bg-surface) 0%, #050505 100%); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 20px; display: flex; flex-direction: column; transition: all 0.3s ease; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.court-card:hover { border-color: var(--border-focus); transform: translateY(-2px); }

.court-header { display: flex; justify-content: space-between; border-bottom: 1px solid var(--border-subtle); padding-bottom: 16px; margin-bottom: 16px; align-items: center;}
.court-header span:first-child { font-weight: 800; font-size: 1.1rem; letter-spacing: -0.5px;}

/* Glowing Status Badges */
.court-status { font-size: 0.65rem; padding: 5px 10px; border-radius: 4px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; background: var(--bg-surface-elevated); color: var(--text-dim); border: 1px solid var(--border-subtle);}
.court-status.active { background: rgba(217, 253, 17, 0.1); color: var(--accent); border-color: rgba(217, 253, 17, 0.3); box-shadow: 0 0 10px rgba(217, 253, 17, 0.15); }

/* Recessed Team Matchup Blocks */
.active-match-row { display: flex; justify-content: center; align-items: center; gap: 12px; width: 100%; margin-bottom: 24px;}
.team-block { display: flex; flex-direction: column; align-items: center; font-size: 0.9rem; font-weight: 600; background: rgba(255,255,255,0.02); padding: 16px 12px; border-radius: var(--radius-md); flex: 1; border: 1px solid var(--border-subtle); gap: 4px; box-shadow: inset 0 2px 10px rgba(0,0,0,0.2);}
.team-label { font-size: 0.6rem; color: var(--text-dim); font-weight: 800; margin-bottom: 4px; letter-spacing: 1px;}
.vs-badge { font-weight: 900; font-size: 0.8rem; color: var(--text-dim); font-style: italic; opacity: 0.6;}
/* DASHBOARD PANELS & STATS */
.dash-panel { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 24px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); }
.panel-header { padding: 18px 24px; border-bottom: 1px solid var(--border-subtle); background: linear-gradient(to right, var(--bg-surface-elevated), var(--bg-surface));}
.panel-header h3 { font-size: 1.15rem; color: #fff; letter-spacing: 0.5px; }
.panel-body { padding: 24px; }

/* Elevated Session Card */
.session-info-card { display: flex; flex-wrap: wrap; gap: 24px; background: linear-gradient(135deg, var(--bg-surface) 0%, #0d0d0d 100%); border: 1px solid var(--border-subtle); border-top: 2px solid var(--border-focus); border-radius: var(--radius-lg); padding: 24px; margin-bottom: 24px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.info-item { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 120px;}
.info-label { font-size: 0.65rem; font-weight: 800; color: var(--text-dim); letter-spacing: 1px; text-transform: uppercase; }
.info-value { font-size: 1.15rem; color: #fff; font-weight: 700; letter-spacing: -0.5px;}

/* Modern Stat Cards */
.dash-stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; margin-bottom: 24px;}
.stat-card { background: linear-gradient(145deg, var(--bg-surface) 0%, #0a0a0a 100%); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); padding: 24px; display: flex; align-items: center; gap: 18px; transition: all 0.3s ease; box-shadow: 0 6px 20px rgba(0,0,0,0.3); }
.stat-card:hover { transform: translateY(-4px); border-color: var(--border-focus); box-shadow: 0 12px 30px rgba(0,0,0,0.6); }

/* Squircle App Icons for Stats */
.stat-icon { font-size: 1.8rem; background: rgba(255,255,255,0.03); width: 60px; height: 60px; border-radius: 16px; display: flex; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,0.05); box-shadow: inset 0 4px 10px rgba(0,0,0,0.3); }
.stat-content { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 0.7rem; color: var(--text-dim); font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 1.5rem; font-weight: 900; color: #fff; letter-spacing: -0.5px; }

/* Logic Engine Selectors */
.logic-selector { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.logic-option { display: flex; gap: 16px; padding: 20px; background: rgba(255,255,255,0.02); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); cursor: pointer; transition: all 0.2s; box-shadow: inset 0 2px 10px rgba(0,0,0,0.2); }
.logic-option:hover { border-color: #444; background: rgba(255,255,255,0.04); }
.logic-option.active { border-color: var(--accent); background: linear-gradient(135deg, rgba(217, 253, 17, 0.08) 0%, rgba(217, 253, 17, 0.01) 100%); box-shadow: 0 0 15px rgba(217, 253, 17, 0.1); }
.logic-icon { font-size: 1.5rem; }
.logic-title { font-weight: 700; color: #fff; margin-bottom: 4px; font-size: 0.95rem;}
.logic-desc { font-size: 0.8rem; color: var(--text-dim); line-height: 1.4;}

/* =========================================
   MATCH HISTORY DROPDOWN
   ========================================= */
.match-history-row { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; border-bottom: 1px solid var(--border-subtle); transition: background 0.2s; }
.match-history-row:last-child { border-bottom: none; }
.match-history-row:hover { background: var(--bg-surface-hover); }
.match-team { font-size: 0.9rem; font-weight: 600; margin-bottom: 2px; }
.match-court-badge { font-size: 0.65rem; background: var(--border-subtle); padding: 3px 6px; border-radius: 4px; color: var(--text-dim); font-weight: 800; letter-spacing: 0.5px; }
.match-score-display { font-size: 1.2rem; font-weight: 800; color: var(--accent); font-family: monospace; }

/* LISTS & LEADERBOARD (TABLE STYLES) */
.tabs { display: flex; background: var(--bg-base); padding: 4px; border-radius: var(--radius-sm); border: 1px solid var(--border-subtle);}
.tab { flex: 1; padding: 8px 16px; border: none; background: transparent; color: var(--text-dim); font-size: 0.85rem; font-weight: 600; border-radius: 2px; cursor: pointer; transition: 0.2s;}
.tab.active { background: var(--bg-surface-elevated); color: #fff; box-shadow: var(--shadow-sm); }

.toolbar { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.search-box { flex: 2; position: relative; min-width: 250px;}
.search-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 0.9rem; opacity: 0.5;}
.search-input { padding-left: 40px !important; }
.toolbar-select { flex: 1; min-width: 200px; }

.list-header { display: flex; padding: 12px 24px; background: var(--bg-surface-elevated); font-size: 0.7rem; color: var(--text-dim); font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid var(--border-subtle); }
.player-list-row, .lb-row { display: flex; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--border-subtle); transition: background 0.2s; }
.player-list-row:last-child, .lb-row:last-child { border-bottom: none; }
.player-list-row:hover, .lb-row:hover { background: var(--bg-base); }

/* Dashboard Roster Specifics */
.p-info { display: flex; align-items: center; gap: 12px; flex: 1; font-weight: 600; }
.p-name { color: #fff; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;}
.status-badge { font-size: 0.7rem; font-weight: 700; padding: 4px 8px; border-radius: 2px; background: var(--bg-base); color: var(--text-dim); border: 1px solid var(--border-subtle);}
.status-badge.playing { color: var(--accent); border-color: rgba(217, 253, 17, 0.3); background: rgba(217, 253, 17, 0.05); }
.status-badge.stale { color: var(--danger); border-color: rgba(255, 59, 48, 0.3); background: var(--danger-bg); }
.p-stats { display: flex; gap: 5px; margin-right: 5px; }
.stat-pill { font-size: 0.65rem; padding: 4px 8px; border-radius: 2px; font-weight: 900; }
.win-pill { background: rgba(204, 255, 0, 0.15); color: var(--accent); border: 1px solid var(--accent); }
.loss-pill { background: rgba(255, 51, 51, 0.15); color: var(--danger); border: 1px solid var(--danger); }

/* Leaderboard Specifics */
.lb-col-rank { width: 40px; font-weight: 800; color: var(--text-dim); }
.lb-col-name { flex: 1; font-weight: 700; color: #fff; font-size: 0.95rem; display: flex; align-items: center; gap: 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lb-col-stat { width: 80px; text-align: center; font-weight: 600; font-size: 0.9rem;}
.win-rate-badge { background: var(--bg-base); border: 1px solid var(--border-subtle); padding: 4px 8px; border-radius: 4px; font-size: 0.75rem; font-weight: 700;}
.win-rate-high { border-color: var(--accent); color: var(--accent); }

/* =========================================
   ARCHIVE ACCORDION
   ========================================= */
.archive-row { 
    border: 1px solid var(--border-subtle); 
    border-radius: var(--radius-sm); 
    margin-bottom: 12px; 
    background: var(--bg-surface); 
    overflow: hidden; 
    transition: border-color 0.2s;
}
.archive-row:hover { 
    border-color: var(--border-focus); 
}
.archive-header { 
    display: flex; 
    padding: 16px 20px; 
    cursor: pointer; 
    align-items: center; 
    background: var(--bg-surface); 
    transition: background 0.2s; 
    user-select: none;
}
.archive-header:hover { 
    background: var(--bg-surface-hover); 
}
.archive-body { 
    max-height: 0; 
    opacity: 0; 
    overflow: hidden; 
    padding: 0 20px; 
    border-top: 1px solid transparent; 
    background: var(--bg-base); 
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.archive-body.open { 
    max-height: 1500px; 
    opacity: 1; 
    padding: 20px 20px; 
    margin-top: 5px; 
    border-top-color: var(--border-subtle); 
}
.archive-stat-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); 
    gap: 16px; 
}
.archive-players { 
    font-size: 0.85rem; 
    color: #fff; 
    line-height: 1.6; 
    background: var(--bg-surface); 
    padding: 12px; 
    border-radius: var(--radius-sm); 
    border: 1px solid var(--border-subtle);
}

/* MODALS & SPLASH SCREEN */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 20px; animation: fadeIn 0.2s ease;}
.modal-card { background: var(--bg-surface); border: 1px solid var(--border-subtle); padding: 32px; border-radius: var(--radius-lg); width: 100%; max-width: 440px; box-shadow: var(--shadow-card); }
.modal-title { font-size: 1.4rem; margin-bottom: 8px; }
.modal-desc { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 24px; line-height: 1.5;}
.modal-actions { display: flex; gap: 12px; }

.score-buttons { display: flex; gap: 16px; margin-bottom: 24px; }
.btn-score { flex: 1; padding: 24px 16px; display: flex; flex-direction: column; align-items: center; background: var(--bg-base); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); cursor: pointer; transition: 0.2s;}
.btn-score:hover { border-color: var(--accent); background: rgba(217, 253, 17, 0.05);}
.team-badge { font-size: 0.65rem; font-weight: 800; color: var(--text-dim); letter-spacing: 1px; margin-bottom: 8px;}
.btn-score strong { font-size: 1.1rem; color: #fff; }
.score-divider { display: flex; align-items: center; font-weight: 900; color: var(--border-focus); font-size: 0.9rem; font-style: italic;}

.splash-screen { position: fixed; inset:0; background: var(--bg-base); z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 20px; }
.splash-card { width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; background: var(--bg-surface); border: 1px solid var(--border-subtle); padding: 40px; border-radius: var(--radius-lg); box-shadow: var(--shadow-card);}
.splash-logo { font-size: 2.5rem; font-weight: 900; font-style: italic; letter-spacing: -1px; margin-bottom: 4px; text-align: center; }
.splash-subtitle { color: var(--text-dim); margin-bottom: 32px; text-align: center; }
.splash-input-group { text-align: left; margin-bottom: 18px;}

.setup-player-list { max-height: 120px; overflow-y: auto; background: var(--bg-base); border: 1px solid var(--border-subtle); border-radius: 4px; padding: 5px; }

.end-title { font-size: 2rem; font-style: italic; font-weight: 900; margin-bottom: 8px; }
.end-stat-box { padding: 24px; border-radius: var(--radius-md); margin-bottom: 16px; background: var(--bg-base); border: 1px solid var(--border-subtle); }
.mvp-box { border-color: rgba(217, 253, 17, 0.3); background: rgba(217, 253, 17, 0.05); }
.ironman-box { margin-bottom: 30px; }
.end-stat-title { font-size: 0.75rem; font-weight: 800; letter-spacing: 1px; color: var(--text-dim); }
.mvp-box .end-stat-title { color: var(--accent); }
.end-stat-name { font-size: 1.8rem; font-weight: 800; color: #fff; margin-top: 8px; }
.end-stat-desc { font-size: 0.85rem; color: var(--text-dim); margin-top: 4px; }

/* =========================================
   RESPONSIVE DESIGN (MOBILE OPTIMIZATION)
   ========================================= */
@media (min-width: 800px) {
    .leaderboard-header, .lb-row { grid-template-columns: 40px 1fr 80px 60px 60px 60px 80px; gap: 15px; }
}

@media (max-width: 800px) {
    body { flex-direction: column; }
    .desktop-only { display: none !important; }
    .mobile-only { display: inline-block; }
    
    /* Sticky Top Header */
    .mobile-header { display: block !important; background: rgba(10, 10, 10, 0.8); backdrop-filter: blur(16px); padding: 16px 20px; border-bottom: 1px solid var(--border-subtle); text-align: center; position: sticky; top: 0; z-index: 50; }
    .mobile-header .brand { font-size: 1.5rem; margin: 0; padding: 0; }

    .app-layout { flex-direction: column; }
    
    /* Bottom Navigation Bar */
    .sidebar { position: fixed; bottom: 0; left: 0; width: 100%; height: calc(65px + var(--safe-bottom)); flex-direction: row; justify-content: space-around; padding: 0; padding-bottom: var(--safe-bottom); border-top: 1px solid var(--border-subtle); border-right: none; z-index: 999; background: rgba(10, 10, 10, 0.95); backdrop-filter: blur(10px); }
    .nav-list { flex-direction: row; width: 100%; padding: 0;}
    .nav-item { flex: 1; flex-direction: column; justify-content: center; gap: 4px; padding: 8px 4px; font-size: 0.65rem; border-radius: 0; border-right: none !important; }
    .nav-item.active { background: transparent; color: var(--accent); }
    .nav-item.active .nav-icon { color: var(--accent); transform: translateY(-2px); transition: 0.2s; }
    .nav-icon { display: block; font-size: 1.2rem; margin-bottom: 2px;}

    .main-content { padding: 12px; padding-bottom: calc(100px + var(--safe-bottom)); }
    
    /* Scrollable Horizontal Action Bar */
    .action-bar { flex-direction: column; align-items: stretch; gap: 12px; padding: 12px 0; position: static; background: transparent;}
    .global-timer-widget { justify-content: space-between; padding: 12px; }
    .action-buttons { display: flex; overflow-x: auto; gap: 10px; padding-bottom: 5px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .action-buttons::-webkit-scrollbar { display: none; }
    .action-buttons .btn { flex: 0 0 auto; white-space: nowrap; font-size: 0.85rem; padding: 10px 16px; }
    
    /* Queue Swipe Layout */
    .rack-container { overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; gap: 12px; padding-bottom: 12px; height: 400px; margin-right: -12px; padding-right: 12px;}
    .rack { flex: 0 0 88vw; min-width: 88vw; scroll-snap-align: center; }
    .rack.wide { flex: 0 0 88vw; min-width: 88vw; }
    
    .courts-container, .dash-stats-grid, .session-info-card, .logic-selector { grid-template-columns: 1fr; gap: 12px; }
    .info-item { padding-bottom: 12px; border-bottom: 1px solid var(--border-subtle); }
    .info-item:last-child { border-bottom: none; padding-bottom: 0;}
    
    /* Mobile Tables & Lists */
    .list-header { display: none !important; }
    .player-list-row, .lb-row { flex-wrap: wrap; gap: 10px; padding: 16px; border-radius: var(--radius-md); border: 1px solid var(--border-subtle); background: var(--bg-surface); margin-bottom: 10px;}
    .player-list-row > div:nth-child(2), .lb-row > div:nth-child(2) { width: 100% !important; order: -1; margin-bottom: 4px; font-size: 1.1rem;}
    .player-list-row > div:nth-child(3), .player-list-row > div:nth-child(4) { width: auto !important; text-align: left !important; }
    .player-list-row > div:nth-child(5) { width: 100% !important; justify-content: flex-start !important; margin-top: 8px; border-top: 1px solid var(--border-subtle); padding-top: 12px;}
    
    .lb-col-rank { width: auto; font-size: 0.8rem; background: var(--border-subtle); padding: 4px 8px; border-radius: 3px;}
    .lb-col-stat { width: auto; font-size: 0.8rem; }

    /* Native Bottom-Sheet Modals */
    .modal { align-items: flex-end; padding: 0; }
    .modal-card { 
        border-radius: 12px 12px 0 0; 
        margin: 0; 
        max-width: 100%; 
        max-height: 85vh; 
        overflow-y: auto;
        border-left: none; 
        border-right: none; 
        border-bottom: none;
        padding: 24px 20px calc(40px + var(--safe-bottom)); 
        animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }
    @keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

    /* Force 16px on inputs to prevent iOS Safari auto-zoom */
    .modal-input, select { font-size: 16px !important; }
}

/* =========================================
   SMOOTH COLLAPSE UTILITY
   ========================================= */
.collapsible {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.collapsible.open {
    max-height: 2000px; /* Expands to fit dynamic content */
    opacity: 1;
}

/* =========================================
   LIGHT MODE THEME OVERRIDES (HIGH CONTRAST)
   ========================================= */
[data-theme="light"] {
    --bg-base: #f4f4f5; /* A soft, premium light gray */
    --bg-surface: #ffffff; /* Pure white cards */
    --bg-surface-elevated: #e4e4e7;
    --bg-surface-hover: #f4f4f5;
    --border-subtle: #d4d4d8; /* Darker borders for crisp lines */
    --border-focus: #a1a1aa;
    --text-main: #18181b; /* Near black for maximum readability */
    --text-dim: #71717a; /* Clean dark gray */
    --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.08);
    --accent: #000000; /* Switches main accent to Black */
    --accent-hover: #333333;
}

/* 1. Universal Text & Icon Colors */
[data-theme="light"] .brand,
[data-theme="light"] .section-title,
[data-theme="light"] .rack-title,
[data-theme="light"] .card-label,
[data-theme="light"] .info-value,
[data-theme="light"] .stat-value,
[data-theme="light"] .logic-title,
[data-theme="light"] .timer,
[data-theme="light"] .p-name,
[data-theme="light"] .match-team,
[data-theme="light"] .archive-players,
[data-theme="light"] .end-stat-name,
[data-theme="light"] .preview-title,
[data-theme="light"] .nav-text {
    color: var(--text-main);
}

/* 2. Primary Buttons (Black background, Neon Yellow Text) */
[data-theme="light"] .btn-primary { 
    background: #18181b; 
    color: #D9FD11; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.15); 
}
[data-theme="light"] .btn-primary:hover { 
    background: #000000; 
    transform: translateY(-2px); 
}

/* 3. Secondary & Utility Buttons */
[data-theme="light"] .btn-secondary,
[data-theme="light"] .btn-tiny,
[data-theme="light"] .btn-icon,
[data-theme="light"] .team-block { 
    background: #ffffff; 
    border-color: #d4d4d8; 
    color: #18181b; 
}
[data-theme="light"] .btn-secondary:hover,
[data-theme="light"] .btn-tiny:hover,
[data-theme="light"] .btn-icon:hover { 
    background: #f4f4f5; 
}

/* 4. Backgrounds & Navigation */
[data-theme="light"] .ambient-background { background: #f4f4f5; }
[data-theme="light"] .blob { opacity: 0.15; } /* Tones down the ambient blobs */
[data-theme="light"] .sidebar { background: #f4f4f5; border-right-color: #d4d4d8; }
[data-theme="light"] .mobile-header,
[data-theme="light"] .action-bar { 
    background: rgba(255, 255, 255, 0.85); 
    border-bottom-color: #d4d4d8; 
}

/* 5. Inputs & Modals */
[data-theme="light"] .modal { background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(8px); }
[data-theme="light"] .modal-card { background: #ffffff; border-color: #d4d4d8; }
[data-theme="light"] .modal-input { background: #ffffff; border-color: #d4d4d8; color: #18181b; }
[data-theme="light"] .modal-input:focus { border-color: #000; box-shadow: 0 0 0 1px #000; }

/* 6. Win/Loss Badges */
[data-theme="light"] .win-pill { background: #dcfce7; color: #16a34a; border-color: #16a34a; }
[data-theme="light"] .loss-pill { background: #fee2e2; color: #dc2626; border-color: #dc2626; }
[data-theme="light"] .status-badge.live { background: #000; color: #D9FD11; }
[data-theme="light"] .status-badge.waiting { background: #d97706; color: #fff; }

/* 7. Logos */
[data-theme="light"] .brand-logo, 
[data-theme="light"] .splash-logo-img { 
    filter: invert(1); /* Turns white SVG logos to black */
}

/* ========================================================
   8. MAGIC OVERRIDES (Fixes Javascript injected colors) 
   ======================================================== */
[data-theme="light"] *[style*="color: #fff"], 
[data-theme="light"] *[style*="color:#fff"] { 
    color: #18181b !important; 
}

/* Convert unreadable Cyan to deep Royal Blue */
[data-theme="light"] *[style*="color:#00e5ff"],
[data-theme="light"] *[style*="color: #00e5ff"] { color: #0284c7 !important; }
[data-theme="light"] *[style*="border-color:#00e5ff"] { border-color: #0284c7 !important; }
[data-theme="light"] *[style*="background:rgba(0,229,255,0.1)"] { background: rgba(2, 132, 199, 0.1) !important; }

/* Convert light Orange to high-contrast Dark Orange */
[data-theme="light"] *[style*="color:orange"],
[data-theme="light"] *[style*="color: orange"] { color: #d97706 !important; }
[data-theme="light"] *[style*="border-color:orange"] { border-color: #d97706 !important; }

/* =========================================
   TOURNAMENT BRACKET ENGINE
   ========================================= */
.bracket-wrapper { 
    display: flex; 
    flex-direction: row; 
    align-items: stretch; 
    overflow-x: auto; 
    padding: 20px 40px 60px 40px; 
    gap: 60px; 
    background: var(--bg-surface); 
    border-radius: var(--radius-md); 
    border: 1px solid var(--border-subtle); 
    min-height: 500px;
    position: relative;
}
.bracket-round { 
    display: flex; 
    flex-direction: column; 
    justify-content: space-around; 
    flex: 1; 
    min-width: 250px; 
    position: relative; 
}
.bracket-round-title { 
    text-align: center; 
    font-size: 0.8rem; 
    font-weight: 800; 
    color: var(--text-dim); 
    text-transform: uppercase; 
    letter-spacing: 2px; 
    margin-bottom: 20px; 
    position: absolute;
    top: -10px;
    width: 100%;
}
.bracket-match { 
    background: var(--bg-base); 
    border: 1px solid var(--border-subtle); 
    border-radius: var(--radius-sm); 
    margin: 15px 0; 
    overflow: hidden; 
    cursor: pointer; 
    transition: all 0.2s ease; 
    position: relative; 
    z-index: 2; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}
.bracket-match:hover { 
    border-color: var(--accent); 
    box-shadow: 0 0 15px rgba(217, 253, 17, 0.15); 
    transform: translateY(-2px);
}
.bracket-match.completed { opacity: 0.8; }
.bracket-match.completed:hover { opacity: 1; border-color: var(--text-dim); box-shadow: none; transform: none;}

.bracket-team { 
    padding: 12px 16px; 
    font-weight: 600; 
    font-size: 0.9rem; 
    color: #fff; 
    border-bottom: 1px solid var(--border-subtle); 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
}
.bracket-team:last-child { border-bottom: none; }

/* Visual States for Advancing */
.bracket-team.winner { color: var(--accent); background: rgba(217, 253, 17, 0.05); }
.bracket-team.loser { color: var(--text-dim); text-decoration: line-through; opacity: 0.6;}
.b-score { font-family: monospace; font-weight: 900; font-size: 1.2rem; }

/* CSS connecting lines pointing to the right */
.bracket-round:not(:last-child) .bracket-match::after {
    content: ''; 
    position: absolute; 
    right: -30px; 
    top: 50%; 
    width: 30px; 
    height: 2px; 
    background: var(--border-subtle);
    z-index: 0;
}

/* =========================================
   INTERACTIVE DUPR TOGGLE
   ========================================= */
.dupr-toggle { 
    cursor: pointer; 
    transition: all 0.2s ease; 
    user-select: none; 
    border: 1px solid transparent; 
    background: transparent; 
    padding: 3px 8px; 
    font-size: 0.65rem; 
    border-radius: 4px; 
    font-weight: 800; 
    letter-spacing: 0.5px; 
    display: inline-flex;
    align-items: center;
}
.dupr-toggle:active { transform: scale(0.95); }
.dupr-pending { background: rgba(245, 158, 11, 0.1); color: #f59e0b; border-color: #f59e0b; }
.dupr-recorded { background: rgba(34, 197, 94, 0.1); color: #22c55e; border-color: #22c55e; }

/* MULTI-SELECT UPGRADE */
.db-selectable-row {
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    border-left: 4px solid transparent !important;
}

.db-selectable-row:hover {
    background: var(--bg-surface-hover) !important;
}

.db-selectable-row {
    transition: all 0.2s ease;
    position: relative;
    border-left: 4px solid transparent !important;
    cursor: default; /* Change from pointer to default */
}

.db-select-indicator {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-subtle);
    border-radius: 4px;
    margin-right: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
    cursor: pointer; /* Ensure only the box shows the hand icon */
}

.selected .db-select-indicator {
    background: var(--accent);
    border-color: var(--accent);
}

.selected .db-select-indicator::after {
    content: '✓';
    color: #000;
    font-size: 12px;
    font-weight: 900;
}

/* FIX SEARCH ICON DRIFT */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 16px;
    pointer-events: none; /* Ensures clicking the icon still focuses the input */
}

.search-input {
    width: 100%;
    padding-left: 45px !important;
}

/* GLOBAL SVG ICON STYLING */
.nav-icon svg, .btn-icon svg {
    display: inline-block;
    vertical-align: middle;
    transition: stroke 0.2s ease;
}

/* Active Nav State colors the SVG */
.nav-item.active .nav-icon svg {
    stroke: var(--accent);
}