/*
 * Tokens del marcador.
 * Paleta tomada del material oficial del torneo: azul marino FIP, azul cielo del póster
 * y el amarillo de la ficha técnica (que además es el color de la pelota).
 *
 * Forma: controles 12px, paneles 18px, pastillas de estado redondas. Nada más.
 */
:root {
  --navy-950: #0d1130;
  --navy-900: #151a42;
  --navy-850: #1b2150;
  --navy-800: #222a60;
  --navy-700: #2e3775;
  --navy-500: #57609e;
  --navy-300: #a9b1dc;
  --sky: #6cc3f2;
  --sky-600: #2f8fc6;
  --sky-100: #dff1fc;
  --yellow: #f4e93b;
  --yellow-600: #c9bc12;
  --yellow-100: #fbf7c8;

  --paper: #eef2f8;
  --paper-2: #e3e8f1;
  --card: #ffffff;
  --ink: #151a42;
  --ink-2: #464d72;
  --ink-3: #636a8c;
  --rule: rgba(21, 26, 66, 0.12);
  --rule-strong: rgba(21, 26, 66, 0.22);
  --danger: #b4233f;
  --danger-100: #fbe3e8;
  --ok: #17784f;
  --ok-100: #dcf3e8;

  --team-a: var(--sky);
  --team-b: var(--yellow);

  --r-control: 12px;
  --r-panel: 18px;

  --font-ui: 'Sofia Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-score: 'Sofia Sans Condensed', 'Sofia Sans', system-ui, sans-serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  /* Semántica (tema claro). El oscuro redefine estas mismas variables más abajo. */
  --strong: #151a42;            /* relleno de énfasis: botón principal, set en curso, avisos */
  --on-strong: #ffffff;
  --on-strong-2: #a9b1dc;
  --strong-hover: #222a60;
  --strong-accent: #6cc3f2;     /* íconos sobre el relleno de énfasis */
  --link: #1c6b9e;
  --focus: #2f8fc6;
  --hover-border: #57609e;
  --seg-on: #ffffff;
  --team-a-soft: #dff1fc;
  --team-b-soft: #fbf7c8;
  --team-a-ink: #1c6b9e;
  --team-b-ink: #6f6500;
  --warn-soft: #fbf7c8;
  --warn-ink: #5f5700;
  --on-danger: #ffffff;
  --decisive-bg: #151a42;       /* Star Point / punto de oro en la franja del árbitro */
  --decisive-ink: #f4e93b;
  --decisive-link: #6cc3f2;
  --inverse-tag: rgba(255, 255, 255, 0.14);
  --shadow-color: rgba(21, 26, 66, 0.12);
  --backdrop: rgba(13, 17, 48, 0.45);
  --nav-bg: #151a42;
  --nav-active: #2e3775;
  color-scheme: light;
}

