/* Stats page styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--gradient);
    min-height: 100vh;
    color: var(--ink);
    line-height: 1.6;
    padding: 20px 8px;
}

.container {
    max-width: 650px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--line-soft);
}

.header h1 {
    color: var(--ink-2);
    font-size: 24px;
    margin-bottom: 8px;
}

.header .subtitle {
    color: var(--muted);
    font-size: 14px;
}

.back-button {
    position: fixed;
    top: 15px;
    left: 15px;
    background: var(--gradient);
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    z-index: 1000;
    cursor: pointer;
    transition: all 0.3s ease;
}

.back-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

/* /stats is the only page with two of these. Both were .back-button, so both
   pinned to top:15/left:15 and the referee link — second in the DOM — painted
   over "Back to Game" and made the way out of /stats unclickable. The modifier
   class existed in stats.html from 2026-09-06 but was never given a rule.
   Anchored right rather than offset by a guessed pixel width, so it cannot
   collide again if either label changes. */
.referee-link {
    left: auto;
    right: 15px;
}

.stats-section {
    background: var(--surface-2);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
    border: 1px solid var(--line-soft);
}

.section-title {
    font-size: 18px;
    font-weight: bold;
    color: var(--ink);
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid var(--line);
    text-align: center;
}

.no-stats {
    text-align: center;
    color: var(--muted);
    font-style: italic;
    padding: 20px;
    background: var(--surface-2);
    border-radius: 8px;
    border: 2px dashed var(--line);
}

.collapsible-section {
    margin-bottom: 25px;
    background: var(--surface-2);
    border-radius: 10px;
    border: 1px solid var(--line);
    overflow: hidden;
}

.collapsible-toggle {
    padding: 15px 20px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--accent);
    color: white;
    user-select: none;
    transition: background 0.3s ease;
}

.collapsible-toggle:hover {
    background: #5a67d8;
}

.collapsible-toggle-text {
    font-weight: 600;
    font-size: 16px;
}

.collapsible-chevron {
    font-size: 14px;
    transition: transform 0.3s ease;
}

