:root {
  --bg: #0b1324;
  --surface: #131f38;
  --surface-2: #1b2a4a;
  --line: #263a63;
  --text: #eef3ff;
  --muted: #9fb0d0;
  --ball: #d9f84a;
  --ball-ink: #1a2400;
  --riviera: #3ea6ff;
  --senderos: #ff8a4c;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px 32px; }
button { font: inherit; color: inherit; }
a { color: var(--ball); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- Encabezado / marcador ---------- */
.hero {
  background:
    radial-gradient(120% 90% at 50% -10%, #1f3c78 0%, transparent 60%),
    repeating-linear-gradient(90deg, transparent 0 48px, rgba(255,255,255,.035) 48px 50px),
    var(--bg);
  border-bottom: 1px solid var(--line);
  padding: max(10px, env(safe-area-inset-top)) 16px 12px;
}
.hero > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.hero-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.event-info { margin: -2px 0 12px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.event-info[hidden] { display: none; }
.event-date { font-size: 17px; font-weight: 800; color: var(--ball); }
.event-time { font-size: 14px; font-weight: 600; color: var(--muted); }
.brand { font-weight: 800; letter-spacing: .02em; text-transform: uppercase; font-size: 13px; display: inline-flex; align-items: center; gap: 8px; }
.ball { width: 16px; height: 16px; border-radius: 50%; background: var(--ball); box-shadow: inset -3px -2px 0 rgba(0,0,0,.15); }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on { color: var(--ok); }
.live.on .dot { background: var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,.6); } 100% { box-shadow: 0 0 0 8px rgba(52,211,153,0); } }

.scoreboard { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.sb-team { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px 10px; border-radius: var(--radius); background: rgba(255,255,255,.04); border: 1px solid var(--line); }
.sb-riviera { border-top: 4px solid var(--riviera); }
.sb-senderos { border-top: 4px solid var(--senderos); }
.sb-team.champ { border-color: var(--ball); box-shadow: 0 0 0 2px var(--ball); }
.sb-name { font-weight: 700; font-size: 15px; text-align: center; }
.sb-num { display: flex; align-items: baseline; gap: 6px; }
.sb-wins { font-size: 42px; line-height: 1; font-weight: 900; font-variant-numeric: tabular-nums; }
.sb-riviera .sb-wins { color: var(--riviera); }
.sb-senderos .sb-wins { color: var(--senderos); }
.sb-unit { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sb-mid { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.sb-goal { background: var(--ball); color: var(--ball-ink); font-weight: 800; font-size: 11px; text-transform: uppercase; padding: 4px 8px; border-radius: 999px; white-space: nowrap; }
.sb-played { font-size: 12px; color: var(--muted); }
.pips { display: flex; gap: 4px; }
.pip { width: 12px; height: 6px; border-radius: 3px; background: var(--line); }
.pips-riviera .pip.on { background: var(--riviera); }
.pips-senderos .pip.on { background: var(--senderos); }

.champion {
  margin-top: 14px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--ball); color: var(--ball-ink); font-weight: 900; font-size: 18px;
  display: flex; align-items: center; justify-content: center; gap: 8px; text-transform: uppercase;
}
.hero-compact .sb-wins { font-size: 36px; }

/* ---------- Franja fija con el marcador ---------- */
.mini {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20; height: calc(44px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: rgba(11,19,36,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px);
  font-size: 14px; font-weight: 700; transform: translateY(-100%); transition: transform .2s ease; pointer-events: none;
}
body.mini-on .mini { transform: none; }
.mini-team { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.mini-score { font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mini-score small { font-size: 11px; color: var(--muted); font-weight: 700; }
.mini-r { color: var(--riviera); }
.mini-s { color: var(--senderos); }
.mini-champ { color: var(--ball); font-size: 12px; white-space: nowrap; }
@media (max-width: 380px) { .mini-team { font-size: 0; gap: 0; } .mini-team .chip { font-size: 11px; } }

.demo-banner { background: #3b2a06; color: var(--warn); text-align: center; font-size: 12px; font-weight: 700; padding: 6px 16px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Pestañas ---------- */
.tabs { position: sticky; top: 0; transition: top .2s ease; z-index: 5; display: flex; gap: 4px; max-width: 640px; margin: 0 auto; padding: 8px 16px; background: var(--bg); }
.tab { flex: 1; border: 1px solid var(--line); background: var(--surface); padding: 10px; border-radius: 999px; font-weight: 700; cursor: pointer; }
body.mini-on .tabs { top: calc(44px + env(safe-area-inset-top)); }
.tab { min-height: 44px; }
.tab.active { background: var(--ball); color: var(--ball-ink); border-color: var(--ball); }

.search input {
  width: 100%; margin: 2px 0 8px; padding: 11px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text); font-size: 16px;
}

/* ---------- Partidos ---------- */
.matches, .stack { display: flex; flex-direction: column; gap: 10px; }
.matches > .section-title { margin: 8px 0 -2px; }
.matches > .section-title ~ .section-title { margin-top: 14px; }
.match, .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.meta .num { color: var(--text); font-weight: 800; }
.meta .time { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.meta .court { color: var(--text); font-weight: 700; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 8px; border-radius: 6px; }
.meta .mod { color: var(--ball); font-weight: 600; }
.match.is-next { border-color: var(--ball); box-shadow: 0 0 0 1px var(--ball) inset; }
.match.is-final { background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
.side { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; padding: 6px 0; }
.side + .side { border-top: 1px dashed var(--line); }
.players { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.games { font-size: 26px; font-weight: 900; font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }
.side.lost { opacity: .6; }
.side.won .games { color: var(--ball); }
.chip { display: inline-block; font-size: 11px; font-weight: 800; padding: 3px 6px; border-radius: 6px; color: #04121f; }
.chip-riviera { background: var(--riviera); }
.chip-senderos { background: var(--senderos); }
.foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.status { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.foot .btn { white-space: nowrap; }
.status-final { background: rgba(52,211,153,.15); color: var(--ok); }
.status-review { background: rgba(251,191,36,.15); color: var(--warn); }
.status-todo { background: var(--surface-2); color: var(--muted); }
.status-next { background: var(--ball); color: var(--ball-ink); }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }
.note { margin: 0 0 4px; font-size: 13px; color: var(--muted); border-left: 3px solid var(--ball); padding: 2px 0 2px 10px; }

/* ---------- Botones ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface-2); padding: 12px 16px; border-radius: 12px;
  font-weight: 700; cursor: pointer; min-height: 44px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--ball); color: var(--ball-ink); border-color: var(--ball); width: 100%; }
.btn-small { padding: 10px 14px; min-height: 44px; font-size: 14px; width: auto; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: var(--danger); border-color: rgba(248,113,113,.4); width: 100%; }
.icon-btn { background: var(--surface-2); border: 0; border-radius: 50%; width: 44px; height: 44px; flex: none; cursor: pointer; font-size: 16px; }

/* ---------- Hoja de envío ---------- */
/* La hoja se ancla al borde inferior del viewport visual: con el teclado abierto
   queda encima de él y el botón de envío sigue visible. */
.sheet {
  position: fixed; left: 0; right: 0; width: 100%; max-width: 520px; margin: 0 auto; padding: 0; border: 0;
  top: calc(var(--vv-top, 0px) + var(--vv-h, 100dvh)); bottom: auto; transform: translateY(-100%);
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
  max-height: calc(var(--vv-h, 100dvh) - 12px); overflow: hidden;
}
@media (min-width: 600px) { .sheet { top: 50%; transform: translateY(-50%); border-radius: 20px; max-height: 90dvh; } }
.sheet::backdrop { background: rgba(3,8,18,.7); }
.sheet form { display: flex; flex-direction: column; max-height: inherit; }
.sheet-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 16px 8px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-match { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.sheet-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 12px; }
.sheet-actions { flex: none; padding: 10px 16px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; gap: 6px; }

.score-editor { display: flex; flex-direction: column; gap: 10px; }
.picker { border: 0; margin: 0; padding: 10px 10px 12px; background: var(--surface-2); border-radius: 12px; border-left: 4px solid var(--line); min-width: 0; }
.picker.team-riviera { border-left-color: var(--riviera); }
.picker.team-senderos { border-left-color: var(--senderos); }
.picker-label { float: left; width: 100%; padding: 0; margin-bottom: 8px; display: flex; flex-direction: column; }
.picker-label + * { clear: both; }
.picker-team { font-size: 15px; font-weight: 800; }
.picker-players { font-size: 13px; color: var(--muted); }
.pick-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.pick {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; cursor: pointer; touch-action: manipulation; padding: 0;
}
.pick[aria-checked="true"] { background: var(--ball); color: var(--ball-ink); border-color: var(--ball); }
.team-riviera .pick[aria-checked="true"] { box-shadow: 0 0 0 2px var(--riviera); }
.team-senderos .pick[aria-checked="true"] { box-shadow: 0 0 0 2px var(--senderos); }
.tiebreak { border: 1px dashed var(--ball); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.tb-title { margin: 0; font-size: 14px; font-weight: 700; color: var(--ball); }
.tb-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 8px; }
.tb-sep { font-size: 24px; font-weight: 800; padding-bottom: 8px; color: var(--muted); }
.tb-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; }
.tb-field.team-riviera span { color: var(--riviera); }
.tb-field.team-senderos span { color: var(--senderos); }
.tb-input { width: 100%; min-height: 52px; text-align: center; font-size: 26px; font-weight: 900; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-variant-numeric: tabular-nums; }
.tb-input:focus { outline: 2px solid var(--ball); outline-offset: 1px; }
.tb-hint { margin: 0; font-size: 12px; color: var(--muted); }
.score-msg { margin: 0; font-size: 14px; color: var(--muted); min-height: 1.45em; text-align: center; }
.score-msg.is-ok { color: var(--ok); font-weight: 700; }
.score-msg.is-error { color: var(--warn); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.field input { padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
.hint { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }
.hp { position: absolute; left: -9999px; }

/* ---------- Clasificación ---------- */
.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; display: flex; align-items: center; gap: 8px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { padding: 10px 8px; text-align: center; border-bottom: 1px solid var(--line); }
th[scope="row"] { text-align: left; font-weight: 600; white-space: nowrap; }
thead th { font-size: 11px; color: var(--muted); text-transform: uppercase; }
tbody tr:last-child > * { border-bottom: 0; }
td.strong { font-weight: 900; color: var(--ball); }
td.pts { font-size: 18px; }
tr.idle > * { color: var(--muted); }
tr.idle td.strong { color: var(--muted); font-weight: 600; }
.count.count-muted { background: var(--surface-2); color: var(--muted); }
.legend { font-size: 12px; color: var(--muted); }
.foot-note { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 24px; }

/* ---------- Avisos ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  width: calc(100% - 32px); max-width: 480px; padding: 12px 16px; border-radius: 12px; font-weight: 600;
  opacity: 0; transition: .25s; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-ok { background: var(--ok); color: #03231a; }
.toast-error { background: var(--danger); color: #2a0606; }

/* ---------- Organizador ---------- */
.login { padding-top: 24px; }
.login .card { display: flex; flex-direction: column; gap: 14px; }
.login h2 { margin: 0; }
.admin-bar { display: flex; justify-content: space-between; align-items: center; padding-top: 14px; }
.link { font-weight: 600; }
.count { background: var(--warn); color: #2a1d00; border-radius: 999px; padding: 1px 8px; font-size: 12px; letter-spacing: 0; }
.pending-card { display: flex; flex-direction: column; gap: 4px; border-left: 4px solid var(--warn); }
.pending-card.conflict { border-left-color: var(--danger); }
.pending-card p { margin: 0; }
.pending-teams { font-size: 14px; }
.pending-score { font-size: 22px; font-weight: 900; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 12px; }
.warn { color: var(--warn); }
.row { display: flex; gap: 8px; margin-top: 8px; }
.history summary { cursor: pointer; }
.audit { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.audit li { display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; background: var(--surface); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.audit time { grid-column: 2; }
.tag { font-size: 11px; font-weight: 800; padding: 2px 6px; border-radius: 6px; background: var(--surface-2); height: fit-content; }
.tag-aprobacion, .tag-registro { color: var(--ok); }
.tag-correccion, .tag-envio { color: var(--warn); }
.tag-rechazo, .tag-borrado { color: var(--danger); }
.tag-sustitucion { color: var(--riviera); }

/* ---------- Sustitución de jugadores ---------- */
.admin .foot { flex-wrap: wrap; }
.foot-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-left: auto; }
.swap-block { margin: 0; padding: 10px 12px; border-radius: 12px; background: rgba(251,191,36,.12); border: 1px solid rgba(251,191,36,.45); color: var(--warn); font-size: 14px; font-weight: 600; }
.swap-pick { border: 0; margin: 0; padding: 0; min-width: 0; }
.swap-step { font-size: 14px; font-weight: 700; margin-bottom: 8px; padding: 0; }
.swap-teams { display: flex; flex-direction: column; gap: 10px; }
.swap-team { background: var(--surface-2); border-radius: 12px; padding: 10px; border-left: 4px solid var(--line); }
.swap-team.team-riviera { border-left-color: var(--riviera); }
.swap-team.team-senderos { border-left-color: var(--senderos); }
.swap-team-name { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 800; margin-bottom: 8px; }
.swap-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; }
.swap-player { min-height: 48px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; padding: 6px 10px; overflow-wrap: anywhere; touch-action: manipulation; }
.swap-player[aria-checked="true"] { background: var(--ball); color: var(--ball-ink); border-color: var(--ball); }
.swap-player:disabled { opacity: .45; cursor: not-allowed; }
.field input:disabled { opacity: .45; }
.swap-hint { text-align: left; }

/* ---------- Conexión: datos atenuados o ocultos ---------- */
.offline-card { display: none; max-width: 608px; margin: 16px auto; padding: 18px 16px; border-radius: var(--radius); background: #2a1414; border: 1px solid rgba(248,113,113,.5); text-align: center; }
.offline-card h2 { margin: 0 0 6px; font-size: 20px; color: var(--danger); }
.offline-card p { margin: 0 0 10px; }
body.is-offline .offline-card { display: block; margin-left: 16px; margin-right: 16px; }
@media (min-width: 640px) { body.is-offline .offline-card { margin-left: auto; margin-right: auto; } }
body.is-offline #scoreboard, body.is-offline #champion, body.is-offline .mini, body.is-offline .tabs,
body.is-offline main, body.is-offline .foot-note { display: none !important; }
body.is-stale:not(.is-offline) #scoreboard, body.is-stale:not(.is-offline) .mini,
body.is-stale:not(.is-offline) main { opacity: .4; filter: grayscale(.7); transition: opacity .2s; }
.live:not(.on) .live-text { color: var(--warn); }

/* ---------- Instalación ---------- */
.install-banner { display: flex; align-items: center; gap: 10px; margin: 2px 0 10px; padding: 8px 8px 8px 10px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; font-weight: 700; }
.install-banner[hidden] { display: none; }
.install-banner img { border-radius: 9px; flex: none; }
.install-banner span { flex: 1; min-width: 0; }
.icon-btn-small { background: transparent; }
.install-intro { margin: 0; color: var(--muted); font-size: 14px; }
.install-block h3, .install-other summary { margin: 0 0 6px; font-size: 16px; }
.install-steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.install-other { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.install-other summary { cursor: pointer; color: var(--muted); font-weight: 700; margin: 0; min-height: 28px; }
.install-other[open] summary { margin-bottom: 8px; }
.link-btn { background: none; border: 0; color: var(--ball); font: inherit; font-weight: 700; text-decoration: underline; padding: 12px 8px; min-height: 44px; cursor: pointer; }
@media (display-mode: standalone) { #install-open-footer { display: none; } }
