*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    background: #f5f5f5;
    color: #222;
    line-height: 1.4;
}

header {
    background: #c0392b;
    color: #fff;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
}

header h1 {
    margin: 0;
    font-size: 1.6rem;
}

header a {
    color: inherit;
    text-decoration: none;
}

main {
    max-width: 800px;
    margin: 2rem auto;
    padding: 0 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: env(safe-area-inset-bottom);
}

.kaart {
    background: #fff;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.kaart h2,
.kaart h3 {
    margin-top: 0;
}

label {
    display: block;
    margin: 0.75rem 0 0.25rem;
}

label.optie {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    min-height: 44px;
    padding: 0.5rem 0;
    font-weight: normal;
    cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
    width: 1.3rem;
    height: 1.3rem;
    margin: 0;
    flex-shrink: 0;
    accent-color: #c0392b;
}

/* Minimaal 16px voorkomt dat iOS inzoomt bij het selecteren van een veld. */
textarea,
input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 0.6rem;
    font: inherit;
    font-size: 16px;
    border: 1px solid #bbb;
    border-radius: 4px;
    background: #fff;
}

.knop {
    display: inline-block;
    min-height: 44px;
    margin-top: 1rem;
    padding: 0.7rem 1.2rem;
    border: none;
    border-radius: 4px;
    background: #c0392b;
    color: #fff;
    font: inherit;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.knop-secundair {
    background: #fff;
    color: #c0392b;
    border: 1px solid #c0392b;
}

.acties {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.melding {
    padding: 0.75rem 1rem;
    border-radius: 4px;
}

.melding-fout {
    background: #fdecea;
    color: #8a1c13;
}

.melding-info {
    background: #e8f5e9;
    color: #1b5e20;
}

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

table {
    border-collapse: collapse;
    width: 100%;
}

th,
td {
    padding: 0.5rem;
    border-bottom: 1px solid #ddd;
    text-align: left;
    vertical-align: top;
}

table.scores input[type="number"] {
    width: 5.5rem;
    padding: 0.4rem;
    -moz-appearance: textfield;
    appearance: textfield;
}

table.scores input[type="number"]::-webkit-inner-spin-button,
table.scores input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.phase-vinkje {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0.4rem 0 0;
    font-size: 0.85rem;
    white-space: nowrap;
    cursor: pointer;
}

.phase-status {
    display: block;
    margin-top: 0.4rem;
    font-size: 0.85rem;
    color: #666;
    white-space: nowrap;
}

thead small {
    font-weight: normal;
    color: #666;
}

.nieuwe-ronde {
    background: #fff8e1;
}

tfoot th,
tfoot td {
    font-weight: bold;
    border-bottom: none;
}

.toelichting {
    font-size: 0.9rem;
    color: #666;
}

.mobiel-label {
    display: none;
}

/* Telefoon: de scoretabel wordt een lijst met een kaart per ronde. */
@media (max-width: 640px) {
    header h1 {
        font-size: 1.3rem;
    }

    main {
        margin-top: 1rem;
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
    }

    .kaart {
        padding: 1rem;
        margin-bottom: 1rem;
    }

    .knop {
        display: block;
        width: 100%;
    }

    .niet-mobiel {
        display: none;
    }

    .acties {
        display: grid;
        grid-template-columns: 2fr 1fr;
        gap: 0.5rem;
        position: sticky;
        bottom: 0;
        z-index: 1;
        margin: 0 -1rem -1rem;
        padding: 0 1rem calc(0.75rem + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.95);
        border-top: 1px solid #eee;
        border-radius: 0 0 8px 8px;
    }

    .acties .knop {
        margin-top: 0.75rem;
    }

    .tabel-container {
        overflow: visible;
    }

    table.scores,
    table.scores tbody,
    table.scores tfoot,
    table.scores tr,
    table.scores th,
    table.scores td {
        display: block;
        width: 100%;
    }

    /* Verborgen, maar wel voorleesbaar. */
    table.scores thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    /* Nieuwste ronde bovenaan, zodat je niet hoeft te scrollen om in te voeren. */
    table.scores tbody {
        display: flex;
        flex-direction: column-reverse;
    }

    table.scores tr {
        margin-bottom: 0.75rem;
        border: 1px solid #ddd;
        border-radius: 6px;
        overflow: hidden;
    }

    table.scores tr > th {
        background: #f0f0f0;
        font-size: 1rem;
    }

    table.scores .nieuwe-ronde > th {
        background: #ffecb3;
    }

    table.scores td {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "label punten"
            "label phase";
        align-items: center;
        column-gap: 0.75rem;
        padding: 0.6rem 0.75rem;
    }

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

    table.scores .mobiel-label,
    .acties .mobiel-label {
        display: inline;
    }

    table.scores td > .mobiel-label {
        grid-area: label;
        display: block;
        font-weight: 600;
    }

    table.scores td > .mobiel-label small {
        display: block;
        font-weight: normal;
        color: #666;
    }

    table.scores td > input[type="number"] {
        grid-area: punten;
        width: 6rem;
        text-align: right;
    }

    table.scores td > .punten {
        grid-area: punten;
        text-align: right;
    }

    table.scores td > .phase-status {
        grid-area: phase;
        text-align: right;
        margin: 0;
    }

    table.scores td > .phase-vinkje {
        grid-area: phase;
        justify-content: flex-end;
        min-height: 44px;
        margin: 0;
    }

    table.scores tfoot td {
        grid-template-areas: "label punten";
        padding-top: 0.4rem;
        padding-bottom: 0.4rem;
        border-bottom: 1px solid #eee;
    }

    table.overzicht th,
    table.overzicht td {
        padding: 0.5rem 0.35rem;
        font-size: 0.95rem;
    }
}
