/* Google Fonts Imports */
@font-face { font-family: 'Roboto'; src: url('/static/fonts/Roboto-Light.ttf') format('truetype'); font-weight: 300; font-style: normal; }
@font-face { font-family: 'Roboto'; src: url('/static/fonts/Roboto-Regular.ttf') format('truetype'); font-weight: 400; font-style: normal; }
@font-face { font-family: 'Roboto'; src: url('/static/fonts/Roboto-Bold.ttf') format('truetype'); font-weight: 700; font-style: normal; }
@font-face { font-family: 'Playfair Display'; src: url('/static/fonts/PlayfairDisplay-Bold.ttf') format('truetype'); font-weight: 700; font-style: normal; }
@font-face { font-family: 'Cinzel Decorative'; src: url('/static/fonts/CinzelDecorative-Bold.ttf') format('truetype'); font-weight: 700; font-style: normal; }

/* Color Palette & Variables */
:root {
    --color-dark-bg: #1A1A1A;
    --color-card-bg: rgba(30, 30, 30, 0.85);
    --color-card-bg-gradient: linear-gradient(180deg, rgba(40, 40, 40, 0.88), rgba(25, 25, 25, 0.88));
    --color-text-light: #E5E5E5;
    --color-text-accent: #FFD700;
    --color-border: rgba(255, 255, 255, 0.1);
    --color-border-subtle: rgba(255, 255, 255, 0.07);
    --color-shadow-dark: rgba(0, 0, 0, 0.5);
    --shadow-elegant: 0 4px 12px rgba(0,0,0,0.4), 0 10px 30px rgba(0,0,0,0.3);

    --color-button-primary: linear-gradient(145deg, #4a2c00, #6b4400);
    --color-button-primary-hover: linear-gradient(145deg, #6b4400, #8c5c00);
    --color-button-secondary: linear-gradient(145deg, #0056b3, #007bff);
    --color-button-secondary-hover: linear-gradient(145deg, #004085, #0056b3);
    --color-button-success: linear-gradient(145deg, #1e8449, #28a745);
    --color-button-success-hover: linear-gradient(145deg, #155d33, #1e8449);

    --control-height: 44px;
    --radius-m: 12px;
    --radius-s: 8px;
}

/* Base Styles */
html { box-sizing: border-box; background-color: transparent; scroll-behavior: smooth; }
body { font-family: 'Roboto', sans-serif; color: var(--color-text-light); margin: 0; padding: 0; min-height: 100vh; text-shadow: 1px 1px 3px var(--color-shadow-dark); line-height: 1.7; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; padding: 0; height: 100%; background: none; background-color: transparent; }

/* Utility helpers */
.is-hidden { display: none !important; }
.inline-flex { display: inline-flex; }
.flex-row-center { display: flex; align-items: center; gap: 16px; }
.flex-column { display: flex; flex-direction: column; }
.gap-12 { gap: 12px; }
.text-center { text-align: center; }
.text-accent { color: var(--color-text-accent); }
.text-dim { opacity: 0.2; }
.text-subtle { opacity: 0.4; margin-left: 4px; }
.text-xs { font-size: 0.8rem; }
.stat-strong { color: var(--color-text-light); font-weight: 700; }
.th-subtle { font-weight: 400; opacity: 0.6; font-size: 0.85em; }
.btn-block { width: 100%; }
.panel.panel-ghost { background: transparent; border: none; box-shadow: none; border-radius: 0; }
.ledger-title-area-wide { width: 100%; display: flex; justify-content: space-between; align-items: center; }
.ledger-content { padding: 0; }
.ledger-content--flush { padding: 0; }
.section-title-small { margin: 0; font-family: 'Playfair Display', serif; color: var(--color-text-accent); font-size: 1.5rem; }
.section-spacer { margin-bottom: 40px; }
.panel-padding { padding: 24px; }
.help-text--compact { font-size: 0.85em; opacity: 0.7; margin-top: 6px; }
.checkbox-card--highlight { width: 100%; justify-content: center; background: rgba(255,215,0,0.05); border-color: var(--color-text-accent); }
.checkbox-card__title { font-weight: 700; font-size: 1.1em; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.flex-1 { flex: 1; }
.color-input { width: 40px; padding: 0; border: none; height: 38px; }
.section-divider { margin-top: 24px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 16px; }
.heading-tight { margin: 0 0 12px 0; }
.ledger-footer--center { justify-content: center; }
.scroll-panel { max-height: 300px; overflow-y: auto; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mt-40 { margin-top: 40px; }

.btn-start-season { min-width: auto; height: 32px; padding: 0 12px; font-size: 0.8rem; }

.background-blur-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-image: url('/static/img/dark_wood_texture.jpg'); background-size: 45% auto; background-repeat: repeat; z-index: -1; backdrop-filter: blur(0px); transition: backdrop-filter 0.1s ease-out; }
.main-content-wrapper { position: relative; z-index: 1; width: 100%; min-height: 100vh; display: flex; flex-direction: column; align-items: center; background-color: transparent; }

/* Header Section */
.app-header {
    --parallax-x: 0px; --parallax-y: 0px; --parallax-tilt-x: 0deg; --parallax-tilt-y: 0deg; --parallax-bleed-x: 8%; --parallax-bleed-y: 14%;
    background-image: url('/static/img/header_background.jpg'); background-color: black; background-size: cover; background-repeat: no-repeat;
    background-position: calc(50% - (var(--parallax-x) * 0.42)) calc(50% - (var(--parallax-y) * 0.42));
    padding: 25px 0; width: 100%; text-align: center; border-bottom: 1px solid var(--color-border);
    box-shadow: 0 5px 20px var(--color-shadow-dark); margin-bottom: 40px;
    animation: background-sine-move 20s infinite ease-in-out alternate; position: relative; overflow: hidden; transition: background-position 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.app-header::after { content: ''; position: absolute; top: calc(var(--parallax-bleed-y) * -1); left: calc(var(--parallax-bleed-x) * -1); width: calc(100% + (var(--parallax-bleed-x) * 2)); height: calc(100% + (var(--parallax-bleed-y) * 2)); background-image: url('/static/img/header_background_overlay.png'); background-size: cover; background-position: center; z-index: 2; pointer-events: none; transform-origin: center; transform: translate3d(calc(var(--parallax-x) * -0.30), calc(var(--parallax-y) * -0.30), 0) scale(1.02); transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: transform; }
.app-header::before { content: ''; position: absolute; top: calc(var(--parallax-bleed-y) * -1); left: calc(var(--parallax-bleed-x) * -1); width: calc(100% + (var(--parallax-bleed-x) * 2)); height: calc(100% + (var(--parallax-bleed-y) * 2)); background: linear-gradient(to right, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 20%, rgba(0,0,0,0) 80%, rgba(0,0,0,1) 100%); z-index: 0; pointer-events: none; transform-origin: center; transform: translate3d(calc(var(--parallax-x) * -0.18), calc(var(--parallax-y) * -0.18), 0) scale(1.02); transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: transform; }
.header-logo-container { display: flex; align-items: flex-end; justify-content: center; padding: 10px 20px; width: 100%; position: relative; z-index: 3; transform: translate3d(calc(var(--parallax-x) * 0.18), calc(var(--parallax-y) * 0.2), 0); transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1); will-change: transform; }
.app-logo { --logo-scale: 1; --logo-offset-y: 22px; max-width: 350px; height: auto; transition: transform 0.35s ease; z-index: 9; flex-shrink: 0; animation: logo-oscillation 20s infinite ease-in-out alternate; transform-origin: center; transform: translate3d(calc(var(--parallax-x) * 0.14), calc(var(--parallax-y) * 0.16 + var(--logo-offset-y)), 0) scale(var(--logo-scale)); will-change: transform; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.app-title-image { height: clamp(3.5rem, 7vw, 7em); width: auto; position: absolute; bottom: 50px; left: 50%; transform: translate(-50%, 0) translate3d(calc(var(--parallax-x) * 0.60), calc(var(--parallax-y) * 0.60), 0); transition: transform 0.8s cubic-bezier(0.2, 0.8, 0.2, 1); z-index: 10; will-change: transform; pointer-events: none; user-select: none; -webkit-user-drag: none; }

.app-header.parallax-x-n5 { --parallax-x: -50px; --parallax-tilt-x: -8deg; }
.app-header.parallax-x-n4 { --parallax-x: -40px; --parallax-tilt-x: -6.4deg; }
.app-header.parallax-x-n3 { --parallax-x: -30px; --parallax-tilt-x: -4.8deg; }
.app-header.parallax-x-n2 { --parallax-x: -20px; --parallax-tilt-x: -3.2deg; }
.app-header.parallax-x-n1 { --parallax-x: -10px; --parallax-tilt-x: -1.6deg; }
.app-header.parallax-x-0 { --parallax-x: 0px; --parallax-tilt-x: 0deg; }
.app-header.parallax-x-1 { --parallax-x: 10px; --parallax-tilt-x: 1.6deg; }
.app-header.parallax-x-2 { --parallax-x: 20px; --parallax-tilt-x: 3.2deg; }
.app-header.parallax-x-3 { --parallax-x: 30px; --parallax-tilt-x: 4.8deg; }
.app-header.parallax-x-4 { --parallax-x: 40px; --parallax-tilt-x: 6.4deg; }
.app-header.parallax-x-5 { --parallax-x: 50px; --parallax-tilt-x: 8deg; }

.app-header.parallax-y-n5 { --parallax-y: -28px; --parallax-tilt-y: 8deg; }
.app-header.parallax-y-n4 { --parallax-y: -22.4px; --parallax-tilt-y: 6.4deg; }
.app-header.parallax-y-n3 { --parallax-y: -16.8px; --parallax-tilt-y: 4.8deg; }
.app-header.parallax-y-n2 { --parallax-y: -11.2px; --parallax-tilt-y: 3.2deg; }
.app-header.parallax-y-n1 { --parallax-y: -5.6px; --parallax-tilt-y: 1.6deg; }
.app-header.parallax-y-0 { --parallax-y: 0px; --parallax-tilt-y: 0deg; }
.app-header.parallax-y-1 { --parallax-y: 5.6px; --parallax-tilt-y: -1.6deg; }
.app-header.parallax-y-2 { --parallax-y: 11.2px; --parallax-tilt-y: -3.2deg; }
.app-header.parallax-y-3 { --parallax-y: 16.8px; --parallax-tilt-y: -4.8deg; }
.app-header.parallax-y-4 { --parallax-y: 22.4px; --parallax-tilt-y: -6.4deg; }
.app-header.parallax-y-5 { --parallax-y: 28px; --parallax-tilt-y: -8deg; }

/* Main Content Area */
/* Unified Spacing using Gap */
.app-main-content { flex-grow: 1; width: min(100%, 1100px); margin: 48px auto 80px; padding: 0 32px; display: flex; flex-direction: column; gap: 32px; }
.section-title { font-family: 'Playfair Display', serif; font-size: 2.8em; color: var(--color-text-accent); text-align: center; margin: 0 0 40px; text-shadow: 0 2px 8px var(--color-shadow-dark); border-bottom: 1px solid var(--color-border); padding-bottom: 20px; position: relative; }
.section-title::after { content: ''; display: block; width: 70px; height: 2px; background-color: var(--color-text-accent); margin: 12px auto 0; border-radius: 5px; opacity: 0.8; }

/* Generic Panels */
.panel { background: var(--color-card-bg-gradient); border: 1px solid var(--color-border); border-radius: var(--radius-m); box-shadow: var(--shadow-elegant); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.panel.table-responsive, .panel.flush { padding: 0; overflow: visible; }

/* Ledger Card & Section Resets */
/* Ensure cards don't have individual margins that conflict with gap */
.ledger-card, .admin-interface, #matchmaking-section, #tournament-section, #season-games-section { margin-bottom: 0 !important; }

.ledger-card { padding: 0; background: rgba(22, 22, 22, 0.92); border: 1px solid rgba(255, 215, 0, 0.15); border-radius: var(--radius-m); overflow: visible; position: relative; box-shadow: var(--shadow-elegant); }
.ledger-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01)); border-bottom: 1px solid var(--color-border); gap: 20px; flex-wrap: wrap; border-top-left-radius: var(--radius-m); border-top-right-radius: var(--radius-m); }
.ledger-title-area { display: flex; align-items: center; }
.season-select-wrapper { position: relative; display: inline-flex; align-items: center; }
.season-select-wrapper select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: transparent;
    border: none;
    box-shadow: none;
    color: var(--color-text-accent);
    font-family: 'Playfair Display', serif;
    font-size: 1.6rem;
    font-weight: 700;
    padding-right: 28px;
    cursor: pointer;
    margin: 0;
    line-height: 1.2;
}
.season-select-wrapper select:focus,
.season-select-wrapper select:focus-visible {
    outline: none;
    box-shadow: none;
    border: none;
    background: transparent;
}
.season-select-wrapper .select-icon { position: absolute; right: 0; top: 50%; transform: translateY(-50%); pointer-events: none; font-size: 0.8em; color: var(--color-text-accent); opacity: 0.6; }
.ledger-card.is-archived { border-color: rgba(255, 255, 255, 0.1); }
.ledger-card.is-archived .ledger-header, .ledger-card.is-archived .ledger-content { filter: grayscale(0.6) opacity(0.85) sepia(0.2); transition: filter 0.4s ease; }
.ledger-controls { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.view-switcher { display: inline-flex; background: rgba(0,0,0,0.3); border-radius: 8px; padding: 4px; border: 1px solid rgba(255,255,255,0.08); }
.view-btn { background: transparent; border: none; color: rgba(229,229,229,0.6); padding: 6px 16px; font-size: 0.9rem; font-weight: 600; border-radius: 6px; cursor: pointer; transition: all 0.2s ease; }
.view-btn:hover { color: #FFF; }
.view-btn.active { background: rgba(255,255,255,0.1); color: var(--color-text-accent); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.hero-pane-container { position: relative; }
.hero-pane { opacity: 0; transform: translateY(8px); pointer-events: none; max-height: 0; overflow: hidden; transition: opacity 0.28s ease, transform 0.28s ease, max-height 0.32s ease; }
.hero-pane.active { opacity: 1; transform: translateY(0); pointer-events: auto; max-height: 4000px; overflow: visible; }

/* ELO Chart */
.elo-chart-card { padding: 0; background: transparent; box-shadow: none; border: none; }
.elo-chart-canvas-wrap { position: relative; height: clamp(320px, 55vh, 520px); width: 100%; padding: 16px; }
.elo-chart-legend { padding: 0 16px 24px; display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.elo-legend-item { background: rgba(255, 255, 255, 0.03); border: 1px solid var(--color-border-subtle); border-radius: 6px; padding: 6px 10px; font-size: 0.85rem; cursor: pointer; color: var(--legend-color, rgba(229,229,229,0.85)); border-color: var(--legend-color, var(--color-border-subtle)); transition: all 0.2s ease; opacity: 1; box-shadow: none; }
.elo-legend-item.is-focus { color: rgba(255,255,255,0.4); border-color: transparent; opacity: 0.5; }
.elo-legend-item.is-focus.is-highlight { color: var(--legend-color, var(--color-text-accent)); border-color: var(--legend-color, rgba(255, 215, 0, 0.4)); opacity: 1; }
.elo-legend-item.is-focus.is-highlight.is-hovered { background: rgba(255,255,255,0.05); }
.elo-legend-item.is-focus.is-dimmed { border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.4); opacity: 0.2; }
.elo-legend-item.is-active { box-shadow: 0 0 8px var(--legend-color, rgba(255, 215, 0, 0.4)); }

/* Buttons */
.btn { background: var(--color-button-primary); color: var(--color-text-accent); padding: 0 30px; height: var(--control-height); border: 1px solid var(--color-text-accent); border-radius: var(--radius-s); cursor: pointer; font-size: 1em; font-weight: 700; transition: all 0.25s ease-out; box-shadow: 0 2px 5px rgba(0,0,0,0.3), 0 5px 15px rgba(0,0,0,0.2); margin: 16px 0 0; text-transform: uppercase; letter-spacing: 1.2px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-shadow: 1px 1px 3px rgba(0,0,0,0.6); position: relative; overflow: hidden; min-width: 180px; }
.btn:hover { background: var(--color-button-primary-hover); box-shadow: 0 4px 10px rgba(0,0,0,0.4), 0 8px 25px rgba(100, 65, 0, 0.4); border-color: #FFF; transform: translateY(-2px); }
.btn:active { transform: translateY(0); box-shadow: 0 2px 5px rgba(0,0,0,0.3), 0 5px 15px rgba(0,0,0,0.2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; transform: none; filter: saturate(0.65); border-color: var(--color-border); }
.primary-btn { background: var(--color-button-secondary); border-color: #007bff; color: #FFF; }
.success-btn { background: var(--color-button-success); border-color: #28a745; color: #FFF; }
.ghost-btn { background: none; border: 1px dashed var(--color-border); color: var(--color-text-accent); box-shadow: none; min-width: 0; padding: 0 24px; font-size: 0.9em; text-transform: none; font-weight: 500; opacity: 0.7; }
.ghost-btn:hover { background: rgba(255,255,255,0.04); border-color: var(--color-text-accent); border-style: solid; opacity: 1; transform: none; box-shadow: none; }

/* Sticky action (jump to add game) */
.sticky-action { position: sticky; top: 10px; z-index: 100; margin-top: 24px; text-align: center; }
.sticky-action .btn { margin: 0; }

/* Tables */
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 0; background-color: transparent; }
.data-table th.rank-col, .data-table td.rank-col { width: 70px; min-width: 60px; text-align: center; }
.data-table th.sortable { cursor: pointer; user-select: none; position: relative; padding-right: 24px; }
.data-table th.sortable::after { content: '↕'; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 0.8em; opacity: 0.35; }
.data-table th.sortable.sorted-asc::after { content: '▲'; opacity: 0.8; }
.data-table th.sortable.sorted-desc::after { content: '▼'; opacity: 0.8; }
.data-table th, .data-table td { padding: 18px 20px; text-align: left; border-bottom: 1px solid var(--color-border-subtle); border-radius: 0 !important; border-left: none !important; border-right: none !important; }
.data-table th { background: rgba(0,0,0,0.2); color: var(--color-text-accent); font-weight: 700; text-transform: uppercase; letter-spacing: 1.5px; font-size: 0.9em; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table tr:last-child td:first-child,
.data-table tr:last-child td:last-child { border-radius: 0 !important; }
.data-table tbody tr { transition: background-color 0.2s ease; }
.data-table tbody tr:nth-child(even) { background-color: rgba(255, 255, 255, 0.02); }
.data-table tbody tr:hover { background-color: rgba(255, 215, 0, 0.05); cursor: pointer; }
@keyframes gold-shimmer { 0% { background-position: -200% center; } 100% { background-position: 200% center; } }
.data-table tbody tr.gold td:nth-child(2) { font-size: 1.4em; font-weight: bold; background: linear-gradient(90deg, #ffd700, #f0e68c, #ffd700); -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation: gold-shimmer 4s infinite linear; background-size: 200% auto; text-shadow: none; }
.data-table tbody tr.silver td:nth-child(2) { font-size: 1.2em; font-weight: bold; color: #c0c0c0; }
.data-table tbody tr.bronze td:nth-child(2) { font-size: 1.1em; font-weight: bold; color: #cd7f32; }
.unranked-player { opacity: 0.6; }

.elo-change { font-weight: 700; font-size: 0.85em; margin-left: 4px; }
.elo-change--pos { color: #4cd137; }
.elo-change--neg { color: #ff4757; }
.elo-change--zero { color: #aaa; }

/* Forms */
.data-form, .compact-form { width: 100%; max-width: 650px; margin: 0 auto; }
.form-group { margin: 0 0 16px; display: flex; flex-direction: column; gap: 10px; }
label { margin-bottom: 0; font-weight: 700; color: var(--color-text-accent); font-size: 1em; }
input[type="text"], input[type="number"], select, textarea { width: 100%; padding: 0 16px; height: var(--control-height); border: 1px solid var(--color-border); border-radius: var(--radius-s); background-color: rgba(10,10,10,0.7); color: var(--color-text-light); font-size: 1em; transition: all 0.2s ease; box-shadow: inset 0 1px 4px rgba(0,0,0,0.3); }
textarea { height: auto; padding: 12px 16px; }
input:focus, select:focus, textarea:focus { border-color: var(--color-text-accent); outline: none; box-shadow: 0 0 10px rgba(255, 215, 0, 0.5); background-color: rgba(0,0,0,0.5); }
.segmented { display: flex; flex-wrap: wrap; gap: 10px; }
.segmented input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { display: inline-flex; align-items: center; justify-content: center; height: 38px; padding: 0 16px; text-align: center; border: 1px solid var(--color-border); border-radius: 999px; background: rgba(255,255,255,0.03); color: var(--color-text-light); cursor: pointer; transition: all 0.2s ease; }

.empty-note { text-align: center; padding: 40px 0; color: rgba(255,255,255,0.3); }

.arena-teams { padding: 24px; border-top: 1px solid rgba(255,255,255,0.08); }
.segmented label:hover { border-color: rgba(255, 215, 0, 0.5); background: rgba(255,255,255,0.05); }
.segmented input[type="radio"]:checked + label { background: var(--color-button-success); border-color: #28a745; color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.5); }

/* UI Layer */
.ui-layer { position: fixed; inset: 0; pointer-events: none; z-index: 300; }
.toast-stack { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 12px; align-items: flex-end; pointer-events: auto; }
.toast { min-width: 240px; max-width: 360px; background: var(--color-card-bg-gradient); border: 1px solid var(--color-border); border-left: 3px solid var(--color-text-accent); border-radius: 12px; box-shadow: var(--shadow-elegant); padding: 14px 16px; color: var(--color-text-light); font-weight: 600; opacity: 0; transform: translateY(10px) scale(0.98); transition: all 0.25s ease-out; }
.toast.visible { opacity: 1; transform: translateY(0) scale(1); }
.toast--success { border-left-color: #28a745; }
.toast--error { border-left-color: #c0392b; }
.modal-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); opacity: 0; pointer-events: none; transition: opacity 0.2s ease-out; padding: 16px; z-index: 350; }
.modal-backdrop.active { opacity: 1; pointer-events: auto; }
.modal-card { background: var(--color-card-bg-gradient); border: 1px solid var(--color-border); border-radius: 14px; box-shadow: var(--shadow-elegant); width: min(100%, 420px); padding: 20px; }
.modal-title { margin: 0 0 10px; font-family: 'Playfair Display', serif; color: var(--color-text-accent); }
.modal-message { margin: 0 0 18px; line-height: 1.5; color: var(--color-text-light); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Matchmaking */
.matchmaking-panel { padding: 26px; margin-bottom: 38px; }
.mm-layout { display: grid; grid-template-columns: 1fr; gap: 0; }
@media(min-width: 900px) { .mm-layout { grid-template-columns: 350px 1fr; } .mm-controls { border-right: 1px solid var(--color-border); } }
.mm-controls, .mm-board { padding: 24px; }
.mm-card { background: linear-gradient(145deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02)); border: 1px solid var(--color-border-subtle); border-radius: 8px; padding: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; transition: transform 0.2s ease; margin-bottom: 12px; }
.mm-card:hover { border-color: rgba(255, 215, 0, 0.3); transform: translateY(-2px); }
.mm-name { font-weight: 700; color: #FFF; display: block; }
.mm-meta { font-size: 0.85rem; color: rgba(229,229,229,0.7); display: flex; align-items: center; gap: 8px; }
.mm-badge { padding: 2px 8px; border-radius: 4px; background: rgba(255,215,0,0.1); color: var(--color-text-accent); font-size: 0.75rem; font-weight: 600; }

/* Impressum */
.impressum-content { padding: 32px; color: var(--color-text-light); line-height: 1.8; font-size: 1.05rem; }
.impressum-content h2 { font-family: 'Playfair Display', serif; color: var(--color-text-accent); margin-top: 0; margin-bottom: 24px; font-size: 1.8rem; border-bottom: 1px solid var(--color-border-subtle); padding-bottom: 12px; }
.impressum-content p { margin-bottom: 20px; }
.mail-obfuscated { font-family: monospace; background: rgba(0,0,0,0.3); padding: 4px 8px; border-radius: 4px; border: 1px solid var(--color-border-subtle); color: var(--color-text-accent); user-select: all; }
@media (max-width: 600px) {
    .ledger-content.impressum-content { padding: 32px 24px !important; font-size: 1rem; line-height: 1.6; }
    .impressum-content h2 { font-size: 1.6rem; margin-bottom: 20px; }
    .app-main-content { padding: 0 16px !important; width: 100% !important; box-sizing: border-box; }
    .ledger-card { border-radius: 12px !important; border: 1px solid rgba(255, 255, 255, 0.1) !important; }
    .mail-obfuscated { font-size: 0.9rem; word-break: break-all; }
}

/* Admin Interface */
.admin-card { display: grid; grid-template-columns: 1fr; gap: 0; padding: 0; overflow: hidden; }
@media (min-width: 900px) { .admin-card { grid-template-columns: 1.2fr auto 0.8fr; } .admin-separator { width: 1px; height: auto; background: linear-gradient(180deg, transparent, var(--color-border), transparent); margin: 20px 0; } .admin-pane { padding: 32px; } }
.admin-pane { padding: 24px; }
.admin-heading { margin: 0 0 20px; font-size: 1.4rem; font-family: 'Playfair Display', serif; color: var(--color-text-accent); display: flex; align-items: center; gap: 12px; }
.admin-heading::after { content: ''; flex: 1; height: 1px; background: var(--color-border-subtle); }
.admin-separator { height: 1px; background: linear-gradient(90deg, transparent, var(--color-border), transparent); width: 100%; }

/* Mobile */
@media (max-width: 600px) {
    .app-header { padding: 12px 0 16px; margin-bottom: 24px; }
    .app-logo { max-width: 160px; }
    .ledger-card { border-radius: 12px; } /* Removed margin-bottom */
    .ledger-header { padding: 12px 16px; }
    /* Fix: Only reduce padding for specific content that needs it, or reset it here */
    .ledger-content, .admin-pane, .mm-controls, .mm-board { padding: 16px !important; }
    .data-table th, .data-table td { padding: 12px 8px; font-size: 0.9rem; }
    .data-table th:first-child, .data-table td:first-child { position: sticky; left: 0; z-index: 2; }
    input, select, textarea, .btn { font-size: 16px !important; min-height: 48px; }
    .mm-layout, .admin-card { grid-template-columns: 1fr; }
    .mm-controls { border-right: none; border-bottom: 1px solid var(--color-border-subtle); }
    .admin-separator { width: 100%; height: 1px; margin: 0; }
    .elo-chart-canvas-wrap { height: 360px; padding: 12px; }
    .elo-chart-legend { justify-content: flex-start; gap: 8px; padding-bottom: 16px; }
    .elo-legend-item { flex: 0 0 auto; min-width: 120px; text-align: center; }
}

/* Accordion */
.ledger-header.accordion-trigger { cursor: pointer; transition: background 0.2s ease; user-select: none; }
.ledger-header.accordion-trigger:hover { background: rgba(255, 255, 255, 0.04); }
.accordion-icon { font-size: 0.9em; color: rgba(255, 255, 255, 0.4); transition: transform 0.3s ease, color 0.2s ease; margin-left: 12px; display: inline-block; }
.ledger-card.is-open .accordion-icon { transform: rotate(180deg); color: var(--color-text-accent); }

/* Accordion Content Logic */
.accordion-content {
    max-height: 0;
    overflow: hidden;
    opacity: 0.6;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    will-change: max-height, opacity;
    display: block; /* Default block, hidden by max-height */
}

.ledger-card.is-open .accordion-content {
    max-height: 3000px; /* High enough */
    opacity: 1;
    overflow: visible; /* Important for Popups/Overlays inside */
    padding: 24px; /* Default desktop padding for open content */
}

/* Clean up collapsed border */
.ledger-card:not(.is-open) { border-bottom-color: transparent; }

/* Special Handling for Arena/Bracket to prevent collapsing layout */
.tournament-section .accordion-content > * {
    width: 100%;
}
.bracket-container { overflow-x: auto; min-height: 200px; }

/* Matchmaking reset padding (it handles its own via mm-layout) */
#matchmaking-section .accordion-content { padding: 0 !important; }

/* Mobile Padding Override */
@media (max-width: 600px) {
    .ledger-card.is-open .accordion-content { padding: 16px; }
    #matchmaking-section .accordion-content { padding: 0 !important; }
}

/* Badges */
.achievements-wrapper { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; }
.achievement-icon { font-size: 1.1em; cursor: help; position: relative; opacity: 0.9; transition: transform 0.2s ease, opacity 0.2s; }
.achievement-icon:hover { transform: scale(1.3); opacity: 1; z-index: 10; }
.achievement-icon::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    top: calc(100% + 8px);
    transform: translateX(-50%) translateY(-6px);
    background: rgba(10, 10, 10, 0.95);
    border: 1px solid var(--color-text-accent);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    width: max-content;
    max-width: 280px;
    pointer-events: none;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.15s ease;
    line-height: 1.4;
    white-space: normal;
}
.achievement-icon:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Unranked Animation */
.unranked-row.is-hidden { display: none; }
.unranked-row.animating { animation: fadeIn 0.4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* Ledger Footer (Cleaned Up) */
.ledger-footer {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: rgba(30, 30, 30, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.85rem;
    gap: 20px;
    flex-wrap: nowrap;
    margin-top: -1px;
    border-bottom-left-radius: var(--radius-m);
    border-bottom-right-radius: var(--radius-m);
}
.footer-info {
    color: rgba(255, 255, 255, 0.6);
    font-weight: 500;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 1;
}
#toggle-unranked-btn {
    margin-left: auto;
    flex-shrink: 0;
    padding: 6px 0;
    background: transparent;
    border: none;
    color: var(--color-text-accent);
    font-weight: 500;
    letter-spacing: 0.3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    white-space: nowrap;
    width: auto;
}
#toggle-unranked-btn:hover {
    background: transparent;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
    transform: none;
    box-shadow: none;
}
@media (max-width: 500px) {
    .ledger-footer { padding: 12px 16px; font-size: 0.8rem; }
}
/* Footer Link */
.app-footer { text-align: center; padding: 20px 0 40px; margin-top: auto; width: 100%; color: rgba(255, 255, 255, 0.4); font-size: 0.9rem; }
.app-footer a { color: inherit; text-decoration: none; transition: color 0.2s ease; }
.app-footer a:hover { color: var(--color-text-accent); }

/* Chevron Icon Styling */
.accordion-chevron {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--color-text-accent);
    border-bottom: 2px solid var(--color-text-accent);
    transform: rotate(45deg);
    transition: transform 0.3s ease;
    margin-bottom: 4px; /* Align visual center */
    opacity: 0.7;
}
.ledger-card.is-open .accordion-chevron {
    transform: rotate(-135deg); /* Flip up */
    border-color: #fff; /* Highlight on active */
    opacity: 1;
}
.ledger-header { justify-content: space-between !important; }
/* --- RESTORED TOURNAMENT STYLES --- */

/* Tournament Setup UI */
.setup-container { display: flex; flex-direction: column; gap: 32px; padding: 10px; }
.setup-group-title { font-family: Playfair Display, serif; font-size: 1.1rem; color: var(--color-text-accent); margin-bottom: 16px; opacity: 0.9; border-bottom: 1px solid var(--color-border-subtle); padding-bottom: 8px; }

/* Mode Cards */
.mode-selection-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.mode-card { background: rgba(255,255,255,0.03); border: 1px solid var(--color-border); border-radius: var(--radius-m); padding: 20px 16px; cursor: pointer; transition: all 0.2s ease; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; }
.mode-card:hover { background: rgba(255,255,255,0.06); transform: translateY(-2px); }
.mode-card.active { background: rgba(255, 215, 0, 0.08); border-color: var(--color-text-accent); box-shadow: 0 0 15px rgba(255, 215, 0, 0.1); }
.mode-card.disabled { opacity: 0.4; pointer-events: none; filter: grayscale(1); }
.mode-icon { font-size: 1.8rem; margin-bottom: 4px; opacity: 0.8; }
.mode-label { font-weight: 700; color: var(--color-text-light); }
.mode-desc { font-size: 0.75rem; color: rgba(229,229,229,0.5); line-height: 1.3; }

/* Player Selection */
.player-select-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; max-height: 400px; overflow-y: auto; margin-bottom: 20px; }
.player-checkbox-card { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: linear-gradient(145deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01)); border: 1px solid var(--color-border-subtle); border-radius: 8px; cursor: pointer; transition: all 0.15s ease; }
.player-checkbox-card:hover { border-color: rgba(255,255,255,0.2); }
.player-checkbox-card input[type=checkbox] { accent-color: var(--color-text-accent); transform: scale(1.2); margin-right: 12px; width: auto; height: auto; }
.player-checkbox-card:has(input:checked) { background: rgba(255, 215, 0, 0.05); border-color: rgba(255, 215, 0, 0.3); }

/* Bracket Flex System */
.bracket-flex-layer { display: flex; flex-direction: row; gap: 20px; padding: 20px; }
.bracket-flex-col { display: flex; flex-direction: column; justify-content: space-around; min-width: 160px; gap: 20px; }
.bracket-match { background: var(--color-card-bg); border: 1px solid var(--color-border); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); min-width: 180px; justify-content: center; position: relative; z-index: 2; height: max-content; margin: 4px 0; }
.bracket-match.is-ready { border-color: var(--color-text-accent); box-shadow: 0 0 12px rgba(255, 215, 0, 0.15); }
.bracket-match.is-completed { opacity: 0.65; filter: grayscale(0.3); }
.bracket-slot { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; padding: 2px 0; }
.bracket-slot.winner { color: #4cd137; font-weight: bold; }
.bracket-slot.loser { opacity: 0.5; text-decoration: line-through; }
.bracket-slot.tbd { font-style: italic; opacity: 0.3; }
.bracket-slot-col { display: flex; flex-direction: column; width: 100%; }
.bracket-slot-row { display: flex; justify-content: space-between; }
.bracket-score { font-weight: 700; }
.roster-warning { font-size: 0.7em; color: #e67e22; margin-top: 2px; }
.roster-remove-link { cursor: pointer; text-decoration: underline; margin-right: 3px; }
.series-info { text-align: center; font-size: 0.7em; opacity: 0.6; margin-bottom: 4px; }
.bracket-bell { cursor: pointer; opacity: 0.2; padding: 2px 6px; }
.bracket-bell:hover, .bracket-bell.active { opacity: 1; color: var(--color-text-accent); }

/* --- SPACING FIX RESTORE --- */
/* Disable Flex Gap and use Margins for robustness */
.app-main-content { gap: 0 !important; }
.ledger-card, .admin-interface, #matchmaking-section, #tournament-section, #season-games-section { margin-bottom: 40px !important; display: block !important; }
.app-main-content > :last-child { margin-bottom: 0 !important; }


/* Remove old Load More Container styles if they exist to avoid conflict */
#load-more-games-container {
    display: none !important;
}


/* Universal Footer Button Style (Fix for Load More) */
.footer-toggle-btn, #load-more-games-btn {
    background: transparent !important;
    border: none !important;
    color: var(--color-text-accent) !important;
    font-weight: 500 !important;
    font-size: 0.85rem !important;
    letter-spacing: 0.3px !important;
    cursor: pointer !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 8px 12px !important;
    width: auto !important;
    text-transform: none !important; /* Prevent uppercase if inherited */
    box-shadow: none !important;
}

.footer-toggle-btn:hover, #load-more-games-btn:hover {
    background: rgba(255, 215, 0, 0.05) !important;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.4) !important;
    transform: none !important;
}

/* Ensure centering for load more */
#load-more-games-btn {
    margin: 0 !important; /* Reset margin-left: auto */
}


/* --- MOBILE SPECIFIC FIXES --- */

@media (max-width: 600px) {
    /* 1. Games Table Visibility & Content */
    .data-table td {
        padding: 10px 8px !important;
        height: auto !important;
        font-size: 0.9rem !important;
        color: rgba(255,255,255,0.9) !important;
        vertical-align: middle;
    }
    
    /* Ensure P1 and P2 names are not truncated too aggressively */
    .data-table td:nth-child(2),
    .data-table td:nth-child(3) {
        white-space: normal;
        max-width: 120px;
    }

    /* 2. Fix Header Text Visibility (Matchmaking/Arena) */
    .ledger-title-area h2 {
        font-size: 1.2rem !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block !important;
        opacity: 1 !important;
        color: var(--color-text-accent) !important;
        max-width: 200px; /* Ensure space for arrow */
    }
    
    /* Ensure Header content is row and aligned */
    .ledger-header {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    
    /* 3. Fix Accordion Collapse (Arena leaking) */
    /* Only allow padding when fully open */
    .accordion-content {
        padding: 0 !important;
        border: none !important;
    }
    
    .ledger-card.is-open .accordion-content {
        padding: 16px !important;
    }
    
    /* Bracket container must collapse fully */
    .bracket-container {
        min-height: 0 !important;
        margin: 0 !important;
    }
    
    .ledger-card.is-open .bracket-container {
        min-height: 200px !important;
        margin: 10px 0 !important;
    }
    
    /* 4. Fix Tournament Section Header Layout */
    /* Specifically target the flex container inside header */
    .ledger-header > div:first-child {
        flex: 1;
        min-width: 0; /* Allow text truncate */
    }
}


/* --- FINAL MOBILE REPAIRS --- */

@media (max-width: 768px) {
    /* 1. Force Hide Columns (Ranking & Games) */
    /* Select by class specifically to override any "table-cell !important" */
    th.hide-on-mobile, 
    td.hide-on-mobile,
    .data-table .hide-on-mobile {
        display: none !important;
    }

    /* 2. Fix Games Table Layout */
    /* Make sure visible columns take space */
    #season-games-section .data-table td {
        white-space: normal !important; /* Wrap names if needed */
    }
    
    /* 3. Fix Arena Content Grids */
    /* Ensure internal grids work even if wrapper is block */
    .mode-selection-grid,
    .player-select-grid {
        display: grid !important;
        grid-template-columns: 1fr !important; /* Stack on mobile */
        gap: 12px !important;
    }
    
    .setup-container {
        display: flex !important; /* Restore flex for setup */
    }
    
    /* Ensure checkboxes are visible */
    .player-checkbox-card {
        display: flex !important;
        opacity: 1 !important;
    }
}


/* --- EMERGENCY MOBILE VISIBILITY FIX --- */

@media (max-width: 768px) {
    /* 1. Games Table Content Visibility */
    #season-games-section .data-table td {
        display: table-cell !important; /* Force cell rendering */
        opacity: 1 !important;
        visibility: visible !important;
        color: rgba(255, 255, 255, 0.95) !important; /* Force White Text */
        background: transparent !important;
    }
    
    /* Re-Hide specific columns explicitly again to be safe */
    #season-games-section .data-table td.hide-on-mobile,
    #season-games-section .data-table th.hide-on-mobile {
        display: none !important;
    }

    /* 2. Arena Content Visibility */
    .tournament-section.is-open .accordion-content {
        height: auto !important;
        min-height: 300px !important; /* Force space for content */
    }
    
    /* Ensure internal divs are visible */
    #tournament-setup, 
    #tournament-bracket-view, 
    #tournament-standings-view {
        opacity: 1 !important;
        visibility: visible !important;
        width: 100% !important;
    }
    
    /* If Setup is active (controlled by JS inline style), ensure flex works */
    #tournament-setup[style*="block"] {
        display: block !important;
    }
    
    .setup-container {
        display: flex !important;
        flex-direction: column !important;
        opacity: 1 !important;
    }
}


/* --- FINAL RANKING COLOR FIX --- */
/* Force Rank Colors to override any mobile defaults */

.data-table tbody tr.gold td:nth-child(2) {
    background: linear-gradient(90deg, #ffd700, #f0e68c, #ffd700) !important;
    -webkit-background-clip: text !important;
    background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    color: #ffd700 !important; /* Fallback */
    font-weight: 800 !important;
    text-shadow: none !important;
}

.data-table tbody tr.silver td:nth-child(2) {
    color: #e0e0e0 !important;
    font-weight: 700 !important;
    text-shadow: 0 0 10px rgba(224, 224, 224, 0.4);
}

.data-table tbody tr.bronze td:nth-child(2) {
    color: #cd7f32 !important;
    font-weight: 700 !important;
    text-shadow: 0 0 10px rgba(205, 127, 50, 0.4);
}


/* --- FINAL VISIBILITY FORCE --- */

@media (max-width: 768px) {
    /* 1. Games Table: Ensure Rows have height */
    #season-games-section .data-table tr {
        display: table-row !important;
        height: auto !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Ensure Cells take space */
    #season-games-section .data-table td {
        white-space: normal !important; /* Allow wrapping */
        overflow: visible !important;
    }

    /* 2. Arena: Force Content Display when Open */
    .ledger-card.is-open .accordion-content * {
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Ensure Setup Container has dimensions */
    .setup-container {
        min-height: 100px;
        width: 100%;
        display: flex !important;
        flex-direction: column;
    }
    
    /* Ensure Mode Cards are visible */
    .mode-card {
        display: flex !important;
        opacity: 1 !important;
        min-height: 80px;
    }
}


/* --- IOS / WEBKIT SPECIFIC FIXES --- */

@media (max-width: 768px) {
    /* 1. Fix Scrolling */
    .table-responsive, 
    .bracket-container, 
    .player-select-grid {
        -webkit-overflow-scrolling: touch !important;
        overflow-y: hidden !important;
        overflow-x: auto !important;
    }

    /* 2. Fix Table Cell Rendering in Safari */
    /* Do NOT force block/flex on table cells, keep table-cell */
    #season-games-section .data-table td {
        display: table-cell !important;
        height: auto !important;
        white-space: normal !important;
    }
    
    /* Ensure Row Height */
    #season-games-section .data-table tr {
        min-height: 44px;
    }

    /* 3. Fix Arena Content Collapse */
    /* Ensure flex items expand */
    .setup-container {
        flex-shrink: 0 !important;
    }
    
    /* Ensure text is strictly white */
    * {
        -webkit-font-smoothing: antialiased;
    }
}


/* --- MOBILE FULL WIDTH TABLES --- */

@media (max-width: 600px) {
    /* Remove padding from ledger content to let tables touch edges */
    .ledger-content {
        padding: 0 !important;
    }
    
    /* Re-add padding for sections that are NOT tables */
    .admin-pane, .mm-controls, .mm-board {
        padding: 16px !important;
    }
    
    /* If there is text directly in ledger-content (like info text), pad it */
    .ledger-content > .info-text {
        padding: 0 16px 16px;
    }
    
    /* Ensure Footer has padding */
    .ledger-footer {
        padding: 12px 16px !important;
    }
}


/* Make Cards Square on Mobile for Full-Width Feel */
@media (max-width: 600px) {
    .ledger-card {
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }
}


/* REVERT: Restore Rounded Corners on Mobile */
@media (max-width: 600px) {
    .ledger-card {
        border-radius: 12px !important; /* Restore Desktop Radius */
        border: 1px solid rgba(255, 215, 0, 0.15) !important; /* Restore Border */
    }
}


/* Footer Spacing Tweak */
.app-footer {
    padding-top: 10px !important;
    padding-bottom: 30px !important; /* Slightly reduce bottom too */
}


/* Mobile Header Tweak */
@media (max-width: 600px) {
    .app-title-image {
        bottom: 18px !important; /* Move title slightly down */
    }
}


/* Footer Spacing Fix */
.app-main-content {
    margin-bottom: 32px !important; /* Match section gap */
}

.app-footer {
    padding-top: 0 !important;
    margin-top: 0 !important;
}


/* --- REPAIR: Header & Visibility Fixes --- */

/* 1. Header Layout Repair */
.ledger-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
}

.ledger-title-area {
    flex-grow: 1;
    min-width: 0; /* Allow text truncate */
    display: flex !important;
    align-items: center !important;
}

.ledger-title-area h2 {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    color: var(--color-text-accent) !important;
}

/* 2. Arena Content Repair */
.tournament-section .accordion-content {
    /* Do not force block if it breaks inner flex */
    /* Let JS handle display, or use flow-root */
    display: block; 
}

/* Ensure inner containers are visible */
.setup-container, .bracket-container {
    opacity: 1 !important;
    visibility: visible !important;
    display: flex !important; /* Restore flex for setup */
}

/* 3. Games Table Repair */
#season-games-section .data-table td {
    color: rgba(255, 255, 255, 0.9) !important;
    opacity: 1 !important;
    visibility: visible !important;
    display: table-cell !important;
}

/* Ensure Row Height */
#season-games-section .data-table tr {
    height: auto !important;
    min-height: 40px !important;
}


/* --- FINAL MOBILE RECOVERY --- */

@media (max-width: 768px) {
    /* 1. FORCE TABLE VISIBILITY (Games List) */
    /* Reset table layout to browser defaults to fix "empty" rows */
    #season-games-section .data-table {
        display: table !important;
        width: 100% !important;
        border-collapse: collapse !important;
    }
    
    #season-games-section .data-table tbody {
        display: table-row-group !important;
    }
    
    #season-games-section .data-table tr {
        display: table-row !important;
        border-bottom: 1px solid rgba(255,255,255,0.1) !important;
    }
    
    #season-games-section .data-table td {
        display: table-cell !important;
        color: rgba(255, 255, 255, 0.9) !important;
        padding: 12px 8px !important;
        vertical-align: middle !important;
        text-align: left !important;
    }

    /* 2. FORCE ARENA CONTENT VISIBILITY */
    /* When open, ensure container has height and opacity */
    .ledger-card.is-open .accordion-content {
        display: block !important;
        height: auto !important;
        min-height: 100px !important;
        opacity: 1 !important;
        visibility: visible !important;
        overflow: visible !important;
    }
    
    /* Ensure the inner Setup Container is visible and flex */
    .setup-container {
        display: flex !important;
        flex-direction: column !important;
        opacity: 1 !important;
        width: 100% !important;
    }
    
    /* Ensure Bracket is visible (horizontal scroll) */
    .bracket-container {
        display: block !important;
        opacity: 1 !important;
        min-height: 200px !important;
        overflow-x: auto !important;
    }
}


/* --- FINAL CSS REWRITE TO CLEAN UP --- */
/* Reset conflicting rules */

/* 1. Ensure Table Visibility on Mobile */
@media (max-width: 768px) {
    #season-games-section .data-table tr {
        display: table-row !important;
    }
    #season-games-section .data-table td {
        display: table-cell !important;
        opacity: 1 !important;
        visibility: visible !important;
        color: rgba(255, 255, 255, 0.9) !important;
    }
}

