/* GetStream — a multi-court wall for ATP Challenger TV and ITF streams.
   Night-session palette: near-black court blues, optic-yellow accent (the ball), red for live. */

:root {
  color-scheme: dark;
  --bg: #090c11;
  --bg-raised: #0e1218;
  --surface: #141920;
  --surface-2: #1a2029;
  --surface-3: #242c37;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.13);
  --text: #eef2f6;
  --text-2: #a7b1bd;
  --text-3: #6f7a88;
  --accent: #d6f43f;
  --accent-hover: #e3fb63;
  --accent-soft: rgba(214, 244, 63, 0.14);
  --accent-ink: #12160a;
  --live: #ff4d5e;
  --live-text: #ff8592;
  --live-soft: rgba(255, 77, 94, 0.14);
  --warn: #ffb648;
  --warn-soft: rgba(255, 182, 72, 0.14);
  --atp: #6aa5ff;
  --itf: #36d8a8;
  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 60px;
  --panel-w: 380px;
  --stage-pad: 12px;
  --font: "Barlow", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-cond: "Barlow Condensed", "Bahnschrift SemiCondensed", "DIN Condensed", "Roboto Condensed", "Arial Narrow", sans-serif;
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2 { margin: 0; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

kbd {
  font: 600 11px/1 var(--font);
  padding: 2px 6px; border-radius: 5px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--text-2);
}

/* ---------------------------------------------------------------- shell */

.app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "top top" "stage panel";
}
.app[data-panel="closed"] .panel { display: none; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  grid-area: top;
  position: relative; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px 0 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0d1117, #0a0d12);
}
.brand { display: flex; align-items: center; gap: 11px; margin-right: auto; min-width: 0; color: inherit; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-ball { fill: var(--accent); }
.brand-seam { fill: none; stroke: var(--bg); stroke-width: 2.2; stroke-linecap: round; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font: 700 23px/0.95 var(--font-cond); letter-spacing: 0.07em; text-transform: uppercase; }
.brand-tag { margin-top: 3px; font-size: 11.5px; line-height: 1.2; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; }
.seg-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 12px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.seg-btn .i { width: 18px; height: 18px; }
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-pressed="true"] { background: var(--surface-3); color: var(--text); }
.seg-btn[aria-pressed="true"] .i { color: var(--accent); }

.top-actions { display: flex; align-items: center; gap: 4px; }
.live-chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; margin-right: 8px; padding: 0 12px; border-radius: 999px;
  background: var(--live-soft); color: var(--live-text);
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.live-chip b { font: 700 16px/1 var(--font-cond); color: #fff; letter-spacing: 0.02em; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.8s infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 94, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(255, 77, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 94, 0); }
}

/* ---------------------------------------------------------------- buttons */

.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: inline-grid; place-items: center; border-radius: 10px;
  color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn:disabled { opacity: 0.4; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}
.btn .i { width: 18px; height: 18px; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.panel-toggle[aria-pressed="true"] { border-color: rgba(214, 244, 63, 0.35); }
.panel-toggle[aria-pressed="true"] .i { color: var(--accent); }

.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-grid; place-items: center;
  font: 700 12px/1 var(--font-cond); letter-spacing: 0.02em;
  background: var(--surface-3); color: var(--text);
}
.badge:empty { display: none; }
.badge-live { background: var(--live); color: #fff; }

/* ---------------------------------------------------------------- stage */

.stage {
  grid-area: stage;
  position: relative;
  min-width: 0; min-height: 0;
  background:
    radial-gradient(1100px 520px at 30% -12%, rgba(214, 244, 63, 0.035), transparent 62%),
    var(--bg);
}
.wall { position: absolute; inset: var(--stage-pad); }
.wall.no-anim .tile { transition: none; }

.stage.is-drop-zone::after {
  content: "";
  position: absolute; inset: 6px; z-index: 8;
  border: 2px dashed var(--accent); border-radius: var(--radius-lg);
  background: rgba(214, 244, 63, 0.04);
  pointer-events: none;
}

.wall-empty { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; overflow: auto; }
.empty-card { max-width: 470px; display: grid; justify-items: center; gap: 14px; }
.court-art { width: min(300px, 72vw); height: auto; margin-bottom: 8px; }
.court-art .ln { fill: none; stroke: rgba(255, 255, 255, 0.15); stroke-width: 1.4; }
.court-art .net { fill: none; stroke: rgba(255, 255, 255, 0.34); stroke-width: 1.6; stroke-dasharray: 2 3; }
.court-art .trail { fill: none; stroke: var(--accent); stroke-opacity: 0.45; stroke-width: 1.4; stroke-dasharray: 3 5; }
.court-art .ball { fill: var(--accent); }
.empty-title { font: 700 34px/1 var(--font-cond); letter-spacing: 0.04em; text-transform: uppercase; }
.empty-text { margin: 0; max-width: 400px; color: var(--text-2); font-size: 15px; }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }
.empty-hint { margin: 6px 0 0; color: var(--text-3); font-size: 12.5px; line-height: 2; }

