:root {
  --felt: #0f4d3a;
  --felt-2: #13644b;
  --felt-ink: #e9f3ee;
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1d2420;
  --muted: #66706a;
  --line: #e3ded3;
  --win: #157a52;
  --win-bg: #e5f4ec;
  --gold: #c89a2b;
  --gold-bg: #fbf3dc;
  --danger: #b3322b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
body.admin { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Header */
.top { background: radial-gradient(120% 140% at 0% 0%, var(--felt-2), var(--felt)); color: var(--felt-ink); padding: calc(14px + env(safe-area-inset-top)) 16px 16px; }
.top-inner { max-width: 680px; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
.top h1 { font-size: 1.15rem; line-height: 1.2; margin: 0; font-weight: 750; letter-spacing: -.01em; }
.status { margin: 3px 0 0; font-size: .9rem; opacity: .85; }
.ball { flex: none; width: 40px; height: 40px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #555, #111 60%); display: grid; place-items: center; box-shadow: inset -3px -4px 6px rgba(0,0,0,.5); }
.ball span { background: #fff; color: #111; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .8rem; }

main { max-width: 680px; margin: 0 auto; padding: 14px 14px 8px; }
section { margin-bottom: 22px; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 8px 2px; font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; }
h2 small { text-transform: none; letter-spacing: 0; font-weight: 500; }
.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 18px; color: var(--muted); text-align: center; line-height: 1.45; }

/* Champion */
.champ { background: linear-gradient(135deg, #fff8e1, var(--gold-bg)); border: 1px solid #ecd9a0; border-radius: var(--radius); padding: 18px; text-align: center; box-shadow: var(--shadow); }
.champ-trophy { height: 170px; display: block; margin: 0 auto; filter: drop-shadow(0 6px 10px rgba(0,0,0,.18)); }
.champ .label { font-size: .75rem; text-transform: uppercase; letter-spacing: .1em; color: #8a6a14; font-weight: 700; margin-top: 6px; }
.champ .name { font-size: 1.4rem; font-weight: 800; margin-top: 2px; }
.champ .players { color: var(--muted); margin-top: 2px; }

/* Match cards */
.matches { display: grid; gap: 10px; }
.match { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border: 1px solid transparent; }
.match.ready { border-color: #cfe3d8; }
.match-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px 0; font-size: .75rem; color: var(--muted); font-weight: 600; }
.pill { font-size: .7rem; padding: 2px 8px; border-radius: 99px; background: #eef1ee; color: var(--muted); font-weight: 700; }
.pill.live { background: var(--win-bg); color: var(--win); }
.side { display: flex; align-items: center; gap: 10px; padding: 9px 12px; width: 100%; text-align: left; background: none; border: 0; min-height: 52px; }
.side + .side { border-top: 1px solid var(--line); }
.side .t { flex: 1; min-width: 0; }
.side .n { font-weight: 650; font-size: 1rem; overflow-wrap: anywhere; }
.side .p { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.side .mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.side.win .mark { background: var(--win); color: #fff; }
.side.win .n { color: var(--win); }
.side.lose { opacity: .45; }
.side.lose .n { text-decoration: line-through; }
.side.tbd .n { color: var(--muted); font-weight: 500; font-style: italic; }
.vs { display: none; }
button.side { cursor: pointer; }
button.side:active { background: var(--win-bg); }
.bye { padding: 10px 12px; display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.bye .p { color: var(--muted); font-size: .82rem; }

/* Teams */
.teams { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.team-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.team-row + .team-row { border-top: 1px solid var(--line); }
.team-row .t { flex: 1; min-width: 0; }
.team-row .n { font-weight: 600; overflow-wrap: anywhere; }
.team-row .p { font-size: .82rem; color: var(--muted); }
.tag { font-size: .72rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; white-space: nowrap; }
.tag.alive { background: var(--win-bg); color: var(--win); }
.tag.out { background: #f0eeea; color: var(--muted); }
.tag.champ-tag { background: var(--gold-bg); color: #8a6a14; }

/* Footer */
.foot { max-width: 680px; margin: 0 auto; padding: 4px 14px 28px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.link { background: none; border: 0; color: var(--muted); font-size: .82rem; padding: 8px 2px; cursor: pointer; text-align: left; }
.live { display: inline-flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #2fb67c; box-shadow: 0 0 0 0 rgba(47,182,124,.6); animation: pulse 2s infinite; flex: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(47,182,124,0); } 100% { box-shadow: 0 0 0 0 rgba(47,182,124,0); } }
.admin-link { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 8px 14px; font-size: .85rem; font-weight: 650; cursor: pointer; }

/* Admin bar */
.admin-bar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--line); display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); z-index: 10; justify-content: center; }
.admin-bar button, .btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 14px; font-weight: 650; font-size: .92rem; cursor: pointer; }
.admin-bar button { flex: 1; max-width: 220px; white-space: nowrap; padding: 11px 10px; }
.primary { background: var(--felt) !important; color: #fff !important; border-color: var(--felt) !important; }
.ghost { color: var(--muted) !important; flex: 0 0 auto !important; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }

/* Sheet (dialog) */
.sheet { border: 0; padding: 0; width: 100%; max-width: 680px; max-height: 92vh; margin: auto auto 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--ink); }
.sheet::backdrop { background: rgba(10,20,15,.45); }
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet-head { position: sticky; top: 0; background: var(--bg); display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); z-index: 1; }
.sheet-head h3 { margin: 0; font-size: 1.05rem; }
.sheet-body { padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); }
.close { background: none; border: 0; font-size: 1.6rem; line-height: 1; padding: 0 4px; color: var(--muted); cursor: pointer; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: .8rem; font-weight: 650; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], textarea { width: 100%; font: inherit; font-size: 16px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
textarea { min-height: 110px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.box { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px; }
.box h4 { margin: 0 0 10px; font-size: .95rem; }
.box p.help { margin: -4px 0 10px; font-size: .82rem; color: var(--muted); line-height: 1.4; }
.edit-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: center; padding: 6px 0; }
.edit-row + .edit-row { border-top: 1px solid var(--line); }
.edit-row input { padding: 8px 9px; }
.edit-row .nick { grid-column: 1 / 3; }
.icon-btn { border: 0; background: #f1ede6; border-radius: 9px; width: 38px; height: 38px; cursor: pointer; font-size: 1rem; }
.err { color: var(--danger); font-size: .85rem; margin: 8px 0 0; }
.review-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; }
.review-item + .review-item { border-top: 1px solid var(--line); }
.review-item input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--felt); }
.review-item .ev { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--felt); border-radius: 50%; animation: spin .8s linear infinite; margin: 18px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast { z-index: 60 !important; position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); background: #1d2420; color: #fff; padding: 11px 14px; border-radius: 12px; font-size: .9rem; display: flex; gap: 14px; align-items: center; z-index: 20; max-width: calc(100% - 24px); box-shadow: 0 6px 20px rgba(0,0,0,.25); }
body:not(.admin) .toast { bottom: calc(20px + env(safe-area-inset-bottom)); }
.toast button { background: none; border: 0; color: #9be3bf; font-weight: 700; cursor: pointer; padding: 0; }


/* Trophy */
.mini-trophy { flex: none; height: 58px; width: auto; margin: -6px 0 -8px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.hero { display: flex; align-items: center; gap: 14px; background: radial-gradient(120% 140% at 100% 0%, var(--felt-2), var(--felt)); color: var(--felt-ink); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); overflow: hidden; }
.hero img { height: 116px; width: auto; flex: none; filter: drop-shadow(0 4px 6px rgba(0,0,0,.35)); }
.hero.compact { padding: 8px 14px; }
.hero.compact img { height: 76px; }
.hero.compact .hero-name { font-size: 1.15rem; }
.hero-kicker { font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; opacity: .75; font-weight: 700; }
.hero-name { font-size: 1.35rem; font-weight: 800; letter-spacing: -.01em; margin: 2px 0 4px; color: #fff; }
.hero-sub { font-size: .9rem; opacity: .85; line-height: 1.35; }

/* Admin: winner buttons */
.admin-tip { margin: -2px 2px 10px; font-size: .85rem; color: var(--muted); }
.won-btn { flex: none; border: 1.5px solid var(--win); color: var(--win); background: #fff; border-radius: 99px; padding: 6px 14px; font-size: .85rem; font-weight: 750; }
button.side.pick { cursor: pointer; }
button.side.pick:active .won-btn, button.side.pick:hover .won-btn { background: var(--win); color: #fff; }
.side .mark { background: var(--win); color: #fff; }
.side:not(.win) .mark { display: none; }

/* Bracket viewer */
.bracket-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.bracket-bar h2 { margin: 0 0 0 2px; }
.btn.small { padding: 7px 12px; font-size: .85rem; border-radius: 99px; }
.rounds-nav { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.rounds-nav::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 8px 14px; font-size: .85rem; font-weight: 650; cursor: pointer; }
.chip.on { background: var(--felt); color: #fff; border-color: var(--felt); }
.bv-wrap { position: relative; }
.bv { height: min(62vh, 540px); overflow: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--line); background-color: #ebe6da; background-image: radial-gradient(#d6cfbf 1px, transparent 1px); background-size: 18px 18px; cursor: grab; }
.bv:active { cursor: grabbing; }
.tree-sizer { position: relative; }
.tree { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.tree-lines { position: absolute; left: 0; top: 0; overflow: visible; }
.ln { fill: none; stroke: #c4bcab; stroke-width: 2; }
.ln.lit { stroke: var(--win); }
.tree-head { position: absolute; top: 10px; text-align: center; font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.tm { position: absolute; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 0; text-align: left; font: inherit; color: inherit; }
button.tm { cursor: pointer; }
button.tm:active { transform: scale(.98); }
.tm.ready { border: 2px solid var(--win); box-shadow: 0 0 0 4px rgba(21,122,82,.12), var(--shadow); }
.tm.waiting { background: #faf8f3; }
.tr { flex: 1; display: flex; align-items: center; gap: 6px; padding: 0 10px; min-width: 0; }
.tr + .tr { border-top: 1px solid var(--line); }
.tn { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; font-weight: 600; }
.tr.win .tn { color: var(--win); font-weight: 800; }
.tw { color: var(--win); font-weight: 900; }
.tr.lose .tn { color: var(--muted); text-decoration: line-through; font-weight: 500; }
.tr.tbd .tn { color: #9a9f99; font-style: italic; font-weight: 500; }
.tm-live { position: absolute; top: -10px; right: 8px; background: var(--win); color: #fff; font-size: .62rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 99px; }
.tm.bye { flex-direction: row; align-items: center; padding: 0 10px; background: transparent; border-style: dashed; box-shadow: none; }
.tm.bye .tn { color: var(--ink); }
.byetag { font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.zoom-ctl { position: absolute; right: 10px; bottom: 10px; display: flex; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 99px; box-shadow: 0 4px 14px rgba(0,0,0,.14); overflow: hidden; }
.zoom-ctl button { border: 0; background: none; min-width: 46px; height: 44px; font-size: 1.3rem; font-weight: 600; cursor: pointer; color: var(--ink); }
.zoom-ctl button + button { border-left: 1px solid var(--line); }
.zoom-ctl #zoomPct { font-size: .78rem; font-weight: 750; min-width: 56px; color: var(--muted); }
.bv-hint { font-size: .78rem; color: var(--muted); margin: 8px 2px 0; text-align: center; }

/* Full-screen bracket */
.bracket-section.full { position: fixed; inset: 0; z-index: 40; margin: 0; background: var(--bg); padding: calc(10px + env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; }
.bracket-section.full .bv-wrap { flex: 1; min-height: 0; }
.bracket-section.full .bv { height: 100%; }
.bracket-section.full .btn.small { background: var(--felt); color: #fff; border-color: var(--felt); }
body.no-scroll { overflow: hidden; }
@media (min-width: 760px) {
  .bracket-section:not(.full) { margin-inline: calc(50% - min(560px, 50vw - 16px)); }
  .bv { height: min(70vh, 640px); }
}

/* Match sheet */
.pick-list { display: grid; gap: 10px; }
.pick-big { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left; background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius); padding: 14px; min-height: 64px; cursor: pointer; }
.pick-big .n { display: block; font-weight: 700; font-size: 1.05rem; }
.pick-big .p { display: block; font-size: .85rem; color: var(--muted); }
.pick-big.on { border-color: var(--win); background: var(--win-bg); }
.pick-big.on .won-btn, .pick-big:active .won-btn { background: var(--win); color: #fff; }
