/* Web app screens. Builds on /assets/css/site.css tokens. */
body.app { min-height: 100dvh; }
.app-main { max-width: 860px; margin: 0 auto; padding: 16px 16px 140px; }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 10px; margin: 6px 0 18px; }
.topbar .title { min-width: 0; flex: 1; }
.topbar h1 { font-size: clamp(1.5rem, 4.6vw, 2.1rem); margin: 0; display: flex; align-items: center; gap: 8px; overflow: hidden; }
.topbar h1 span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tb-actions { display: flex; gap: 8px; }
.icon-btn { width: 50px; height: 50px; min-height: 0; padding: 0; border-radius: 16px; }
.icon-btn svg { width: 24px; height: 24px; }
@media (max-width: 520px) { .icon-btn { width: 44px; height: 44px; border-radius: 14px; } .tb-actions { gap: 6px; } .hide-sm { display: none !important; } }

/* Room list */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.room-card { display: flex; flex-direction: column; gap: 6px; padding: 18px; text-decoration: none; cursor: pointer; position: relative; transition: transform .12s; }
.room-card:hover { transform: translateY(-2px); }
.room-card .emoji { width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; font-size: 1.9rem; background: var(--sunken); border: 3px solid var(--ink); }
.room-card h3 { margin: 8px 0 0; font-size: 1.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-card .meta { color: var(--muted); font-weight: 600; font-size: .92rem; }
.room-card .del { position: absolute; top: 12px; right: 12px; }
.new-room { display: grid; place-items: center; min-height: 170px; border-style: dashed; background: transparent; box-shadow: none; font-weight: 800; color: var(--muted); font-size: 1.1rem; }
.new-room:hover { background: var(--surface); color: var(--text); }

.quick-tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 28px 0 10px; }
.quick-tools .btn { flex-direction: column; height: 92px; gap: 4px; font-size: .9rem; }
.quick-tools .btn span.e { font-size: 1.7rem; line-height: 1; }
@media (max-width: 560px) { .quick-tools { grid-template-columns: repeat(2, 1fr); } }

