:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --ink: #15241f;
  --muted: #5d6f68;
  --green: #0b3d2e;
  --green2: #15663f;
  --accent: #e8b94a;
  --accent-ink: #3d2e07;
  --line: #e2e8e5;
  --red: #b3372f;
  --nav-bg: #ffffff;
  --input-bg: #fafcfb;
  --chip-bg: #eef4f1;
  --me-row: #fdf6e3;
  --tt-bg: #f0f4f2;
  --sec-btn: #eef1f0;
  --hit-bg: #e3f2e9;
  --hit-line: #bcdcc9;
  --hit-ink: #15663f;
  --toast-bg: #15241f;
  --toast-ink: #ffffff;
  --radius: 14px;
}
:root[data-theme="dark"] {
  --bg: #0f1512;
  --card: #1a231e;
  --ink: #e8efe9;
  --muted: #9ab0a4;
  --green: #0b3d2e;
  --green2: #37b878;
  --accent: #e0b54e;
  --accent-ink: #3d2e07;
  --line: #2b362f;
  --red: #e0705f;
  --nav-bg: #161e1a;
  --input-bg: #121a16;
  --chip-bg: #243029;
  --me-row: #34301a;
  --tt-bg: #243029;
  --sec-btn: #2a352f;
  --hit-bg: #1e3a2b;
  --hit-line: #2e5740;
  --hit-ink: #86d8ab;
  --toast-bg: #e8efe9;
  --toast-ink: #15241f;
}
* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
*::-webkit-scrollbar { width: 7px; height: 7px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }
html, body { margin: 0; padding: 0; }
html { touch-action: manipulation; }
body {
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background: var(--bg); color: var(--ink);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
.small { font-size: 12px; color: var(--muted); }

/* login */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0b3d2e, #15663f 60%, #0b3d2e); padding: 20px; }
.login-card { background: var(--card); border-radius: 20px; padding: 32px 26px; max-width: 360px; width: 100%;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login-card h1 { margin: 8px 0 10px; font-size: 26px; line-height: 1.15; }
.login-card p { color: var(--muted); font-size: 14px; }
.login-card .ball { font-size: 44px; }
#gbtn { display: flex; justify-content: center; margin-top: 18px; min-height: 44px; }
#login-err { color: var(--red); min-height: 1em; }
.iab { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; padding: 14px;
  background: var(--hit-bg); border: 1px solid var(--hit-line); border-radius: 12px; font-size: 14px; color: var(--ink); }
.iab .btn { margin-top: 4px; }

/* header */
header { position: sticky; top: 0; z-index: 20; background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: space-between; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top)); }
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 7px; }
.ic { vertical-align: -3px; flex-shrink: 0; }
.ball-svg { color: var(--green2); }
.mepill { position: relative; font-size: 13px; }
.mepill img { width: 26px; height: 26px; border-radius: 50%; }
.mebtn { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.25); color: #fff; border-radius: 999px;
  padding: 4px 10px 4px 5px; font-size: 13px; cursor: pointer; font-family: inherit; }
.memenu { position: absolute; right: 0; top: calc(100% + 8px); background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.25);
  min-width: 185px; overflow: hidden; z-index: 30; }
.memenu button { display: flex; align-items: center; gap: 9px; width: 100%; background: none; border: none;
  padding: 11px 14px; font-size: 14px; color: var(--ink); cursor: pointer; text-align: left; font-family: inherit; }
.memenu button:hover { background: var(--chip-bg); }

main { max-width: 760px; margin: 0 auto; padding: 12px; }

/* tabs */
nav#tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--nav-bg);
  border-top: 1px solid var(--line); display: flex; padding-bottom: env(safe-area-inset-bottom); }
nav#tabs button { flex: 1; background: none; border: none; padding: 8px 4px 6px; font-size: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); cursor: pointer; }
nav#tabs button span { font-size: 11px; }
nav#tabs button.active { color: var(--green2); font-weight: 700; }

