/* ---------------------------------------------------------------- tokens */
:root {
  --bg:        #0f1115;
  --bg-2:      #171a21;
  --card:      #1c2029;
  --card-2:    #232834;
  --line:      #2c323d;
  --text:      #eef1f6;
  --muted:     #8b94a5;
  --accent:    #c8ff28;   /* pickleball yellow-green */
  --accent-ink:#14180a;
  --live:      #2ee6a8;
  --warn:      #ffb020;
  --danger:    #ff5a5a;
  --teamA:     #4cc2ff;
  --teamB:     #ff8ac2;
  --radius:    16px;
  --tabbar-h:  calc(58px + env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Classes below set display, which would otherwise beat the UA rule for [hidden]. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior-y: contain;
}

body { padding-bottom: var(--tabbar-h); }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 17px; }
h2 { font-size: 15px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.ball {
  width: 26px; height: 26px; flex: none;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, #eaff7a, var(--accent) 60%, #9ccc12);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.25);
  position: relative;
}
.ball::after {
  content: "";
  position: absolute; inset: 5px;
  background:
    radial-gradient(circle at 25% 25%, rgba(0,0,0,.35) 1.6px, transparent 1.7px),
    radial-gradient(circle at 72% 30%, rgba(0,0,0,.35) 1.6px, transparent 1.7px),
    radial-gradient(circle at 40% 70%, rgba(0,0,0,.35) 1.6px, transparent 1.7px),
    radial-gradient(circle at 78% 72%, rgba(0,0,0,.35) 1.6px, transparent 1.7px);
}

.sub { margin: 1px 0 0; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  transition: background .3s;
}
.dot.on  { background: var(--live); box-shadow: 0 0 0 3px rgba(46,230,168,.15); }
.dot.off { background: var(--danger); }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 16px;
  width: 40px; height: 40px;
  border-radius: 12px;
  display: grid; place-items: center;
  cursor: pointer;
  flex: none;
}
.icon-btn.armed { border-color: var(--accent); background: rgba(200,255,40,.12); }

/* ----------------------------------------------------------------- views */
main { padding: 14px 14px 24px; max-width: 640px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.card-flat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}

.pill {
  display: inline-block;
  background: var(--card-2);
  color: var(--muted);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  margin-left: 6px;
}

.link {
  background: none; border: 0; padding: 4px 2px;
  color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer;
}

/* --------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 700;
  padding: 12px 16px;
  min-height: 46px;
  cursor: pointer;
  transition: transform .06s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); cursor: not-allowed; }
.btn.full { width: 100%; }
.btn.big { font-size: 17px; padding: 15px; width: 100%; }
.btn.ghost { background: var(--card-2); color: var(--text); border: 1px solid var(--line); }
.btn.ghost + .btn.ghost { margin-top: 8px; }
.btn.danger { color: var(--danger); border-color: rgba(255,90,90,.35); }
.btn.sm { min-height: 36px; padding: 7px 12px; font-size: 13px; border-radius: 10px; }

/* ---------------------------------------------------------------- courts */
.courts { display: grid; gap: 14px; margin-bottom: 14px; }

.court {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  overflow: hidden;
}
.court.live   { border-color: rgba(46,230,168,.4); }
.court.warn   { border-color: rgba(255,176,32,.55); }
.court.over   { border-color: rgba(255,90,90,.65); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,90,90,0); }
  50%      { box-shadow: 0 0 0 4px rgba(255,90,90,.14); }
}

.court-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
}
.court-name { font-weight: 700; font-size: 14px; }
.court-status { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.court.live .court-status { color: var(--live); }
.court.warn .court-status { color: var(--warn); }
.court.over .court-status { color: var(--danger); }

.court-body { padding: 14px; }

.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 46px;
  line-height: 1;
  letter-spacing: -0.02em;
  text-align: center;
  margin: 2px 0 10px;
}
.court.warn .clock { color: var(--warn); }
.court.over .clock { color: var(--danger); }

.bar { height: 5px; background: var(--card-2); border-radius: 999px; overflow: hidden; margin-bottom: 14px; }
.bar > i { display: block; height: 100%; background: var(--live); border-radius: 999px; transition: width 1s linear; }
.court.warn .bar > i { background: var(--warn); }
.court.over .bar > i { background: var(--danger); }

