:root {
  --bg: #0b1210;
  --bg2: #111b18;
  --card: #15221e;
  --card2: #1b2b26;
  --line: #24382f;
  --text: #e8f1ec;
  --muted: #8ea69a;
  --table: #0f5c45;
  --table2: #13785a;
  --ball: #ff7a1a;
  --ball2: #ffb067;
  --win: #34d399;
  --loss: #f87171;
  --warn: #fbbf24;
  --info: #60a5fa;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  padding-bottom: calc(84px + var(--safe-b));
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--ball); }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tnum { font-variant-numeric: tabular-nums; }
.win { color: var(--win); } .loss { color: var(--loss); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: rgba(11,18,16,.86);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.topbar .logo { font-weight: 800; letter-spacing: -.3px; font-size: 17px; display: flex; gap: 8px; align-items: center; }
.topbar .logo .dot { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff 0 12%, var(--ball2) 13%, var(--ball) 70%); box-shadow: 0 0 12px var(--ball); }
.topbar .spacer { flex: 1; }
.topbar .back { background: none; border: 0; font-size: 22px; padding: 0 6px 0 0; cursor: pointer; }
main { max-width: 640px; margin: 0 auto; padding: 16px; }
.section { margin: 22px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.section a { color: var(--ball2); font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: rgba(17,27,24,.95); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + var(--safe-b));
}
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 6px 0; position: relative; }
.nav a .ic { font-size: 20px; line-height: 1; filter: grayscale(.8); }
.nav a.active { color: var(--text); }
.nav a.active .ic { filter: none; }
.nav a.plus .ic {
  width: 52px; height: 52px; margin-top: -26px; border-radius: 50%; display: grid; place-items: center; filter: none;
  background: linear-gradient(145deg, var(--ball2), var(--ball)); color: #1b0d00; font-size: 30px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(255,122,26,.45), 0 0 0 5px var(--bg);
}
.badge {
  position: absolute; top: 0; right: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--loss); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--card2); border-radius: 12px; padding: 11px 16px; font-weight: 600; cursor: pointer; min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(145deg, var(--ball2), var(--ball)); border: 0; color: #1d0e00; }
.btn.green { background: var(--table2); border-color: var(--table2); }
.btn.danger { background: transparent; border-color: #7f2a2a; color: var(--loss); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 34px; padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--bg2); color: var(--muted); border-radius: 999px; padding: 7px 14px; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

/* ---------- avatar ---------- */
.av {
  --c: var(--ball); flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-size: 21px; background: color-mix(in srgb, var(--c) 22%, var(--card2)); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 70%, transparent);
}
.av.sm { width: 30px; height: 30px; font-size: 16px; }
.av.lg { width: 72px; height: 72px; font-size: 38px; }
.av.xl { width: 92px; height: 92px; font-size: 50px; }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 20px; padding: 18px;
  background: linear-gradient(160deg, var(--table2), var(--table) 60%, #0b3e2f);
  border: 1px solid #1f8a67;
}
.hero::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: rgba(255,255,255,.25); }
.hero::after { content: ""; position: absolute; inset: 8px; border: 2px solid rgba(255,255,255,.35); border-radius: 14px; pointer-events: none; }
.hero > * { position: relative; z-index: 1; }
.hero .big { font-size: 40px; font-weight: 800; letter-spacing: -1px; }
.hero .kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.hero .kpi { background: rgba(0,0,0,.22); border-radius: 12px; padding: 8px 10px; text-align: center; }
.hero .kpi b { display: block; font-size: 18px; }
.hero .kpi span { font-size: 11px; opacity: .8; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 18px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }

/* ---------- form dots ---------- */
.form { display: inline-flex; gap: 3px; }
.form i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.form i.W { background: var(--win); } .form i.L { background: var(--loss); }

