/* ==========================================================================
   Scoreboard: referee controller + TV display
   ========================================================================== */
.serve-ball {
  display: inline-block; width: .62em; height: .62em; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 30%, #f4ffb0, var(--accent) 45%, #8fb000);
  box-shadow: 0 0 14px rgba(214,255,61,.55); margin-right: .45em; vertical-align: .02em;
}

/* ---------- referee ---------- */
body.ref { overscroll-behavior: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.ref-app { display: grid; grid-template-rows: auto 1fr auto; height: 100vh; height: 100dvh; }
.ref-bar { display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 14px 10px; border-bottom: 1px solid var(--line); }
.ref-title { flex: 1; min-width: 0; display: grid; text-align: center; }
.ref-title strong { font: 800 .95rem/1.2 var(--display); font-stretch: 112%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ref-title span { font: 500 .72rem/1.3 var(--mono); color: var(--muted); letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line-2); background: none; color: var(--text); }
.icon-btn svg { width: 22px; height: 22px; }

.ref-court { display: grid; grid-template-rows: 1fr auto 1fr; min-height: 0; }
.ref-team {
  position: relative; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto 1fr auto;
  grid-template-areas: "names points" "sets points" "games plus";
  gap: 6px 14px; padding: 18px 20px; border: 0; background: var(--bg); color: var(--text); text-align: left; cursor: pointer;
  transition: background .15s; -webkit-tap-highlight-color: transparent; overflow: hidden;
}
.ref-team::after { content: ""; position: absolute; inset: 0; background: var(--accent); opacity: 0; transition: opacity .35s; pointer-events: none; }
.ref-team:active::after { opacity: .14; transition: none; }
.ref-team.serving { background: linear-gradient(90deg, rgba(214,255,61,.06), transparent 70%), var(--bg); }
.ref-team.winner { background: var(--accent-soft); }
.ref-team:disabled { cursor: default; }
.ref-names { grid-area: names; display: grid; gap: 2px; font: 800 clamp(1.15rem, 5vw, 1.8rem)/1.15 var(--display); font-stretch: 112%; }
.ref-names span { display: flex; align-items: center; opacity: .72; }
.ref-names span.is-serving { opacity: 1; }
.ref-sets { grid-area: sets; display: flex; gap: 6px; align-self: start; }
.ref-sets b { position: relative; min-width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); font: 700 1rem/1 var(--mono); color: var(--muted); }
.ref-sets b.w { color: var(--text); }
.ref-sets sup { position: absolute; top: 2px; right: 3px; font-size: .55rem; }
.ref-games { grid-area: games; display: flex; align-items: baseline; gap: 10px; }
.ref-games small { font: 600 .68rem/1 var(--mono); letter-spacing: .2em; color: var(--muted); }
.ref-games b { font: 800 2rem/1 var(--display); font-stretch: 125%; }
.ref-points {
  grid-area: points; align-self: center; justify-self: end; font: 900 clamp(4.5rem, 26vw, 9rem)/.9 var(--display); font-stretch: 125%;
  color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: -.04em;
}
.ref-points.bump { animation: bump .32s var(--ease); }
@keyframes bump { 0% { transform: scale(.86); opacity: .4; } 100% { transform: none; opacity: 1; } }
.ref-plus { grid-area: plus; justify-self: end; align-self: end; font: 700 .68rem/1 var(--mono); letter-spacing: .2em; color: var(--dim); }
.ref-pressure { position: absolute; top: 14px; right: 20px; font: 800 .7rem/1 var(--mono); letter-spacing: .2em; color: #ff6b6b; }
.ref-mid { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; border-block: 1px solid var(--line); background: var(--bg-2); }
.ref-label { font: 800 .82rem/1 var(--display); font-stretch: 125%; letter-spacing: .12em; color: var(--accent); text-transform: uppercase; }
.ref-meta { font: 500 .8rem/1 var(--mono); color: var(--muted); white-space: nowrap; }
.ref-actions { display: flex; align-items: center; gap: 12px; padding: 12px 14px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.ref-actions .btn { --h: 54px; flex: none; }
.ref-actions .btn:disabled { opacity: .35; }
.ref-status { color: var(--muted); font-size: .85rem; }
.is-busy .ref-team { pointer-events: none; }
.ref-toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); z-index: 20; padding: 14px 22px; border-radius: 999px;
  background: var(--text); color: var(--bg); font: 700 .9rem/1.2 var(--body); box-shadow: 0 20px 50px rgba(0,0,0,.5); animation: rise .3s var(--ease);
  max-width: calc(100% - 40px); text-align: center;
}
@keyframes rise { from { transform: translate(-50%, 20px); opacity: 0; } }
.ref-done { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; text-align: center; padding: 30px; background: rgba(10,10,11,.92); backdrop-filter: blur(8px); }
.ref-done h2 { font-size: clamp(2rem, 8vw, 3.4rem); color: var(--accent); margin: 6px 0 12px; }
.ref-done p { font: 600 1.3rem/1 var(--mono); margin-bottom: 28px; }
@media (orientation: landscape) and (min-width: 700px) {
  .ref-court { grid-template-columns: 1fr auto 1fr; grid-template-rows: 1fr; }
  .ref-mid { flex-direction: column; justify-content: center; border-block: 0; border-inline: 1px solid var(--line); writing-mode: vertical-rl; transform: rotate(180deg); padding: 20px 10px; }
}

