/* Theme Custom Properties */
:root {
    /* Backgrounds */
    --bg-primary: #f5f5f5;
    --bg-section: white;
    --bg-card: white;
    --bg-input: white;
    --bg-table-header: #f8f9fa;
    --bg-table-alt-row: #f8f9fa;
    --bg-game-preview: #f8f9fa;
    --bg-active-game: #e7f3ff;
    --bg-completed-game: #f8f9fa;
    --bg-in-game-row: #e7f3ff;
    --bg-drag: #e3f2fd;
    --bg-drag-over: #e3f2fd;
    --bg-evaluation: #f8f9fa;
    --bg-modal: white;
    --bg-modal-overlay: rgba(0, 0, 0, 0.5);

    /* Text */
    --text-primary: #333;
    --text-secondary: #495057;
    --text-muted: #666;
    --text-link: #007bff;
    --text-link-hover: #0056b3;
    --text-modal-title: #333;
    --text-modal-body: #666;

    /* Borders */
    --border-primary: #ddd;
    --border-light: #eee;
    --border-input: #ddd;
    --border-card: #ddd;

    /* Badge colors */
    --badge-session-rank-bg: #28a745;
    --badge-overall-rank-bg: #007bff;
    --badge-points-bg: #ffc107;
    --badge-points-text: #333;
    --badge-games-bg: #fd7e14;
    --badge-wait-bg: #dc3545;
    --badge-gained-bg: #ffc107;
    --badge-gained-text: #333;
    --badge-wonlost-bg: #fff;
    --badge-wonlost-text: #111;
    --badge-wonlost-border: #ccc;
    --badge-wl-rank-bg: #6f42c1;
    --badge-avg-points-bg: #d4edda;
    --badge-avg-points-text: #155724;
    --badge-optimized-bg: #ff6b6b;

    /* Shadows and highlights */
    --shadow-card: rgba(0, 0, 0, 0.1);
    --highlight-bg: #2196f3;
    --highlight-text: white;
}

/* SVG icon styling for buttons */
.icon-svg {
  vertical-align: middle;
  margin-right: 0.4em;
  color: #fff;
}
/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.4;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    font-size: 18px;
}

.container {
    max-width: 100%;
    padding: 8px;
}

/* Section Styles */
section {
    background: var(--bg-section);
    margin-bottom: 12px;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 1px 3px var(--shadow-card);
}

.toolbar-section { padding: 8px 12px; }
.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}

h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

/* Attendance Header with Year Select */
.attendance-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.attendance-header h2 {
    margin-bottom: 0;
}

.year-select {
    padding: 6px 8px;
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    font-size: 16px;
    background: var(--bg-input);
    cursor: pointer;
}

/* Games Section */
.section-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    row-gap: 8px;
    margin-bottom: 12px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-left: auto;
    justify-content: flex-end;
}

.algorithm-select {
    padding: 6px 8px;
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    font-size: 16px;
    background: var(--bg-input);
}

/* Buttons */
.btn {
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: background-color 0.2s;
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
}

/* Add-player form: align inputs with buttons */
.add-player-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.player-input {
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.2;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    box-sizing: border-box;
}

/* Width modifiers for the add-player form */
.player-input--full {
    flex: 2 1 160px;
}

.player-input--half {
    flex: 1 1 80px;
    min-width: 60px;
}

/* Admin star badge in attendance list */
.admin-star {
    font-size: 0.55em;
    color: #e53e3e;
    vertical-align: super;
    margin-left: 2px;
    line-height: 1;
}

.player-admin-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    color: var(--text-primary);
}

/* Announcement download icon button in games header */
.announcement-download-btn {
    padding: 4px 8px;
    line-height: 1;
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #1e7e34;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-absent {
    background-color: #9aa0a6;
    color: #fff;
    border: 1px solid #7f858a;
}

.btn-absent:hover {
    background-color: #7f858a;
}

.btn-paused {
    background-color: #f0ad4e;
    color: #1a1a1a;
    border: 1px solid #c98a2e;
}

.btn-paused:hover {
    background-color: #ec971f;
}

/* Game Cards */
.game-card {
    border: 1px solid var(--border-card);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
}

.game-preview {
    background-color: var(--bg-game-preview);
}