.theater-exit { display: none; position: absolute; z-index: 30; top: 12px; left: 50%; transform: translateX(-50%); opacity: 0.3; background: rgba(14, 18, 24, 0.9); transition: opacity 0.2s; }
.theater-exit:hover, .theater-exit:focus-visible { opacity: 1; }

/* ---------------------------------------------------------------- tiles */

/* Idle, a tile is just the picture: square corners, no border, no overlays. Everything else
   appears on hover / tap (see "Showing the overlays" below). */
.tile {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  overflow: hidden;
  background: #000;
  container-type: size;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-touch-callout: none; /* no iOS long-press menu over the video */
  transition: transform 0.38s var(--ease), width 0.38s var(--ease), height 0.38s var(--ease);
}
.tile.no-anim { transition: none; }
.tile.is-entering { animation: tile-in 0.34s var(--ease); }
@keyframes tile-in { from { opacity: 0; scale: 0.96; } }

.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
/* Only for short-lived feedback: a drop target while dragging, or a flash when a match that's
   already on the wall is picked again. */
.tile::after {
  content: "";
  position: absolute; inset: 0; z-index: 9;
  pointer-events: none;
  transition: box-shadow 0.2s;
}
.tile.is-drop::after { box-shadow: inset 0 0 0 2px var(--accent), inset 0 0 0 999px rgba(214, 244, 63, 0.12); }
.tile.is-flash::after { animation: tile-flash 0.55s var(--ease) 3; }
.tile.is-dragging { opacity: 0.5; }
@keyframes tile-flash { 50% { box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 999px rgba(214, 244, 63, 0.14); } }

.tile-shade {
  position: absolute; inset: 0; z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.62) 0, rgba(0, 0, 0, 0) 64px),
    linear-gradient(0deg, rgba(0, 0, 0, 0.5) 0, rgba(0, 0, 0, 0) 96px);
  opacity: 0;
  transition: opacity 0.2s;
}

