:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1f2630;
  --line: #2b3440;
  --text: #e9eef4;
  --muted: #8b98a8;
  --accent: #ffcc00;      /* giallo pallone */
  --live: #ff3b30;
  --ok: #34c759;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- elementi comuni ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; text-decoration: none; color: var(--text);
  font-weight: 600; user-select: none; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #111; border-color: transparent; }
.btn.danger { background: var(--live); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; pointer-events: none; }
input[type=text], input[type=password], select {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); outline: none; }
input:focus, select:focus { border-color: var(--accent); }
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 6px; }
.err { color: #ff7b72; min-height: 1.4em; font-size: .9rem; margin-top: 8px; }
.muted { color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px;
  font-size: .78rem; font-weight: 700; background: var(--panel-2); }
.pill.live { background: var(--live); color: #fff; }
.pill.rec { background: rgba(0,0,0,.55); color: #ff6b5e; }
.pill.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- pagina principale ---------- */
.wrap { max-width: 720px; margin: 0 auto; padding: 16px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.25rem; letter-spacing: .3px; }
.brand img { width: 34px; height: 34px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 4px; font-size: 1.1rem; }
.tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tabs button { flex: 1; min-height: 40px; border-radius: 10px; border: 0; background: var(--panel-2); color: var(--muted); font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--accent); color: #111; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row > * { flex: 1 1 160px; }
.row > .btn { flex: 0 0 auto; }

.ch-list { display: grid; gap: 10px; }
.ch { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.ch-main { flex: 1 1 220px; min-width: 0; }
.ch-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-meta { font-size: .82rem; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.ch-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: end; }
.ch-actions .btn { min-height: 40px; padding: 0 14px; }
.empty { text-align: center; padding: 24px; color: var(--muted); }

/* ---------- palco video (trasmissione e visione) ---------- */
body.stage-page { overflow: hidden; background: #000; }
.stage { position: fixed; inset: 0; background: #000; container-type: size; }
/* .frame ha le proporzioni del video: il tabellone si aggancia all'angolo dell'immagine,
   non alle bande nere, così chi trasmette e chi guarda lo vedono nello stesso punto */
.frame { position: absolute; inset: 0; margin: auto; --ar: 1.7778;
  width: min(100cqw, calc(100cqh * var(--ar))); height: auto; aspect-ratio: var(--ar);
  container-type: size; }
.frame video { width: 100%; height: 100%; object-fit: cover; background: #000; display: block; }
.frame video.mirror { transform: scaleX(-1); }
.fade { transition: opacity .35s; }
.fade.hidden-ui { opacity: 0; pointer-events: none; }

/* tabellone */
.scorebug { position: absolute; z-index: 5; pointer-events: none;
  --u: min(1cqw, 1.8cqh);
  font-size: calc(var(--u) * 1.9); font-weight: 800; color: #fff;
  background: rgba(10, 14, 20, .82); border-radius: .45em; overflow: hidden;
  box-shadow: 0 .2em .8em rgba(0,0,0,.35); font-variant-numeric: tabular-nums;
  min-width: 13em; }
.scorebug.size-s { font-size: calc(var(--u) * 1.45); }
.scorebug.size-l { font-size: calc(var(--u) * 2.5); }
.scorebug.size-xl { font-size: calc(var(--u) * 3.3); }
.scorebug.corner-tl { top: 2.5cqh; left: 2cqw; }
.scorebug.corner-tr { top: 2.5cqh; right: 2cqw; }
.scorebug.corner-bl { bottom: 2.5cqh; left: 2cqw; }
.scorebug.corner-br { bottom: 2.5cqh; right: 2cqw; }
.sb-row { display: flex; align-items: stretch; height: 1.9em; border-bottom: 1px solid rgba(255,255,255,.08); }
.sb-color { width: .35em; flex: 0 0 auto; }
.sb-name { flex: 1; display: flex; align-items: center; gap: .4em; padding: 0 .55em; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.sb-to { display: inline-flex; gap: .15em; }
.sb-to i { width: .28em; height: .28em; border-radius: 50%; background: #9aa6b4; }
.sb-serve { width: 1.4em; display: flex; align-items: center; justify-content: center; }
.sb-serve::before { content: ""; width: .5em; height: .5em; border-radius: 50%; background: var(--accent); box-shadow: 0 0 .4em var(--accent); }
.sb-serve.off::before { display: none; }
.sb-sets { width: 1.6em; display: flex; align-items: center; justify-content: center; background: rgba(255,255,255,.1); color: #cfd8e3; }
.sb-pts { min-width: 2.1em; display: flex; align-items: center; justify-content: center; padding: 0 .3em; background: #fff; color: #0d1117; font-size: 1.12em; }
.sb-won .sb-pts { background: var(--accent); }
.sb-foot { display: flex; justify-content: space-between; gap: .8em; padding: .2em .6em; font-size: .62em; color: #c3ccd7; letter-spacing: .08em; }
.sb-hist { color: #8b98a8; letter-spacing: 0; }

/* barre sopra il video */
.hud-top { position: absolute; z-index: 10; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  background: linear-gradient(rgba(0,0,0,.65), transparent); transition: opacity .3s; }
.hud-top .spacer { flex: 1; }
.hud-top .btn { min-height: 38px; padding: 0 12px; background: rgba(30,36,44,.75); border-color: rgba(255,255,255,.12); }
.icon-btn { width: 42px; min-height: 42px; padding: 0 !important; font-size: 1.2rem; }
.stat { font-size: .78rem; color: #dbe3ec; background: rgba(0,0,0,.45); padding: 4px 8px; border-radius: 8px; white-space: nowrap; }
.stat.warn { color: #ffd60a; }
.stat.bad { color: #ff7b72; }

/* pulsanti punteggio (lati del video) */
/* pulsanti punteggio: in basso, ai due lati */
.pad { position: absolute; z-index: 8; bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: flex-end; }
.pad.left { left: max(12px, env(safe-area-inset-left)); }
.pad.right { right: max(12px, env(safe-area-inset-right)); flex-direction: row-reverse; }
.pad .plus { width: 80px; height: 80px; border-radius: 50%; border: 3px solid rgba(255,255,255,.85);
  font-size: 1.8rem; font-weight: 900; color: #fff; cursor: pointer; box-shadow: 0 4px 18px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; opacity: .92; }
.pad .plus small { font-size: .6rem; font-weight: 700; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 4px; letter-spacing: .04em; }
.pad .plus:active { transform: scale(.92); }
.pad .mini { display: flex; gap: 6px; padding-bottom: 4px; }
.pad.right .mini { flex-direction: row-reverse; }
.pad .mini button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(20,24,30,.8); color: #fff; font-weight: 800; cursor: pointer; font-size: .9rem; }
.pad .mini button:active { transform: scale(.92); }

.hud-bottom { position: absolute; z-index: 10; left: 50%; transform: translateX(-50%);
  bottom: max(12px, env(safe-area-inset-bottom)); display: flex; gap: 10px; align-items: center; }
.hud-bottom .btn { background: rgba(30,36,44,.8); border-color: rgba(255,255,255,.14); white-space: nowrap; padding: 0 14px; }
.hud-bottom .btn.primary { background: var(--accent); color: #111; border-color: transparent; }
.golive { min-width: 150px; font-size: 1.05rem; }
/* flag registrazione, scelto prima di andare in diretta */
.hud-bottom .recbtn.on { color: #ff8a80; border-color: rgba(255,107,94,.7); }
.hud-bottom .recbtn.off { color: #8b98a8; }
.hud-bottom .recbtn.recording { background: #fff; color: var(--live); border-color: transparent; font-weight: 800; animation: recblink 1.6s infinite; }
@keyframes recblink { 50% { opacity: .7; } }
@media (prefers-reduced-motion: reduce) { .hud-bottom .recbtn.recording { animation: none; } }
.golive.on { background: var(--live) !important; color: #fff; border-color: transparent !important; }

/* pannello impostazioni */
.sheet { position: absolute; z-index: 30; top: 0; right: 0; bottom: 0; width: min(420px, 100%);
  background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 18px 24px; box-shadow: -10px 0 30px rgba(0,0,0,.5); }
.sheet h3 { margin: 18px 0 4px; font-size: .95rem; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1 1 auto; min-height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-weight: 600; }
.seg button.on { background: var(--accent); color: #111; border-color: transparent; }
.team-edit { display: grid; grid-template-columns: 1fr 52px; gap: 8px; }
.team-edit input[type=color] { width: 52px; height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 4px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

/* centro: messaggi */
.center-msg { position: absolute; z-index: 6; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 24px; color: #cfd8e3; }
.center-msg .big { font-size: 1.3rem; font-weight: 700; color: #fff; }
.code-box { display: flex; gap: 8px; width: min(360px, 100%); }

.toast { position: absolute; z-index: 40; left: 50%; top: 70px; transform: translateX(-50%); background: rgba(20,24,30,.92);
  border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; font-weight: 600; transition: opacity .3s; }

.rotate-hint { position: absolute; z-index: 9; left: 50%; top: 60px; transform: translateX(-50%);
  background: rgba(0,0,0,.6); padding: 6px 12px; border-radius: 10px; font-size: .85rem; }
@media (orientation: landscape) { .rotate-hint { display: none; } }

@media (max-height: 420px) {
  .pad .plus { width: 70px; height: 70px; font-size: 1.6rem; }
  .pad .mini button { width: 40px; height: 40px; }
}

/* poco spazio in larghezza: i comandi centrali mostrano solo l'icona */
@media (max-width: 920px) { .hud-bottom .lbl { display: none; } .golive { min-width: 0; } }
.gl-short { display: none; }
@media (max-width: 760px) { .gl-full { display: none; } .gl-short { display: inline; } }
@media (max-width: 680px) {
  .hud-bottom { gap: 6px; }
  .hud-bottom .btn { padding: 0 10px; font-size: .92rem; }
  .pad .mini button { width: 38px; height: 38px; }
}
/* telefono in verticale: i comandi centrali salgono sopra i pulsanti del punteggio */
@media (orientation: portrait) { .hud-bottom { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 96px); } }
