* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
    background: #f5f5f5;
}

h1 {
    margin-bottom: 0;
    color: #333;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.lang-switcher {
    display: flex;
    gap: 4px;
}

.lang-btn {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    transition: all 0.2s;
}

.lang-btn:hover {
    background: #f0f0f0;
}

.lang-btn.active {
    background: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

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

.panel {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.player-list {
    margin-top: 20px;
}

.player-item {
    position: relative;
    padding: 10px;
    padding-right: 28px;
    margin-bottom: 8px;
    background: #f8f8f8;
    border-radius: 4px;
    display: flex;
    align-items: flex-start;
}

.player-item.guest {
    background: #fff3e0;
    border-left: 3px solid #ff9800;
}

.player-item.disabled {
    background: #e0e0e0;
    border-left: 3px solid #9e9e9e;
    opacity: 0.7;
}

.player-item.disabled .player-name {
    text-decoration: line-through;
    color: #666;
}

.player-info {
    flex: 1;
    min-width: 0;
}

.btn-icon {
    position: absolute;
    width: 20px;
    height: 20px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 3px;
    background: transparent;
    color: #999;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.btn-delete {
    top: 4px;
    right: 4px;
    font-size: 18px;
}

.btn-delete:hover {
    background: #f44336;
    color: white;
}

.btn-edit-icon {
    bottom: 4px;
    right: 4px;
    font-size: 12px;
}

.btn-edit-icon:hover {
    background: #2196f3;
    color: white;
}

.player-tags {
    font-size: 11px;
    color: #666;
    margin-top: 3px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

.player-tags .tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 18px;
    padding: 0 4px;
    border-radius: 3px;
    font-weight: 600;
    font-size: 10px;
    cursor: default;
}

.player-tags .keeper { background: #ffeb3b; color: #333; }
.player-tags .side { background: #9c27b0; color: white; }
.player-tags .pos-pref { background: #00796b; color: white; }
.player-tags .pos-avoid { background: #c62828; color: white; }
.player-tags .lock { background: #37474f; color: white; }
.player-tags .partial { background: #6a1b9a; color: white; }
.player-tags .defense-skill { background: #1565c0; color: white; }
.player-tags .offense-skill { background: #e65100; color: white; }
.player-tags .guest { background: #ff9800; color: white; }
.player-tags .disabled-tag { background: #9e9e9e; color: white; }

button {
    padding: 10px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-right: 8px;
}

.btn-primary {
    background: #4CAF50;
    color: white;
}

.btn-secondary {
    background: #2196f3;
    color: white;
}

.btn-edit {
    background: #9e9e9e;
    color: white;
    padding: 6px 10px;
    font-size: 12px;
}

.btn-danger {
    background: #f44336;
    color: white;
    padding: 6px 10px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    margin-right: 4px;
    white-space: nowrap;
}

/* Modal styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    width: 400px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    margin: 0;
    line-height: 1;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
}

.modal-body .form-group {
    margin-bottom: 16px;
}

.modal-body .form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.modal-body .form-group input[type="text"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.modal-body .form-row {
    display: flex;
    gap: 12px;
}

.modal-body .form-row .form-group {
    flex: 1;
    /* Flex items default to min-width:auto, which refuses to shrink below the
       content's intrinsic width - that is how the star picker pushed past the
       modal edge instead of the column narrowing. */
    min-width: 0;
}

.modal-body .checkbox-group {
    display: flex;
    gap: 20px;
}

.modal-body .checkbox-group label {
    display: inline-flex;
    align-items: center;
    font-weight: normal;
    cursor: pointer;
}

.modal-body .checkbox-group input[type="checkbox"] {
    margin-right: 6px;
}

.modal-body select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: white;
}

/* 5-star skill picker (accessible radiogroup).
   Two pickers sit side by side in a .form-row, so the whole strip has to fit
   half the modal: five stars plus four gaps, at the WCAG minimum target size
   and no larger. */
.modal-body .star-picker {
    display: flex;
    gap: 2px;
}

.modal-body .star-picker .star {
    /* 24x24px is the floor, not a preference: WCAG 2.2 SC 2.5.8. */
    min-width: 24px;
    min-height: 24px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #bdbdbd;
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
}

.modal-body .star-picker .star.filled {
    color: #f5a623;
}

.modal-body .star-picker .star:focus-visible,
.modal-body .star-picker .star:focus {
    /* No offset: the modal clips horizontally, so a ring drawn outside the
       last star is cut off at the modal edge. */
    outline: 2px solid #1565c0;
    outline-offset: 0;
}

/* Tri-state line chips: neutral (border only) / prefer (green + check) /
   avoid (red + cross). State is carried by the symbol as well as the colour. */
.modal-body .line-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.modal-body .line-chips .line-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-height: 32px;
    padding: 4px 10px;
    margin: 0;
    border: 1px solid #bdbdbd;
    border-radius: 16px;
    background: white;
    color: #555;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.modal-body .line-chips .line-chip .chip-state {
    font-size: 12px;
    line-height: 1;
}

.modal-body .line-chips .line-chip.prefer {
    border-color: #2e7d32;
    background: #e8f5e9;
    color: #1b5e20;
}

.modal-body .line-chips .line-chip.avoid {
    border-color: #c62828;
    background: #ffebee;
    color: #b71c1c;
}

.modal-body .line-chips .line-chip:focus-visible,
.modal-body .line-chips .line-chip:focus {
    outline: 2px solid #1565c0;
    outline-offset: 1px;
}

.modal-body .line-chips-hint {
    font-size: 11px;
    color: #888;
    margin-top: 6px;
}

/* Per-period availability checkboxes */
.modal-body .availability-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
}

.modal-body .availability-group label {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    margin: 0;
    font-size: 13px;
    font-weight: normal;
    color: #555;
    cursor: pointer;
}

.modal-body .availability-group input[type="checkbox"] {
    margin-right: 6px;
}

.modal-body .section-label {
    font-size: 12px;
    text-transform: uppercase;
    color: #888;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
}

.section-header h2 {
    margin: 0;
}

.header-buttons {
    display: flex;
    gap: 4px;
}

.player-buttons {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
    justify-content: space-between;
}

.player-buttons-right {
    display: flex;
    gap: 4px;
}

.team-input {
    margin-bottom: 15px;
}

.team-input label {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    display: inline-block;
    width: 80px;
}

.team-input input[type="text"] {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    width: 180px;
}

/* Match settings group (team size, formation, keeper policy, bench streak) */
.match-settings {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.settings-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #888;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
}

.setting-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.setting-row label {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    /* Wide enough for the longest label in either language - Dutch
       "Leeftijdscategorie:" - so every row's select starts at the same x.
       A narrower box let that one row's dropdown sit out of line. */
    width: 134px;
    flex: 0 0 134px;
}

.setting-row select {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 13px;
}

.formation-hint {
    font-size: 11px;
    color: #888;
    margin-top: -4px;
    margin-bottom: 8px;
    margin-left: 118px;
}

/* Controls that do not apply to the selected format (keeper settings in 4v4). */
.setting-hidden { display: none !important; }

.rotation-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.rotation-header h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    color: #333;
}

.btn-clear-all {
    background: transparent;
    border: 1px solid #ccc;
    color: #666;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    margin: 0;
}

.btn-clear-all:hover {
    background: #f44336;
    border-color: #f44336;
    color: white;
}

.quarters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.quarter {
    background: white;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Half-time break between block 2 and 3 (8v8 only); spans the whole grid row */
.half-time-divider {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0;
}

.half-time-divider::before,
.half-time-divider::after {
    content: '';
    flex: 1;
    border-top: 2px dashed #a5d6a7;
}

.half-time-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #2e7d32;
}

.quarter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 2px solid #4CAF50;
    padding-bottom: 8px;
}

.quarter-header h3 {
    margin: 0;
    color: #333;
}

.btn-clear {
    background: #eee;
    border: none;
    color: #666;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    margin: 0;
}

.btn-clear:hover {
    background: #f44336;
    color: white;
}

.position {
    margin-bottom: 10px;
}

.position-label {
    font-weight: 600;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.position select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

.bench {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.bench-label {
    font-weight: 600;
    font-size: 12px;
    color: #999;
    margin-bottom: 4px;
}

.bench-players {
    font-size: 13px;
    color: #666;
}

.stats {
    margin-top: 20px;
    padding: 15px;
    background: #f8f8f8;
    border-radius: 4px;
}

.stats h4 {
    margin-bottom: 10px;
}

.stats-table {
    width: 100%;
    font-size: 13px;
}

.stats-table td {
    padding: 4px 8px;
}

.stats-table .unequal {
    color: #f44336;
    font-weight: 600;
}

.warning {
    background: #fff3cd;
    padding: 12px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 13px;
    color: #856404;
}

.controls {
    margin-bottom: 15px;
    display: flex;
    gap: 8px;
}

.controls button {
    white-space: nowrap;
}

#exportCanvas {
    display: none;
}

/* Responsive styles for tablets and mobile */
@media (max-width: 900px) {
    .container {
        grid-template-columns: 1fr;
    }

    .quarters-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 600px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 1.4em;
        margin-bottom: 15px;
    }

    .panel {
        padding: 15px;
    }

    /* Header buttons stack better */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .header-buttons {
        width: 100%;
        display: flex;
        gap: 6px;
    }

    .header-buttons button {
        flex: 1;
        margin-right: 0;
    }

    /* Quarters stack vertically on mobile */
    .quarters-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .quarter {
        padding: 12px;
    }

    /* Player list items - icon buttons stay in place on mobile */
    .player-item {
        padding-right: 28px;
    }

    /* Controls stack vertically */
    .controls {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .controls button {
        width: 100%;
        margin-right: 0;
    }

    /* Modal adjustments */
    .modal {
        width: 95%;
        max-height: 85vh;
    }

    .modal-header {
        padding: 12px 16px;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-body .form-row {
        flex-direction: column;
        gap: 0;
    }

    .modal-footer {
        padding: 12px 16px;
    }

    .modal-footer button {
        padding: 12px 16px;
    }

    /* Match settings stack label above control */
    .setting-row {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
    }

    .setting-row label {
        width: auto;
        flex: none;
    }

    .setting-row select {
        width: 100%;
    }

    .formation-hint {
        margin-left: 0;
        margin-top: 0;
    }

    /* Line chips: full-width rows are easier to hit on phones */
    .modal-body .line-chips .line-chip {
        flex: 1 1 30%;
    }

    /* Star picker: larger touch targets on phones */
    .modal-body .star-picker .star {
        min-width: 36px;
        min-height: 36px;
        font-size: 22px;
    }

    /* Team input */
    .team-input input {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Stats table */
    .stats-table {
        font-size: 12px;
    }

    /* Touch-friendly dropdowns */
    .position select {
        padding: 10px 8px;
        font-size: 14px;
    }

    /* Bench section */
    .bench-players {
        font-size: 12px;
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .player-tags span {
        font-size: 10px;
        padding: 1px 4px;
    }

    .header-buttons {
        flex-wrap: wrap;
    }

    .modal-body .checkbox-group {
        flex-direction: column;
        gap: 10px;
    }
}