/* Above .tile-state, so remove/drag stay usable while a tile is connecting or waiting. */
.tile-top {
  position: absolute; z-index: 5; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 7px; min-width: 0;
  padding: 9px 9px 0 10px;
  font-size: 12.5px; color: rgba(255, 255, 255, 0.9);
  cursor: grab;
  opacity: 0; visibility: hidden;
  transition: opacity 0.18s, visibility 0s linear 0.18s;
}
.tile-top:active { cursor: grabbing; }
.tile-index {
  display: none;
  width: 18px; flex: none; border-radius: 5px; text-align: center;
  font: 700 11px/18px var(--font-cond);
  background: rgba(255, 255, 255, 0.16); color: #fff;
}
.src-badge {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  height: 20px; padding: 0 6px; border-radius: 6px;
  background: rgba(9, 12, 17, 0.72); border: 1px solid rgba(255, 255, 255, 0.12);
  font: 600 11.5px/1 var(--font-cond); letter-spacing: 0.06em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.9);
}
.src-badge b { font-weight: 700; }
.tile[data-source="atp"] .src-badge b { color: var(--atp); }
.tile[data-source="itf"] .src-badge b { color: var(--itf); }
.tile-event { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }
.tile-top-spacer { flex: 1; }
.tile-live {
  flex: none;
  display: inline-flex; align-items: center; gap: 5px;
  height: 20px; padding: 0 7px; border-radius: 6px;
  background: var(--live); color: #fff;
  font: 700 11.5px/1 var(--font-cond); letter-spacing: 0.08em; text-transform: uppercase;
  cursor: default;
}
.tile-live i { width: 6px; height: 6px; border-radius: 50%; background: #fff; }
.tile-live.is-behind { cursor: pointer; background: rgba(9, 12, 17, 0.75); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2); color: rgba(255, 255, 255, 0.9); }
.tile-live.is-behind i { background: var(--text-3); }
.tile-live.is-behind .tile-live-text::before { content: "Go "; }
.tile-live.is-behind:hover { background: var(--live); }
.tile-x {
  flex: none;
  width: 26px; height: 26px; border-radius: 7px;
  display: grid; place-items: center;
  background: rgba(9, 12, 17, 0.62); color: #fff;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}
.tile-x .i { width: 16px; height: 16px; }
.tile-x:hover { background: rgba(255, 77, 94, 0.92); }

/* scoreboard "bug" — top-left, because both ATP and some ITF court feeds burn their own
   broadcast scoreboard into the bottom-left of the picture. Only shown with the other
   overlays (hover / tap), so it never sits on top of the match. */
.tile-bug {
  position: absolute; z-index: 2; left: 10px; top: 37px;
  display: grid; gap: 1px;
  max-width: calc(100% - 20px);
  padding: 4px 5px 4px 7px; border-radius: 7px;
  /* no backdrop blur: over 16 playing videos it costs real GPU time, especially on phones */
  background: rgba(8, 11, 15, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font: 600 12.5px/1.3 var(--font-cond); letter-spacing: 0.03em; text-transform: uppercase;
  opacity: 0; visibility: hidden;
  transition: opacity 0.18s, visibility 0s linear 0.18s;
}
.sb-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.sb-cc { width: 26px; flex: none; font-size: 11px; letter-spacing: 0.08em; color: var(--text-3); }
.sb-cc:empty { display: none; }
.sb-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #fff; }
.sb-serve { width: 6px; height: 6px; flex: none; border-radius: 50%; }
.is-serving .sb-serve { background: var(--accent); }
.sb-set { min-width: 15px; text-align: center; color: rgba(255, 255, 255, 0.82); font-variant-numeric: tabular-nums; }
.sb-set sup { font-size: 8px; margin-left: 1px; }
.sb-game {
  min-width: 26px; margin-left: 2px; padding: 0 4px; border-radius: 4px;
  text-align: center; font-weight: 700;
  background: var(--accent); color: var(--accent-ink);
}
.is-winner .sb-name { color: var(--accent); }

/* replay offer */
.tile-notice {
  position: absolute; z-index: 4; left: 50%; bottom: 72px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  max-width: calc(100% - 20px); white-space: nowrap;
  padding: 5px 5px 5px 12px; border-radius: 10px;
  background: rgba(9, 12, 17, 0.88); border: 1px solid var(--line-2);
  font-size: 13px;
}
.notice-btn { height: 28px; padding: 0 12px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-size: 12.5px; font-weight: 600; }

/* controls */
.tile-controls {
  position: absolute; z-index: 4; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 2px;
  height: 48px; padding: 0 6px 8px;
  opacity: 0; transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.22s var(--ease);
}
.tc {
  width: 34px; height: 34px; flex: none;
  display: grid; place-items: center; border-radius: 9px;
  color: #fff;
  transition: background 0.15s, color 0.15s;
}
.tc:hover { background: rgba(255, 255, 255, 0.15); }
.tc .i { width: 19px; height: 19px; }
.tc-audio.is-on { color: var(--accent); }
.tc-text { width: auto; padding: 0 8px; font: 700 13px/1 var(--font-cond); letter-spacing: 0.04em; }
.tc-time { padding: 0 4px; white-space: nowrap; font: 600 12.5px/1 var(--font-cond); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; color: rgba(255, 255, 255, 0.78); }
.tc-spacer { flex: 1; }
/* Play/pause, −10s and the clock only mean something once a stream is attached. */
.tile:not([data-state="playing"], [data-state="buffering"], [data-state="paused"]) :is(.tc-play, .tc-back, .tc-time) { display: none; }
.tc-volume { width: 76px; margin: 0 6px 0 2px; accent-color: var(--accent); cursor: pointer; }

/* seek bar — a replay, or a live stream's DVR window with the live edge on the right. Shown with
   the other overlays, just above the controls. --p is the played fraction. */
.tile-progress {
  --p: 0;
  position: absolute; z-index: 5; left: 14px; right: 14px; bottom: 46px;
  height: 16px;
  cursor: pointer; touch-action: none;
  opacity: 0; pointer-events: none;
  transition: opacity 0.18s;
}
.tp-track, .tp-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; border-radius: 3px; transition: height 0.15s; }
.tp-track { background: rgba(255, 255, 255, 0.24); }
.tp-fill { background: var(--accent); transform-origin: left; transform: scaleX(var(--p)); }
.tp-knob {
  position: absolute; bottom: -4px; left: calc(var(--p) * 100%);
  width: 13px; height: 13px; margin-left: -6.5px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.35);
  transform: scale(0); transition: transform 0.15s;
}
.tp-tip {
  position: absolute; left: 0; bottom: 17px; transform: translateX(-50%);
  padding: 4px 7px; border-radius: 6px;
  background: rgba(9, 12, 17, 0.92); border: 1px solid var(--line-2); color: #fff;
  font: 600 12px/1 var(--font-cond); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity 0.12s;
}
.tile-progress:is(:hover, .is-scrubbing) :is(.tp-track, .tp-fill) { height: 5px; }
.tile-progress:is(:hover, .is-scrubbing) .tp-knob { transform: scale(1); }
.tile-progress:is(.is-hover, .is-scrubbing) .tp-tip { opacity: 1; }

