:root {
  --bg: #0b0e13;
  --bg-elevated: #151a22;
  --bg-elevated-2: #1c2330;
  --accent: #8ce23a;
  --accent-dim: #5c9a28;
  --accent-b: #ff3b3b; /* rojo: se distingue mejor desde lejos que el azul */
  --serve-ball-size: clamp(48px, 10vh, 80px);
  --text: #f5f7fa;
  --text-dim: #9aa4b2;
  --danger: #ff5c5c;
  --border: #262e3b;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

button {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: none;
  margin: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.view.is-active { display: flex; }

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

#view-home {
  position: relative;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 32px;
  text-align: center;
}

#view-pin {
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 32px;
  text-align: center;
}

.home-logo {
  width: 96px;
  height: 96px;
  border-radius: 24px;
  box-shadow: 0 0 40px rgba(140, 226, 58, 0.25);
}

.home-logo--big {
  width: clamp(190px, 30vh, 260px);
  height: clamp(190px, 30vh, 260px);
  border-radius: 23%;
  box-shadow: 0 0 60px rgba(140, 226, 58, 0.3);
}

.home-footer {
  position: absolute;
  bottom: calc(20px + var(--safe-bottom));
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}

.home-footer a {
  color: var(--text-dim);
  text-decoration: none;
}

.home-footer a:active { color: var(--accent); }
.home-footer-sep { color: var(--border); }

#pin-input {
  width: 200px;
  text-align: center;
  font-size: 40px;
  font-weight: 800;
  letter-spacing: 24px;
  padding: 14px 0 14px 24px;
}

.home-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text-dim);
}

.home-title strong { color: var(--accent); }

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 340px;
}

/* ---------- Botones ---------- */

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease;
  color: var(--text);
  background: var(--bg-elevated-2);
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0b0e13;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.btn-danger {
  background: rgba(255, 92, 92, 0.12);
  color: var(--danger);
  border: 1px solid rgba(255, 92, 92, 0.3);
}

.btn-block { width: 100%; }
.btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- Setup wizard ---------- */

#view-setup {
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  overflow-y: auto;
}

#view-setup .btn {
  padding: 19px 22px;
  font-size: 19px;
}

#view-setup .wizard-search {
  padding: 16px 16px;
  font-size: 17px;
}

.setup-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.setup-header h1 { font-size: 18px; margin: 0; flex: 1; }

.step { display: none; flex-direction: column; gap: 16px; }
.step.is-active { display: flex; }

.field-label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option-card {
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}

.option-card .option-title { font-weight: 700; font-size: 15px; }
.option-card .option-sub { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

/* Pasos del asistente: botones y letras más grandes (se leen/tocan mejor) */
.option-grid--wizard .option-card { padding: 20px 18px; }
.option-grid--wizard .option-card .option-title { font-size: 19px; }
.option-grid--wizard .option-card .option-sub { font-size: 14px; margin-top: 5px; }

.option-card.is-selected {
  border-color: var(--accent);
  background: rgba(140, 226, 58, 0.08);
}

input[type="text"], input[type="number"], input[type="tel"], input[type="password"], select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 14px;
}

.switch {
  position: relative;
  width: 46px;
  height: 27px;
  flex: none;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  transition: background 0.15s ease;
}

.switch-track::before {
  content: '';
  position: absolute;
  width: 21px;
  height: 21px;
  left: 2px;
  top: 2px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s ease, background 0.15s ease;
}

.switch input:checked + .switch-track { background: rgba(140, 226, 58, 0.25); border-color: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(19px); background: var(--accent); }

.pair-row { display: flex; gap: 10px; }
.pair-row > div { flex: 1; }

.step-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.wizard-progress-track {
  flex: 1;
  height: 6px;
  background: var(--bg-elevated-2);
  border-radius: 4px;
  overflow: hidden;
}

.wizard-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width 0.2s ease;
}

.wizard-step {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: wizard-fade-in 0.15s ease;
}

@keyframes wizard-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.wizard-question {
  font-size: 27px;
  font-weight: 800;
  line-height: 1.3;
}

.wizard-sub {
  font-size: 16px;
  line-height: 1.4;
  color: var(--text-dim);
  margin-top: -6px;
}

.option-grid--wizard {
  grid-template-columns: 1fr;
}

.wizard-search {
  width: 100%;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 40vh;
  overflow-y: auto;
}

.chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 13px 20px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.chip:active { border-color: var(--accent); }

.summary-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-card-row { font-size: 15px; }
.summary-card-row.muted { color: var(--text-dim); font-size: 13px; }

