:root {
  --bg: #faf7f2; --card: #ffffff; --ink: #1c1a17; --muted: #7a746b; --line: #ebe6dd; --soft: #f3efe8;
  --accent: #e84d4a; --ok: #38b875; --warn: #f7942e; --gold: #e6b422; --silver: #a8aab0; --bronze: #c5793b;
  --shadow: 0 1px 2px rgba(30,20,0,.06), 0 8px 24px -12px rgba(30,20,0,.18);
  --radius: 18px; --nav: 64px;
  --c0:#e84d4a; --c1:#4087f5; --c2:#38b875; --c3:#9e66ed; --c4:#f7942e; --c5:#29b5bd; --c6:#f06ba8; --c7:#e6c238;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#131316; --card:#1e1e23; --ink:#f2efe9; --muted:#9a958c; --line:#2c2c33; --soft:#26262c; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -14px rgba(0,0,0,.7); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; overscroll-behavior-y: none; }
h1, h2, h3, .display { font-family: "Bricolage Grotesque", -apple-system, system-ui, sans-serif; font-weight: 800; letter-spacing: -.02em; margin: 0; }
h1 { font-size: 30px; line-height: 1.1; } h2 { font-size: 20px; } h3 { font-size: 16px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; }
.hidden { display: none !important; }

#app { max-width: 600px; margin: 0 auto; padding: 12px 16px calc(var(--nav) + 24px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0 14px; }
.topbar .sub { color: var(--muted); font-size: 14px; }
.iconbtn { width: 42px; height: 42px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; font-size: 20px; }
.iconbtn.accent { background: var(--ink); color: var(--bg); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.flat { box-shadow: none; border: 1px solid var(--line); }
.card h2 { margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stack > * + * { margin-top: 10px; }
.sep { height: 1px; background: var(--line); margin: 12px 0; }

/* bottoni */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 999px; font-weight: 700; background: var(--ink); color: var(--bg); transition: transform .08s; }
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--soft); color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: #fde8e7; color: #b3261e; }
@media (prefers-color-scheme: dark) { .btn.danger { background: #3a1f1e; color: #ff8a80; } }
.btn.wide { width: 100%; }
.btn.sm { padding: 8px 14px; font-size: 14px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* chip */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; background: var(--soft); font-size: 14px; font-weight: 600; white-space: nowrap; }
.chip.on { background: var(--ink); color: var(--bg); }
.chip.color { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 3px solid transparent; }
.chip.color.on { border-color: var(--ink); }

/* input */
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); outline: none; }
.input:focus { border-color: var(--ink); }
.input.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; text-transform: uppercase; font-size: 18px; }
select.input { appearance: none; }
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); }

