/* —— TV scoreboard: calm club-court broadcast —— */

.tv-page {
  --tv-bg: #070e0c;
  --tv-panel: #16382f;
  --tv-panel-raised: color-mix(in srgb, var(--tv-panel) 82%, #fff);
  --tv-games: #6d9a7c;
  --tv-line: rgba(244, 247, 242, 0.1);
  --tv-ink: #f4f7f2;
  --tv-mute: #6a8a7a;
  --tv-faint: rgba(244, 247, 242, 0.38);
  --tv-accent: #d7ff3e;
  --tv-pts-ink: #142820;
  --tv-spring: cubic-bezier(0.23, 1, 0.32, 1);
  --tv-press: 100ms ease-out;

  margin: 0;
  padding: 0;
  min-height: 100vh;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(34, 72, 58, 0.45), transparent 55%),
    radial-gradient(80% 50% at 100% 100%, rgba(22, 56, 47, 0.35), transparent 45%),
    var(--tv-bg);
  color: var(--tv-ink);
  font-family: 'Poppins', system-ui, sans-serif;
  overflow: hidden;
}

.tv-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  padding: clamp(16px, 2.2vh, 28px) clamp(20px, 2.6vw, 40px) clamp(16px, 2vh, 26px);
  gap: clamp(14px, 2vh, 28px);
}

/* —— top bar —— */
.tv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(16px, 2vw, 28px);
  min-height: clamp(36px, 4.2vh, 48px);
}
.tv-brand {
  display: flex;
  align-items: center;
  gap: clamp(14px, 1.6vw, 22px);
  min-width: 0;
}
.tv-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(1.15rem, 1.9vw, 1.75rem);
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--tv-ink);
}
.tv-context {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1vw, 14px);
  min-width: 0;
  padding-left: clamp(14px, 1.6vw, 22px);
  border-left: 1px solid var(--tv-line);
}
.tv-context:has(.tv-chip:empty):has(.tv-meta:empty) {
  display: none;
}
.tv-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.4em 0.75em;
  border-radius: 6px;
  background: color-mix(in srgb, var(--tv-panel) 88%, #fff);
  box-shadow: inset 0 1px 0 rgba(244, 247, 242, 0.08);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(0.78rem, 1.05vw, 1rem);
  line-height: 1;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--tv-ink);
  white-space: nowrap;
}
.tv-chip:empty { display: none; }
.tv-meta {
  font-size: clamp(0.7rem, 0.88vw, 0.84rem);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tv-mute);
  white-space: nowrap;
}
.tv-meta:empty { display: none; }

.tv-top-right {
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.5vw, 22px);
  flex: none;
}
.tv-meta--phase { color: var(--tv-faint); }
.tv-meta--phase[data-tiebreak="1"] { color: var(--tv-accent); }
.tv-status {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.42em 0.8em;
  border-radius: 6px;
  font-size: clamp(0.66rem, 0.82vw, 0.78rem);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--tv-faint);
  background: rgba(244, 247, 242, 0.05);
  box-shadow: inset 0 1px 0 rgba(244, 247, 242, 0.06);
  transition: color 280ms var(--tv-spring), background-color 280ms var(--tv-spring);
}
.tv-status i {
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.tv-status[data-state="live"] {
  color: var(--tv-pts-ink);
  background: var(--tv-accent);
  box-shadow: none;
}
.tv-status[data-state="live"] i {
  animation: tv-live-pulse 1.8s var(--tv-spring) infinite;
}
.tv-status[data-state="error"] {
  color: var(--tv-mute);
  background: rgba(106, 138, 122, 0.16);
}
@keyframes tv-live-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}
.tv-clock {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 600;
  font-size: clamp(1.05rem, 1.55vw, 1.4rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--tv-mute);
}

/* —— main —— */
.tv-main {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 0;
}
.tv-feature { display: flex; flex-direction: column; justify-content: center; min-height: 0; }

