:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface-2: #202633;
  --line: #2c3444;
  --text: #f3f4f6;
  --muted: #a3adbb;
  --ok: #22c55e;
  --danger: #dc2626;
  --warn: #f59e0b;
  --brand: #1d4ed8;
  --brand-ink: #ffffff;
  --accent: #fbbf24;
  --accent-ink: #111111;
  --accent-text: #fbbf24;
  --radius: 18px;
  --gap: 16px;
  font-size: 20px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.35;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  flex-direction: column;
}

input, textarea { -webkit-user-select: text; user-select: text; }

[hidden] { display: none !important; }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.25rem; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, label:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }

.noscript { padding: 24px; }

/* Kop */
#header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 10px 20px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand);
  color: var(--brand-ink);
  border-bottom: 4px solid var(--accent);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; background: none; border: 0; color: inherit; padding: 4px 0; text-align: left; }
.brand-logo, .brand-mark { width: 44px; height: 44px; border-radius: 12px; flex: none; }
.brand-logo { object-fit: contain; background: rgba(255, 255, 255, 0.92); padding: 3px; }
.brand-mark { display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 1.3rem; }
.brand-text { min-width: 0; }
.brand-name { font-weight: 800; font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-loc { font-size: 0.8rem; opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-right { display: flex; align-items: center; gap: 10px; flex: none; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  background: rgba(0, 0, 0, 0.35); color: #fff; white-space: nowrap;
}
.pill.warn { background: var(--warn); color: #111; }

.lang { display: inline-flex; border-radius: 12px; overflow: hidden; border: 2px solid rgba(255, 255, 255, 0.55); }
.lang button { background: transparent; border: 0; padding: 8px 14px; font-weight: 800; font-size: 0.9rem; color: inherit; min-height: 44px; }
.lang button[aria-pressed='true'] { background: var(--accent); color: var(--accent-ink); }

.btn-home { min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.55); background: transparent; font-weight: 800; color: inherit; }

/* Hoofdvlak */
#app { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 20px; }

.title { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.sub { color: var(--muted); font-size: 0.9rem; }

/* Knoppen */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 60px; padding: 12px 24px;
  border-radius: var(--radius); border: 2px solid var(--line);
  background: var(--surface-2); color: var(--text); font-weight: 700;
}
.btn:active { transform: translateY(1px); filter: brightness(1.12); }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-xl { min-height: 110px; font-size: 1.6rem; width: 100%; }
.btn-sm { min-height: 44px; padding: 6px 14px; font-size: 0.85rem; border-radius: 12px; }
.btn-ghost { background: transparent; }

.actions { display: grid; grid-template-columns: 2fr 1fr; gap: var(--gap); }

.footer-actions { display: flex; gap: var(--gap); justify-content: space-between; margin-top: auto; }
.footer-actions .btn { flex: 1; }
.footer-actions .btn-primary { flex: 2; }

/* Kaarten */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.empty { color: var(--muted); padding: 8px 0; }

.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.rank-list li { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.rank-num { font-weight: 800; color: var(--accent-text); text-align: center; }
.rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.rank-pts { font-weight: 800; }

.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.recent-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.recent-main { min-width: 0; }
.recent-line { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { color: var(--muted); font-size: 0.8rem; }
.score { color: var(--accent-text); }

/* Keuzekaarten */
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.choice { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 190px; padding: 20px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface); text-align: center; }
.choice strong { font-size: 1.6rem; }
.choice span { color: var(--muted); }
.choice:active { background: var(--surface-2); }

/* Spelers kiezen */
.players { display: flex; flex-direction: column; gap: 16px; flex: 1; }
.slots { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.slot-side { display: flex; flex-direction: column; gap: 8px; }
.slot-side h3 { font-size: 0.9rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.slot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 64px; padding: 10px 16px; border-radius: var(--radius); border: 2px dashed var(--line); background: var(--surface); text-align: left; font-weight: 700; width: 100%; }
.slot.filled { border-style: solid; background: var(--surface-2); }
.slot.active { border-color: var(--accent); border-style: solid; box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.25); }
.slot .placeholder { color: var(--muted); font-weight: 500; }
.slot .x { color: var(--muted); font-size: 1.2rem; }

.picker { display: flex; flex-direction: column; gap: 12px; }
.picker-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.input { flex: 1; min-width: 200px; min-height: 56px; padding: 10px 16px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface); color: var(--text); font: inherit; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 56px; padding: 0 8px; color: var(--muted); }
.switch input { width: 26px; height: 26px; accent-color: var(--brand); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; max-height: 46vh; overflow-y: auto; padding: 2px; }
.chip { min-height: 60px; padding: 8px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--surface-2); font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; }
.chip span.nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .tag { font-size: 0.7rem; color: var(--accent-ink); background: var(--accent); border-radius: 8px; padding: 2px 8px; flex: none; }
.chip:active { filter: brightness(1.2); }

/* Uitslag */
.sets { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--gap); }
.set-btn { min-height: 120px; font-size: 2.2rem; font-weight: 800; border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface); }
.set-btn:active { background: var(--brand); color: var(--brand-ink); }
.stepper-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stepper { display: inline-flex; align-items: center; gap: 12px; }
.stepper button { width: 64px; height: 64px; border-radius: 16px; border: 2px solid var(--line); background: var(--surface-2); font-size: 1.8rem; font-weight: 800; }
.stepper output { min-width: 44px; text-align: center; font-size: 2rem; font-weight: 800; }