/* referee home / pin */
.ref-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.pin-input { text-align: center; font: 800 2rem/1 var(--mono); letter-spacing: .5em; }
.teams-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; align-items: center; }
.team-box { border: 1px solid var(--line-2); border-radius: 16px; padding: 14px; margin: 0; display: grid; gap: 10px; min-width: 0; }
.team-box legend { padding: 0 8px; font: 700 .72rem/1 var(--mono); letter-spacing: .18em; color: var(--muted); }
.vs { font: 900 1rem/1 var(--display); font-stretch: 125%; color: var(--dim); }
@media (max-width: 560px) { .teams-grid { grid-template-columns: 1fr; } .vs { text-align: center; } }

/* ---------- TV ---------- */
body.tv { overflow: hidden; height: 100vh; cursor: none; background: #050506; }
body.tv.show-cursor { cursor: default; }
.tv-app { position: relative; height: 100vh; display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); padding: 3.2vh 4vw 2.6vh; gap: 2vh; isolation: isolate; }
.tv-app::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: radial-gradient(60vw 60vw at 85% -10%, rgba(255,255,255,.07), transparent 60%), radial-gradient(50vw 50vw at 0% 110%, rgba(214,255,61,.05), transparent 60%);
}
.tv-court { position: absolute; inset: 0; z-index: -1; opacity: .5; display: grid; place-items: center; overflow: hidden; }
.tv-court svg { width: 120vw; max-width: none; }
.tv-court svg * { stroke: rgba(255,255,255,.045); stroke-width: .5; fill: none; }
.tv-head { display: flex; align-items: center; justify-content: space-between; gap: 2vw; }
.tv-brand { display: flex; align-items: center; gap: 1.2vw; }
.tv-brand img:first-child { height: 7vh; width: auto; }
.tv-brand img.word { height: 5vh; width: auto; }
.tv-event { text-align: center; flex: 1; min-width: 0; }
.tv-event strong { display: block; font: 800 2.4vh/1.2 var(--display); font-stretch: 125%; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-event span { font: 500 1.7vh/1.4 var(--mono); color: var(--muted); letter-spacing: .08em; }
.tv-status { display: flex; align-items: center; gap: 1.4vw; font: 600 2vh/1 var(--mono); color: var(--muted); }
.tv-status .live-pill { font-size: 1.8vh; }
.tv-status .live-pill::before { width: 1.2vh; height: 1.2vh; }

.tv-board { align-self: center; display: grid; gap: 1.6vh; }
.tv-colhead, .tv-row { display: grid; grid-template-columns: 6vh 1fr var(--setcols, 0px) 13vh 26vh; align-items: center; column-gap: 2vw; }
.tv-colhead { font: 600 1.6vh/1 var(--mono); letter-spacing: .22em; color: var(--dim); padding: 0 3vh; }
.tv-colhead .sets, .tv-row .sets { display: grid; grid-auto-flow: column; grid-auto-columns: 9vh; justify-items: center; gap: 1vw; }
.tv-colhead > :nth-last-child(-n+2) { text-align: center; }
.tv-row {
  position: relative; padding: 2.6vh 3vh; border-radius: 3vh; background: rgba(255,255,255,.035); border: 1px solid rgba(255,255,255,.07);
  transition: background .4s, border-color .4s;
}
.tv-row.serving { border-color: rgba(214,255,61,.28); background: linear-gradient(90deg, rgba(214,255,61,.07), rgba(255,255,255,.03) 60%); }
.tv-row.winner { border-color: var(--accent); background: rgba(214,255,61,.12); }
.tv-serve { width: 3.6vh; height: 3.6vh; justify-self: center; border-radius: 50%; opacity: 0; transform: scale(.4); transition: .35s var(--ease);
  background: radial-gradient(circle at 35% 30%, #f4ffb0, var(--accent) 45%, #8fb000); box-shadow: 0 0 3vh rgba(214,255,61,.6); }
.tv-row.serving .tv-serve { opacity: 1; transform: none; }
.tv-names { display: grid; gap: .6vh; min-width: 0; }
.tv-names span { font: 800 5.4vh/1.05 var(--display); font-stretch: 118%; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tv-names.dbl span { font-size: 4.3vh; }
.tv-names span.srv { color: var(--accent); }
.tv-row .sets b { position: relative; font: 700 5.6vh/1 var(--mono); color: var(--dim); }
.tv-row .sets b.w { color: var(--text); }
.tv-row .sets sup { position: absolute; top: -.6vh; right: -1.8vh; font-size: 2vh; color: var(--muted); }
.tv-games { text-align: center; font: 900 9vh/1 var(--display); font-stretch: 125%; color: var(--text); }
.tv-points {
  text-align: center; font: 900 13vh/1 var(--display); font-stretch: 125%; color: var(--accent); letter-spacing: -.04em;
  font-variant-numeric: tabular-nums; background: rgba(0,0,0,.35); border-radius: 2.4vh; padding: 1.2vh 0;
}
.tv-points.bump { animation: bump .4s var(--ease); }
.tv-pressure {
  position: absolute; top: -1.6vh; right: 3vh; padding: .9vh 1.6vh; border-radius: 1vh; background: #ff3b3b; color: #fff;
  font: 800 1.7vh/1 var(--display); font-stretch: 125%; letter-spacing: .14em; opacity: 0; transform: translateY(1vh); transition: .3s var(--ease);
}
.tv-pressure.on { opacity: 1; transform: none; }
.tv-label-wrap { height: 6vh; display: grid; place-items: center; }
.tv-label {
  font: 900 3.6vh/1 var(--display); font-stretch: 125%; letter-spacing: .3em; text-transform: uppercase; color: var(--bg);
  background: var(--accent); padding: 1.2vh 3vh 1.2vh 3.3vh; border-radius: 999px; transform: scale(.9); opacity: 0; transition: .3s var(--ease);
}
.tv-label.on { transform: none; opacity: 1; }
.tv-label.alert { background: #fff; }

.tv-foot { display: flex; align-items: center; gap: 2.4vw; border-top: 1px solid rgba(255,255,255,.08); padding-top: 2vh; min-height: 9vh; }
.tv-foot .lbl { font: 600 1.5vh/1.3 var(--mono); letter-spacing: .24em; color: var(--dim); white-space: nowrap; }
.tv-sponsors { flex: 1; min-width: 0; overflow: hidden; -webkit-mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); mask-image: linear-gradient(90deg, transparent, #000 6%, #000 94%, transparent); }
.tv-track { display: flex; align-items: center; gap: 6vw; width: max-content; animation: marquee var(--dur, 40s) linear infinite; }
.tv-track img { height: 6vh; width: auto; max-width: 22vw; object-fit: contain; opacity: .85; }
.tv-track img.mono { filter: grayscale(1) brightness(0) invert(1); }
.tv-track span { font: 800 2.6vh/1 var(--display); font-stretch: 118%; color: #cfd1d5; white-space: nowrap; }
@keyframes marquee { to { transform: translateX(-50%); } }
.tv-clock { font: 600 2.2vh/1 var(--mono); color: var(--muted); }

.tv-idle { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; z-index: 2; background: #050506; }
.tv-idle .mark { width: 34vh; height: 34vh; position: relative; margin: 0 auto 4vh; }
.tv-idle .mark .spin { position: absolute; inset: 0; animation: spin 60s linear infinite; }
.tv-idle .mark .ball { position: absolute; inset: 21.5%; animation: bob 4s var(--ease) infinite alternate; }
.tv-idle h1 { font-size: 6vh; }
.tv-idle p { font: 500 2.2vh/1.5 var(--mono); color: var(--muted); margin-top: 2vh; letter-spacing: .06em; }
.tv-win { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; text-align: center; background: rgba(5,5,6,.86); backdrop-filter: blur(6px); }
.tv-win .eyebrow { font-size: 2vh; }
.tv-win h2 { font-size: 10vh; color: var(--accent); margin: 2vh 0; font-weight: 900; }
.tv-win p { font: 700 5vh/1 var(--mono); letter-spacing: .1em; }
.tv-fs { position: fixed; right: 2vw; bottom: 2vh; z-index: 5; opacity: 0; transition: opacity .3s; }
.show-cursor .tv-fs { opacity: 1; }
.tv-change { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 4; padding: 3vh 6vh; border-radius: 3vh; background: var(--text); color: var(--bg); font: 900 5vh/1 var(--display); font-stretch: 125%; letter-spacing: .08em; text-transform: uppercase; animation: rise2 .4s var(--ease); }
@keyframes rise2 { from { opacity: 0; transform: translate(-50%, -40%); } }

/* ---------- live list ---------- */
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.live-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; display: grid; gap: 10px; }
.live-card.is-live { border-color: rgba(255,59,59,.3); }
.live-card header, .live-card footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.live-card footer { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.lc-row { display: grid; grid-template-columns: 1fr auto auto auto; align-items: center; gap: 10px; }
.lc-name { font-weight: 700; display: flex; align-items: center; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.lc-row.win .lc-name, .is-live .lc-name { color: var(--text); }
.lc-sets { display: flex; gap: 4px; }
.lc-sets b { width: 26px; text-align: center; font: 600 1rem/1 var(--mono); color: var(--dim); }
.lc-sets b.w { color: var(--text); }
.lc-g { width: 30px; text-align: center; font: 800 1.2rem/1 var(--display); font-stretch: 125%; }
.lc-p { min-width: 52px; text-align: center; font: 900 1.25rem/1 var(--display); font-stretch: 125%; color: var(--accent); background: var(--bg); border-radius: 8px; padding: 6px 0; }
/* v2 light live list */
.live-card { box-shadow: var(--shadow); padding: 20px 22px; gap: 12px; }
.live-card.is-live { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink), var(--shadow); }
.lc-g { font-stretch: normal; font-size: 1.4rem; }
.lc-p { color: var(--ball); background: var(--ink); font-stretch: normal; font-size: 1.3rem; border-radius: 10px; }
body.dark .lc-p { background: var(--bg); }
@media (max-width: 420px) { .live-grid { grid-template-columns: 1fr; } }
