/* ===========================================================================
   Pétanque Lacanau — iOS-stijl (Apple HIG)
   SF Pro via -apple-system · semantische systeemkleuren · Light + Dark Mode
   =========================================================================== */

:root {
  /* labels */
  --label: #000000;
  --label2: rgba(60,60,67,.60);
  --label3: rgba(60,60,67,.30);
  /* achtergronden */
  --bg: #f2f2f7;                 /* systemGroupedBackground */
  --cell: #ffffff;              /* secondarySystemGroupedBackground */
  --cell-press: rgba(60,60,67,.09);
  --fill: rgba(120,120,128,.12);
  --sep: rgba(60,60,67,.29);
  /* systeemkleuren */
  --blue: #007aff;
  --blue-fill: rgba(0,122,255,.12);
  --green: #34c759;
  --green-fill: rgba(52,199,89,.14);
  --green-text: #248a3d;        /* donkerder groen voor tekst → AA-contrast op wit */
  --red: #ff3b30;
  --red-text: #d70015;
  --gold: #d99000;
  --gold-bg: rgba(255,196,0,.12);
  /* materiaal (nav/tab) */
  --bar: rgba(249,249,249,.80);
  --radius: 12px;
  --inset: 16px;
  /* tekststijlen */
  --font: -apple-system, "SF Pro Text", "SF Pro Display", system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --label: #ffffff;
    --label2: rgba(235,235,245,.60);
    --label3: rgba(235,235,245,.30);
    --bg: #000000;
    --cell: #1c1c1e;
    --cell-press: rgba(235,235,245,.13);
    --fill: rgba(118,118,128,.24);
    --sep: rgba(84,84,88,.65);
    --blue: #0a84ff;
    --blue-fill: rgba(10,132,255,.22);
    --green: #30d158;
    --green-fill: rgba(48,209,88,.22);
    --green-text: #30d158;       /* op zwart is het heldere groen al contrastrijk */
    --red: #ff453a;
    --red-text: #ff453a;
    --gold: #ffd60a;
    --gold-bg: rgba(255,214,10,.10);
    --bar: rgba(22,22,24,.80);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--label);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

.app { position: fixed; inset: 0; }

