:root {
  --bg: #0d0b14;
  --bg-2: #15121f;
  --card: #1c1829;
  --card-2: #252036;
  --line: #2e2843;
  --text: #f4f1ff;
  --muted: #9a93b5;
  --dim: #6b6487;
  --glib: #8cff5a;
  --glib-2: #3ddc84;
  --glib-ink: #0f2a05;
  --purple: #8b5cf6;
  --pink: #ff5fa2;
  --gold: #ffd166;
  --red: #ff5d6c;
  --green: #4ade80;
  --radius: 20px;
  --radius-sm: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); }
body { overscroll-behavior: none; -webkit-font-smoothing: antialiased; font-size: 16px; line-height: 1.35; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }

#app { height: 100%; display: flex; flex-direction: column; }

/* ---------- Splash ---------- */
.splash { flex: 1; display: grid; place-content: center; justify-items: center; gap: 16px; color: var(--muted); }
.splash-coin { width: 72px; height: 72px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #d4ffb8, var(--glib) 40%, var(--glib-2)); animation: bob 1.2s ease-in-out infinite; box-shadow: 0 0 40px #8cff5a55; }
@keyframes bob { 50% { transform: translateY(-10px) scale(1.05); } }

/* ---------- Layout ---------- */
.view { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--safe-top) + 12px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px); }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 18px; }
.view-head h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.5px; }
.back-link { color: var(--glib); font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 2px 10px; font-size: 13px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--muted); }
.section-title button { text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--glib); font-weight: 600; }

