:root {
  --bg: #07070d;
  --panel: rgba(22, 22, 36, 0.78);
  --panel-2: #1c1c2e;
  --line: rgba(255, 255, 255, 0.07);
  --text: #f4f4fa;
  --muted: #8a8aa6;
  --gold: #f7c548;
  --gold-2: #ff9a1f;
  --green: #2ee59d;
  --red: #ff4d6d;
  --violet: #8b5cf6;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 500 15px/1.4 Inter, system-ui, sans-serif;
  overflow-x: hidden;
  user-select: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

.glow { position: fixed; border-radius: 50%; filter: blur(90px); opacity: .35; pointer-events: none; z-index: 0; }
.glow-a { width: 340px; height: 340px; background: var(--violet); top: -120px; left: -120px; }
.glow-b { width: 300px; height: 300px; background: var(--gold-2); bottom: 40px; right: -140px; opacity: .18; }

#app { position: relative; z-index: 1; max-width: 520px; margin: 0 auto; min-height: 100%; padding: 0 14px calc(90px + var(--safe-b)); }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; position: sticky; top: 0; z-index: 5; backdrop-filter: blur(12px); }
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
  font: 800 18px Unbounded, sans-serif; color: #1a1205;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  box-shadow: 0 6px 20px rgba(247, 197, 72, .35);
}
.brand-name { font: 800 16px Unbounded, sans-serif; letter-spacing: .08em; }
.balance {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 14px;
  background: var(--panel); border: 1px solid var(--line); font: 700 15px Unbounded, sans-serif;
}
.coin { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff3c4, var(--gold) 45%, var(--gold-2)); box-shadow: 0 0 10px rgba(247,197,72,.6); }
.tag { font: 700 9px Inter; letter-spacing: .08em; padding: 2px 5px; border-radius: 6px; background: rgba(139,92,246,.25); color: #c4b5fd; }
.balance.bump { animation: bump .45s ease; }
@keyframes bump { 40% { transform: scale(1.08); } }

/* ---------- common ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; backdrop-filter: blur(14px); margin-bottom: 12px; }
h2 { font: 700 18px Unbounded, sans-serif; margin: 6px 0 14px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); margin-bottom: 12px; }
.seg button { padding: 10px; border-radius: 10px; font-weight: 600; color: var(--muted); transition: .2s; }
.seg button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px rgba(255,255,255,.08); }

.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
.game { display: none; }
.game.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.bet-row { display: flex; gap: 6px; }
.bet-row input {
  flex: 1; min-width: 0; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(0,0,0,.35); font-weight: 700; outline: none;
}
.bet-row input:focus { border-color: rgba(247,197,72,.5); }
.bet-row button { padding: 0 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; font-size: 13px; }
.bet-row button:active { transform: scale(.95); }

.cta {
  display: block; width: 100%; margin-top: 14px; padding: 16px; border-radius: 16px;
  font: 800 16px Unbounded, sans-serif; letter-spacing: .02em; color: #1a1205;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  box-shadow: 0 10px 30px rgba(255,154,31,.3), inset 0 1px 0 rgba(255,255,255,.4);
  transition: transform .1s, filter .2s;
}
.cta:active { transform: scale(.98); }
.cta:disabled { filter: grayscale(.6) brightness(.7); }
.cta.ghost { background: var(--panel-2); color: var(--text); box-shadow: none; border: 1px solid var(--line); }
.cta.cashout { background: linear-gradient(135deg, #3cf0aa, #14b87a); box-shadow: 0 10px 30px rgba(46,229,157,.3); }

/* ---------- dice ---------- */
.stage { text-align: center; }
.roll { font: 800 56px/1 Unbounded, sans-serif; margin-top: 8px; transition: color .2s; }
.roll.win { color: var(--green); text-shadow: 0 0 30px rgba(46,229,157,.5); }
.roll.lose { color: var(--red); text-shadow: 0 0 30px rgba(255,77,109,.4); }
.roll-label { color: var(--muted); font-size: 13px; margin-top: 6px; min-height: 18px; }

.slider-wrap { position: relative; margin: 34px 4px 8px; }
.track { height: 12px; border-radius: 8px; }
.slider-wrap input[type=range] {
  position: absolute; inset: -10px 0 auto; width: 100%; height: 32px; margin: 0; background: none;
  -webkit-appearance: none; appearance: none;
}
.slider-wrap input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 28px; height: 28px; border-radius: 9px;
  background: linear-gradient(135deg, #fff, #d9d9ec); box-shadow: 0 4px 14px rgba(0,0,0,.5); border: 3px solid var(--gold);
}
.slider-wrap input[type=range]::-moz-range-thumb { width: 24px; height: 24px; border-radius: 9px; background: #fff; border: 3px solid var(--gold); }
.marker { position: absolute; top: -34px; transform: translateX(-50%); transition: left .5s cubic-bezier(.2,.8,.2,1); opacity: 0; pointer-events: none; }
.marker.show { opacity: 1; }
.marker span { display: block; padding: 3px 7px; border-radius: 8px; font: 700 12px Unbounded; background: var(--panel-2); border: 1px solid var(--line); }
.marker.win span { color: var(--green); border-color: rgba(46,229,157,.5); }
.marker.lose span { color: var(--red); border-color: rgba(255,77,109,.5); }
.scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 10px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.stats div, .mines-head div { background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; }
.stats small, .mines-head small { display: block; color: var(--muted); font-size: 11px; }
.stats b, .mines-head b { font: 700 15px Unbounded, sans-serif; }
.profit { margin-top: 12px; font-size: 13px; color: var(--muted); }
.profit b { color: var(--gold); }

/* ---------- mines ---------- */
.mines-head { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
#minesMult { color: var(--gold); }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tile {
  aspect-ratio: 1; border-radius: 12px; font-size: 26px; display: grid; place-items: center;
  background: linear-gradient(160deg, #2a2a44, #1b1b2c); border: 1px solid rgba(255,255,255,.06);
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.35); transition: transform .12s, background .2s, opacity .3s;
}
.grid.live .tile:not(.open):hover { background: linear-gradient(160deg, #34345a, #22223a); }
.grid.live .tile:not(.open):active { transform: scale(.92); }
.tile.open { animation: flip .35s ease; box-shadow: none; }
.tile.gem { background: radial-gradient(circle, rgba(46,229,157,.25), rgba(46,229,157,.05)); border-color: rgba(46,229,157,.5); }
.tile.mine { background: radial-gradient(circle, rgba(255,77,109,.35), rgba(255,77,109,.05)); border-color: rgba(255,77,109,.6); }
.tile.ghost { opacity: .4; }
@keyframes flip { 0% { transform: rotateY(90deg) scale(.8); } 100% { transform: none; } }

.mines-count { margin-bottom: 12px; }
.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.chips button { padding: 9px 0; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-weight: 700; }
.chips button.active { border-color: var(--gold); color: var(--gold); }
.chips button:disabled { opacity: .5; }

/* ---------- history ---------- */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.history .ico { font-size: 22px; }
.history .info { flex: 1; }
.history .info b { display: block; }
.history .info small { color: var(--muted); font-size: 12px; }
.history .res { text-align: right; font: 700 14px Unbounded; }
.history .res.win { color: var(--green); }
.history .res.lose { color: var(--red); }
.history .res small { display: block; font: 500 11px Inter; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* ---------- fair ---------- */
.fair label { margin-top: 14px; }
.fair p { margin: 0; font-size: 13px; }
code { display: block; padding: 10px 12px; border-radius: 10px; background: rgba(0,0,0,.4); border: 1px solid var(--line); font: 12px ui-monospace, Menlo, monospace; word-break: break-all; user-select: text; }

/* ---------- nav ---------- */
.bottom {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b)); z-index: 10;
  width: calc(100% - 28px); max-width: 492px; display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px; border-radius: 20px; background: rgba(18, 18, 30, .9); border: 1px solid var(--line); backdrop-filter: blur(16px);
}
.bottom button { padding: 8px 0; border-radius: 14px; font-size: 11px; font-weight: 600; color: var(--muted); display: grid; gap: 2px; justify-items: center; }
.bottom button span { font-size: 20px; }
.bottom button.active { color: var(--text); background: var(--panel-2); }

/* ---------- modal & toast ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(4,4,10,.8); backdrop-filter: blur(8px); }
.modal-card { width: 100%; max-width: 360px; text-align: center; padding: 26px 20px; border-radius: 24px; background: var(--panel-2); border: 1px solid var(--line); }
.modal-card h3 { font: 700 20px Unbounded; margin: 14px 0 8px; }
.modal-card p { font-size: 14px; margin: 0 0 6px; }
.big-badge { display: inline-grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; font: 800 22px Unbounded; color: #1a1205; background: linear-gradient(135deg, var(--gold), var(--gold-2)); }

.toast {
  position: fixed; left: 50%; top: 16px; transform: translate(-50%, -140%); z-index: 60;
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 14px; font-weight: 600; font-size: 14px;
  background: var(--panel-2); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.5); transition: transform .3s;
}
.toast.show { transform: translate(-50%, 0); }
.toast.err { border-color: rgba(255,77,109,.5); }
.toast.ok { border-color: rgba(46,229,157,.5); }

/* ---------- arena: lobby ---------- */
.game-tabs { grid-auto-columns: 1fr; }
.arena-intro { text-align: center; }
.arena-hero { font-size: 44px; filter: drop-shadow(0 6px 18px rgba(46,229,157,.4)); }
.arena-intro h3 { font: 800 20px Unbounded, sans-serif; margin: 6px 0 4px; }
.arena-intro p { margin: 0 0 10px; font-size: 13px; }
.rules { list-style: none; margin: 0; padding: 0; text-align: left; display: grid; gap: 6px; font-size: 13px; }
.rules li { padding: 8px 10px; border-radius: 10px; background: rgba(0,0,0,.25); border: 1px solid var(--line); }
.rules b { color: var(--gold); }
.rooms { display: grid; gap: 10px; }
.room { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin: 0; }
.room-stake small { display: block; color: var(--muted); font-size: 11px; }
.room-stake b { font: 800 18px Unbounded, sans-serif; color: var(--gold); }
.room-info { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.room-btn { width: auto; margin: 0; padding: 12px 18px; font-size: 14px; }

/* ---------- arena: game ---------- */
body.no-scroll { overflow: hidden; }
.arena { position: fixed; inset: 0; z-index: 40; background: #07070d; touch-action: none; }
.arena canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.a-top { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
.a-val { padding: 8px 12px; border-radius: 14px; background: rgba(18,18,30,.75); border: 1px solid var(--line); backdrop-filter: blur(8px); }
.a-val small { display: block; font-size: 10px; color: var(--muted); }
.a-val b { font: 800 20px Unbounded, sans-serif; color: var(--gold); }
.a-profit { display: block; font: 700 12px Unbounded; color: var(--muted); }
.a-profit.up { color: var(--green); }
.a-profit.down { color: var(--red); }
.a-lb { margin: 0; padding: 8px 10px; list-style: none; min-width: 140px; border-radius: 14px; background: rgba(18,18,30,.65); border: 1px solid var(--line); font-size: 11px; counter-reset: lb; }
.a-lb li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; color: rgba(255,255,255,.75); counter-increment: lb; }
.a-lb li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 90px; }
.a-lb li span::before { content: counter(lb) ". "; color: var(--muted); }
.a-lb li.me { color: var(--gold); font-weight: 700; }
.a-center { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); padding: 10px 16px; border-radius: 14px; background: rgba(18,18,30,.8); border: 1px solid var(--line); font-weight: 600; font-size: 14px; text-align: center; pointer-events: none; max-width: 80%; }
.a-bottom { position: absolute; left: 0; right: 0; bottom: calc(16px + var(--safe-b)); display: flex; justify-content: space-between; align-items: center; padding: 0 16px; pointer-events: none; }
.a-btn { pointer-events: auto; user-select: none; -webkit-user-select: none; touch-action: none; }
.a-btn.boost { width: 72px; height: 72px; border-radius: 50%; font-size: 30px; background: rgba(139,92,246,.25); border: 2px solid rgba(139,92,246,.6); box-shadow: 0 0 20px rgba(139,92,246,.3); transition: transform .1s, background .2s; }
.a-btn.boost.on { transform: scale(.92); background: rgba(139,92,246,.6); }
.a-btn.cash { padding: 16px 20px; border-radius: 18px; font: 800 15px Unbounded, sans-serif; color: #04140c; background: linear-gradient(135deg, #3cf0aa, #14b87a); box-shadow: 0 10px 30px rgba(46,229,157,.35); }
.a-btn.cash.busy { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #1a1205; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.arena .modal { z-index: 45; }
