:root {
  color-scheme: light;
  --bg: #aeb9c8;
  --surface: #e1e7ed;
  --surface-strong: #f1f4f7;
  --ink: #1e2632;
  --muted: #68727f;
  --line: rgba(36,38,42,.13);
  --graphite: #252c38;
  --graphite-soft: #394657;
  --accent: #4f6fe8;
  --accent-deep: #344ea8;
  --steel: #268aa6;
  --sage: #358b77;
  --page-bg: #b8c3d2;
  --card: #edf2f6;
  --panel: #e3e9ef;
  --input: #d6dfe7;
  --economy: #252e3b;
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-bottom: max(24px, env(safe-area-inset-bottom));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111722;
  --surface: #202938;
  --surface-strong: #293547;
  --ink: #f0f4fa;
  --muted: #9ca9ba;
  --line: rgba(255,255,255,.11);
  --graphite: #0e1420;
  --graphite-soft: #34445a;
  --accent: #6f88ff;
  --accent-deep: #91a4ff;
  --steel: #2697b8;
  --sage: #3a9b84;
  --page-bg: #111722;
  --card: #1b2431;
  --panel: #1a2330;
  --input: #141c27;
  --economy: #0d131d;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--page-bg); }
body {
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  background: var(--page-bg);
}
button, input { font: inherit; }
button { color: inherit; }
.page[hidden] { display: none !important; }

.shell {
  width: min(100%, 520px);
  min-height: var(--tg-viewport-stable-height, 100svh);
  margin: 0 auto;
  padding: var(--safe-top) 16px var(--safe-bottom);
  overflow: hidden;
  position: relative;
}
.shell::before {
  display: none;
}
.page { position: relative; z-index: 1; }

.balance-card { padding: 17px 8px 16px; text-align: center; }
.balance-card .eyebrow { display: block; margin-bottom: 6px; color: var(--accent-deep); font-size: 10px; font-weight: 900; letter-spacing: .16em; }
.balance-card strong { display: block; font-size: clamp(33px, 10vw, 50px); line-height: 1.04; letter-spacing: -.055em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.balance-card>small { display: block; margin-top: 6px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .16em; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 3px 0 14px; }
.stats article { min-width: 0; padding: 11px 12px; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 17px; background: var(--card); box-shadow: none; }
.stats article>div { min-width: 0; }
.stats small, .stats strong { display: block; }
.stats small { margin-bottom: 3px; color: var(--muted); font-size: 9px; }
.stats strong { overflow: hidden; text-overflow: ellipsis; font-size: 11px; font-variant-numeric: tabular-nums; }
.stat-mark { width: 29px; height: 29px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 9px; color: #f2f5f7; font-size: 15px; font-weight: 900; }
.stat-mark-click { background: var(--accent); }
.stat-mark-auto { background: #258ba9; }

.section-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.section-grid button {
  min-height: 74px;
  padding: 13px;
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--card);
  box-shadow: none;
  cursor: pointer;
  text-align: left;
  transition: transform .13s ease, box-shadow .13s ease;
}
.section-grid button:active { transform: translateY(2px) scale(.98); box-shadow: none; }
.section-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; color: #eef2f4; background: var(--accent); }
.section-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.section-grid button:first-child .section-icon svg { fill: currentColor; stroke: none; }
.section-grid button:nth-child(2) .section-icon { background: #6a5bb8; }
.section-grid button:nth-child(3) .section-icon { background: var(--steel); }
.section-grid button:nth-child(4) .section-icon { background: var(--sage); }
.section-grid button:nth-child(5) .section-icon { background: #5667c5; }
.section-grid button:nth-child(6) .section-icon { background: #7658b5; }
.section-grid button>strong { font-size: 12px; }
.section-grid button>small { color: var(--muted); font-size: 9px; }
.economy-card { margin-top: 14px; padding: 14px; border: 1px solid rgba(111,142,255,.18); border-radius: 20px; background: var(--economy); color: #eef2f4; box-shadow: none; }
.economy-card header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.economy-card header>div { display: flex; align-items: center; gap: 8px; }
.economy-card header strong { font-size: 12px; }
.economy-card header small { padding: 4px 7px; border-radius: 999px; color: #91e5d1; background: rgba(53,139,119,.22); font-size: 8px; font-weight: 900; letter-spacing: .1em; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #4fd4b4; }
.economy-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.economy-grid article { min-width: 0; padding: 10px 8px; border-radius: 13px; background: rgba(255,255,255,.055); }
.economy-grid small, .economy-grid strong { display: block; }
.economy-grid small { min-height: 24px; color: #aeb0b1; font-size: 8px; line-height: 1.35; }
.economy-grid strong { margin-top: 6px; overflow: hidden; text-overflow: ellipsis; font-size: 10px; font-variant-numeric: tabular-nums; }

.smack-zone { min-height: 490px; padding: 35px 0 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; }
.smack-zone>p { margin: 0 0 18px; color: #5f666c; font-size: 10px; font-weight: 750; letter-spacing: .05em; }
.smack-zone::before, .smack-zone::after { content: ""; position: absolute; border-radius: 50%; pointer-events: none; }
.smack-zone::before { display: none; }
.smack-zone::after { display: none; }
.smack-button {
  width: min(330px, 86vw);
  height: auto;
  aspect-ratio: 1;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  color: #f1f5f7;
  cursor: pointer;
  position: relative;
  z-index: 1;
  background: linear-gradient(145deg, #7491ff 0%, var(--accent) 46%, var(--accent-deep) 100%);
  box-shadow: inset 0 4px 2px rgba(255,255,255,.28), inset 0 -18px 34px rgba(28,43,110,.25), 0 22px 0 #263d8c;
  transform: translateY(-10px);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.smack-button::before { content: ""; position: absolute; inset: 10px; border: 2px solid rgba(255,255,255,.18); border-radius: inherit; }
.smack-button strong { font-size: 40px; line-height: 1; letter-spacing: .09em; text-shadow: 0 3px 0 rgba(24,39,51,.22); }
.smack-button:not(:disabled):active { transform: translateY(7px) scale(.98); box-shadow: inset 0 3px 1px rgba(255,255,255,.2), inset 0 -7px 20px rgba(28,43,110,.24), 0 3px 0 #263d8c; filter: brightness(1.06); }
.smack-button:disabled { opacity: .78; cursor: wait; }
.floating-gain { position: fixed; z-index: 40; pointer-events: none; color: #fff; font-weight: 950; text-shadow: 0 2px 8px rgba(0,0,0,.55); animation: float-gain .8s ease-out forwards; }

.subpage { padding-top: 2px; }
#upgrades-page { padding-top: 60px; }
.page-head { min-height: 46px; margin-bottom: 19px; display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; }
#upgrades-page .page-head {
  position: fixed;
  z-index: 20;
  top: 0;
  left: 50%;
  width: min(100%, 520px);
  min-height: calc(var(--safe-top) + 50px);
  margin: 0;
  padding: var(--safe-top) 16px 10px;
  transform: translateX(-50%);
  background: var(--page-bg);
}
.page-head>button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); cursor: pointer; box-shadow: none; }
#upgrades-page .page-head>button { box-shadow: none; }
.page-head h1 { margin: 0; font-size: 21px; letter-spacing: -.025em; }
.page-head>strong { max-width: 150px; overflow: hidden; text-overflow: ellipsis; font-size: 11px; font-variant-numeric: tabular-nums; }
.upgrade-tabs, .top-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 14px; padding: 4px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); }
.top-tabs { grid-template-columns: repeat(3, 1fr); }
.upgrade-tabs button, .top-tabs button { min-height: 39px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 800; }
.upgrade-tabs button[aria-selected="true"], .top-tabs button[aria-selected="true"] { color: #eef2f4; background: var(--graphite-soft); box-shadow: none; }
.upgrade-list, .top-list { display: grid; gap: 10px; }
.upgrade-card, .transfer-form, .referral-card, .games-card, .settings-card { border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: none; }
.upgrade-card { --card-accent: var(--accent); padding: 14px; }
.accent-cyan { --card-accent: var(--steel); }
.upgrade-card.purchase-success { animation: purchase-pop .52s ease; }
.upgrade-top { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.upgrade-icon { width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 13px; color: #eef2f4; background: var(--card-accent); font-size: 10px; font-weight: 900; }
.upgrade-copy { min-width: 0; flex: 1; }
.upgrade-copy>div { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.upgrade-copy h2 { margin: 0; font-size: 14px; }
.upgrade-copy span { color: var(--card-accent); font-size: 10px; font-weight: 800; }
.upgrade-copy p { margin: 5px 0 0; color: var(--muted); font-size: 10px; }
.upgrade-owned { white-space: nowrap; }
.upgrade-button { width: 100%; min-height: 43px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; border: 0; border-radius: 12px; color: #eef2f4; background: var(--card-accent); cursor: pointer; font-size: 10px; font-weight: 800; transition: transform .1s ease, filter .1s ease; }
.upgrade-button:active { transform: scale(.98); filter: brightness(.95); }
.upgrade-button:disabled { opacity: .35; cursor: not-allowed; }
.upgrade-button strong { font-variant-numeric: tabular-nums; }
.rank, .counter { margin: 0 0 12px; color: var(--muted); font-size: 10px; }
.top-row { padding: 11px 12px; display: grid; grid-template-columns: 28px 34px 1fr auto; align-items: center; gap: 9px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.top-row.is-me { border-color: rgba(184,101,66,.65); }
.top-place { color: var(--muted); font-size: 10px; }
.top-avatar { width: 32px; height: 32px; display: grid; place-items: center; overflow: hidden; border-radius: 10px; color: #eef2f4; background: var(--steel); font-size: 10px; }
.top-avatar img { width: 100%; height: 100%; object-fit: cover; }
.top-person { min-width: 0; }
.top-person strong, .top-person small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-person strong { font-size: 11px; }
.top-person small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.top-value { font-size: 10px; font-variant-numeric: tabular-nums; }
.transfer-form, .referral-card, .games-card, .settings-card { padding: 16px; }
.transfer-form { display: grid; gap: 13px; }
.transfer-form label>span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; }
.transfer-form input, .referral-card input { width: 100%; height: 45px; padding: 0 12px; border: 1px solid var(--line); border-radius: 11px; outline: none; color: var(--ink); background: var(--input); font-variant-numeric: tabular-nums; }
.transfer-form input:focus, .referral-card input:focus { border-color: rgba(184,101,66,.75); box-shadow: 0 0 0 3px rgba(184,101,66,.1); }
.transfer-form>button, .referral-card button { height: 44px; border: 0; border-radius: 11px; color: #eef2f4; background: var(--graphite-soft); cursor: pointer; font-weight: 800; }
.counter { margin-top: 11px; }
.referral-card { text-align: center; }
.referral-card>strong { display: block; font-size: 34px; }
.referral-card>span { display: block; margin: 3px 0 16px; color: var(--muted); font-size: 10px; }
.referral-card>p { margin: 0 0 16px; color: var(--muted); font-size: 11px; line-height: 1.55; }
.referral-card input { margin-bottom: 10px; font-size: 10px; }
.referral-card button { width: 100%; }
.mini-title { margin: 22px 0 11px; font-size: 14px; }
.games-card { min-height: 190px; display: grid; place-items: center; }
.games-card strong { color: var(--muted); font-size: 18px; }
.recipient-card { padding: 11px; display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); }
.recipient-card[hidden] { display: none; }
.recipient-avatar { width: 42px; height: 42px; display: grid; place-items: center; overflow: hidden; border-radius: 12px; color: #fff; background: var(--accent); font-weight: 900; }
.recipient-avatar img { width: 100%; height: 100%; object-fit: cover; }
.recipient-person { min-width: 0; }
.recipient-person strong, .recipient-person small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipient-person strong { font-size: 12px; }
.recipient-person small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.recipient-status { color: var(--sage); font-size: 18px; font-weight: 900; }
.recipient-card[data-status="missing"] .recipient-status { color: #d46776; }
.recipient-card[data-status="loading"] { opacity: .7; }
.settings-card h2 { margin: 0 0 14px; font-size: 14px; }
.theme-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.theme-options button { min-height: 44px; padding: 8px; border: 1px solid var(--line); border-radius: 11px; color: var(--muted); background: var(--panel); cursor: pointer; font-size: 10px; font-weight: 800; }
.theme-options button[aria-pressed="true"] { color: #fff; border-color: transparent; background: var(--accent); }
.toast { position: fixed; z-index: 50; left: 50%; top: max(18px, env(safe-area-inset-top)); max-width: min(90vw, 430px); transform: translateX(-50%); padding: 12px 17px 12px 42px; border: 1px solid rgba(105,127,113,.28); border-radius: 14px; color: #28352d; background: rgba(220,226,218,.98); box-shadow: 0 15px 35px rgba(43,47,45,.2); font-size: 12px; font-weight: 750; text-align: left; animation: toast-in .25s ease both; }
.toast::before { content: "✓"; position: absolute; left: 13px; top: 50%; width: 20px; height: 20px; display: grid; place-items: center; transform: translateY(-50%); border-radius: 50%; color: #eeeae2; background: var(--sage); font-size: 11px; }
.toast.is-error { color: #54323a; border-color: rgba(126,76,89,.28); background: rgba(220,207,211,.98); }
.toast.is-error::before { content: "!"; background: var(--accent); }

@keyframes breathe { 50% { transform: scale(1.08); opacity: .65; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes live-pulse { 50% { box-shadow: 0 0 0 7px rgba(130,153,136,0); } }
@keyframes float-gain { to { transform: translateY(-72px) scale(1.12) rotate(-4deg); opacity: 0; } }
@keyframes toast-in { from { transform: translate(-50%, -14px); opacity: 0; } }
@keyframes purchase-pop { 45% { transform: scale(1.025); box-shadow: 0 16px 34px rgba(105,127,113,.22); } }
@media (max-width: 360px) { .economy-grid { grid-template-columns: 1fr; } .economy-grid small { min-height: auto; } }
@media (max-height: 720px) { .smack-zone { min-height: 450px; } .smack-button { width: min(303px, 84vw); } .smack-zone::before { width: min(360px, 98%); } .smack-zone::after { width: min(330px, 92%); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