.balance-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 800; font-variant-numeric: tabular-nums; }
.balance-pill .glib-coin { width: 24px; height: 24px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 10px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.list-item:last-child { border-bottom: 0; }
button.list-item:active { background: var(--card-2); }
.empty { text-align: center; padding: 26px 16px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 6px; }

/* ---------- Avatar & coin ---------- */
.avatar { --c: var(--purple); flex: none; width: 42px; height: 42px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 22px; background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--c) 55%, white 10%), color-mix(in srgb, var(--c) 70%, black)); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 60%, white 20%); }
.avatar.sm { width: 30px; height: 30px; font-size: 16px; }
.avatar.lg { width: 64px; height: 64px; font-size: 34px; }
.avatar.xl { width: 92px; height: 92px; font-size: 50px; }
.glib-coin { display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em; flex: none; }
.amount { font-weight: 800; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.plus { color: var(--green); }
.minus { color: var(--red); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: 14px; font-weight: 700; background: var(--card-2); border: 1px solid var(--line); transition: transform .1s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: linear-gradient(180deg, var(--glib), var(--glib-2)); color: var(--glib-ink); border: 0; box-shadow: 0 6px 20px -6px #8cff5a88; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 12px; border-radius: 11px; font-size: 14px; }
.btn.big { height: 54px; font-size: 17px; border-radius: 16px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); }

.chip { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-weight: 600; font-size: 14px; white-space: nowrap; }
.chip.on { background: color-mix(in srgb, var(--glib) 18%, var(--card)); border-color: var(--glib); color: var(--glib); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 3px; margin-bottom: 16px; }
.segmented button { height: 36px; border-radius: 11px; font-weight: 700; font-size: 15px; color: var(--muted); position: relative; }
.segmented button.on { background: var(--card-2); color: var(--text); box-shadow: 0 2px 8px #0006; }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--pink); color: white; font-size: 12px; font-weight: 800; }
.segmented .badge { margin-left: 6px; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--card-2); color: var(--muted); }
.tag.open { background: #4ade8022; color: var(--green); }
.tag.closed { background: #ffd16622; color: var(--gold); }
.tag.done { background: #8b5cf622; color: #b69cff; }
.tag.cancel { background: #ff5d6c22; color: var(--red); }

/* ---------- Tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; height: calc(var(--tabbar-h) + var(--safe-bottom)); padding: 0 6px var(--safe-bottom); background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(20px) saturate(1.4); -webkit-backdrop-filter: blur(20px) saturate(1.4); border-top: 1px solid var(--line); }
.tab { height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 700; color: var(--dim); position: relative; }
.tab svg { width: 26px; height: 26px; }
.tab.on { color: var(--text); }
.tab .badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 18px; height: 18px; font-size: 11px; }
.tab-bet { align-self: start; }
.tab-bet .bet-orb { width: 60px; height: 60px; margin-top: -18px; border-radius: 50%; display: grid; place-items: center; background: radial-gradient(circle at 35% 30%, #d4ffb8, var(--glib) 45%, var(--glib-2)); box-shadow: 0 8px 24px -4px #8cff5a99, 0 0 0 5px var(--bg); color: var(--glib-ink); transition: transform .15s; }
.tab-bet.on .bet-orb { transform: scale(1.06) rotate(-8deg); }
.tab-bet .bet-orb svg { width: 30px; height: 30px; }
.tab-bet span { margin-top: 2px; }

/* ---------- Home ---------- */
.hero { position: relative; overflow: hidden; border-radius: 26px; padding: 20px; background: radial-gradient(120% 120% at 100% 0%, #3ddc8455, transparent 55%), radial-gradient(100% 100% at 0% 100%, #8b5cf666, transparent 60%), var(--card); border: 1px solid var(--line); }
.hero .hello { color: var(--muted); font-weight: 600; }
.hero .big-balance { display: flex; align-items: center; gap: 12px; margin: 8px 0 6px; font-size: 52px; font-weight: 900; letter-spacing: -1.5px; font-variant-numeric: tabular-nums; }
.hero .big-balance .glib-coin { width: 50px; height: 50px; }
.hero .sub { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 14px; font-weight: 600; }
.hero .blob-deco { position: absolute; right: -24px; bottom: -30px; width: 140px; height: 140px; opacity: .18; transform: rotate(-14deg); }

.alerts { display: grid; gap: 8px; margin-top: 12px; }
.alert { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); text-align: left; width: 100%; font-weight: 600; }
.alert .em { font-size: 22px; }
.alert .chev { margin-left: auto; color: var(--dim); }
.alert.hot { border-color: color-mix(in srgb, var(--pink) 50%, var(--line)); background: linear-gradient(90deg, #ff5fa214, var(--card)); }

.friends-row { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.friends-row::-webkit-scrollbar { display: none; }
.friend-tile { flex: none; width: 76px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.friend-tile .avatar { width: 58px; height: 58px; font-size: 30px; }
.friend-tile .name { font-size: 13px; font-weight: 700; width: 100%; }
.friend-tile .amount { font-size: 12px; color: var(--muted); }
.add-tile .avatar { background: var(--card); box-shadow: inset 0 0 0 2px var(--line); color: var(--glib); font-size: 28px; }

.feed-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.feed-item:last-child { border-bottom: 0; }
.feed-item .ic { flex: none; width: 34px; height: 34px; border-radius: 11px; background: var(--card-2); display: grid; place-items: center; font-size: 18px; }
.feed-item b { font-weight: 700; }

/* ---------- Quests ---------- */
.quest { display: flex; align-items: center; gap: 14px; padding: 14px; }
.quest .q-emoji { flex: none; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 24px; background: var(--card-2); }
.quest.ready .q-emoji { background: color-mix(in srgb, var(--glib) 22%, var(--card-2)); box-shadow: 0 0 0 2px var(--glib); }
.quest.claimed { opacity: .5; }
.quest .q-title { font-weight: 700; }
.progress { height: 7px; border-radius: 999px; background: var(--bg-2); overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple), var(--glib)); transition: width .4s; }
.quest .q-meta { display: flex; justify-content: space-between; margin-top: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.reward { display: inline-flex; align-items: center; gap: 3px; font-weight: 800; color: var(--glib); }
.reset-timer { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--muted); font-size: 14px; }

/* ---------- Bets ---------- */
.flip-card { display: flex; gap: 12px; align-items: center; }
.flip-card .stake { font-size: 20px; }
.flip-actions { display: flex; gap: 8px; margin-top: 12px; }
.flip-actions .btn { flex: 1; }
.side-badge { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--text); }

.event { padding: 0; overflow: hidden; }
.event .ev-head { padding: 16px 16px 10px; }
.event .ev-title { font-size: 18px; font-weight: 800; margin: 8px 0 2px; }
.event .ev-desc { color: var(--muted); font-size: 14px; margin-top: 4px; }
.event .ev-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); font-weight: 600; }
.opt { position: relative; display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 16px; border-top: 1px solid var(--line); text-align: left; overflow: hidden; }
.opt .bar { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #8b5cf633, #8b5cf611); transition: width .4s; }
.opt.mine .bar { background: linear-gradient(90deg, #8cff5a33, #8cff5a0d); }
.opt.winner .bar { background: linear-gradient(90deg, #ffd16644, #ffd16611); }
.opt > * { position: relative; }
.opt .o-label { flex: 1; font-weight: 700; min-width: 0; }
.opt .o-odds { font-size: 12px; color: var(--muted); font-weight: 700; }
.opt .o-amt { min-width: 48px; text-align: right; }
button.opt:active { background: var(--card-2); }
.ev-foot { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg-2); align-items: center; }
.ev-foot .grow { font-size: 14px; }
.ev-foot .row .btn { flex: 1; padding: 0 8px; white-space: nowrap; }
.bettors { display: flex; margin-left: 4px; }
.bettors .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--card); }

/* ---------- Leaderboard ---------- */
.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; margin: 6px 0 18px; }
.podium .p { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; min-width: 0; }
.podium .p .name { font-weight: 800; font-size: 14px; width: 100%; }
.podium .p .step { width: 100%; border-radius: 16px 16px 6px 6px; display: grid; place-items: center; font-size: 26px; font-weight: 900; padding: 10px 0; background: var(--card); border: 1px solid var(--line); }
.podium .p1 .step { height: 92px; background: linear-gradient(180deg, #ffd16640, var(--card)); border-color: #ffd16666; }
.podium .p2 .step { height: 70px; background: linear-gradient(180deg, #c0c6d640, var(--card)); }
.podium .p3 .step { height: 56px; background: linear-gradient(180deg, #e0905040, var(--card)); }
.rank-num { width: 28px; text-align: center; font-weight: 900; color: var(--muted); font-variant-numeric: tabular-nums; }
.list-item.me { background: color-mix(in srgb, var(--glib) 9%, var(--card)); }

/* ---------- Account ---------- */
.profile-card { text-align: center; padding: 24px 16px 18px; }
.profile-card .avatar { margin: 0 auto 10px; }
.profile-card h2 { font-size: 24px; font-weight: 800; }
.profile-card .bio { margin-top: 8px; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 8px; text-align: center; }
.stat b { display: block; font-size: 22px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.tx { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.steps { margin: 8px 0 0; padding-left: 20px; color: var(--muted); }
.steps li { margin: 4px 0; }

/* ---------- Auth ---------- */
.auth { flex: 1; overflow-y: auto; padding: calc(var(--safe-top) + 40px) 22px calc(var(--safe-bottom) + 30px); display: flex; flex-direction: column; max-width: 460px; width: 100%; margin: 0 auto; }
.auth .logo { width: 110px; height: 110px; margin: 0 auto 12px; animation: bob 2.4s ease-in-out infinite; filter: drop-shadow(0 12px 30px #8cff5a44); }
.auth h1 { text-align: center; font-size: 40px; font-weight: 900; letter-spacing: -1px; background: linear-gradient(90deg, var(--glib), #c4ff9e 40%, #b69cff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth .tagline { text-align: center; color: var(--muted); margin: 4px 0 26px; }
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 0 0 6px 4px; }
.input { width: 100%; height: 50px; padding: 0 16px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); outline: none; }
textarea.input { height: auto; min-height: 80px; padding: 12px 16px; resize: none; }
.input:focus { border-color: var(--glib); box-shadow: 0 0 0 3px #8cff5a22; }
.form-error { color: var(--red); font-weight: 600; font-size: 14px; min-height: 20px; margin: 4px 4px 10px; }
.demo-banner { margin-top: 22px; padding: 14px; border-radius: 16px; border: 1px dashed #ffd16688; background: #ffd1660d; font-size: 14px; color: var(--gold); }
.demo-accounts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.emoji-grid button { height: 44px; border-radius: 12px; font-size: 24px; background: var(--card); border: 1px solid var(--line); }
.emoji-grid button.on { border-color: var(--glib); background: color-mix(in srgb, var(--glib) 15%, var(--card)); }
.color-row { display: flex; gap: 10px; flex-wrap: wrap; }
.color-row button { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; }
.color-row button.on { border-color: var(--text); }

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 50; background: #0009; animation: fade .2s; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg-2); border: 1px solid var(--line); border-bottom: 0; border-radius: 26px 26px 0 0; padding: 10px 18px calc(var(--safe-bottom) + 22px); animation: up .28s cubic-bezier(.2, .9, .3, 1.1); }
.sheet .grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
.sheet .sheet-sub { color: var(--muted); margin-bottom: 18px; }
.sheet .label { font-size: 13px; font-weight: 700; color: var(--muted); margin: 18px 4px 8px; text-transform: uppercase; letter-spacing: .5px; }
.sheet.closing { animation: down .2s forwards; }
.sheet-backdrop.closing { animation: fade .2s reverse forwards; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes down { to { transform: translateY(100%); } }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .icon-btn { width: 50px; height: 50px; font-size: 26px; font-weight: 700; background: var(--card); }
.stepper input { flex: 1; text-align: center; font-size: 30px; font-weight: 900; height: 58px; }
.side-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.side-pick button { padding: 14px; border-radius: 18px; background: var(--card); border: 2px solid var(--line); display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 800; }
.side-pick button.on { border-color: var(--glib); background: color-mix(in srgb, var(--glib) 12%, var(--card)); }
.side-pick .mini-face { width: 54px; height: 54px; }
.opt-input { display: flex; gap: 8px; margin-bottom: 8px; }
.payout-preview { margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--card); display: flex; justify-content: space-between; font-weight: 700; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; top: calc(var(--safe-top) + 10px); left: 0; right: 0; z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { max-width: 420px; padding: 12px 18px; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line); box-shadow: 0 10px 30px #000a; font-weight: 700; animation: toast-in .3s cubic-bezier(.2, .9, .3, 1.2); display: flex; gap: 10px; align-items: center; }
.toast.error { border-color: #ff5d6c88; color: #ffb3bb; }
.toast.win { border-color: #8cff5a88; }
@keyframes toast-in { from { transform: translateY(-30px); opacity: 0; } }

/* ---------- Coin flip overlay ---------- */
.flip-overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-content: center; justify-items: center; gap: 26px; background: radial-gradient(circle at 50% 40%, #1d2a16, #0d0b14 70%); animation: fade .25s; padding: 24px; text-align: center; }
.flip-stage { perspective: 900px; width: 180px; height: 180px; }
.flip-coin { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; }
.flip-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 50%; }
.flip-face svg { width: 100%; height: 100%; }
.flip-face.back { transform: rotateY(180deg); }
.flip-shadow { width: 120px; height: 16px; border-radius: 50%; background: #0008; filter: blur(6px); margin-top: -10px; }
.flip-result { min-height: 110px; opacity: 0; transform: translateY(10px); transition: all .35s; }
.flip-result.show { opacity: 1; transform: none; }
.flip-result h2 { font-size: 34px; font-weight: 900; }
.flip-result .amount { display: flex; justify-content: center; font-size: 26px; margin: 6px 0 16px; }
.flip-result .amount .glib-coin { width: 26px; height: 26px; }
.confetti { position: fixed; top: -10px; width: 10px; height: 14px; border-radius: 3px; z-index: 81; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (min-width: 700px) {
  .view { max-width: 560px; margin: 0 auto; width: 100%; }
  .tabbar { max-width: 560px; margin: 0 auto; border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0; }
}