/* what's going on: connecting / waiting / error / ended / paused */
.tile-state {
  position: absolute; z-index: 3; inset: 0;
  display: none; place-content: center; justify-items: center; gap: 8px;
  padding: 18px; text-align: center;
  background: rgba(6, 8, 11, 0.74);
}
.tile[data-state="loading"] .tile-state,
.tile[data-state="waiting"] .tile-state,
.tile[data-state="error"] .tile-state,
.tile[data-state="ended"] .tile-state,
.tile[data-state="paused"] .tile-state { display: grid; }
.tile[data-state="buffering"] .tile-state { display: grid; background: none; pointer-events: none; }
.tile[data-state="paused"] .tile-state { background: rgba(6, 8, 11, 0.35); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.14); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.state-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.08); }
.state-icon .i { width: 22px; height: 22px; }
.state-icon-waiting { color: var(--accent); background: var(--accent-soft); }
.state-icon-error { color: var(--live-text); background: var(--live-soft); }
.state-title { max-width: 34ch; font-size: 15px; font-weight: 600; line-height: 1.25; color: #fff; }
.state-detail { max-width: 38ch; color: var(--text-2); font-size: 13px; }
.state-countdown { color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.state-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }
.state-btn { height: 32px; padding: 0 14px; border-radius: 9px; font-size: 13px; font-weight: 600; }
.state-btn-solid { background: var(--accent); color: var(--accent-ink); }
.state-btn-solid:hover { background: var(--accent-hover); }
.state-btn-ghost { background: rgba(255, 255, 255, 0.1); color: #fff; }
.state-btn-ghost:hover { background: rgba(255, 255, 255, 0.18); }
.state-play {
  width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(9, 12, 17, 0.72); border: 1px solid rgba(255, 255, 255, 0.22); color: #fff;
}
.state-play .i { width: 28px; height: 28px; margin-left: 3px; }

/* per-tile menu */
.tile-menu {
  position: absolute; z-index: 8; right: 8px; bottom: 52px;
  min-width: min(196px, calc(100% - 16px)); max-width: calc(100% - 16px);
  max-height: calc(100% - 64px); overflow: auto;
  padding: 6px; border-radius: 12px;
  background: rgba(20, 25, 32, 0.97); border: 1px solid var(--line-2);
  box-shadow: var(--shadow-lg);
}
.menu-label { padding: 6px 10px 4px; font: 700 11px/1 var(--font-cond); letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-3); }
.menu-item { width: 100%; height: 34px; display: flex; align-items: center; gap: 10px; padding: 0 10px; border-radius: 8px; font-size: 13.5px; text-align: left; color: var(--text); }
.menu-item:hover { background: var(--surface-3); }
.menu-item .i { width: 17px; height: 17px; color: var(--text-2); }
.menu-item[aria-checked="true"] .i { color: var(--accent); }
.menu-item-danger, .menu-item-danger .i { color: var(--live-text); }
.menu-sep { height: 1px; margin: 5px 4px; background: var(--line); }

/* Showing the overlays: hover with a mouse, a tap on touch screens (.show-controls, hides
   itself again), an open menu, or keyboard focus inside the tile. Keyboard focus only — a
   mouse click on a tile button shouldn't keep everything pinned after the pointer leaves. */
.tile:is(.show-controls, .menu-open, :has(:focus-visible)) .tile-shade { opacity: 1; }
.tile:is(.show-controls, .menu-open, :has(:focus-visible)) .tile-controls { opacity: 1; transform: none; pointer-events: auto; }
.tile:is(.show-controls, .menu-open, :has(:focus-visible)) :is(.tile-top, .tile-x, .tile-bug) { opacity: 1; visibility: visible; transition: opacity 0.18s; }
.tile:is(.show-controls, .menu-open, :has(:focus-visible)) .tile-progress { opacity: 1; pointer-events: auto; }

@media (hover: hover) and (pointer: fine) {
  .tile:hover .tile-shade { opacity: 1; }
  .tile:hover .tile-controls { opacity: 1; transform: none; pointer-events: auto; }
  .tile:hover :is(.tile-top, .tile-x, .tile-bug) { opacity: 1; visibility: visible; transition: opacity 0.18s; }
  .tile:hover .tile-progress { opacity: 1; pointer-events: auto; }
  .tile:hover .tile-index { display: inline-block; }
}

/* No picture to look at (connecting, waiting, error, finished): keep the label up so the tile
   still says which match it is. */
.tile:not([data-state="playing"], [data-state="buffering"], [data-state="paused"]) :is(.tile-top, .tile-bug) {
  opacity: 1; visibility: visible;
}
@media (hover: none) {
  .tc-volume { display: none; } /* iOS ignores volume; hardware buttons do it everywhere */
}

/* small tiles (3×3, 4×4, the focus strip) shed controls progressively */
@container (min-width: 900px) {
  .tile-bug { top: 45px; left: 14px; font-size: 14.5px; padding: 5px 6px 5px 9px; }
  .sb-cc { width: 30px; font-size: 12px; }
  .tile-top { font-size: 13.5px; padding: 12px 12px 0 14px; }
}
@container (max-width: 560px) { .tc-volume { display: none; } }
@container (max-width: 440px) {
  .tile-event, .tc-time { display: none; }
  .tile-bug { font-size: 12px; }
  .sb-cc { display: none; }
}
/* The feature (spotlight) button belongs to Focus layout only — in Grid it would switch layouts. */
.app[data-layout="grid"] .tc-spot { display: none; }

/* In Focus it stays at every size. */
@container (max-width: 340px) {
  .tc-back, .tc-play { display: none; }
  .state-detail, .state-countdown { display: none; }
  .tile-bug { top: 33px; left: 7px; padding: 3px 4px 3px 6px; font-size: 11px; border-radius: 6px; }
  .sb-set { min-width: 12px; }
  .sb-game { min-width: 20px; }
}
/* The close (×) button stays at every size — on a phone it's the way to take a stream off the wall. */
@container (max-width: 250px) {
  .tile-bug, .tile-index, .tile-progress, .state-actions, .state-icon, .tile-notice { display: none !important; }
  .tile-top { padding: 6px; }
  .tile-controls { height: 42px; padding: 0 4px 6px; }
  .state-title { font-size: 12px; }
  .spinner { width: 24px; height: 24px; border-width: 2px; }
}
@container (max-width: 170px) { .tc-full, .tc-more, .tile-live { display: none; } }
@container (max-height: 150px) { .tile-bug { display: none; } }

/* ---------------------------------------------------------------- match panel */

.panel {
  grid-area: panel;
  width: var(--panel-w);
  display: flex; flex-direction: column;
  min-height: 0;
  background: var(--bg-raised);
  border-left: 1px solid var(--line);
}
.panel-head { display: grid; gap: 12px; padding: 14px 14px 12px; border-bottom: 1px solid var(--line); }
.panel-title { display: flex; align-items: center; justify-content: space-between; min-height: 24px; }
.panel-title h2 { font: 700 20px/1 var(--font-cond); letter-spacing: 0.07em; text-transform: uppercase; }
.panel-close { display: none; margin: -8px -6px -8px 0; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.tab { height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--text-2); transition: background 0.15s, color 0.15s; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); }
.tab-count { font: 700 12.5px/1 var(--font-cond); color: var(--text-3); }
.tab[aria-selected="true"] .tab-count { color: var(--accent); }

