/* LOVE·ALL — the screen is a hard court seen from above. */
:root {
  --navy: #0b2140;
  --navy-2: #112c55;
  --sheet: #10294d;
  --court: #1f5aa6;
  --court-far: #1a4d92;
  --chalk: #f4f7fb;
  --chalk-dim: rgba(244, 247, 251, 0.66);
  --chalk-faint: rgba(244, 247, 251, 0.14);
  --line: rgba(244, 247, 251, 0.55);
  --me: #e6f03c;
  --opp: #ff8266;
  --ink: #0b2140;
  --danger: #ff6b6b;
  --display: 'Big Shoulders Display', 'Arial Narrow', 'Roboto Condensed', system-ui, sans-serif;
  --text: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: #071730;
  color: var(--chalk);
  font: 500 16px/1.4 var(--text);
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, button, select { touch-action: manipulation; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--me); outline-offset: 2px; }

/* ---------- layout ---------- */
.app {
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--navy);
  position: relative;
  overflow: hidden;
}
@media (min-width: 560px) {
  .app { box-shadow: 0 0 0 1px var(--chalk-faint), 0 30px 80px rgba(0, 0, 0, 0.5); }
}

.top {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 8px;
  min-height: 44px;
}
.brand {
  margin: 0; font: 800 26px/1 var(--display); letter-spacing: 0.02em;
}
.brand span { color: var(--me); margin: 0 1px; }
.status {
  margin: 0; font-size: 14px; font-weight: 600; color: var(--chalk-dim);
  text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status b { color: var(--chalk); font-weight: 700; }
.status .ends {
  display: inline-block; background: var(--me); color: var(--ink);
  padding: 1px 9px; border-radius: 99px; font-weight: 700; margin-left: 6px;
}

.court {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
  min-height: 0;
}

/* ---------- the two halves ---------- */
.side { position: relative; min-height: 0; }
.side-b { background: linear-gradient(180deg, var(--court-far), var(--court)); }
.side-a { background: linear-gradient(0deg, #235fae, var(--court)); }

.tap {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: block; text-align: center;
  color: var(--chalk);
  transition: background-color 0.12s;
}
.tap:active { background-color: rgba(255, 255, 255, 0.07); }
.tap:focus-visible { outline-offset: -6px; }

.lines {
  position: absolute; inset: 0; width: 100%; height: 100%;
  fill: none; stroke: var(--line); stroke-width: 2px; pointer-events: none;
}
.lines path { vector-effect: non-scaling-stroke; }
.lines.flip { transform: scaleY(-1); }

.name {
  position: absolute; left: 50%; transform: translateX(-50%);
  max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font: 700 19px/1 var(--display); letter-spacing: 0.04em;
  color: var(--chalk); padding: 5px 12px 4px; border-radius: 99px;
  background: rgba(11, 33, 64, 0.55);
}
.name::before {
  content: ''; display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 8px; background: var(--pc); vertical-align: 1px;
}
.side-a { --pc: var(--me); }
.side-b { --pc: var(--opp); }
.side-a .name { bottom: 5px; }
.side-b .name { top: 5px; }

.score {
  position: absolute; left: 0; right: 0; top: 50%;
  transform: translateY(-54%);
  font: 800 min(34vw, 21dvh, 176px)/0.9 var(--display);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--chalk);
  text-shadow: 0 3px 0 rgba(11, 33, 64, 0.28);
}
.score.pop { animation: pop 0.22s ease-out; }
@keyframes pop {
  0% { transform: translateY(-54%) scale(0.86); }
  60% { transform: translateY(-54%) scale(1.06); }
  100% { transform: translateY(-54%) scale(1); }
}
.score.small { font-size: min(26vw, 16dvh, 130px); }

.tags {
  position: absolute; left: 0; right: 0; display: flex; justify-content: center; gap: 6px;
}
.side-a .tags { top: 10px; }
.side-b .tags { bottom: 10px; }
.tag {
  background: var(--chalk); color: var(--ink);
  font: 700 13px/1 var(--text); padding: 6px 11px; border-radius: 99px;
}
.tag.hot { background: var(--me); }
.tag.break { background: var(--opp); }

/* the ball: sits at the baseline on the side the server serves from */
.ball {
  position: absolute; width: 30px; height: 30px; border-radius: 50%;
  left: var(--bx, 30%); margin-left: -15px;
  background: radial-gradient(circle at 34% 30%, #f7ff8a 0%, #e6f03c 45%, #b9c41d 100%);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.35);
  opacity: 0; transform: scale(0.4);
  transition: left 0.38s cubic-bezier(0.3, 1.4, 0.5, 1), opacity 0.2s, transform 0.3s;
}
.ball::before, .ball::after {
  content: ''; position: absolute; top: 3px; bottom: 3px; width: 12px;
  border: 2px solid rgba(255, 255, 255, 0.85); border-radius: 50%;
}
.ball::before { left: -7px; clip-path: inset(0 0 0 55%); }
.ball::after { right: -7px; clip-path: inset(0 55% 0 0); }
.side-a .ball { bottom: 34px; }
.side-b .ball { top: 34px; }
.side.serving .ball { opacity: 1; transform: scale(1); }

/* ---------- the net ---------- */
.net {
  position: relative;
  background:
    repeating-linear-gradient(90deg, rgba(244, 247, 251, 0.07) 0 1px, transparent 1px 9px),
    repeating-linear-gradient(0deg, rgba(244, 247, 251, 0.07) 0 1px, transparent 1px 9px),
    var(--navy);
  border-top: 5px solid var(--chalk);
  border-bottom: 3px solid rgba(244, 247, 251, 0.5);
  padding: 8px 12px 9px;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.25);
  z-index: 2;
}
.board { display: grid; gap: 5px; }
.row { display: flex; align-items: center; gap: 4px; height: 46px; }
.who {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 9px;
  font: 700 25px/1 var(--display); letter-spacing: 0.03em;
}
.who .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .sv {
  flex: none; width: 12px; height: 12px; border-radius: 50%;
  background: var(--me); box-shadow: 0 0 0 3px rgba(230, 240, 60, 0.25);
  opacity: 0; transition: opacity 0.2s;
}
.who .sv.on { opacity: 1; }
.cell {
  min-width: 34px; text-align: center; font: 700 30px/1 var(--display);
  color: var(--chalk-dim); font-variant-numeric: tabular-nums; position: relative;
}
.cell.won { color: var(--chalk); }
.cell sup { font: 700 13px/1 var(--display); position: absolute; top: -2px; margin-left: 1px; color: var(--chalk-dim); }
.cell.mtb { font-size: 24px; }
.gm {
  width: 52px; height: 42px; margin-left: 6px; border-radius: 7px;
  display: grid; place-items: center;
  font: 800 34px/1 var(--display); color: var(--ink); background: var(--pc);
  font-variant-numeric: tabular-nums;
}
.row.p0 { --pc: var(--me); }
.row.p1 { --pc: var(--opp); }
.gm.flash { animation: flash 0.7s ease-out; }
@keyframes flash {
  0% { box-shadow: 0 0 0 0 var(--pc); transform: scale(1.18); }
  100% { box-shadow: 0 0 0 14px transparent; transform: scale(1); }
}

/* ---------- picker (detail mode) ---------- */
.picker {
  position: absolute; inset: 0; z-index: 3;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-content: center;
  padding: 16px; background: rgba(8, 24, 50, 0.95);
  animation: fade 0.15s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.picker button {
  min-height: 74px; border-radius: 14px; background: var(--chalk-faint);
  border: 2px solid rgba(244, 247, 251, 0.28); text-align: left; padding: 10px 14px;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
}
.picker button:active { background: var(--pc); color: var(--ink); }
.picker b { font: 700 24px/1 var(--display); letter-spacing: 0.03em; }
.picker small { font-size: 13px; color: var(--chalk-dim); }
.picker button:active small { color: var(--ink); }
.picker .who-tag { grid-column: 1 / -1; text-align: center; font-size: 14px; color: var(--chalk-dim); }

/* ---------- dock ---------- */
.dock {
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--navy); border-top: 1px solid var(--chalk-faint);
  padding-bottom: var(--safe-b);
}
.dock button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 62px; font-size: 12px; font-weight: 600; color: var(--chalk-dim);
}
.dock svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dock button:active { color: var(--chalk); }
.dock button[disabled] { opacity: 0.35; }
.dock button[aria-pressed='true'] { color: var(--me); }
.dock button[aria-pressed='true'] span::after { content: ' on'; }

.toast {
  position: absolute; left: 50%; bottom: calc(76px + var(--safe-b)); z-index: 6;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  background: var(--chalk); color: var(--ink); font-weight: 700; padding: 10px 18px; border-radius: 99px;
  max-width: 88%; text-align: center;
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- sheets ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 20; background: rgba(4, 12, 26, 0.72);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.18s ease-out;
}
.sheet {
  width: 100%; max-width: 520px; max-height: 93dvh; overflow-y: auto;
  background: var(--sheet); border-radius: 22px 22px 0 0;
  border: 1px solid var(--chalk-faint); border-bottom: 0;
  padding: 0 18px calc(22px + var(--safe-b));
  animation: rise 0.24s cubic-bezier(0.2, 0.9, 0.3, 1);
  -webkit-user-select: text; user-select: text;
  overscroll-behavior: contain;
}
@keyframes rise { from { transform: translateY(40px); opacity: 0.4; } }
@media (min-width: 560px) { .backdrop { align-items: center; } .sheet { border-radius: 22px; border-bottom: 1px solid var(--chalk-faint); } }

.sh-head {
  position: sticky; top: 0; z-index: 2; background: var(--sheet);
  display: flex; align-items: center; gap: 10px; padding: 16px 0 12px;
}
.sh-head h2 { flex: 1; margin: 0; font: 800 30px/1 var(--display); letter-spacing: 0.02em; }
.iconbtn {
  min-width: 44px; height: 44px; border-radius: 12px; background: var(--chalk-faint);
  display: grid; place-items: center; font-weight: 700; padding: 0 12px;
}
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.sec { margin: 18px 0 0; }
.sec > h3, fieldset > legend {
  margin: 0 0 8px; padding: 0; font: 600 14px/1.2 var(--text); color: var(--chalk-dim);
}
fieldset { border: 0; margin: 18px 0 0; padding: 0; min-width: 0; }
.hint { margin: 8px 0 0; font-size: 13.5px; color: var(--chalk-dim); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 54px; border-radius: 14px; font-weight: 700; font-size: 17px; padding: 0 18px;
  background: var(--chalk-faint); border: 1px solid rgba(244, 247, 251, 0.22);
}
.btn:active { transform: scale(0.985); }
.btn.primary { background: var(--me); color: var(--ink); border-color: transparent; font-family: var(--display); font-size: 24px; letter-spacing: 0.04em; }
.btn.danger { color: var(--danger); }
.btn.armed { background: var(--danger); color: var(--ink); }
.btn-col { display: grid; gap: 10px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.list button {
  width: 100%; text-align: left; min-height: 58px; padding: 10px 14px; border-radius: 14px;
  background: var(--chalk-faint); display: flex; align-items: center; gap: 12px;
}
.list .grow { flex: 1; min-width: 0; }
.list .grow b { display: block; font-weight: 700; }
.list .grow small { color: var(--chalk-dim); font-size: 13.5px; }
.list .chev { color: var(--chalk-dim); font-size: 22px; line-height: 1; }

.pref { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 10px 14px; border-radius: 14px; background: var(--chalk-faint); cursor: pointer; }
.pref .grow { flex: 1; min-width: 0; }
.pref b { display: block; }
.pref small { color: var(--chalk-dim); font-size: 13.5px; }
.toggle { position: relative; width: 52px; height: 30px; flex: none; }
.toggle input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle i {
  position: absolute; inset: 0; border-radius: 99px; background: rgba(244, 247, 251, 0.25);
  transition: background 0.15s; pointer-events: none;
}
.toggle i::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--chalk); transition: transform 0.15s;
}
.toggle input:checked + i { background: var(--me); }
.toggle input:checked + i::after { transform: translateX(22px); background: var(--ink); }
.toggle input:focus-visible + i { outline: 3px solid var(--me); outline-offset: 2px; }

