        :root {
            --bg-color: #ffffff;
            --fg-color: #111111;
            --gray-100: #fafafa;
            --gray-200: #eaeaea;
            --gray-500: #666666;
            --accent-color: #0070f3;
            --radius: 8px;
            --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            --font-heading: "Outfit", sans-serif;
            --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
            --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
            --transition: all 0.2s ease;
        }

        body {
            font-family: var(--font-sans);
            margin: 0; 
            padding: 40px 20px;
            background-color: var(--bg-color); 
            color: var(--fg-color);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            -webkit-font-smoothing: antialiased;
        }

        .container { 
            width: 100%; 
            max-width: 1280px; 
            display: flex;
            flex-direction: column;
            gap: 24px;
        }

        header { 
            text-align: center; 
            margin-bottom: 10px;
        }
        
        h1 { 
            font-family: var(--font-heading);
            font-weight: 600;
            font-size: 2.4rem;
            letter-spacing: -0.01em;
            margin: 0;
            color: #000;
            line-height: 1.2;
        }
        
        /* Card container */
        .card {
            background: #fff;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius);
            padding: 20px;
            box-shadow: var(--shadow-sm);
            transition: var(--transition);
            display: flex;
            flex-direction: column;
            gap: 16px;
        }
        
        /* Top control layout */
        .controls-header {
            display: flex;
            gap: 12px;
            align-items: center;
            width: 100%;
        }

        /* Search input styles */
        .search-wrapper {
            position: relative;
            flex: 1; 
        }
        .search-input {
            width: 100%;
            padding: 8px 32px 8px 32px;
            font-size: 0.9rem;
            border: 1px solid var(--gray-200);
            border-radius: 6px;
            background: var(--gray-100);
            color: #333;
            transition: var(--transition);
            box-sizing: border-box;
            appearance: none; 
            font-family: var(--font-sans);
        }
        .search-input:focus {
            background: #fff;
            border-color: #999;
            outline: none;
        }
        .search-icon {
            position: absolute;
            left: 10px;
            top: 50%;
            transform: translateY(-50%);
            width: 14px;
            height: 14px;
            opacity: 0.4;
            pointer-events: none;
        }
        .search-clear {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            width: 16px;
            height: 16px;
            cursor: pointer;
            opacity: 0.4;
            display: none;
            align-items: center;
            justify-content: center;
            background: #ccc;
            border-radius: 50%;
            color: #fff;
            font-size: 12px;
            line-height: 1;
        }
        .search-clear:hover { opacity: 0.8; background: #999; }
        .search-input:not(:placeholder-shown) + .search-clear { display: flex; }

        /* Select-all button styles */
        .action-btn {
            border: 1px solid var(--gray-200);
            background: var(--gray-100);
            padding: 8px 16px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 0.85rem;
            font-weight: 500;
            color: var(--gray-500);
            transition: var(--transition);
            white-space: nowrap;
            height: 35px; 
            display: flex;
            align-items: center;
            justify-content: center;
            font-family: var(--font-sans);
        }
        .action-btn:active {
            background: #f0f0f0;
            transform: scale(0.98);
        }

        /* Hunt selector */
        .controls-scroll-area {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            max-height: 160px;
            overflow-y: auto;
            padding-right: 4px;
            -webkit-overflow-scrolling: touch;
        }
        
        .controls-scroll-area::-webkit-scrollbar { width: 6px; }
        .controls-scroll-area::-webkit-scrollbar-track { background: transparent; }
        .controls-scroll-area::-webkit-scrollbar-thumb { background-color: var(--gray-200); border-radius: 3px; }

        .checkbox-wrapper {
            display: flex; 
            align-items: center; 
            gap: 8px; 
            cursor: pointer;
            padding: 6px 10px;
            border-radius: 6px;
            border: 1px solid transparent;
            font-size: 0.85rem;
            font-weight: 500;
            color: #333;
            background: var(--gray-100);
            transition: opacity 0.2s, transform 0.2s; 
            user-select: none;
            -webkit-tap-highlight-color: transparent;
        }

        .checkbox-wrapper:active { background: #f5f5f5; }
        .checkbox-wrapper.hidden { display: none; }

        .checkbox-wrapper input { 
            accent-color: var(--accent-color); 
            width: 16px; 
            height: 16px;
            margin: 0;
        }

        .dot {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            display: inline-block;
            flex-shrink: 0; 
        }

        /* Toolbar */
        .toolbar {
            flex-direction: row;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            padding: 10px 16px;
        }

        .mode-group {
            display: flex;
            background: var(--gray-100);
            border-radius: 6px;
            padding: 4px;
            border: 1px solid var(--gray-200);
            flex-wrap: wrap;
        }

        .mode-btn {
            border: none;
            background: transparent;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.85rem;
            font-weight: 500;
            color: var(--gray-500);
            transition: var(--transition);
            -webkit-tap-highlight-color: transparent;
            font-family: var(--font-sans);
        }
        
        .mode-btn.active { 
            background: #fff; 
            color: #000;
            box-shadow: 0 1px 2px rgba(0,0,0,0.1);
            font-weight: 600;
        }
        
        .input-control-group {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 0.9rem;
            color: #666;
        }
        .small-input {
            width: 50px;
            padding: 6px;
            border: 1px solid #eaeaea;
            border-radius: 4px;
            text-align: center;
            font-family: var(--font-sans);
        }

        /* Chart area */
        #chart-wrapper {
            position: relative;
            height: 75vh;
            min-height: 500px;
            background: #fff;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius);
            overflow: hidden;
            box-shadow: var(--shadow-sm);
            display: flex;
            flex-direction: column;
        }

        #chart-container { 
            width: 100%; 
            height: 100%; 
            touch-action: none; 
        }

        /* Data Grid & Leaderboard Container */
        .html-table-container {
            width: 100%;
            height: 100%;
            overflow-y: auto;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            padding-bottom: 20px;
        }

        /* Avg-rank section styles */
        .avg-rank-header {
            margin-bottom: 12px;
            background: #fafafa;
            border-bottom: 1px solid var(--gray-200);
        }
        
        details.avg-rank-details summary {
            list-style: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px 16px;
            font-size: 0.9rem;
            font-weight: 500;
            color: #444;
            user-select: none;
            transition: background 0.2s;
        }
        details.avg-rank-details summary:hover { background: #f0f0f0; }
        details.avg-rank-details summary::-webkit-details-marker { display: none; }
        details.avg-rank-details summary svg { transition: transform 0.2s ease; opacity: 0.6; }
        details.avg-rank-details[open] summary svg { transform: rotate(180deg); }
        
        .avg-rank-chip-container {
            padding: 0 16px 12px 16px;
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
        }
        
        .rank-strip {
            display: flex;
            gap: 6px;
            overflow-x: auto;
            white-space: nowrap;
            padding-bottom: 4px;
            scrollbar-width: thin;
            max-width: 100%;
            align-items: center;
        }
        .rank-strip::-webkit-scrollbar { height: 4px; }
        .rank-strip::-webkit-scrollbar-thumb { background-color: var(--gray-200); border-radius: 2px; }

        .mini-chip {
            flex-shrink: 0;
            display: inline-flex;
            align-items: center;
            font-size: 0.75rem;
            padding: 2px 8px;
            border-radius: 4px;
            border: 1px solid #eaeaea;
            background: #fff;
            color: #333;
            height: 22px;
            box-sizing: border-box;
        }
        
        .avg-rank-table { min-width: 760px; }
        .avg-rank-table th:nth-child(1) { width: 70px; }
        .avg-rank-table th:nth-child(3),
        .avg-rank-table th:nth-child(4),
        .avg-rank-table th:nth-child(5) { width: 110px; }
        .avg-rank-table td { vertical-align: middle !important; }

        /* Leaderboard-specific container */
        #leaderboard-view { overflow-x: hidden; }
        #lb-ui-structure { min-width: 0; }
        #lb-content {
            flex: 1 1 auto;
            min-width: 0;
            overflow-y: auto;
            overflow-x: auto;
        }

        /* Table Styles */
        table.modern-table {
            width: 100%;
            border-collapse: separate; 
            border-spacing: 0;
            font-size: 0.9rem;
            table-layout: fixed; 
        }

        table.modern-table th {
            background: #fafafa;
            position: sticky;
            top: 0;
            z-index: 10;
            font-weight: 600;
            text-align: left;
            padding: 14px 20px;
            border-bottom: 1px solid var(--gray-200);
            color: var(--gray-500);
            white-space: nowrap;
        }

        table.modern-table td {
            padding: 14px 20px;
            border-bottom: 1px solid var(--gray-200);
            color: #111;
            background: #fff;
            font-variant-numeric: tabular-nums; 
            vertical-align: top;
        }

        table.modern-table tr:last-child td { border-bottom: none; }

        /* Data Grid Specifics */
        .datagrid-table {
            min-width: 1000px; 
            table-layout: fixed; 
        }
        
        .datagrid-table th:nth-child(1) { 
            width: 240px; 
            background: #fafafa; 
            border-right: 1px solid var(--gray-200);
            position: sticky;
            top: 0; 
            left: auto !important; 
            z-index: 10;
        }
        
        .datagrid-table td.event-name {
            background: #fff;
            border-right: 1px solid var(--gray-200);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            position: static !important; 
            left: auto !important;
            z-index: auto !important;
        }

        .datagrid-table th:nth-child(2), .datagrid-table th:nth-child(3) { width: 110px; }
        .datagrid-table th:nth-child(4), .datagrid-table th:nth-child(5),
        .datagrid-table th:nth-child(6), .datagrid-table th:nth-child(7),
        .datagrid-table th:nth-child(8) { width: 90px; }

        /* Leaderboard Normal Mode */
        .leaderboard-table { width: 100%; min-width: 640px; table-layout: fixed; } 
        .leaderboard-table th:nth-child(1) { width: 60px; } 
        .leaderboard-table th:nth-child(2) { width: 28%; }
        .leaderboard-table th:last-child { width: 90px; } 
        
        .leaderboard-table td.wrap-text {
            white-space: normal;
            overflow-wrap: break-word;
            word-wrap: break-word;
            word-break: normal;
        }
        
        .member-cell {
            font-family: var(--font-sans);
            font-size: 0.85rem;
            color: #555;
            line-height: 1.5;
        }

        .team-link {
            color: #222;
            text-decoration: none;
            cursor: pointer;
            font-weight: 600;
            border-bottom: 1px dashed transparent;
            transition: color 0.15s, border-color 0.15s;
        }
        .team-link:hover { color: #000; border-color: #999; }
        
        /* Leaderboard Search Mode */
        .leaderboard-search-table { min-width: 1000px; table-layout: fixed; }
        
        .leaderboard-search-table th:nth-child(1) { 
            width: 240px; 
            background: #fafafa; 
            border-right: 1px solid var(--gray-200); 
            position: sticky;
            top: 0;
            left: auto !important;
            z-index: 10;
        } 
        
        .leaderboard-search-table td.event-col {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            background: #fff;
            border-right: 1px solid var(--gray-200);
            position: static !important; 
            left: auto !important;
        }

        .leaderboard-search-table th:nth-child(2) { width: 100px; } 
        .leaderboard-search-table th:nth-child(3) { width: 60px; } 
        .leaderboard-search-table th:nth-child(5) { width: auto; } 
        .leaderboard-search-table th:nth-child(6) { width: 90px; }

        /* Sort Button */
        .sort-btn {
            display: inline-flex;
            align-items: center;
            gap: 4px;
            border: none;
            background: transparent;
            font: inherit;
            color: var(--gray-500);
            cursor: pointer;
            padding: 4px 0;
        }
        .sort-btn.active { color: #000; font-weight: 600; }

        /* Leaderboard Tabs */
        #lb-tabs {
            background: #fff;
            border-bottom: 1px solid #eaeaea;
            padding: 12px 16px;
            display: flex;
            gap: 8px;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
            flex-shrink: 0; 
            width: 100%;
            max-width: 100%;
            box-sizing: border-box;
            scrollbar-gutter: stable;
        }
        
        .lb-tab-btn {
            padding: 6px 14px;
            border-radius: 20px;
            border: 1px solid var(--gray-200);
            background: #fff;
            font-size: 0.85rem;
            color: #666;
            cursor: pointer;
            white-space: nowrap;
            display: flex;
            align-items: center;
            gap: 6px;
            transition: var(--transition);
            font-family: var(--font-sans);
        }
        
        .lb-tab-btn:hover {
            background: var(--gray-100);
            color: #000;
            border-color: #ccc;
        }

        .lb-tab-btn.active {
            background: #000;
            color: #fff;
            border-color: #000;
        }
        
        /* Leaderboard Tools */
        .lb-tools {
            padding: 12px 16px;
            border-bottom: 1px solid #eaeaea;
            background: #fafafa;
            flex-shrink: 0;
        }
        .lb-tools .search-input {
            background: #fff;
            height: 36px;
            padding-top: 0;
            padding-bottom: 0;
        }

        /* Team Modal */
        .modal-overlay {
            position: fixed; top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.45);
            backdrop-filter: blur(2px);
            z-index: 200;
            display: flex; align-items: center; justify-content: center;
            opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
        }
        .modal-overlay.open { opacity: 1; pointer-events: all; }
        .modal-content {
            background: #fff;
            width: 92%; max-width: 680px; max-height: 85vh;
            border-radius: 12px;
            box-shadow: var(--shadow-md);
            display: flex; flex-direction: column;
            overflow: hidden;
        }
        .modal-header {
            padding: 14px 18px;
            border-bottom: 1px solid var(--gray-200);
            display: flex; align-items: center; justify-content: space-between;
            background: #fafafa;
        }
        .modal-title { font-family: var(--font-heading); font-weight: 600; font-size: 1.1rem; margin: 0; }
        .modal-close { background: none; border: none; font-size: 22px; color: #666; cursor: pointer; line-height: 1; }
        .modal-body { padding: 16px 18px 20px; overflow-y: auto; }
        .chip {
            display: inline-flex; align-items: center; gap: 6px;
            padding: 6px 10px;
            background: var(--gray-100);
            border: 1px solid var(--gray-200);
            border-radius: 999px;
            font-size: 0.85rem;
            margin: 0 8px 8px 0;
        }
        
        /* Merger Composition Buttons */
        .comp-btn {
            display: inline-flex; align-items: center; justify-content: space-between;
            padding: 8px 14px;
            background: #fff;
            border: 1px solid var(--gray-200);
            border-radius: 6px;
            font-size: 0.9rem;
            margin: 0 8px 8px 0;
            cursor: pointer;
            transition: all 0.2s;
            color: #333;
            font-family: var(--font-sans);
            text-decoration: none;
        }
        .comp-btn:hover {
            background: var(--gray-100);
            border-color: #999;
            transform: translateY(-1px);
        }
        .comp-btn svg { margin-left: 6px; width: 14px; height: 14px; color: #999; }
        
        .section-title { font-weight: 600; margin: 8px 0 6px; }
        .modal-table-wrap { border: 1px solid var(--gray-200); border-radius: 8px; overflow: hidden; }
        .modal-chart { height: 220px; width: 100%; margin-top: 16px; }

        /* Animation for internal modal navigation */
        @keyframes slideInRight {
            from { opacity: 0; transform: translateX(10px); }
            to { opacity: 1; transform: translateX(0); }
        }
        .animate-slide-in {
            animation: slideInRight 0.25s ease-out forwards;
        }

        /* Help Section */
        details.help-card summary {
            list-style: none;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: space-between;
            font-size: 0.9rem;
            font-weight: 600;
            color: #333;
            user-select: none;
            -webkit-tap-highlight-color: transparent;
        }
        details.help-card summary::-webkit-details-marker { display: none; }
        details.help-card summary svg { transition: transform 0.2s ease; }
        details.help-card[open] summary svg { transform: rotate(180deg); }

        .help-content {
            margin-top: 12px;
            padding-top: 12px;
            border-top: 1px solid var(--gray-200);
            font-size: 0.85rem;
            line-height: 1.6;
            color: #444;
        }
        .help-content ul { padding-left: 20px; margin: 0; }
        .help-content li { margin-bottom: 6px; }
        .help-content a {
            color: #3b82f6;
            text-decoration: none;
            font-weight: 500;
            transition: color 0.2s ease;
        }
        .help-content a:hover {
            color: #2563eb;
        }
        
        /* Supplemental Paragraph Styles */
        .help-paragraph {
            margin-bottom: 12px;
            font-size: 0.85rem;
            color: #444;
            line-height: 1.6;
            margin-top: 0;
        }
        .help-subtitle {
            font-weight: 600;
            color: #333;
            margin-bottom: 6px;
            display: block;
        }

        .site-footer {
            margin-top: 4px;
            padding: 14px 2px 6px;
            color: #666;
            font-size: 0.83rem;
            line-height: 1.6;
            display: flex;
            flex-direction: column;
            gap: 2px;
            align-items: center;
            text-align: center;
        }

        .site-footer-line {
            display: flex;
            flex-wrap: wrap;
            gap: 4px;
            justify-content: center;
        }

        .site-footer a {
            color: #444;
            text-decoration: none;
            border-bottom: 1px dashed #bbb;
        }

        .site-footer a:hover {
            color: #111;
            border-bottom-color: #888;
        }

        /* Loading */
        .loading-overlay {
            position: absolute; top:0; left:0; width:100%; height:100%;
            background: rgba(255,255,255,0.7);
            backdrop-filter: blur(2px);
            z-index: 20;
            display: flex; justify-content: center; align-items: center;
            opacity: 0; pointer-events: none; transition: opacity 0.2s;
        }
        .loading-overlay.active { opacity: 1; pointer-events: all; }
        .spinner {
            width: 32px; height: 32px;
            border: 3px solid var(--gray-200);
            border-top-color: #000;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }
        @keyframes spin { to { transform: rotate(360deg); } }

         /* Mobile optimization */
        @media (max-width: 768px) {
            body { padding: 20px 12px; }
            h1 { font-size: 1.75rem; }
            .controls-header { flex-direction: column; align-items: stretch; gap: 10px; }
            .action-btn { width: 100%; }
            .mode-group { width: 100%; margin-bottom: 10px; }
            .mode-btn { flex: 1 1 30%; text-align: center; padding: 8px 4px; font-size: 0.8rem; }
            #chart-wrapper { height: 60vh; min-height: 350px; }
            
            .input-control-group { width: 100%; justify-content: flex-end; }

            .html-table-container { 
                overflow-x: auto; 
                -webkit-overflow-scrolling: touch; 
            }

            /* Mobile: keep wide tables with horizontal scrolling, no card layout */
            .datagrid-table { min-width: 1000px; }
            .leaderboard-table { min-width: 640px; }
            .leaderboard-search-table { min-width: 1000px; }
            .site-footer {
                font-size: 0.8rem;
                padding-top: 12px;
            }
        }
