:root {
  --bg: var(--tg-theme-bg-color, #0f1218);
  --card: var(--tg-theme-secondary-bg-color, #1a1f2a);
  --text: var(--tg-theme-text-color, #f2f4f8);
  --muted: var(--tg-theme-hint-color, #8a93a6);
  --accent: var(--tg-theme-button-color, #3d8bfd);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --win: #2fbf71;
  --lose: #e5484d;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main { padding: 16px 16px 90px; max-width: 520px; margin: 0 auto; }
h3 { margin: 20px 0 8px; font-size: 15px; }
code { font-size: 11px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.big { font-size: 22px; font-weight: 700; }
.tab { display: none; }
.tab.active { display: block; }

button { font: inherit; border: 0; cursor: pointer; border-radius: 12px; }
button.primary { width: 100%; padding: 14px; background: var(--accent); color: var(--accent-text); font-weight: 600; margin: 12px 0; }
button.primary:disabled { opacity: .4; }
button.ghost { background: none; color: var(--text); padding: 6px 10px; }
button.small { padding: 6px 10px; background: var(--card); color: var(--text); font-size: 13px; }

nav {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex;
  background: var(--card); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
nav button { flex: 1; background: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; font-size: 20px; padding: 4px; }
nav button span { font-size: 11px; }
nav button.active { color: var(--accent); }

.card { background: var(--card); border-radius: 14px; padding: 12px; }
.list > * + * { margin-top: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }

.gift { background: var(--card); border-radius: 14px; padding: 8px; text-align: center; position: relative; border: 2px solid transparent; }
.gift img { width: 100%; aspect-ratio: 1; border-radius: 10px; object-fit: cover; background: #0003; }
.gift .name { font-size: 12px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gift .val { font-size: 12px; color: var(--muted); }
.gift.selected { border-color: var(--accent); }
.gift.disabled { opacity: .4; pointer-events: none; }
.gift .badge { position: absolute; top: 12px; left: 12px; font-size: 10px; background: #000a; color: #fff; padding: 2px 6px; border-radius: 6px; }

/* PvP wheel */
.wheel-wrap, .upgrade-ring { position: relative; width: 260px; height: 260px; margin: 8px auto 4px; }
.wheel { width: 100%; height: 100%; border-radius: 50%; background: var(--card); transition: transform 6s cubic-bezier(.12,.8,.18,1); }
.wheel::after { content: ""; position: absolute; inset: 38px; border-radius: 50%; background: var(--bg); }
.wheel-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.pointer { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 0; height: 0; z-index: 2;
  border-left: 10px solid transparent; border-right: 10px solid transparent; border-top: 18px solid var(--text); }

.player { display: flex; align-items: center; gap: 10px; }
.player .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.player .info { flex: 1; min-width: 0; }
.player .thumbs { display: flex; gap: 4px; margin-top: 4px; }
.player .thumbs img { width: 28px; height: 28px; border-radius: 6px; }
.player .chance { font-weight: 700; }

.fair { margin-top: 16px; }
.fair summary { color: var(--muted); cursor: pointer; }
.history-row { font-size: 12px; padding: 6px 0; border-top: 1px solid #ffffff14; word-break: break-all; }

/* Upgrade */
.upgrade-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--card); stroke-width: 12; }
.ring-arc { fill: none; stroke: var(--win); stroke-width: 12; stroke-dasharray: 0 327; transition: stroke-dasharray .3s; }
.needle { position: absolute; left: 50%; top: 0; width: 4px; height: 50%; margin-left: -2px; transform-origin: 50% 100%;
  transition: transform 4s cubic-bezier(.12,.8,.18,1); }
.needle::before { content: ""; position: absolute; top: -2px; left: -6px; border-left: 8px solid transparent; border-right: 8px solid transparent; border-top: 16px solid var(--text); }
.up-row { display: flex; gap: 8px; align-items: center; }
.up-slot { flex: 1; background: var(--card); border-radius: 14px; padding: 10px; text-align: center; font-size: 12px; color: var(--muted); }
.up-slot b { color: var(--text); font-size: 14px; }
.arrow { font-size: 20px; color: var(--muted); }

/* Cases */
.case { display: flex; justify-content: space-between; align-items: center; }
.case-items { margin: 8px 0; }
.case-item { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #ffffff14; font-size: 14px; }
.prize { text-align: center; animation: pop .5s ease-out; }
.prize img { width: 180px; border-radius: 16px; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Modal & toast */
.modal { position: fixed; inset: 0; background: #0009; display: flex; align-items: flex-end; z-index: 10; }
.modal.hidden, .toast.hidden { display: none; }
.sheet { background: var(--bg); width: 100%; max-height: 85vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: 80px; background: var(--card); padding: 12px 14px; border-radius: 12px; z-index: 20; box-shadow: 0 6px 24px #0006; }
.toast.error { border-left: 4px solid var(--lose); }
.toast.ok { border-left: 4px solid var(--win); }
.deposit { margin-bottom: 12px; }
.deposit p { margin: 4px 0 0; }

/* Shared form bits */
input[type="number"], input[type="text"], input[type="search"] {
  width: 100%; padding: 10px 12px; margin-top: 4px; border-radius: 10px; border: 1px solid #ffffff1f;
  background: var(--bg); color: var(--text); font: inherit;
}
label { display: block; font-size: 12px; color: var(--muted); }
.field-row { display: flex; gap: 8px; }
.field-row > * { flex: 1; }
.quick { display: flex; gap: 6px; margin: 8px 0; }
.quick button { flex: 1; }
button.wide { width: 100%; }
[hidden] { display: none !important; }

/* Crash */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.chip { flex: none; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 8px; background: var(--card); }
.chip.low { color: var(--lose); }
.chip.mid { color: var(--accent); }
.chip.high { color: var(--win); }
.crash-stage { position: relative; height: 220px; border-radius: 16px; overflow: hidden; margin: 6px 0 10px;
  background: radial-gradient(120% 100% at 0% 100%, #3d8bfd22, transparent 60%), var(--card); }
.crash-stage canvas { width: 100%; height: 100%; display: block; }
.crash-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.crash-x { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; }
.crash-x.crashed { color: var(--lose); }
.crash-x.won { color: var(--win); }
.crash-panel { margin-bottom: 10px; }
.crash-balance { margin-bottom: 8px; }
#crash-action.cashout { background: var(--win); }
.bet-row { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.bet-row .win { color: var(--win); font-weight: 600; }

/* Inventory */
.balance-card { margin-bottom: 8px; }

/* Admin */
.subtabs { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.subtabs button { padding: 8px 12px; background: var(--card); color: var(--muted); font-size: 13px; flex: none; }
.subtabs button.active { background: var(--accent); color: var(--accent-text); }
.sub { display: none; }
.sub.active { display: block; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; }
.stat .value.neg { color: var(--lose); }
.stat .value.pos { color: var(--win); }
.row { display: flex; align-items: center; gap: 8px; }
.row .grow { flex: 1; min-width: 0; }
.row input { margin: 0; width: 90px; }
.tag { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: #ffffff14; color: var(--muted); }
.tag.auto { color: var(--win); }
.tag.warn { color: #f5b942; }
.gift .badge.rare { background: linear-gradient(135deg, #f5d27a, #c8902e); color: #2a1a00; font-weight: 700; }
.card.row img.thumb { width: 44px; height: 44px; border-radius: 10px; flex: none; object-fit: cover; }
.case-form .item-row { display: flex; gap: 6px; margin-top: 6px; }
.case-form .item-row input:first-child { flex: 3; }
.case-form .item-row input:last-child { flex: 1; }
.inactive { opacity: .5; }
.steps { padding-left: 20px; margin: 12px 0; }
.steps li + li { margin-top: 6px; }

/* Profile */
.profile-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.avatar { width: 52px; height: 52px; flex: none; border-radius: 50%; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), #a855f7); color: #fff; font-size: 22px; font-weight: 700; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.pf-name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-head .grow { flex: 1; min-width: 0; }
.pf-balance { text-align: right; }
.pf-balance .big { font-size: 18px; }
.mode-stat .row { margin-bottom: 2px; }
.history-item { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.history-item .grow { flex: 1; min-width: 0; }
.history-item .h-icon { font-size: 20px; }
.history-item .pos, .stat .value.pos { color: var(--win); }
.history-item .neg { color: var(--lose); }
.history-item b { white-space: nowrap; }
.grid > p { grid-column: 1 / -1; margin: 0; }
.odds-preview { color: var(--muted); padding-top: 4px; border-top: 1px solid #ffffff14; }
.case-form .item-row { align-items: center; }
.item-chance { width: 48px; text-align: right; flex: none; }
#odds-reset { margin-bottom: 8px; }
.case-form .item-row input[type="number"] { flex: 1; }

/* Case covers */
.case { gap: 10px; }
.case .grow { flex: 1; min-width: 0; }
.case-thumb { width: 48px; height: 48px; flex: none; border-radius: 10px; object-fit: cover; background: #0003;
  display: inline-flex; align-items: center; justify-content: center; font-size: 26px; }
.case-cover { display: block; width: 100%; max-width: 240px; aspect-ratio: 1; object-fit: cover; margin: 0 auto 8px; border-radius: 16px; }
.case-photo-actions { margin-top: 8px; flex-wrap: wrap; }

/* Mines */
nav button span { font-size: 10px; }
.mines-info { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.mines-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 10px; }
.cell { aspect-ratio: 1; border-radius: 12px; background: var(--card); font-size: 24px; display: flex; align-items: center; justify-content: center;
  border: 2px solid transparent; transition: transform .1s, background .2s; padding: 0; }
.cell:not(:disabled):active { transform: scale(.94); }
.cell.idle:not(:disabled) { background: linear-gradient(180deg, #ffffff12, #ffffff05), var(--card); }
.cell:disabled { cursor: default; color: var(--text); }
.cell.gem { background: #2fbf7126; border-color: #2fbf7166; animation: pop .25s ease-out; }
.cell.mine { background: #e5484d26; }
.cell.hit { background: var(--lose); border-color: var(--lose); animation: pop .25s ease-out; }
.cell.faded { opacity: .45; }
.mines-panel { margin-bottom: 10px; }
#mines-action.cashout { background: var(--win); }
#mines-presets button.active { background: var(--accent); color: var(--accent-text); }