/* ---------- form ---------- */
.field { display: grid; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; color: var(--chalk-dim); }
.field input[type='text'] {
  width: 100%; height: 52px; padding: 0 14px; border-radius: 12px; font: 600 18px var(--text);
  color: var(--chalk); background: rgba(4, 12, 26, 0.55); border: 2px solid rgba(244, 247, 251, 0.22);
  -webkit-user-select: text; user-select: text;
}
.field input:focus-visible { outline: none; border-color: var(--me); }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.seg label { position: relative; display: block; }
.seg input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.seg label > span {
  display: grid; place-items: center; min-height: 52px; padding: 6px 8px; text-align: center; line-height: 1.15;
  border-radius: 12px; font-weight: 700; font-size: 15px;
  background: var(--chalk-faint); border: 2px solid transparent;
}
.seg small { display: block; font-weight: 500; font-size: 12px; color: var(--chalk-dim); margin-top: 2px; }
.seg input:checked + span { background: var(--chalk); color: var(--ink); }
.seg input:checked + span small { color: var(--ink); opacity: 0.7; }
.seg input:focus-visible + span { outline: 3px solid var(--me); outline-offset: 2px; }
.coin { display: inline-block; }
.coin.spin { animation: spin 0.7s ease-in-out; }
@keyframes spin { to { transform: rotateY(1080deg); } }

