:root {
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --gold: #d4af37;
    --gold-dark: #b8962e;
    --text-main: #2c3e50;
    --text-muted: #7f8c8d;
    --border-color: #e1e8ed;
    
    --correct-bg: #d4af37; /* Gold */
    --incorrect-bg: #d46c6c; /* Muted Subdued Red */
    --pending-bg: #eaeced; /* Gray */
}

* { box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: 'Rubik', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0 10px 20px 10px; /* Provides boundary space for desktop view limit */
}

/* Mobile specific: table completely flush with viewport edge */
@media (max-width: 600px) {
    body { padding: 0 0 20px 0; }
    .table-wrapper {
        border-radius: 0 !important;
        box-shadow: none !important;
        border-left: none !important;
        border-right: none !important;
    }
}

/* Tooltip */
.tooltip {
    position: fixed;
    background: rgba(17, 17, 17, 0.95);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    pointer-events: none;
    z-index: 9999;
    white-space: pre-wrap;
    text-align: left;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    font-weight: 400;
    left: 0; top: 0;
}
.tooltip.visible { opacity: 1; visibility: visible; }
.tooltip b { color: var(--gold); }

header { text-align: center; padding: 15px 5px 20px 5px; margin: 0; }
h1 { color: #111; margin: 0 0 4px 0; font-weight: 700; letter-spacing: -0.5px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px;}
.subtitle { color: var(--text-muted); font-size: 0.85rem; margin: 0; font-weight: 500; }

/* Latest Award Blob */
.latest-award-blob {
    display: inline-block;
    margin-top: 12px;
    padding: 6px 14px;
    background: linear-gradient(135deg, #fff9e6, #fff3cd);
    border: 1px solid #ffeeba;
    color: #856404;
    border-radius: 30px;
    font-size: 0.85rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    animation: blobFadeIn 0.4s ease forwards;
}
@keyframes blobFadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}
.latest-award-blob b { color: var(--gold-dark); margin-right: 4px; }
.latest-award-blob .winner {
    font-weight: 700;
    color: #111;
}
.latest-award-blob .pts {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255,255,255,0.6);
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 6px;
}

#loader { text-align: center; color: var(--gold-dark); font-size: 1.2rem; margin-top: 50px; font-weight: 500; }
.loading-pulse { animation: pulse 1.5s infinite ease-in-out; }
@keyframes pulse {
    0% { opacity: 0.5; }
    50% { opacity: 1; }
    100% { opacity: 0.5; }
}

/* Table Layout */
.table-wrapper {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    background: var(--card-bg);
    overflow: auto; /* Contains X and Y scrolling independently */
    max-height: calc(100vh - 110px); /* Keeps header pinned while table scrolls gracefully */
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
    border: 1px solid var(--border-color);
}

.leaderboard-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 700px;
}

.leaderboard-table th, .leaderboard-table td {
    padding: 8px 4px;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    box-sizing: border-box;
}

.leaderboard-table tbody tr:last-child td { border-bottom: none; }
.leaderboard-table tbody tr:hover td { background-color: #f8f9fa; }

.leaderboard-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #fafbfc;
    border-bottom: 2px solid var(--border-color);
    vertical-align: bottom;
    padding: 0; /* Handled by flex container */
    box-shadow: 0 2px 4px rgba(0,0,0,0.03); /* Subtle shadow on scroll */
}

/* Sticky Columns Setup */
.rank-col {
    width: 30px; min-width: 30px; max-width: 30px;
    font-weight: 600; color: var(--text-muted); font-size: 0.85rem;
    position: sticky; left: 0; z-index: 2;
    background: var(--card-bg);
}
.player-col {
    text-align: left !important;
    font-weight: 500;
    font-size: 0.8rem;
    line-height: 1.15;
    white-space: normal;
    word-break: break-word;
    padding-left: 12px !important;
    padding-right: 6px !important;
    width: 90px; min-width: 90px; max-width: 90px;
    position: sticky; left: 30px; z-index: 2;
    background: var(--card-bg);
}
.score-col {
    width: 35px; min-width: 35px; max-width: 35px;
    font-weight: 700; color: var(--gold-dark); font-size: 0.95rem;
    position: sticky; left: 105px; z-index: 2;
    background: var(--card-bg);
}
.possible-pts-col {
    width: 25px; min-width: 25px; max-width: 25px;
    position: sticky; left: 140px; z-index: 2;
    background-color: #e8f4f8 !important; /* Soft distinct color for Max Pts column */
    border-right: 2px solid #bce0ed !important;
}

