/* Night session (dark, default look) and day session (light, for bright sun at the courts). */
:root {
  --bg: #edf0f7;
  --glow: radial-gradient(120% 60% at 100% -10%, rgb(59 91 255 / 0.14), transparent 60%),
    radial-gradient(80% 40% at -10% 0%, rgb(255 79 163 / 0.08), transparent 60%);
  --card: #ffffff;
  --card-edge: rgb(11 16 38 / 0.08);
  --ink: #0b1026;
  --muted: #5d6585;
  --line: rgb(11 16 38 / 0.08);
  --hi: #2e4bff;            /* highlight text */
  --ball: #d7ff3c;          /* optic yellow fills */
  --ball-ink: #0b1026;
  --win: #0f9d63;
  --loss: #e0334f;
  --draw: #c77d00;
  --grad: linear-gradient(135deg, #3b5bff 0%, #7b3dff 55%, #ff4fa3 100%);
  --mine: rgb(46 75 255 / 0.07);
  --shadow: 0 1px 2px rgb(11 16 38 / 0.06), 0 8px 24px rgb(11 16 38 / 0.06);
  --display: 'Unbounded', system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #070b1d;
    --glow: radial-gradient(120% 55% at 100% -10%, rgb(59 91 255 / 0.28), transparent 60%),
      radial-gradient(90% 45% at -20% 5%, rgb(255 79 163 / 0.14), transparent 60%);
    --card: #10163a;
    --card-edge: rgb(255 255 255 / 0.07);
    --ink: #f2f4ff;
    --muted: #8f97c2;
    --line: rgb(255 255 255 / 0.07);
    --hi: #d7ff3c;
    --win: #d7ff3c;
    --loss: #ff5a6e;
    --draw: #ffb547;
    --mine: rgb(215 255 60 / 0.07);
    --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #070b1d;
  --glow: radial-gradient(120% 55% at 100% -10%, rgb(59 91 255 / 0.28), transparent 60%),
    radial-gradient(90% 45% at -20% 5%, rgb(255 79 163 / 0.14), transparent 60%);
  --card: #10163a;
  --card-edge: rgb(255 255 255 / 0.07);
  --ink: #f2f4ff;
  --muted: #8f97c2;
  --line: rgb(255 255 255 / 0.07);
  --hi: #d7ff3c;
  --win: #d7ff3c;
  --loss: #ff5a6e;
  --draw: #ffb547;
  --mine: rgb(215 255 60 / 0.07);
  --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--glow), var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--line);
}
.top h1 {
  flex: 1;
  margin: 0;
  font: 700 17px/1.2 var(--display);
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.top h1 .dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-left: 3px;
  border-radius: 50%;
  background: var(--ball);
  box-shadow: 0 0 12px rgb(215 255 60 / 0.8);
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  cursor: pointer;
  flex: none;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; }
.spin svg { animation: spin 0.9s linear infinite; color: var(--hi); }
@keyframes spin { to { transform: rotate(360deg); } }

main { max-width: 560px; margin: 0 auto; padding: 14px 16px 36px; }

/* ---------- cards ---------- */
.card {
  display: block;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 14px;
}
a.card { transition: transform 0.12s ease; }
a.card:active { transform: scale(0.985); }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.title { font: 800 24px/1.15 var(--display); letter-spacing: -0.02em; margin: 4px 0 2px; }
.sub { color: var(--muted); font-size: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { text-align: right; }
.chev { color: var(--muted); flex: none; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 14px 0 0; font-size: 15px; }
.facts dt { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding-top: 3px; }
.facts dd { margin: 0; min-width: 0; }
.facts b { font-weight: 750; }
.out.W { color: var(--win); }
.out.L { color: var(--loss); }
.out.D { color: var(--draw); }

/* next-match banner */
.next {
  position: relative;
  overflow: hidden;
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--grad);
  color: #fff;
}
.next::after {
  /* a tennis-ball seam curve in the corner */
  content: '';
  position: absolute;
  right: -46px;
  top: -46px;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 3px solid rgb(255 255 255 / 0.22);
}
.next .when { font: 700 16px/1.3 var(--display); color: var(--ball); letter-spacing: -0.01em; }
.next .vs { font-weight: 700; font-size: 17px; margin-top: 2px; }
.next .sub, .next .vs .sub { color: rgb(255 255 255 / 0.78); }