/* —— board —— */
.tv-board {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  overflow: hidden;
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(244, 247, 242, 0.06), transparent 28%),
    var(--tv-panel);
  box-shadow:
    0 1px 0 rgba(244, 247, 242, 0.08) inset,
    0 18px 48px rgba(0, 0, 0, 0.4);
}
.tv-row { display: contents; }
.tv-row > * {
  display: flex;
  align-items: center;
  padding: clamp(12px, 2.8vh, 36px) 0;
}
.tv-row:first-child > * { border-bottom: 1px solid rgba(0, 0, 0, 0.22); }

.tv-serve {
  width: clamp(1.8rem, 2.6vw, 2.8rem);
  justify-content: center;
  padding-left: clamp(8px, 1vw, 14px);
}
.tv-serve::after {
  content: '';
  width: clamp(0.55rem, 0.85vw, 0.85rem);
  height: clamp(0.55rem, 0.85vw, 0.85rem);
  border-radius: 50%;
  background: var(--tv-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tv-accent) 18%, transparent);
  opacity: 0;
  transform: scale(0.55);
  transition:
    opacity 320ms var(--tv-spring),
    transform 320ms var(--tv-spring);
}
.tv-row[data-serving="1"] .tv-serve::after {
  opacity: 1;
  transform: scale(1);
}

.tv-name {
  min-width: 0;
  padding-right: clamp(12px, 1.6vw, 28px);
  padding-left: clamp(4px, 0.5vw, 10px);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(1.5rem, min(5vw, 8vh), 4.6rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 280ms var(--tv-spring);
}
.tv-row[data-loser="1"] .tv-name,
.tv-row[data-loser="1"] .tv-sets,
.tv-row[data-loser="1"] .tv-games { color: var(--tv-mute); }

.tv-trophy { flex: none; margin-left: 0.4em; font-size: 0; }
.tv-trophy::after {
  content: '✓';
  font-family: 'Barlow Condensed', sans-serif;
  font-size: clamp(0.9rem, 1.4vw, 1.4rem);
  font-weight: 700;
  color: var(--tv-accent);
}

.tv-sets {
  gap: 0;
  padding-left: 0;
  padding-right: 0;
}
.tv-sets:empty { padding: 0; }
.tv-sets b {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(1.6rem, 3.2vw, 3.2rem);
  text-align: center;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(1.15rem, min(2.8vw, 4.6vh), 2.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--tv-mute);
  font-variant-numeric: tabular-nums;
  transition: color 280ms var(--tv-spring);
}
.tv-sets b[data-won="1"] { color: var(--tv-ink); }

.tv-games {
  justify-content: center;
  min-width: clamp(2.8rem, 5.4vw, 5.4rem);
  background: var(--tv-games);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(1.5rem, min(3.6vw, 5.8vh), 3.2rem);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--tv-ink);
}
.tv-row[data-loser="1"] .tv-games { color: rgba(244, 247, 242, 0.7); }

.tv-pts {
  justify-content: center;
  min-width: clamp(3.6rem, 8vw, 7.5rem);
  padding-left: clamp(8px, 1vw, 16px);
  padding-right: clamp(8px, 1vw, 16px);
  background: #fff;
  color: var(--tv-pts-ink);
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(2.4rem, min(7vw, 11vh), 6.6rem);
  line-height: 0.9;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.tv-row[data-loser="1"] .tv-pts {
  background: rgba(244, 247, 242, 0.72);
  color: var(--tv-mute);
}
.tv-board[data-over="1"] .tv-games,
.tv-board[data-over="1"] .tv-pts { visibility: hidden; }
.tv-pts.is-bump { animation: tv-pts-bump 380ms var(--tv-spring); }

@keyframes tv-pts-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* —— idle —— */
.tv-idle {
  display: none;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0.45em;
  padding: clamp(20px, 2.6vh, 36px) clamp(20px, 2.2vw, 36px);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(244, 247, 242, 0.06), transparent 28%),
    var(--tv-panel);
  box-shadow:
    0 1px 0 rgba(244, 247, 242, 0.08) inset,
    0 18px 48px rgba(0, 0, 0, 0.4);
}
.tv-feature[data-state="idle"] .tv-board { display: none; }
.tv-feature[data-state="idle"] .tv-idle { display: flex; }
.tv-idle-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(1.6rem, 4vw, 3rem);
  line-height: 0.95;
  letter-spacing: -0.015em;
  text-transform: uppercase;
  color: var(--tv-ink);
}
.tv-idle-sub {
  font-size: clamp(0.8rem, 1.05vw, 1rem);
  line-height: 1.45;
  color: var(--tv-mute);
}