/* --------------------------------------------------------------- matchup */
.matchup { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.side { min-width: 0; }
.side-label {
  font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  margin-bottom: 6px;
}
.side.a .side-label { color: var(--teamA); }
.side.b .side-label { color: var(--teamB); }
.side.b { text-align: right; }

.pname {
  font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pname .dupr { font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.pname .lock { font-size: 11px; margin-left: 4px; }

.vs {
  font-size: 12px; font-weight: 800; color: var(--muted);
  background: var(--card-2); border-radius: 999px; padding: 4px 8px;
}

.court-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.court-actions .btn { min-height: 42px; font-size: 14px; }
.court-actions .wide { grid-column: 1 / -1; }
.btn.win-a { background: var(--teamA); color: #04121c; }
.btn.win-b { background: var(--teamB); color: #24081a; }

.empty-court { text-align: center; padding: 8px 0 4px; }
.empty-court p { color: var(--muted); font-size: 14px; margin: 0 0 12px; }

/* ----------------------------------------------------------------- queue */
.queue { list-style: none; margin: 0 0 12px; padding: 0; }
.queue li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.queue li:last-child { border-bottom: 0; }
.queue .pos {
  width: 24px; height: 24px; flex: none;
  border-radius: 8px;
  background: var(--card-2);
  color: var(--muted);
  font-size: 12px; font-weight: 800;
  display: grid; place-items: center;
}
.queue li.on-deck .pos { background: var(--accent); color: var(--accent-ink); }
.queue .grow { flex: 1; min-width: 0; }
.queue .meta { font-size: 12px; color: var(--muted); }
.qbtn {
  border: 1px solid var(--line); background: var(--card-2); color: var(--muted);
  width: 32px; height: 32px; border-radius: 9px; font-size: 14px; cursor: pointer; flex: none;
}

/* --------------------------------------------------------------- next up */
.next .teams { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.next-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 6px 0; }

/* --------------------------------------------------------------- players */
.players { display: grid; gap: 2px; }
.prow {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.prow:last-child { border-bottom: 0; }
.avatar {
  width: 36px; height: 36px; flex: none; border-radius: 11px;
  background: var(--card-2); color: var(--text);
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
}
.avatar.playing { background: rgba(46,230,168,.16); color: var(--live); }
.prow .grow { flex: 1; min-width: 0; }
.prow .nm { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.prow .stats { font-size: 12px; color: var(--muted); margin-top: 1px; }
.tag {
  font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 6px;
}
.tag.playing { background: rgba(46,230,168,.16); color: var(--live); }
.tag.queued  { background: rgba(200,255,40,.14); color: var(--accent); }
.tag.dupr    { background: rgba(76,194,255,.14); color: var(--teamA); }

/* --------------------------------------------------------------- history */
.history { display: grid; gap: 10px; }
.hrow { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.hrow .line { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.hrow .win { font-weight: 700; }
.hrow .win.a { color: var(--teamA); }
.hrow .win.b { color: var(--teamB); }
.hrow .when { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* -------------------------------------------------------------- settings */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 11px;
  padding: 12px;
  font: inherit;
  min-height: 46px;   /* 16px font + this height stops iOS zoom-on-focus */
}
textarea { resize: vertical; margin-bottom: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(200,255,40,.5); outline-offset: 1px; }

.mini-select { width: auto; min-height: 34px; padding: 5px 8px; font-size: 13px; border-radius: 9px; }

.checkline { display: flex; align-items: center; gap: 10px; font-size: 14px; margin-bottom: 12px; }
.checkline input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }

.addrow { display: flex; gap: 8px; align-items: center; }
.addrow input { flex: 1; }

.court-admin { display: grid; gap: 8px; margin-bottom: 12px; }
.court-admin .row { display: flex; gap: 8px; align-items: center; }

.danger-zone { border-color: rgba(255,90,90,.25); }

/* ----------------------------------------------------------------- tabbar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(15,17,21,.95);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
  background: none; border: 0; cursor: pointer;
  color: var(--muted);
  font: inherit; font-size: 10px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 9px;
}
.tab span { font-size: 19px; line-height: 1; }
.tab.active { color: var(--accent); }

/* ----------------------------------------------------------------- sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.sheet {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh;
  overflow-y: auto;
  animation: rise .2s ease;
}
@keyframes rise { from { transform: translateY(24px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet h3 { font-size: 17px; }

.picklist { display: grid; gap: 2px; max-height: 46vh; overflow-y: auto; margin-bottom: 14px; }
.picklist label {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.picklist input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.picklist .nm { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picklist .r { margin-left: auto; flex: none; padding-left: 8px; font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 14px);
  z-index: 80;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  max-width: 88vw;
  box-shadow: 0 8px 28px rgba(0,0,0,.45);
  animation: rise .18s ease;
}
.toast.err { border-color: rgba(255,90,90,.5); color: #ffbcbc; }

/* ----------------------------------------------------------------- alarm */
.alarm {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(10, 6, 6, .93);
  display: grid; place-items: center;
  padding: 24px;
  animation: fade .2s ease;
}
.alarm-inner { text-align: center; max-width: 340px; width: 100%; }
.alarm-emoji { font-size: 62px; animation: shake .7s ease-in-out infinite; }
@keyframes shake {
  0%, 100% { transform: rotate(-9deg); }
  50%      { transform: rotate(9deg); }
}
.alarm h2 { font-size: 30px; margin: 10px 0 6px; color: var(--danger); }
.alarm p { color: var(--muted); margin: 0 0 22px; font-size: 15px; }


/* ============================================================ player view */
/* ?live=1 keeps the board and drops everything that runs the session. */
.live-mode .admin-only { display: none !important; }
.live-mode .tabbar { grid-template-columns: repeat(4, 1fr); }

.topbar-actions { display: flex; gap: 8px; flex: none; }
.head-actions { display: flex; gap: 12px; align-items: center; }

/* --------------------------------------------------------- up next queue */
.hint { margin: 8px 0 0; text-align: center; }

.then {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 0 0;
  margin-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}
.then-n {
  width: 20px; height: 20px; flex: none;
  border-radius: 6px; background: var(--card-2); color: var(--muted);
  font-size: 11px; font-weight: 800;
  display: grid; place-items: center;
}
.then-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.then-t:last-child { text-align: right; }

/* ----------------------------------------------------------------- queue */
.queue .wait { font-size: 11px; font-weight: 700; color: var(--muted); flex: none; }
.queue li.on-deck .wait { color: var(--accent); }

.pname .st { font-size: 10px; color: var(--warn); margin-left: 5px; letter-spacing: -1px; }
.tag.pair { background: rgba(200,255,40,.1); color: var(--accent); font-weight: 700; }

/* --------------------------------------------------------------- players */
.group-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
  padding: 14px 0 6px;
}
.group-head .link { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 12px; }
.group-head:first-child { padding-top: 4px; }
.prow.away .avatar { opacity: .45; }
.prow.away .nm { color: var(--muted); }
.qbtn.wide { width: auto; min-width: 44px; padding: 0 10px; font-size: 12px; font-weight: 700; color: var(--text); }

#playerSearch { margin-bottom: 6px; }

/* ----------------------------------------------------------------- stats */
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 6px; text-align: center;
}
.stat b { display: block; font-size: 19px; font-weight: 800; letter-spacing: -.02em; }
.stat span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.board { display: grid; gap: 2px; }
.brow {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-bottom: 1px solid var(--line); cursor: pointer;
}
.brow:last-child { border-bottom: 0; }
.brow .rank {
  width: 30px; flex: none; text-align: center;
  font-size: 15px; font-weight: 800; color: var(--muted);
}
.brow .grow { flex: 1; min-width: 0; }
.brow .nm { font-weight: 600; }
.brow .stats { font-size: 12px; color: var(--muted); }
.brow .wl { font-size: 13px; font-weight: 800; color: var(--live); flex: none; }
.brow .wl i { font-style: normal; color: var(--muted); }

/* --------------------------------------------------------------- history */
.hrow-actions { display: flex; gap: 14px; margin-top: 6px; }
.hrow-actions .link { padding: 2px 0; }

/* ---------------------------------------------------------------- sheets */
.scorerow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.teams-flat {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 14px; margin-bottom: 14px;
}
.teams-flat .a { color: var(--teamA); }
.teams-flat .b { color: var(--teamB); text-align: right; }

.picklist label[data-in] { cursor: pointer; }
.picklist .tag { background: var(--card-2); color: var(--muted); }

.card-hero {
  background: linear-gradient(160deg, var(--card-2), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px 16px;
  text-align: center;
  margin-bottom: 14px;
}
.ch-rank { font-size: 13px; font-weight: 800; color: var(--accent); letter-spacing: .08em; }
.ch-name { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.ch-sub { font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.ch-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ch-grid b { display: block; font-size: 20px; font-weight: 800; }
.ch-grid span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ch-skill { margin-top: 14px; font-size: 12px; color: var(--warn); }

@media (min-width: 560px) {
  .courts { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