/* ---------------------------------------------------------- navigatiebalk */
.navbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  padding-top: env(safe-area-inset-top);
  background: transparent;
  transition: background .25s ease, box-shadow .25s ease;
}
.navbar.scrolled {
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 .5px 0 var(--sep);
}
.navbar-inner {
  height: 44px; display: flex; align-items: center; justify-content: center; position: relative;
  padding: 0 max(8px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-right));
}
.navbar-title {
  font-size: 17px; font-weight: 600; letter-spacing: -.2px; color: var(--label);
  opacity: var(--title-op, 0); max-width: 70%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.navbar-action {
  position: absolute; right: max(8px, env(safe-area-inset-right)); top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; display: grid; place-items: center;
  background: none; border: 0; color: var(--blue); cursor: pointer;
}
.navbar-action:active { opacity: .4; }
.navbar-action .sym { width: 26px; height: 26px; fill: currentColor; }
.navbar-leading { right: auto; left: max(8px, env(safe-area-inset-left)); }

/* ---------------------------------------------------------- scroll + large title */
.scroll {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-top: calc(44px + env(safe-area-inset-top));
  padding-bottom: calc(58px + env(safe-area-inset-bottom));
}
.largetitle { padding: 4px var(--inset) 8px; opacity: calc(1 - var(--title-op, 0)); }
.largetitle h1 {
  margin: 0; font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: .374px;
  color: var(--label); font-family: -apple-system, "SF Pro Display", system-ui, var(--font);
}

/* ---------------------------------------------------------- screens */
.screen { display: none; }
.screen.is-active { display: block; animation: screen-in .28s cubic-bezier(.32,.72,0,1); }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------- grouped lists */
.grouped-header {
  margin: 22px calc(var(--inset) + 4px) 7px; padding: 0;
  font-size: 13px; font-weight: 400; letter-spacing: .2px;
  text-transform: uppercase; color: var(--label2);
}
.grouped-footer {
  margin: 7px calc(var(--inset) + 4px) 0;
  font-size: 13px; line-height: 18px; color: var(--label2);
}
.group {
  background: var(--cell); border-radius: var(--radius);
  margin: 0 var(--inset) 18px; overflow: hidden;
}

/* cellen */
.cell {
  position: relative; display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 11px var(--inset);
  background: transparent; border: 0; text-align: left; color: var(--label);
  font-family: var(--font); font-size: 17px; cursor: default;
}
.cell:not(:last-child)::after {
  content: ""; position: absolute; left: var(--inset); right: 0; bottom: 0;
  height: .5px; background: var(--sep);
}
.cell-tap { cursor: pointer; -webkit-user-select: none; user-select: none; transition: background .12s ease; }
.cell-tap:active { background: var(--cell-press); }
.cell-rank {
  flex: 0 0 24px; font-size: 16px; font-weight: 400; color: var(--label2);
  font-variant-numeric: tabular-nums; text-align: center;
}
.cell-title { flex: 1; min-width: 0; font-size: 17px; color: var(--label);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-accessory { flex: 0 0 auto; display: grid; place-items: center; color: var(--label3); }
.chev { width: 8px; height: 13px; }

/* input-cel (spelers toevoegen) */
.cell-input { padding: 8px var(--inset); }
.cell-input textarea {
  width: 100%; border: 0; background: transparent; resize: none; outline: none;
  font-family: var(--font); font-size: 17px; line-height: 22px; color: var(--label);
  min-height: 44px;
}
.cell-input textarea::placeholder { color: var(--label3); }

/* ---------------------------------------------------------- knoppen */
.group-btns { margin: 0 var(--inset) 18px; display: flex; flex-direction: column; gap: 4px; }
.btn {
  appearance: none; border: 0; border-radius: var(--radius); font-family: var(--font);
  font-size: 17px; font-weight: 600; cursor: pointer; padding: 14px 16px;
  transition: opacity .15s ease, transform .06s ease; -webkit-user-select: none; user-select: none;
}
.btn:active { opacity: .7; }   /* iOS-knoppen dimmen, ze schalen niet */
.btn-filled { background: var(--blue); color: #fff; }
.btn-plain { background: transparent; color: var(--blue); font-weight: 400; padding: 12px; }
.btn-plain:disabled { color: var(--label3); opacity: 1; transform: none; cursor: default; }

/* ---------------------------------------------------------- rondes / wedstrijden */
.round-header { display: flex; align-items: baseline; justify-content: space-between; }
.round-header .status { text-transform: none; font-size: 13px; }
.round-header .status.done { color: var(--green-text); }
.round-header .status.busy { color: var(--label2); }

.match .cell-team { gap: 12px; }
.team-names { flex: 1; min-width: 0; font-size: 17px; color: var(--label); }
.team-names .equipe { display: block; font-size: 13px; color: var(--label2); margin-top: 1px; }
.cell-team.winner .team-names { color: var(--green-text); font-weight: 600; }
.score-field {
  flex: 0 0 62px; width: 62px; min-height: 44px; text-align: center;
  font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--label); background: var(--fill); border: 0; border-radius: 9px;
  outline: none; padding: 6px 4px; font-family: var(--font);
}
.score-field:focus { box-shadow: inset 0 0 0 2px var(--blue); }
.cell-team.winner .score-field { background: var(--green-fill); color: var(--green-text); }
.cell-save {
  justify-content: center; color: var(--blue); font-size: 17px; font-weight: 600;
  cursor: pointer; transition: background .12s ease;
}
.cell-save:active { background: var(--cell-press); }
.cell-save.done { color: var(--blue); font-weight: 400; }

/* ---------------------------------------------------------- stand */
.cell-stand { align-items: center; }
.cell-stand .cell-rank { font-weight: 700; color: var(--label2); }
/* Podium: goud / zilver / brons medailles */
.cell-stand.rank-1 .cell-rank,
.cell-stand.rank-2 .cell-rank,
.cell-stand.rank-3 .cell-rank {
  width: 24px; height: 24px; border-radius: 50%; color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
  box-shadow: inset 0 -1px 1px rgba(0,0,0,.22);
}
.cell-stand.rank-1 .cell-rank { background: linear-gradient(180deg,#f7cf5b,#d99000); }
.cell-stand.rank-2 .cell-rank { background: linear-gradient(180deg,#d7dbe0,#a8aeb6); }
.cell-stand.rank-3 .cell-rank { background: linear-gradient(180deg,#e0a877,#b06a30); }
.cell-stand.rank-1 { background: var(--gold-bg); }
.stand-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.stand-name { font-size: 17px; color: var(--label); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-stand.rank-1 .stand-name, .cell-stand.rank-2 .stand-name, .cell-stand.rank-3 .stand-name { font-weight: 600; }
.stand-caption { font-size: 13px; color: var(--label2); font-variant-numeric: tabular-nums; }
.stand-trailing { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.stand-w { font-size: 17px; font-weight: 600; color: var(--label); font-variant-numeric: tabular-nums; }
.stand-w small { font-size: 12px; font-weight: 600; color: var(--label2); margin-left: 2px; }
.stand-saldo { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stand-saldo.pos { color: var(--green-text); }
.stand-saldo.neg { color: var(--red-text); }
.stand-saldo.zero { color: var(--label2); }
.trophy { width: 15px; height: 15px; fill: var(--gold); margin-right: 1px; vertical-align: -2px; }

/* ---------------------------------------------------------- empty state */
.empty { text-align: center; padding: 60px 30px; color: var(--label2); }
.empty-glyph { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px;
  display: grid; place-items: center; background: var(--fill); }
.empty-glyph .sym { width: 30px; height: 30px; fill: var(--label2); }
.empty-title { margin: 0 0 4px; font-size: 17px; font-weight: 600; color: var(--label); }
.empty-sub { margin: 0; font-size: 15px; line-height: 20px; }

/* ---------------------------------------------------------- tabbalk */
.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 -.5px 0 var(--sep);
}
.tabitem {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 4px; min-height: 49px; background: none; border: 0; cursor: pointer;
  color: var(--label2); font-family: var(--font);
}
.tabitem .sym { width: 27px; height: 27px; fill: currentColor; transition: opacity .15s ease; }
.tabitem span { font-size: 10px; font-weight: 500; letter-spacing: .1px; }
.tabitem.is-active { color: var(--blue); }
.tabitem[data-tab="rondes"].is-active { color: #2e9e54; }   /* groen */
.tabitem[data-tab="stand"].is-active { color: #e08200; }    /* oranje */
.tabitem:active { opacity: .5; }

/* ---------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 80;
  background: rgba(40,40,42,.92); color: #fff; font-size: 15px; font-weight: 500;
  padding: 11px 18px; border-radius: 22px; max-width: 86vw; text-align: center;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(0,0,0,.28); transition: opacity .22s ease, transform .22s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: rgba(200,40,35,.95); }
.toast.ok { background: rgba(40,160,80,.95); }

/* ---------------------------------------------------------- alert (UIAlertController) */
.scrim {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 28px;
  background: rgba(0,0,0,.2); animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.alert {
  width: 270px; max-width: 100%; border-radius: 14px; overflow: hidden; text-align: center;
  background: rgba(250,250,250,.86); color: var(--label);
  -webkit-backdrop-filter: saturate(180%) blur(30px); backdrop-filter: saturate(180%) blur(30px);
  box-shadow: 0 12px 40px rgba(0,0,0,.25); animation: pop .26s cubic-bezier(.32,1.4,.6,1);
}
@media (prefers-color-scheme: dark) { .alert { background: rgba(40,40,42,.78); } }
@keyframes pop { from { opacity: 0; transform: scale(1.12); } to { opacity: 1; transform: scale(1); } }
.alert-body { padding: 19px 16px 15px; }
.alert-title { font-size: 17px; font-weight: 600; margin: 0 0 2px; }
.alert-msg { font-size: 13px; line-height: 18px; margin: 2px 0 0; color: var(--label); }
.alert-field {
  width: 100%; margin-top: 15px; padding: 9px 10px; font-size: 16px; font-family: var(--font);
  border: .5px solid var(--sep); border-radius: 6px; background: var(--cell); color: var(--label);
  outline: none;
}
.alert-field:focus { border-color: var(--blue); }
.alert-actions { display: flex; border-top: .5px solid var(--sep); }
.alert-actions.stacked { flex-direction: column; }
.alert-btn {
  flex: 1; padding: 12px 8px; background: none; border: 0; cursor: pointer;
  font-size: 17px; color: var(--blue); font-family: var(--font); min-height: 44px;
}
.alert-actions:not(.stacked) .alert-btn + .alert-btn { border-left: .5px solid var(--sep); }
.alert-actions.stacked .alert-btn + .alert-btn { border-top: .5px solid var(--sep); }
.alert-btn:active { background: var(--cell-press); }
.alert-btn.bold { font-weight: 600; }
.alert-btn.destructive { color: var(--red); }

/* ---------------------------------------------------------- action sheet */
.sheet-scrim {
  position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
  justify-content: flex-end; padding: 8px; background: rgba(0,0,0,.2); animation: fade .2s ease;
}
.sheet {
  padding-bottom: env(safe-area-inset-bottom);
  animation: sheet-up .32s cubic-bezier(.32,.72,0,1);
}
@keyframes sheet-up { from { transform: translateY(110%); } to { transform: none; } }
.sheet-group, .sheet-cancel {
  border-radius: 14px; overflow: hidden;
  background: rgba(250,250,250,.82);
  -webkit-backdrop-filter: saturate(180%) blur(30px); backdrop-filter: saturate(180%) blur(30px);
}
@media (prefers-color-scheme: dark) { .sheet-group, .sheet-cancel { background: rgba(40,40,42,.78); } }
.sheet-cancel { margin-top: 8px; }
.sheet-title { padding: 14px 16px; font-size: 13px; color: var(--label2); text-align: center;
  border-bottom: .5px solid var(--sep); }
.sheet-btn {
  width: 100%; padding: 18px 16px; background: none; border: 0; cursor: pointer;
  font-size: 17px; color: var(--blue); font-family: var(--font); min-height: 57px;
}
.sheet-btn + .sheet-btn { border-top: .5px solid var(--sep); }
.sheet-btn:active { background: var(--cell-press); }
.sheet-btn.destructive { color: var(--red); }
.sheet-btn.cancel { font-weight: 600; }

/* ---------------------------------------------------------- avatars (initialen) */
.avatar {
  flex: 0 0 auto; display: inline-grid; place-items: center; border-radius: 50%;
  background: var(--avb, var(--blue)); color: #fff; font-weight: 600; line-height: 1;
  letter-spacing: .2px; box-shadow: inset 0 0 0 .5px rgba(0,0,0,.08);
}
.av-md { width: 30px; height: 30px; font-size: 12px; }
.av-sm { width: 23px; height: 23px; font-size: 10px; }
.av-stack { flex: 0 0 auto; display: inline-flex; align-items: center; }
.av-stack .avatar { box-shadow: 0 0 0 2px var(--cell); }
.av-stack .avatar + .avatar { margin-left: -8px; }
.cell-stand .av-md { margin-right: 2px; }

/* ---------------------------------------------------------- spelregels (page sheet) */
.page-scrim {
  position: fixed; inset: 0; z-index: 110; background: rgba(0,0,0,.32);
  display: flex; flex-direction: column; justify-content: flex-end; animation: fade .2s ease;
}
.page-sheet {
  background: var(--bg); border-radius: 14px 14px 0 0; max-height: 92vh;
  display: flex; flex-direction: column; overflow: hidden;
  animation: sheet-up .38s cubic-bezier(.32,.72,0,1);
}
.page-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label3); margin: 7px auto 0; flex: 0 0 auto; }
.page-nav {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 6px 8px 10px 16px; flex: 0 0 auto;
}
.page-nav h2 { margin: 0; font-size: 17px; font-weight: 600; }
.page-done { background: none; border: 0; color: var(--blue); font-size: 17px; font-weight: 600;
  cursor: pointer; min-height: 44px; min-width: 44px; padding: 0 8px; }
.page-done:active { opacity: .4; }
.page-body { overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 2px 0 calc(24px + env(safe-area-inset-bottom)); }
.page-intro { margin: 4px var(--inset) 4px; font-size: 15px; line-height: 20px; color: var(--label2); }
.rule { align-items: flex-start; gap: 12px; }
.rule-emoji { flex: 0 0 24px; font-size: 19px; line-height: 24px; text-align: center; }
.rule-text { flex: 1; min-width: 0; font-size: 16px; line-height: 22px; color: var(--label); }
.rule-text b { font-weight: 600; }

/* ---------------------------------------------------------- teams (vaste teams) */
.team-card { position: relative; }
.team-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--team, var(--blue));
}
.team-head { gap: 10px; }
.team-dot { flex: 0 0 auto; width: 14px; height: 14px; border-radius: 50%; background: var(--team, var(--blue));
  box-shadow: inset 0 0 0 .5px rgba(0,0,0,.12); }
.team-name { font-weight: 700; }
.team-count { flex: 0 0 auto; font-size: 15px; color: var(--label2); font-variant-numeric: tabular-nums; }
.team-members { gap: 10px; }
.av-row { flex: 0 0 auto; display: inline-flex; align-items: center; }
.av-row .avatar { box-shadow: 0 0 0 2px var(--cell); }
.av-row .avatar + .avatar { margin-left: -7px; }
.team-member-names { flex: 1; min-width: 0; font-size: 15px; color: var(--label2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-team .tname { color: var(--team, var(--label)); font-weight: 700; }
.cell-stand .team-dot { margin: 0 1px; }
.team-names .equipe { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stand-caption { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.partij-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.partij-header .status { text-transform: none; font-weight: 600; }
.partij-header .status.done { color: var(--green-text); }
.partij-header .status.busy { color: var(--label2); }
.partij-del { background: none; border: 0; color: var(--label2); cursor: pointer;
  padding: 6px 8px; margin: -6px -4px -6px 0; border-radius: 8px; display: grid; place-items: center; }
.partij-del:active { background: var(--cell-press); }
