/* ---------------------------------------------------------------
   Padel Tournaments — mobile-first stylesheet
   --------------------------------------------------------------- */
:root {
  --bg:            #0d1512;
  --bg-elev:       #14201b;
  --bg-elev-2:     #1b2a23;
  --line:          #24382e;
  --line-soft:     #1c2b24;
  --text:          #e8f2ec;
  --text-dim:      #92a89c;
  --text-faint:    #63796d;
  --accent:        #52e3a4;
  --accent-ink:    #06231a;
  --accent-soft:   #52e3a41f;
  --warn:          #ffb454;
  --danger:        #ff6b6b;
  --gold:          #ffd166;
  --silver:        #cfd8dc;
  --bronze:        #d9a06b;
  --radius:        14px;
  --radius-lg:     20px;
  --tap:           48px;
  --pad:           16px;
  --safe-b:        env(safe-area-inset-bottom, 0px);
  --safe-t:        env(safe-area-inset-top, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body { overflow: hidden; }

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  position: relative;
}

/* ---------- top bar ---------- */
.topbar {
  flex: 0 0 auto;
  padding: calc(var(--safe-t) + 10px) var(--pad) 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  border-bottom: 1px solid var(--line-soft);
}
.topbar h1 {
  font-size: 18px;
  font-weight: 650;
  margin: 0;
  letter-spacing: -0.01em;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .sub {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0;
}
.icon-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: none;
  border-radius: 12px;
  background: var(--bg-elev);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.icon-btn:active { background: var(--bg-elev-2); }
.icon-btn.ghost { background: transparent; }

/* ---------- view ---------- */
.view {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px var(--pad) 28px;
}
.view.has-tabbar { padding-bottom: 12px; }

/* ---------- tab bar ---------- */
.tabbar {
  flex: 0 0 auto;
  display: flex;
  border-top: 1px solid var(--line-soft);
  background: var(--bg-elev);
  padding-bottom: var(--safe-b);
}
.tabbar:empty { display: none; }
.tabbar button {
  flex: 1 1 0;
  min-height: var(--tap);
  padding: 8px 4px 10px;
  border: none;
  background: none;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.tabbar button .ico { line-height: 0; }
.tabbar button .ico svg { width: 23px; height: 23px; display: block; }
.tabbar button.active { color: var(--accent); }

/* ---------- generic bits ---------- */
h2 { font-size: 15px; margin: 22px 0 10px; font-weight: 650; letter-spacing: -0.01em; }
h2:first-child { margin-top: 4px; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.small { font-size: 13px; }
.tiny  { font-size: 11.5px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.hidden { display: none !important; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 14px;
}
.card + .card { margin-top: 10px; }

.empty {
  text-align: center;
  padding: 46px 20px;
  color: var(--text-faint);
}
.empty .big { font-size: 40px; margin-bottom: 10px; }
.empty p { margin: 6px 0 0; font-size: 14px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: var(--tap);
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 650;
  font-family: inherit;
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.outline { background: transparent; border-color: var(--line); color: var(--text); }
.btn.subtle  { background: transparent; color: var(--text-dim); border-color: transparent; }
.btn.danger  { background: transparent; border-color: #46201f; color: var(--danger); }
.btn.block { display: flex; width: 100%; }
.btn.sm { min-height: 38px; padding: 8px 13px; font-size: 13.5px; border-radius: 11px; }

.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1 1 0; }

/* ---------- form controls ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > .lbl {
  display: block;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 7px;
}
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2392a89c' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* segmented control */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}
.segmented button {
  flex: 1 1 0;
  min-height: 40px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 640;
  cursor: pointer;
  padding: 6px 8px;
}
.segmented button.active { background: var(--accent); color: var(--accent-ink); }

/* chips (numeric presets) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px;
  min-width: 58px;
  padding: 8px 15px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  font-weight: 640;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

input[type="range"] {
  width: 100%;
  height: 34px;
  accent-color: var(--accent);
  background: transparent;
}

/* stepper */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 46px; height: 46px;
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 22px;
  font-family: inherit;
  cursor: pointer;
  display: grid; place-items: center;
}
.stepper .val {
  flex: 1 1 auto;
  text-align: center;
  font-size: 19px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: var(--tap); }
.switch .txt { font-size: 15px; }
.switch input { display: none; }
.switch .track {
  width: 50px; height: 30px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  position: relative;
  transition: background .15s;
  cursor: pointer;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .15s, background .15s;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); background: var(--accent-ink); }

/* ---------- player picker ---------- */
.picker-list { display: flex; flex-direction: column; gap: 6px; }
.picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line-soft);
  background: var(--bg-elev);
  cursor: pointer;
}
.picker-row.on { border-color: var(--accent); background: var(--accent-soft); }
.picker-row .name { flex: 1 1 auto; font-size: 15px; font-weight: 560; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-row .box {
  width: 24px; height: 24px;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 1.5px solid var(--line);
  display: grid; place-items: center;
  font-size: 13px;
  color: transparent;
}
.picker-row.on .box { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.avatar {
  width: 34px; height: 34px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px;
  font-weight: 700;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

/* ---------- match cards ---------- */
.match {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  overflow: hidden;
  margin-bottom: 12px;
}
.match .match-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  background: var(--bg-elev-2);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.match .match-head .done { color: var(--accent); }
.team {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
}
.team + .team { border-top: 1px solid var(--line-soft); }
.team .names { flex: 1 1 auto; min-width: 0; }
.team .names .n { font-size: 15.5px; font-weight: 620; line-height: 1.3; }
.team .score {
  flex: 0 0 auto;
  font-size: 26px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  text-align: right;
  color: var(--text-faint);
}
.team.win .score { color: var(--accent); }
.team.win .names .n { color: var(--text); }
.match .vs {
  position: relative;
  height: 0;
}
.match-actions { padding: 10px 14px 14px; }

/* ---------- score entry ---------- */
.score-entry { padding: 4px 0 0; }
.score-side { padding: 12px 2px; }
.score-side .who { font-size: 14px; font-weight: 620; margin-bottom: 10px; color: var(--text-dim); }
.score-big {
  display: flex;
  align-items: center;
  gap: 12px;
}
.score-big .num {
  flex: 1 1 auto;
  text-align: center;
  font-size: 46px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 6px 0;
  min-height: auto;
}
.score-big .num:focus { outline: none; }
.score-hint { text-align: center; font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.quick-scores { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 4px; }

/* ---------- leaderboard ---------- */
.lb { border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--line-soft); }
.lb-head, .lb-row {
  display: grid;
  grid-template-columns: 30px 1fr 46px 46px 52px;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
}
.lb-head {
  background: var(--bg-elev-2);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.lb-row { background: var(--bg-elev); border-top: 1px solid var(--line-soft); }
.lb-row:first-child { border-top: none; }
.lb-row .pos { font-size: 14px; font-weight: 750; color: var(--text-faint); text-align: center; }
.lb-row.p1 .pos { color: var(--gold); }
.lb-row.p2 .pos { color: var(--silver); }
.lb-row.p3 .pos { color: var(--bronze); }
.lb-row .nm { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .nm .tag { font-size: 11px; color: var(--text-faint); font-weight: 500; }
.lb-row .num { text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; color: var(--text-dim); }
.lb-row .pts { text-align: right; font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 750; }
.lb-row.resting { opacity: 0.62; }

/* ---------- misc ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-size: 11.5px;
  font-weight: 650;
}
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: #ffb4541f; color: var(--warn); }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  padding: 10px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  color: inherit;
  font-size: inherit;
}
.list-item .ttl { font-size: 15.5px; font-weight: 620; }
.list-item .meta { font-size: 12.5px; color: var(--text-faint); }
.list-item .chev { color: var(--text-faint); font-size: 20px; }

.rest-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  padding: 11px 13px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: transparent;
  margin-bottom: 12px;
}
.rest-strip .lbl { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-faint); }

.swap-chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 620;
  cursor: pointer;
  min-height: 34px;
}
.swap-chip.sel { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.swap-mode .team .names .n { cursor: pointer; }
.swap-mode .name-chip {
  display: inline-block;
  padding: 3px 9px;
  margin: -3px -3px 0;
  border-radius: 9px;
  border: 1px dashed var(--line);
}
.swap-mode .name-chip.sel { background: var(--accent); color: var(--accent-ink); border-style: solid; border-color: var(--accent); }

/* ---------- sheet / modal ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  animation: fade .15s ease;
}
.sheet {
  width: 100%;
  max-width: 620px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  padding: 8px var(--pad) calc(20px + var(--safe-b));
  animation: rise .2s cubic-bezier(.2,.8,.3,1);
}
.sheet .grabber {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--line);
  margin: 6px auto 12px;
}
.sheet h3 { margin: 0 0 14px; font-size: 17px; font-weight: 680; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- toast ---------- */
.toast-root {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(78px + var(--safe-b));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 80;
}
.toast {
  background: var(--bg-elev-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  animation: fade .15s ease;
}