/* 2. Ensure Arena Visibility when Open */
.ledger-card.is-open .accordion-content {
    display: block !important;
    height: auto !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* 3. Ensure Setup Container is visible */
.setup-container {
    display: flex !important;
    opacity: 1 !important;
}

/* --- TEAMS MANAGEMENT --- */
.teams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.team-card {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-border); /* Default, overridden via dynamic class */
    border-radius: 8px;
    padding: 16px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.team-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    background: rgba(255,255,255,0.05);
}

.team-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.team-name {
    font-weight: 700;
    font-size: 1.1em;
    color: var(--color-text-light);
    display: flex;
    align-items: center;
    gap: 8px;
}

.team-count { font-size: 0.8em; opacity: 0.5; font-weight: 400; }
.teams-empty { grid-column: 1 / -1; text-align: center; padding: 20px; }

.team-actions {
    display: flex;
    gap: 8px;
}

.team-btn-icon {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 4px;
    font-size: 0.9em;
    transition: color 0.2s;
}

.team-btn-icon:hover {
    color: var(--color-text-light);
}

.team-btn-icon.delete:hover {
    color: #ff4757;
}

.team-members-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.team-member-badge {
    background: rgba(0,0,0,0.3);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid rgba(255,255,255,0.05);
}

.team-member-remove {
    cursor: pointer;
    opacity: 0.5;
    font-weight: bold;
    font-size: 1.1em;
    line-height: 1;
}

