:root {
  --bg: var(--tg-theme-bg-color, #0f1115);
  --bg2: var(--tg-theme-secondary-bg-color, #1a1d24);
  --text: var(--tg-theme-text-color, #f2f2f2);
  --hint: var(--tg-theme-hint-color, #8b93a3);
  --btn: var(--tg-theme-button-color, #3390ec);
  --btn-text: var(--tg-theme-button-text-color, #fff);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --win: #37c26b;
  --lose: #e5484d;
  --gold: #f5c542;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; min-height: 100vh;
  user-select: none; -webkit-user-select: none;
}
.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--bg2); }
.who { color: var(--hint); font-size: 14px; }
.balance { font-weight: 700; font-size: 18px; color: var(--gold); transition: transform .2s; }
.balance.bump { transform: scale(1.15); }

.tabs { display: flex; background: var(--bg2); border-bottom: 1px solid rgba(128,128,128,.2); }
.tabs button { flex: 1; padding: 10px 0; font-size: 22px; background: none; border: 0; border-bottom: 3px solid transparent; opacity: .55; cursor: pointer; }
.tabs button.active { opacity: 1; border-bottom-color: var(--btn); }

main { flex: 1; padding: 16px 16px 8px; overflow-y: auto; }
.panel { display: none; }
.panel.active { display: block; }
h2 { font-size: 18px; margin: 0 0 12px; }
.hint { color: var(--hint); font-size: 13px; text-align: center; margin: 6px 0 12px; }
.hint b { color: var(--text); }

.stage { display: flex; justify-content: center; align-items: center; min-height: 140px; margin-bottom: 8px; }

.choices { display: grid; gap: 8px; margin-bottom: 10px; }
.grid2 { grid-template-columns: repeat(2, 1fr); }
.grid3 { grid-template-columns: repeat(3, 1fr); }
.grid4 { grid-template-columns: repeat(4, 1fr); }
.grid6 { grid-template-columns: repeat(6, 1fr); }
.choices button, .choices input {
  padding: 12px 6px; border-radius: 10px; border: 2px solid transparent; font-size: 15px; font-weight: 600;
  background: var(--bg2); color: var(--text); cursor: pointer;
}
.choices button.selected { border-color: var(--btn); background: color-mix(in srgb, var(--btn) 25%, var(--bg2)); }
.choices button:disabled { opacity: .4; }
.rc-red { background: #b3261e !important; color: #fff; }
.rc-black { background: #222 !important; color: #fff; }
.numrow { grid-template-columns: 2fr 1fr; }
.numrow input { text-align: center; font-size: 18px; width: 100%; }

.play {
  width: 100%; padding: 14px; border: 0; border-radius: var(--radius); font-size: 17px; font-weight: 700;
  background: var(--btn); color: var(--btn-text); cursor: pointer; transition: opacity .2s;
}
.play:disabled { opacity: .5; }
.play.secondary { background: var(--bg2); color: var(--text); }
.bonus-row { display: grid; gap: 8px; margin-bottom: 16px; }

/* Кости */
.die {
  width: 96px; height: 96px; background: #fff; border-radius: 18px; padding: 12px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.die span { width: 16px; height: 16px; border-radius: 50%; background: #111; place-self: center; visibility: hidden; }
.die[data-face="1"] span:nth-child(5) { visibility: visible; }
.die[data-face="2"] :is(span:nth-child(3), span:nth-child(7)) { visibility: visible; }
.die[data-face="3"] :is(span:nth-child(3), span:nth-child(5), span:nth-child(7)) { visibility: visible; }
.die[data-face="4"] :is(span:nth-child(1), span:nth-child(3), span:nth-child(7), span:nth-child(9)) { visibility: visible; }
.die[data-face="5"] :is(span:nth-child(1), span:nth-child(3), span:nth-child(5), span:nth-child(7), span:nth-child(9)) { visibility: visible; }
.die[data-face="6"] :is(span:nth-child(1), span:nth-child(3), span:nth-child(4), span:nth-child(6), span:nth-child(7), span:nth-child(9)) { visibility: visible; }
.die.rolling { animation: shake .12s infinite; }
@keyframes shake { 0% { transform: rotate(-12deg) translateX(-3px); } 50% { transform: rotate(12deg) translateX(3px); } 100% { transform: rotate(-12deg); } }

/* Монетка */
.coin { width: 110px; height: 110px; position: relative; transform-style: preserve-3d; transition: transform 1.4s cubic-bezier(.2,.8,.2,1); }
.coin .face {
  position: absolute; inset: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 48px; font-weight: 800; backface-visibility: hidden; color: #5a3d00;
  background: radial-gradient(circle at 35% 35%, #ffe88a, #d9a300 70%, #a67900); border: 4px solid #b58a00;
}
.coin .tails { transform: rotateY(180deg); }

/* КНБ */
.rps-stage { gap: 16px; }
.rps-hand { font-size: 64px; width: 100px; text-align: center; transition: transform .2s; }
.rps-hand.shake { animation: bob .25s infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
.rps-vs { font-weight: 800; color: var(--hint); }

/* Блэкджек */
.bj { background: #0d5c35; border-radius: var(--radius); padding: 12px; min-height: 180px; box-shadow: inset 0 0 40px rgba(0,0,0,.4); }
.bj-row { margin-bottom: 10px; }
.bj-label { color: #cfe9d9; font-size: 13px; margin-bottom: 6px; }
.bj-label span { font-weight: 700; color: #fff; }
.cards { display: flex; gap: 6px; flex-wrap: wrap; min-height: 64px; }
.cardx {
  width: 46px; height: 64px; border-radius: 6px; background: #fff; color: #111;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,.4); animation: dealIn .25s ease-out;
}
.cardx.red { color: #c62828; }
.cardx.back { background: repeating-linear-gradient(45deg, #3b5bdb, #3b5bdb 6px, #2f49b0 6px, #2f49b0 12px); }
@keyframes dealIn { from { transform: translateY(-20px) scale(.8); opacity: 0; } }

/* Слоты */
.reels { display: flex; gap: 10px; }
.reel { width: 80px; height: 90px; border-radius: 12px; background: var(--bg2); display: flex; align-items: center; justify-content: center; font-size: 44px; box-shadow: inset 0 4px 12px rgba(0,0,0,.35); }
.reel.spin { animation: blur .1s infinite; }
@keyframes blur { 50% { filter: blur(2px); transform: translateY(4px); } }
.paytable { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; font-size: 13px; color: var(--hint); margin-bottom: 12px; text-align: center; }
.paytable div { background: var(--bg2); border-radius: 8px; padding: 6px 2px; }

/* Рулетка */
.ball { width: 96px; height: 96px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 40px; font-weight: 800; color: #fff; border: 5px solid var(--gold); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.ball.red { background: #b3261e; } .ball.black { background: #222; } .ball.green { background: #1b8f4a; }
.ball.spin { animation: spin .5s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Профиль, топ */
.card { background: var(--bg2); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 14px; }
.card b { font-size: 16px; }
.top { margin: 0; padding: 0 0 0 20px; }
.top li { padding: 8px 0; border-bottom: 1px solid rgba(128,128,128,.15); display: flex; justify-content: space-between; }
.top li.me { color: var(--gold); font-weight: 700; }

/* Ставка */
.betbar { position: sticky; bottom: 0; background: var(--bg2); padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(128,128,128,.2); }
.betbar[hidden] { display: none; }
.bet-ctl { display: flex; gap: 8px; margin-bottom: 8px; }
.bet-ctl button { width: 48px; border: 0; border-radius: 10px; background: var(--bg); color: var(--text); font-size: 22px; }
.bet-ctl input { flex: 1; text-align: center; font-size: 20px; font-weight: 700; border: 0; border-radius: 10px; padding: 10px; background: var(--bg); color: var(--gold); }
.chips { display: flex; gap: 6px; }
.chips button { flex: 1; padding: 8px 0; border: 0; border-radius: 20px; background: var(--bg); color: var(--text); font-weight: 600; }

.toast {
  position: fixed; left: 50%; top: 110px; transform: translateX(-50%) translateY(-20px);
  background: var(--bg2); color: var(--text); padding: 10px 18px; border-radius: 24px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all .25s; box-shadow: 0 8px 24px rgba(0,0,0,.4); white-space: nowrap; z-index: 10;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.win { color: var(--win); } .toast.lose { color: var(--lose); }
