:root {
  --bg: #0d0c1a;
  --card: #17171f;
  --secondary: #1c1c26;
  --fg: #f3f4f8;
  --hint: #8b8fa3;
  --primary: #57bad1;
  --primary-fg: #04222e;
  --border: rgba(255, 255, 255, 0.08);
  --green: #22c55e;
  --red: #ff5c5c;
  --tile-orange: #f5a524;
  --tile-green: #22c55e;
  --tile-pink: #ec4899;
  --tile-purple: #a855f7;
  --tile-cyan: #22d3ee;
  --tile-blue: #3b82f6;
  --r-lg: 0.75rem;
  --r-xl: 1.05rem;
  --r-2xl: 1.35rem;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--fg);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 15px; -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none;
  overscroll-behavior-y: none; color-scheme: dark;
}
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; }
.tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--hint); }
.gold { color: var(--primary); }
.xs { font-size: 12px; }
.sm { font-size: 13px; }
.min-w { min-width: 0; flex: 1; }
.px { padding-inline: 16px; }
.gap16 { display: flex; flex-direction: column; gap: 16px; }
.hidden { display: none !important; }
.rules { line-height: 1.55; }

@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(0.93); } 100% { transform: scale(1); } }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.8); }
  25% { opacity: 1; transform: translate(-50%, -30px) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -120px) scale(1); }
}
@keyframes rise { 0% { opacity: 0; transform: translateY(14px); } 100% { opacity: 1; transform: translateY(0); } }
@keyframes breathe { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-6px) scale(1.015); } }
@keyframes page-in { 0% { opacity: 0; transform: translateX(24px); } 100% { opacity: 1; transform: translateX(0); } }
.rise { animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) both; }
.pop:active { animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }

.app { max-width: 448px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; position: relative; }