.filters { display: grid; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 30px; display: inline-flex; align-items: center; gap: 7px;
  padding: 0 11px; border-radius: 999px; border: 1px solid var(--line-2);
  font-size: 13px; font-weight: 600; color: var(--text-2);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.24); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip-dot { width: 7px; height: 7px; border-radius: 50%; }
.chip-atp .chip-dot { background: var(--atp); }
.chip-itf .chip-dot { background: var(--itf); }
.chip-count { font: 700 12.5px/1 var(--font-cond); opacity: 0.7; }

.search { position: relative; display: flex; align-items: center; }
.search > .i { position: absolute; left: 11px; width: 17px; height: 17px; color: var(--text-3); pointer-events: none; }
.search input {
  width: 100%; height: 38px; padding: 0 38px 0 36px;
  border-radius: 10px; border: 1px solid var(--line); outline: none;
  background: var(--surface); font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input:focus { border-color: rgba(214, 244, 63, 0.55); box-shadow: 0 0 0 3px rgba(214, 244, 63, 0.12); }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-clear { position: absolute; right: 5px; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 7px; color: var(--text-3); }
.search-clear:hover { background: var(--surface-2); color: var(--text); }
.search-clear .i { width: 16px; height: 16px; }

.panel-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 2px 10px 18px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}