/* avatar con i badge attorno */
.avatar { position: relative; display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 800; flex: 0 0 auto; }
.avatar .pin { position: absolute; width: 52%; height: 52%; min-width: 24px; min-height: 24px; object-fit: contain; filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); }
.avatar .pin.p0 { top: -14%; right: -16%; } .avatar .pin.p1 { bottom: -14%; right: -16%; } .avatar .pin.p2 { bottom: -14%; left: -16%; } .avatar .pin.p3 { top: -14%; left: -16%; }
.avatar .pin.more { width: 34%; height: 34%; border-radius: 50%; background: var(--card); color: var(--ink); display: grid; place-items: center; font-size: 42%; font-weight: 800; box-shadow: var(--shadow); }
.avatar.first { box-shadow: 0 0 0 3px var(--card), 0 0 0 6px #d9a520; }
.md { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font: 800 11px/1 "Bricolage Grotesque", system-ui, sans-serif; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.35); flex: 0 0 auto; }
.md.g { background: linear-gradient(160deg, #f5cf4d, #c48f14); } .md.s { background: linear-gradient(160deg, #d9dce2, #8b8f97); } .md.b { background: linear-gradient(160deg, #dba26b, #96521f); }
.md.z { opacity: .22; } .md.onav { position: absolute; bottom: -5px; right: -6px; width: 18px; height: 18px; font-size: 10px; box-shadow: 0 0 0 2px var(--card); }
.nav button svg { width: 24px; height: 24px; } .iconbtn svg { width: 20px; height: 20px; }

/* classifica */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; align-items: end; padding: 22px 6px 6px; }
.podium .spot { text-align: center; }
.podium .spot .name { font-weight: 700; margin-top: 8px; font-size: 14px; }
.podium .spot .bar { margin: 8px auto 0; width: 100%; border-radius: 12px 12px 6px 6px; display: grid; place-items: center; font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 800; font-size: 22px; color: #fff; }
.podium .spot .bar { height: 30px; font-size: 15px; color: var(--muted); background: var(--soft); border-radius: 10px; margin-top: 10px; }
.podium .spot.first .bar { height: 42px; color: #fff; background: linear-gradient(160deg, #f5cf4d, #c48f14); }
.lb { display: flex; flex-direction: column; }
.lb .item { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-top: 1px solid var(--line); }
.lb .item:first-child { border-top: 0; }
.lb .rank { width: 22px; text-align: right; font-weight: 800; color: var(--muted); font-family: "Bricolage Grotesque", system-ui, sans-serif; }
.lb .item.zero { opacity: .5; }
.medals { display: flex; gap: 6px; }

/* serata */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(56,184,117,.25); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(56,184,117,.08); } }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--soft); }
.pill.live { background: #e3f7ec; color: #1d7a48; } @media (prefers-color-scheme: dark) { .pill.live { background: #173627; color: #7ee2a8; } }
.table-wrap { width: min(100%, 320px); margin: 4px auto; }
.table-wrap svg { width: 100%; height: auto; display: block; }
.table-wrap text { font: 600 12px -apple-system, system-ui, sans-serif; fill: var(--ink); }
.table-wrap .seat-n { font: 800 12px "Bricolage Grotesque", system-ui, sans-serif; fill: #fff; }
.mymatch { text-align: center; padding: 18px 12px; }
.mymatch .vs { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .1em; }
.mymatch .names { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.mymatch .who { display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 700; }
.match { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.match:first-child { border-top: 0; }
.match .p { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 600; }
.match .p.r { justify-content: flex-end; text-align: right; }
.match .p.won { font-weight: 800; }
.match .score { font-family: "Bricolage Grotesque", system-ui, sans-serif; font-weight: 800; font-size: 18px; padding: 4px 10px; border-radius: 10px; background: var(--soft); min-width: 54px; text-align: center; }
.match .score.pending { color: var(--muted); font-weight: 600; font-size: 14px; }
.scores { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; padding-top: 6px; }
.scores button { padding: 8px 0; border-radius: 9px; background: var(--soft); font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.scores button.on { background: var(--ink); color: var(--bg); }
.standings { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.standings th { text-align: right; font-size: 11px; color: var(--muted); font-weight: 700; padding: 4px 4px; }
.standings th:nth-child(2), .standings td:nth-child(2) { text-align: left; }
.standings td { padding: 7px 4px; border-top: 1px solid var(--line); text-align: right; }
.standings td.pts { font-weight: 800; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* badge grid */
.badges { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.badge { text-align: center; padding: 12px 6px; border-radius: 14px; background: var(--soft); }
.badge .e { width: 60px; height: 60px; object-fit: contain; filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
.badge .n { font-weight: 700; font-size: 13px; margin-top: 4px; }
.badge .d { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.25; }
.badge.locked { opacity: .38; filter: grayscale(1); }

/* draft list */
.draft { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.draft:first-child { border-top: 0; }
.draft .pod { display: flex; gap: 4px; }
.draft .pod .avatar { box-shadow: 0 0 0 2px var(--card); }

/* nav */
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-top: 1px solid var(--line); display: flex; justify-content: center; z-index: 10; }
.nav .inner { width: 100%; max-width: 600px; display: grid; grid-template-columns: repeat(4, 1fr); }
.nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted); height: var(--nav); position: relative; }
.nav button .i { font-size: 22px; line-height: 1; }
.nav button.on { color: var(--ink); }
.nav button .dot { position: absolute; top: 12px; right: calc(50% - 18px); }

/* ingresso */
.hero { text-align: center; padding: 26px 0 10px; }
.hero img { width: 92px; height: 92px; border-radius: 26px; box-shadow: var(--shadow); }
.hero h1 { margin-top: 12px; font-size: 40px; }
.hero p { color: var(--muted); margin: 6px 0 0; }
.empty { text-align: center; padding: 30px 12px; color: var(--muted); }
.empty .e { font-size: 44px; margin-bottom: 8px; }
.empty h3 { color: var(--ink); margin-bottom: 4px; }

/* toast + dialog */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); z-index: 20; max-width: 90vw; text-align: center; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
dialog { border: 0; border-radius: 20px; padding: 20px; background: var(--card); color: var(--ink); width: min(92vw, 380px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin-bottom: 6px; }
dialog .actions { margin-top: 16px; justify-content: flex-end; }
.spin { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.member-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.member-row:first-child { border-top: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--soft); font-weight: 600; font-size: 14px; border: 2px solid transparent; }
.check.on { border-color: var(--ink); background: var(--card); }
