:root {
  --bg: #0f1013;
  --panel: #17191f;
  --panel-2: #1f222a;
  --line: #2b2f39;
  --text: #ecebe6;
  --muted: #8d919c;
  --accent: #f0b03a;
  --accent-ink: #1a1305;
  --good: #4cd68a;
  --bad: #ff6a6a;
  --felt: #13241d;
  --felt-line: #1f3a2e;
  --cell: 78px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }

#app { max-width: 520px; margin: 0 auto; min-height: 100vh; padding-bottom: calc(76px + var(--safe-bottom)); }

/* ---------- верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: linear-gradient(var(--bg) 82%, rgba(15,16,19,0));
}
.who-label { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); font-weight: 700; }
.who-name { font-size: 15px; font-weight: 600; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.balance { text-align: right; }
.balance-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.balance-value { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.balance-value.bump { animation: bump .45s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.12); color: var(--accent); } 100% { transform: scale(1); } }

main { padding: 4px 16px 0; }
.screen { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- автомат ---------- */
.machine {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 14px 12px;
  box-shadow: inset 0 0 0 1px rgba(240,176,58,.06);
}
.reels {
  position: relative;
  display: flex; gap: 8px; justify-content: center;
  padding: 8px;
  background: #0b0c0f;
  border-radius: 12px;
  border: 1px solid #000;
}
.reel {
  flex: 1; max-width: 110px;
  height: calc(var(--cell) * 3);
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(#15171d, #1c1f27 50%, #15171d);
  -webkit-mask-image: linear-gradient(transparent 0, #000 22%, #000 78%, transparent 100%);
          mask-image: linear-gradient(transparent 0, #000 22%, #000 78%, transparent 100%);
}
.strip { will-change: transform; }
.cell { height: var(--cell); display: flex; align-items: center; justify-content: center; }
.sym { width: calc(var(--cell) - 16px); height: calc(var(--cell) - 16px); filter: drop-shadow(0 2px 3px rgba(0,0,0,.45)); }
.reel.spinning .strip { filter: blur(1.6px); }
.payline {
  position: absolute; left: 0; right: 0; top: 50%; height: 0; pointer-events: none;
  border-top: 2px solid rgba(240,176,58,.75);
  box-shadow: 0 0 10px rgba(240,176,58,.45);
}
.payline::before, .payline::after {
  content: ""; position: absolute; top: -7px; border: 6px solid transparent;
}
.payline::before { left: 0; border-left-color: var(--accent); }
.payline::after { right: 0; border-right-color: var(--accent); }
.reels.win .reel { animation: winpulse .7s ease 3; }
@keyframes winpulse { 50% { box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(240,176,58,.7); } }

.result { min-height: 24px; margin-top: 12px; text-align: center; color: var(--muted); font-size: 14px; }
.result.win { color: var(--good); font-weight: 800; font-size: 18px; }
.result.lose { color: var(--muted); }

/* ---------- ставка ---------- */
.bet-panel { margin: 14px 0 10px; }
.bet-row { display: flex; gap: 8px; align-items: stretch; }
.bet-input {
  flex: 1; min-width: 0;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums;
  outline: none;
}
.bet-input:focus { border-color: var(--accent); }
.chip {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 0 12px; min-width: 52px; font-weight: 700; font-size: 13px; color: var(--text);
}
.chip:active { background: #2a2e39; }
.bet-chips { display: flex; gap: 8px; margin-top: 8px; }
.bet-chips .chip { flex: 1; padding: 9px 0; }
.bet-limits { margin-top: 6px; font-size: 12px; color: var(--muted); }

.cta {
  display: block; width: 100%;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 14px; padding: 15px; text-align: center;
  font-size: 17px; font-weight: 800; letter-spacing: .02em;
  transition: transform .08s ease, opacity .2s;
}
.cta:active { transform: scale(.985); }
.cta:disabled { opacity: .45; }
.cta.link { text-decoration: none; margin-top: 16px; }
.btn-secondary {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 15px; font-size: 17px; font-weight: 700; width: 100%;
}
.btn-secondary:disabled { opacity: .45; }

.paytable { margin-top: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 4px 14px; }
.paytable summary { padding: 10px 0; cursor: pointer; color: var(--muted); font-size: 14px; }
.pay-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); }
.pay-row .trio { display: flex; gap: 2px; }
.pay-row .trio svg { width: 30px; height: 30px; }
.pay-row b { font-variant-numeric: tabular-nums; font-size: 16px; }
.pay-note { padding: 8px 0 10px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

/* ---------- блэкджек ---------- */
.table {
  background: radial-gradient(120% 90% at 50% 40%, #183327, var(--felt));
  border: 1px solid var(--felt-line);
  border-radius: 18px; padding: 14px;
}
.hand-row { min-height: 128px; }
.hand-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: #b9d3c5; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; }
.total { min-width: 30px; text-align: center; padding: 2px 9px; border-radius: 99px; background: rgba(0,0,0,.35); color: #fff; font-weight: 800; font-size: 14px; }
.total:empty { display: none; }
.total.bust { background: var(--bad); }
.cards { display: flex; gap: 6px; min-height: 92px; flex-wrap: wrap; }
.card {
  position: relative; width: 62px; height: 90px; border-radius: 9px;
  background: #f6f3ea; color: #191a1f;
  box-shadow: 0 3px 8px rgba(0,0,0,.45);
  display: flex; flex-direction: column; align-items: flex-start; padding: 6px 7px;
  font-weight: 800; font-size: 19px; line-height: 1;
}
.card.red { color: #c9312f; }
.card i { font-style: normal; font-size: 17px; margin-top: 2px; }
.card::after { content: attr(data-suit); position: absolute; right: 7px; bottom: 4px; font-size: 30px; }
.card.back { background: repeating-linear-gradient(45deg, #274b3b 0 6px, #1d3a2d 6px 12px); border: 3px solid #f6f3ea; color: transparent; }
.card.back::after, .card.back i { display: none; }
.card.deal { animation: deal .32s cubic-bezier(.2,.8,.3,1); }
@keyframes deal { from { opacity: 0; transform: translate(60px, -40px) rotate(8deg); } to { opacity: 1; transform: none; } }

.table-mid { text-align: center; padding: 10px 0; color: #b9d3c5; font-size: 15px; }
.table-mid.win { color: #7dffb0; font-weight: 800; font-size: 19px; }
.table-mid.lose { color: #ff9c9c; font-weight: 700; font-size: 17px; }
.table-mid.push { color: #ffe08a; font-weight: 700; font-size: 17px; }
#bjBetBlock, .bj-actions { margin-top: 14px; }
.bj-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.rules { margin: 14px 2px 0; color: var(--muted); font-size: 12.5px; }

/* ---------- топ ---------- */
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 10px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 9px; color: var(--muted); font-weight: 700; }
.seg.small button { font-size: 13px; padding: 7px 2px; }
.seg button.on { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.note { margin: 4px 2px 10px; padding: 10px 12px; border-radius: 12px; background: rgba(240,176,58,.09); color: var(--accent); font-size: 13px; }
.toplist { list-style: none; margin: 0; padding: 0; }
.toplist li { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.toplist li.me { background: rgba(240,176,58,.08); border-radius: 10px; border-bottom-color: transparent; }
.place { width: 30px; text-align: center; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.place.p1 { color: #ffd45a; } .place.p2 { color: #d7dbe3; } .place.p3 { color: #d99a5f; }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.psum { font-weight: 800; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.mystats { margin-top: 16px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; color: var(--muted); font-size: 13.5px; line-height: 1.7; }
.mystats b { color: var(--text); font-variant-numeric: tabular-nums; }
.mystats .plus { color: var(--good); } .mystats .minus { color: var(--bad); }

/* ---------- нижняя навигация ---------- */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 6;
  width: 100%; max-width: 520px;
  display: flex; padding: 6px 8px calc(6px + var(--safe-bottom));
  background: rgba(15,16,19,.94); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; color: var(--muted); font-size: 11.5px; font-weight: 700; }
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--accent); }

/* ---------- экран-заглушка и тосты ---------- */
.gate { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.gate-card { max-width: 380px; text-align: center; }
.gate-title { font-size: 20px; font-weight: 800; margin-bottom: 8px; }
.gate-text { color: var(--muted); }
.toast {
  position: fixed; left: 50%; bottom: calc(92px + var(--safe-bottom)); transform: translateX(-50%); z-index: 30;
  max-width: 86vw; padding: 11px 16px; border-radius: 12px;
  background: #2a2d37; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-weight: 600; text-align: center; animation: fade .15s ease;
}
.toast.bad { border-color: rgba(255,106,106,.5); }

@media (max-width: 360px) { :root { --cell: 68px; } .card { width: 54px; height: 80px; } }

/* ---------- «Армия»: карточки профиля/действий ---------- */
.army-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 16px; margin-top: 4px;
}
.army-avatar-row { display: flex; align-items: center; gap: 12px; }
.army-avatar {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover;
  background: var(--panel-2); border: 2px solid var(--line); flex: none;
}
.army-name { font-size: 17px; font-weight: 800; }
.army-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.army-stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.army-stat {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 6px; text-align: center;
}
.army-stat svg { width: 18px; height: 18px; color: var(--accent); }
.army-stat b { display: block; font-size: 16px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.army-stat span { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 1px; }

.army-shield {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  padding: 10px 12px; border-radius: 12px; background: rgba(76,214,138,.1); color: var(--good);
  font-size: 12.5px; font-weight: 600;
}
.army-shield svg { width: 18px; height: 18px; flex: none; }

.army-action-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px; margin-top: 12px;
}
.army-action-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.army-action-head svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.army-action-head b { display: block; font-size: 14.5px; }
.army-action-head span { display: block; color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.army-qty-row .chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- топ «Армии» / кланов — строки со своим аватаром ---------- */
.army-toplist li, .clan-toplist li { cursor: pointer; }
.army-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.row-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--panel-2); flex: none; }
.row-icon-stat { display: flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.row-icon-stat svg { width: 14px; height: 14px; color: var(--accent); }
.clan-toplist .pname small { color: var(--muted); font-weight: 500; }

/* ---------- нижний лист: профиль игрока / атака ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  position: relative; width: 100%; max-width: 520px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  animation: sheetUp .2s ease;
}
@keyframes sheetUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-close {
  position: absolute; right: 12px; top: 12px; width: 30px; height: 30px; border-radius: 50%;
  background: var(--panel-2); font-size: 18px; line-height: 1; color: var(--muted);
}
.sheet-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.sheet-buttons .btn-secondary { text-decoration: none; display: flex; align-items: center; justify-content: center; }

/* ---------- иконка у баланса в шапке ---------- */
.balance-row { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.balance-icon { width: 20px; height: 20px; color: var(--accent); flex: none; }
.inline-coin { width: 14px; height: 14px; color: var(--accent); vertical-align: -2px; margin-right: 3px; }
.price-with-icon { display: inline-flex; align-items: center; }