.grp-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 2px 8px;
  background: var(--bg-raised);
}
.grp-toggle { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; text-align: left; }
.grp-chev { width: 16px; height: 16px; color: var(--text-3); transition: transform 0.2s var(--ease); }
.grp-toggle[aria-expanded="false"] .grp-chev { transform: rotate(-90deg); }
.tier {
  flex: none; height: 19px; padding: 0 6px; border-radius: 5px;
  display: inline-flex; align-items: center;
  font: 700 11px/1 var(--font-cond); letter-spacing: 0.06em; text-transform: uppercase;
}
.tier-atp { background: rgba(106, 165, 255, 0.15); color: var(--atp); }
.tier-itf { background: rgba(54, 216, 168, 0.13); color: var(--itf); }
.grp-name { flex: none; max-width: 52%; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp-loc { min-width: 0; color: var(--text-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp-count { flex: none; font: 700 12.5px/1 var(--font-cond); color: var(--text-3); }
.grp-all {
  flex: none; height: 26px; padding: 0 9px 0 5px; border-radius: 7px;
  display: inline-flex; align-items: center; gap: 3px;
  border: 1px solid var(--line-2);
  font-size: 12px; font-weight: 600; color: var(--text-2);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.grp-all .i { width: 15px; height: 15px; }
.grp-all:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.mrow {
  position: relative;
  display: grid; grid-template-columns: minmax(0, 1fr) 34px; grid-template-areas: "top add" "sides add";
  align-items: center; gap: 7px 10px;
  margin: 0 0 6px; padding: 10px 10px 10px 12px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.mrow:hover { background: var(--surface-2); border-color: var(--line-2); }
.mrow:active { transform: scale(0.995); }
.mrow.is-added { border-color: rgba(214, 244, 63, 0.32); background: linear-gradient(90deg, rgba(214, 244, 63, 0.07), transparent 65%), var(--surface); }
.mrow-top { grid-area: top; display: flex; align-items: center; gap: 8px; min-width: 0; }
.mrow-meta { min-width: 0; color: var(--text-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mrow-sides { grid-area: sides; display: grid; gap: 3px; min-width: 0; }
.mrow-add {
  grid-area: add;
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.mrow:hover .mrow-add { background: var(--accent); color: var(--accent-ink); }
.mrow.is-added .mrow-add { background: var(--accent-soft); color: var(--accent); }

.side { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 14px; }
.cc { flex: none; width: 30px; font: 600 11.5px/1 var(--font-cond); letter-spacing: 0.08em; color: var(--text-3); }
.side-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.seed { flex: none; padding: 1px 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.06); font: 600 11px/1.2 var(--font-cond); color: var(--text-3); }
.side-score { flex: none; display: flex; gap: 2px; margin-left: auto; font: 600 14.5px/1 var(--font-cond); font-variant-numeric: tabular-nums; color: var(--text-2); }
.sc-set { min-width: 16px; text-align: center; }
.sc-set sup { font-size: 9px; }
.sc-game { min-width: 26px; margin-left: 4px; text-align: center; color: var(--accent); }
.side.is-serving .side-name::after {
  content: "";
  display: inline-block; width: 6px; height: 6px; margin-left: 7px;
  border-radius: 50%; background: var(--accent); vertical-align: 2px;
}
.side.is-winner .side-name { font-weight: 700; }
.side.is-winner .side-score { color: var(--text); }

.pill {
  flex: none;
  display: inline-flex; align-items: center; gap: 6px;
  height: 20px; padding: 0 8px; border-radius: 999px;
  font: 700 11.5px/1 var(--font-cond); letter-spacing: 0.08em; text-transform: uppercase;
  white-space: nowrap;
}
.pill-live { background: var(--live-soft); color: var(--live-text); }
.pill-live i { width: 6px; height: 6px; border-radius: 50%; background: var(--live); animation: blink 1.6s ease-in-out infinite; }
.pill-live.is-halted { background: var(--warn-soft); color: var(--warn); }
.pill-live.is-halted i { background: var(--warn); animation: none; }
.pill-soon, .pill-done { background: rgba(255, 255, 255, 0.06); color: var(--text-2); }
@keyframes blink { 50% { opacity: 0.3; } }

.list-empty { display: grid; justify-items: center; gap: 10px; padding: 52px 20px; text-align: center; color: var(--text-2); }
.list-empty strong { font: 700 19px/1.1 var(--font-cond); letter-spacing: 0.05em; text-transform: uppercase; color: var(--text); }

.skeleton {
  height: 78px; margin: 0 0 6px; border-radius: 12px;
  background: linear-gradient(90deg, var(--surface) 0, var(--surface-2) 40%, var(--surface) 80%) 0 0 / 300% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton-head { width: 55%; height: 18px; margin: 16px 2px 10px; border-radius: 6px; }
@keyframes shimmer { to { background-position: -300% 0; } }

.panel-foot { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 14px; border-top: 1px solid var(--line); color: var(--text-3); font-size: 12.5px; }
.status { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.status.has-error { color: var(--warn); }
.refresh-btn { width: 32px; height: 32px; }
.refresh-btn .i { width: 18px; height: 18px; }
.refresh-btn.is-spinning .i { animation: spin 0.9s linear infinite; }

/* ---------------------------------------------------------------- phone chrome */

.bottombar { display: none; }
.fab { display: none; }

.toasts {
  position: fixed; z-index: 60; left: 50%; bottom: 22px;
  transform: translateX(-50%);
  display: grid; justify-items: center; gap: 8px;
  width: max-content; max-width: calc(100vw - 24px);
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; border-radius: 12px;
  background: #1f2731; border: 1px solid var(--line-2);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  pointer-events: auto;
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.2s, transform 0.25s var(--ease);
}
.toast:has(.toast-btn) { padding-right: 8px; }
.toast.is-in { opacity: 1; transform: none; }
.toast-btn { height: 28px; padding: 0 12px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 12.5px; font-weight: 600; }

/* ---------------------------------------------------------------- fullscreen wall */

.app.is-theater { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "stage"; }
.app.is-theater .topbar,
.app.is-theater .panel,
.app.is-theater .bottombar,
.app.is-theater .fab { display: none !important; }
.app.is-theater .wall { inset: 4px; }
.app.is-theater .theater-exit { display: inline-flex; }

/* ---------------------------------------------------------------- phones, portrait */

@media (max-width: 760px) {
  :root { --topbar-h: 54px; --stage-pad: 6px; }

  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top" "stage" "nav";
  }
  .topbar { height: calc(var(--topbar-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0 12px; gap: 6px; }
  .brand-mark { width: 28px; height: 28px; }
  .brand-name { font-size: 21px; }
  .brand-tag { display: none; }
  .seg-btn { padding: 0 9px; }
  .seg-btn span { display: none; }
  .live-chip { margin-right: 2px; padding: 0 10px; }
  .live-chip-label, #btn-theater, #btn-panel { display: none; }
  .icon-btn { width: 36px; height: 36px; }

  .app[data-panel] .panel {
    position: fixed; z-index: 40; left: 0; right: 0;
    top: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px);
    bottom: calc(62px + env(safe-area-inset-bottom));
    width: auto;
    display: flex;
    border: 0; border-top: 1px solid var(--line-2);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -18px 40px rgba(0, 0, 0, 0.55);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 0.32s var(--ease), visibility 0s linear 0.32s;
  }
  .app[data-view="matches"] .panel { transform: none; visibility: visible; transition: transform 0.32s var(--ease); }
  .panel-close { display: inline-grid; }
  .panel-head { padding-top: 16px; }

  .bottombar {
    grid-area: nav;
    position: relative; z-index: 45;
    display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--bg-raised);
  }
  .nav-btn { height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; border-radius: 12px; font-weight: 600; color: var(--text-2); }
  .nav-btn[aria-current="page"] { background: var(--surface-2); color: var(--text); }
  .nav-btn[aria-current="page"] .i { color: var(--accent); }

  .toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .empty-title { font-size: 28px; }
  .empty-hint { display: none; }
  .mrow { padding: 11px 10px 11px 12px; }
  .side { font-size: 15px; }
}

/* ---------------------------------------------------------------- phones, landscape: all wall */

@media (max-height: 520px) and (orientation: landscape) and (pointer: coarse) {
  :root { --stage-pad: 4px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "stage"; }
  .topbar, .bottombar { display: none; }
  .wall { left: max(4px, env(safe-area-inset-left)); right: max(4px, env(safe-area-inset-right)); }

  .app[data-panel] .panel {
    position: fixed; z-index: 40; top: 0; right: 0; bottom: 0; left: auto;
    width: min(380px, 62vw);
    display: flex;
    padding-right: env(safe-area-inset-right);
    border-radius: 0; border: 0; border-left: 1px solid var(--line-2);
    box-shadow: -18px 0 40px rgba(0, 0, 0, 0.55);
    transform: translateX(105%);
    visibility: hidden;
    transition: transform 0.3s var(--ease), visibility 0s linear 0.3s;
  }
  .app[data-view="matches"] .panel { transform: none; visibility: visible; transition: transform 0.3s var(--ease); }
  .panel-close { display: inline-grid; }

  .fab {
    position: fixed; z-index: 35;
    right: max(12px, env(safe-area-inset-right)); bottom: 12px;
    width: 46px; height: 46px; border-radius: 50%;
    display: grid; place-items: center;
    background: rgba(20, 25, 32, 0.82); border: 1px solid var(--line-2); color: var(--text);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-lg);
  }
  .fab .badge { position: absolute; top: -4px; right: -4px; }
  .app[data-view="matches"] .fab { display: none; }
  .toasts { bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