/* Player cards */
.players { display: grid; gap: 18px; }
.pcard { --c: #007AFF; position: relative; color: #fff; border-radius: 26px; padding: 16px 16px 14px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 80%, #fff) 0%, var(--c) 34%);
  border: 3px solid var(--ink); box-shadow: 0 7px 0 color-mix(in srgb, var(--c) 55%, #000);
  transition: transform .25s ease; }
.pcard.leader::after { content: "👑"; position: absolute; top: -16px; left: 22px; font-size: 1.5rem; transform: rotate(-12deg); }
.pcard.won { animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { to { box-shadow: 0 7px 0 color-mix(in srgb, var(--c) 55%, #000), 0 0 0 6px var(--primary); } }
.prow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto auto; align-items: center; gap: 12px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 1.45rem;
  background: color-mix(in srgb, var(--c) 68%, #000); border: 3px solid var(--ink); cursor: pointer; flex: none; }
.pname { font-weight: 800; font-size: 1.3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.pbadges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.pbadge { font-size: .78rem; font-weight: 800; padding: 0 8px; border-radius: 999px; background: color-mix(in srgb, var(--c) 60%, #000); border: 2px solid var(--ink); }
.pscore { font-weight: 800; font-size: clamp(2.3rem, 7vw, 3.2rem); line-height: 1; min-width: 2.4ch; text-align: center; cursor: pointer;
  -webkit-text-stroke: 3px color-mix(in srgb, var(--c) 50%, #000); paint-order: stroke fill; user-select: none; }
.pscore.bump { animation: bump .3s ease; }
@keyframes bump { 40% { transform: scale(1.22); } }
.sbtn { min-width: 58px; height: 58px; padding: 0 10px; border-radius: 18px; font: inherit; font-weight: 800; font-size: 1.3rem; color: #fff; cursor: pointer;
  background: color-mix(in srgb, var(--c) 70%, #fff); border: 3px solid var(--ink); box-shadow: 0 5px 0 var(--ink); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.sbtn:active { transform: translateY(5px); box-shadow: none; }
.sbtn[disabled] { opacity: .5; pointer-events: none; }
.qrow { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.qbtn { height: 42px; min-width: 64px; padding: 0 14px; border-radius: 999px; font: inherit; font-weight: 800; color: #fff; cursor: pointer;
  background: color-mix(in srgb, var(--c) 72%, #fff); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); touch-action: manipulation; }
.qbtn:active { transform: translateY(4px); box-shadow: none; }
.progress { height: 10px; margin-top: 12px; border-radius: 99px; background: color-mix(in srgb, var(--c) 55%, #000); border: 2px solid var(--ink); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s ease; }
@media (max-width: 520px) {
  .prow { grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "a n n" "m s p"; row-gap: 12px; }
  .prow .avatar { grid-area: a; width: 44px; height: 44px; font-size: 1.2rem; }
  .prow .pinfo { grid-area: n; }
  .prow .minus { grid-area: m; justify-self: start; }
  .prow .pscore { grid-area: s; }
  .prow .plus { grid-area: p; justify-self: end; }
  .sbtn { min-width: 64px; height: 56px; }
}

/* Bottom bar (like the app) */
.bottombar { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  width: min(820px, calc(100% - 24px)); display: grid; grid-template-columns: 1fr 1fr 88px 1fr 1fr; align-items: end;
  padding: 10px 8px 8px; background: var(--surface); border: 3px solid var(--ink); border-radius: 30px; box-shadow: 0 6px 0 var(--ink); }
.bb { display: flex; flex-direction: column; align-items: center; gap: 2px; background: none; border: 0; color: var(--text); font: inherit; font-weight: 800; font-size: .8rem; cursor: pointer; padding: 0; }
.bb .ic { width: 50px; height: 40px; display: grid; place-items: center; border-radius: 14px; background: var(--sunken); font-size: 1.3rem; }
.bb:active .ic { transform: scale(.92); }
.fab { justify-self: center; margin-top: -42px; width: 78px; height: 78px; border-radius: 50%; border: 4px solid var(--ink); background: var(--primary); color: var(--on-primary);
  box-shadow: 0 5px 0 var(--ink); font-size: 2rem; cursor: pointer; display: grid; place-items: center; }
.fab:active { transform: translateY(5px); box-shadow: none; }
.fab svg { width: 34px; height: 34px; }
.undo-fab { position: fixed; right: max(16px, calc(50% - 410px)); bottom: 128px; z-index: 39; }

/* Empty state */
.empty { text-align: center; padding: 40px 20px; }
.empty .big { font-size: 4rem; }
.empty p { color: var(--muted); }

/* Dialogs */
dialog.sheet { width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 40px); padding: 0; border: 3px solid var(--ink); border-radius: 28px;
  background: var(--bg); color: var(--text); box-shadow: 0 8px 0 var(--ink); overflow: hidden; }
dialog.sheet.wide { width: min(860px, calc(100% - 24px)); }
dialog.sheet::backdrop { background: rgba(20, 14, 50, .55); backdrop-filter: blur(3px); }
dialog.sheet[open] { animation: pop .22s ease; display: flex; flex-direction: column; }
@keyframes pop { from { transform: translateY(14px) scale(.97); opacity: 0; } }
.sheet-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 3px solid var(--ink); background: var(--surface); }
.sheet-head h2 { margin: 0; font-size: 1.4rem; flex: 1; }
.sheet-body { padding: 18px; overflow-y: auto; }
.sheet-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px; border-top: 3px solid var(--ink); background: var(--surface); flex-wrap: wrap; }

.field { margin-bottom: 18px; }
.field > label, .field-label { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: .8rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.field-label::before, .field > label::before { content: ""; width: 6px; height: 16px; border-radius: 3px; background: var(--primary); border: 2px solid var(--ink); }
.input, select.input { width: 100%; height: 52px; padding: 0 16px; font: inherit; font-weight: 700; font-size: 1.05rem; color: var(--text);
  background: var(--sunken); border: 3px solid var(--ink); border-radius: 16px; outline: none; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 40%, transparent); }
.hint { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.row { display: flex; gap: 12px; align-items: center; }
.row > * { flex: 1; }
.card-box { padding: 16px; border-radius: 20px; background: var(--surface); border: 3px solid var(--ink); }

.switch { position: relative; flex: none !important; width: 64px; height: 36px; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--sunken); border: 3px solid var(--ink); cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); transition: .2s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(28px); }
.switch input:focus-visible + span { outline: 3px solid var(--secondary); outline-offset: 2px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.toggle-row + .toggle-row { border-top: 2px dashed color-mix(in srgb, var(--ink) 15%, transparent); }
.toggle-row b { display: block; }
.toggle-row small { color: var(--muted); }

.sport-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.sport-opt { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 4px; border-radius: 16px; cursor: pointer;
  background: var(--sunken); border: 3px solid color-mix(in srgb, var(--ink) 25%, transparent); font: inherit; font-weight: 800; font-size: .82rem; color: var(--text); }
.sport-opt b { font-size: 1.6rem; line-height: 1.2; }
.sport-opt[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--ink); box-shadow: 0 4px 0 var(--ink); }
@media (max-width: 460px) { .sport-grid { grid-template-columns: repeat(3, 1fr); } }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { flex: 1; min-width: 90px; min-height: 44px; border-radius: 14px; font: inherit; font-weight: 800; cursor: pointer; color: var(--text);
  background: var(--sunken); border: 3px solid color-mix(in srgb, var(--ink) 25%, transparent); }
.seg button[aria-pressed="true"] { background: var(--secondary); color: #fff; border-color: var(--ink); }

.colors { display: flex; flex-wrap: wrap; gap: 10px; }
.colors button { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--ink); cursor: pointer; }
.colors button[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--ink); }

/* Pin pad (bowling) */
.pinpad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pinpad button { height: 62px; font-size: 1.5rem; }
.frames { display: grid; grid-template-columns: repeat(10, 1fr); border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; font-weight: 800; font-size: .8rem; margin-bottom: 16px; background: var(--surface); }
.frames div { border-right: 2px solid var(--ink); text-align: center; min-height: 52px; display: flex; flex-direction: column; }
.frames div:last-child { border-right: 0; }
.frames .mk { border-bottom: 2px solid var(--ink); padding: 2px; min-height: 22px; letter-spacing: .1em; }
.frames .tot { padding: 2px; flex: 1; display: grid; place-items: center; }
.frames .cur { background: color-mix(in srgb, var(--primary) 40%, transparent); }

/* Versus */
.versus { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: grid; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); }
.versus.n2 { grid-template-columns: 1fr 1fr; }
.versus.n3 { grid-template-columns: 1fr 1fr 1fr; }
.versus.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
@media (orientation: portrait) { .versus.n2, .versus.n3 { grid-template-columns: 1fr; grid-auto-rows: 1fr; } .versus.n4 { grid-template-columns: 1fr 1fr; } }
.vside { --c: #007AFF; position: relative; border-radius: 28px; color: #fff; border: 3px solid var(--ink); box-shadow: 0 6px 0 color-mix(in srgb, var(--c) 55%, #000);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 80%, #fff) 0%, var(--c) 30%); display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; user-select: none; touch-action: manipulation; overflow: hidden; -webkit-tap-highlight-color: transparent; }
.vside.flip { transform: rotate(180deg); }
.vside .vn { position: absolute; top: 14px; left: 20px; right: 20px; font-weight: 800; font-size: 1.4rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vside .vs { font-weight: 800; font-size: clamp(4rem, 16vmin, 11rem); line-height: 1; -webkit-text-stroke: 4px color-mix(in srgb, var(--c) 50%, #000); paint-order: stroke fill; }
.vside .vsub { font-weight: 800; opacity: .9; }
.vside .vminus { position: absolute; bottom: 16px; left: 16px; }
.vside .vtap { position: absolute; bottom: 22px; right: 22px; opacity: .8; font-weight: 800; font-size: .9rem; }
.vside:active { filter: brightness(1.08); }
.vctrl { position: fixed; z-index: 81; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; gap: 10px; }
@media (orientation: portrait) { .vctrl { flex-direction: row; } }

/* Celebration */
.celebrate { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; background: rgba(20, 14, 50, .6); padding: 20px; }
.celebrate .box { text-align: center; padding: 28px 24px; max-width: 420px; width: 100%; animation: pop .3s ease; }
.celebrate .trophy { font-size: 5rem; animation: bounce 1s ease infinite; }
@keyframes bounce { 50% { transform: translateY(-10px) rotate(-6deg); } }
.celebrate h2 { font-size: 2rem; margin: 6px 0; }
.celebrate .actions { display: grid; gap: 10px; margin-top: 18px; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 91; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 130px; transform: translateX(-50%); z-index: 100; padding: 10px 18px; border-radius: 16px;
  background: var(--ink); color: #fff; font-weight: 800; border: 3px solid var(--ink); animation: pop .2s ease; max-width: calc(100% - 40px); text-align: center; }
:root[data-theme="dark"] .toast { background: #fff; color: #23194A; }

/* Lists */
.list { display: grid; gap: 12px; }
.li { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 18px; background: var(--surface); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); }
.li .grow { flex: 1; min-width: 0; }
.li .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li small { color: var(--muted); font-weight: 600; }
.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); flex: none; display: inline-block; }
.stat-table { width: 100%; border-collapse: collapse; font-weight: 700; }
.stat-table th, .stat-table td { padding: 10px 8px; text-align: left; border-bottom: 2px solid var(--sunken); }
.stat-table td:nth-child(n+2), .stat-table th:nth-child(n+2) { text-align: right; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }

/* Wheel */
.wheel-wrap { position: relative; width: min(360px, 100%); aspect-ratio: 1; margin: 0 auto 16px; }
.wheel-wrap canvas { width: 100%; height: 100%; border-radius: 50%; border: 4px solid var(--ink); box-shadow: 0 6px 0 var(--ink); }
.wheel-wrap .pointer { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); width: 0; height: 0; border-left: 16px solid transparent; border-right: 16px solid transparent; border-top: 30px solid var(--danger); filter: drop-shadow(0 3px 0 var(--ink)); }
.wheel-result { text-align: center; font-weight: 800; font-size: 1.5rem; min-height: 2.2em; }

.teams-out { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-top: 14px; }
.team-box { padding: 12px; border-radius: 18px; border: 3px solid var(--ink); color: #fff; box-shadow: 0 4px 0 var(--ink); }
.team-box h4 { margin: 0 0 6px; }
.team-box ul { margin: 0; padding-left: 1.1em; font-weight: 700; }

.chart-svg { width: 100%; height: auto; background: var(--surface); border: 3px solid var(--ink); border-radius: 18px; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; font-weight: 700; font-size: .9rem; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.app-header-mini { display: flex; align-items: center; gap: 10px; padding: 12px 16px; max-width: 860px; margin: 0 auto; }
.app-header-mini .brand img { width: 36px; height: 36px; }
.app-header-mini .spacer { flex: 1; }
.clock-pill { cursor: pointer; }
.clock-pill.running { background: var(--success); color: #fff; }
.clock-pill.over { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

/* Tournaments */
.champ { display: flex; align-items: center; gap: 14px; padding: 16px 20px; margin-bottom: 20px; background: var(--primary); color: var(--on-primary); }
.champ span { font-size: 2.6rem; }
.champ small { display: block; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; }
.champ b { font-size: 1.6rem; }
.bracket { display: flex; gap: 22px; overflow-x: auto; padding: 4px 4px 24px; margin: 0 -4px; scroll-snap-type: x proximity; }
.bround { flex: 0 0 230px; display: flex; flex-direction: column; scroll-snap-align: start; }
.bround h3 { font-size: .85rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 12px; text-align: center; }
.bmatches { flex: 1; display: flex; flex-direction: column; justify-content: space-around; gap: 14px; }
.match { display: block; width: 100%; padding: 6px 0; font: inherit; color: var(--text); text-align: left; cursor: pointer; border-radius: 18px; box-shadow: 0 4px 0 var(--ink); }
.match.off { cursor: default; opacity: .75; box-shadow: none; border-style: dashed; }
.match:not(.off):hover { transform: translateY(-1px); }
.match:not(.off):not(.done) { outline: 3px solid color-mix(in srgb, var(--primary) 70%, transparent); outline-offset: 2px; }
.mrow { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 6px 14px; font-weight: 700; }
.mrow + .mrow { border-top: 2px dashed color-mix(in srgb, var(--ink) 15%, transparent); }
.mrow span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow b { font-size: 1.15rem; min-width: 1.6ch; text-align: right; }
.mrow.win span, .mrow.win b { font-weight: 800; color: var(--success); }
.mrow.tbd { color: var(--muted); font-style: italic; }
.mrow.tbd .dot { background: var(--sunken); }
.rr-matches { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.result-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; }
.rside { --c: #007AFF; text-align: center; padding: 14px 10px; border-radius: 20px; color: #fff; border: 3px solid var(--ink); box-shadow: 0 5px 0 color-mix(in srgb, var(--c) 55%, #000);
  background: linear-gradient(180deg, color-mix(in srgb, var(--c) 80%, #fff) 0%, var(--c) 40%); min-width: 0; }
.rside > b { display: block; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 10px; }
.rstep { display: flex; gap: 6px; align-items: center; justify-content: center; }
.rstep .sbtn { min-width: 44px; width: 44px; height: 48px; font-size: 1.3rem; }
.rstep .input { width: 70px; height: 56px; text-align: center; font-size: 1.6rem; padding: 0 4px; }
.vs-badge { font-weight: 800; font-size: 1.1rem; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); border: 3px solid var(--ink); }
@media (max-width: 520px) { .result-grid { grid-template-columns: 1fr; } .vs-badge { margin: 0 auto; } }
