:root {
  --bg: #0b0f14;
  --surface: #121923;
  --surface-2: #19222f;
  --surface-3: #212c3b;
  --border: #263244;
  --text: #eaf0f7;
  --muted: #8b9ab0;
  --faint: #5d6b80;
  --accent: #d4f24a;
  --accent-ink: #11160a;
  --accent-soft: rgba(212, 242, 74, .14);
  --f: #ff77b4;
  --f-soft: rgba(255, 119, 180, .15);
  --m: #5fb0ff;
  --m-soft: rgba(95, 176, 255, .15);
  --x: #b894ff;
  --x-soft: rgba(184, 148, 255, .16);
  --danger: #ff6464;
  --ok: #3ddc97;
  --warn: #ffc15e;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f1f4f8; --surface-3: #e7ecf2; --border: #dfe5ee;
    --text: #111823; --muted: #5d6b80; --faint: #8b98ab; --accent: #b6d91b; --accent-ink: #141a05;
    --accent-soft: rgba(160, 200, 20, .16); --shadow: 0 8px 24px rgba(20, 30, 50, .10); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f1f4f8; --surface-3: #e7ecf2; --border: #dfe5ee;
  --text: #111823; --muted: #5d6b80; --faint: #8b98ab; --accent: #b6d91b; --accent-ink: #141a05;
  --accent-soft: rgba(160, 200, 20, .16); --shadow: 0 8px 24px rgba(20, 30, 50, .10); color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; line-height: 1.4; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: inherit; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { max-width: 760px; margin: 0 auto; padding: 0 16px calc(var(--nav-h) + var(--safe-b) + 28px); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: calc(env(safe-area-inset-top, 0px) + 14px) 0 12px;
  background: linear-gradient(var(--bg) 70%, transparent); }
.topbar h1 { font-size: 26px; letter-spacing: -.02em; margin: 0; flex: 1; font-weight: 800; }
.topbar .sub { color: var(--muted); font-size: 13px; font-weight: 500; display: block; letter-spacing: 0; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); flex: none; }

.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  padding: 8px 12px calc(8px + var(--safe-b)); background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--border); }
.nav-inner { display: flex; gap: 4px; width: 100%; max-width: 520px; }
.nav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 4px; border-radius: 14px;
  color: var(--muted); font-size: 11.5px; font-weight: 600; position: relative; }
.nav button svg { width: 24px; height: 24px; }
.nav button.active { color: var(--text); background: var(--surface-3); }
.nav button.active svg { color: var(--accent); }
.nav .live { position: absolute; top: 6px; right: calc(50% - 20px); width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--surface); }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 22px 4px 10px; display: flex; align-items: center; gap: 8px; }
.section-title .count { background: var(--surface-3); color: var(--text); border-radius: 99px; padding: 1px 8px; font-size: 12px; letter-spacing: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.center { text-align: center; }
.stack > * + * { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 14px;
  background: var(--surface-3); color: var(--text); font-weight: 700; font-size: 15px; transition: transform .08s ease, opacity .15s; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { background: rgba(255, 100, 100, .14); color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn.xs { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); flex: none; }
.icon-btn svg { width: 22px; height: 22px; }

.field { display: block; }
.field > span { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin: 0 2px 6px; }
.input { width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); outline: none; font-size: 16px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 160px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; color: var(--faint); }
.search .input { padding-left: 44px; }

.seg { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 42px; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--muted); padding: 0 8px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 0 var(--border), 0 4px 12px rgba(0,0,0,.15); }
.seg button.on.m { color: var(--m); }
.seg button.on.f { color: var(--f); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 700; font-size: 14px; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

.cat-picker { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cat-picker button { min-height: 52px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); font-weight: 800; font-size: 17px; color: var(--muted); }
.cat-picker button.on { color: #10140a; border-color: transparent; background: var(--c); }

.cat { --c: var(--faint); display: inline-flex; align-items: center; justify-content: center; min-width: 34px; height: 24px; padding: 0 7px; border-radius: 8px; font-weight: 800; font-size: 13px;
  color: var(--c); background: color-mix(in srgb, var(--c) 16%, transparent); border: 1px solid color-mix(in srgb, var(--c) 35%, transparent); white-space: nowrap; }
.cat.lg { height: 30px; min-width: 42px; font-size: 15px; border-radius: 10px; }
[data-cat="A+"] { --c: #ffd24d; } [data-cat="A"] { --c: #ffa94d; } [data-cat="B+"] { --c: #9be15d; } [data-cat="B"] { --c: #3ddc97; }
[data-cat="C+"] { --c: #4cc9f0; } [data-cat="C"] { --c: #5f8bff; } [data-cat="D"] { --c: #a3adc2; }
.shift { font-size: 11px; font-weight: 800; margin-left: 3px; }
.shift.up { color: var(--ok); } .shift.down { color: var(--danger); }

.avatar { width: 42px; height: 42px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; flex: none; }
.avatar.M { background: var(--m-soft); color: var(--m); }
.avatar.F { background: var(--f-soft); color: var(--f); }
.g-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.g-dot.M { background: var(--m); } .g-dot.F { background: var(--f); }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; min-height: 64px; }
.item + .item { border-top: 1px solid var(--border); }
.item:active { background: var(--surface-2); }
.item .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.item .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }

.bal { width: 64px; height: 6px; border-radius: 6px; background: var(--surface-3); position: relative; overflow: hidden; }
.bal i { position: absolute; top: 0; bottom: 0; }
.bal i.pos { left: 50%; background: var(--ok); }
.bal i.neg { right: 50%; background: var(--danger); }
.bal::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--faint); }