/* ---------- results, stats, chart ---------- */
.result { padding: 4px 0 6px; }
.res-names { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font: 700 22px/1.1 var(--display); letter-spacing: 0.03em; }
.res-names .vs { color: var(--chalk-dim); font-size: 16px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.a { background: var(--me); } .dot.b { background: var(--opp); }
.res-line { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 6px; font: 800 52px/1 var(--display); letter-spacing: 0.01em; font-variant-numeric: tabular-nums; }
.res-line span { white-space: nowrap; }
.res-line .tbs { font-size: 24px; color: var(--chalk-dim); margin-left: 2px; vertical-align: 22px; }
.res-line .live { color: var(--chalk-dim); }
.res-sub { color: var(--chalk-dim); font-size: 15px; font-weight: 600; }
.res-sub b { color: var(--chalk); }

.chart { position: relative; margin: 14px 0 4px; background: rgba(4, 12, 26, 0.35); border-radius: 14px; padding: 10px 6px 6px; touch-action: pan-y; }
.chart h3 { margin: 0 0 2px 8px; font: 600 14px/1.2 var(--text); color: var(--chalk-dim); }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font: 600 10.5px var(--text); fill: var(--chalk-dim); }
.chart .legend { display: flex; gap: 16px; margin: 4px 8px 2px; font-size: 13px; color: var(--chalk-dim); font-weight: 600; }
.chart .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.chart .tip {
  position: absolute; top: 6px; right: 10px; background: var(--chalk); color: var(--ink);
  font-size: 12.5px; font-weight: 700; padding: 4px 9px; border-radius: 8px; pointer-events: none;
}
.chart .empty { margin: 18px 8px; color: var(--chalk-dim); font-size: 14px; }