.streak { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.streak.up { background: rgba(52,211,153,.15); color: var(--win); }
.streak.down { background: rgba(248,113,113,.15); color: var(--loss); }

/* ---------- podium & ranking ---------- */
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; margin: 8px 0 14px; }
.podium .pl { text-align: center; }
.podium .pl .name { font-weight: 700; font-size: 13px; margin-top: 6px; }
.podium .step { margin-top: 8px; border-radius: 12px 12px 4px 4px; display: grid; place-items: center; font-weight: 800; font-size: 22px; color: rgba(0,0,0,.55); }
.podium .p1 .step { height: 92px; background: linear-gradient(#fde68a, #f59e0b); }
.podium .p2 .step { height: 68px; background: linear-gradient(#e5e7eb, #9ca3af); }
.podium .p3 .step { height: 52px; background: linear-gradient(#fdba74, #c2410c); }
.podium .crown { font-size: 22px; display: block; margin-bottom: -4px; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); }
.li:first-child { border-top: 0; }
.li.me { background: rgba(255,122,26,.08); }
.li .pos { width: 22px; text-align: center; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.li .elo { font-weight: 800; font-size: 17px; font-variant-numeric: tabular-nums; text-align: right; }
.tag { font-size: 10.5px; padding: 1px 6px; border-radius: 6px; background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.tag.pending { color: var(--warn); border-color: #6b5314; background: rgba(251,191,36,.08); }
.tag.disputed { color: var(--loss); border-color: #7f2a2a; background: rgba(248,113,113,.08); }
.tag.cancelled { text-decoration: line-through; }
.tag.confirmed { color: var(--win); border-color: #1d6b50; background: rgba(52,211,153,.08); }

/* ---------- match card ---------- */
.match { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.match .side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.match .side.r { flex-direction: row-reverse; text-align: right; }
.match .side .nm { font-weight: 600; min-width: 0; }
.match .side.lose .nm { color: var(--muted); font-weight: 500; }
.match .score { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; text-align: center; letter-spacing: 1px; }
.match .score .w { color: var(--text); } .match .score .l { color: var(--muted); }
.match-meta { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 8px; font-size: 12px; color: var(--muted); }
.sets-mini { font-size: 12px; color: var(--muted); text-align: center; margin-top: 2px; font-variant-numeric: tabular-nums; }
.delta { font-size: 11px; font-weight: 700; }
.delta.p { color: var(--win); } .delta.n { color: var(--loss); }

.alert { border-color: #6b5314; background: linear-gradient(0deg, rgba(251,191,36,.06), rgba(251,191,36,.06)), var(--card); }
.alert.red { border-color: #7f2a2a; background: linear-gradient(0deg, rgba(248,113,113,.07), rgba(248,113,113,.07)), var(--card); }

/* ---------- new match ---------- */
.pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.pick button { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.pick button.on { border-color: var(--ball); background: rgba(255,122,26,.1); box-shadow: 0 0 0 1px var(--ball); }
.pick .nm { font-size: 12.5px; font-weight: 600; max-width: 100%; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--card2); color: var(--text); }
.setrow { display: grid; grid-template-columns: 34px 1fr 20px 1fr 34px; gap: 6px; align-items: center; margin-top: 8px; }
.setrow .n { color: var(--muted); font-size: 12px; text-align: center; }
.stepper { display: grid; grid-template-columns: 38px 1fr 38px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }
.stepper input { border: 0; text-align: center; font-size: 22px; font-weight: 800; padding: 8px 0; background: transparent; border-radius: 0; font-variant-numeric: tabular-nums; }
.stepper.win { border-color: #1d6b50; } .stepper.win input { color: var(--win); }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; cursor: pointer; }
.summary { text-align: center; padding: 16px; border-radius: 14px; background: var(--bg2); border: 1px dashed var(--line); font-weight: 600; }
.summary .res { font-size: 28px; font-weight: 800; }

/* ---------- elo chart ---------- */
.chart svg { width: 100%; height: 150px; display: block; }
.chart .axis { fill: var(--muted); font-size: 10px; }

/* ---------- achievements ---------- */
.ach { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ach > div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 6px; text-align: center; }
.ach .e { font-size: 28px; }
.ach .n { font-size: 11.5px; font-weight: 700; margin-top: 2px; }
.ach .d { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.ach .off { opacity: .35; filter: grayscale(1); }

/* ---------- h2h ---------- */
.vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; text-align: center; gap: 8px; }
.vs .big { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--line); }
.bar > div { height: 100%; transition: width .5s; }

/* ---------- timeline ---------- */
.tl { position: relative; padding-left: 18px; }
.tl::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl .ev { position: relative; padding: 4px 0 12px; }
.tl .ev::before { content: ""; position: absolute; left: -17px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); border: 2px solid var(--card); }
.tl .ev.match_created::before { background: var(--info); }
.tl .ev.match_confirmed::before, .tl .ev.auto_confirmed::before, .tl .ev.match_confirmed_by_admin::before { background: var(--win); }
.tl .ev.match_disputed::before, .tl .ev.match_cancelled::before { background: var(--loss); }
.tl .ev.match_edited::before { background: var(--warn); }
.diff { font-size: 12px; background: var(--bg2); border-radius: 8px; padding: 6px 8px; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- matrix ---------- */
.matrix { overflow-x: auto; }
.matrix table { border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.matrix th, .matrix td { padding: 6px 8px; text-align: center; border: 1px solid var(--line); white-space: nowrap; }
.matrix th { color: var(--muted); font-weight: 600; position: sticky; left: 0; background: var(--bg); }
.matrix td.self { background: var(--card2); }

/* ---------- sheet / toast ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 640px; max-height: 90dvh; overflow-y: auto; background: var(--bg2); border-radius: 22px 22px 0 0; padding: 10px 16px calc(20px + var(--safe-b)); border: 1px solid var(--line); animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: calc(100% - 32px); animation: up .2s; }
.toast.err { background: var(--loss); color: #fff; }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px 40px; max-width: 420px; margin: 0 auto; }
.auth .brand { text-align: center; margin-bottom: 26px; }
.auth .brand .ball { width: 74px; height: 74px; margin: 0 auto 14px; border-radius: 50%; background: radial-gradient(circle at 32% 30%, #fff 0 10%, var(--ball2) 11%, var(--ball) 65%, #c2410c); box-shadow: 0 10px 40px rgba(255,122,26,.5); animation: bounce 1.6s infinite cubic-bezier(.5,0,.5,1); }
@keyframes bounce { 50% { transform: translateY(-14px); } }
.auth h1 { font-size: 28px; letter-spacing: -.5px; }
.err-msg { color: var(--loss); font-size: 13px; margin-top: 10px; min-height: 18px; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty .e { font-size: 40px; }
.menu .li { cursor: pointer; }
.menu .li .ic { font-size: 20px; width: 26px; text-align: center; }
.skel { height: 80px; border-radius: 16px; background: linear-gradient(90deg, var(--card), var(--card2), var(--card)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
canvas.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
@media (min-width: 700px) { body { padding-bottom: 100px; } }

/* ---------- v2: registro rápido ---------- */
.step-t { display: flex; align-items: center; gap: 8px; margin: 20px 0 10px; font-weight: 700; font-size: 16px; }
.step-t .n { width: 22px; height: 22px; border-radius: 50%; background: var(--ball); color: #1d0e00; font-size: 12px; display: grid; place-items: center; font-weight: 800; }
.pick button[disabled] { opacity: .3; }
.pick button.mate .role { color: var(--info); }
.pick button .role { font-size: 10.5px; color: var(--ball2); font-weight: 700; min-height: 13px; }
.pick button.mate { border-color: var(--info); background: rgba(96,165,250,.1); box-shadow: 0 0 0 1px var(--info); }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.who button {
  background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 16px 8px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px; font-weight: 700; min-height: 120px; justify-content: center;
}
.who button.on { border-color: var(--win); background: rgba(52,211,153,.1); }
.who button.on::after { content: "🏆 Ganó"; font-size: 12px; color: var(--win); }
.who .avs { display: flex; }
.who .avs .av + .av { margin-left: -12px; }
.pts { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pts button {
  aspect-ratio: 1.25; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 20px; font-weight: 800;
  cursor: pointer; font-variant-numeric: tabular-nums;
}
.pts button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.pts button.deuce { grid-column: span 5; aspect-ratio: auto; padding: 12px; font-size: 14px; font-weight: 700; color: var(--warn); border-style: dashed; }
.final { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; border-radius: 16px; background: var(--bg2); border: 1px dashed var(--line); margin-top: 16px; }
.final .sc { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.final .who-n { font-size: 13px; color: var(--muted); max-width: 100px; text-align: center; }
details.more { margin-top: 14px; }
details.more summary { color: var(--muted); font-size: 13px; cursor: pointer; padding: 6px 0; }
.sticky-cta { position: sticky; bottom: calc(78px + var(--safe-b)); z-index: 5; padding-top: 10px; background: linear-gradient(transparent, var(--bg) 30%); }

/* ---------- inicio: subida rápida ---------- */
.quick { border-radius: 20px; padding: 14px 14px 12px; background: var(--card); border: 1px solid var(--line); }
.quick .hd { display: flex; justify-content: space-between; align-items: center; }
.quick .hd a { color: var(--ball2); }
.quick .rivals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.quick .rv { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 2px; border-radius: 14px; font-size: 12.5px; font-weight: 600; min-width: 0; }
.quick .rv:active { background: var(--card2); }
.quick .rv span.ellipsis { max-width: 100%; }
.quick .rv.more .av { background: var(--bg2); box-shadow: inset 0 0 0 2px var(--line); color: var(--muted); font-size: 26px; }
.team { display: inline-flex; align-items: center; }
.team .av + .av { margin-left: -10px; }
.match .side .nm small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.kind-tag { font-size: 10px; font-weight: 800; letter-spacing: .5px; color: var(--info); }
.topbar .logo img { width: 24px; height: 24px; border-radius: 6px; }
.auth .brand-logo { width: 96px; height: 96px; border-radius: 24px; margin: 0 auto 16px; display: block; box-shadow: 0 12px 40px rgba(26,154,111,.35); animation: bounce 2.4s infinite cubic-bezier(.5,0,.5,1); }
.summary { text-align: center; padding: 16px; border-radius: 14px; background: var(--bg2); border: 1px dashed var(--line); font-weight: 600; }
.summary .res { font-size: 28px; font-weight: 800; }
#submit, #qs { scroll-margin-bottom: calc(110px + var(--safe-b)); }