.summary { text-align: center; padding: 32px 20px; border-radius: var(--radius); background: var(--surface); border: 2px solid var(--brand); display: flex; flex-direction: column; gap: 10px; }
.summary .big { font-size: 2rem; font-weight: 800; overflow-wrap: anywhere; }
.summary .meta { color: var(--muted); }
.summary .big-score { font-size: 3.2rem; font-weight: 800; color: var(--accent-text); }

.done { align-items: center; text-align: center; justify-content: center; flex: 1; gap: 18px; display: flex; flex-direction: column; }
.done .check { width: 110px; height: 110px; border-radius: 50%; background: var(--ok); display: grid; place-items: center; font-size: 4rem; color: #fff; }
.done .btn-row { display: flex; gap: var(--gap); width: 100%; max-width: 700px; flex-wrap: wrap; }
.done .btn-row .btn { flex: 1; min-width: 200px; }

/* Ranglijst */
.tabs, .chips { display: flex; gap: 10px; flex-wrap: wrap; }
.tab, .pchip { min-height: 52px; padding: 8px 20px; border-radius: 999px; border: 2px solid var(--line); background: var(--surface); font-weight: 700; }
.tab[aria-pressed='true'], .pchip[aria-pressed='true'] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.table-wrap { overflow-x: auto; }
table.board { width: 100%; border-collapse: separate; border-spacing: 0 8px; }
.board th { text-align: right; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 0 12px; font-weight: 700; }
.board th:first-child, .board th:nth-child(2) { text-align: left; }
.board td { padding: 12px; background: var(--surface-2); text-align: right; font-variant-numeric: tabular-nums; }
.board td:first-child { border-radius: 12px 0 0 12px; text-align: center; font-weight: 800; color: var(--accent-text); width: 56px; }
.board td:nth-child(2) { text-align: left; font-weight: 700; }
.board td:last-child { border-radius: 0 12px 12px 0; }
.board td.pts { font-weight: 800; }
.board tr.top td { background: #2a3142; }
.team-players { display: block; color: var(--muted); font-size: 0.75rem; font-weight: 500; }

/* Instellingen */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }

/* Dialoog en toast */
#modal .overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); display: grid; place-items: center; padding: 20px; z-index: 20; }
.dialog { width: min(560px, 100%); background: var(--surface); border: 2px solid var(--line); border-radius: 22px; padding: 24px; display: flex; flex-direction: column; gap: 16px; max-height: 92vh; overflow-y: auto; }
.dialog-actions { display: flex; gap: var(--gap); }
.dialog-actions .btn { flex: 1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; }
.field .hint { color: var(--muted); font-size: 0.8rem; }
.check-row { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; }
.check-row input { width: 28px; height: 28px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.error-text { color: #fca5a5; font-weight: 700; min-height: 1.35em; }

#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; max-width: min(640px, 92vw); padding: 14px 22px; border-radius: 16px; font-weight: 700; background: var(--surface-2); border: 2px solid var(--line); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); text-align: center; }
#toast.error { background: #7f1d1d; border-color: #ef4444; }
#toast.ok { background: #14532d; border-color: var(--ok); }

.setup { max-width: 640px; margin: 8vh auto 0; width: 100%; display: flex; flex-direction: column; gap: 18px; }
.center { text-align: center; padding: 60px 0; color: var(--muted); }

@media (max-width: 800px) {
  :root { font-size: 18px; }
  .actions, .cols, .slots, .choices { grid-template-columns: 1fr; }
  .sets { grid-template-columns: repeat(2, 1fr); }
  .set-btn { min-height: 88px; white-space: nowrap; }
  .choice { min-height: 120px; }
  #header { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .brand-loc { display: none; }
  .brand { gap: 8px; }
  .brand-logo, .brand-mark { width: 38px; height: 38px; }
  .brand-name { font-size: 1rem; white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; line-height: 1.15; }
  .head-right { gap: 6px; }
  .btn-home { padding: 8px 10px; }
  .lang button { padding: 8px 10px; }
  .board th, .board td { padding-left: 8px; padding-right: 8px; }
  .board td:first-child { width: 40px; }
  .c-played { display: none; }
  .grid { max-height: 38vh; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
