:root {
  --bg: #0b0b0c; --surface: #151518; --surface2: #1e1e23; --line: #2a2a31;
  --text: #f4f4f5; --muted: #9b9ba5; --faint: #5f5f69;
  --gold: #ffd60a; --gold-ink: #111; --gold-dim: rgba(255, 214, 10, .14);
  --live: #ff4d4f; --good: #37d67a;
  --r: 14px; --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea { background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
textarea { resize: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

#app { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-t) + 0px) 0 calc(84px + var(--safe-b)); }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-t)) var(--pad) 10px; background: rgba(11, 11, 12, .92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top .party { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; min-width: 0; }
.top .party span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--gold); color: var(--gold-ink); display: grid; place-items: center; font-weight: 900; font-size: 15px; flex: none; }
.top .spacer { flex: 1; }
.iconbtn { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); flex: none; }
.iconbtn:active { background: var(--surface2); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; justify-content: center; background: rgba(15, 15, 17, .96); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; max-width: 180px; padding: 9px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--faint); font-size: 12px; font-weight: 600; }
.tabs button.on { color: var(--gold); }
.tabs svg { width: 24px; height: 24px; }

.page { padding: var(--pad); display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: var(--pad); }
.card h2 { font-size: 15px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .grow { flex: 1; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.wrap { display: flex; flex-wrap: wrap; gap: 8px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--line); font-weight: 650; }
.btn:active { transform: scale(.98); }
.btn.gold { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }
.btn.big { min-height: 58px; font-size: 18px; width: 100%; }
.btn.wide { width: 100%; }
.btn.danger { color: #ff8a8a; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .4; }
.link { color: var(--gold); font-weight: 600; font-size: 14px; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--line); font-weight: 550; font-size: 15px; }
.chip.on { background: var(--gold-dim); border-color: var(--gold); color: var(--gold); }
.chip .tag { color: var(--faint); font-size: 12px; }
.chip.out { opacity: .4; text-decoration: line-through; }

.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); text-align: left; width: 100%; }
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--faint); flex: none; }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.seg { display: flex; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--gold); color: var(--gold-ink); }

.toggle { display: flex; align-items: center; gap: 12px; padding: 10px 0; width: 100%; text-align: left; }
.toggle .grow { flex: 1; }
.sw { width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle.on .sw { background: var(--gold); }
.toggle.on .sw::after { left: 21px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--line); font-size: 20px; font-weight: 700; }
.stepper b { min-width: 34px; text-align: center; font-size: 18px; }

/* up next */
.next { border-color: var(--gold); background: linear-gradient(180deg, var(--gold-dim), transparent 70%), var(--surface); }
.next h2 { color: var(--gold); }
.match { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--line); text-align: left; }
.match + .match { margin-top: 8px; }
.match .vs { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.match .vs .n { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .vs .v { color: var(--faint); font-size: 12px; font-weight: 700; letter-spacing: .1em; }
.match .meta { color: var(--muted); font-size: 12px; text-align: right; flex: none; }
.livedot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 rgba(255, 77, 79, .6); animation: pulse 1.6s infinite; vertical-align: middle; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(255, 77, 79, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0); } }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 3px 7px; border-radius: 6px; background: var(--surface2); color: var(--muted); }
.pill.live { background: rgba(255, 77, 79, .15); color: var(--live); }
.pill.gold { background: var(--gold-dim); color: var(--gold); }

.champ { text-align: center; padding: 22px 16px; border-color: var(--gold); background: radial-gradient(circle at 50% 0, rgba(255, 214, 10, .25), transparent 70%), var(--surface); }
.champ .cup { font-size: 40px; line-height: 1; }
.champ .who { font-size: 26px; font-weight: 800; color: var(--gold); margin-top: 6px; }

