:root {
  --bg: #0b1020;
  --panel: #141b2e;
  --panel-2: #1b2440;
  --line: #26304d;
  --text: #e8ecf5;
  --muted: #8c97b3;
  --live: #ff4d5e;
  --half: #f5a524;
  --upcoming: #4da3ff;
  --accent: #3ddc97;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---------- cabecera ---------- */
.site-header {
  background: linear-gradient(180deg, #121a33, var(--bg));
  border-bottom: 1px solid var(--line);
  padding: 22px 0 16px;
  margin-bottom: 18px;
}
.site-header h1 { margin: 0; font-size: clamp(1.5rem, 4vw, 2.3rem); letter-spacing: -0.02em; }
.header-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.header-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.who { color: var(--muted); font-size: 0.9rem; }

.conn { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; display: flex; align-items: center; gap: 8px; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 2s infinite; }
.conn.offline .dot { background: var(--half); animation: none; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- controles comunes ---------- */
input, select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit; min-width: 0; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--upcoming); outline-offset: 1px; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
  touch-action: manipulation; user-select: none;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #062417; border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--live); background: transparent; }
.btn.armed { background: var(--live); color: #fff; border-color: var(--live); }
.btn.tiny { padding: 6px 10px; font-size: 0.85rem; }

.toolbar { display: flex; gap: 12px; margin-bottom: 10px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 20px; }
.chip {
  background: var(--panel); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 0.85rem; cursor: pointer;
}
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

.badge {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap; background: var(--panel-2); color: var(--muted);
}
.badge.first, .badge.second { background: rgba(255, 77, 94, 0.15); color: var(--live); }
.badge.halftime { background: rgba(245, 165, 36, 0.15); color: var(--half); }
.badge.upcoming { background: rgba(77, 163, 255, 0.15); color: var(--upcoming); }

.team-dot {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.group { margin-bottom: 28px; }
.group h2, .panel h2 {
  font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin: 0 0 12px; display: flex; align-items: center; gap: 8px;
}
.count { background: var(--panel-2); border-radius: 999px; padding: 1px 8px; font-size: 0.8rem; }
.count:empty { display: none; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }
.link { color: var(--upcoming); text-decoration: none; }
.link:hover { text-decoration: underline; }
.error { color: var(--live); margin: 0; }

/* ---------- página pública: campos en juego ---------- */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.field-name { font-weight: 800; font-size: 1.05rem; margin-bottom: 8px; }
.no-game { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; margin: 0; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 10px; border-left: 4px solid var(--line);
}
.card.first, .card.second { border-left-color: var(--live); }
.card.halftime { border-left-color: var(--half); }
.card.upcoming { border-left-color: var(--upcoming); }
.card-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.where { color: var(--muted); font-size: 0.9rem; }

.team { padding: 8px 0; }
.team + .team { border-top: 1px solid var(--line); }
.team-main { display: flex; align-items: center; gap: 10px; }
.team .name { font-size: 1.2rem; font-weight: 700; flex: 1; overflow-wrap: anywhere; }
.team .score { font-size: 2.4rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.card.upcoming .score { color: var(--muted); }
.goals { color: var(--muted); font-size: 0.85rem; margin: 4px 0 0 22px; }

.score.flash { animation: flash 1.4s ease-out; }
@keyframes flash { 0% { color: var(--accent); transform: scale(1.3); } 100% { transform: scale(1); } }

/* ---------- listas (próximos / resultados) ---------- */
.rows { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
}
.admin .row { grid-template-columns: 1fr auto auto; }
.row-time { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.row.final .row-time { color: var(--muted); font-weight: 700; font-size: 0.75rem; text-transform: uppercase; }
.row-teams { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; min-width: 0; }
.row-team { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-team.a { justify-content: flex-end; text-align: right; }
.row-team.win { font-weight: 800; }
.row-score { font-weight: 800; font-variant-numeric: tabular-nums; color: var(--muted); min-width: 3.2em; text-align: center; }
.row.final .row-score { color: var(--text); }
.row-meta { color: var(--muted); font-size: 0.8rem; text-align: right; }
.row-actions { display: flex; gap: 6px; }

@media (max-width: 640px) {
  .row { grid-template-columns: 44px 1fr; }
  .row-meta { grid-column: 2; text-align: left; }
  .admin .row { grid-template-columns: 1fr; }
  .admin .row-meta { grid-column: 1; }
}

/* ---------- mesa de control ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.login { max-width: 400px; margin: 40px auto; display: flex; flex-direction: column; gap: 14px; }
.login h2 { font-size: 1.1rem; text-transform: none; letter-spacing: 0; color: var(--text); }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1 1 260px; }
.add-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }

/* ---------- mesa de control (pensada para el móvil) ---------- */
.admin-header { padding: 10px 0; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.admin-header h1 { margin: 0; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-header .conn { margin: 0; }

.btn.big { min-height: 52px; font-size: 1.05rem; }
.btn.wide { display: block; width: 100%; min-height: 50px; margin: 14px 0; }

/* Pestañas de campo: siempre a la vista, con el marcador de cada campo */
.field-tabs {
  position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 8px;
  background: var(--bg); padding: 6px 0 10px; margin-top: -6px;
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 6px;
  background: var(--panel); color: var(--muted); border: 2px solid var(--line); border-radius: 12px;
  font: inherit; cursor: pointer; touch-action: manipulation; min-width: 0;
}
.tab.active { border-color: var(--text); color: var(--text); background: var(--panel-2); }
.tab-name { font-weight: 700; font-size: 0.85rem; display: flex; align-items: center; gap: 6px; }
.tab.live .tab-name::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--live); animation: pulse 1.5s infinite; }
.tab-score { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; color: var(--text); }
.tab-status { font-size: 0.75rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* En el móvil solo se ve el campo elegido; en pantallas grandes, los dos. */
.ctl-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.ctl-col:not(.active) { display: none; }
.ctl-field { display: none; }
@media (min-width: 860px) {
  .field-tabs { display: none; }
  .ctl-grid { grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); }
  .ctl-col:not(.active) { display: block; }
  .ctl-field { display: block; margin: 0 0 8px; font-size: 1.15rem; }
}
.ctl-col { min-width: 0; }
.ctl-empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; margin: 0; text-align: center; }
.ctl-next { margin: 10px 2px 0; font-size: 0.9rem; }

.ctl-card {
  background: var(--panel); border: 1px solid var(--line); border-top: 5px solid var(--upcoming);
  border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 12px;
}
.ctl-card.first, .ctl-card.second { border-top-color: var(--live); }
.ctl-card.halftime { border-top-color: var(--half); }
.ctl-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 0.85rem; }
.ctl-clock { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; line-height: 1; }
.ctl-clock.idle { color: var(--muted); }

.ctl-team { background: var(--panel-2); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.ctl-team-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ctl-name { flex: 1; font-weight: 700; font-size: 1.1rem; overflow-wrap: anywhere; }
.ctl-score { font-size: 2.8rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }
.ctl-team-btns { display: flex; gap: 8px; }
.btn.goal {
  flex: 1; min-height: 72px; font-size: 1.5rem; font-weight: 800; letter-spacing: 0.02em;
  background: var(--accent); color: #062417; border-color: var(--accent);
}
.btn.goal:active:not(:disabled) { transform: scale(0.97); }
.btn.goal:disabled { background: var(--panel); color: var(--muted); border-color: var(--line); opacity: 0.6; }
.btn.minus { width: 56px; padding: 0; color: var(--muted); background: transparent; }

.btn.state { min-height: 64px; font-size: 1.2rem; font-weight: 800; letter-spacing: 0.02em; }
.btn.state.go { background: var(--upcoming); color: #04162b; border-color: var(--upcoming); }
.btn.state.half { background: var(--half); color: #2b1a00; border-color: var(--half); }
.btn.state.end { background: transparent; color: var(--live); border: 2px solid var(--live); }
.btn.state.end.armed { background: var(--live); color: #fff; }

.ctl-links { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.linkish {
  background: none; border: none; color: var(--muted); font: inherit; font-size: 0.95rem;
  text-decoration: underline; cursor: pointer; padding: 8px 4px; touch-action: manipulation;
}
.danger-link { color: var(--live); }
.armed-link { font-weight: 700; }

/* Gestión */
.q-row {
  display: flex; align-items: center; gap: 10px; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.q-time { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.q-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.q-teams { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.q-cat { color: var(--muted); font-size: 0.75rem; }
.q-actions { display: flex; gap: 4px; }
.q-actions .btn.tiny { min-width: 38px; min-height: 38px; }
.account { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
#tournament-form { display: flex; flex-direction: column; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px;
  font-weight: 600; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4); max-width: calc(100% - 40px); z-index: 10;
}

/* ---------- títulos de día, enlaces y ventana de edición ---------- */
.day-header {
  margin: 14px 0 4px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--upcoming);
}
.day-header:first-child { margin-top: 0; }
.ctl-links { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }

.overlay {
  position: fixed; inset: 0; background: rgba(5, 8, 18, 0.75); z-index: 20;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 12px; overflow-y: auto;
}
.edit-panel { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 14px; margin: 0; }
.edit-panel h2 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0; }
.check { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); font-size: 0.9rem; }
.check input { width: auto; margin-top: 3px; }
.edit-actions { display: flex; justify-content: flex-end; gap: 10px; }
.toast { display: flex; align-items: center; gap: 14px; bottom: calc(16px + env(safe-area-inset-bottom)); }
.toast-btn {
  background: var(--bg); color: var(--text); border: none; border-radius: 8px; padding: 8px 12px;
  font: inherit; font-weight: 700; cursor: pointer;
}
.q-row.playing { border-color: var(--live); }
.q-actions { align-items: center; }
.edit-danger { display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- escudos ---------- */
.team-logo { width: 22px; height: 22px; object-fit: contain; flex: none; }
.team .team-logo, .ctl-team-head .team-logo { width: 34px; height: 34px; }
.row-team .team-logo { width: 22px; height: 22px; }

/* ======================================================================
   Página pública: fondo del campo del Carabanchel
   (la mesa de control no lo usa: allí cuenta más la batería y la rapidez)
   ====================================================================== */
body.public {
  --panel: rgba(14, 20, 38, 0.74);
  --panel-2: rgba(30, 40, 70, 0.7);
  --line: rgba(255, 255, 255, 0.12);
  background: #0b1020;
}

/* Capa fija detrás de todo */
.stadium { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }

.stadium-photo {
  position: absolute; inset: -2%;
  background: url("/img/campo-movil.jpg") center 30% / cover no-repeat;
  animation: drift 40s ease-in-out infinite alternate;
}
@media (min-width: 900px) { .stadium-photo { background-image: url("/img/campo.jpg"); } }
/* Velo azul noche: deja ver el cielo y el campo, pero el texto se lee bien */
.stadium-photo::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(180deg, rgba(6, 10, 26, 0.12) 0%, rgba(6, 10, 26, 0.45) 40%, rgba(6, 10, 26, 0.82) 100%),
    radial-gradient(120% 80% at 50% 0%, transparent 45%, rgba(6, 10, 26, 0.45) 100%);
}
@keyframes drift { from { transform: scale(1); } to { transform: scale(1.06) translateY(-1%); } }

/* Focos del estadio encendidos, uno a cada lado */
.stadium-lights::before, .stadium-lights::after {
  content: ""; position: absolute; top: -18vmax; width: 70vmax; height: 70vmax; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 250, 225, 0.32) 0%, rgba(255, 250, 225, 0.08) 35%, transparent 65%);
  animation: floodlight 6s ease-in-out infinite alternate;
}
.stadium-lights::before { left: -30vmax; }
.stadium-lights::after { right: -30vmax; animation-delay: -3s; }
@keyframes floodlight { from { opacity: 0.6; } to { opacity: 1; } }

/* Líneas del campo dibujadas en el césped, en perspectiva */
.stadium-lines {
  position: absolute; left: 50%; bottom: -12vh; width: 150vmax; height: 95vmax;
  transform: translateX(-50%) perspective(900px) rotateX(62deg);
  transform-origin: 50% 100%; opacity: 0.16;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1050 680' fill='none' stroke='white' stroke-width='5'%3E%3Crect x='5' y='5' width='1040' height='670'/%3E%3Cline x1='525' y1='5' x2='525' y2='675'/%3E%3Ccircle cx='525' cy='340' r='92'/%3E%3Ccircle cx='525' cy='340' r='6' fill='white'/%3E%3Crect x='5' y='138' width='165' height='404'/%3E%3Crect x='880' y='138' width='165' height='404'/%3E%3Crect x='5' y='248' width='55' height='184'/%3E%3Crect x='990' y='248' width='55' height='184'/%3E%3Cpath d='M170 266 A92 92 0 0 1 170 414'/%3E%3Cpath d='M880 266 A92 92 0 0 0 880 414'/%3E%3C/svg%3E") center / contain no-repeat;
}

/* Nieve de Navidad, muy suave */
.snow {
  position: absolute; inset: -300px 0 0;
  background-image:
    radial-gradient(3px 3px at 20px 30px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2px 2px at 90px 140px, rgba(255,255,255,0.8), transparent),
    radial-gradient(3px 3px at 160px 60px, rgba(255,255,255,0.7), transparent),
    radial-gradient(2px 2px at 230px 210px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2.5px 2.5px at 280px 110px, rgba(255,255,255,0.8), transparent);
  background-size: 300px 300px;
  animation: snowfall 18s linear infinite;
  opacity: 0.55;
}
.snow-far { background-size: 180px 180px; opacity: 0.3; animation-duration: 30s; filter: blur(0.6px); }
@keyframes snowfall { to { transform: translate3d(40px, 300px, 0); } }

@media (prefers-reduced-motion: reduce) {
  .stadium-photo, .stadium-lights::before, .stadium-lights::after, .snow { animation: none; }
}

/* Cabecera sobre el cielo */
.public .site-header {
  background: none; border-bottom: none;
  padding: 34px 0 26px; margin-bottom: 8px; text-align: center;
}
.public .site-header .wrap { display: flex; flex-direction: column; align-items: center; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 10px;
  padding: 5px 14px 5px 6px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; color: #fff;
}
.eyebrow-logo { width: 24px; height: 24px; object-fit: contain; }
.public .site-header h1 {
  font-size: clamp(2rem, 7vw, 3.6rem); font-weight: 900; letter-spacing: -0.03em; line-height: 1.05;
  text-transform: uppercase; color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25), 0 8px 30px rgba(0, 0, 0, 0.55);
}
/* Rayita roja y blanca bajo el título, como una bufanda */
.public .site-header h1::after {
  content: ""; display: block; width: 120px; height: 5px; margin: 12px auto 0; border-radius: 3px;
  background: repeating-linear-gradient(90deg, #e30613 0 14px, #fff 14px 28px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}
.public .conn { justify-content: center; color: rgba(255, 255, 255, 0.8); }

/* Títulos de sección más visibles sobre la foto */
.public .group h2 { color: rgba(255, 255, 255, 0.85); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6); }
.public .field-name { text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6); }

/* Tarjetas de cristal */
.public .card, .public .no-game {
  background: linear-gradient(160deg, rgba(30, 40, 72, 0.78), rgba(10, 15, 30, 0.82));
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.public .card.first, .public .card.second { animation: live-glow 2.4s ease-in-out infinite; }
@keyframes live-glow {
  0%, 100% { box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 77, 94, 0.25); }
  50% { box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 26px 2px rgba(255, 77, 94, 0.35); }
}
.public .team .score { text-shadow: 0 0 18px rgba(255, 255, 255, 0.25); }
.public .row { background: rgba(12, 18, 34, 0.8); }
.public .row:hover { background: rgba(22, 30, 54, 0.88); }
.public input { background: rgba(12, 18, 34, 0.8); }
.public .chip { background: rgba(12, 18, 34, 0.75); color: #cfd6e6; }
.public .chip.active { background: #fff; color: #0b1020; }
.public .empty { color: rgba(255, 255, 255, 0.75); }

@media (prefers-reduced-motion: reduce) {
  .public .card.first, .public .card.second { animation: none; }
}