/* ---------- badges & tags ---------- */
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  border-radius: 10px;
  font: 800 13px/1 var(--display);
  flex: none;
}
.badge.W { background: var(--ball); color: var(--ball-ink); box-shadow: 0 0 14px rgb(215 255 60 / 0.35); }
.badge.L { background: var(--loss); color: #fff; }
.badge.D { background: var(--draw); color: var(--ball-ink); }
.badge.muted { background: var(--line); color: var(--muted); box-shadow: none; }
.tag { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: var(--line); color: var(--muted); vertical-align: 2px; letter-spacing: 0.04em; }

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.tabs a {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}
.tabs a.on { background: var(--ball); color: var(--ball-ink); }

/* ---------- lists ---------- */
.list { background: var(--card); border: 1px solid var(--card-edge); border-radius: 20px; overflow: hidden; margin-bottom: 14px; box-shadow: var(--shadow); }
.list > * { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.list > *:first-child { border-top: 0; }
.list .mine { background: var(--mine); box-shadow: inset 4px 0 0 var(--hi); }
.list .cut { border-top: 2px dashed var(--muted); }
.list h3 { margin: 0; font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; background: color-mix(in srgb, var(--line) 60%, transparent); }
.list .num b, .list .right b { font: 700 16px/1.2 var(--display); }

h2.section { font: 700 12px/1.2 var(--display); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 24px 4px 10px; }

/* players */
.list > details.player { display: block; }
.player summary { list-style: none; cursor: pointer; }
.player summary::-webkit-details-marker { display: none; }
.player .line { display: flex; align-items: center; gap: 10px; }
.player .pos { width: 34px; flex: none; align-self: flex-start; padding-top: 1px; font: 800 15px/1.3 var(--display); color: var(--hi); }
.player .apps { font-size: 12px; color: var(--muted); }
.player[open] { background: var(--mine); }
.history { margin-top: 10px; font-size: 13px; color: var(--muted); }
.history div { display: flex; gap: 8px; padding: 6px 0; border-top: 1px dashed var(--line); }
.history .res { font-weight: 800; width: 14px; flex: none; }
.history .res.W { color: var(--win); }
.history .res.L { color: var(--loss); }

/* ---------- match ---------- */
.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; text-align: center; }
.scoreboard .team { font-weight: 700; font-size: 15px; }
.scoreboard .big {
  font: 800 40px/1 var(--display);
  letter-spacing: -0.03em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.scoreboard .games { font-size: 13px; color: var(--muted); margin-top: 4px; }

.rubber { padding: 12px 16px !important; flex-direction: column; align-items: stretch !important; gap: 5px !important; }
.rubber .kind { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.rubber .side { display: flex; align-items: baseline; gap: 10px; }
.rubber .side .names { flex: 1; min-width: 0; }
.rubber .side .score { font: 700 19px/1 var(--display); min-width: 24px; text-align: right; }
.rubber .side.won { font-weight: 750; }
.rubber .side.won .score { color: var(--hi); }
.rubber .side.lost { color: var(--muted); }
.rubber .tick { width: 9px; height: 9px; border-radius: 50%; background: var(--ball); box-shadow: 0 0 10px rgb(215 255 60 / 0.7); flex: none; align-self: center; visibility: hidden; }
.rubber .side.won .tick { visibility: visible; }

/* ---------- UTR ratings ---------- */
.utr {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font: 700 11px/1.5 var(--display);
  letter-spacing: 0.01em;
  white-space: nowrap;
  vertical-align: 1px;
  color: var(--hi);
  background: color-mix(in srgb, var(--hi) 13%, transparent);
}
.utr-mini { font-size: 12px; font-weight: 700; color: var(--muted); }
.rubber .side.won .utr-mini { color: var(--hi); opacity: 0.85; }

/* ---------- UTR sign-in ---------- */
.utr-prompt { background: var(--grad); color: #fff; border: 0; }
.utr-prompt .sub, .utr-prompt .chev { color: rgb(255 255 255 / 0.8); }
.form label { display: block; margin-top: 14px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.3 system-ui, sans-serif; /* 16px stops iOS zooming in on focus */
}
.form input:focus { outline: 2px solid var(--hi); outline-offset: 1px; }
.btn {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 13px;
  border: 0;
  border-radius: 999px;
  background: var(--ball);
  color: var(--ball-ink);
  font: 800 15px/1 var(--display);
  cursor: pointer;
}
.btn:disabled { opacity: 0.6; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* ---------- teams, settings ---------- */
.welcome .title { font-size: 26px; }
.welcome .btn { text-align: center; }
a.btn { text-decoration: none; }
.add-team { display: block; text-align: center; padding: 12px; margin: -2px 0 6px; font-weight: 700; color: var(--hi); }
.list button.pick, .list > button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.list > button:first-child { border-top: 0; }
.list button.pick:active { background: var(--mine); }
.filter {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font: 16px/1.3 system-ui, sans-serif;
}
.card .filter { margin: 8px 0 0; background: var(--bg); }
.btn-small { flex: none; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--loss); font-weight: 700; font-size: 13px; cursor: pointer; }
.tag.you { background: var(--ball); color: var(--ball-ink); }

/* ---------- head-to-head ---------- */
.apps.h2h { color: var(--ink); }
.apps.h2h b { color: var(--hi); }
.h2h-head { display: block !important; border: 0 !important; padding: 8px 0 2px !important; font-size: 10px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

/* ---------- match preview ---------- */
.preview { padding-bottom: 12px; }
.pv-sum { font-size: 15px; margin-bottom: 4px; }
.pv-sum b { font: 800 18px/1 var(--display); color: var(--hi); }
.pv { padding: 10px 0; border-top: 1px solid var(--line); }
.pv:first-of-type { border-top: 0; }
.pv-top { display: flex; justify-content: space-between; align-items: baseline; }
.pv-top .kind { font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.pv-pct { font: 800 15px/1 var(--display); }
.pv-pct.good { color: var(--win); }
.pv-pct.bad { color: var(--loss); }
.pv-pct.even { color: var(--draw); }
.pv-names { margin: 4px 0 6px; font-size: 14px; }
.pv-names i { font-style: normal; font-size: 12px; font-weight: 700; color: var(--muted); }
.pv-me { font-weight: 800; }
.pv-bar { height: 6px; border-radius: 6px; background: color-mix(in srgb, var(--loss) 30%, transparent); overflow: hidden; }
.pv-bar span { display: block; height: 100%; border-radius: 6px; background: var(--win); }
.pv-bar span.even { background: var(--draw); }

.ha { font-weight: 500; color: var(--muted); }
.next .ha { color: rgb(255 255 255 / 0.8); }

/* ---------- misc ---------- */
.info div { padding: 3px 0; }
.info a, a.link { color: var(--hi); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.error { color: var(--loss); }
.foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 20px; }
.foot a { text-decoration: underline; }

/* ---------- opening animation (~1.1s) ---------- */
#splash {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--glow), var(--bg);
  transition: opacity 0.3s ease;
}
#splash.done { opacity: 0; pointer-events: none; }
#splash .stage { position: relative; width: 260px; height: 150px; }
#splash .line {
  position: absolute;
  left: 30px;
  right: 30px;
  bottom: 18px;
  height: 3px;
  border-radius: 3px;
  background: var(--ink);
  opacity: 0;
  transform: scaleX(0.2);
  animation: line-in 0.35s 0.05s ease-out forwards;
}
/* x moves steadily; y (in .hop) does the arc, bounce and launch */
#splash .track { position: absolute; left: 0; bottom: 21px; animation: ball-x 1.05s forwards; }
#splash .hop { animation: ball-y 1.05s forwards; }
#splash .ball { display: block; width: 40px; height: 40px; transform-origin: 50% 100%; filter: drop-shadow(0 0 14px rgb(215 255 60 / 0.6)); animation: ball-squash 1.05s forwards; }
#splash .seams { transform-origin: 32px 32px; animation: ball-spin 1.05s linear forwards; }
#splash .burst { position: absolute; left: 50%; bottom: 22px; width: 0; height: 0; }
#splash .burst i {
  position: absolute;
  left: -1.5px;
  bottom: 0;
  width: 3px;
  height: 14px;
  border-radius: 3px;
  background: var(--ball);
  opacity: 0;
  transform-origin: 50% 100%;
  animation: burst 0.35s 0.42s ease-out forwards;
}
#splash .burst i:nth-child(1) { --r: -55deg; }
#splash .burst i:nth-child(2) { --r: 0deg; }
#splash .burst i:nth-child(3) { --r: 55deg; }
#splash .word {
  font: 800 30px/1 var(--display);
  letter-spacing: -0.03em;
  opacity: 0;
  transform: translateY(10px);
  animation: word-in 0.45s 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.3) forwards;
}
@keyframes line-in { to { opacity: 0.25; transform: scaleX(1); } }
/* steady approach to the bounce (centre of the line), then accelerates away like it's been hit */
@keyframes ball-x {
  0% { transform: translateX(-60px); animation-timing-function: linear; }
  42% { transform: translateX(110px); animation-timing-function: cubic-bezier(0.2, 0.4, 0.7, 1); }
  100% { transform: translateX(520px); }
}
@keyframes ball-y {
  0% { transform: translateY(-120px); animation-timing-function: cubic-bezier(0.5, 0, 1, 0.6); }
  42% { transform: translateY(0); animation-timing-function: cubic-bezier(0, 0.5, 0.6, 1); }
  100% { transform: translateY(-360px); }
}
@keyframes ball-squash {
  0%, 36% { transform: scale(1); }
  42% { transform: scale(1.3, 0.7); }
  50%, 100% { transform: scale(1); }
}
@keyframes ball-spin { to { transform: rotate(540deg); } }
@keyframes burst {
  0% { opacity: 1; transform: rotate(var(--r)) translateY(-6px) scaleY(0.3); }
  100% { opacity: 0; transform: rotate(var(--r)) translateY(-26px) scaleY(1); }
}
@keyframes word-in { to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  #splash { display: none; }
}
