:root {
  /* Default colour scheme = "Rally" (the landing-page look). Others in the colour-schemes block below. */
  --bg: #0b1f16;
  --bg2: #10291d;
  --card: #14332a;
  --line: #1f4a3a;
  --text: #f2f7f4;
  --muted: #9bb3a8;
  --a: #d9f24f;      /* team A accent (lime) */
  --b: #5aa9ff;      /* team B accent (blue) */
  --ball: #ffd84d;
  --on-a: #0b1f16;   /* text on accent buttons */
  --lime: #e8f54a;   /* landing page lime, fixed across schemes */
  --danger: #ff6b6b;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
.screen { min-height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-top); }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 650; }
.topbar.compact { padding: 8px 12px; }
.brand { display: flex; align-items: center; gap: 8px; }
.ball { width: 14px; height: 14px; border-radius: 50%; background: var(--ball); display: inline-block; box-shadow: inset -3px -3px 0 rgba(0,0,0,.25); }
.status { flex: 1; text-align: center; color: var(--muted); font-size: 14px; }
.content { padding: 16px; display: flex; flex-direction: column; gap: 14px; flex: 1; padding-bottom: calc(24px + var(--safe-bottom)); }
.foot { padding: 12px 16px calc(12px + var(--safe-bottom)); font-size: 12px; text-align: center; }
.muted { color: var(--muted); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 10px 0 0; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.row > * { flex: 1; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 9px 14px; font-size: 15px; font-weight: 650;
  min-height: 42px; cursor: pointer; touch-action: manipulation; user-select: none;
  position: relative; overflow: hidden; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 1px 0 rgba(255,255,255,.05) inset, 0 2px 8px rgba(0,0,0,.12);
  transition: transform .12s ease, box-shadow .2s ease, filter .2s ease;
}
.btn:active { transform: scale(.97); filter: brightness(1.08); }
.btn.primary {
  background: linear-gradient(135deg, color-mix(in srgb, var(--a) 85%, #fff), var(--a) 55%, color-mix(in srgb, var(--a) 80%, #000));
  color: var(--on-a); border-color: transparent;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--a) 35%, transparent), 0 1px 0 rgba(255,255,255,.25) inset;
}
.btn.primary::after { /* soft moving shine */
  content: ''; position: absolute; inset: 0; transform: translateX(-120%);
  background: linear-gradient(110deg, transparent 30%, rgba(255,255,255,.28) 50%, transparent 70%);
  animation: shine 4.5s ease-in-out infinite;
}
@keyframes shine { 0%, 70% { transform: translateX(-120%); } 100% { transform: translateX(120%); } }
.btn.big { min-height: 50px; font-size: 17px; border-radius: 14px; }
.btn.ghost { background: color-mix(in srgb, var(--card) 55%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.btn.small { min-height: 34px; font-size: 13px; padding: 6px 10px; border-radius: 10px; }
.btn.danger { color: var(--danger); }
.btn.icon { width: 40px; min-height: 40px; padding: 0; font-size: 20px; line-height: 1; border-radius: 11px; flex: none; }

input[type=text], input:not([type]) {
  width: 100%; background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; font-size: 16px; min-height: 46px;
}
input:focus { outline: 2px solid var(--a); outline-offset: 0; border-color: transparent; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; background: var(--card); }
legend { padding: 0 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.team-card.t0 legend { color: var(--a); }
.team-card.t1 legend { color: var(--b); }
.opt { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.opt.toggle { flex-direction: row; justify-content: space-between; align-items: center; color: var(--text); min-height: 44px; }
.opt.toggle input { width: 24px; height: 24px; accent-color: var(--a); }
.seg { display: flex; background: var(--bg2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 10px 6px; border-radius: 8px; color: var(--muted);
  font-size: 14px; font-weight: 600; min-height: 40px; line-height: 20px; cursor: pointer;
}
.seg input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 0 rgba(0,0,0,.3); }

/* history */
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.history .h-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.history .h-row { display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; font-size: 18px; }
.history .h-trophy { font-size: 20px; text-align: center; }
.history .h-team { min-width: 0; line-height: 1.3; overflow-wrap: anywhere; }
.history .h-team .muted { font-size: 16px; }
.history .h-sets { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .02em; white-space: nowrap; }
.history .h-row.won .h-sets { font-weight: 800; }
.history .live { color: var(--ball); }

/* live */
.screen.live { height: 100dvh; min-height: 0; }
.court { flex: 1; display: flex; flex-direction: column; position: relative; min-height: 0; }
.half {
  flex: 1; appearance: none; border: 0; margin: 0; color: var(--text); text-align: left;
  padding: 14px 18px calc(14px); display: grid; cursor: pointer; touch-action: manipulation; user-select: none;
  grid-template-columns: 1fr auto; grid-template-rows: auto 1fr; align-items: center; position: relative;
  background: linear-gradient(180deg, var(--bg2), var(--bg));
  -webkit-user-select: none;
}
.half[data-team="0"] { border-bottom: 2px solid var(--line); }
.half:active { filter: brightness(1.25); }
.half.winner { outline: 3px solid var(--ball); outline-offset: -3px; }
.half .names { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 2px; }
.half .tname { font-size: 28px; font-weight: 800; line-height: 1.15; }
.half[data-team="0"] .tname { color: var(--a); }
.half[data-team="1"] .tname { color: var(--b); }
.half .tplayers { font-size: 19px; color: var(--muted); }
.half .tplayers b { color: var(--text); font-weight: 600; }
.half .sets { display: flex; gap: 10px; align-self: center; }
.half .sets span {
  min-width: 44px; height: 54px; border-radius: 10px; background: var(--card); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.half .sets span.cur { border-color: var(--text); }
.half .sets span.won { background: var(--line); }
.half .sets small { font-size: 11px; vertical-align: super; margin-left: 2px; color: var(--muted); }
.half .pts {
  font-size: clamp(72px, 22vh, 150px); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums;
  text-align: right; min-width: 2ch; letter-spacing: -.03em;
}
.half .serve { position: absolute; right: 18px; top: 16px; width: 18px; height: 18px; border-radius: 50%; background: var(--ball); opacity: 0; box-shadow: 0 0 0 4px rgba(232,245,74,.2); }
.half.serving .serve { opacity: 1; }
.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 2;
  background: var(--ball); color: #1a1f00; font-weight: 800; padding: 8px 16px; border-radius: 999px;
  font-size: 14px; letter-spacing: .06em; text-transform: uppercase; pointer-events: none; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.controls {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--line); background: var(--bg);
}
.controls .btn { min-width: 88px; }
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 14px; }

/* summary */
.headline { font-size: 24px; font-weight: 700; line-height: 1.3; }
.scoretable, .stats { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.scoretable td, .scoretable th, .stats td, .stats th { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: center; font-variant-numeric: tabular-nums; }
.scoretable th:first-child, .scoretable td:first-child { text-align: left; }
.scoretable tr:last-child td, .stats tr:last-child td { border-bottom: 0; }
.scoretable .w { font-weight: 800; }
.stats th { color: var(--muted); font-weight: 500; font-size: 13px; }
.stats td:first-child, .stats td:last-child { font-weight: 700; width: 25%; }
.stats td:nth-child(2) { color: var(--muted); font-size: 13px; }
.c-a { color: var(--a); } .c-b { color: var(--b); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

@media (orientation: landscape) and (max-height: 500px) {
  .court { flex-direction: row; }
  .half[data-team="0"] { border-bottom: 0; border-right: 2px solid var(--line); }
  .half .pts { font-size: clamp(64px, 30vh, 120px); }
}
/* Light theme: chosen in the app (data-theme="light"), or following the phone when set to Auto */
:root[data-theme="light"] { --bg: #f4f7f2; --bg2: #e9efe6; --card: #ffffff; --line: #d6e0d4; --text: #10211a; --muted: #5d7068; --a: #4d7c0f; --b: #2563eb; --ball: #c8d400; --on-a: #fff; color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) { --bg: #f4f7f2; --bg2: #e9efe6; --card: #ffffff; --line: #d6e0d4; --text: #10211a; --muted: #5d7068; --a: #4d7c0f; --b: #2563eb; --ball: #c8d400; --on-a: #fff; color-scheme: light; }
}
.brand { flex: 1; }

/* names in the summary table */
.scoretable td:first-child b { font-size: 18px; }
.scoretable td:first-child .muted { font-size: 15px; }

/* celebration */
.celebrate {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 50% 35%, rgba(232,245,74,.25), rgba(0,0,0,.82) 70%);
  animation: cel-fade .3s ease-out;
}
.cel-card {
  position: relative; z-index: 1; width: min(100%, 380px); text-align: center;
  background: var(--card); border: 2px solid var(--ball); border-radius: 22px; padding: 28px 22px 22px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: cel-pop .5s cubic-bezier(.2,1.4,.4,1);
}
.cel-trophy { font-size: 84px; line-height: 1; animation: cel-bounce 1.4s ease-in-out infinite; }
.cel-kicker { margin-top: 8px; font-size: 15px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.cel-team { margin: 6px 0 4px; font-size: 34px; font-weight: 900; line-height: 1.1; }
.cel-players { font-size: 20px; font-weight: 600; color: var(--text); }
.cel-score { margin: 16px 0 20px; font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .04em; }
.cel-actions { display: flex; flex-direction: column; gap: 10px; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i {
  position: absolute; top: -20px; width: 9px; height: 15px; border-radius: 2px; opacity: .95;
  animation-name: cel-fall; animation-timing-function: linear; animation-iteration-count: infinite;
}
@keyframes cel-fall { to { top: 105%; transform: rotate(720deg) translateX(40px); } }
@keyframes cel-pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes cel-bounce { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }
@keyframes cel-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .celebrate, .cel-card, .cel-trophy { animation: none; }
}

/* colour schemes (Settings → Colour scheme). Rally = the default tokens above. */
:root[data-palette="classic"] { --a: #2fd37a; --b: #4ea8ff; --ball: #e8f54a; --on-a: #06261a; }
:root[data-palette="classic"][data-theme="light"] { --bg: #f4f7f5; --bg2: #e9efec; --card: #ffffff; --line: #d6e0da; --a: #16a34a; --b: #2563eb; --ball: #cbd500; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="classic"]:not([data-theme]) { --bg: #f4f7f5; --bg2: #e9efec; --card: #ffffff; --line: #d6e0da; --a: #16a34a; --b: #2563eb; --ball: #cbd500; --on-a: #fff; } }
:root[data-palette="clay"] { --bg: #1c120e; --bg2: #26170f; --card: #32201a; --line: #4a3025; --a: #f0784b; --b: #3abff0; --ball: #ffe066; --on-a: #2a1200; }
:root[data-palette="clay"][data-theme="light"] { --bg: #fbf4ef; --bg2: #f3e7df; --card: #ffffff; --line: #ead7cb; --a: #c2410c; --b: #0369a1; --ball: #d4b000; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="clay"]:not([data-theme]) { --bg: #fbf4ef; --bg2: #f3e7df; --card: #ffffff; --line: #ead7cb; --a: #c2410c; --b: #0369a1; --ball: #d4b000; --on-a: #fff; } }
:root[data-palette="berry"] { --bg: #1b0f1a; --bg2: #241424; --card: #301b30; --line: #4a2b49; --a: #f472b6; --b: #34d399; --ball: #fde047; --on-a: #2a0a1f; }
:root[data-palette="berry"][data-theme="light"] { --bg: #fbf2f8; --bg2: #f5e4ef; --card: #ffffff; --line: #ead3e2; --a: #be185d; --b: #047857; --ball: #d4b000; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="berry"]:not([data-theme]) { --bg: #fbf2f8; --bg2: #f5e4ef; --card: #ffffff; --line: #ead3e2; --a: #be185d; --b: #047857; --ball: #d4b000; --on-a: #fff; } }
:root[data-palette="mono"] { --bg: #111111; --bg2: #1a1a1a; --card: #222222; --line: #383838; --a: #ffffff; --b: #9ca3af; --ball: #e8f54a; --on-a: #111111; }
:root[data-palette="mono"][data-theme="light"] { --bg: #f5f5f5; --bg2: #ebebeb; --card: #ffffff; --line: #d9d9d9; --a: #111111; --b: #6b7280; --ball: #c8d400; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="mono"]:not([data-theme]) { --bg: #f5f5f5; --bg2: #ebebeb; --card: #ffffff; --line: #d9d9d9; --a: #111111; --b: #6b7280; --ball: #c8d400; --on-a: #fff; } }
:root[data-palette="night"] { --bg: #000000; --bg2: #0a0a0a; --card: #141414; --line: #2a2a2a; --a: #39ff88; --b: #ff5c8a; --ball: #fff04d; --on-a: #002b14; }
:root[data-palette="night"][data-theme="light"] { --bg: #f3f4f6; --bg2: #e5e7eb; --card: #ffffff; --line: #d1d5db; --a: #15803d; --b: #be123c; --ball: #c8d400; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="night"]:not([data-theme]) { --bg: #f3f4f6; --bg2: #e5e7eb; --card: #ffffff; --line: #d1d5db; --a: #15803d; --b: #be123c; --ball: #c8d400; --on-a: #fff; } }
:root[data-palette="sunset"] { --bg: #1f120b; --bg2: #2a180e; --card: #341f13; --line: #4d2e1c; --a: #ff8a3d; --b: #ff5c8a; --ball: #ffd84d; --on-a: #2a1200; }
:root[data-palette="sunset"][data-theme="light"] { --bg: #fbf5f1; --bg2: #f5ebe4; --card: #ffffff; --line: #ecd9cc; --a: #c2410c; --b: #be185d; --ball: #e0b400; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="sunset"]:not([data-theme]) { --bg: #fbf5f1; --bg2: #f5ebe4; --card: #ffffff; --line: #ecd9cc; --a: #c2410c; --b: #be185d; --ball: #e0b400; --on-a: #fff; } }
:root[data-palette="ocean"] { --bg: #0b1a24; --bg2: #0f2330; --card: #13303f; --line: #1d4458; --a: #2dd4bf; --b: #818cf8; --ball: #e8f54a; --on-a: #042f2e; }
:root[data-palette="ocean"][data-theme="light"] { --bg: #f1f7f9; --bg2: #e4eff3; --card: #ffffff; --line: #cfe2e9; --a: #0f766e; --b: #4338ca; --ball: #cbd500; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="ocean"]:not([data-theme]) { --bg: #f1f7f9; --bg2: #e4eff3; --card: #ffffff; --line: #cfe2e9; --a: #0f766e; --b: #4338ca; --ball: #cbd500; --on-a: #fff; } }
:root[data-palette="royal"] { --bg: #170f24; --bg2: #1f1530; --card: #2a1d40; --line: #3d2b5c; --a: #c084fc; --b: #fbbf24; --ball: #fde047; --on-a: #2a0a3d; }
:root[data-palette="royal"][data-theme="light"] { --bg: #f7f3fb; --bg2: #efe7f7; --card: #ffffff; --line: #e0d3ee; --a: #7e22ce; --b: #b45309; --ball: #d4b000; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="royal"]:not([data-theme]) { --bg: #f7f3fb; --bg2: #efe7f7; --card: #ffffff; --line: #e0d3ee; --a: #7e22ce; --b: #b45309; --ball: #d4b000; --on-a: #fff; } }
:root[data-palette="court"] { --bg: #0b1a2a; --bg2: #0f2337; --card: #132d46; --line: #1d4263; --a: #38bdf8; --b: #f472b6; --ball: #d9f99d; --on-a: #062436; }
:root[data-palette="court"][data-theme="light"] { --bg: #f1f6fb; --bg2: #e3edf7; --card: #ffffff; --line: #cfdeee; --a: #0369a1; --b: #be185d; --ball: #a3c900; --on-a: #fff; }
@media (prefers-color-scheme: light) { :root[data-palette="court"]:not([data-theme]) { --bg: #f1f6fb; --bg2: #e3edf7; --card: #ffffff; --line: #cfdeee; --a: #0369a1; --b: #be185d; --ball: #a3c900; --on-a: #fff; } }

/* settings */
.palettes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pal { display: flex; align-items: center; gap: 10px; padding: 12px; border: 2px solid var(--line); border-radius: 12px; background: var(--bg2); cursor: pointer; min-height: 52px; }
.pal.on { border-color: var(--a); }
.pal input { position: absolute; opacity: 0; pointer-events: none; }
.pal-dots { display: flex; }
.pal-dots i { width: 20px; height: 20px; border-radius: 50%; margin-right: -6px; border: 2px solid var(--card); }
.pal-name { margin-left: 8px; font-weight: 700; color: var(--text); font-size: 15px; }
.small-note { font-size: 13px; text-align: center; }

/* share sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; animation: cel-fade .2s ease-out; }
.sheet { width: min(100%, 520px); background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 16px calc(16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 12px; animation: sheet-up .25s ease-out; }
.sheet-title { margin: 0; font-size: 20px; text-align: center; }
.share-preview { margin: 0; font-size: 14px; color: var(--muted); white-space: pre-line; text-align: center; }
.share-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.share-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; font-size: 14px; min-height: 76px; }
.share-ico { font-size: 24px; line-height: 1; }
.share-btn.wa { background: #25d366; color: #052e16; border-color: transparent; }
.share-btn.fb { background: #1877f2; color: #fff; border-color: transparent; }
.share-btn.ig { background: linear-gradient(45deg, #f58529, #dd2a7b 50%, #8134af); color: #fff; border-color: transparent; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* rules & tips */
.guide-tabs { position: sticky; top: 0; z-index: 2; }
.guide-pane { display: flex; flex-direction: column; gap: 10px; }
.guide details { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 16px; }
.guide details[open] { border-color: var(--a); }
.guide summary { cursor: pointer; list-style: none; padding: 16px 0; font-size: 18px; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: '+'; font-size: 22px; color: var(--muted); }
.guide details[open] summary::after { content: '–'; }
.guide ul { margin: 0 0 16px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.guide li, .guide details p { font-size: 16px; line-height: 1.5; }
.guide details p { margin: 0 0 16px; }
.guide b { color: var(--text); }
.guide-src { font-size: 13px; text-align: center; }
.guide-src a { color: var(--a); }

/* player photos */
.players { display: flex; flex-direction: column; gap: 10px; }
.pl { position: relative; display: flex; align-items: center; gap: 10px; }
.pl input[name] { flex: 1; min-width: 0; }
.av-pick { flex: none; padding: 0; color: inherit; width: 52px; height: 52px; border-radius: 50%; border: 2px dashed var(--line); background: var(--bg2); display: grid; place-items: center; cursor: pointer; overflow: hidden; font-size: 22px; }
.av-pick img { width: 100%; height: 100%; object-fit: cover; }
.av-pick:has(img:not([hidden])) { border-style: solid; border-color: var(--a); }
.t1 .av-pick:has(img:not([hidden])) { border-color: var(--b); }
.av-clear { position: absolute; left: 36px; top: -4px; width: 22px; height: 22px; border-radius: 50%; border: none; background: var(--text); color: var(--bg); font-size: 12px; line-height: 22px; padding: 0; cursor: pointer; }
.av { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; vertical-align: middle; margin-right: 6px; border: 2px solid var(--line); }
.av.sm { width: 22px; height: 22px; margin-right: 4px; border-width: 1px; }
.av.lg { width: 64px; height: 64px; margin: 0 0 6px; border: 3px solid var(--ball); }
.half .tplayers .pn { white-space: nowrap; }
.cel-players { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.cel-pl { display: flex; flex-direction: column; align-items: center; }
.share-img { display: block; width: min(60vw, 220px); aspect-ratio: 1; margin: 0 auto; border-radius: 14px; background: var(--bg2); object-fit: cover; }

/* donations */
.donate { text-align: center; text-decoration: none; border-color: #ff6b8a; color: #ff6b8a; }
.donate-note { margin: 0; text-align: center; font-size: 13px; }

/* in-app camera */
.camera { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.cam-video { width: 100%; max-width: 560px; aspect-ratio: 1; object-fit: cover; background: #000; }
.cam-video.mirror { transform: scaleX(-1); }
.cam-guide { position: absolute; width: min(70vw, 360px); aspect-ratio: 1; border-radius: 50%; border: 3px dashed rgba(255,255,255,.8); box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); pointer-events: none; top: 50%; left: 50%; transform: translate(-50%, -50%); }
.cam-bar { position: absolute; left: 0; right: 0; bottom: calc(24px + var(--safe-bottom)); display: flex; align-items: center; justify-content: space-around; }
.cam-btn { color: #fff; border-color: rgba(255,255,255,.4); min-width: 88px; }
.cam-snap { width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; background: var(--ball); cursor: pointer; }
.cam-snap:active { transform: scale(.92); }

/* edit names */
.half .tname-row { display: flex; align-items: center; gap: 8px; }
.edit-names { font-size: 18px; line-height: 1; padding: 6px 8px; border-radius: 10px; background: rgba(127,127,127,.18); cursor: pointer; }
.edit-names:active { transform: scale(.92); }
#names-form input { font-size: 18px; }

/* singles / doubles */
.match-type { margin-bottom: 2px; }
#setup-form.singles .pl.p2 { display: none; }

/* who serves first */
.clock-wrap { display: flex; justify-content: center; align-items: center; min-width: 0; }
.serve-btn { font-size: 15px; padding: 10px 12px; border-color: var(--ball); color: var(--text); white-space: nowrap; }
.serve-hint { margin: -4px 0 0; text-align: center; font-size: 14px; }
.serve-choices { display: flex; flex-direction: column; gap: 10px; }
.serve-choice { display: flex; align-items: center; gap: 8px; justify-content: flex-start; text-align: left; }
.serve-choice small { margin-left: auto; color: var(--muted); font-weight: 500; font-size: 13px; }
.serve-choice.c-a { border-left: 5px solid var(--a); }
.serve-choice.c-b { border-left: 5px solid var(--b); }

/* recent players */
.recent { display: flex; flex-direction: column; gap: 8px; }
.recent-title { font-size: 14px; font-weight: 700; }
.recent-title .muted { font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; }
.chip .av { margin-right: 2px; }
.chip.used { opacity: .4; }

/* settings button on every screen */
.topbar .open-settings { margin-left: auto; }
.topbar.compact .open-settings { margin-left: 0; }

/* ---------- look & feel: court pattern, depth, motion ---------- */
:root { --pat: rgba(255,255,255,.045); --glow-a: color-mix(in srgb, var(--a) 22%, transparent); --glow-b: color-mix(in srgb, var(--b) 18%, transparent); }
:root[data-theme="light"] { --pat: rgba(16,33,26,.05); }
@media (prefers-color-scheme: light) { :root:not([data-theme]) { --pat: rgba(16,33,26,.05); } }
body {
  background-color: var(--bg);
  background-image:
    radial-gradient(60vmax 40vmax at 0% 0%, var(--glow-a), transparent 60%),
    radial-gradient(60vmax 40vmax at 100% 100%, var(--glow-b), transparent 60%),
    linear-gradient(var(--pat) 2px, transparent 2px),
    linear-gradient(90deg, var(--pat) 2px, transparent 2px);
  background-size: 100% 100%, 100% 100%, 140px 180px, 140px 180px;
  background-position: 0 0, 0 0, -1px 89px, 69px -1px;
  background-attachment: fixed;
}
.screen:not(.live) { animation: screen-in .28s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.topbar { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); background: color-mix(in srgb, var(--bg) 70%, transparent); position: sticky; top: 0; z-index: 5; }
.brand-icon { width: 28px; height: 28px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }

/* ---------- Landing page (Home) ---------- */
.home-top { border-bottom: 0; }
.brand-name { font-weight: 800; letter-spacing: .06em; text-transform: uppercase; font-size: 17px; }
.hero {
  position: relative; overflow: hidden; min-height: 540px; display: flex; align-items: flex-end;
  padding: 28px 20px 96px; background: #0b1f16; color: #fff;
}
.hero-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 68% 40%; filter: brightness(.6) saturate(.9); }
.hero::before { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(5,20,14,.45), rgba(5,20,14,.2) 35%, rgba(5,20,14,.9)); }
.hero-body { position: relative; display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 440px; }
.hero-badge {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 9px; padding: 9px 14px;
  border: 1px solid rgba(255,255,255,.28); border-radius: 8px; background: rgba(5,20,14,.55);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: #eef5f0;
}
.hero-badge i { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); }
.hero-h { margin: 4px 0 0; font-size: clamp(44px, 14vw, 68px); line-height: 1.02; font-weight: 800; letter-spacing: -.025em; color: #fff; }
.hero-h span { color: var(--lime); }
.hero-sub { margin: 0 0 6px; font-size: 17px; line-height: 1.5; color: #d7e3dc; }
.btn.lime {
  background: var(--lime); color: #0b1f16; border-color: transparent; border-radius: 8px;
  justify-content: space-between; padding: 0 22px; min-height: 56px; font-size: 18px; font-weight: 750;
  box-shadow: 0 10px 26px color-mix(in srgb, var(--lime) 28%, transparent);
}
.btn.lime::after { content: none; }
.hero-link { appearance: none; background: none; border: 0; color: #fff; font: inherit; font-weight: 700; font-size: 16px; padding: 6px 0; text-align: left; cursor: pointer; display: inline-flex; gap: 8px; align-self: flex-start; }
.scorecard {
  --cols: 3; position: relative; z-index: 1; margin: -76px 16px 0; padding: 16px 18px 6px;
  background: #fff; color: #10211a; border-radius: 16px; box-shadow: 0 18px 44px rgba(0,0,0,.35); cursor: pointer;
}
.scorecard:active { transform: scale(.99); }
.sc-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-bottom: 12px; border-bottom: 1px solid #e3e9e5; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #3c5048; }
.sc-live { display: flex; align-items: center; gap: 8px; }
.sc-live i { width: 10px; height: 10px; border-radius: 50%; background: #0b3b2a; }
.sc-live.on i { background: #16a34a; box-shadow: 0 0 0 4px rgba(22,163,74,.2); }
.sc-right { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sc-row { display: grid; grid-template-columns: minmax(0, 1fr) repeat(var(--cols), minmax(34px, auto)); gap: 8px; align-items: center; padding: 11px 0; border-bottom: 1px solid #e3e9e5; font-size: 22px; font-weight: 700; }
.sc-row:last-child { border-bottom: 0; }
.sc-th { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: #5d7068; font-weight: 700; padding: 10px 0 8px; }
.sc-v { text-align: center; font-variant-numeric: tabular-nums; }
.sc-team { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 17px; }
.sc-team b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-team i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot-a { background: #0b3b2a; } .dot-b { background: #2563eb; }
.sc-game { background: var(--lime); color: #0b1f16; border-radius: 8px; padding: 5px 4px; font-size: 20px; }
.sc-empty { margin: 12px 0 10px; color: #5d7068; font-size: 15px; line-height: 1.45; }
.home .content { padding-top: 18px; }
.install { border-color: color-mix(in srgb, var(--a) 60%, var(--line)); }

/* cards get depth */
fieldset, .history li, .guide details, .sheet { box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.history li { transition: transform .15s ease; }
.history li:active { transform: scale(.985); }

/* live screen: court feel + score pop */
.half {
  background:
    radial-gradient(120% 90% at 50% 120%, var(--glow-a), transparent 60%),
    linear-gradient(180deg, var(--bg2), var(--bg));
}
.half[data-team="1"] { background:
    radial-gradient(120% 90% at 50% -20%, var(--glow-b), transparent 60%),
    linear-gradient(180deg, var(--bg2), var(--bg)); }
.half.serving .serve { animation: serve-pulse 1.6s ease-in-out infinite; }
@keyframes serve-pulse { 0%, 100% { box-shadow: 0 0 0 4px rgba(232,245,74,.2); } 50% { box-shadow: 0 0 0 10px rgba(232,245,74,0); } }
.half .pts.pop { animation: pop .28s cubic-bezier(.2,1.6,.4,1); }
@keyframes pop { from { transform: scale(.8); opacity: .5; } to { transform: scale(1); opacity: 1; } }
.controls { background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }

/* install help */
.install-icon { width: 64px; height: 64px; border-radius: 16px; margin: 0 auto; display: block; box-shadow: 0 6px 18px rgba(0,0,0,.3); }
.install-steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 10px; font-size: 16px; line-height: 1.45; }
.kbd { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg2); }

@media (prefers-reduced-motion: reduce) {
  .btn.primary::after, .half.serving .serve, .half .pts.pop, .screen:not(.live) { animation: none; }
}
/* slimmer form controls to match the smaller buttons */
input[type=text], input:not([type]) { min-height: 42px; padding: 9px 12px; }
.av-pick { width: 44px; height: 44px; font-size: 19px; }
.av-clear { left: 30px; }
.seg span { padding: 8px 6px; min-height: 36px; }

/* watch remote */
.beta { font-size: 10px; padding: 2px 6px; border-radius: 999px; background: var(--ball); color: #1a1f00; vertical-align: middle; letter-spacing: .04em; }
.watch-help { margin: 4px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.45; display: flex; flex-direction: column; gap: 4px; }
.watch-btn.on { border-color: var(--a); color: var(--a); }
.clock-wrap { flex-direction: column; gap: 4px; }
.clock-wrap .serve-btn { min-height: 32px; padding: 5px 10px; font-size: 13px; }

/* sets: Best of / Race to */
.seg-wrap { flex-wrap: wrap; }
.seg-wrap label { flex: 1 1 30%; }
.sets-hint { font-size: 12px; color: var(--muted); }

/* ---------- court view: players in their service boxes ---------- */
.half .tplayers { display: block; margin-top: 6px; }
.court-boxes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  border: 2px solid rgba(255,255,255,.55); border-radius: 6px; overflow: hidden;
  background: color-mix(in srgb, var(--a) 10%, transparent);
}
:root[data-theme="light"] .court-boxes { border-color: rgba(16,33,26,.35); }
@media (prefers-color-scheme: light) { :root:not([data-theme]) .court-boxes { border-color: rgba(16,33,26,.35); } }
.half[data-team="1"] .court-boxes { background: color-mix(in srgb, var(--b) 10%, transparent); }
.cbox {
  display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px 10px; min-height: 52px;
  font-size: 16px; color: var(--text); position: relative; cursor: pointer;
}
.cbox + .cbox { border-left: 2px solid rgba(255,255,255,.55); } /* centre service line */
:root[data-theme="light"] .cbox + .cbox { border-left-color: rgba(16,33,26,.35); }
@media (prefers-color-scheme: light) { :root:not([data-theme]) .cbox + .cbox { border-left-color: rgba(16,33,26,.35); } }
.cbox .cname { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.cbox small, .cbox .ctag { position: absolute; right: 6px; bottom: 3px; font-size: 10px; color: var(--muted); letter-spacing: .02em; }
.cbox.empty { justify-content: center; cursor: default; }
.cbox.empty small { position: static; }
.cav { width: 30px; height: 30px; margin: 0; flex: none; }
.cav.initial { display: inline-grid; place-items: center; border-radius: 50%; background: var(--bg2); border: 2px solid var(--line); font-size: 14px; font-weight: 800; color: var(--muted); }
.cbox.srv { background: color-mix(in srgb, var(--ball) 22%, transparent); box-shadow: inset 0 0 0 2px var(--ball); }
.cbox.srv .ctag { color: var(--text); font-weight: 800; }
.cbox.rcv { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--text) 55%, transparent); }
.cbox.rcv .ctag { color: var(--text); font-weight: 700; }
.half .court { position: relative; }
.court::after { /* the net between the halves */
  content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 4px; transform: translateY(-50%); pointer-events: none;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.7) 0 6px, transparent 6px 10px);
}
@media (prefers-reduced-motion: no-preference) { .cbox.srv { animation: srv-glow 1.6s ease-in-out infinite; } }
@keyframes srv-glow { 50% { box-shadow: inset 0 0 0 2px var(--ball), 0 0 14px color-mix(in srgb, var(--ball) 55%, transparent); } }

/* mirrored score screen: top team's names at the very top, bottom team's names at the
   very bottom, both scores in the middle next to the net */
.court .half .sets, .court .half .pts { grid-row: 2; }
.court .half:first-of-type .sets, .court .half:first-of-type .pts { align-self: end; }
.court .half ~ .half { grid-template-rows: 1fr auto; }
.court .half ~ .half .names { grid-row: 2; flex-direction: column-reverse; gap: 6px; }
.court .half ~ .half .sets, .court .half ~ .half .pts { grid-row: 1; align-self: start; }
.court .half ~ .half .tplayers { margin-top: 0; }
.court .half ~ .half .serve { top: auto; bottom: 16px; }

/* change of ends after a set */
.court { overflow: hidden; }
.court.flip-anim .half:first-of-type { animation: ends-up 1s cubic-bezier(.65, 0, .35, 1) both; }
.court.flip-anim .half ~ .half { animation: ends-down 1s cubic-bezier(.65, 0, .35, 1) both; }
.court.flip-anim::after { animation: net-pulse 1s ease both; }
@keyframes ends-up {   /* this team was at the bottom and moves to the top */
  0%   { transform: translateY(100%) scale(.96); opacity: 0; }
  35%  { opacity: 1; }
  100% { transform: none; opacity: 1; }
}
@keyframes ends-down { /* this team was at the top and moves to the bottom */
  0%   { transform: translateY(-100%) scale(.96); opacity: 0; }
  35%  { opacity: 1; }
  100% { transform: none; opacity: 1; }
}
@keyframes net-pulse { 0%, 100% { box-shadow: none; } 50% { box-shadow: 0 0 18px 4px var(--ball); } }
@media (prefers-reduced-motion: reduce) { .court.flip-anim .half, .court.flip-anim::after { animation: none; } }

/* Landing page on wide screens: keep the card readable, let the text breathe */
@media (min-width: 900px) {
  .hero-body { max-width: 560px; }
  .scorecard { max-width: 760px; }
  .home .content { max-width: 792px; }
}
/* Landing page in phone landscape: compact two-column hero so the buttons stay on screen */
@media (orientation: landscape) and (max-height: 560px) {
  .hero { min-height: 0; padding: 16px 20px 44px; }
  .hero-body {
    max-width: none; display: grid; grid-template-columns: 1.15fr 1fr; grid-template-rows: auto auto auto;
    column-gap: 28px; row-gap: 8px; align-items: end;
  }
  .hero-badge { grid-column: 1; grid-row: 1; padding: 6px 10px; font-size: 11px; }
  .hero-h { grid-column: 1; grid-row: 2; font-size: clamp(30px, 6vw, 44px); margin: 0; }
  .hero-sub { grid-column: 1; grid-row: 3; font-size: 14px; margin: 0; }
  #btn-resume { grid-column: 2; grid-row: 1; }
  #btn-new { grid-column: 2; grid-row: 2; }
  #btn-rules { grid-column: 2; grid-row: 3; justify-self: start; padding: 0; }
  .btn.lime { min-height: 46px; font-size: 16px; padding: 0 16px; }
  .scorecard { margin-top: -28px; padding: 12px 16px 2px; }
  .sc-row:not(.sc-th) { padding: 7px 0; font-size: 18px; }
  .sc-game { font-size: 17px; padding: 3px 4px; }
}