.leaderboard-table th.rank-col {
    z-index: 16; /* Higher than other sticky columns to allow absolute overlap */
    background-color: #f1f3f5;
}

.leaderboard-table th.player-col,
.leaderboard-table th.score-col {
    z-index: 15;
    background-color: #f1f3f5;
}
.leaderboard-table th.possible-pts-col {
    z-index: 15;
    background-color: #d1ecf1 !important;
}

/* Sync hover colors for sticky cells */
.leaderboard-table tbody tr:hover .rank-col,
.leaderboard-table tbody tr:hover .player-col,
.leaderboard-table tbody tr:hover .score-col {
    background-color: #f8f9fa;
}
.leaderboard-table tbody tr:hover .possible-pts-col { background-color: #d1ecf1 !important; }

.max-pts-text { color: #0c5460 !important; font-weight: 700; }

/* Advanced Three-Tier Sticky Header */
.th-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 250px;
}
.th-top {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    position: relative;
    padding-bottom: 22px;
}
.th-middle {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid var(--border-color);
    background-color: #f8f9fa;
}
.th-bottom {
    height: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-top: 1px solid var(--border-color);
    background-color: #f1f3f5;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Top Left Area - Blended and blank for future stats */
.leaderboard-table th.rank-col .th-middle,
.leaderboard-table th.player-col .th-middle,
.leaderboard-table th.score-col .th-middle,
.leaderboard-table th.possible-pts-col .th-middle {
    background-color: transparent !important;
    border-top: none !important;
}
.leaderboard-table th.possible-pts-col .th-bottom { background-color: #d1ecf1 !important; border-top: 1px solid #bce0ed !important; }

.cat-col {
    width: 22px;
}

.vert-text {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    height: 160px; /* Increased for longer category names */
    margin: 0 auto;
    display: flex;
    align-items: center;
    white-space: nowrap;
}

.vert-text.completed {
    color: var(--gold-dark);
    font-weight: 700;
}

.winner-circle {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    cursor: pointer;
}
.winner-circle.gold { background-color: var(--gold); box-shadow: 0 0 4px var(--gold); }
.winner-circle.gray { background-color: #dcdcdc; }

.pts-legend-stack {
    position: absolute;
    right: 4px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    width: max-content;
    z-index: 5;
}
.pts-legend-half {
    background-color: burlywood;
    color: #352e12;
    font-size: 8px;
    font-weight: 700;
    text-align: center;
    padding: 3px 6px;
    border-radius: 2px;
    line-height: 1.1;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Slivers */
.sliver-container { padding: 0 2px; }

.pts-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 8pt;
    line-height: 1.1;
    font-weight: 600;
    color: #31708f;
}
.pts-stack span:first-child { color: #0c5460; font-weight: 700; font-size: 8pt; margin-bottom: 2px;}

.sliver {
    width: 16px;
    height: 32px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0 auto;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.sliver:hover {
    transform: scale(1.15);
}

.sliver-half {
    flex: 1;
    border-radius: 2px;
    width: 100%;
}

.status-correct { background-color: var(--correct-bg); }
.status-incorrect { background-color: var(--incorrect-bg); }
.status-pending { background-color: var(--pending-bg); }

/* Mock Rectangle Stack for Category Pts Row */
.pts-sliver { cursor: pointer; }

.pts-half {
    font-weight: 500;
    color: #352e12;
    background-color: burlywood;
    font-size: 9pt;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}
.modal-content {
    background: #fff;
    width: 90%;
    max-width: 800px;
    height: 90%;
    max-height: 900px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    position: relative;
    transform: translateY(20px);
    transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content {
    transform: translateY(0);
}
.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: #f1f3f5;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    transition: background 0.2s;
    z-index: 10;
}
.modal-close:hover { background: #e1e8ed; }
.modal-header {
    padding: 20px 20px 15px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h2 { margin: 0; color: var(--gold-dark); font-size: 1.5rem; }
.modal-body {
    padding: 20px;
    flex-grow: 1;
    overflow-y: auto;
}

/* Top Left Stats Area */
.top-left-stats {
    position: absolute;
    top: 0;
    left: 0;
    width: 180px;
    height: 100%;
    z-index: 30;
    padding: 10px 5px 0 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    pointer-events: auto;
}
.pot-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
    background: #e8f4f8;
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid #bce0ed;
    white-space: nowrap;
}
.prizes-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: -4px;
}
.prizes-boxes {
    display: flex;
    gap: 4px;
    width: 100%;
    justify-content: center;
}
.prize-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 2px;
    width: 50px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.prize-medal {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.prize-medal.gold { background: linear-gradient(135deg, #FFDF00, #D4AF37); }
.prize-medal.silver { background: linear-gradient(135deg, #E0E0E0, #A9A9A9); }
.prize-medal.bronze { background: linear-gradient(135deg, #CD7F32, #8B4513); }

.prize-amt {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-main);
}

.fun-btn {
    margin-top: auto;
    margin-bottom: 15px;
    width: 90%;
    justify-content: center;
    background: linear-gradient(135deg, #ffdf00, var(--gold-dark));
    color: #fff;
    border: 2px solid #ffe84d;
    border-radius: 30px;
    padding: 10px 15px;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 6px 15px rgba(212, 175, 55, 0.5);
    transition: all 0.2s ease;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    font-family: 'Rubik', sans-serif;
    animation: pulse-glow 2s infinite;
}
.fun-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(212, 175, 55, 0.6);
    animation: none;
}
.fun-btn svg {
    width: 44px;
    height: 44px;
    fill: #fff;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.3));
}

@keyframes pulse-glow {
    0% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.7); }
    70% { box-shadow: 0 0 0 12px rgba(212, 175, 55, 0); }
    100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0); }
}

/* Recent points tracker */
.recent-pts {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 4px;
    display: inline-block;
    vertical-align: text-bottom;
    white-space: nowrap;
}
.recent-pts.positive {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}
.recent-pts.negative {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* --- Fun Stats Panels --- */
.fun-panel {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.fun-panel-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 0;
    margin-bottom: 15px;
    border-bottom: 2px solid #f1f3f5;
    padding-bottom: 8px;
}

/* --- New Grid Layout for Player Awards --- */
.awards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}
@media (min-width: 768px) {
    .awards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
.award-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #f8f9fa;
    border: 2px solid #8c7721;
    border-radius: 8px;
    padding: 20px 15px;
    text-align: center;
}
.award-card .trophy-container {
    margin-right: 0;
    margin-bottom: 12px;
}
.award-card .stat-name {
    font-weight: 700;
    color: var(--text-main);
    font-size: 1.05rem;
    margin-bottom: 5px;
}
.award-card .stat-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    line-height: 1.4;
}

.chalk-award .award-info {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.chalk-award .award-players {
    width: 100%;
    margin-top: 15px;
    display: flex;
}
.chalk-award .award-players .chip {
    width: 100%;
}

/* For the chalk award spanning full width on desktop */
@media (min-width: 768px) {
    .chalk-award {
        grid-column: 1 / -1;
        flex-direction: row;
        text-align: left;
        align-items: stretch;
    }
    .chalk-award .award-info {
        align-items: flex-start;
        flex: 0 0 40%;
        padding-right: 20px;
        border-right: 1px dashed var(--border-color);
    }
    .chalk-award .award-players {
        flex: 1;
        padding-left: 20px;
        align-items: center;
        margin-top: 0;
    }
}

/* --- Legacy Stat Cards for Group Stats --- */
.stat-card {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 10px;
}
.stat-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-right: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    font-family: "Noto Emoji", sans-serif;
    font-weight: 600;
    color: var(--gold-dark);
}
.trophy-container {
    position: relative;
    width: 65px;
    height: 80px;
    min-width: 65px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
}
.trophy-svg {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
}
.trophy-emoji {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.4rem;
    z-index: 1;
    font-family: "Noto Emoji", sans-serif;
    font-weight: 700;
    color: #967615; /* Dark bronze/gold for the engraved look */
    text-shadow: 1px 1px 0px rgba(255, 255, 255, 0.4), -1px -1px 0px rgba(0, 0, 0, 0.1);
}
.stat-info {
    flex-grow: 1;
}
.stat-name {
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.95rem;
    margin-bottom: 3px;
}
.stat-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.chip {
    display: inline-block;
    padding: 4px 10px;
    background: #e1e8ed;
    color: #2c3e50;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    text-align: left;
}
.award-card .chip {
    background: #fffdf5;
    color: #856404;
    border: 2px solid #8c7721;
    box-shadow: 0 2px 4px rgba(212, 175, 55, 0.1);
    padding: 6px 12px;
    text-align: center;
}
.chip.winner-chip {
    background: #d4edda;
    color: #155724;
}
.chip.pending-chip {
    background: #fff3cd;
    color: #856404;
}
.chip.incorrect-chip {
    background: #f8d7da;
    color: #721c24;
}

.chip-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
    margin-top: 5px;
}
.chip b {
    color: var(--gold-dark);
    margin-right: 4px;
}
.award-card .chip b {
    display: none;
}

.stat-card.inactive {
    opacity: 0.6;
    background: #f1f3f5;
}
.stat-card.inactive .stat-icon {
    filter: grayscale(100%);
}

/* --- Category Breakdown --- */
.cat-breakdown-item {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px dashed var(--border-color);
}
.cat-breakdown-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}
.cat-breakdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.cat-breakdown-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}
.stacked-bar {
    display: flex;
    height: 12px;
    border-radius: 6px;
    overflow: hidden;
    background: #e1e8ed;
}
.bar-segment {
    height: 100%;
    transition: width 0.3s ease;
    cursor: pointer;
}
.bar-segment:hover {
    filter: brightness(1.1);
}
.bar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}
.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.legend-item.is-winner {
    background-color: #d4edda;
    color: #155724;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}
.legend-color {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}

/* Footer Credits */
.footer-credits {
    text-align: center;
    margin-top: 25px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.footer-credits a {
    color: var(--gold-dark);
    text-decoration: none;
    font-weight: 500;
}
.footer-credits a:hover {
    text-decoration: underline;
}

/* Player Filter Input */
.player-filter-wrapper {
    position: relative;
    width: 100%;
}
.player-filter-input {
    width: 100%;
    padding: 3px 18px 3px 4px;
    font-size: 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    background-color: #fff;
    box-sizing: border-box; /* Keeps it strictly inside the 90px width */
}
.player-filter-input:focus { border-color: var(--gold); }
.clear-filter-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 10px;
    color: #999;
    padding: 2px;
    display: none;
}
.clear-filter-btn:hover {
    color: #333;
}

/* Pinned Row Styling */
.pin-btn {
    position: absolute;
    left: -2px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    cursor: pointer;
    opacity: 0.15;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 10;
}
.player-row:hover .pin-btn {
    opacity: 0.4;
}
.pin-btn.active {
    opacity: 1 !important;
}
.pin-btn:hover {
    opacity: 1 !important;
    transform: translateY(-50%) scale(1.3);
}

.pinned-row td.player-col,
.pinned-row td.rank-col,
.pinned-row td.score-col {
    background-color: #fffbf0 !important;
}
.pinned-row:hover td {
    background-color: #fcf6e3 !important;
}
