/* Rally. De baan als uitgangspunt: witte voorwand, rode lijnen, esdoorn vloer, zwarte bal met gele stip. */
:root {
  --wall: #F2F3EF;
  --paper: #FFFFFF;
  --ink: #17191C;
  --line: #D3271D;
  --line-dark: #A81D15;
  --dot: #F4C20D;
  --floor: #EAD3A8;
  --floor-deep: #B88E4E;
  --glass: #5C6870;
  --rule: #DADDD6;
  --good: #1F7A4D;
  --display: "Avenir Next Condensed", "sans-serif-condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --body: "Avenir Next", "Segoe UI", Roboto, system-ui, sans-serif;
  --tab-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--wall);
  color: var(--ink);
  font: 17px/1.4 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.locked { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }

.num { font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.muted { color: var(--glass); }
.small { font-size: 14px; }
.pos { color: var(--good); }
.neg { color: var(--line-dark); }

/* ------------------------------------------------ opbouw */
.page {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 14px) 16px calc(var(--tab-h) + var(--safe-b) + 28px);
  min-height: 100dvh;
}
.page.bare { padding-bottom: calc(var(--safe-b) + 28px); }

.top {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 48px; margin-bottom: 12px;
}
.top h1 { font: 700 34px/1 var(--display); letter-spacing: 0.01em; }
.wordmark { display: flex; align-items: center; gap: 10px; }
.wordmark .ball { width: 26px; height: 26px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: none; border-radius: 50%;
  display: grid; place-items: center; margin-right: -8px;
}
.icon-btn svg { width: 24px; height: 24px; }
.back {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px;
  margin-left: -6px; padding-right: 10px; color: var(--glass); font-weight: 600;
}
.back svg { width: 22px; height: 22px; }

section { margin-top: 26px; }
section > h2, .h2 {
  font: 700 22px/1.1 var(--display); letter-spacing: 0.01em;
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 10px;
}
section > h2 a, section > h2 button {
  font: 600 15px var(--body); color: var(--glass); background: none; border: 0;
  padding: 8px 0 8px 12px;
}

/* ------------------------------------------------ tabbalk: de vloer onder de rode lijn */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--floor);
  border-top: 4px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs nav { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--tab-h); }
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 600; color: #6B5330;
}
.tabs svg { width: 24px; height: 24px; }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"] span { box-shadow: 0 2px 0 var(--ink); }

/* ------------------------------------------------ knoppen */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 54px; padding: 12px 18px;
  border: 2px solid var(--ink); border-radius: 14px;
  background: var(--paper); color: var(--ink);
  font-weight: 700; font-size: 17px; text-align: center;
}
.btn svg { width: 22px; height: 22px; flex: none; }
.btn.primary { background: var(--line); border-color: var(--line); color: #fff; }
.btn.primary:active { background: var(--line-dark); }
.btn.dark { background: var(--ink); color: #fff; }
.btn.quiet { border-color: var(--rule); font-weight: 600; }
.btn.danger { border-color: transparent; background: none; color: var(--line-dark); font-weight: 600; min-height: 44px; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.55; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: grid; gap: 10px; }

/* ------------------------------------------------ rittenkaart */
.punch {
  background: var(--paper);
  border-radius: 18px;
  padding: 18px 18px 16px;
  box-shadow: 0 1px 0 var(--rule), 0 10px 24px -18px rgba(23, 25, 28, 0.55);
  position: relative;
  display: block;
}
.punch-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.punch-left { font: 700 56px/0.9 var(--display); letter-spacing: -0.01em; }
.punch-left small { font: 600 16px/1.2 var(--body); color: var(--glass); display: block; margin-top: 8px; letter-spacing: 0; }
.punch-rate { text-align: right; font-size: 14px; color: var(--glass); line-height: 1.3; }
.punch-rate b { display: block; font: 700 22px/1 var(--display); color: var(--ink); }
.punch-line { height: 4px; background: var(--line); border-radius: 2px; margin: 16px -18px 16px; }
.holes { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 9px; }
.hole {
  aspect-ratio: 1; border-radius: 50%; position: relative;
  background: var(--ink);
}
.hole.used { background: var(--wall); box-shadow: inset 0 2px 3px rgba(23, 25, 28, 0.28); }
.hole.bonus:not(.used)::before, .hole.bonus:not(.used)::after {
  content: ""; position: absolute; top: 50%; width: 18%; aspect-ratio: 1; border-radius: 50%;
  background: var(--dot); transform: translateY(-50%);
}
.hole.bonus:not(.used)::before { left: 26%; }
.hole.bonus:not(.used)::after { right: 26%; }
.punch-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 14px; font-size: 14px; color: var(--glass); }
.punch-foot .key { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex: none; }
.punch-foot .key i { width: 12px; height: 12px; border-radius: 50%; background: var(--ink); position: relative; display: inline-block; }
.punch-foot .key i::after { content: ""; position: absolute; inset: 4px 2px; background: radial-gradient(circle at 25% 50%, var(--dot) 1.6px, transparent 2px), radial-gradient(circle at 75% 50%, var(--dot) 1.6px, transparent 2px); }
.bar { height: 10px; border-radius: 5px; background: var(--wall); overflow: hidden; box-shadow: inset 0 1px 2px rgba(23,25,28,.2); }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 5px; }

