:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #e9edf2;
  --text: #121820;
  --muted: #5b6573;
  --border: #d8dee6;
  --accent: #0f766e;
  --accent-soft: rgba(15, 118, 110, 0.18);
  --danger: #c81e1e;
  --home: #1d4ed8;
  --away: #b91c1c;
  --ball: #fbbf24;
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-2: #212833;
    --text: #e6edf3;
    --muted: #8d98a6;
    --border: #2d3541;
    --accent: #14b8a6;
    --accent-soft: rgba(20, 184, 166, 0.22);
    --danger: #f87171;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #212833;
  --text: #e6edf3;
  --muted: #8d98a6;
  --border: #2d3541;
  --accent: #14b8a6;
  --accent-soft: rgba(20, 184, 166, 0.22);
  --danger: #f87171;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body.scoring { overflow: hidden; overscroll-behavior: none; }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */

.page {
  width: 100%;
  min-height: 100dvh;
  padding: clamp(16px, 3vw, 40px);
  padding-left: max(clamp(16px, 3vw, 40px), env(safe-area-inset-left));
  padding-right: max(clamp(16px, 3vw, 40px), env(safe-area-inset-right));
  padding-bottom: max(clamp(16px, 3vw, 40px), env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: clamp(16px, 2.5vw, 28px);
  flex-wrap: wrap;
}
.topbar h1 { flex: 1; font-size: clamp(1.35rem, 2.6vw, 2rem); min-width: 0; }

.section { margin-bottom: clamp(20px, 3vw, 36px); }
.section > h2 { font-size: clamp(1rem, 1.6vw, 1.2rem); color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: clamp(10px, 1.4vw, 18px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
}

.empty {
  text-align: center;
  padding: clamp(32px, 8vh, 96px) 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}
.empty h2 { margin-bottom: 8px; }
.empty p { margin: 0 0 20px; }

/* ---------- Buttons & inputs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5em;
  min-height: 46px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.big { min-height: 56px; padding: 0 28px; font-size: 1.1rem; }
.btn:disabled { opacity: .45; filter: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
}
.icon-btn.danger { color: var(--danger); }
.icon-btn svg { flex: none; }

.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; }

input {
  font: inherit;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: .85rem; font-weight: 650; color: var(--muted); }
.field-row { display: flex; gap: 12px; }
.field-row .field.small { flex: 0 0 110px; }
.field-row .field.grow { flex: 1; min-width: 0; }

.player-row { display: flex; gap: 8px; margin-bottom: 8px; }

.inline-form { display: flex; gap: 10px; margin-top: 18px; max-width: 640px; }
.inline-form input { flex: 1; }

/* ---------- Chips ---------- */

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 16px;
  min-height: 40px;
  font-weight: 600;
}
.chip.active { background: var(--text); border-color: var(--text); color: var(--bg); }

.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.live { background: var(--accent); color: #fff; }

/* ---------- Home ---------- */

.home { display: flex; flex-direction: column; gap: clamp(24px, 4vh, 44px); }
.hero { display: flex; align-items: center; gap: 16px; }
.hero svg { width: clamp(52px, 7vw, 80px); height: auto; flex: none; }
.hero h1 { font-size: clamp(1.7rem, 4vw, 3rem); }
.hero p { margin: 4px 0 0; }

.home-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: clamp(12px, 2vw, 22px);
}
.tile {
  min-height: clamp(120px, 22vh, 240px);
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 4px;
  padding: clamp(18px, 2.4vw, 30px);
  text-align: left;
  transition: transform .12s ease;
}
.tile:hover { transform: translateY(-2px); }
.tile:active { transform: scale(.98); }
.tile.primary { background: var(--accent); border-color: transparent; color: #fff; }
.tile-label { font-size: clamp(1.25rem, 2.2vw, 1.8rem); font-weight: 800; }
.tile-sub { opacity: .78; }
.home-foot { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: auto; }

/* ---------- Match cards ---------- */

.match-card { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.match-card:hover { border-color: var(--muted); }
.mc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: .85rem; }
.mc-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.mc-row .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-row small { color: var(--muted); margin-left: 6px; }
.mc-row.win b { color: var(--accent); }
.mc-games { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.mc-detail { font-size: .85rem; font-variant-numeric: tabular-nums; }

/* ---------- Teams ---------- */

.team-card { display: flex; flex-direction: column; gap: 12px; }
.tc-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.tc-name { font-size: 1.2rem; font-weight: 750; word-break: break-word; }
.tc-actions { display: flex; gap: 6px; flex: none; }
.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.player-list li { background: var(--surface-2); padding: 4px 12px; border-radius: 999px; font-size: .92rem; }

/* ---------- Wizard ---------- */

.step-meta { display: flex; justify-content: space-between; font-size: .9rem; color: var(--muted); font-weight: 600; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 6px 0 18px; }
.progress > div { height: 100%; background: var(--accent); transition: width .25s ease; }

.wiz-summary { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.sum-chip {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 10px;
  padding: 6px 12px;
  text-align: left;
  max-width: 100%;
}
.sum-chip small { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.sum-chip span { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }

.step-title { font-size: clamp(1.3rem, 2.6vw, 2rem); margin-bottom: 16px; }
.step-title .muted { font-weight: 500; }
.step-foot { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; align-items: center; }

.options.compact { grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); }
.options.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }

.option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-height: 88px;
  padding: 16px 18px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  text-align: left;
  transition: border-color .12s, transform .12s;
}
.option:hover:not(:disabled) { border-color: var(--muted); }
.option:active:not(:disabled) { transform: scale(.985); }
.option.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.option:disabled { opacity: .4; }
.option.big { align-items: center; text-align: center; min-height: clamp(110px, 18vh, 180px); }
.opt-kicker { font-size: .75rem; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.opt-title { font-size: clamp(1.1rem, 1.8vw, 1.4rem); font-weight: 750; word-break: break-word; }
.opt-num { font-size: clamp(2.4rem, 5vw, 3.6rem); font-weight: 850; line-height: 1; font-variant-numeric: tabular-nums; }
.option.side-home.selected { border-color: var(--home); box-shadow: 0 0 0 3px rgba(29, 78, 216, .25); }
.option.side-away.selected { border-color: var(--away); box-shadow: 0 0 0 3px rgba(185, 28, 28, .25); }

/* ---------- Match detail ---------- */

.detail-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center; margin-bottom: 24px; }
.detail-head .p { min-width: 0; }
.detail-head .p:last-child { text-align: right; }
.detail-head .p b { display: block; font-size: clamp(1.1rem, 2.6vw, 1.8rem); word-break: break-word; }
.detail-head .final { font-size: clamp(2.2rem, 6vw, 4rem); font-weight: 850; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; margin-bottom: 24px; }
.games-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.games-table th, .games-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); text-align: center; }
.games-table th { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.games-table td:first-child, .games-table th:first-child { text-align: left; }
.games-table .w { font-weight: 850; color: var(--accent); }
.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 12px; margin-bottom: 24px; }
.meta div { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.meta small { display: block; color: var(--muted); font-weight: 650; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- Transfer & backup ---------- */

.tile:disabled { opacity: .45; transform: none; cursor: not-allowed; }
.data-summary { margin: -8px 0 24px; }
.sync-page { max-width: 680px; }
.sync-page > p { font-size: 1.05rem; }
.sync-wait { display: flex; align-items: center; gap: 16px; padding: 32px 0; font-size: 1.1rem; }
.sync-wait p { margin: 0; }
.sync-wait .spinner, .sync-result .spinner { border-color: var(--border); border-top-color: var(--accent); margin: 0; flex: none; }
.sync-result { padding: clamp(20px, 4vw, 36px); border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.sync-result.ok { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sync-result h2 { margin-bottom: 8px; }
.sync-result p { margin: 0 0 20px; }

.import-from { margin: 0 0 4px; font-size: 1.05rem; }
.import-from + .muted { margin: 0 0 16px; }
.choice-list { display: grid; gap: 10px; }
.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 16px 18px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  text-align: left;
}
.choice b { font-size: 1.1rem; }
.choice:hover { border-color: var(--accent); }
.choice.danger b { color: var(--danger); }
.choice.danger:hover { border-color: var(--danger); }
#sync-host-body .step-foot { margin-top: 14px; }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .55);
}
.modal.open { display: flex; }
.modal-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--surface);
  border-radius: 18px;
  padding: clamp(18px, 3vw, 28px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.modal-card h2 { margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-weight: 650;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.scoring .toast { top: 16%; bottom: auto; font-size: clamp(1.1rem, 3vmin, 1.8rem); padding: 16px 28px; transform: translate(-50%, -40%); }
body.scoring .toast.show { transform: translate(-50%, -50%); }

/* ---------- Scoring screen ---------- */

.score-screen {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  background: #0a0e13;
  color: #e9eef4;
  user-select: none;
  -webkit-user-select: none;
}

.score-top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
.score-top .icon-btn { background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .14); color: #e9eef4; }
.score-top .icon-btn:disabled { opacity: .35; }
.st-title { flex: 1; text-align: center; font-weight: 750; font-size: clamp(.95rem, 2.2vmin, 1.3rem); min-width: 0; }
.st-title small { display: block; font-weight: 500; opacity: .65; font-size: .8em; }
.btn-label { display: inline; }

.courts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 0 8px;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  min-height: 0;
}

.side {
  position: relative;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  min-height: 0;
  min-width: 0;
  padding: clamp(12px, 2.2vmin, 28px);
  border: 0;
  border-radius: 20px;
  color: #fff;
  text-align: center;
  overflow: hidden;
  transition: filter .1s;
}
.side-home { background: var(--home); }
.side-away { background: var(--away); }
.side:active:not(:disabled) { filter: brightness(1.15); }
.side:disabled { cursor: default; }
/* Server: lit, thick yellow frame + ball badge. Receiver: dimmed. */
.side.serving { box-shadow: inset 0 0 0 clamp(6px, 1.1vmin, 10px) var(--ball), 0 0 clamp(12px, 3vmin, 32px) rgba(251, 191, 36, .45); }
.side.receiving::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(0, 0, 0, .36);
  pointer-events: none;
}
.serve-ball {
  position: absolute;
  top: clamp(12px, 2.4vmin, 26px);
  left: clamp(12px, 2.4vmin, 26px);
  width: clamp(30px, 8vmin, 76px);
  height: clamp(30px, 8vmin, 76px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff7d6 0 12%, var(--ball) 45%, #d97706 100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  animation: serve-pulse 1.4s ease-in-out infinite;
}
@keyframes serve-pulse { 50% { transform: scale(.86); } }

.side-head { padding: 0 calc(clamp(30px, 8vmin, 76px) + 8px); min-width: 0; }
.side-player { font-size: clamp(1.15rem, 4vmin, 2.6rem); font-weight: 850; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-team { font-size: clamp(.8rem, 2vmin, 1.2rem); opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-games { display: flex; justify-content: center; align-items: center; gap: clamp(6px, 1.2vmin, 12px); margin-top: clamp(6px, 1.2vmin, 14px); }
.dot { width: clamp(12px, 2.4vmin, 22px); height: clamp(12px, 2.4vmin, 22px); border-radius: 50%; border: 2px solid rgba(255, 255, 255, .7); }
.dot.on { background: #fff; border-color: #fff; }

.side-points {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  font-size: min(46vh, 27vw);
  font-weight: 850;
  line-height: .9;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em;
}
.side-points.bump { animation: bump .28s ease-out; }
@keyframes bump { 0% { transform: scale(1.12); } 100% { transform: scale(1); } }

.side-foot { display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap; min-height: clamp(32px, 5vmin, 44px); }
.serve-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  padding: clamp(6px, 1vmin, 10px) clamp(16px, 2.6vmin, 28px);
  border-radius: 99px;
  background: var(--ball);
  color: #1b1b1b;
  font-weight: 900;
  font-size: clamp(.95rem, 2.8vmin, 1.6rem);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.serve-pill small { font-size: .72em; font-weight: 700; opacity: .7; letter-spacing: .02em; }
.gp-pill {
  padding: 6px 12px;
  border-radius: 99px;
  background: #fff;
  color: #1b1b1b;
  font-weight: 850;
  font-size: clamp(.72rem, 1.8vmin, 1rem);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.score-bottom {
  display: flex;
  justify-content: center;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  font-variant-numeric: tabular-nums;
}
.g-chip { flex: none; padding: 4px 12px; border-radius: 8px; background: rgba(255, 255, 255, .08); font-size: clamp(.8rem, 1.8vmin, 1rem); }
.g-chip b { opacity: .6; font-weight: 600; margin-right: 6px; }
.hint { opacity: .45; font-size: .8rem; align-self: center; }

.score-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, .6);
}
.overlay-card {
  width: min(560px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: clamp(20px, 4vmin, 40px);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
}
.ov-kicker { font-size: .8rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ov-title { font-size: clamp(1.4rem, 4vmin, 2.2rem); font-weight: 850; margin: 6px 0; word-break: break-word; }
.ov-score { font-size: clamp(2.6rem, 10vmin, 5rem); font-weight: 850; font-variant-numeric: tabular-nums; line-height: 1.1; }
.ov-games { color: var(--muted); font-variant-numeric: tabular-nums; margin: 6px 0 0; }
.ov-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; }

/* ---------- Second screen ---------- */

.score-top .icon-btn { position: relative; }
.cast-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 99px;
  background: #22c55e;
  color: #052e16;
  font-size: .75rem;
  font-weight: 800;
  line-height: 20px;
}

.cast-card { width: min(760px, 100%); }
.cast-card h2 { margin-bottom: 6px; }
.cast-intro { margin: 0 0 18px; }
.cast-body { display: grid; grid-template-columns: minmax(0, 260px) minmax(0, 1fr); gap: 22px; align-items: start; }
.qr {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  width: 100%;
  padding: 10px;
  border-radius: 14px;
  background: #fff;
  color: #555;
  text-align: center;
}
.qr svg { width: 100%; height: 100%; display: block; }
.qr svg rect[fill="#ffffff"], .qr svg path { shape-rendering: crispEdges; }
.cast-side { min-width: 0; }
.cast-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: var(--surface-2);
  font-weight: 650;
}
.cast-status::before { content: ""; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.cast-status[data-state="ready"]::before { background: var(--ball); }
.cast-status[data-state="live"]::before { background: #22c55e; }
.cast-status[data-state="error"]::before, .cast-status[data-state="no-lib"]::before { background: var(--danger); }
.cast-status[data-state="connecting"]::before { animation: pulse 1s infinite alternate; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; font-size: .9rem; }
.cast-adv { margin-bottom: 8px; }
.cast-adv summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
.cast-warning {
  margin: 0;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--ball);
  background: rgba(251, 191, 36, .12);
  font-size: .92rem;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .08);
  font-weight: 800;
  font-size: .85rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.live-pill span { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; animation: pulse 1.2s infinite alternate; }
.live-pill[data-state="waiting"] span { background: var(--ball); }
@keyframes pulse { from { opacity: 1; } to { opacity: .3; } }

.score-overlay.passive { background: rgba(0, 0, 0, .45); pointer-events: none; }

.viewer-wait { display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.wait-card { max-width: 480px; }
.wait-card svg { width: 72px; height: 72px; margin-bottom: 16px; }
.wait-card h1 { font-size: clamp(1.5rem, 4vmin, 2.2rem); margin-bottom: 10px; }
.wait-card p { opacity: .7; margin: 0 0 24px; }
.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .15);
  border-top-color: var(--ball);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1000px) {
  .btn-label.wide { display: none; }
}

@media (max-width: 640px) {
  .cast-body { grid-template-columns: 1fr; }
  .qr { max-width: 280px; margin: 0 auto; }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; }
}

/* Portrait: stack the two players */
@media (orientation: portrait) {
  .courts { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .side-points { font-size: min(24vh, 52vw); }
}

/* Short landscape screens (phones on their side) */
@media (orientation: landscape) and (max-height: 520px) {
  .score-top { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px; }
  .score-top .icon-btn { min-height: 38px; }
  .side { padding: 8px 12px; border-radius: 14px; }
  .side-team { display: none; }
  .side-games { margin-top: 4px; }
  .side-points { font-size: min(44vh, 26vw); }
  .score-bottom { display: none; }
  .courts { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
  .btn-label { display: none; }
  .hint { display: none; }
  .inline-form { flex-direction: column; }
  .field-row { flex-direction: column; gap: 0; }
  .field-row .field.small { flex: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