.check { width: 26px; height: 26px; border-radius: 9px; border: 2px solid var(--border); flex: none; display: inline-flex; align-items: center; justify-content: center; }
.check svg { width: 16px; height: 16px; opacity: 0; color: var(--accent-ink); }
.on > .check, .check.on { background: var(--accent); border-color: var(--accent); }
.on > .check svg, .check.on svg { opacity: 1; }

.fab { position: fixed; right: max(16px, calc(50% - 364px)); bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 25; width: 60px; height: 60px; border-radius: 20px;
  background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow); }
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.94); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.empty h3 { color: var(--text); margin: 0 0 6px; font-size: 19px; }

/* ---------- evento ---------- */
.hero { background: radial-gradient(120% 140% at 100% 0%, var(--accent-soft), transparent 60%), var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 18px; }
.hero h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 10px 8px; text-align: center; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper b { min-width: 34px; text-align: center; font-size: 20px; font-variant-numeric: tabular-nums; }
.stepper button { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-3); font-size: 22px; font-weight: 700; }
.setting-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-row .label { flex: 1; font-weight: 600; }
.setting-row .label small { display: block; color: var(--muted); font-weight: 500; font-size: 12.5px; margin-top: 1px; }

.round-head { display: flex; align-items: center; gap: 10px; margin: 18px 2px 12px; }
.round-head h2 { margin: 0; font-size: 20px; flex: 1; }
.timer { font-variant-numeric: tabular-nums; font-weight: 800; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 6px 10px; font-size: 15px; }
.timer.over { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }

.courts { display: grid; gap: 12px; }
@media (min-width: 700px) { .courts { grid-template-columns: 1fr 1fr; } }
.court { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 12px; position: relative; overflow: hidden; }
.court::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--t, var(--m)); }
.court.F { --t: var(--f); } .court.X { --t: var(--x); } .court.M { --t: var(--m); }
.court.done { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.court-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 10px 8px; }
.court-head .num { font-weight: 800; font-size: 15px; }
.type { font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 8px; color: var(--t); background: color-mix(in srgb, var(--t) 15%, transparent); }
.court-head .rep { font-size: 11.5px; color: var(--warn); font-weight: 700; margin-left: auto; }
.teams { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: stretch; }
.team { background: var(--surface-2); border: 2px solid transparent; border-radius: 14px; padding: 10px; text-align: left; display: flex; flex-direction: column; gap: 8px; min-height: 92px; position: relative; transition: background .15s, border-color .15s, opacity .15s; }
.team .p { display: flex; align-items: center; gap: 7px; min-width: 0; }
.team .p .n { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.team.win { background: var(--accent-soft); border-color: var(--accent); }
.team.lose { opacity: .5; }
.team .trophy { position: absolute; top: -9px; right: -6px; background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; font-weight: 900; padding: 2px 8px; letter-spacing: .04em; }
.vs { align-self: center; font-size: 12px; font-weight: 900; color: var(--faint); }
.hint { font-size: 12px; color: var(--faint); text-align: center; margin-top: 8px; }
.resting { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 5px 10px 5px 8px; font-size: 13.5px; font-weight: 600; }
.warning { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); border-radius: 14px; padding: 10px 12px; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.actions .btn { flex: 1; }
.finish-link { display: block; margin: 26px auto 0; color: var(--muted); font-size: 13px; font-weight: 700; padding: 8px 14px; border: 1px dashed var(--border); border-radius: 10px; }

.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 8px 6px; }
.table td { padding: 10px 6px; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.table td.n { font-weight: 700; }
.table .num { text-align: center; width: 44px; }
.tag-up { color: var(--ok); font-weight: 800; } .tag-down { color: var(--danger); font-weight: 800; }

.old-round { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; margin-top: 10px; overflow: hidden; }
.old-round summary { list-style: none; padding: 12px 14px; font-weight: 700; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.old-round summary::-webkit-details-marker { display: none; }
.old-round .body { padding: 0 12px 12px; }
.mini-match { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; font-size: 13.5px; padding: 8px 0; border-top: 1px solid var(--border); align-items: center; }
.mini-match button { text-align: left; padding: 6px 8px; border-radius: 10px; background: var(--surface-2); font-weight: 600; }
.mini-match button.win { background: var(--accent-soft); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--accent); }

/* ---------- sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 50; animation: fade .18s ease; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 92dvh; overflow-y: auto; background: var(--surface); border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(22px + var(--safe-b)); box-shadow: var(--shadow); animation: up .22s cubic-bezier(.2, .9, .3, 1); max-width: 640px; margin: 0 auto; border: 1px solid var(--border); border-bottom: 0; }
.sheet .grab { width: 44px; height: 5px; border-radius: 5px; background: var(--surface-3); margin: 0 auto 14px; }
.sheet h3 { margin: 0 0 16px; font-size: 21px; }
.sheet .stack > * + * { margin-top: 16px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 90px); transform: translateX(-50%) translateY(20px); z-index: 80; background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 14px; font-weight: 700; font-size: 14.5px; opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); color: #fff; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 380px; }
.login .logo { width: 76px; height: 76px; border-radius: 24px; margin: 0 auto 18px; display: block; }
.login h1 { text-align: center; margin: 0 0 4px; font-size: 28px; letter-spacing: -.02em; }
.login p { text-align: center; color: var(--muted); margin: 0 0 24px; }
.err-msg { color: var(--danger); font-weight: 600; font-size: 14px; min-height: 20px; margin-top: 8px; text-align: center; }

.boot { min-height: 100dvh; display: flex; align-items: center; justify-content: center; }
.ball { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); animation: bounce .7s cubic-bezier(.3, 0, .7, 1) infinite alternate; }
@keyframes bounce { from { transform: translateY(-24px); } to { transform: translateY(12px) scaleY(.9); } }

.summary-list .item { min-height: 56px; }
.change { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 13px; }

.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.item .meta { min-width: 0; }
.bal { width: 42px; }

.item-icon { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; flex: none; }
.item-icon svg { width: 21px; height: 21px; }
.item-icon.warn { color: var(--warn); } .item-icon.danger { color: var(--danger); }
.item svg { max-width: 24px; max-height: 24px; }
a.item { text-decoration: none; }
.status { font-size: 12px; font-weight: 800; padding: 3px 9px; border-radius: 99px; background: var(--surface-3); color: var(--muted); flex: none; }
.status.in { background: var(--accent-soft); color: var(--text); }
.status.out { background: rgba(255, 100, 100, .14); color: var(--danger); }
.btn.xs svg { width: 15px; height: 15px; }
.warning .btn { background: var(--surface); color: var(--text); flex: none; }