.team-member-remove:hover {
    opacity: 1;
    color: #ff4757;
}

.team-add-member {
    margin-top: 8px;
    display: flex;
    gap: 6px;
}

.team-add-member select {
    height: 32px;
    font-size: 0.85em;
    background: rgba(0,0,0,0.2);
}

.team-add-member button {
    height: 32px;
    padding: 0 12px;
    font-size: 0.85em;
    min-width: auto;
}

.team-edit-row {
    display: none;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.team-edit-row.is-open {
    display: flex;
}
.team-edit-row input[type="text"] {
    flex: 1;
    min-width: 160px;
    height: 32px;
    font-size: 0.85em;
}
.team-edit-row input[type="color"] {
    width: 40px;
    height: 32px;
    padding: 0;
    border: none;
}
.team-edit-actions {
    display: flex;
    gap: 6px;
}

/* --- ARENA LEAGUE --- */
.arena-league-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: linear-gradient(120deg, rgba(255, 215, 0, 0.08), rgba(0,0,0,0.2));
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: 14px;
    padding: 18px 20px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.35);
    margin-bottom: 16px;
}
.arena-league-title {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 240px;
}
.arena-league-badge {
    background: rgba(255, 215, 0, 0.12);
    border: 1px solid rgba(255, 215, 0, 0.35);
    color: var(--color-text-accent);
    font-weight: 700;
    letter-spacing: 0.8px;
    padding: 6px 10px;
    border-radius: 999px;
    text-transform: uppercase;
    font-size: 0.7rem;
}
.arena-league-name {
    margin: 0;
    font-family: 'Playfair Display', serif;
    font-size: 1.3rem;
    color: #fff;
}
.arena-league-sub {
    margin: 4px 0 0;
    font-size: 0.86rem;
    color: rgba(229,229,229,0.7);
}
.arena-league-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
    align-items: center;
    flex: 1;
}
.arena-meta-card {
    background: rgba(0,0,0,0.35);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.arena-meta-card .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: rgba(229,229,229,0.6);
}
.arena-meta-card .value {
    font-weight: 700;
    color: var(--color-text-accent);
}
.arena-league-table th:nth-child(1),
.arena-league-table td:nth-child(1) {
    width: 70px;
    text-align: center;
}
.arena-league-table th:nth-child(3),
.arena-league-table th:nth-child(4),
.arena-league-table th:nth-child(5),
.arena-league-table td:nth-child(3),
.arena-league-table td:nth-child(4),
.arena-league-table td:nth-child(5) {
    text-align: center;
}
.arena-league-table .arena-num {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.2px;
}
.arena-rank-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 28px;
    border-radius: 999px;
    background: rgba(255, 215, 0, 0.12);
    border: 1px solid rgba(255, 215, 0, 0.3);
    color: var(--color-text-accent);
    font-weight: 700;
    font-size: 0.85rem;
}
.arena-league-table tbody tr.gold .arena-rank-pill {
    background: linear-gradient(90deg, rgba(255,215,0,0.3), rgba(255,215,0,0.08));
    border-color: rgba(255, 215, 0, 0.6);
    color: #fff3b0;
}
.arena-league-table tbody tr.silver .arena-rank-pill {
    background: rgba(224,224,224,0.2);
    border-color: rgba(224,224,224,0.5);
    color: #f0f0f0;
}
.arena-league-table tbody tr.bronze .arena-rank-pill {
    background: rgba(205,127,50,0.2);
    border-color: rgba(205,127,50,0.45);
    color: #f2c48a;
}
.arena-league-table th,
.arena-league-table td {
    padding: 16px 18px;
}
.arena-league-table tbody tr:hover {
    background: linear-gradient(90deg, rgba(255,215,0,0.08), rgba(255,215,0,0.02));
}

