:root {
  --bg: #0a0910;
  --panel: #15151c;
  --line: #20202b;
  --text: #f1f2f6;
  --hint: #8b90a0;
  --green: #2fa85a;
  --green-bright: #3ddc84;
  --red: #e23b4e;
  --red-bright: #ff5667;
  --gold: #f4c84a;
  --blue: #4a86ff;
  --accent: #7c5cff;
  --accent-press: #6a49f0;
  --pill: #1c1c24;
  --felt-1: #1b5e43;
  --felt-2: #0f3b2c;
  --card-w: 60px;
  --card-h: 84px;
  --deal-dur: .42s;   /* per-card deal animation; #app.slow scales these up (slow mode) */
  --flip-dur: .5s;    /* hole-card flip */
}
/* slow mode: longer deal + flip; JS scales the stagger/reveal delays by the same factor */
#app.slow { --deal-dur: 1.3s; --flip-dur: 1.1s; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; -webkit-user-select: none; user-select: none; }
html { background: #0a0910; }
body { background: radial-gradient(1100px 640px at 50% -6%, #1d1830 0%, #120f1c 44%, #0a0910 100%) no-repeat fixed; }
#app { display: flex; flex-direction: column; min-height: 100vh; width: 100%; max-width: 460px;
  margin: 0 auto; padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom); gap: 10px; }

/* ---------- top bar ---------- */
#topbar { display: flex; align-items: center; gap: 8px; padding-top: 8px; }
.balance { font-weight: 800; font-size: 17px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn { font-size: 16px; padding: 7px 9px; border-radius: 9px; border: 0; background: var(--pill);
  color: #c9ccd6; line-height: 1; cursor: pointer; }
.icon-btn:active { background: #262631; }
.icon-btn.off { opacity: 0.55; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green-bright);
  box-shadow: 0 0 8px var(--green-bright); transition: background .2s, box-shadow .2s; }
.dot.off { background: var(--red); box-shadow: none; }

/* ---------- table / felt ---------- */
#table { position: relative; border-radius: 20px; overflow: hidden;
  padding: 16px 12px 18px; min-height: 360px; display: flex; flex-direction: column;
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(124,92,255,.18), transparent 60%),
    radial-gradient(90% 70% at 50% 40%, var(--felt-1), var(--felt-2) 78%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04), inset 0 30px 60px rgba(0,0,0,.35),
    0 16px 40px rgba(0,0,0,.45); }
/* faint felt texture */
#table::before { content: ""; position: absolute; inset: 0; opacity: .5; pointer-events: none;
  background-image: radial-gradient(circle at 30% 20%, rgba(255,255,255,.04) 0, transparent 38%),
    radial-gradient(circle at 75% 70%, rgba(0,0,0,.18) 0, transparent 45%); }

.rail { display: flex; justify-content: center; min-height: 22px; }
.felt-label { text-align: center; color: rgba(255,255,255,.62); font-size: 11px; letter-spacing: 1.5px;
  font-weight: 700; margin: 8px 0; text-transform: uppercase; }