.active-game {
    background-color: var(--bg-active-game);
}

.completed-game {
    background-color: var(--bg-completed-game);
}

.teams-container {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.team {
    flex: 1;
    border: 1px solid var(--border-primary);
    border-radius: 4px;
    padding: 8px;
    background: var(--bg-card);
}

.player-name {
    font-weight: 500;
    margin-bottom: 4px;
}

/* Wrapper for player-name + remove button inside a game card.
   Scoped to .game-card to avoid colliding with the .player-row <tr>
   used in the attendance table.
   Button sits directly next to the player name (not flush right) so it
   does not disappear under the absolutely-positioned .win-probability-badge
   in the team's top-right corner. */
.game-card .player-row {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    overflow: hidden;
}

.game-card .player-row .player-name {
    margin-bottom: 0;
    flex: 0 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.game-card .btn-remove-player {
    flex: 0 0 auto;
    min-width: 20px;
    background: none;
    border: none;
    color: #c00;
    cursor: pointer;
    font-size: 0.9em;
    padding: 0 4px;
    line-height: 1;
}

.game-card .btn-remove-player:hover {
    color: #900;
}

.player-badges {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
}

.badge {
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 12px;
    color: white;
    font-weight: 500;
}

.badge-session-rank { background-color: var(--badge-session-rank-bg); }
.badge-overall-rank { background-color: var(--badge-overall-rank-bg); }
.badge-rank { background-color: var(--badge-overall-rank-bg); }
.badge-points { background-color: var(--badge-points-bg); color: var(--badge-points-text); }
.badge-games { background-color: var(--badge-games-bg); }
.badge-wait { background-color: var(--badge-wait-bg); }
.badge-gained { background-color: var(--badge-gained-bg); color: var(--badge-gained-text); }
.badge-wonlost, .badge-points-vs {
  background-color: var(--badge-wonlost-bg);
  color: var(--badge-wonlost-text);
}

.badge-wl-rank {
  background-color: var(--badge-wl-rank-bg);
  color: white;
}

.badge-avg-points {
  background-color: var(--badge-avg-points-bg);
  color: var(--badge-avg-points-text);
}

.badge-optimized {
  background-color: var(--badge-optimized-bg);
  color: white;
  font-weight: 600;
}

/* Win probability badge positioning */
.win-probability-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
}

.team {
  position: relative;
}

/* Ensure badges for W/L and P/G are visible on all backgrounds */
.badge-wonlost, .badge-points-vs {
  background: var(--badge-wonlost-bg);
  color: var(--badge-wonlost-text);
  border: 1px solid var(--badge-wonlost-border);
  font-weight: 600;
}

.badge-gained .plus-sign {
    color: #fff !important;
}

.score-input {
    width: 60px;
    padding: 4px;
    border: 1px solid var(--border-input);
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
}

.game-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.suggestion-navigation.inline {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 12px;
}

.suggestion-navigation.inline .btn {
    min-width: 32px;
    height: 32px;
    padding: 4px 8px;
    font-size: 16px;
    background-color: #28a745;
    color: white;
}

.suggestion-navigation.inline .btn:hover:not(:disabled) {
    background-color: #1e7e34;
}

.suggestion-counter {
    font-weight: bold;
    min-width: 20px;
    text-align: center;
    color: var(--text-muted);
}

.score-display {
    font-size: 18px;
    font-weight: bold;
    text-align: center;
    margin-top: 8px;
}

.winner-icon {
    color: #28a745;
    margin-left: 4px;
}

/* Attendance Table */
.table-container {
    overflow-x: auto;
    margin-bottom: 12px;
}

.attendance-table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

.attendance-table th,
.attendance-table td {
    padding: 6px 2px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    font-size: 16px;
}

.attendance-table th {
    background-color: var(--bg-table-header);
    font-weight: 600;
    position: sticky;
    top: 0;
    text-align: center;
}

.attendance-table td:first-child {
    width: 20px;
    text-align: center;
    padding: 6px 1px;
}

.attendance-table td:nth-child(2) {
    width: 25px;
    text-align: center;
    padding: 6px 1px;
}

.attendance-table td:nth-child(3) {
    min-width: 100px;
    text-align: left;
}

.attendance-table .player-name {
    font-weight: 500;
    font-size: 18px;
    text-align: left !important;
}

.attendance-table td:nth-child(n+4) {
    text-align: right;
    width: 35px;
    padding: 6px 2px;
}


.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    height: 20px;
    max-height: 20px;
    line-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.drag-handle:active {
    cursor: grabbing;
}

.player-row.dragging {
    opacity: 0.5;
    background-color: var(--bg-drag);
}

.player-row.in-game {
    background-color: var(--bg-in-game-row);
}

.player-row.is-paused {
    background-color: rgba(240, 173, 78, 0.18);
}

.player-row.in-game input[type="checkbox"] {
    opacity: 0.5;
    pointer-events: none;
}

/* Larger checkboxes for mobile devices */
.attendance-table input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    margin: 0;
    vertical-align: middle;
}