@media (max-width: 600px) {
    .arena-league-header {
        padding: 14px;
    }
    .arena-league-title {
        flex-direction: column;
        align-items: flex-start;
    }
    .arena-league-meta {
        width: 100%;
    }
    .arena-league-table th,
    .arena-league-table td {
        padding: 12px 10px;
    }
}

/* Fixed Layout for Games Table to prevent jumping */
#season-games-section .data-table {
    table-layout: fixed;
    width: 100%;
}
/* Desktop Widths (5 cols) */
#season-games-section .data-table th:nth-child(1) { width: 10%; } /* KW */
#season-games-section .data-table th:nth-child(2) { width: 20%; } /* P1 */
#season-games-section .data-table th:nth-child(3) { width: 20%; } /* P2 */
#season-games-section .data-table th:nth-child(4) { width: 25%; } /* Details */
#season-games-section .data-table th:nth-child(5) { width: 25%; } /* Badges */

@media (max-width: 600px) {
    /* Mobile Widths (2 cols visible) */
    #season-games-section .data-table th:nth-child(2) { width: 50%; }
    #season-games-section .data-table th:nth-child(3) { width: 50%; }
}

/* Player Management List - Industrial Redesign */
.player-manage-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    padding: 12px 16px;
    background: rgba(30, 30, 30, 0.6);
    border: 1px solid var(--color-border);
    margin-bottom: 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}
