:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --bg: #080b12;
  --panel: #131b2c;
  --panel-2: #1b2640;
  --line: #2b3854;
  --text: #f4f6fb;
  --muted: #a9b6cc;
  --ok: #2fbf71;
  --warn: #f2b33d;
  --bad: #e5484d;
  --team-a: #1e6fd9;
  --team-b: #d62f4b;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { cursor: pointer; border: 0; border-radius: 12px; background: #f4f5f8; color: #0d1117; padding: 12px 16px; font-weight: 700; }
button.alt { background: var(--panel-2); color: var(--text); }
button.danger { background: #ad304a; color: #fff; }
button.ok { background: var(--ok); color: #04130b; }
button:disabled { opacity: .4; cursor: default; }
a { color: #a8c7ff; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* Indicador de conexión */
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.conn::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--warn); }
.conn[data-status="online"]::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.conn[data-status="offline"]::before, .conn[data-status="error"]::before { background: var(--bad); }

/* Avisos */
#toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 50; pointer-events: none; width: max-content; max-width: 90vw; }
.toast { background: #222d45; border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 15px; animation: toast-in .15s ease-out; }
.toast.bad { border-color: var(--bad); }
.toast.good { border-color: var(--ok); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* Banner de desconexión */
.offline-banner { display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 40; background: var(--bad); color: #fff; text-align: center; padding: 6px; font-weight: 700; font-size: 15px; }
body.is-offline .offline-banner { display: block; }

/* ---------- Inicio ---------- */
.landing { max-width: 720px; margin: 0 auto; padding: 40px 16px; text-align: center; }
.landing h1 { font-size: clamp(28px, 6vw, 44px); margin: 0 0 6px; letter-spacing: 1px; }
.landing input { padding: 14px; background: #192238; color: #fff; border: 1px solid #4f5c73; border-radius: 10px; width: 220px; text-align: center; font-size: 20px; }
.landing .actions a { display: inline-block; background: #fff; color: #111; padding: 13px 18px; border-radius: 12px; text-decoration: none; margin: 8px; font-weight: bold; }
.landing .actions a.alt { background: var(--panel-2); color: var(--text); }
.share { text-align: left; background: var(--panel); border-radius: 16px; padding: 16px; margin-top: 24px; }
.share h2 { font-size: 17px; margin: 0 0 10px; }
.share-row { display: grid; grid-template-columns: 90px 1fr auto; gap: 8px; align-items: center; margin: 8px 0; }
.share-row code { overflow-wrap: anywhere; background: #0c1220; padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.share-row button { padding: 8px 12px; font-size: 14px; }
@media (max-width: 520px) { .share-row { grid-template-columns: 1fr auto; } .share-row span { grid-column: 1 / -1; } }

/* ---------- Marcador ---------- */
body.scoreboard { min-height: 100dvh; overflow: hidden; }
.sb { height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; padding: clamp(8px, 2vh, 24px) clamp(10px, 2vw, 32px); gap: clamp(8px, 2vh, 20px); }
.sb-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: clamp(14px, 2vh, 22px); }
.sb-top .brand { font-weight: 800; letter-spacing: 1px; }
.sb-top .right { display: flex; align-items: center; gap: 14px; }
.sb-top button { padding: 6px 12px; font-size: 14px; }
.sb-teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: clamp(8px, 2vw, 28px); min-height: 0; }
.sb-team { border-radius: clamp(14px, 3vh, 32px); background: var(--c); display: grid; grid-template-rows: auto 1fr auto; align-items: center; text-align: center; padding: clamp(8px, 2vh, 24px); min-height: 0; position: relative; overflow: hidden; transition: box-shadow .2s; }
.sb-team .name { font-size: clamp(22px, min(6vh, 4.5vw), 72px); font-weight: 800; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-team .score { font-weight: 900; font-variant-numeric: tabular-nums; line-height: .9; font-size: clamp(90px, min(42vh, 24vw), 520px); }
.sb-team .sets { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: clamp(18px, 3.4vh, 40px); font-weight: 700; }
.sb-team .sets b { background: rgba(0,0,0,.35); border-radius: 10px; padding: 0 .4em; font-size: 1.3em; }
.sb-team.bump .score { animation: bump .35s ease-out; }
.sb-team.winner { box-shadow: 0 0 0 6px #fff inset; }
@keyframes bump { 30% { transform: scale(1.08); } }
.sb-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-width: clamp(70px, 10vw, 160px); }
.sb-mid .set-label { font-size: clamp(14px, 2.2vh, 24px); color: var(--muted); text-transform: uppercase; letter-spacing: 2px; }
.sb-mid .set-num { font-size: clamp(48px, 12vh, 140px); font-weight: 900; line-height: 1; }
.sb-mid .target { font-size: clamp(13px, 2vh, 22px); color: var(--muted); text-align: center; }
.sb-bottom { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; min-height: 1.5em; font-size: clamp(14px, 2.4vh, 26px); }
.sb-bottom .chip { background: var(--panel); border-radius: 10px; padding: 4px 12px; font-variant-numeric: tabular-nums; }
.sb-banner { position: absolute; inset: auto 0 0 0; }
.sb-status { background: var(--panel-2); border-radius: 12px; padding: 6px 18px; font-weight: 800; }
.sb-status.won { background: #fff; color: #0d1117; }
@media (orientation: portrait) {
  .sb-teams { grid-template-columns: 1fr; grid-template-rows: 1fr auto 1fr; }
  .sb-mid { flex-direction: row; gap: 16px; }
  .sb-mid .set-num { font-size: clamp(40px, 7vh, 90px); }
  .sb-team .score { font-size: clamp(90px, min(22vh, 40vw), 400px); }
}
body.scoreboard.fs .sb-top button { opacity: 0; }
body.scoreboard.fs:hover .sb-top button { opacity: 1; }

/* ---------- Control ---------- */
body.controller {
  height: 100dvh; overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.ctl { height: 100dvh; display: grid; grid-template-rows: auto 1fr; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.ctl-bar { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); font-size: 14px; }
.ctl-bar .info { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 700; }
.ctl-bar button { padding: 8px 12px; font-size: 14px; }
.ctl-pads { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; min-height: 0; }
.pad { position: relative; border-radius: 22px; background: var(--c); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px; overflow: hidden; touch-action: manipulation; transition: filter .1s, transform .08s; }
.pad:active { transform: scale(.985); }
.pad .name { font-size: clamp(18px, 6vh, 36px); font-weight: 800; text-transform: uppercase; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad .score { font-size: clamp(56px, 32vh, 180px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
.pad .sets { font-size: clamp(14px, 4vh, 22px); opacity: .9; }
.pad .hint { font-size: clamp(11px, 3vh, 15px); opacity: .75; margin-top: 4px; }
.pad .fx { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: clamp(60px, 30vh, 160px); font-weight: 900; pointer-events: none; opacity: 0; }
.pad.pending { filter: brightness(1.25); }
.pad.pending .fx { opacity: .35; }
.pad.flash-plus .fx { animation: fx 0.6s ease-out; background: rgba(47,191,113,.45); }
.pad.flash-minus .fx { animation: fx 0.6s ease-out; background: rgba(0,0,0,.55); }
.pad.flash-error .fx { animation: fx 0.6s ease-out; background: rgba(229,72,77,.6); }
@keyframes fx { 0% { opacity: 1; } 100% { opacity: 0; } }
body.locked .pad { filter: grayscale(.7) brightness(.6); }
.overlay { position: fixed; inset: 0; background: rgba(5,8,14,.86); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.overlay .box { background: var(--panel); border-radius: 18px; padding: 18px; max-width: 520px; width: 100%; text-align: center; max-height: 100%; overflow: auto; }
.overlay h2 { margin: 0 0 6px; font-size: clamp(18px, 5vh, 28px); }
.overlay .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; text-align: left; }
.menu-grid label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.menu-grid select { padding: 10px; background: #0c1220; color: var(--text); border: 1px solid var(--line); border-radius: 10px; }
.rotate-hint { display: none; }
@media (orientation: portrait) {
  .rotate-hint { display: block; text-align: center; font-size: 13px; color: var(--warn); padding: 4px; background: var(--panel); }
  .ctl { grid-template-rows: auto auto 1fr; }
}

/* ---------- Admin ---------- */
.admin { max-width: 900px; margin: 0 auto; padding: 20px 16px 60px; }
.admin header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.admin h1 { font-size: 24px; margin: 0; }
.card { background: var(--panel); border-radius: 16px; padding: 16px; margin-top: 16px; }
.card h2 { font-size: 17px; margin: 0 0 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 600px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.field input, .field select { padding: 10px; background: #0c1220; color: var(--text); border: 1px solid var(--line); border-radius: 10px; width: 100%; }
.field input[type="color"] { height: 44px; padding: 4px; }
.field select.color-select { color: #fff; font-weight: 700; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
details.setup > summary { cursor: pointer; font-weight: 700; font-size: 17px; list-style: none; }
details.setup > summary::-webkit-details-marker { display: none; }
details.setup > summary::before { content: '▸ '; }
details.setup[open] > summary::before { content: '▾ '; }
details.setup[open] > summary { margin-bottom: 12px; }
.ready { background: #10301f; border: 1px solid var(--ok); border-radius: 16px; padding: 16px; margin-top: 24px; text-align: center; }
.ready h2 { margin: 0 0 6px; font-size: 19px; }
.ready .actions a { font-size: 18px; }
.team-row { display: grid; grid-template-columns: 1fr 130px; gap: 8px; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.log { list-style: none; padding: 0; margin: 0; max-height: 260px; overflow: auto; font-size: 14px; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; }
.log .by { color: var(--muted); margin-left: auto; font-size: 12px; }
.summary { font-size: 20px; font-weight: 800; }
.pin-box { max-width: 360px; margin: 60px auto; text-align: center; }
.pin-box input { font-size: 28px; text-align: center; letter-spacing: 8px; padding: 12px; width: 100%; background: #0c1220; color: var(--text); border: 1px solid var(--line); border-radius: 12px; margin: 12px 0; }