/* round sections */
.round { margin-bottom: 14px; }
.round-head { display: flex; justify-content: space-between; align-items: center; background: var(--green);
  color: #fff; border-radius: var(--radius); padding: 10px 14px; cursor: pointer; user-select: none; }
.round-head .small { color: #cfe3d8; }
.round.closed .round-body { display: none; }
.round-body { padding-top: 8px; }

/* match card */
.match { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 8px; }
.match .when { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.match .when .live, .live { color: var(--red); font-weight: 700; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .45; } }
.teamrow { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.teamrow img.crest { width: 22px; height: 22px; object-fit: contain; }
.teamrow .crest-ph { width: 22px; text-align: center; }
.teamrow .tname { flex: 1; font-weight: 600; font-size: 15px; }
.teamrow .tname.tbd { color: var(--muted); font-weight: 400; font-size: 13px; }
.teamrow input { width: 52px; height: 38px; text-align: center; font-size: 17px; font-weight: 700;
  border: 2px solid var(--line); border-radius: 10px; background: var(--input-bg); color: var(--ink); }
.teamrow input:focus { border-color: var(--green2); outline: none; }
.teamrow .goals { width: 52px; text-align: center; font-size: 18px; font-weight: 800; }
.match-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; min-height: 22px; gap: 8px; flex-wrap: wrap; }
.match-foot .state { font-size: 12px; color: var(--muted); }
.match-foot .state.saved { color: var(--green2); font-weight: 600; }
.match-foot .state.err { color: var(--red); font-weight: 600; }
.badge { display: inline-block; background: var(--chip-bg); border: 1px solid var(--line); color: var(--muted);
  font-size: 11px; border-radius: 999px; padding: 2px 8px; margin-left: 4px; }
.badge.pt { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }
.badge.hit { background: var(--hit-bg); border-color: var(--hit-line); color: var(--hit-ink); }
.linkbtn { background: none; border: none; color: var(--green2); font-size: 13px; cursor: pointer;
  text-decoration: underline; padding: 0; }
.lock { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.match.gray { background: var(--bg); }
.match.gray .teamrow { opacity: .5; }
.match.gray .when { opacity: .65; }
.lockcenter { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0 2px; color: var(--muted); }
.lockcenter .countdown { font-size: 14px; }
.lockcenter .ltime { font-size: 12px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; }
.lockcenter .linkbtn { margin-top: 2px; }
.countdown { color: var(--red); font-weight: 700; font-variant-numeric: tabular-nums; }
.countdown.cd-open { color: var(--green2); font-weight: 600; }

/* leaderboard */
table.board { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--line); }
table.board th { background: var(--green); color: #fff; font-size: 12px; padding: 8px 6px; text-align: left; }
table.board td { padding: 8px 6px; border-top: 1px solid var(--line); font-size: 14px; }
table.board td.num, table.board th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.board tr.me td { background: var(--me-row); }
tr.prow { cursor: pointer; }
tr.prow:hover td { background: var(--chip-bg); }
.chevtd { color: var(--muted); font-size: 16px; width: 18px; text-align: right; }
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; margin: 10px 0; }
.stat { background: var(--chip-bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px;
  text-align: center; display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 18px; }
.stat span { font-size: 11px; color: var(--muted); }
.pname { display: flex; align-items: center; gap: 8px; }
.pname img { width: 24px; height: 24px; border-radius: 50%; }
.medal { font-size: 16px; }
h2.viewtitle { margin: 6px 2px 12px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
td.rk { font-weight: 700; }
td.rk1 { color: var(--accent); }
.boardnote { margin-top: 10px; }
table.rounds { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; margin-top: 16px; }
table.rounds th { background: var(--green2); color: #fff; font-size: 11px; padding: 6px 4px; }
table.rounds td { font-size: 12px; padding: 6px 4px; border-top: 1px solid var(--line); text-align: center; font-variant-numeric: tabular-nums; }
table.rounds td:first-child { text-align: left; font-weight: 600; }

/* matches view */
.mlist .match { cursor: pointer; }
.scoreline { font-weight: 800; font-size: 16px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(10,20,16,.55); z-index: 40; display: flex;
  align-items: flex-end; justify-content: center; }
@media (min-width: 600px) { .modal { align-items: center; } }
.modal-box { background: var(--card); color: var(--ink); width: 100%; max-width: 560px; max-height: 82vh; overflow: auto;
  border-radius: 18px 18px 0 0; padding: 16px; }
@media (min-width: 600px) { .modal-box { border-radius: 18px; } }
.modal-box h3 { margin: 2px 0 4px; }
.tiprow { display: flex; align-items: center; gap: 8px; padding: 7px 2px; border-top: 1px solid var(--line); font-size: 14px; }
.tiprow:first-of-type { border-top: none; }
.tiprow .tt { font-weight: 700; width: 46px; text-align: center; background: var(--tt-bg); border-radius: 8px; padding: 3px 0; }
.tiprow .nm { flex: 1; display: flex; align-items: center; gap: 7px; }
.tiprow img { width: 22px; height: 22px; border-radius: 50%; }
.closex { float: right; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }

/* settings */
.setrow { margin: 14px 0; }
.setrow label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.setrow input[type=text] { flex: 1; min-width: 0; padding: 10px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--input-bg); color: var(--ink); font-size: 15px; }
.setrow { margin: 16px 0; }
.setlist { display: flex; flex-direction: column; margin-top: 6px; }
.setitem { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 2px; border-top: 1px solid var(--line); }
.setitem:first-child { border-top: none; }
.setitem.col { flex-direction: column; align-items: stretch; gap: 10px; }
.setinfo { display: flex; flex-direction: column; gap: 2px; }
.setinfo b { font-size: 14px; }
.namectl { display: flex; gap: 8px; }
.namectl input { flex: 1; min-width: 0; padding: 10px 12px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--input-bg); color: var(--ink); font-size: 15px; }
.namectl input:focus { border-color: var(--green2); outline: none; }
.seg.seg-sm { width: 150px; flex-shrink: 0; }
.seg.seg-sm button { padding: 8px 0; }
.switch { position: relative; width: 47px; height: 27px; flex-shrink: 0; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .knob { position: absolute; inset: 0; background: var(--line); border-radius: 999px; cursor: pointer; transition: background .2s; }
.switch .knob::after { content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; background: #fff;
  border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + .knob { background: var(--green2); }
.switch input:checked + .knob::after { transform: translateX(20px); }
.switch input:disabled + .knob { opacity: .55; }
.setrow .arow { border: none; padding: 0; display: flex; gap: 8px; align-items: center; }
.joinrow { display: flex; gap: 8px; }
.joinrow input { flex: 1; min-width: 0; padding: 10px; border: 2px solid var(--line); border-radius: 10px;
  background: var(--input-bg); color: var(--ink); font-size: 14px; text-transform: uppercase; }
.grpline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 2px 2px 10px; }
.joincard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  max-width: 380px; margin: 36px auto; padding: 28px 22px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); }
.joincard h3 { margin: 4px 0 0; color: var(--ink); }
.joincard .joinrow { width: 100%; margin-top: 12px; }
.joinmini { max-width: 380px; margin: 18px auto 0; }
.setrow input[type=text]:focus { border-color: var(--green2); outline: none; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; padding: 9px 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; font-size: 13px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px; }
.seg button.active { background: var(--green2); border-color: var(--green2); color: #fff; font-weight: 700; }
.set-err { color: var(--red); font-size: 13px; min-height: 1.2em; margin-top: 6px; }
.setrow .btn { margin-top: 8px; }

/* torna */
.cupseg { margin-bottom: 12px; max-width: 340px; }
.groups { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 620px) { .groups { grid-template-columns: 1fr 1fr; } }
table.gtable { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; }
table.gtable th { background: var(--green); color: #fff; font-size: 11px; padding: 6px 4px; text-align: center; }
table.gtable th:first-child, table.gtable th:nth-child(2) { text-align: left; }
table.gtable td { font-size: 12px; padding: 5px 4px; border-top: 1px solid var(--line); text-align: center; font-variant-numeric: tabular-nums; }
table.gtable td.gteam { text-align: left; font-weight: 600; }
table.gtable td.gteam img { width: 18px; height: 18px; object-fit: contain; vertical-align: -4px; margin-right: 5px; }
table.gtable tr.adv td { background: var(--hit-bg); }
.bracket { display: flex; gap: 16px; overflow-x: auto; padding: 4px 2px 12px; align-items: stretch; scroll-snap-type: x proximity; }
.bracket .bcol { scroll-snap-align: start; }
.bcol { min-width: 220px; display: flex; flex-direction: column; gap: 8px; }
.bpairs { display: flex; flex-direction: column; justify-content: space-around; flex: 1; gap: 14px; }
.bpair { position: relative; display: flex; flex-direction: column; justify-content: space-around; gap: 10px; flex: 1; padding-right: 12px; }
.bpair:not(.bsolo)::after { content: ''; position: absolute; right: 0; top: 25%; bottom: 25%; width: 10px;
  border: 2px solid var(--line); border-left: none; border-radius: 0 10px 10px 0; }
.bcol + .bcol .bmatch::before { content: ''; position: absolute; left: -14px; top: 50%; width: 14px; height: 2px; background: var(--line); }
.btitle { font-weight: 700; font-size: 12px; color: var(--muted); text-align: center; background: var(--chip-bg);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; letter-spacing: .3px; text-transform: uppercase; }
.btitle.b3 { font-size: 10px; margin-bottom: 2px; background: none; border: none; padding: 2px; }
.bmatch { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 7px 9px; position: relative;
  box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.brow.bwin { background: var(--hit-bg); border-radius: 7px; margin: 0 -4px; padding-left: 4px; padding-right: 4px; }
.bmatch.final { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.bmatch.blive { border-color: var(--red); }
.bhead { font-size: 10px; color: var(--muted); margin-bottom: 3px; }
.brow { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 13px; }
.brow img { width: 16px; height: 16px; object-fit: contain; }
.brow .bph { width: 16px; display: inline-block; }
.brow .bname { flex: 1; }
.brow .bname.tbd { color: var(--muted); font-size: 11px; }
.brow .bsc { font-weight: 800; min-width: 18px; text-align: right; }
.brow.bwin .bname { font-weight: 800; }
.brow.bwin .bsc { color: var(--green2); }

/* admin */
.acard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.acard h3 { margin: 0 0 8px; font-size: 15px; }
.arow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.arow:first-of-type { border-top: none; }
.arow .grow { flex: 1; }
button.btn { background: var(--green2); color: #fff; border: none; border-radius: 10px; padding: 9px 14px;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: filter .15s, transform .05s; font-family: inherit; }
button.btn:hover { filter: brightness(1.08); }
button.btn:active { transform: scale(.97); }
button.btn.sec { background: var(--sec-btn); color: var(--ink); }
button.btn.danger { background: var(--red); }
select, .acard input[type=number], .acard input[type=text] { padding: 7px; border: 1px solid var(--line); border-radius: 9px; font-size: 14px;
  background: var(--input-bg); color: var(--ink); }
.acard input[type=text] { flex: 1; min-width: 120px; }
.acard select { width: 100%; min-width: 0; }
.acard .arow { width: 100%; }
.acard .arow input[type=number] { flex: 1; min-width: 56px; max-width: 110px; }
@media (max-width: 620px) {
  .acard .arow .btn { flex: 1 1 auto; }
  .acard .arow select { flex: 1 1 100%; }
}
.acard input[type=number] { width: 64px; }

/* toast */
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--toast-bg); color: var(--toast-ink);
  padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.3);
  max-width: 90vw; text-align: center; }