.stats { margin-top: 12px; display: grid; gap: 14px; }
.stat { display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; row-gap: 5px; column-gap: 8px; }
.stat .l { grid-column: 2; grid-row: 1; font-size: 14px; font-weight: 600; color: var(--chalk-dim); text-align: center; white-space: nowrap; }
.stat .v { font: 800 30px/1 var(--display); font-variant-numeric: tabular-nums; }
.stat .v small { font: 600 13px var(--text); color: var(--chalk-dim); margin-left: 5px; }
.stat .v.a { grid-column: 1; grid-row: 1; text-align: left; }
.stat .v.b { grid-column: 3; grid-row: 1; text-align: right; }
.stat .bar { grid-column: 1 / -1; grid-row: 2; display: flex; gap: 2px; height: 7px; }
.stat .bar i { display: block; border-radius: 4px; min-width: 0; }
.stat .bar i.a { background: var(--me); }
.stat .bar i.b { background: var(--opp); }
.stat .bar i.zero { background: var(--chalk-faint); flex: 1; }

.career { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 4px; }
.career > div { background: var(--chalk-faint); border-radius: 14px; padding: 12px 14px; }
.career b { display: block; font: 800 40px/1 var(--display); font-variant-numeric: tabular-nums; }
.career b em { font-style: normal; color: var(--chalk-dim); }
.career span { font-size: 13.5px; color: var(--chalk-dim); font-weight: 600; }
.badge { flex: none; min-width: 30px; text-align: center; font: 800 20px/1 var(--display); padding: 6px 8px 5px; border-radius: 8px; }
.badge.w { background: var(--me); color: var(--ink); }
.badge.l { border: 2px solid var(--chalk-dim); color: var(--chalk-dim); }
.badge.u { border: 2px dashed var(--chalk-dim); color: var(--chalk-dim); }
.score-mini { font: 700 22px/1 var(--display); letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.empty-state { padding: 26px 8px; text-align: center; color: var(--chalk-dim); }
.empty-state b { display: block; color: var(--chalk); font: 800 26px var(--display); margin-bottom: 4px; }

@media (max-height: 640px) {
  .brand { font-size: 22px; }
  .dock button { height: 54px; }
  .row { height: 40px; }
  .gm { height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