.home-head { position: relative; z-index: 10; display: flex; align-items: center; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 16px 4px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--secondary); display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.whoami { min-width: 0; }
.whoami p:first-child { font-size: 14px; font-weight: 500; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.whoami p:last-child { font-size: 12px; line-height: 1.25; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.home-main { position: relative; display: flex; flex: 1; flex-direction: column; }

.balance-section { text-align: center; padding: 20px 16px 12px; }
.bal-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.bal-main { text-align: left; }
.bal-label { font-size: 11px; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: var(--hint); }
.bal-value { font-size: 32px; font-weight: 700; line-height: 1.1; }
.bal-badges { display: flex; flex-direction: column; gap: 6px; }
.badge { display: inline-flex; align-items: center; gap: 4px; background: var(--secondary); border-radius: 999px; padding: 5px 10px; font-size: 12px; font-weight: 600; font-family: "JetBrains Mono", monospace; }
.badge-neuron { color: #a78bfa; }
.badge-image { color: #f59e0b; }
.bal-stats { display: flex; gap: 16px; margin-top: 8px; justify-content: center; }
.bal-stat { font-size: 11px; color: var(--hint); font-family: "JetBrains Mono", monospace; }

.tiles { position: relative; margin-top: 16px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding-inline: 16px; }
.tile { aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-2xl); font-size: 12px; font-weight: 500; transition: transform 0.15s ease; }
.tile:active { transform: scale(0.95); }
.tile-icon { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: color-mix(in oklab, var(--tint) 16%, transparent); font-size: 22px; }

.extra-row { display: flex; gap: 8px; padding: 12px 16px 0; }
.extra-btn { flex: 1; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 8px; font-size: 12px; font-weight: 500; text-align: center; }
.extra-btn:active { transform: scale(0.97); }

.coin-zone { position: relative; margin-top: auto; display: flex; justify-content: center; overflow: hidden; padding-top: 16px; }
#coin-btn { position: relative; width: 104%; transform: translateY(12%); display: flex; justify-content: center; outline: none; }
.coin-img { position: relative; width: 100%; transition: transform 0.1s ease-out; }
.coin-img.breathe { animation: breathe 5s ease-in-out infinite; }
#coin-btn.pressed .coin-img { animation: none; transform: scale(0.97); }
.coin-img img { display: block; width: 100%; height: auto; pointer-events: none; }
.float-num { position: absolute; z-index: 10; pointer-events: none; font-family: "JetBrains Mono", monospace; font-size: 22px; font-weight: 700; color: var(--primary); text-shadow: 0 2px 8px rgba(0,0,0,0.45); animation: float-up 0.9s cubic-bezier(0.22, 0.61, 0.36, 1) forwards; }

.page { position: fixed; inset: 0; margin: 0 auto; max-width: 448px; background: var(--bg); z-index: 40; display: none; flex-direction: column; }
.page.open { display: flex; animation: page-in 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
.page-head { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; padding: max(12px, env(safe-area-inset-top)) 12px 12px; background: rgba(13,12,26,0.85); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.page-head h1 { font-size: 16px; font-weight: 600; flex: 1; }
.back-btn { width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--fg); font-size: 18px; transition: background 0.15s ease; }
.back-btn:active { background: var(--secondary); }
.page-body { flex: 1; overflow-y: auto; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.page-body::-webkit-scrollbar { display: none; }
.page-body { scrollbar-width: none; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-2xl); padding: 16px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { background: var(--secondary); color: var(--hint); border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 500; transition: background 0.15s ease, color 0.15s ease; white-space: nowrap; }
.tab.active { background: rgba(255,255,255,0.1); color: var(--fg); }
.sub-tabs { margin-bottom: 12px; }

.gap-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.shop-item { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-2xl); padding: 12px; }
.si-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--secondary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 22px; }
.si-body { flex: 1; min-width: 0; }
.si-name { display: block; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.si-desc { display: block; font-size: 12px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.si-stat { display: block; font-size: 11px; margin-top: 2px; }
.si-lvl { color: var(--hint); font-size: 12px; }
.si-buy { flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px; border-radius: 12px; padding: 8px 12px; font-size: 13px; font-weight: 600; background: var(--primary); color: var(--primary-fg); transition: background 0.2s ease; }
.si-buy:active { animation: pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1); }
.si-buy.cant { background: var(--secondary); color: var(--hint); }
.si-buy.ruble-buy { background: var(--green); color: #fff; }

.list { list-style: none; overflow: hidden; padding: 0; margin-bottom: 16px; }
.list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.list li + li { border-top: 1px solid var(--border); }
.t-place { width: 24px; flex-shrink: 0; font-family: "JetBrains Mono", monospace; font-size: 13px; color: var(--hint); font-variant-numeric: tabular-nums; text-align: center; }
.t-mark { width: 24px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.lb-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--secondary); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.t-name { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.t-balance { font-family: "JetBrains Mono", monospace; font-size: 13px; font-variant-numeric: tabular-nums; }
.list li.you { background: rgba(87,186,209,0.08); }

.income-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.income-val { font-size: 20px; font-weight: 600; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--secondary); border-radius: 999px; padding: 7px 12px; font-size: 13px; flex-shrink: 0; }

.exchange-card { display: flex; flex-direction: column; gap: 10px; }
.exchange-card .btn-primary { margin-top: 8px; }

.game-card { display: flex; flex-direction: column; gap: 10px; }
.game-header { display: flex; align-items: center; gap: 12px; }
.game-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 22px; }
.game-icon.big { width: 64px; height: 64px; border-radius: 16px; }
.pink-tint { background: rgba(236,72,153,0.16); color: var(--tile-pink); }
.cyan-tint { background: rgba(34,211,238,0.14); color: var(--tile-cyan); }
.blue-tint { background: rgba(59,130,246,0.16); color: var(--tile-blue); }
.red-tint { background: rgba(255,92,92,0.16); color: var(--red); }

.stake-row { display: flex; gap: 6px; }
.stake { flex: 1; background: var(--secondary); color: var(--hint); border-radius: 12px; padding: 9px 0; font-size: 12px; font-weight: 500; transition: background 0.15s ease, color 0.15s ease; text-align: center; }
.stake.active { background: rgba(255,255,255,0.1); color: var(--fg); }

.btn-primary { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--primary); color: var(--primary-fg); border-radius: 12px; padding: 11px 14px; font-size: 14px; font-weight: 600; }
.btn-primary.wide { width: 100%; }
.btn-primary:disabled { opacity: 0.45; cursor: default; }
.btn-ghost { color: var(--hint); font-size: 14px; padding: 8px; }

.mono { font-family: "JetBrains Mono", monospace; }
.win { color: var(--green); }
.lose { color: var(--red); }

#dice-result, #roulette-result, #crash-multiplier { min-height: 20px; font-size: 14px; text-align: center; }
.crash-mult-display { text-align: center; padding: 16px 0; }
.crash-mult { font-size: 48px; font-weight: 700; color: var(--green); }
.crash-controls { display: flex; gap: 8px; }
.crash-controls .btn-primary { flex: 1; }
.crash-bet-item, .roulette-bet-item { display: flex; justify-content: space-between; padding: 4px 0; font-size: 12px; }

.roulette-wheel { text-align: center; font-size: 48px; padding: 8px 0; }

.rebirth-stat { font-size: 28px; font-weight: 700; margin-top: 4px; }

.ref-hero { display: flex; align-items: flex-start; gap: 12px; font-size: 13px; line-height: 1.6; }
.ref-hero-icon { font-size: 28px; flex-shrink: 0; }
.ref-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { text-align: center; padding: 14px 12px; }
.stat b { display: block; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--hint); }
.ref-link-text { word-break: break-all; background: var(--secondary); padding: 8px 12px; border-radius: 8px; margin-top: 4px; }

.tr-banner { text-align: center; }
.tr-balance { font-size: 28px; font-weight: 600; margin-top: 4px; }

.tr-input { background: var(--secondary); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--fg); outline: none; width: 100%; }
.tr-input:focus { border-color: var(--primary); }

.chat-layout { display: flex; flex: 1; overflow: hidden; }
.chat-sidebar { width: 120px; border-right: 1px solid var(--border); overflow-y: auto; padding: 8px; flex-shrink: 0; display: flex; flex-direction: column; gap: 4px; }
.chat-list-item { padding: 8px 10px; border-radius: 8px; font-size: 12px; text-align: left; color: var(--hint); background: transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list-item.active { background: var(--secondary); color: var(--fg); }
.chat-list-item.new-chat { color: var(--primary); font-weight: 500; margin-top: 8px; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.45; word-break: break-word; }
.chat-msg.user { align-self: flex-end; background: var(--primary); color: var(--primary-fg); border-bottom-right-radius: 4px; }
.chat-msg.model { align-self: flex-start; background: var(--secondary); border-bottom-left-radius: 4px; }
.chat-empty { text-align: center; color: var(--hint); margin: auto; font-size: 13px; }
.chat-controls { padding: 8px 12px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.chat-mode-btns { display: flex; gap: 6px; }
.chat-mode-btn { flex: 1; padding: 6px; font-size: 12px; border-radius: 8px; background: var(--secondary); color: var(--hint); }
.chat-mode-btn.active { background: rgba(255,255,255,0.1); color: var(--fg); }
.chat-input-row { display: flex; gap: 6px; }
.chat-input-row .tr-input { flex: 1; padding: 10px 12px; }
.chat-input-row .btn-primary { padding: 10px 16px; }

.modal { position: fixed; inset: 0; z-index: 60; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); padding: 24px; }
.modal.open { display: flex; }
.modal-box { width: min(320px, 100%); background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 24px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; animation: rise 0.4s cubic-bezier(0.16, 1, 0.3, 1); }
.modal-box h3 { font-size: 18px; font-weight: 600; }
.modal-box p { font-size: 13px; color: var(--hint); line-height: 1.5; }
.modal-box .btn-primary { width: 100%; }

#toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, 16px); max-width: min(400px, calc(100vw - 40px)); background: var(--secondary); border: 1px solid var(--border); border-radius: 999px; padding: 10px 18px; font-size: 13px; text-align: center; opacity: 0; pointer-events: none; transition: opacity 0.3s ease, transform 0.3s ease; z-index: 70; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
