:root {
  --bg-0: #0a0714;
  --bg-1: #140d28;
  --surface: rgba(255, 255, 255, 0.06);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f2eefc;
  --text-dim: #a79dc9;
  --accent: #8b6bff;
  --accent-2: #38e8ff;
  --gold: #ffd166;
  --green: #4ade80;
  --red: #ff5c5c;
  --blue: #3b82f6;
  --black: #2a2438;
  --tabbar-h: 72px;
  --topbar-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }

body {
  background:
    radial-gradient(circle at 50% -10%, #2a1f57 0%, transparent 55%),
    radial-gradient(circle at 90% 10%, rgba(56, 232, 255, 0.1) 0%, transparent 40%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { position: relative; height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border);
  background: rgba(10, 7, 20, 0.6); backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 15px; }
.balance-chip {
  display: flex; align-items: center; gap: 5px;
  background: linear-gradient(135deg, rgba(139, 107, 255, 0.25), rgba(56, 232, 255, 0.15));
  border: 1px solid rgba(139, 107, 255, 0.4); border-radius: 999px; padding: 6px 12px;
  font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums;
}

#views { flex: 1 1 auto; overflow-y: auto; padding: 14px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 16px); -webkit-overflow-scrolling: touch; }
.view { display: none; animation: fadein .2s ease; }
.view.active { display: block; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-title { font-size: 20px; font-weight: 800; margin: 4px 0 4px; }
.view-subtitle { color: var(--text-dim); font-size: 13px; margin: 0 0 14px; }
.section-title { font-size: 14px; font-weight: 700; margin: 18px 0 10px; color: var(--text-dim); }

.phase-banner {
  text-align: center; font-weight: 700; font-size: 13px; padding: 8px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); margin-bottom: 14px;
  color: var(--accent-2);
}
.phase-banner.spinning { color: var(--gold); }
.phase-banner.result, .phase-banner.crashed { color: var(--green); }

/* ---------------- roulette wheel ---------------- */

.wheel-stage {
  position: relative; width: 220px; height: 220px; margin: 6px auto 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 45%, rgba(139,107,255,0.15), transparent 70%);
}
.wheel-svg {
  width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 0 24px rgba(139,107,255,0.25));
}
#wheelTicks { transition: transform 8.5s cubic-bezier(.2,.8,.2,1); transform-origin: 100px 100px; }
.wheel-tick { stroke-linecap: round; }
.wheel-center {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.wheel-pointer {
  position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
  font-size: 18px; color: var(--gold); text-shadow: 0 2px 6px rgba(0,0,0,0.6); z-index: 2;
}

.history-strip { display: flex; gap: 4px; overflow-x: auto; padding: 6px 2px 14px; }
.history-dot { flex: 0 0 auto; width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.15); }
.history-dot.black { background: var(--black); }
.history-dot.red { background: var(--red); }
.history-dot.blue { background: var(--blue); }
.history-dot.green { background: var(--green); }
.history-x { flex: 0 0 auto; font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); }
.history-x.win { color: var(--green); }

.bet-panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 14px; }

.amount-row { display: flex; gap: 8px; margin-bottom: 10px; }
.amount-input {
  flex: 1; border-radius: 12px; border: 1px solid var(--border); background: rgba(0,0,0,0.25);
  color: var(--text); padding: 12px; font-size: 15px; font-weight: 700; min-width: 0;
}
.amount-input::placeholder { color: var(--text-dim); font-weight: 500; font-size: 12px; }
.chip-btn {
  border-radius: 12px; border: 1px solid var(--border); background: rgba(255,255,255,0.05);
  color: var(--text); padding: 0 16px; font-weight: 700; font-size: 13px;
}

.color-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.color-btn {
  border-radius: 12px; border: 1px solid var(--border); padding: 12px 4px; text-align: center; color: var(--text);
  font-weight: 700; font-size: 12px; position: relative;
}
.color-btn .swatch { width: 22px; height: 22px; border-radius: 50%; margin: 0 auto 6px; }
.color-btn.black .swatch { background: var(--black); border: 1px solid rgba(255,255,255,0.2); }
.color-btn.red .swatch { background: var(--red); }
.color-btn.blue .swatch { background: var(--blue); }
.color-btn.green .swatch { background: var(--green); }
.color-btn.selected { border-color: var(--gold); background: rgba(255,209,102,0.12); }
.color-btn.disabled { opacity: 0.4; pointer-events: none; }
.color-btn .mult { display: block; color: var(--text-dim); font-weight: 600; font-size: 10px; margin-top: 2px; }