/* bracket */
.bsect { margin-top: 4px; }
.bsect h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 6px 0 10px; }
.bracket { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; scroll-snap-type: x proximity; margin: 0 calc(-1 * var(--pad)); padding-left: var(--pad); padding-right: var(--pad); }
.bcol { display: flex; flex-direction: column; min-width: 190px; max-width: 220px; flex: none; scroll-snap-align: start; }
.bcol .rh { font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 2px 8px; text-align: left; }
.bcol .games { display: flex; flex-direction: column; justify-content: space-around; flex: 1; gap: 10px; }
.gm { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.gm.st-ready { border-color: #4a4a55; }
.gm.st-live { border-color: var(--live); }
.gm.st-maybe, .gm.st-waiting { opacity: .75; }
.gm-h { display: flex; justify-content: space-between; align-items: center; font-size: 11px; font-weight: 700; color: var(--faint); padding: 6px 10px 2px; text-transform: uppercase; letter-spacing: .05em; }
.gm-r { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-weight: 600; font-size: 15px; }
.gm-r + .gm-r { border-top: 1px solid var(--line); }
.gm-r .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gm-r.tbd .nm { color: var(--faint); font-style: italic; font-weight: 500; font-size: 13px; }
.gm-r.win { color: var(--gold); }
.gm-r.lose { color: var(--faint); }
.gm-r b { font-variant-numeric: tabular-nums; }
.gm-r .ov { font-size: 11px; color: var(--gold); }

table.st { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.st th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); text-align: right; padding: 4px 6px; font-weight: 700; }
table.st th:nth-child(2) { text-align: left; }
table.st td { padding: 9px 6px; border-top: 1px solid var(--line); text-align: right; }
table.st td:nth-child(2) { text-align: left; font-weight: 650; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.st td:first-child { color: var(--faint); width: 26px; }
table.st tr.adv td:nth-child(2) { color: var(--gold); }
table.st tr.out td { opacity: .45; }
.gl { display: flex; align-items: center; gap: 8px; width: 100%; padding: 10px 0; border-top: 1px solid var(--line); text-align: left; font-size: 15px; }
.gl .a, .gl .b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.gl .b { text-align: right; }
.gl .sc { flex: none; min-width: 58px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.gl .win { color: var(--gold); }
.gl .lose { color: var(--faint); }
.rhd { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 2px; display: flex; gap: 8px; align-items: center; }

/* sheets */
.scrim { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-bottom: 0; border-radius: 20px 20px 0 0; padding: 8px var(--pad) calc(var(--pad) + var(--safe-b)); animation: up .2s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { font-size: 20px; margin-bottom: 4px; }
.sheet .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.scrim.still, .scrim.still .sheet { animation: none; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick button { min-height: 86px; border-radius: 14px; background: var(--surface2); border: 2px solid var(--line); padding: 10px; font-weight: 750; font-size: 17px; word-break: break-word; }
.pick button.on { border-color: var(--gold); background: var(--gold-dim); color: var(--gold); }
.pick .lab { display: block; font-size: 11px; color: var(--faint); font-weight: 700; letter-spacing: .08em; margin-bottom: 4px; }
.warnbox { background: rgba(255, 77, 79, .08); border: 1px solid rgba(255, 77, 79, .35); border-radius: 12px; padding: 12px; font-size: 14px; }

/* wizard */
.steps { display: flex; gap: 6px; }
.steps i { flex: 1; height: 4px; border-radius: 2px; background: var(--line); }
.steps i.on { background: var(--gold); }
.fmt { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 14px; border-radius: 14px; background: var(--surface2); border: 2px solid var(--line); }
.fmt + .fmt { margin-top: 8px; }
.fmt.on { border-color: var(--gold); background: var(--gold-dim); }
.fmt .ic { width: 42px; height: 42px; border-radius: 10px; background: var(--bg); display: grid; place-items: center; flex: none; color: var(--gold); }
.fmt .t { font-weight: 750; }
.fmt .s { color: var(--muted); font-size: 13px; }

/* hat + tools */
.hat { display: grid; place-items: center; text-align: center; min-height: 170px; border-radius: 16px; background: radial-gradient(circle at 50% 30%, rgba(255, 214, 10, .12), transparent 70%), var(--surface2); border: 1px solid var(--line); padding: 18px; }
.hat .drawn { font-size: 34px; font-weight: 850; color: var(--gold); word-break: break-word; animation: pop .35s cubic-bezier(.2, 1.6, .4, 1); }
.hat .drawn.many { font-size: 24px; line-height: 1.35; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.coin { width: 150px; height: 150px; margin: 6px auto; border-radius: 50%; display: grid; place-items: center; font-size: 26px; font-weight: 900; background: radial-gradient(circle at 35% 30%, #fff3b0, var(--gold) 55%, #b38f00); color: #3a2f00; box-shadow: 0 10px 30px rgba(255, 214, 10, .2); }
.coin.flip { animation: flip .9s ease-out; }
@keyframes flip { 0% { transform: rotateY(0) scale(1); } 50% { transform: rotateY(900deg) scale(1.15); } 100% { transform: rotateY(1800deg) scale(1); } }
.dice { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; min-height: 70px; }
.die { width: 64px; height: 64px; border-radius: 14px; background: #fff; color: #111; display: grid; place-items: center; font-size: 28px; font-weight: 900; }
.die.roll { animation: roll .5s ease-out; }
@keyframes roll { from { transform: rotate(-200deg) scale(.5); } }
.wheelbox { position: relative; width: min(300px, 80vw); aspect-ratio: 1; margin: 6px auto; }
.wheelbox canvas { width: 100%; height: 100%; transition: transform 4s cubic-bezier(.12, .8, .12, 1); }
.wheelbox .ptr { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 14px solid transparent; border-right: 14px solid transparent; border-top: 24px solid var(--gold); filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5)); }
.bigresult { text-align: center; font-size: 26px; font-weight: 850; color: var(--gold); min-height: 36px; }
.order li { padding: 8px 0; border-bottom: 1px solid var(--line); font-weight: 650; }
.order { margin: 0; padding-left: 26px; }
.team { background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.team .t { font-weight: 800; color: var(--gold); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 30; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 650; font-size: 14px; animation: up .2s; max-width: 90vw; }
.ffa-in { width: 88px; text-align: right; padding: 8px 10px; }
.num { font-variant-numeric: tabular-nums; }
@media (min-width: 640px) { .pick button { min-height: 100px; } }