.empty {
  background: var(--paper); border-radius: 18px; padding: 22px 18px; text-align: left;
  border: 2px dashed var(--rule);
}
.empty h3 { font: 700 24px/1.1 var(--display); margin-bottom: 6px; }
.empty p { color: var(--glass); margin-bottom: 16px; }

/* ------------------------------------------------ saldo */
.saldo { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; }
.saldo-cell { background: var(--paper); border-radius: 14px; padding: 12px 10px 11px; min-width: 0; }
.saldo-cell .who { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.saldo-cell .amt { font: 700 clamp(17px, 5.3vw, 23px)/1.1 var(--display); margin-top: 4px; white-space: nowrap; }
.me-tag { font-size: 11px; font-weight: 700; background: var(--dot); color: var(--ink); border-radius: 6px; padding: 1px 5px; }

/* ------------------------------------------------ lijsten */
.list { background: var(--paper); border-radius: 16px; overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px;
  border-top: 1px solid var(--rule); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left;
}
.row:first-child { border-top: 0; }
.row:active { background: var(--wall); }
.row-date { width: 44px; flex: none; text-align: center; line-height: 1; }
.row-date b { font: 700 26px/1 var(--display); display: block; }
.row-date span { font-size: 12px; font-weight: 600; color: var(--glass); }
.row-main { flex: 1; min-width: 0; }
.row-main > div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { text-align: right; flex: none; line-height: 1.15; }
.row-end b { font: 700 22px/1 var(--display); display: block; white-space: nowrap; }
.row-end span { font-size: 12px; color: var(--glass); }
.chev { width: 18px; height: 18px; color: var(--rule); flex: none; }
.month { font-size: 14px; font-weight: 600; color: var(--glass); margin: 20px 4px 8px; }
.month:first-child { margin-top: 0; }

.av {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; color: #fff; font: 700 15px/1 var(--display);
}
.av.sm { width: 20px; height: 20px; font-size: 11px; }
.c0 { background: var(--ink); } .c1 { background: var(--line); } .c2 { background: #2C6E8F; }
.c3 { background: var(--floor-deep); } .c4 { background: #4F7A3A; } .c5 { background: #7A4E8C; }

/* ------------------------------------------------ sessie */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--paper); border-radius: 16px; }
.facts div { padding: 14px 10px 12px; text-align: center; border-left: 1px solid var(--rule); min-width: 0; }
.facts div:first-child { border-left: 0; }
.facts b { font: 700 26px/1 var(--display); display: block; white-space: nowrap; }
.facts span { font-size: 13px; color: var(--glass); }
.who-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.pill { display: inline-flex; align-items: center; gap: 7px; background: var(--paper); border-radius: 20px; padding: 5px 12px 5px 5px; font-weight: 600; font-size: 15px; }
.note { margin-top: 12px; color: var(--glass); }

.duel { background: var(--paper); border-radius: 16px; padding: 14px; margin-bottom: 10px; }
.duel-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.duel-head .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.duel-head .name:last-child { text-align: right; }
.duel-head .tally { font: 700 34px/1 var(--display); white-space: nowrap; }
.duel-head .tally i { font-style: normal; color: var(--rule); padding: 0 4px; }
.games { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; justify-content: center; }
.game {
  border: 1.5px solid var(--rule); background: none; border-radius: 10px; min-height: 40px; padding: 4px 12px;
  font: 700 19px/1 var(--display); color: var(--glass);
}
.game b { color: var(--ink); }

/* ------------------------------------------------ stand */
.table { background: var(--paper); border-radius: 16px; overflow: hidden; }
.trow { display: grid; grid-template-columns: 24px 1fr 48px 54px 52px; align-items: center; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--rule); }
.trow:first-child { border-top: 0; }
.trow.head { font-size: 12px; font-weight: 600; color: var(--glass); padding-top: 10px; padding-bottom: 8px; }
.trow > *:nth-child(n+3) { text-align: right; }
.trow .rank { font: 700 22px/1 var(--display); color: var(--glass); }
.trow .pl { min-width: 0; }
.trow .pl b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.trow .n { font: 700 21px/1 var(--display); }
.form { display: flex; gap: 4px; margin-top: 5px; }
.form i { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); }
.form i.l { background: none; box-shadow: inset 0 0 0 1.5px var(--glass); }
.h2h { background: var(--paper); border-radius: 16px; padding: 14px; margin-bottom: 10px; }
.h2h .split { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin-top: 12px; background: var(--wall); gap: 2px; }
.h2h .split i:first-child { background: var(--ink); }
.h2h .split i:last-child { background: var(--line); }
.h2h .pts { display: flex; justify-content: space-between; font-size: 13px; color: var(--glass); margin-top: 6px; }

