:root {
  --bg: #0b0e13;
  --bg-elevated: #151a22;
  --bg-elevated-2: #1c2330;
  --accent: #8ce23a;
  --accent-dim: #5c9a28;
  --accent-blue: #3fa9f5;
  --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: 148px;
  height: 148px;
  border-radius: 34px;
}

.home-footer {
  position: absolute;
  bottom: calc(20px + var(--safe-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  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;
}

.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(63, 169, 245, 0.12), transparent 55%),
    linear-gradient(180deg, rgba(63, 169, 245, 0.05), 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(4px + var(--safe-top));
  left: 8px;
  right: 8px;
  text-align: center;
  z-index: 2;
  pointer-events: none;
}

.team-name {
  font-size: clamp(12px, 1.8vw, 17px);
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-meta {
  font-size: clamp(13px, 2.4vw, 20px);
  font-weight: 800;
  letter-spacing: 0.6px;
  margin-top: 2px;
}

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

/* 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(12px + var(--safe-top));
  width: clamp(22px, 4vh, 34px);
  height: clamp(22px, 4vh, 34px);
  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(30px, 8vh, 46px); /* 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);
}

.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-blue); text-shadow: 0 0 50px rgba(63, 169, 245, 0.35), 0 0 110px rgba(63, 169, 245, 0.15); }

.scoreboard-topbar {
  position: absolute;
  top: calc(10px + 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: 46px;
  height: 46px;
  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: rgba(255, 92, 92, 0.12);
  border: 2px solid rgba(255, 92, 92, 0.45);
  color: var(--danger);
  font-size: 30px;
  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 {
  background: rgba(255, 92, 92, 0.25);
  transform: scale(0.92);
}

.tiebreak-banner {
  position: absolute;
  top: calc(64px + 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;
}

/* ---------- 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; }

/* ---------- 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; }