.collapsible-section.expanded .collapsible-chevron {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.collapsible-section.expanded .collapsible-content {
    max-height: 1200px;
}

.collapsible-inner {
    padding: 20px;
}

.winloss-explanation {
    background: #e8f5e9;
    border: 2px solid #4caf50;
    border-radius: 10px;
    padding: 20px;
}

.winloss-explanation h3 {
    color: #2e7d32;
    margin-bottom: 12px;
    font-size: 18px;
}

.winloss-explanation p {
    margin-bottom: 10px;
    color: var(--ink);
}

.winloss-explanation ul {
    margin: 10px 0 10px 20px;
}

.winloss-explanation li {
    margin-bottom: 6px;
    color: var(--ink);
}

.winloss-explanation strong {
    color: #2e7d32;
}

.counts-section {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 12px;
    margin-top: 12px;
    border-radius: 4px;
}

.counts-section strong {
    color: #856404;
}

.legend-columns {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.legend-column {
    background: white;
    border-radius: 8px;
    padding: 15px;
}

.legend-category {
    font-weight: bold;
    font-size: 14px;
    color: var(--ink);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--line-soft);
}

.legend-item {
    margin-bottom: 10px;
    padding: 8px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.legend-item:hover {
    background: #e3f2fd;
}

.legend-label {
    font-weight: 600;
    color: var(--accent);
    display: block;
    margin-bottom: 3px;
}

.legend-description {
    color: var(--muted);
    font-size: 13px;
    display: block;
}

.legend-note {
    padding: 15px;
    background: white;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 13px;
    color: var(--muted);
    border-left: 4px solid var(--accent);
}

.desktop-table {
    display: none;
}

.mobile-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.table-container {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
}

.stats-table th,
.stats-table td {
    padding: 8px 4px;
    text-align: center;
    border-bottom: 1px solid var(--line-soft);
}

.stats-table th {
    background: var(--accent);
    color: white;
    font-weight: 600;
    position: sticky;
    top: 0;
    font-size: 10px;
}

.stats-table tr:hover {
    background: var(--surface-2);
}

.player-link {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s;
}
.player-link:hover {
    color: var(--accent-2);
    text-decoration: underline;
}

.player-card {
    background: white;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid var(--line);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.player-card.rank-1 {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    border-color: #ffc107;
    box-shadow: 0 3px 8px rgba(255, 193, 7, 0.3);
}

.player-card.rank-2 {
    background: linear-gradient(135deg, #e2e3e5 0%, var(--surface-2) 100%);
    border-color: #6c757d;
}

.player-card.rank-3 {
    background: linear-gradient(135deg, #f4cccc 0%, #fce4ec 100%);
    border-color: #e91e63;
}

.player-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.player-rank {
    background: var(--accent);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
    min-width: 30px;
    text-align: center;
}

.player-name {
    font-weight: bold;
    font-size: 16px;
    flex-grow: 1;
    text-align: center;
}

.player-hands {
    background: var(--accent);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: bold;
}

.player-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 10px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 6px;
}

.stat-label {
    font-size: 11px;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 2px;
    text-transform: uppercase;
}

.stat-value {
    font-size: 14px;
    font-weight: bold;
}

.stat-value.bid-stat {
    color: #6f42c1;
}

.stat-value.nil-stat {
    color: var(--loss);
}

.stat-value.bags-stat {
    color: var(--bags);
}

.competitive-card {
    background: white;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid var(--line);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.competitive-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 6px;
}

.winning-stats {
    background: rgba(40, 167, 69, 0.1);
    border: 1px solid rgba(40, 167, 69, 0.2);
}

.losing-stats {
    background: rgba(220, 53, 69, 0.1);
    border: 1px solid rgba(220, 53, 69, 0.2);
}

.win-loss-record {
    font-size: 14px;
    font-weight: bold;
    color: var(--accent);
    text-align: center;
}

.win-loss-stat {
    color: var(--ink);
    font-weight: bold;
}

.win-stat {
    color: var(--win);
    font-weight: 600;
}

.loss-stat {
    color: var(--loss);
    font-weight: 600;
}

.monthly-container {
    margin-top: 15px;
}

.month-card {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 8px;
    background: white;
    border: 1px solid var(--line);
}

.month-card.current-month {
    background: linear-gradient(135deg, #e8f5e9 0%, #f1f8f4 100%);
    border: 2px solid #4caf50;
}

.month-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--line-soft);
}

.month-title {
    font-weight: bold;
    font-size: 15px;
    color: var(--ink);
}

.current-badge {
    background: #4caf50;
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
}

.month-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.table-note {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    margin-top: 8px;
    font-style: italic;
}

@media (min-width: 768px) {
    .container {
        padding: 25px;
        max-width: 900px;
    }

    .desktop-table {
        display: block;
    }

    .mobile-cards {
        display: none;
    }

    .player-stats {
        grid-template-columns: repeat(4, 1fr);
        gap: 10px;
    }

    .stat-item {
        padding: 10px;
    }

    .player-card {
        padding: 20px;
    }

    .player-header {
        margin-bottom: 15px;
    }

    .player-name {
        font-size: 18px;
    }

    .legend-columns {
        grid-template-columns: repeat(2, 1fr);
    }

    .competitive-stats {
        flex-direction: row;
        gap: 15px;
    }

    .stat-group {
        flex: 1;
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .month-stats {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px;
        margin: 0 4px;
    }

    .header h1 {
        font-size: 20px;
    }

    .back-button {
        top: 10px;
        left: 10px;
        padding: 8px 12px;
        font-size: 12px;
    }

    /* Side by side would be ~300px of button on a 320px phone. Stack instead:
       no width assumption, so it holds whatever the labels say. */
    .referee-link {
        top: 48px;
        left: 10px;
        right: auto;
    }

    .player-stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .stat-item {
        padding: 6px;
    }

    .stat-label {
        font-size: 10px;
    }

    .stat-value {
        font-size: 12px;
    }

    .winloss-explanation {
        padding: 15px;
    }

    .winloss-explanation h3 {
        font-size: 16px;
    }
}