/* ---------- Tarjetas de "dato" (resumen, historial, estadísticas) ---------- */
/* Etiqueta chica arriba + valor grande abajo: más fácil de leer de un
   vistazo que una fila "etiqueta: valor" cuando el valor es largo. */

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  text-align: left;
  margin: 4px 2px 2px;
}

.stat-tile-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 16px;
  text-align: left;
  width: 100%;
}

.stat-tile {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.stat-tile:last-child { border-bottom: none; }

.stat-tile-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.stat-tile-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}

.match-summary-line {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  text-align: center;
}

/* ---------- Scoreboard ---------- */

#view-scoreboard {
  background: var(--bg);
  position: relative;
  text-transform: uppercase;
  --center-clear: 96px; /* ancho que ocupan reloj y menu en el centro de arriba */
}

.scoreboard {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.team-panel {
  padding: 0 6px;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  user-select: none;
}

.team-panel:active { filter: brightness(1.08); }

.team-panel--a {
  background:
    radial-gradient(circle at 50% 55%, rgba(140, 226, 58, 0.12), transparent 55%),
    linear-gradient(180deg, rgba(140, 226, 58, 0.05), transparent 30%);
}
.team-panel--b {
  background:
    radial-gradient(circle at 50% 55%, rgba(255, 59, 59, 0.14), transparent 55%),
    linear-gradient(180deg, rgba(255, 59, 59, 0.06), transparent 30%);
  border-left: 1px solid var(--border);
  box-shadow: -1px 0 0 rgba(255, 255, 255, 0.03);
}

/* Nombre + games/sets: van SUPERPUESTOS arriba (position:absolute), no
   ocupan espacio en el flujo, así el número de abajo puede usar casi toda
   la altura de la pantalla en vez de "lo que sobra". */
.team-top {
  position: absolute;
  top: calc(2px + var(--safe-top));
  /* deja libre el lugar de la pelota de saque en ambas puntas (simétrico,
     así el nombre queda centrado en su mitad de pantalla) */
  left: calc(var(--serve-ball-size) + 16px);
  right: calc(var(--serve-ball-size) + 16px);
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 12px;
  font-size: 22px; /* la ajusta ui-scoreboard.js para que el nombre entre entero */
  z-index: 2;
  pointer-events: none;
}

/* El nombre y los games/sets no pueden llegar al centro, donde estan el
   reloj y el boton de menu: se les deja ese espacio libre. */
.team-panel--a .team-top { right: var(--center-clear); }
.team-panel--b .team-top { left: var(--center-clear); }

.team-name {
  flex: 0 1 auto;
  min-width: 0;
  font-size: 1em;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-meta .lbl { font-size: 0.78em; opacity: 0.85; letter-spacing: 0.8px; }
.team-meta .sep { opacity: 0.5; }

.team-meta {
  flex: none;
  font-size: 0.9em;
  font-weight: 800;
  letter-spacing: 0.6px;
  line-height: 1.15;
  white-space: nowrap;
}

.team-panel--a .team-meta { color: var(--accent); }
.team-panel--b .team-meta { color: var(--accent-b); }

/* Pelota de saque: un círculo sólido tipo pelota de pádel, en la esquina
   superior de cada lado (no compite por espacio con el nombre). */
.serve-ball {
  position: absolute;
  top: calc(6px + var(--safe-top));
  width: var(--serve-ball-size);
  height: var(--serve-ball-size);
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #f9ffb0, #d7e600 55%, #9aa800 100%);
  box-shadow: 0 0 14px rgba(215, 230, 0, 0.85), inset -3px -3px 6px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.serve-ball--a { left: calc(12px + var(--safe-left)); }
.serve-ball--b { right: calc(12px + var(--safe-right)); }

.serve-ball.is-serving {
  opacity: 1;
  transform: scale(1);
  animation: serve-ball-glow 2.2s ease-in-out infinite;
}

@keyframes serve-ball-glow {
  0%, 100% { box-shadow: 0 0 14px rgba(215, 230, 0, 0.85), inset -3px -3px 6px rgba(0, 0, 0, 0.25); }
  50% { box-shadow: 0 0 22px rgba(215, 230, 0, 1), inset -3px -3px 6px rgba(0, 0, 0, 0.25); }
}

.team-point {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: clamp(34px, 9vh, 48px); /* deja lugar al nombre/games-sets superpuestos arriba */
  /* vh en vez de vw: el marcador siempre va horizontal, así que el alto de
     pantalla es el límite real (en landscape el ancho sobra). */
  font-size: clamp(200px, 92vh, 700px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* Textos (PUNTO DE ORO, VENTAJA, IGUALES) en lugar de numero: mas chicos, en
   varias lineas si hace falta, para que entren enteros en la mitad de pantalla. */
.team-point.is-long {
  font-size: min(22vh, 8.5vw);
  line-height: 1.05;
  text-align: center;
  padding-left: 4px;
  padding-right: 4px;
  overflow-wrap: anywhere;
}

.team-panel--a .team-point { color: var(--accent); text-shadow: 0 0 50px rgba(140, 226, 58, 0.35), 0 0 110px rgba(140, 226, 58, 0.15); }
.team-panel--b .team-point { color: var(--accent-b); text-shadow: 0 0 50px rgba(255, 59, 59, 0.4), 0 0 110px rgba(255, 59, 59, 0.18); }

.scoreboard-topbar {
  position: absolute;
  top: calc(2px + var(--safe-top));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  z-index: 5;
  pointer-events: none;
}

.scoreboard-topbar > * { pointer-events: auto; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(21, 26, 34, 0.85);
  backdrop-filter: blur(6px);
  color: var(--text-dim);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.match-clock {
  background: rgba(21, 26, 34, 0.85);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}

.team-subtract-btn {
  position: absolute;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 6;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--accent-b);
  border: none;
  color: #fff;
  box-shadow: 0 4px 14px rgba(255, 59, 59, 0.45);
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 2px;
}

/* Alejado del centro (donde se toca para sumar) para no restar por error */
.team-subtract-btn--a { left: calc(16px + var(--safe-left)); }
.team-subtract-btn--b { right: calc(16px + var(--safe-right)); }

.team-subtract-btn:active {
  filter: brightness(0.85);
  transform: scale(0.92);
}

.tiebreak-banner {
  position: absolute;
  top: calc(50px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #0b0e13;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 16px;
  border-radius: 20px;
  letter-spacing: 0.4px;
  z-index: 5;
}

/* ---------- Celebraciones: GANO + chispas ---------- */
.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

.win-banner {
  position: absolute;
  top: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  background: rgba(8, 10, 14, 0.94);
  z-index: 9;
  pointer-events: none;
  text-shadow: 0 0 40px currentColor;
}

.win-banner.is-active { display: flex; animation: win-pop 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.win-banner--game.win-banner--a { left: 0; right: 50%; }
.win-banner--game.win-banner--b { left: 50%; right: 0; }
.win-banner--set, .win-banner--match { left: 0; right: 0; }
.win-banner--match { pointer-events: auto; cursor: pointer; background: rgba(8, 10, 14, 0.82); }

.wb-title {
  font-weight: 900;
  line-height: 1;
  letter-spacing: 1px;
  font-size: min(30vh, 13vw);
}

.win-banner--set .wb-title { font-size: min(24vh, 9.5vw); animation: win-pulse 0.7s ease-in-out infinite alternate; }
.win-banner--match .wb-title { font-size: min(21vh, 8.5vw); animation: win-pulse 0.5s ease-in-out infinite alternate; }

.wb-sub {
  font-weight: 800;
  font-size: min(8vh, 4vw);
  letter-spacing: 1px;
  color: #fff;
  padding: 0 16px;
}

@keyframes win-pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes win-pulse {
  from { transform: scale(1); }
  to { transform: scale(1.07); }
}

/* Indicador de toques del control: muestra cuantos se contaron antes de aplicar */
.tap-hint {
  position: absolute;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  min-width: 280px;
  padding: 12px 26px 16px;
  border-radius: 22px;
  background: #ffffff;
  color: #0b0e13;
  text-align: center;
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 900;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.5);
  z-index: 9;
  pointer-events: none;
}

.tap-hint[data-side="a"] { background: var(--accent); }
.tap-hint[data-side="b"] { background: var(--accent-b); color: #fff; }

.tap-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 6px;
  background: rgba(0, 0, 0, 0.55);
  transform-origin: left center;
}

.tap-hint[data-side="b"] .tap-bar { background: rgba(255, 255, 255, 0.8); }

/* Aviso antes del primer tanto: el primer toque del control elige quién saca */
.serve-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 86vw;
  padding: 20px 34px;
  border-radius: 26px;
  background: #ffffff;
  color: #e0152b;
  text-align: center;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.55);
  z-index: 8;
  pointer-events: none;
}

.serve-hint strong { font-size: clamp(26px, 5vw, 46px); font-weight: 900; letter-spacing: 0.5px; }
.serve-hint span { font-size: clamp(13px, 2.4vw, 22px); font-weight: 800; letter-spacing: 0.4px; }

/* ---------- Overlay / modal ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 19, 0.72);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}

.overlay.is-active { display: flex; }

.sheet {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 86vh;
  overflow-y: auto;
}

.sheet h2 { margin: 0 0 4px; font-size: 18px; }
.sheet p { margin: 0; color: var(--text-dim); font-size: 14px; line-height: 1.5; }

/* ---------- History ---------- */

#view-history { padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom)); overflow-y: auto; }

.match-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}

.match-card-row { display: flex; justify-content: space-between; align-items: center; }
.match-card-teams { font-weight: 700; font-size: 15px; }
.match-card-meta { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.match-card-score { font-weight: 700; color: var(--accent); font-size: 14px; }

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 20px; line-height: 1.5; }

/* Pestañas: Partidos / Parejas / Jugadores */
.hist-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.hist-tab {
  flex: 1;
  padding: 12px 6px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dim);
  transition: background 0.15s ease, color 0.15s ease;
}

.hist-tab.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0b0e13;
}

/* Tarjeta de partido: tablero con una fila por pareja y una columna por set */
.hm-card {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 14px;
  padding: 14px 16px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, var(--bg-elevated-2), var(--bg-elevated) 60%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.hm-card:active { transform: scale(0.985); }

.hm-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

.hm-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.hm-badge--live { color: var(--accent); border-color: var(--accent-dim); }

.hm-table { display: flex; flex-direction: column; gap: 2px; }

.hm-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.hm-row + .hm-row { border-top: 1px solid var(--border); }

.hm-dot {
  flex: none;
  width: 6px;
  align-self: stretch;
  border-radius: 4px;
}

.hm-row--a .hm-dot { background: var(--accent); }
.hm-row--b .hm-dot { background: var(--accent-b); }

.hm-name {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hm-row.is-loser .hm-name,
.hm-row.is-loser .hm-dot { opacity: 0.5; }

.hm-trophy { flex: none; font-size: 16px; }

.hm-sets { display: flex; flex: none; gap: 4px; }

.hm-set {
  min-width: 30px;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
}

.hm-row--a .hm-set.is-won { color: var(--accent); font-weight: 800; }
.hm-row--b .hm-set.is-won { color: var(--accent-b); font-weight: 800; }

.hm-foot {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
}

/* Detalle del partido: tablero más grande */
.hm-table--big .hm-name { font-size: 19px; }
.hm-table--big .hm-set { font-size: 32px; min-width: 40px; }
.hm-table--big .hm-row { padding: 14px 0; }

.hm-winner {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  text-align: center;
  margin-top: 2px;
}

.hm-winner--muted { color: var(--text-dim); font-size: 16px; }

/* Ranking interno (parejas y jugadores) */
.rk-intro {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(140, 226, 58, 0.06);
  border: 1px solid rgba(140, 226, 58, 0.2);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-dim);
}

.rk-intro strong { color: var(--accent); font-size: 14px; }

.rk-card {
  margin-bottom: 12px;
  padding: 14px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, var(--bg-elevated-2), var(--bg-elevated) 60%);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.rk-card--top1 { border-color: rgba(255, 200, 60, 0.55); box-shadow: 0 8px 28px rgba(255, 200, 60, 0.12); }
.rk-card--top2 { border-color: rgba(200, 210, 225, 0.4); }
.rk-card--top3 { border-color: rgba(205, 127, 50, 0.45); }

.rk-head { display: flex; align-items: center; gap: 12px; }

.rk-pos {
  flex: none;
  width: 40px;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  color: var(--text-dim);
}

.rk-main { flex: 1; min-width: 0; }

.rk-name {
  font-size: 16px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.rk-sub { margin-top: 4px; font-size: 13px; color: var(--text-dim); }

.is-win { color: var(--accent); }
.is-loss { color: var(--accent-b); }

.rk-pts { flex: none; text-align: right; line-height: 1; }
.rk-pts b { display: block; font-size: 30px; font-weight: 800; color: var(--text); }
.rk-pts span { font-size: 11px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

.rk-bar {
  height: 5px;
  margin-top: 12px;
  border-radius: 4px;
  background: var(--bg);
  overflow: hidden;
}

.rk-bar i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
}

.rk-detail { display: none; margin-top: 14px; }
.rk-card.is-open .rk-detail { display: block; }

.rk-summary { margin: 0 0 6px; font-size: 14px; line-height: 1.5; color: var(--text); }
.rk-summary b { font-weight: 800; }

.rk-sub-title {
  margin: 14px 0 6px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}

.rk-list { list-style: none; margin: 0; padding: 0; }

.rk-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.rk-list li:last-child { border-bottom: none; }
.rk-list li b { flex: none; color: var(--text-dim); }
.rk-empty { font-size: 13px; color: var(--text-dim); }

/* ---------- Summary ---------- */

#view-summary {
  align-items: center;
  justify-content: center;
  padding: 32px;
  gap: 20px;
  text-align: center;
  overflow-y: auto;
}

.summary-winner { font-size: 24px; font-weight: 800; color: var(--accent); }
.summary-score { font-size: 32px; font-weight: 800; }
.summary-detail { color: var(--text-dim); font-size: 14px; line-height: 1.7; }

/* ---------- Configuracion ---------- */

#view-settings { padding: calc(20px + var(--safe-top)) 20px calc(24px + var(--safe-bottom)); overflow-y: auto; }
#view-settings .toggle-row, #view-settings .set-card, #view-settings > div > .btn { margin-bottom: 12px; }
#view-settings .section-title { margin-top: 18px; }

.set-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.set-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.set-title { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.set-value { flex: none; font-size: 20px; font-weight: 800; color: var(--accent); }

.range { width: 100%; margin-top: 12px; accent-color: var(--accent); height: 28px; }

.seg { display: flex; gap: 4px; padding: 4px; margin-top: 10px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; }
.seg-btn { flex: 1; padding: 12px 6px; border-radius: 9px; font-size: 15px; font-weight: 700; color: var(--text-dim); }
.seg-btn.is-active { background: linear-gradient(135deg, var(--accent), var(--accent-dim)); color: #0b0e13; }

/* ---------- Alto contraste (sol directo) ---------- */

:root.hc { --bg: #000; --bg-elevated: #0a0a0a; --bg-elevated-2: #141414; --accent: #2bff3a; --accent-b: #ff2a2a; --text: #fff; --text-dim: #d5d9df; --border: #4a4f57; }
:root.hc .team-panel--a, :root.hc .team-panel--b { background: #000; }
:root.hc .team-panel--a .team-point, :root.hc .team-panel--b .team-point { text-shadow: none; }
:root.hc .team-panel--b { border-left: 3px solid #fff; }
:root.hc .team-point { -webkit-text-stroke: 3px currentColor; }
:root.hc .team-name, :root.hc .team-meta { text-shadow: none; }
:root.hc .team-meta .lbl { opacity: 1; }
:root.hc .match-clock, :root.hc .icon-btn { background: #000; color: #fff; border-color: #fff; }

/* ---------- Ranking: filtros, rachas, estadisticas ---------- */

.period-chips { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.period-chip {
  flex: none;
  padding: 10px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-dim);
}
.period-chip.is-active { background: var(--accent); border-color: var(--accent); color: #0b0e13; }

.rk-fire { color: #ffb347; font-weight: 800; }
.rk-streak { margin: 0 0 4px; font-size: 13px; color: var(--text-dim); }
.rk-streak b { color: var(--text); }

.rk-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rk-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border-radius: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.rk-stat b { font-size: 24px; font-weight: 800; color: var(--accent); line-height: 1.1; }
.rk-stat span { font-size: 12px; font-weight: 700; color: var(--text); }
.rk-stat em { font-size: 11px; font-style: normal; color: var(--text-dim); }

.rk-edit { margin-top: 16px; }

/* ---------- Partido en vivo ---------- */

.match-clock.is-live::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent-b);
  box-shadow: 0 0 8px var(--accent-b);
  animation: live-blink 1.4s ease-in-out infinite;
}

@keyframes live-blink { 50% { opacity: 0.25; } }

.live-status { text-align: center; font-weight: 800; color: var(--accent); font-size: 15px; }
.live-status.is-offline { color: #ffb347; }
.live-error { color: var(--accent-b) !important; font-weight: 700; }
.live-qr { display: block; width: 210px; height: 210px; margin: 4px auto; border-radius: 14px; background: #fff; image-rendering: pixelated; }
.live-code { text-align: center; font-size: 34px; font-weight: 900; letter-spacing: 6px; }
.live-url { text-align: center; font-size: 12px; color: var(--text-dim); word-break: break-all; }

.home-version { color: var(--text-dim); font-weight: 700; }