/* Tema oscuro: elegido a mano (data-theme="dark") o siguiendo al sistema (data-theme="auto"). */
html[data-theme='dark'] {
  --paper: #0b0f2a;
  --paper-2: #1a2050;
  --card: #141a44;
  --ink: #eef1fa;
  --ink-2: #b8bfe0;
  --ink-3: #8e96c4;
  --rule: rgba(238, 241, 250, 0.12);
  --rule-strong: rgba(238, 241, 250, 0.24);
  --danger: #ff8fa1;
  --danger-100: rgba(255, 143, 161, 0.14);
  --ok: #6fdcae;
  --ok-100: rgba(111, 220, 174, 0.14);
  --team-a: #5db6ea;
  --team-b: #e4d935;
  --strong: #eef1fa;
  --on-strong: #151a42;
  --on-strong-2: #464d72;
  --strong-hover: #ffffff;
  --strong-accent: #2f8fc6;
  --link: #8ad0f5;
  --focus: #8ad0f5;
  --hover-border: #8e96c4;
  --seg-on: #2c3474;
  --team-a-soft: rgba(108, 195, 242, 0.16);
  --team-b-soft: rgba(244, 233, 59, 0.14);
  --team-a-ink: #8ad0f5;
  --team-b-ink: #f4e93b;
  --warn-soft: rgba(244, 233, 59, 0.14);
  --warn-ink: #f4e93b;
  --on-danger: #151a42;
  --decisive-bg: #f4e93b;
  --decisive-ink: #151a42;
  --decisive-link: #2e3775;
  --inverse-tag: rgba(21, 26, 66, 0.12);
  --shadow-color: rgba(0, 0, 0, 0.45);
  --backdrop: rgba(3, 5, 20, 0.6);
  --nav-bg: #080b22;
  --nav-active: #232a62;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-theme='auto'] {
  --paper: #0b0f2a;
  --paper-2: #1a2050;
  --card: #141a44;
  --ink: #eef1fa;
  --ink-2: #b8bfe0;
  --ink-3: #8e96c4;
  --rule: rgba(238, 241, 250, 0.12);
  --rule-strong: rgba(238, 241, 250, 0.24);
  --danger: #ff8fa1;
  --danger-100: rgba(255, 143, 161, 0.14);
  --ok: #6fdcae;
  --ok-100: rgba(111, 220, 174, 0.14);
  --team-a: #5db6ea;
  --team-b: #e4d935;
  --strong: #eef1fa;
  --on-strong: #151a42;
  --on-strong-2: #464d72;
  --strong-hover: #ffffff;
  --strong-accent: #2f8fc6;
  --link: #8ad0f5;
  --focus: #8ad0f5;
  --hover-border: #8e96c4;
  --seg-on: #2c3474;
  --team-a-soft: rgba(108, 195, 242, 0.16);
  --team-b-soft: rgba(244, 233, 59, 0.14);
  --team-a-ink: #8ad0f5;
  --team-b-ink: #f4e93b;
  --warn-soft: rgba(244, 233, 59, 0.14);
  --warn-ink: #f4e93b;
  --on-danger: #151a42;
  --decisive-bg: #f4e93b;
  --decisive-ink: #151a42;
  --decisive-link: #2e3775;
  --inverse-tag: rgba(21, 26, 66, 0.12);
  --shadow-color: rgba(0, 0, 0, 0.45);
  --backdrop: rgba(3, 5, 20, 0.6);
  --nav-bg: #080b22;
  --nav-active: #232a62;
  color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font-ui); font-size: 16px; line-height: 1.45; color: var(--ink); background: var(--paper); }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: var(--yellow); color: var(--navy-900); }
