*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #1a5638;
    --primary-dark: #0c2e1e;
    --primary-light: #e4f2eb;
    --accent: #d4a017;
    --accent-light: #faf3dc;
    --court: #267a4a;
    --court-light: #d0eddb;
    --danger: #c53030;
    --danger-light: #fde8e8;
    --bg: #f0f2f1;
    --card: #ffffff;
    --text: #1a1a1a;
    --text-light: #7a7a7e;
    --border: #dfe3e0;
    --shadow: 0 1px 3px rgba(0,0,0,.06);
    --shadow-lg: 0 6px 18px rgba(0,0,0,.10);
    --radius: 14px;
    --tab-h: 56px;
    --header-h: 58px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --reserve: #7b61ff;
    --reserve-light: #ede8ff;
}
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg); color: var(--text); height: 100%; overflow: hidden;
    -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.app-header {
    position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    background: var(--primary-dark);
    background-image:
        linear-gradient(90deg, transparent 49.5%, rgba(255,255,255,.05) 49.5%, rgba(255,255,255,.05) 50.5%, transparent 50.5%),
        linear-gradient(0deg, rgba(255,255,255,.03) 0%, transparent 100%);
    padding: calc(var(--safe-top) + 12px) 16px 12px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 2px solid var(--accent);
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { display: flex; flex-direction: column; gap: 1px; }
.logo h1 { color: #fff; font-size: 1.05rem; font-weight: 800; letter-spacing: -0.4px; line-height: 1.1; }
.logo h1 span { color: var(--accent); }
.logo-subtitle { color: rgba(255,255,255,.45); font-size: 0.58rem; font-weight: 600; letter-spacing: 2px; text-transform: uppercase; }
.header-badge {
    background: rgba(255,255,255,.15); color: #fff; font-size: 0.75rem;
    font-weight: 600; padding: 4px 10px; border-radius: 20px;
}
.app-content {
    position: fixed; top: calc(var(--safe-top) + var(--header-h));
    bottom: calc(var(--tab-h) + var(--safe-bottom)); left: 0; right: 0;
    overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 20px;
}
.page { display: none; }
.page.active { display: block; }
.tab-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--tab-h) + var(--safe-bottom));
    background: #fff; border-top: 1px solid var(--border);
    display: flex; padding-bottom: var(--safe-bottom); z-index: 200;
    box-shadow: 0 -2px 10px rgba(0,0,0,.04);
}
.tab-item {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; background: none; border: none;
    color: var(--text-light); font-size: 0.6rem; font-weight: 600;
    font-family: inherit; cursor: pointer; padding: 4px 0;
}
.tab-item.active { color: var(--primary); }
.tab-icon { width: 24px; height: 24px; }
.tab-icon svg { width: 100%; height: 100%; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 12px; color: var(--primary-dark); }
.stats-bar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stat-card { background: var(--card); border-radius: 12px; padding: 10px 6px; text-align: center; box-shadow: var(--shadow); border-top: 2px solid var(--court); }
.stat-value { font-size: 1.2rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 0.6rem; color: var(--text-light); font-weight: 600; margin-top: 2px; }
.form-stack { display: flex; flex-direction: column; gap: 10px; }
.form-group label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-light); margin-bottom: 4px; }
.form-group input, .form-group select {
    width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
    border-radius: 10px; font-size: 16px; font-family: inherit;
    background: var(--bg); color: var(--text); -webkit-appearance: none; appearance: none;
}
.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8a8e' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 11px 18px; border: none; border-radius: 10px; font-size: 0.85rem;
    font-weight: 700; font-family: inherit; cursor: pointer; transition: opacity .15s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-accent { background: var(--accent); color: var(--primary-dark); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-sm { padding: 8px 12px; font-size: 0.75rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.player-list { list-style: none; }
.player-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.player-item:last-child { border-bottom: none; }
.player-num {
    width: 28px; height: 28px; background: var(--primary-light); color: var(--primary);
    font-size: 0.75rem; font-weight: 700; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.player-num.reserve { background: var(--reserve-light); color: var(--reserve); }
.player-info { flex: 1; min-width: 0; }
.player-name-text { font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.player-meta span { font-size: 0.7rem; color: var(--text-light); }
.badge { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 0.65rem; font-weight: 700; }
.badge-a { background: var(--primary-light); color: var(--primary); }
.badge-b { background: var(--accent-light); color: #b8860b; }
.badge-reserve { background: var(--reserve-light); color: var(--reserve); }
.badge-level { background: var(--court-light); color: var(--court); }
.badge-gender { background: #f0f0f5; color: #666; }
.delete-btn { width: 30px; height: 30px; border: none; background: var(--danger-light); color: var(--danger); border-radius: 8px; font-size: 0.8rem; cursor: pointer; flex-shrink: 0; }
.group-toggle { display: flex; background: var(--border); border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.group-toggle button { flex: 1; padding: 9px; border: none; border-radius: 8px; font-size: 0.8rem; font-weight: 700; font-family: inherit; background: transparent; color: var(--text-light); cursor: pointer; }
.group-toggle .active-group { background: #fff; color: var(--primary); box-shadow: var(--shadow); }
.round-pills { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 10px; margin-bottom: 4px; }
.round-pill { flex-shrink: 0; padding: 7px 14px; border-radius: 20px; border: 1.5px solid var(--border); background: #fff; font-size: 0.75rem; font-weight: 600; font-family: inherit; color: var(--text-light); cursor: pointer; }
.round-pill.active-round { background: var(--primary); color: #fff; border-color: var(--primary); }
.court-card { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; box-shadow: var(--shadow); border-left: 3px solid var(--court); }
.court-header { background: linear-gradient(135deg, var(--court) 0%, #1f6b3e 100%); color: white; padding: 10px 14px; font-size: 0.85rem; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.court-body { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; padding: 12px; gap: 8px; }
.team-block { text-align: center; }
.team-label { font-size: 0.65rem; font-weight: 700; text-transform: uppercase; color: var(--text-light); margin-bottom: 6px; letter-spacing: 0.5px; }
.team-player { font-size: 0.8rem; font-weight: 600; padding: 3px 0; }
.vs-divider { font-size: 0.7rem; font-weight: 800; color: var(--accent); align-self: center; padding: 0 4px; }
.win-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 12px 12px; }
.win-btn { padding: 9px 8px; border: 1.5px solid var(--border); border-radius: 8px; background: #fff; font-size: 0.75rem; font-weight: 700; font-family: inherit; color: var(--text-light); cursor: pointer; }
.win-btn.selected { background: var(--primary); color: #fff; border-color: var(--primary); }
.rest-indicator { background: var(--accent-light); border-radius: 10px; padding: 10px 14px; font-size: 0.8rem; color: #8b6914; font-weight: 600; margin-bottom: 10px; }
.confirm-bar { padding: 8px 0; text-align: center; }
.confirm-bar .btn { width: 100%; }
.schedule-timeline { border-left: 2px solid var(--primary-light); margin-left: 8px; padding-left: 14px; }
.schedule-item { position: relative; padding-bottom: 14px; }
.schedule-item::before { content: ''; position: absolute; left: -20px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.schedule-item.rest-item::before { background: var(--accent); }
.schedule-round { font-size: 0.75rem; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.schedule-detail { background: var(--bg); border-radius: 10px; padding: 10px; }
.schedule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.detail-label { font-size: 0.65rem; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.3px; }
.detail-value { font-size: 0.8rem; font-weight: 600; margin-top: 2px; }
.result-badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 0.7rem; font-weight: 700; margin-top: 4px; }
.result-win { background: var(--primary-light); color: var(--primary); }
.result-loss { background: var(--danger-light); color: var(--danger); }
.result-pending { background: var(--border); color: var(--text-light); }
.final-card { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.final-header { background: linear-gradient(135deg, var(--primary-dark) 0%, #1a5638 100%); color: #fff; padding: 20px 16px; text-align: center; position: relative; }
.final-header::after { content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: var(--accent); }
.final-header h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; opacity: .7; }
.final-header h2 { font-size: 1.2rem; margin-top: 4px; }
.final-header h2 span { color: var(--accent); }
.final-body { padding: 16px; }
.final-team { background: var(--bg); border-radius: 12px; padding: 14px; text-align: center; margin-bottom: 10px; border: 2px solid transparent; }
.final-team.winner { border-color: var(--accent); background: var(--accent-light); }
.team-source { font-size: 0.7rem; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.player-name { font-size: 1rem; font-weight: 700; padding: 2px 0; }
.crown-text { margin-top: 8px; font-size: 0.7rem; font-weight: 800; color: var(--accent); letter-spacing: 1px; }
.final-vs { text-align: center; font-size: 0.9rem; font-weight: 800; color: var(--accent); margin: 6px 0; }
.admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; min-width: 400px; }
.admin-table th { text-align: left; padding: 8px 6px; font-size: 0.65rem; font-weight: 700; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.3px; border-bottom: 2px solid var(--border); white-space: nowrap; }
.admin-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.admin-stat { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.admin-stat .val { font-size: 1.1rem; font-weight: 800; color: var(--primary); }
.admin-stat .lbl { font-size: 0.65rem; color: var(--text-light); font-weight: 600; margin-top: 2px; }
.result-item { padding: 10px 0; border-bottom: 1px solid var(--border); }
.result-item:last-child { border-bottom: none; }
.result-round-label { font-size: 0.7rem; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.result-match { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; padding: 4px 0; }
.toast { position: fixed; bottom: calc(var(--tab-h) + var(--safe-bottom) + 14px); left: 16px; right: 16px; background: var(--primary-dark); color: white; padding: 14px 16px; border-radius: 12px; font-size: 0.85rem; font-weight: 600; text-align: center; box-shadow: var(--shadow-lg); transform: translateY(120px); opacity: 0; transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); z-index: 300; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--danger); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty-icon { width: 56px; height: 56px; border-radius: 50%; background: var(--border); display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.empty-icon svg { width: 26px; height: 26px; stroke: var(--text-light); fill: none; stroke-width: 1.5; }
.empty-state h3 { font-size: 1rem; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 0.85rem; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 12px; }
.text-muted { color: var(--text-light); }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-head h2 { font-size: 1rem; font-weight: 700; color: var(--primary-dark); }
.admin-group-toggle { display: flex; gap: 6px; margin-bottom: 10px; }
.admin-group-toggle button { padding: 6px 14px; border: 1.5px solid var(--border); border-radius: 8px; background: #fff; font-size: 0.75rem; font-weight: 700; font-family: inherit; color: var(--text-light); cursor: pointer; }
.admin-group-toggle button.active-admin { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== LOGIN OVERLAY ===== */
.login-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(160deg, #0c2e1e 0%, #1a5638 50%, #0c2e1e 100%);
    background-size: cover;
    z-index: 9999; display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.login-overlay::before {
    content: ''; position: absolute; inset: 0;
    background:
        linear-gradient(0deg, transparent 48%, rgba(255,255,255,.03) 48%, rgba(255,255,255,.03) 52%, transparent 52%),
        linear-gradient(90deg, transparent 49%, rgba(255,255,255,.03) 49%, rgba(255,255,255,.03) 51%, transparent 51%);
    pointer-events: none;
}
.login-overlay.hidden { display: none; }
.login-box {
    background: var(--card); border-radius: 20px; padding: 36px 24px 28px;
    width: 100%; max-width: 360px; box-shadow: var(--shadow-lg);
    text-align: center;
}
.login-box h2 { font-size: 1.6rem; font-weight: 800; color: var(--primary-dark); margin-bottom: 2px; line-height: 1.15; }
.login-box h2 span { color: var(--accent); }
.login-box .login-sport { font-size: 0.68rem; font-weight: 700; color: var(--court); letter-spacing: 2.5px; text-transform: uppercase; margin-bottom: 6px; }
.login-box p { font-size: 0.85rem; color: var(--text-light); margin-bottom: 24px; }
.login-role-buttons { display: flex; flex-direction: column; gap: 12px; }
.login-role-btn {
    display: flex; align-items: center; gap: 14px; padding: 16px;
    border: 2px solid var(--border); border-radius: 14px; background: var(--bg);
    cursor: pointer; text-align: left; font-family: inherit; transition: all .15s;
}
.login-role-btn:active { transform: scale(0.97); }
.login-role-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.login-role-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.login-role-icon svg { width: 24px; height: 24px; stroke: #fff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.login-role-icon.player { background: var(--primary); }
.login-role-icon.scheids { background: #3b82f6; }
.login-role-icon.toeschouwer { background: #8b5cf6; }
.login-role-icon.admin { background: var(--accent); }
.login-role-icon.admin svg { stroke: var(--primary-dark); }
.login-role-info h3 { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.login-role-info span { font-size: 0.75rem; color: var(--text-light); }

/* Admin password modal */
.admin-pw-section { display: none; margin-top: 20px; }
.admin-pw-section.show { display: block; }
.admin-pw-section label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-light); margin-bottom: 6px; text-align: left; }
.admin-pw-section input {
    width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
    border-radius: 10px; font-size: 16px; font-family: inherit;
    background: var(--bg); color: var(--text); margin-bottom: 12px;
    -webkit-appearance: none; appearance: none;
}
.admin-pw-section input:focus { outline: none; border-color: var(--primary); }
.admin-pw-error { color: var(--danger); font-size: 0.8rem; font-weight: 600; margin-bottom: 10px; display: none; }
.admin-pw-back { font-size: 0.8rem; color: var(--text-light); cursor: pointer; margin-top: 8px; text-decoration: underline; border: none; background: none; font-family: inherit; }

/* Logout button in header */
.header-right { display: flex; align-items: center; gap: 8px; }
.logout-btn {
    background: rgba(255,255,255,.15); color: #fff; border: none;
    font-size: 0.7rem; font-weight: 600; padding: 4px 10px; border-radius: 20px;
    font-family: inherit; cursor: pointer; display: flex; align-items: center; gap: 4px;
}
.logout-btn:active { opacity: 0.7; }
.role-badge {
    background: var(--accent); color: var(--primary-dark);
    font-size: 0.65rem; font-weight: 700; padding: 3px 8px; border-radius: 20px;
}

/* Role-based hiding */
.admin-only { display: none; }
.admin-referee-only { display: none; }
.player-admin-only { display: none; }
.hide-spectator { display: block; }

/* Admin */
body.role-admin .admin-only { display: initial; }
body.role-admin button.admin-only { display: inline-flex; }
body.role-admin div.admin-only { display: block; }
body.role-admin .win-buttons.admin-only { display: grid; }
body.role-admin .admin-referee-only { display: initial; }
body.role-admin button.admin-referee-only { display: inline-flex; }
body.role-admin div.admin-referee-only { display: block; }
body.role-admin .win-buttons.admin-referee-only { display: grid; }
body.role-admin .player-admin-only { display: initial; }
body.role-admin button.player-admin-only { display: inline-flex; }
body.role-admin div.player-admin-only { display: block; }

/* Scheidsrechter */
body.role-scheids .admin-referee-only { display: initial; }
body.role-scheids button.admin-referee-only { display: inline-flex; }
body.role-scheids div.admin-referee-only { display: block; }
body.role-scheids .win-buttons.admin-referee-only { display: grid; }

/* Speler */
body.role-player .player-admin-only { display: initial; }
body.role-player button.player-admin-only { display: inline-flex; }
body.role-player div.player-admin-only { display: block; }

/* Toeschouwer & Scheids – hide registration form */
body.role-toeschouwer .hide-spectator { display: none; }
body.role-scheids .hide-spectator { display: none; }

/* Hide admin tab for non-admins */
.tab-admin-only { display: none; }
body.role-admin .tab-admin-only { display: flex; }