/* —— bottom: other courts + QR —— */
.tv-bottom {
  display: flex;
  align-items: flex-end;
  gap: clamp(12px, 1.4vw, 22px);
  min-height: 0;
}
.tv-cards {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(8px, 1vw, 16px);
  min-width: 0;
}
.tv-cards:empty,
.tv-cards[hidden] { display: none; }

.tv-qr-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45em;
  width: clamp(72px, 7.2vw, 96px);
  margin-left: auto;
  flex: none;
}
.tv-qr {
  width: 100%;
  aspect-ratio: 1;
  padding: 0.32rem;
  background: #fff;
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.tv-qr img,
.tv-qr canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}
.tv-qr-label {
  font-size: clamp(0.52rem, 0.68vw, 0.68rem);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tv-faint);
  white-space: nowrap;
}

.tv-card {
  appearance: none;
  display: grid;
  gap: 0.2em;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: clamp(8px, 1vh, 12px) clamp(10px, 1vw, 14px) clamp(9px, 1.1vh, 13px);
  border: 0;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(244, 247, 242, 0.05), transparent 40%),
    var(--tv-panel);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(244, 247, 242, 0.06) inset;
  transition:
    box-shadow 280ms var(--tv-spring),
    background-color 280ms var(--tv-spring),
    transform var(--tv-press);
  will-change: transform;
}
@media (hover: hover) and (pointer: fine) {
  .tv-card:hover {
    background:
      linear-gradient(180deg, rgba(244, 247, 242, 0.08), transparent 40%),
      var(--tv-panel-raised);
  }
}
.tv-card:active {
  transform: scale(0.97);
}
.tv-card:focus-visible {
  outline: 2px solid var(--tv-accent);
  outline-offset: 3px;
}
.tv-card[data-live="1"] {
  box-shadow: 0 1px 0 rgba(244, 247, 242, 0.06) inset;
}
.tv-card.is-on {
  box-shadow: 0 1px 0 rgba(244, 247, 242, 0.08) inset;
  background:
    linear-gradient(180deg, rgba(244, 247, 242, 0.1), transparent 45%),
    color-mix(in srgb, var(--tv-panel) 72%, #fff);
}
.tv-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6em;
  padding-bottom: 0.3em;
  margin-bottom: 0.2em;
  border-bottom: 1px solid rgba(0, 0, 0, 0.2);
  font-size: clamp(0.56rem, 0.72vw, 0.72rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tv-mute);
}
.tv-card-games {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 1.2em;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--tv-ink);
}
.tv-card-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8em;
  min-width: 0;
}
.tv-card-name {
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(0.95rem, 1.4vw, 1.35rem);
  line-height: 1.15;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tv-card-row[data-serving="1"] .tv-card-name::before {
  content: '';
  display: inline-block;
  width: 0.42em;
  height: 0.42em;
  margin-right: 0.4em;
  vertical-align: 0.12em;
  border-radius: 50%;
  background: var(--tv-accent);
}
.tv-card-score {
  flex: none;
  min-width: 1.2em;
  text-align: right;
  font-family: 'Barlow Condensed', sans-serif;
  font-weight: 700;
  font-size: clamp(1rem, 1.45vw, 1.4rem);
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .tv-qr-block { display: none; }
  .tv-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .tv-pts.is-bump,
  .tv-status[data-state="live"] i { animation: none; }
  .tv-serve::after,
  .tv-status,
  .tv-card,
  .tv-name,
  .tv-sets b { transition: none; }
  .tv-card:active { transform: none; }
}
