:root {
  --bg: #ECEFEA; --surface: #FFFFFF; --ink: #17201C; --muted: #5B6862; --line: #D3DAD4; --chip: #F2F4F0;
  --win: #1F7A3D; --loss: #C0392B; --ball: #D3DE3F; --on-ink: #FFFFFF;
  --cond: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111614; --surface: #1A201D; --ink: #E6ECE8; --muted: #98A59E; --line: #2C3530; --chip: #232A26;
    --win: #3DA862; --loss: #DD5B4C; --ball: #C9D43C; --on-ink: #0E1411; color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ball); outline-offset: 2px; }

/* Ingreso */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 22px; display: grid; gap: 14px; }
.login-card h1 { font-family: var(--cond); font-size: 32px; line-height: 1; margin: 6px 0 0; }
.login-card p { margin: 0; color: var(--muted); }
.ball-mark { width: 44px; height: 44px; border-radius: 50%; background: var(--ball); position: relative; overflow: hidden; }
.ball-mark::before, .ball-mark::after { content: ""; position: absolute; width: 44px; height: 44px; border: 3px solid var(--surface); border-radius: 50%; }
.ball-mark::before { left: -30px; } .ball-mark::after { right: -30px; }

/* Encabezado */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: max(14px, env(safe-area-inset-top)) 16px 0; max-width: 760px; margin: 0 auto; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-family: var(--cond); font-weight: 700; font-size: 30px; line-height: 1; margin: 0; }
.brand span { color: var(--muted); font-size: 14px; }
.tabs { display: flex; gap: 4px; max-width: 760px; margin: 6px auto 0; padding: 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 10px 14px 9px; font-family: var(--cond); font-size: 19px; font-weight: 600; color: var(--muted); border-bottom: 4px solid transparent; cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ball); }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(40px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.on { display: grid; gap: 14px; }

/* Formularios */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 14px 16px; margin: 0; min-width: 0; display: grid; gap: 12px; }
.card legend, .card .head h3 { font-family: var(--cond); font-size: 20px; font-weight: 600; padding: 0 4px; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
input:not([type=checkbox]), select { width: 100%; height: 44px; border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 0 11px; font-size: 16px; color: var(--ink); min-width: 0; }
input[type=date] { padding-right: 6px; }
input.nuevo { border-color: var(--ball); box-shadow: inset 0 -3px 0 var(--ball); }
.head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 6px; font-size: 14px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { flex: 1; min-height: 42px; border: 0; background: var(--surface); color: var(--muted); cursor: pointer; padding: 0 6px; font-size: 15px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); font-weight: 600; }
.campo { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.lado { display: grid; gap: 8px; padding: 10px; border-radius: 10px; background: var(--chip); }
.lado .tit { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.lado.gana { box-shadow: inset 4px 0 0 var(--win); }
.lado.gana .tit b { color: var(--win); }

.res-out { font-size: 14px; min-height: 20px; }
.res-out .ok { color: var(--win); font-weight: 600; }
.res-out .err { color: var(--loss); }
.res-out .warn { color: var(--muted); display: block; }
.res-extra:empty { display: none; }

/* Combo de jugadores */
.combo { position: relative; }
.clist { position: relative; margin-top: 4px; z-index: 30; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 240px; overflow: auto; padding: 4px; }
.clist div { padding: 10px; border-radius: 7px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; font-size: 15px; color: var(--ink); }
.clist div small { color: var(--muted); }
.clist div.on, .clist div:hover { background: var(--chip); }
.clist div.add { color: var(--muted); font-style: italic; }

.nuevo-j { border: 1px dashed var(--ball); border-radius: 12px; padding: 12px; display: grid; gap: 10px; background: var(--surface); }
.nuevo-j p { margin: 0; font-weight: 600; }

/* Botones */
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }
.btn { min-height: 46px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; font-size: 16px; }
.btn.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.danger { background: var(--loss); color: #fff; border-color: var(--loss); }
.btn.ghost { background: transparent; border-style: dashed; color: var(--muted); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.errs { color: var(--loss); margin: 0; padding-left: 18px; font-size: 14px; }
.errs:empty { display: none; }
.err { color: var(--loss); font-size: 14px; min-height: 1em; }
.banner { background: var(--ball); color: #17201C; border-radius: 12px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 600; }
.banner .link { color: #17201C; }

/* Lista de partidos */
.search { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); white-space: nowrap; }
.chk input { width: 20px; height: 20px; }
#lista { display: grid; gap: 8px; }
.match { display: grid; grid-template-columns: 5px 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.match > .edge { background: var(--muted); opacity: .4; }
.match .body { padding: 10px 12px; display: grid; gap: 5px; min-width: 0; }
.mmeta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 13px; color: var(--muted); }
.mmeta b { color: var(--ink); }
.mside { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.mside .names { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.mside .names small { color: var(--muted); font-size: 12px; margin-right: 6px; }
.mside.won .names { font-weight: 600; }
.sets { display: flex; gap: 3px; }
.g { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 5px; background: var(--chip); font-family: var(--cond); font-size: 18px; color: var(--muted); }
.g.won { color: var(--ink); font-weight: 700; }
.g.tb { width: 30px; font-size: 15px; }
.mfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 2px; }
.mfoot .id { font-size: 12px; color: var(--muted); }
.mfoot .actions { gap: 6px; }
.tag { font-size: 12px; border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; color: var(--muted); }
.more { justify-self: center; }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }

/* Estados */
.cargando { position: fixed; inset: 0; background: rgba(0,0,0,.25); display: grid; place-items: center; z-index: 80; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--surface); border-top-color: var(--ball); animation: gira .8s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: 10px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 90; max-width: 90vw; }
#toast.on { opacity: 1; }
#toast.err { background: var(--loss); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); width: min(420px, calc(100vw - 32px)); padding: 18px 18px 16px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog p { margin: 0 0 16px; }

@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.equipos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lados { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
}
@media (max-width: 639px) { .lados { display: grid; gap: 8px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }
.grid.dos { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.clave-wrap { position: relative; margin-top: -10px; }
.clave-wrap input { padding-right: 92px; }
.ver-clave { -webkit-tap-highlight-color: transparent; position: absolute; right: 4px; top: 4px; bottom: 4px; min-width: 80px; border: 0; border-radius: 7px; background: var(--chip); color: var(--ink); font-size: 14px; font-weight: 600; cursor: pointer; }
.login-card > label { margin-bottom: 0; }
.clist div { flex-wrap: wrap; }
.clist div small { font-size: 12.5px; }
.cnota { margin: 4px 6px 6px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.parecidos { display: grid; gap: 6px; }
.parecidos > span:first-child { font-size: 14px; font-weight: 600; color: var(--ink); }
.parecidos button { display: grid; gap: 1px; text-align: left; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--chip); cursor: pointer; }
.parecidos button b { font-size: 15px; }
.parecidos button small { font-size: 12.5px; color: var(--muted); }