/* ------------------------------------------------ verrekenen */
.owe { background: var(--paper); border-radius: 16px; padding: 14px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px; }
.owe-text { flex: 1; min-width: 0; line-height: 1.3; }
.owe-text b { font: 700 26px/1.1 var(--display); display: block; }
.owe .btn { width: auto; min-height: 46px; padding: 8px 14px; font-size: 15px; }
.hint { font-size: 14px; color: var(--glass); margin-top: 10px; line-height: 1.45; }

/* ------------------------------------------------ formulieren in een sheet */
.sheet-back { position: fixed; inset: 0; background: rgba(23, 25, 28, 0.5); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 520px; margin: 0 auto; max-height: 92dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--wall); border-radius: 22px 22px 0 0; border-top: 4px solid var(--line);
  padding: 18px 16px calc(var(--safe-b) + 18px);
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .btn:active { transform: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { font: 700 28px/1 var(--display); }
.field { margin-bottom: 18px; }
.field > label, .field > .label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 8px; }
.field .help { font-size: 14px; color: var(--glass); margin-top: 6px; }
.input {
  width: 100%; min-height: 52px; padding: 10px 14px; background: var(--paper);
  border: 2px solid var(--rule); border-radius: 12px; font-size: 18px; -webkit-appearance: none; appearance: none;
}
.input:focus { outline: none; border-color: var(--ink); }
.input::placeholder { color: #B9BEB6; opacity: 1; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip span {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; min-width: 60px; padding: 8px 16px;
  background: var(--paper); border: 2px solid var(--rule); border-radius: 12px; font-weight: 600;
}
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 2px; }
.chip.wide { flex: 1 1 100%; }
.chip.wide span { width: 100%; justify-content: space-between; text-align: left; }
.chip.wide small { font-weight: 500; opacity: 0.75; font-size: 14px; }
.form-error { background: #FBE4E1; color: var(--line-dark); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-weight: 600; font-size: 15px; }
.score-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.score-pair label { display: block; font-weight: 600; font-size: 15px; margin-bottom: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-pair .input { font: 700 44px/1 var(--display); text-align: center; min-height: 84px; }

/* ------------------------------------------------ inloggen en begin */
.gate { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; max-width: 420px; margin: 0 auto; padding: 24px 22px calc(var(--safe-b) + 24px); }
.gate h1 { font: 700 64px/0.95 var(--display); }
.gate .gate-line { height: 6px; background: var(--line); margin: 18px -22px 22px; }
.gate p { color: var(--glass); margin-bottom: 22px; }

/* ------------------------------------------------ live tellen */
.teller { position: fixed; inset: 0; z-index: 30; display: grid; grid-template-rows: 1fr auto 1fr; background: var(--wall); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.side { border: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 0; min-height: 0; }
.side.a { background: var(--wall); color: var(--ink); padding-top: var(--safe-t); }
.side.b { background: var(--ink); color: #fff; padding-bottom: var(--safe-b); }
.side:active:not([disabled]) { filter: brightness(0.93); }
.side.b:active:not([disabled]) { filter: brightness(1.5); }
.side .t-name { font-size: 20px; font-weight: 600; max-width: 90%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side .t-score { font: 700 min(38vh, 62vw) / 0.82 var(--display); letter-spacing: -0.02em; }
.side .t-won { font-size: 15px; font-weight: 700; background: var(--dot); color: var(--ink); border-radius: 8px; padding: 3px 10px; }
.side .t-tap { font-size: 14px; opacity: 0.55; }
.t-bar { background: var(--line); color: #fff; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 8px 10px; min-height: 64px; }
.t-bar button { border: 0; background: rgba(255,255,255,0.16); color: #fff; font-weight: 700; font-size: 15px; min-height: 48px; padding: 6px 14px; border-radius: 12px; }
.t-bar button[disabled] { opacity: 0.4; }
.t-bar .t-left { justify-self: start; }
.t-bar .t-right { justify-self: end; }
.t-bar .t-mid { text-align: center; font-weight: 600; font-size: 15px; line-height: 1.2; }
.t-bar .t-save { background: #fff; color: var(--line-dark); font-size: 17px; padding: 6px 18px; }

/* ------------------------------------------------ melding */
#toast { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 60; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
#toast div { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 15px; max-width: 480px; box-shadow: 0 8px 24px -8px rgba(0,0,0,.5); }
#toast div.bad { background: var(--line-dark); }

@media (min-width: 560px) {
  body { background: #E6E8E2; }
  .page, .gate { background: var(--wall); }
}