.icon { width: 1.25em; height: 1.25em; fill: currentColor; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum' 1; }
h1, h2 { text-wrap: balance; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 16px; border-radius: var(--r-control); background: var(--yellow); color: var(--navy-900); font-weight: 700; text-decoration: none; }
.skip:focus { top: 12px; }

/* ---------- números que ruedan al cambiar ---------- */
.roll { position: relative; display: inline-block; overflow: hidden; vertical-align: top; }
.roll > span { display: block; text-align: center; transition: transform 260ms var(--ease-out), opacity 200ms ease; }
.roll > .roll-out { position: absolute; left: 0; right: 0; top: 0; }
.roll > .roll-out.up { transform: translateY(-70%); opacity: 0; }
.roll > .roll-out.down { transform: translateY(70%); opacity: 0; }
.roll > .from-below { transform: translateY(70%); opacity: 0; transition: none; }
.roll > .from-above { transform: translateY(-70%); opacity: 0; transition: none; }
@media (prefers-reduced-motion: reduce) {
  .roll > span { transition: opacity 120ms ease; transform: none !important; }
}

/* ---------- fotos ---------- */
.ph { position: relative; display: inline-flex; align-items: flex-end; justify-content: center; overflow: hidden; background: var(--paper-2); flex: none; }
.ph img { width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.ph-ini { align-self: center; font-family: var(--font-score); font-weight: 700; color: var(--ink-3); letter-spacing: 0.02em; }
.flag { display: inline-block; width: 1.4em; height: auto; border-radius: 2px; box-shadow: 0 0 0 1px var(--rule-strong); }

/* ---------- controles (control y mesa) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5em;
  min-height: 48px; padding: 0 1.15em; border-radius: var(--r-control);
  border: 1px solid var(--rule-strong); background: var(--card); color: var(--ink);
  font-weight: 650; font-size: 1rem; line-height: 1.1; text-decoration: none; white-space: nowrap;
  transition: transform 140ms var(--ease-out), background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .seg button:focus-visible, .field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .link:focus-visible, .pick:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}
.btn-primary { background: var(--strong); border-color: var(--strong); color: var(--on-strong); }
.btn-danger { background: var(--card); border-color: rgba(180, 35, 63, 0.4); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-lg { min-height: 60px; font-size: 1.125rem; padding: 0 1.4em; }
.btn-block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-busy='true'] { opacity: 0.55; pointer-events: none; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { border-color: var(--hover-border); }
  .btn-primary:hover { background: var(--strong-hover); border-color: var(--strong-hover); }
}
.link { color: var(--link); font-weight: 650; text-decoration: underline; text-underline-offset: 3px; background: none; border: 0; padding: 0; }

.field { display: grid; gap: 6px; }
.field > label, .field > .label { font-weight: 650; font-size: 0.9375rem; color: var(--ink); }
.field .help { font-size: 0.875rem; color: var(--ink-2); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: var(--r-control);
  border: 1px solid var(--rule-strong); background: var(--card); color: var(--ink); font-size: 1rem;
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.field input::placeholder { color: var(--ink-3); }
.field .error { color: var(--danger); font-size: 0.875rem; font-weight: 600; }

/* selector segmentado */
.seg { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px; border-radius: calc(var(--r-control) + 4px); background: var(--paper-2); }
.seg button {
  flex: 1 1 auto; min-height: 44px; padding: 0 14px; border: 0; border-radius: var(--r-control);
  background: transparent; color: var(--ink-2); font-weight: 650; white-space: nowrap;
  transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}
.seg button[aria-pressed='true'] { background: var(--seg-on); color: var(--ink); box-shadow: 0 1px 2px var(--shadow-color), 0 2px 8px var(--shadow-color); }

/* ---------- avisos ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 90; width: min(92vw, 460px); pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-radius: var(--r-control);
  background: var(--strong); color: var(--on-strong); font-weight: 600; box-shadow: 0 8px 28px var(--shadow-color);
  animation: toast-in 220ms var(--ease-out); transition: opacity 300ms ease, transform 300ms ease;
}
.toast .icon { color: var(--strong-accent); }
.toast-error { background: var(--card); color: var(--danger); border: 1px solid var(--danger); }
.toast-error .icon { color: var(--danger); }
.toast-out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- capa a pantalla completa (selector de parejas, menús) ---------- */
.sheet-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: var(--backdrop); z-index: 50; opacity: 0; transition: opacity 200ms ease; }
.sheet-backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--paper); border-radius: var(--r-panel) var(--r-panel) 0 0; box-shadow: 0 -10px 40px var(--shadow-color);
  transform: translateY(100%); transition: transform 300ms var(--ease-out); padding-bottom: env(safe-area-inset-bottom);
}
.sheet.is-open { transform: none; }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 8px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; flex: 1; }
.sheet-body { padding: 8px 16px 20px; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (min-width: 760px) {
  .sheet { left: auto; top: 0; width: 520px; max-height: none; border-radius: var(--r-panel) 0 0 var(--r-panel); transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .sheet, .sheet-backdrop { transition: opacity 150ms ease; }
}

/* ---------- formulario "Preparar partido" y selector de parejas ---------- */
.setup { display: grid; gap: 18px; }
.error { margin: 0; color: var(--danger); font-size: 0.9375rem; font-weight: 650; }
.error:empty { display: none; }
.help { margin: 0; font-size: 0.875rem; color: var(--ink-2); }
.pick {
  display: flex; align-items: center; width: 100%; min-height: 64px; padding: 10px 12px; border-radius: var(--r-control);
  border: 1px solid var(--rule-strong); background: var(--card); color: var(--ink); text-align: left;
  transition: border-color 160ms ease, transform 120ms var(--ease-out); -webkit-tap-highlight-color: transparent;
}
.pick:active { transform: scale(0.99); }
.pick.is-selected { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
@media (hover: hover) and (pointer: fine) { .pick:hover { border-color: var(--hover-border); } }
.pick-empty { display: inline-flex; align-items: center; gap: 8px; color: var(--link); font-weight: 700; }
.pair-sum { display: flex; align-items: center; gap: 12px; min-width: 0; width: 100%; }
.pair-ph { display: flex; flex: none; }
.pair-ph .ph { width: 46px; height: 46px; border-radius: 10px; background: var(--paper-2); }
.pair-ph .ph + .ph { margin-left: -10px; box-shadow: 0 0 0 2px var(--card); }
.pair-ph .ph-ini { font-size: 16px; }
.pair-txt { display: flex; flex-direction: column; min-width: 0; }
.pair-txt strong { font-family: var(--font-score); font-size: 1.1875rem; font-weight: 800; line-height: 1.15; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pair-txt small { display: flex; align-items: center; gap: 6px; font-size: 0.875rem; color: var(--ink-2); white-space: nowrap; }
.pair-txt small em { font-style: normal; font-weight: 700; color: var(--danger); }
.pair-txt .flag { width: 20px; }
.picker { display: grid; gap: 12px; }
.pick-pairs { display: grid; gap: 8px; }
.picker .empty { margin: 8px 0; color: var(--ink-2); }
.fmt { padding: 0 14px; border-radius: var(--r-control); background: var(--card); border: 1px solid var(--rule); }
.fmt summary { display: flex; flex-direction: column; gap: 2px; padding: 12px 0; font-weight: 700; cursor: pointer; list-style: none; }
.fmt summary::-webkit-details-marker { display: none; }
.fmt summary small { font-weight: 500; color: var(--ink-2); }
.fmt[open] { padding-bottom: 16px; }
.fmt .field + .field { margin-top: 14px; }

/* ---------- foto del jugador: tomar, quitar fondo, vista previa como en la TV ---------- */
.ph-flow { display: grid; gap: 14px; justify-items: stretch; }
.ph-tv { justify-self: center; width: 216px; height: 290px; border-radius: 18px; overflow: hidden; background: var(--navy-800); display: flex; align-items: flex-end; justify-content: center; box-shadow: 0 6px 18px var(--shadow-color); }
.ph-tv img { width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.ph-tv .ph { width: 100%; height: 100%; background: var(--navy-800); border-radius: 0; }
.ph-tv .ph-ini { color: var(--navy-300); font-size: 56px; }
.ph-tv.is-working img { animation: ph-breathe 1.1s ease-in-out infinite alternate; }
@keyframes ph-breathe { from { opacity: 0.85; } to { opacity: 0.4; } }
.ph-who { display: flex; align-items: center; gap: 14px; }
.ph-who .ph-tv { width: 96px; height: 129px; border-radius: 12px; justify-self: auto; flex: none; }
.ph-who .ph-tv .ph-ini { font-size: 28px; }
.ph-who strong { display: block; font-size: 1.125rem; }
.ph-who small { display: block; color: var(--ink-2); }
.ph-tips { margin: 0; padding-left: 1.2em; color: var(--ink-2); display: grid; gap: 4px; }
.ph-status { margin: 0; text-align: center; font-weight: 650; color: var(--ink-2); }
.ph-status.is-warn { color: var(--danger); }
@media (prefers-reduced-motion: reduce) { .ph-tv.is-working img { animation: none; opacity: 0.6; } }
.ph-flow, .setup, .picker, .pick-pairs { grid-template-columns: minmax(0, 1fr); }
/* La vista previa "así se verá en la TV" usa el tema de las TVs. */
html[data-tv-theme='light'] .ph-tv, html[data-tv-theme='light'] .ph-tv .ph { background: #d3ddef; }
html[data-tv-theme='light'] .ph-tv .ph-ini { color: #57609e; }
