:root {
  --bg: #120d2e; --panel: rgba(255,255,255,.06); --panel2: rgba(255,255,255,.045); --line: rgba(255,255,255,.1);
  --text: #fff; --muted: #a39fc4; --accent: #a78bfa; --hot: #ffd93d; --ok: #4ee38f; --bad: #ff5d73;
  --teal: #4ecdc4; --orange: #ff6b35; --blue: #5aa9ff;
  --c1: #ff6b35; --c2: #4ecdc4; --c3: #ffd93d; --c4: #a78bfa; --c5: #4ee38f; --c6: #5aa9ff; --c7: #ff5d9e;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
/* No pull-to-refresh or rubber-band bounce: a swipe during a game never reloads the page */
html, body { overscroll-behavior: none; }
/* Installed app (no browser bar): keep clear of the phone's notch and status bar */
@media (display-mode: standalone) { .app { padding-top: max(16px, env(safe-area-inset-top)); } }
/* Connection banner */
.netbar { position: fixed; left: 50%; top: calc(10px + env(safe-area-inset-top)); z-index: 60; transform: translate(-50%, -160%); padding: 9px 16px; border-radius: 999px;
  background: #ff5d73; color: #fff; font-size: .88em; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.4); transition: transform .25s; white-space: nowrap; }
.netbar.show { transform: translate(-50%, 0); }
.netbar.ok { background: #2fbf71; }
/* Install card */
.card.install { position: relative; }
.card.install .head { display: flex; gap: 12px; align-items: center; }
.card.install .head img { width: 52px; height: 52px; border-radius: 14px; flex: none; }
.card.install h2 { margin: 0; }
.inst-x { position: absolute; top: 8px; right: 10px; width: 32px; height: 32px; border: 0; border-radius: 10px; background: rgba(255,255,255,.08); color: var(--muted); font-size: 20px; cursor: pointer; }
html, body { height: 100%; }
body {
  font-family: 'Poppins', system-ui, sans-serif; color: var(--text); background: var(--bg);
  -webkit-user-select: none; user-select: none; touch-action: manipulation; overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
.app { max-width: 560px; min-height: 100%; margin: 0 auto; padding: 16px 16px 0; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; gap: 14px; padding-bottom: 16px; }
.screen.centered { justify-content: center; }
.ic { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }

/* Header */
.hdr { display: flex; align-items: center; gap: 12px; }
.hdr .logo { width: 48px; height: 48px; display: block; }
.hdr .home-link { display: block; border-radius: 14px; }
a.btn { text-decoration: none; }
.hdr .names { flex: 1; line-height: 1.05; }
.hdr .names b { font-size: 1.35em; font-weight: 800; }
.hdr .names b span, .brand-accent { color: var(--accent); }
.hdr .names small { display: block; font-size: .68em; color: var(--muted); letter-spacing: .5px; margin-top: 3px; }
.hdr .title { flex: 1; font-size: 1.5em; font-weight: 600; }
.chip-bal { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 999px; background: rgba(255,255,255,.07); border: 1px solid var(--line); color: var(--ok); font-size: .92em; font-weight: 500; }
.chip-bal .ic { width: 20px; height: 20px; color: var(--hot); }
.chip-bal .chip-sep { width: 1px; align-self: stretch; margin: 0 2px; background: var(--line); }
.chip-bal .chip-real { display: inline-flex; align-items: center; gap: 4px; color: var(--hot); }
.chip-bal .chip-real .ic { width: 16px; height: 16px; }
.back { width: 48px; height: 48px; border-radius: 15px; border: 1px solid var(--line); background: rgba(255,255,255,.08); display: grid; place-items: center; cursor: pointer; }
.back .ic { width: 22px; height: 22px; }
/* Game board header: back, music, balances only */
.hdr-game { gap: 8px; }
.hdr-game .back { width: 42px; height: 42px; border-radius: 13px; }
.hdr-game .hdr-fill { flex: 1; }
.mus .ic { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.mus.off { color: var(--muted); }
.screen.play { gap: 10px; }

/* Cards, rows, buttons */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
h1 { font-size: 2em; font-weight: 600; line-height: 1.15; }
h2 { font-size: 1.15em; font-weight: 500; }
.muted { color: var(--muted); }
.small { font-size: .82em; }
.label { font-size: .85em; color: var(--muted); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 0 18px; border-radius: 14px; border: 0; background: var(--accent); color: #fff; font-weight: 500; font-size: 1em; cursor: pointer; transition: filter .15s, transform .1s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn:disabled { background: rgba(255,255,255,.08); color: rgba(255,255,255,.4); cursor: default; }
.btn.ghost { background: transparent; border: 1px solid rgba(255,255,255,.2); }
.btn.green { background: #3aaa6b; }
.btn.block { width: 100%; }
.btn.big { min-height: 60px; }
.btn .ic { width: 22px; height: 22px; }
input.field { width: 100%; min-height: 52px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0,0,0,.3); -webkit-user-select: text; user-select: text; }
input.field:focus { outline: none; border-color: var(--accent); }
input.field[readonly] { color: #fff; }
select.field { width: 100%; min-height: 52px; padding: 0 44px 0 14px; border-radius: 12px; border: 1px solid var(--line); color: #fff; font: inherit; cursor: pointer;
  -webkit-appearance: none; appearance: none; text-overflow: ellipsis;
  background: rgba(0,0,0,.3) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23a78bfa' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 16px center; }
select.field:focus { outline: none; border-color: var(--accent); }
select.field option { background: #1a1440; color: #fff; }
/* Payment method dropdown with logos */
.mpick { position: relative; }
.mpick-btn { width: 100%; min-height: 56px; display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0,0,0,.3); color: #fff; font: inherit; text-align: left; cursor: pointer; }
.mpick-btn[aria-expanded="true"] { border-color: var(--accent); }
.mpick-cur { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.mpick-arrow { width: 14px; height: 9px; flex: none; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23a78bfa' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat center; }
.mpick-btn[aria-expanded="true"] .mpick-arrow { transform: rotate(180deg); }
.mpick-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 6px); max-height: 320px; overflow-y: auto; padding: 6px; border-radius: 14px; background: #1a1440; border: 1px solid var(--line); box-shadow: 0 14px 40px rgba(0,0,0,.5); }
.mpick-opt { width: 100%; display: flex; align-items: center; gap: 12px; padding: 9px 10px; border: 0; border-radius: 10px; background: transparent; color: #fff; font: inherit; text-align: left; cursor: pointer; }
.mpick-opt:hover, .mpick-opt.on { background: rgba(167,139,250,.18); }
.mlogo { width: 36px; height: 36px; flex: none; border-radius: 10px; overflow: hidden; display: grid; place-items: center; background: #fff; }
.mlogo img { width: 100%; height: 100%; object-fit: contain; }
.mlogo.badge { color: #fff; font-weight: 800; font-size: .92em; letter-spacing: .3px; }
.mtext { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.mtext b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mtext small { color: var(--muted); font-size: .8em; margin-top: 2px; }
.err { color: var(--bad); font-size: .9em; }
.err:empty { display: none; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 16px; background: var(--panel2); border: 1px solid rgba(255,255,255,.07); }
.row .txt { flex: 1; min-width: 0; }
.row .txt b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .txt small { display: block; color: var(--muted); font-size: .78em; }
.row .btn { min-height: 44px; }
.tile { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; flex: none; border: 1px solid; }
.tile .ic { width: 24px; height: 24px; }
.tag { font-size: .78em; padding: 4px 10px; border-radius: 10px; border: 1px solid; white-space: nowrap; }
.list { display: flex; flex-direction: column; gap: 9px; }

/* Home */
.wallet { background: #3a2c8c; border: 1px solid rgba(167,139,250,.55); border-radius: 22px; padding: 20px; box-shadow: 0 0 22px rgba(167,139,250,.25); display: flex; flex-direction: column; gap: 4px; }
.wallet .top { display: flex; justify-content: space-between; color: rgba(255,255,255,.75); }
.wallet .top .ic { color: rgba(255,255,255,.6); }
.wallet .amt { font-size: 2.6em; font-weight: 500; }
.wallet .real { display: flex; align-items: center; gap: 6px; color: rgba(255,255,255,.85); font-size: .92em; }
.wallet .real .ic { width: 20px; height: 20px; color: var(--hot); }
.wallet .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.game-card .head, .invite .head { display: flex; gap: 14px; align-items: center; }
.invite h2 { margin: 0; }
.game-card img { width: 88px; height: 88px; }
.game-card h2 { font-size: 1.5em; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mtile { text-align: left; min-height: 140px; padding: 16px; border-radius: 20px; background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.09); cursor: pointer; display: flex; flex-direction: column; gap: 4px; transition: background .15s, border-color .15s; }
.mtile:hover { background: color-mix(in srgb, var(--t) 12%, transparent); border-color: color-mix(in srgb, var(--t) 50%, transparent); }
.mtile .tile { margin-bottom: auto; }
.mtile b { font-weight: 500; font-size: 1.1em; margin-top: 12px; }
.mtile small { color: var(--muted); font-size: .78em; }
select.saga-lang { min-height: 48px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: #1d1846; width: 100%; cursor: pointer; }
.lang-row { display: flex; align-items: center; gap: 12px; }
.lang-row .label { white-space: nowrap; }

/* Bottom navigation */
.nav { position: sticky; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; padding: 6px; margin: 0 -2px calc(10px + env(safe-area-inset-bottom)); border-radius: 22px; background: #1a1440; border: 1px solid rgba(255,255,255,.08); z-index: 10; }
.nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; border-radius: 16px; background: transparent; color: var(--muted); font-size: .72em; cursor: pointer; }
.nav button .ic { width: 24px; height: 24px; }
.nav button.on { background: rgba(167,139,250,.16); color: var(--accent); }
.nav button:hover { color: #fff; }

/* Methods */
.method { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 14px 16px; border-radius: 16px; background: rgba(255,255,255,.05); border: 1px solid var(--line); cursor: pointer; }
.method .ic { width: 28px; height: 28px; }
.method b { display: block; font-weight: 500; }
.method small { color: #fff; opacity: .85; font-size: .82em; }
.method.on { background: rgba(167,139,250,.2); border-color: var(--accent); }
.copy { display: flex; gap: 8px; }
.copy .btn { width: 52px; padding: 0; flex: none; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tabs button { min-height: 44px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.06); cursor: pointer; font-size: .85em; }
.tabs button.on { background: var(--accent); border-color: transparent; }
.sum { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sum .card { gap: 0; padding: 14px 16px; }
.sum b { font-size: 1.5em; font-weight: 500; }

/* Result + dialogs */
.overlay { position: fixed; inset: 0; background: rgba(8,5,25,.82); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.overlay.show { display: flex; }
.overlay .card { max-width: 420px; width: 100%; background: #1d1846; border-radius: 24px; padding: 26px; text-align: center; gap: 12px; }
.overlay .res-ic { width: 84px; height: 84px; margin: 0 auto; }
.overlay h1 { font-size: 1.8em; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid rgba(255,255,255,.12); border-top-color: var(--accent); margin: 4px auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: #2a2160; padding: 10px 16px; border-radius: 12px; font-size: .9em; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; }
.login-logo { width: 120px; height: 120px; margin: 0 auto; display: block; }
.login-brand { text-align: center; font-size: 2.3em; font-weight: 800; }
.center { text-align: center; }
a.link { color: var(--accent); }
.hidden { display: none !important; }

/* Tournament */
.pool-card { background: linear-gradient(135deg, rgba(255,217,61,.16), rgba(255,107,53,.14)); border: 1px solid rgba(255,217,61,.4); border-radius: 22px; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.pool-card .amt { font-size: 2.2em; font-weight: 600; color: var(--hot); line-height: 1.1; }
.pool-card .ends { color: var(--muted); font-size: .82em; }
.pos { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: rgba(167,139,250,.14); border: 1px solid rgba(167,139,250,.45); }
.pos .rank { font-size: 1.8em; font-weight: 700; color: var(--accent); min-width: 56px; text-align: center; }
.pos .txt { flex: 1; }
.pos .txt small { display: block; color: var(--muted); font-size: .8em; }
.lb .rk { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; flex: none; background: rgba(255,255,255,.07); }
.lb .rk.r1 { background: #ffd93d; color: #3a2a00; } .lb .rk.r2 { background: #d4d8e6; color: #222; } .lb .rk.r3 { background: #e0a26a; color: #3a1d00; }
.lb .me { border-color: var(--accent); background: rgba(167,139,250,.12); }
.mini-pool { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 18px; background: rgba(255,217,61,.08); border: 1px solid rgba(255,217,61,.3); cursor: pointer; text-align: left; width: 100%; }
.mini-pool .ic { color: var(--hot); width: 30px; height: 30px; }
.mini-pool b { color: var(--hot); }

/* Game history detail */
.row.tap { cursor: pointer; transition: border-color .15s, background .15s; }
.row.tap:hover { border-color: rgba(167,139,250,.5); background: rgba(167,139,250,.08); }
.detail-list { display: flex; flex-direction: column; margin: 6px 0 4px; }
.dl { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid rgba(255,255,255,.07); font-size: .92em; }
.dl span { color: var(--muted); }
.dl b { font-weight: 500; text-align: right; }
#detail .card { max-height: 86vh; overflow-y: auto; }

/* ── Async duel games (saga-duel.js): Sudoku Rush, Mo Kache, Konekte, Solitaire Duel, Saga Match, Saga Path ── */
.dl-play { justify-content: center; gap: 12px; }
.dl-hud { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.dl-opp { color: var(--muted); font-size: .85em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-score { text-align: center; line-height: 1; }
.dl-score b { display: block; font-size: 2.4em; font-weight: 800; font-variant-numeric: tabular-nums; }
.dl-score small { color: var(--muted); font-size: .72em; letter-spacing: 1px; }
.dl-timer { justify-self: end; font-size: 1.5em; font-weight: 700; font-variant-numeric: tabular-nums; padding: 4px 12px; border-radius: 999px; background: rgba(255,255,255,.07); }
.dl-timer.low { color: var(--bad); background: rgba(255,93,115,.16); }
.dl-stage { position: relative; width: min(100%, 480px); margin: 0 auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.dl-stage.is-paused .dl-board { visibility: hidden; }
.dl-msg { position: absolute; inset: 0; display: none; place-items: center; text-align: center; padding: 24px; border-radius: 22px; background: rgba(18,13,46,.78); font-weight: 600; z-index: 4; }
.dl-msg.show { display: grid; }
.dl-msg.paused { background: #120d2e; gap: 10px; align-content: center; min-height: 320px; position: relative; }
.dl-stage.is-paused { min-height: 320px; }
.dl-stage.is-paused .dl-msg.paused { position: absolute; }
.dl-msg.paused b { font-size: 1.8em; }
.dl-msg.paused small { color: var(--muted); font-weight: 500; max-width: 300px; }
.dl-meta { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); font-size: .9em; }
.dl-bottom { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dl-btns { display: flex; gap: 8px; }
.dl-bottom .btn { min-height: 46px; min-width: 96px; }
.dl-tip { color: var(--muted); font-size: .8em; margin: 0; }
@keyframes dl-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes dl-shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes dl-glow { 0% { box-shadow: 0 0 0 0 rgba(255,217,61,.8); } 100% { box-shadow: 0 0 0 14px rgba(255,217,61,0); } }

/* How to play */
.howto { margin: 14px 0 16px; padding: 0; list-style: none; counter-reset: st; display: flex; flex-direction: column; gap: 10px; text-align: left; }
.howto li { counter-increment: st; position: relative; padding-left: 36px; line-height: 1.45; font-size: .95em; }
.howto li::before { content: counter(st); position: absolute; left: 0; top: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--accent, #a78bfa); color: #120d2e; font-weight: 700; font-size: .8em; display: grid; place-items: center; }
.back.howto-q { font-weight: 700; font-size: 1.05em; }