.player-manage-row:hover {
    background: rgba(255, 255, 255, 0.03);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateX(2px);
}
.player-manage-row.is-inactive {
    border-color: rgba(255, 255, 255, 0.05);
    background: rgba(20, 20, 20, 0.4);
    opacity: 0.7;
}
.player-manage-row.is-inactive .player-manage-name {
    text-decoration: line-through;
    opacity: 0.6;
}

.player-manage-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 16px;
}

.player-manage-name {
    font-family: 'Roboto', sans-serif;
    font-weight: 700;
    color: var(--color-text-light);
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.player-manage-pseudo {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--color-border-subtle);
    border-radius: 4px;
    color: var(--color-text-accent);
    font-size: 0.85em;
    padding: 8px 12px;
    width: 100%;
    transition: border-color 0.2s;
}
.player-manage-pseudo:focus {
    outline: none;
    border-color: var(--color-text-accent);
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 0 1px rgba(255, 215, 0, 0.2);
}

/* Industrial Switch */
.switch-toggle {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
}
.switch-toggle input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #2a2a2a;
    border: 1px solid var(--color-border);
    transition: .3s;
    border-radius: 4px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: #666;
    transition: .3s;
    border-radius: 2px;
}
input:checked + .slider {
    background-color: rgba(40, 167, 69, 0.15);
    border-color: #28a745;
}
input:checked + .slider:before {
    transform: translateX(24px);
    background-color: #28a745;
    box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
}