.player-row.drag-over {
    border-top: 3px solid var(--highlight-bg);
    border-bottom: 3px solid var(--highlight-bg);
    background-color: var(--bg-drag-over) !important;
    position: relative;
}

.player-row.drag-over::before {
    content: "▼ Hier ablegen ▼";
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--highlight-bg);
    color: var(--highlight-text);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
    white-space: nowrap;
    pointer-events: none;
}

.player-row[draggable="true"]:hover {
    background-color: var(--bg-table-alt-row);
}


/* Touch optimizations */
@media (max-width: 480px) {
    .drag-handle {
        font-size: 18px;
        padding: 8px 4px;
        min-width: 20px;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .player-row.dragging {
        transform: scale(1.02);
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        background-color: #e3f2fd !important;
        z-index: 1000;
        position: relative;
        opacity: 0.8;
    }
    
    .player-row.drag-over {
        border-top: 4px solid #2196f3;
        border-bottom: 4px solid #2196f3;
        background-color: #e3f2fd !important;
        animation: pulse-drop-zone 1s ease-in-out infinite;
    }
    
    .player-row.drag-over::before {
        content: "👆 Hier ablegen";
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        background: #2196f3;
        color: white;
        padding: 3px 10px;
        border-radius: 6px;
        font-size: 14px;
        font-weight: bold;
        z-index: 10;
        white-space: nowrap;
        pointer-events: none;
    }
    
    /* Spezielle Touch-Target Klasse für noch bessere Sichtbarkeit */
    .player-row.touch-target {
        background-color: #e3f2fd !important;
        border-top: 4px solid #2196f3 !important;
        border-bottom: 4px solid #2196f3 !important;
        animation: pulse-drop-zone 0.8s ease-in-out infinite !important;
        position: relative !important;
    }
    
    .player-row.touch-target::before {
        content: "👆 TOUCH HIER";
        position: absolute !important;
        left: 50% !important;
        top: 50% !important;
        transform: translate(-50%, -50%) !important;
        background: #ff5722 !important;
        color: white !important;
        padding: 4px 12px !important;
        border-radius: 8px !important;
        font-size: 16px !important;
        font-weight: bold !important;
        z-index: 1000 !important;
        white-space: nowrap !important;
        pointer-events: none !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
    }
    .attendance-table {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

/* Evaluation Details */
.evaluation-details {
    margin-top: 15px;
    background: var(--bg-evaluation);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    animation: fadeIn 0.3s ease-in-out;
}

.evaluation-content {
    padding: 12px;
}

.evaluation-table {
    width: 100%;
    font-size: 13px;
    font-family: monospace;
    border-collapse: collapse;
}

.evaluation-table td {
    padding: 2px 8px 2px 0;
    color: var(--text-secondary);
}

.factor-name {
    width: 40%;
}

.factor-calc {
    width: 35%;
    text-align: right;
}

.factor-result {
    width: 25%;
    text-align: right;
    font-weight: 500;
}

.total-row {
    border-top: 1px solid var(--border-primary);
    margin-top: 4px;
}

.total-row td {
    padding-top: 6px;
    color: var(--text-secondary);
}

.total-result {
    font-weight: 600 !important;
    text-align: right;
}

.loading {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 12px;
}

.error {
    text-align: center;
    color: #dc3545;
    font-weight: 500;
    padding: 12px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-drop-zone {
    0%, 100% { 
        background-color: #e3f2fd !important;
        border-color: #2196f3;
    }
    50% { 
        background-color: #bbdefb !important;
        border-color: #1976d2;
    }
}

/* Info button styling */
.btn.btn-info {
    background-color: #17a2b8;
    border-color: #17a2b8;
    color: white;
    margin-left: 8px;
}

.btn.btn-info:hover {
    background-color: #138496;
    border-color: #117a8b;
}

/* Responsive evaluation details */
@media (max-width: 480px) {
    .evaluation-header {
        flex-direction: column;
        gap: 8px;
        align-items: flex-start;
    }
    
    .factor-breakdown {
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .evaluation-content {
        padding: 12px;
    }
}

/* Responsive Design */
@media (max-width: 320px) {
    .container {
        padding: 4px;
    }
    
    section {
        padding: 8px;
    }
    
    .teams-container {
        flex-direction: column;
        gap: 8px;
    }
}

/* Very narrow screens - only break when absolutely necessary */
@media (max-width: 280px) {
    .game-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .suggestion-navigation.inline {
        margin-left: 0;
        margin-top: 8px;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-modal-overlay);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.modal-content {
    background: var(--bg-modal);
    border-radius: 8px;
    padding: 20px;
    max-width: 90%;
    min-width: 300px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-content h3 {
    margin-bottom: 15px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-modal-title);
}

.modal-content p {
    margin-bottom: 20px;
    font-size: 16px;
    color: var(--text-modal-body);
    line-height: 1.5;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-buttons .btn {
    min-width: 80px;
    padding: 8px 16px;
    font-size: 14px;
}

/* Responsive Modal */
@media (max-width: 480px) {
    .modal-content {
        max-width: 95%;
        padding: 16px;
    }
    
    .modal-buttons {
        justify-content: stretch;
    }
    
    .modal-buttons .btn {
        flex: 1;
    }
}

/* Factor Edit Modal Slider Styles */
.factor-edit-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
    align-items: center;
}

.factor-edit-controls label {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-primary);
    text-align: center;
}

.weight-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--border-primary);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.weight-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.weight-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #007bff;
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.weight-slider::-webkit-slider-track {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #28a745 0%, #ffc107 50%, #dc3545 100%);
}

.weight-slider::-moz-range-track {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(to right, #28a745 0%, #ffc107 50%, #dc3545 100%);
    border: none;
}

/* --- Custom styles for completed game card result/time row --- */
.score-row-completed {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
  margin-top: 2px;
  margin-bottom: 2px;
  min-height: 24px;
}
.score-date-left {
  flex: 1;
  text-align: left;
  color: var(--text-muted);
  font-size: 13px;
  min-width: 60px;
}
.score-value-right {
  flex: 1;
  text-align: right;
  font-weight: bold;
  font-size: 20px;
}
.score-value-left {
  flex: 1;
  text-align: left;
  font-weight: bold;
  font-size: 20px;
}
.score-time-right {
  flex: 1;
  text-align: right;
  color: var(--text-muted);
  font-size: 13px;
  min-width: 60px;
}
.score-date-left, .score-time-right {
  font-size: 16px !important;
  font-family: inherit;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.2;
}

/* Revert badge-wonlost and badge-points-vs to previous style (if any) */
.badge-wonlost, .badge-points-vs {
  background: var(--badge-wonlost-bg);
  color: var(--badge-wonlost-text);
  border: 1px solid var(--border-primary);
  font-weight: 600;
  font-size: 13px;
  padding: 0 4px;
  min-width: 28px;
  display: inline-block;
  border-radius: 8px;
}

/* Responsive/mobile fix: ensure badge-wonlost and badge-points-vs are always visible on small screens */
@media (max-width: 600px) {
  .badge-wonlost, .badge-points-vs {
    font-size: 13px;
    min-width: 24px;
    padding: 0 3px;
  }
  .score-time-right {
    text-align: right !important;
    display: block;
    width: 100%;
  }
}

/* Highlighted player name */
.highlight {
    background-color: var(--highlight-bg) !important;
    font-weight: bold !important;
    color: var(--highlight-text) !important;
    padding: 2px 4px !important;
    border-radius: 3px !important;
}

/* Clickable player names */
.player-name {
    color: var(--text-link);
    text-decoration: underline;
    cursor: pointer;
}

.player-name:hover {
    color: var(--text-link-hover);
    text-decoration: underline;
}

/* Clickable player names in attendance list */
.attendance-table .player-name {
    color: var(--text-link);
    text-decoration: underline;
    cursor: pointer;
}

.attendance-table .player-name:hover {
    color: var(--text-link-hover);
    text-decoration: underline;
}

/* Sortable table headers */
.sortable-header {
    color: var(--text-link) !important;
    text-decoration: underline !important;
    cursor: pointer !important;
    user-select: none;
}

.sortable-header:hover {
    color: var(--text-link-hover) !important;
    background-color: rgba(0, 123, 255, 0.1);
}

/* Stats tables styling */
.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.85em;
}

.stats-table th, .stats-table td {
    border: 1px solid var(--border-primary);
    padding: 6px;
    text-align: left;
    white-space: nowrap;
}

.stats-table th {
    background-color: var(--bg-table-header);
    font-weight: bold;
}

.stats-table tbody tr:nth-child(even) {
    background-color: var(--bg-table-alt-row);
}

#player-stats-section h3 {
    margin-top: 15px;
    margin-bottom: 5px;
    font-size: 1.1em;
}

/* Dark Mode */
@media (prefers-color-scheme: dark) {
    :root {
        /* Backgrounds */
        --bg-primary: #1a1a2e;
        --bg-section: #16213e;
        --bg-card: #1a1a2e;
        --bg-input: #1a1a2e;
        --bg-table-header: #1a1a2e;
        --bg-table-alt-row: #16213e;
        --bg-game-preview: #16213e;
        --bg-active-game: #1a2744;
        --bg-completed-game: #16213e;
        --bg-in-game-row: #1a2744;
        --bg-drag: #1a2744;
        --bg-drag-over: #1a2744;
        --bg-evaluation: #1a1a2e;
        --bg-modal: #16213e;
        --bg-modal-overlay: rgba(0, 0, 0, 0.7);

        /* Text */
        --text-primary: #e0e0e0;
        --text-secondary: #b0b0b0;
        --text-muted: #888;
        --text-link: #5dade2;
        --text-link-hover: #85c1e9;
        --text-modal-title: #e0e0e0;
        --text-modal-body: #b0b0b0;

        /* Borders */
        --border-primary: #333;
        --border-light: #2a2a3e;
        --border-input: #444;
        --border-card: #333;

        /* Badge colors */
        --badge-session-rank-bg: #1e7e34;
        --badge-overall-rank-bg: #0069d9;
        --badge-points-bg: #d4a017;
        --badge-points-text: #fff;
        --badge-games-bg: #d46b08;
        --badge-wait-bg: #c82333;
        --badge-gained-bg: #d4a017;
        --badge-gained-text: #fff;
        --badge-wonlost-bg: #2a2a3e;
        --badge-wonlost-text: #e0e0e0;
        --badge-wonlost-border: #444;
        --badge-wl-rank-bg: #5a32a3;
        --badge-avg-points-bg: #1e4d2b;
        --badge-avg-points-text: #a3d9a5;
        --badge-optimized-bg: #cc4444;

        /* Shadows and highlights */
        --shadow-card: rgba(0, 0, 0, 0.3);
        --highlight-bg: #1976d2;
        --highlight-text: #fff;
    }

    /* Ensure icon SVGs adapt */
    .icon-svg {
        color: currentColor;
    }

    /* Fix score input for dark mode */
    .score-input {
        background-color: var(--bg-input);
        color: var(--text-primary);
    }

    /* Fix select elements for dark mode */
    .algorithm-select,
    .year-select {
        color: var(--text-primary);
    }

    /* Fix sortable header hover */
    .sortable-header:hover {
        background-color: rgba(93, 173, 226, 0.15);
    }

    /* Fix pulse animation for dark mode */
    @keyframes pulse-drop-zone {
        0%, 100% {
            background-color: var(--bg-drag-over) !important;
            border-color: var(--highlight-bg);
        }
        50% {
            background-color: #1a3050 !important;
            border-color: #1565c0;
        }
    }
}


/* Auto-mode UI */
.auto-mode-banner {
    background: #fff7e6;
    border: 1px solid #ffb84d;
    color: #663d00;
    padding: 8px 12px;
    border-radius: 4px;
    margin: 8px 0;
    font-size: 0.9em;
}
.btn-warning {
    background: #f0ad4e;
    color: #fff;
    border: 1px solid #eea236;
}
.btn-warning:hover {
    background: #ec971f;
}
#auto-mode-toggle.active {
    background: #28a745;
    color: #fff;
}

/* ===== Availability calendar (availability-calendar change) ===== */

.calendar-view {
    margin: 0 0 12px 0;
}
.calendar-view-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.calendar-view-header h2 { margin: 0; }
.calendar-view-header .calendar-back { margin-left: auto; }

.calendar-week {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.calendar-day-row {
    display: block;
    padding: 10px 12px;
    border: 1px solid var(--border-color, #ccc);
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    background: var(--bg-card, #fff);
}
.calendar-day-row.enough {
    border-color: #28a745;
    background: rgba(40, 167, 69, 0.08);
}
.calendar-day-row:hover { background: rgba(0, 123, 255, 0.06); }

.calendar-day-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.calendar-weekday { font-weight: 700; min-width: 2.2em; }
.calendar-date { color: var(--text-muted, #666); }
.calendar-weather { font-size: 0.9em; color: var(--text-muted, #555); }
.calendar-day-body {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-top: 6px;
}
.calendar-times { color: #28a745; font-weight: 600; }
.calendar-self-inline { color: #1565c0; }

.calendar-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--border-color, #ccc);
    background: var(--bg-table-alt-row, #f2f2f2);
    color: var(--text-primary, inherit);
    cursor: pointer;
    font-size: 0.95em;
}
.calendar-badge:hover {
    background: var(--bg-game-preview, #e6e6e6);
}

.calendar-weather-icon { font-size: 1.1em; }

/* Hash-router toggles main sections via this class so late-running
   scripts that set inline `style.display` cannot re-show them while a
   calendar route is active. */
.router-hidden { display: none !important; }

.calendar-hour-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-color, #eee);
}
.calendar-hour-row.self {
    background: var(--calendar-self-bg, rgba(21, 101, 192, 0.08));
}
@media (prefers-color-scheme: dark) {
    .calendar-hour-row.self {
        background: rgba(46, 160, 67, 0.28);
    }
}
.calendar-hour-weather {
    font-size: 0.85em;
    color: var(--text-muted, #666);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.calendar-hour-row .calendar-badge { justify-self: end; }
.calendar-hour-time-btns { display: flex; align-items: center; gap: 2px; }
.calendar-hour-btn {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    padding: 2px 5px;
    min-width: 28px;
    border: 1px solid var(--border-color, #ccc);
    border-radius: 4px;
    background: var(--calendar-btn-bg, #e9e9e9);
    color: var(--calendar-btn-fg, #222);
    cursor: pointer;
    font-size: 0.95em;
    white-space: nowrap;
    text-align: center;
}
.calendar-hour-btn.active {
    background: #28a745;
    border-color: #1e7e34;
    color: #fff;
}
.calendar-hour-btn.clear {
    background: #dc3545;
    border-color: #b02a37;
    color: #fff;
}
@media (prefers-color-scheme: dark) {
    .calendar-hour-btn {
        background: #2a2a3a;
        border-color: #555;
        color: #ddd;
    }
}
.calendar-hour-btn-sep { padding: 0 1px; color: var(--text-muted, #666); }

.calendar-loading,
.calendar-empty,
.calendar-error {
    padding: 16px;
    text-align: center;
    color: var(--text-muted, #666);
}
.calendar-error { color: #c62828; }

/* Next-session banner */
.next-session-banner {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    color: #0d47a1;
    padding: 10px 14px;
    border-radius: 6px;
    margin: 8px 0 0 0;
}
.next-session-banner-link {
    display: block;
    text-decoration: none;
    color: inherit;
}
.next-session-banner-link:hover { text-decoration: underline; }
.next-session-banner-sub {
    font-size: 0.9em;
    color: #1565c0;
    margin-top: 2px;
}

@media (max-width: 480px) {
    .calendar-hour-row {
        gap: 4px;
        padding: 6px 6px;
    }
    .calendar-hour-weather { font-size: 0.78em; }
    .calendar-hour-btn { min-width: 24px; padding: 2px 4px; font-size: 0.9em; }
}

.unit { font-size: 0.5em; vertical-align: super; }

.logout-word { display: none; }

/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP WIDE LAYOUT — 5 columns (min-width: 2500px)
   ~500 px per column; confirmed on 3840px monitor at 150% OS scaling.
   desktop-col-1w and #calendar-col use display:contents so their children
   become direct grid items (games+col-2 in cols 1-2, both calendar
   views in cols 4-5).
   ═══════════════════════════════════════════════════════════════════════ */
@media (min-width: 2500px) {
    body {
        overflow: hidden;
    }

    .container {
        display: grid;
        grid-template-columns: 19fr 24fr 19fr 19fr 19fr;
        grid-template-rows: auto 1fr;
        height: 100dvh;
        overflow: hidden;
        gap: 0 8px;
        padding: 4px 8px 0;
        box-sizing: border-box;
        align-items: start;
    }

    /* Toolbar spans all 5 columns, sits in row 1 */
    .toolbar-section {
        grid-column: 1 / -1;
        grid-row: 1;
        margin-bottom: 4px;
    }

    /* desktop-col-1w is transparent: games-section and desktop-col-2
       become direct grid children and get their own column assignments */
    .desktop-col-1w {
        display: contents;
    }

    /* Column 1: Games */
    .games-section {
        grid-column: 1;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        margin-bottom: 0;
    }

    /* Column 2: Attendance + Add Player */
    .desktop-col-2 {
        grid-column: 2;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-2 section {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Column 3: History + Player Stats */
    .desktop-col-3 {
        grid-column: 3;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-3 section {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* #calendar-col is transparent: both calendar views become direct grid items */
    #calendar-col {
        display: contents;
    }

    /* Column 4: Calendar Week View — always visible via display:block !important
       which overrides any JS-set inline style="display:none;" */
    #calendar-week-view {
        grid-column: 4;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        margin-bottom: 0;
        display: block !important;
    }

    /* Column 5: Calendar Day View — always visible */
    #calendar-day-view {
        grid-column: 5;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        margin-bottom: 0;
        display: block !important;
    }

    /* Back buttons not needed — both calendar views always visible */
    #calendar-week-view .calendar-back,
    #calendar-day-view .calendar-back {
        display: none;
    }

    /* Duplicate auth buttons in calendar headers are redundant —
       the main toolbar is always visible */
    #cal-login-button,
    #cal-logout-button,
    #day-login-button,
    #day-logout-button {
        display: none !important;
    }

    /* Calendar icon button is redundant — calendar always visible */
    #calendar-open-button {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP 4-COLUMN LAYOUT (2000px–2499px)
   Week and day calendar views are toggled inside #calendar-col (no stacking).
   ═══════════════════════════════════════════════════════════════════════ */
@media (min-width: 2000px) and (max-width: 2499px) {
    body {
        overflow: hidden;
    }

    .container {
        display: grid;
        grid-template-columns: 19fr 24fr 19fr 19fr;
        grid-template-rows: auto 1fr;
        height: 100dvh;
        overflow: hidden;
        gap: 0 8px;
        padding: 4px 8px 0;
        box-sizing: border-box;
        align-items: start;
    }

    /* Toolbar spans all 4 columns */
    .toolbar-section {
        grid-column: 1 / -1;
        grid-row: 1;
        margin-bottom: 4px;
    }

    /* desktop-col-1w transparent: games-section (col 1) and desktop-col-2 (col 2)
       become direct grid children */
    .desktop-col-1w {
        display: contents;
    }

    /* Column 1: Games */
    .games-section {
        grid-column: 1;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        margin-bottom: 0;
    }

    /* Column 2: Attendance + Add Player */
    .desktop-col-2 {
        grid-column: 2;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-2 section {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Column 3: History + Stats */
    .desktop-col-3 {
        grid-column: 3;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-3 section {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Column 4: Calendar wrapper — JS toggles week/day view inside */
    #calendar-col {
        grid-column: 4;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
    }

    /* Calendar views are toggled by JS (display:block/none).
       No display:block !important here — JS toggle must work. */

    /* Back button on week view not useful — main sections always visible */
    #calendar-week-view .calendar-back {
        display: none;
    }

    /* Calendar icon button not needed — calendar always visible */
    #calendar-open-button {
        display: none !important;
    }

    /* Duplicate auth buttons in calendar headers are redundant */
    #cal-login-button,
    #cal-logout-button,
    #day-login-button,
    #day-logout-button {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP 3-COLUMN LAYOUT (1500px–1999px)
   Col 1: Games + Attendance + Add Player
   Col 2: History + Stats
   Col 3: Calendar (toggle week ↔ day)
   ═══════════════════════════════════════════════════════════════════════ */
@media (min-width: 1500px) and (max-width: 1999px) {
    body {
        overflow: hidden;
    }

    .container {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-rows: auto 1fr;
        height: 100dvh;
        overflow: hidden;
        gap: 0 8px;
        padding: 4px 8px 0;
        box-sizing: border-box;
        align-items: start;
    }

    /* Toolbar spans all 3 columns */
    .toolbar-section {
        grid-column: 1 / -1;
        grid-row: 1;
        margin-bottom: 4px;
    }

    /* Column 1: Games + Attendance + Add Player stacked and scrollable */
    .desktop-col-1w {
        grid-column: 1;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-1w > * {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Column 2: History + Stats */
    .desktop-col-3 {
        grid-column: 2;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-3 section {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Column 3: Calendar wrapper (toggle) */
    #calendar-col {
        grid-column: 3;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
    }

    /* Back button on week view not needed — main sections always visible */
    #calendar-week-view .calendar-back {
        display: none;
    }

    /* Calendar icon button not needed — calendar always visible */
    #calendar-open-button {
        display: none !important;
    }

    /* Duplicate auth buttons in calendar headers are redundant */
    #cal-login-button,
    #cal-logout-button,
    #day-login-button,
    #day-logout-button {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP 2-COLUMN LAYOUT (600px–899px)
   Col 1 (top): Games + Attendance + Add Player
   Col 1 (bottom): History + Stats
   Col 2 (full height): Calendar (toggle week ↔ day)
   ═══════════════════════════════════════════════════════════════════════ */
@media (min-width: 1000px) and (max-width: 1499px) {
    body {
        overflow: hidden;
    }

    .container {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-template-rows: auto minmax(0, 1fr) minmax(0, 1fr);
        height: 100dvh;
        overflow: hidden;
        gap: 0 8px;
        padding: 4px 8px 0;
        box-sizing: border-box;
        align-items: start;
    }

    /* Toolbar spans both columns */
    .toolbar-section {
        grid-column: 1 / -1;
        grid-row: 1;
        margin-bottom: 4px;
    }

    /* Col 1, row 2: Games + Attendance + Add Player */
    .desktop-col-1w {
        grid-column: 1;
        grid-row: 2;
        overflow-y: auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-1w > * {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Col 1, row 3: History + Stats */
    .desktop-col-3 {
        grid-column: 1;
        grid-row: 3;
        overflow-y: auto;
        min-height: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }
    .desktop-col-3 section {
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Col 2, rows 2–3: Calendar wrapper (toggle, full height) */
    #calendar-col {
        grid-column: 2;
        grid-row: 2 / 4;
        overflow-y: auto;
        min-height: 0;
        height: 100%;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
    }

    /* Back button on week view not needed — main sections always visible */
    #calendar-week-view .calendar-back {
        display: none;
    }

    /* Calendar icon button not needed — calendar always visible */
    #calendar-open-button {
        display: none !important;
    }

    /* Duplicate auth buttons in calendar headers are redundant */
    #cal-login-button,
    #cal-logout-button,
    #day-login-button,
    #day-logout-button {
        display: none !important;
    }
}

/* -----------------------------------------------------------------------
   PAGE-ROUTE OVERLAY (>=1000px)
   #player-page and #invitations-page live outside the CSS grid container.
   In all desktop layouts the container is height:100dvh with overflow:hidden,
   so these sections need position:fixed to appear above the grid when active.
   JS calls hideMainSections() first so grid content is hidden behind them.
   ----------------------------------------------------------------------- */
@media (min-width: 1000px) {
    #player-page,
    #invitations-page {
        position: fixed;
        inset: 0;
        z-index: 50;
        overflow-y: auto;
        background: var(--bg-primary);
    }
}