.felt-label b { color: var(--gold); }
.shoe { position: absolute; top: 12px; right: 12px; width: 30px; height: 42px; border-radius: 6px;
  background: linear-gradient(135deg, #2a2150, #160f2e); box-shadow: inset 0 0 0 2px rgba(124,92,255,.5),
    0 4px 10px rgba(0,0,0,.5); opacity: .9; }
.shoe::after { content: ""; position: absolute; inset: 5px; border-radius: 3px;
  background: repeating-linear-gradient(45deg, rgba(124,92,255,.25) 0 3px, transparent 3px 6px); }

/* ---------- hands ---------- */
.hand-cards { display: flex; justify-content: center; gap: 4px; min-height: var(--card-h); }
.dealer-cards { margin-bottom: 2px; }
.boxes { display: flex; justify-content: center; align-items: flex-start; gap: 8px; margin-top: auto;
  flex-wrap: nowrap; }
.box { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: 0 1 auto;
  min-width: 0; transition: transform .2s; }
.box-hands { display: flex; gap: 6px; }
.subhand { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 5px 5px 3px;
  border-radius: 12px; border: 2px solid transparent; transition: border-color .25s, box-shadow .25s, background .25s; }
/* the active hand glows */
.subhand.active { border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(244,200,74,.55); background: rgba(244,200,74,.07);
  animation: activePulse 1.6s ease-in-out infinite; }
@keyframes activePulse { 0%,100% { box-shadow: 0 0 0 1px var(--gold), 0 0 14px rgba(244,200,74,.4); }
  50% { box-shadow: 0 0 0 1px var(--gold), 0 0 24px rgba(244,200,74,.75); } }
.subhand.won { border-color: var(--green-bright); box-shadow: 0 0 20px rgba(61,220,132,.5); }
.subhand.lost { opacity: .62; }
.subhand.push { border-color: #c7ccd6; }

/* overlapped cards within a hand (so 4+ cards still fit) */
.subhand .hand-cards { gap: 0; }
.subhand .hand-cards .card { margin-left: -22px; }
.subhand .hand-cards .card:first-child { margin-left: 0; }
.dealer-cards .card { margin-left: -18px; }
.dealer-cards .card:first-child { margin-left: 0; }

/* ---------- card ---------- */
/* The OUTER .card owns position/deal motion (translate/scale/rotateZ); the INNER owns the 3D flip
   (rotateY) — separating them lets a card slide in face-up without the deal transform fighting the
   flip transform. */
.card { position: relative; width: var(--card-w); height: var(--card-h); flex: 0 0 auto; perspective: 600px; }
.card.dealing { animation: dealIn var(--deal-dur) cubic-bezier(.2,.8,.25,1) both; }
@keyframes dealIn {
  from { transform: translate(120px, -150px) rotate(22deg) scale(.7); opacity: 0; }
  60%  { opacity: 1; }
  to   { transform: translate(0,0) rotate(0) scale(1); opacity: 1; } }
.card-inner { position: absolute; inset: 0; transform-style: preserve-3d; will-change: transform;
  transition: transform var(--flip-dur) cubic-bezier(.2,.7,.3,1); }
.card-inner.faceup { transform: rotateY(180deg); }
.face, .back { position: absolute; inset: 0; border-radius: 8px; backface-visibility: hidden;
  -webkit-backface-visibility: hidden; box-shadow: 0 3px 8px rgba(0,0,0,.45); overflow: hidden; }
.face { background: linear-gradient(160deg, #ffffff, #eef0f6); transform: rotateY(180deg);
  display: flex; flex-direction: column; padding: 4px 5px; }
.back { background: linear-gradient(150deg, #3a2a72 0%, #221546 60%, #160f2e 100%);
  box-shadow: inset 0 0 0 2px rgba(124,92,255,.45), 0 3px 8px rgba(0,0,0,.5); }
.back::after { content: "🃏"; position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font-size: calc(var(--card-w) * 0.43); opacity: .85; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
/* fonts scale with --card-w so a row that fitRow() shrinks stays proportional/legible */
.rank { font-weight: 800; font-size: calc(var(--card-w) * 0.27); line-height: 1; }
.pip { font-size: calc(var(--card-w) * 0.25); line-height: 1; }
.mid { flex: 1; display: flex; align-items: center; justify-content: center; font-size: calc(var(--card-w) * 0.43); }
.br { align-self: flex-end; transform: rotate(180deg); display: flex; flex-direction: column; align-items: center; }
.face.red { color: #e0244a; }
.face.black { color: #16181d; }
.corner { display: flex; flex-direction: column; align-items: center; }

/* ---------- hand total badge ---------- */
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 30px;
  height: 22px; padding: 0 7px; border-radius: 11px; font-weight: 800; font-size: 12px;
  background: rgba(8,8,14,.7); color: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4);
  font-variant-numeric: tabular-nums; }
.badge.win { background: var(--green-bright); color: #06230f; }
.badge.bust, .badge.lose { background: var(--red); color: #fff; }
.badge.push { background: #c7ccd6; color: #14141a; }
.badge.bj { background: linear-gradient(135deg, #ffd75e, #e79a18); color: #1a1a1a; }
.dealer-badge { margin: 0 auto; }
.box-bet { font-size: 11px; color: rgba(255,255,255,.7); font-weight: 700; }
.box-payout { font-size: 11px; font-weight: 800; }
.box-payout.win { color: var(--green-bright); } .box-payout.lose { color: var(--red-bright); }
.box-payout.push { color: #d4d8e0; }

/* ---------- result banner ---------- */
.result-banner { position: absolute; left: 50%; top: 46%; transform: translate(-50%,-50%) scale(1);
  padding: 12px 22px; border-radius: 14px; font-weight: 900; font-size: 22px; pointer-events: none;
  box-shadow: 0 10px 34px rgba(0,0,0,.55); animation: bannerPop .35s cubic-bezier(.2,.9,.3,1.3) both;
  text-align: center; z-index: 5; }
@keyframes bannerPop { from { transform: translate(-50%,-50%) scale(.7); opacity: 0; }
  to { transform: translate(-50%,-50%) scale(1); opacity: 1; } }
.result-banner.win { background: linear-gradient(135deg, var(--green-bright), #1f9d5b); color: #06230f; }
.result-banner.lose { background: linear-gradient(135deg, #3a3a44, #23232b); color: #ff8b97; }
.result-banner.push { background: linear-gradient(135deg, #cfd4de, #9aa0ad); color: #14141a; }
.result-banner.bj { background: linear-gradient(135deg, #ffe27a, #e79a18); color: #1a1a1a;
  box-shadow: 0 0 40px rgba(244,200,74,.6); }

/* win/bust feedback on the table */
#table.flash-win { animation: flashWin .6s ease; }
#table.flash-bust { animation: flashBust .5s ease; }
@keyframes flashWin { 0%,100% { box-shadow: inset 0 0 0 1px rgba(255,255,255,.04), inset 0 30px 60px rgba(0,0,0,.35), 0 16px 40px rgba(0,0,0,.45); }
  40% { box-shadow: inset 0 0 0 2px rgba(61,220,132,.7), inset 0 0 60px rgba(61,220,132,.35), 0 16px 40px rgba(0,0,0,.45); } }
@keyframes flashBust { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }

/* ---------- controls ---------- */
#controls { display: flex; flex-direction: column; gap: 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.act { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 15px 8px;
  border: 0; border-radius: 13px; font-size: 15px; font-weight: 800; color: #fff; cursor: pointer;
  transition: transform .08s, opacity .15s, filter .15s; }
.act .act-i { font-size: 16px; }
.act:active { transform: scale(.96); }
.act-hit    { background: linear-gradient(135deg, #34c46e, #1f9d5b); }
.act-stand  { background: linear-gradient(135deg, #ff5667, #d12d40); }
.act-split  { background: linear-gradient(135deg, #5a93ff, #2f6bdc); }
.act-double { background: linear-gradient(135deg, #ffd35e, #e79a18); color: #2a2008; }
.act[disabled] { filter: grayscale(.8) brightness(.6); opacity: .5; cursor: default; pointer-events: none; }

.betpanel { display: flex; flex-direction: column; gap: 10px; }
.field { background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 10px 12px; }
.field-label { font-size: 12px; color: var(--hint); margin-bottom: 7px; font-weight: 600; }
.field-row { display: flex; gap: 8px; align-items: center; }
.field-row input { flex: 1; min-width: 0; background: #0e0e14; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 11px 12px; font-size: 17px; font-weight: 700; outline: none;
  font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.field-row input::-webkit-outer-spin-button, .field-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.chip { flex: 0 0 auto; min-width: 46px; background: var(--pill); border: 1px solid var(--line); color: #d6d9e2;
  border-radius: 10px; padding: 11px 10px; font-size: 14px; font-weight: 800; cursor: pointer; }
.chip:active { background: #262631; }
.seats { display: flex; gap: 8px; }
.seat { flex: 1; background: var(--pill); border: 1px solid var(--line); color: #d6d9e2; border-radius: 11px;
  padding: 12px 0; font-size: 17px; font-weight: 800; cursor: pointer; transition: background .15s, color .15s; }
.seat.active { background: linear-gradient(135deg, var(--accent), var(--accent-press)); color: #fff;
  border-color: transparent; box-shadow: 0 4px 14px rgba(124,92,255,.4); }
.deal { width: 100%; padding: 16px; border: 0; border-radius: 14px; font-size: 17px; font-weight: 800;
  color: #fff; cursor: pointer; background: linear-gradient(135deg, var(--accent), var(--accent-press));
  box-shadow: 0 6px 20px rgba(124,92,255,.4); transition: transform .08s, filter .15s; }
.deal:active { transform: scale(.98); }
.deal[disabled] { filter: grayscale(.7) brightness(.6); opacity: .6; pointer-events: none; }

.sound-row { display: flex; align-items: center; gap: 9px; padding: 2px 2px 0; }
.snd-btn { flex: 0 0 auto; height: 34px; padding: 0 11px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--pill); color: #c9ccd6; font-size: 14px; font-weight: 700;
  line-height: 1; cursor: pointer; white-space: nowrap; }
.snd-btn:active { background: #262631; }
.snd-btn.off { opacity: .55; }
.slow-btn { margin-left: auto; }   /* far right — opposite the volume slider/button on the left */
.slow-btn.on { background: linear-gradient(135deg, var(--accent), var(--accent-press)); color: #fff;
  border-color: transparent; box-shadow: 0 4px 14px rgba(124,92,255,.35); }
.vol { flex: 0 1 150px; max-width: 150px; accent-color: var(--accent); height: 6px; }
.message { min-height: 18px; font-size: 13px; color: var(--amber, #e7b743); text-align: center; }
.hidden { display: none !important; }

/* ---------- fairness modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(6,6,11,.72); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 50; backdrop-filter: blur(3px); }
.modal-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; overflow: hidden; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px;
  font-weight: 800; border-bottom: 1px solid var(--line); }
.modal-close { background: var(--pill); border: 0; color: #c9ccd6; border-radius: 8px; width: 30px;
  height: 30px; font-size: 15px; cursor: pointer; }
.modal-body { padding: 14px 16px; }
.fair-label { font-size: 11px; color: var(--hint); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .5px; }
.fair-code { display: block; word-break: break-all; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px; background: #0e0e14; border: 1px solid var(--line); border-radius: 8px; padding: 8px;
  color: #b9c0cf; }
.fair-note { font-size: 12px; color: var(--hint); margin-top: 12px; line-height: 1.5; }
.fair-note b { color: #d7dbe5; }

/* compact for 3 boxes / small phones */
@media (max-width: 380px) { :root { --card-w: 50px; --card-h: 70px; }
  .subhand .hand-cards .card { margin-left: -18px; } }
/* on phones, 3 boxes get smaller cards so even long draw-outs fit (JS also tightens the overlap) */
@media (max-width: 719px) { #app.boxes-3 { --card-w: 50px; --card-h: 70px; } }

/* ---------- desktop (mouse) single-column: fill the wider, shorter Mini-App window ---------- */
@media (hover: hover) and (pointer: fine) and (max-width: 719px) {
  #app { max-width: 100%; }
}

/* ---------- desktop / wide window: bet panel + seats + Раздать + sound move to a LEFT column
   beside the table (mirrors how crash/slide reflow the bet/players panel on desktop) ---------- */
@media (min-width: 720px) {
  #app {
    max-width: min(96vw, 1040px);
    display: grid;
    column-gap: 16px;
    row-gap: 10px;
    grid-template-columns: 320px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "top      top"
      "controls table";
    align-items: start;
  }
  #topbar   { grid-area: top; }
  #controls { grid-area: controls; align-self: center; }   /* vertically centre the panel */
  #table    { grid-area: table; min-height: 460px; }
}