.bets-list { display: flex; flex-direction: column; gap: 6px; }
.bet-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12px;
}
.bet-row .who { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bet-row .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.bet-row .dot.black { background: var(--black); border: 1px solid rgba(255,255,255,0.3); }
.bet-row .dot.red { background: var(--red); }
.bet-row .dot.blue { background: var(--blue); }
.bet-row .dot.green { background: var(--green); }
.bet-row .amt { font-weight: 700; flex: 0 0 auto; }
.bet-row .amt.won { color: var(--green); }
.list-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 14px 0; }

/* ---------------- crash ---------------- */

.crash-stage {
  position: relative; height: 220px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--surface); overflow: hidden; margin-bottom: 10px;
}
.crash-graph { position: absolute; inset: 0; width: 100%; height: 100%; }
.crash-rocket {
  position: absolute; font-size: 26px; left: 0; bottom: 0;
  transform: translate(-50%, 50%) rotate(-45deg);
  transition: left .1s linear, bottom .1s linear;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,0.5));
}
.crash-multiplier {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-size: 34px; font-weight: 800; text-shadow: 0 2px 10px rgba(0,0,0,0.5);
}
.crash-multiplier.crashed-text { color: var(--red); }
.crash-hash { position: absolute; bottom: 6px; left: 8px; right: 8px; font-size: 9px; color: var(--text-dim); word-break: break-all; opacity: 0.6; }

.primary-btn {
  width: 100%; border: none; border-radius: 14px; padding: 14px; font-size: 15px; font-weight: 700;
  color: #16102e; background: linear-gradient(135deg, var(--gold), #ffb020);
  box-shadow: 0 8px 20px rgba(255, 209, 102, 0.25); margin-top: 4px;
}
.primary-btn:active { transform: scale(0.98); }
.primary-btn.danger { background: linear-gradient(135deg, #ff8a8a, var(--red)); color: #2a0808; }
.primary-btn:disabled { opacity: 0.45; }

/* ---------------- cases ---------------- */

.case-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.case-card {
  display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 14px;
}
.case-card .icon { font-size: 34px; }
.case-card .info { flex: 1; min-width: 0; }
.case-card .name { font-weight: 800; font-size: 15px; }
.case-card .price { color: var(--gold); font-weight: 700; font-size: 13px; margin-top: 2px; }
.case-card .open-btn {
  border: none; border-radius: 10px; padding: 10px 14px; font-weight: 700; font-size: 13px;
  background: linear-gradient(135deg, var(--gold), #ffb020); color: #16102e;
}

.case-open-stage { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 140px; }
.case-box { font-size: 64px; transition: transform .15s ease; }
.case-box.shaking { animation: shake .5s infinite; }
@keyframes shake { 0%,100% { transform: rotate(0deg); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
.case-prize-result { text-align: center; font-size: 22px; font-weight: 800; color: var(--gold); }

.prize-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 6px; }
.prize-chip { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 4px; text-align: center; }
.prize-chip .val { font-weight: 800; font-size: 13px; color: var(--gold); }
.prize-chip .chance { font-size: 10px; color: var(--text-dim); margin-top: 2px; }

/* ---------------- profile ---------------- */

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; margin-bottom: 4px; }
.stat-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 800; }

.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; font-size: 13px; }
.history-item .amount.positive { color: var(--green); font-weight: 700; }
.history-item .amount.negative { color: var(--red); font-weight: 700; }
.history-item .meta { color: var(--text-dim); font-size: 11px; }
.history-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 20px 0; }

/* ---------------- tabbar / sheet / toast (shared) ---------------- */

.tabbar {
  position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom); display: flex; background: rgba(10, 7, 20, 0.85);
  backdrop-filter: blur(14px); border-top: 1px solid var(--border);
}
.tab-btn { flex: 1; border: none; background: none; color: var(--text-dim); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10px; font-weight: 600; }
.tab-icon { font-size: 20px; filter: grayscale(1); opacity: 0.6; transition: all .15s ease; }
.tab-btn.active { color: var(--gold); }
.tab-btn.active .tab-icon { filter: none; opacity: 1; transform: translateY(-2px); }

.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); opacity: 0; pointer-events: none; transition: opacity .2s ease; z-index: 20; }
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; background: var(--bg-1); border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0; padding: 10px 18px calc(20px + var(--safe-bottom));
  transform: translateY(100%); transition: transform .25s ease; z-index: 21; max-height: 85vh; overflow-y: auto;
}
.sheet.open { transform: translateY(0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: var(--border); margin: 6px auto 14px; }
.sheet-title { font-size: 17px; font-weight: 800; margin: 0 0 10px; text-align: center; }
.hidden { display: none !important; }
.close-sheet-btn { width: 100%; margin-top: 14px; padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: transparent; color: var(--text-dim); font-size: 14px; }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); transform: translate(-50%, 20px);
  background: rgba(20, 15, 40, 0.95); border: 1px solid var(--border); color: var(--text); padding: 10px 18px;
  border-radius: 999px; font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s ease;
  z-index: 30; max-width: 85vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
