* { box-sizing: border-box; }

:root {
  --bg: #0e0f14;
  --panel: #171922;
  --panel-2: #1f2230;
  --line: #2a2e3d;
  --text: #e9ebf2;
  --muted: #8a90a6;
  --red: #ff3b3b;
  --green: #22c55e;
  --amber: #ffb800;
}

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }
input { font: inherit; }

/* ---------- Шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.logo {
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 1px;
  white-space: nowrap;
}
.logo span {
  margin-left: 4px;
  color: var(--red);
  text-shadow: 0 0 12px rgba(255, 59, 59, 0.7);
}

.history {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow: hidden;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.chip {
  padding: 3px 9px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 12px;
  background: #222636;
  white-space: nowrap;
}
.chip.low { color: #6fb6ff; }
.chip.mid { color: #c48cff; }
.chip.high { color: var(--amber); }

.top-right { display: flex; align-items: center; gap: 10px; }
.top-btn {
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}
.top-btn.accent { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.balance { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.balance span, .balance small { font-size: 11px; color: var(--muted); }
.balance b { font-size: 17px; color: var(--green); }
.packs { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.pack { display: flex; flex-direction: column; gap: 2px; min-width: 108px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); text-align: left; }
.pack b { font-size: 16px; }
.pack span { color: var(--muted); font-size: 12px; }
.pay-custom { display: flex; gap: 8px; }
.pay-custom input { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0c0d12; color: var(--text); }

/* ---------- Раскладка ---------- */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 56px);
}

.players {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.players-head {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 12px 12px 4px;
  border: 0;
  background: none;
  color: var(--muted);
  text-align: left;
  cursor: default;
}
.players-head b { color: var(--text); }
.players-sum { padding: 0 12px 8px; color: var(--muted); }
.players-sum b { color: var(--text); }
.players-cols, .prow {
  display: grid;
  grid-template-columns: 1fr 62px 50px 70px;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
}
.players-cols { font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--line); }
.players-list { flex: 1; overflow-y: auto; }
.prow { font-size: 13px; border-bottom: 1px solid rgba(255, 255, 255, 0.03); grid-template-columns: 24px 1fr 62px 50px 70px; }
.players-cols { grid-template-columns: 1fr 62px 50px 70px; padding-left: 42px; }
.ava {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
}
.pname { display: flex; flex-direction: column; line-height: 1.1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pname small { font-size: 10px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.pbet, .pmult, .pwin { text-align: right; font-variant-numeric: tabular-nums; }
.prow.win { background: rgba(34, 197, 94, 0.1); }
.prow.win .pmult, .prow.win .pwin { color: var(--green); font-weight: 700; }
.prow.win small { color: #f5c542; }
.prow.lost { opacity: 0.45; }
.prow.me { background: rgba(255, 59, 59, 0.12); }
.prow.me.win { background: rgba(34, 197, 94, 0.18); }

/* ---------- Сцена ---------- */
.stage { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }
.scene-wrap {
  position: relative;
  flex: 1;
  min-height: 320px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 28px 12px;
  border-radius: 40px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.4), transparent 72%);
  pointer-events: none;
  text-align: center;
}
.hud-tier {
  padding: 3px 12px;
  border: 2px solid;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.55);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.hud-floor {
  margin-top: 4px;
  font-family: "Courier New", monospace;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
}
.hud-mult {
  font-size: clamp(42px, 7vw, 76px);
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.7);
  font-variant-numeric: tabular-nums;
}
.hud-mult.crashed { color: var(--red); text-shadow: 0 0 24px rgba(255, 59, 59, 0.8); }
.hud-mult.waiting { opacity: 0.6; }
.hud-status {
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.9);
}
.countdown {
  width: 220px;
  height: 5px;
  margin-top: 6px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
#countdownBar { height: 100%; background: var(--red); }

.toasts {
  position: absolute;
  bottom: 54px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 8px 16px;
  border-radius: 10px;
  border: 2px solid var(--line);
  background: rgba(10, 11, 16, 0.88);
  font-weight: 700;
  white-space: nowrap;
  animation: toast-in 0.25s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}
.toast.win { border-color: var(--green); color: #b6f5cb; }
.toast.tier { color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.95); } }

/* ---------- Панели ставок ---------- */
.bets { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.bet-panel {
  display: flex;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.bet-left { display: flex; flex-direction: column; gap: 8px; flex: 0 0 auto; }
.amount { display: flex; gap: 4px; }
.amount-input {
  width: 100px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c0d12;
  color: var(--text);
  text-align: center;
  font-weight: 700;
}
.step, .quick button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
}
.step { width: 38px; font-weight: 700; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.quick button { padding: 4px 0; font-size: 12px; }
.auto { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.auto-val {
  width: 58px;
  padding: 3px 4px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #0c0d12;
  color: var(--text);
  text-align: center;
}

.bet-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  min-height: 92px;
  border: none;
  border-radius: 12px;
  color: #fff;
  transition: transform 0.08s, filter 0.15s;
}
.bet-btn:active:not(:disabled) { transform: scale(0.98); }
.bet-btn:hover:not(:disabled) { filter: brightness(1.08); }
.bet-btn .main { font-size: 19px; font-weight: 900; letter-spacing: 0.5px; }
.bet-btn .sub { font-size: 14px; font-weight: 600; opacity: 0.9; }
.bet-btn.bet { background: linear-gradient(180deg, #2ecc71, #18a558); box-shadow: 0 4px 0 #0f7a3f; }
.bet-btn.cancel { background: linear-gradient(180deg, #ff5a5a, #d42a2a); box-shadow: 0 4px 0 #8f1717; }
.bet-btn.cashout { background: linear-gradient(180deg, #ffc93c, #f39c12); box-shadow: 0 4px 0 #a86507; color: #2a1a00; }
.bet-btn.done { background: #2a2e3d; }

.hint { margin: 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ---------- Модалка ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 10;
}
.modal[hidden] { display: none; }
.modal-box {
  position: relative;
  width: min(620px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.modal-box h2 { margin-top: 0; }
.modal-box p { color: var(--muted); line-height: 1.5; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 26px;
}
.kv { display: flex; flex-direction: column; gap: 2px; margin: 10px 0; }
.kv span { font-size: 12px; color: var(--muted); }
.kv code {
  padding: 6px 8px;
  border-radius: 6px;
  background: #0c0d12;
  font-size: 12px;
  word-break: break-all;
}
#fairCheckResult { margin-left: 10px; font-weight: 700; }
#fairCheckResult.ok { color: var(--green); }
#fairCheckResult.bad { color: var(--red); }
.formula { font-size: 12px; }

.fair-checks { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; font-weight: 700; }
.fair-checks .ok { color: var(--green); }
.fair-checks .bad { color: var(--red); }

/* ---------- Шапка: профиль и меню ---------- */
.me-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 180px;
  padding: 3px 12px 3px 3px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
}
.me-chip img { width: 30px; height: 30px; border-radius: 50%; flex: none; }
.me-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-menu { display: flex; gap: 8px; }
.menu-btn { display: none; font-size: 18px; line-height: 1; padding: 6px 11px; }
.top-btn[hidden], .menu-btn[hidden] { display: none; }

/* ---------- Сцена: связь и шаринг ---------- */
.net-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 20px;
  border-radius: 12px;
  background: rgba(10, 11, 16, 0.9);
  border: 2px solid var(--amber);
  font-weight: 800;
  pointer-events: none;
}
.net-status[hidden] { display: none; }
.share-chip {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 9px 14px;
  border: 2px solid #1d1b2c;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffd34d, #ffb800);
  color: #2a1a00;
  font-weight: 900;
  box-shadow: 0 3px 0 #a86507;
  animation: share-pop 0.35s ease-out;
}
.share-chip[hidden] { display: none; }
@keyframes share-pop { from { transform: scale(0.6); opacity: 0; } }

.bet-note { min-height: 0; font-size: 11px; color: var(--amber); max-width: 190px; line-height: 1.25; }
.bet-note:empty { display: none; }
.prow img.ava, .lrow img.ava { width: 24px; height: 24px; object-fit: cover; }
.add-panel { display: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Гардероб ---------- */
.modal-box.wide { width: min(860px, 94vw); }
.profile { display: flex; gap: 16px; align-items: center; }
.profile-ava { width: 112px; height: 112px; border-radius: 20px; border: 3px solid var(--line); flex: none; }
.profile-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.name-row { display: flex; gap: 8px; }
.name-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0c0d12;
  color: var(--text);
  font-weight: 700;
}
.pstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pstat { padding: 6px 8px; border-radius: 8px; background: var(--panel-2); display: flex; flex-direction: column; }
.pstat span { font-size: 11px; color: var(--muted); }
.pstat b { font-size: 14px; }
.looks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.look {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--text);
  text-align: center;
}
.look img { width: 100%; max-width: 132px; aspect-ratio: 1; border-radius: 12px; }
.look b { font-size: 14px; }
.look small { font-size: 11px; color: var(--muted); min-height: 28px; }
.look:not(.locked):hover { border-color: var(--tc); }
.look.active { border-color: var(--tc); box-shadow: 0 0 0 2px var(--tc) inset; }
.look.locked { opacity: 0.75; }
.look-tag { font-size: 11px; font-weight: 800; padding: 2px 10px; border-radius: 10px; background: #0c0d12; color: var(--tc); }
.look.active .look-tag { background: var(--tc); color: #1d1b2c; }

/* ---------- Рейтинг ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tab { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--muted); font-weight: 700; }
.tab.active { background: var(--red); border-color: var(--red); color: #fff; }
.lrow { display: grid; grid-template-columns: 30px 28px 1fr auto; gap: 8px; align-items: center; padding: 7px 8px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
.lrow.me { background: rgba(255, 59, 59, 0.12); border-radius: 8px; }
.lrank { text-align: center; font-weight: 900; color: var(--muted); }
.lrank.top1 { color: #ffd34d; }
.lrank.top2 { color: #d7dbe6; }
.lrank.top3 { color: #e0965a; }
.lname { display: flex; flex-direction: column; overflow: hidden; font-weight: 700; }
.lname small { font-size: 11px; color: var(--muted); font-weight: 400; }
.lval { font-weight: 900; color: var(--green); font-variant-numeric: tabular-nums; }

/* ---------- Шаринг ---------- */
.share-box { width: min(460px, 94vw); }
.share-img { display: block; width: 100%; border-radius: 12px; border: 1px solid var(--line); }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.share-actions .top-btn { flex: 1; padding: 10px; }

/* ---------- Планшет ---------- */
@media (max-width: 1100px) {
  .menu-btn { display: block; }
  .top-menu {
    position: absolute;
    top: 52px;
    right: 10px;
    z-index: 20;
    display: none;
    flex-direction: column;
    min-width: 200px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  }
  .top-menu.open { display: flex; }
  .top-menu .top-btn { text-align: left; padding: 10px 12px; }
  .topbar { position: relative; }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .players { order: 2; max-height: 360px; }
  .scene-wrap { min-height: 58vh; }
  .bets { grid-template-columns: 1fr; }
}

/* ---------- Телефон ---------- */
@media (max-width: 760px) {
  html, body { font-size: 13px; overscroll-behavior-y: none; }
  button, input { touch-action: manipulation; }
  .topbar {
    flex-wrap: wrap;
    height: auto;
    gap: 6px 8px;
    padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  }
  .logo { font-size: 16px; flex: 1; }
  .top-right { gap: 6px; }
  .me-chip { padding: 2px; border-radius: 50%; }
  .me-chip span { display: none; }
  .balance b { font-size: 16px; }
  .history { order: 10; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; mask-image: none; }
  .history::-webkit-scrollbar { display: none; }
  .top-menu { top: 100%; margin-top: 4px; }

  .layout { display: flex; flex-direction: column; gap: 8px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .stage { gap: 8px; }
  .scene-wrap { flex: none; height: min(54vh, 125vw); min-height: 300px; border-radius: 10px; }
  .hud { top: 6px; padding: 4px 18px 6px; width: max-content; max-width: 96%; }
  .hud-tier { font-size: 11px; padding: 2px 10px; }
  .hud-floor { display: none; }
  .hud-mult { font-size: 44px; }
  .hud-status { font-size: 11px; white-space: nowrap; }
  .countdown { width: 150px; margin-top: 4px; }
  /* плашки — в левом нижнем углу сцены, кнопка «Поделиться» — в правом: центр сцены остаётся открытым */
  .toasts { left: 8px; bottom: 8px; transform: none; align-items: flex-start; gap: 4px; max-width: 56%; }
  .toast { font-size: 11px; line-height: 1.25; padding: 5px 9px; border-width: 1.5px; white-space: normal; text-align: left; max-width: 100%; }
  .share-chip { top: auto; bottom: 8px; right: 8px; font-size: 12px; padding: 7px 12px; }

  .bets { gap: 8px; }
  .bets:not(.two) .bet-panel:nth-child(2) { display: none; }
  .bet-panel { padding: 10px; gap: 8px; }
  .bet-left { flex: 0 1 auto; min-width: 0; }
  .amount-input { width: 76px; font-size: 16px; }
  .step { width: 40px; height: 36px; }
  .quick button { padding: 7px 0; }
  .auto { font-size: 12px; }
  .auto-on { width: 18px; height: 18px; }
  .auto-val { width: 68px; font-size: 16px; }
  .bet-btn { min-height: 104px; border-radius: 14px; }
  .bet-btn .main { font-size: 17px; text-align: center; line-height: 1.1; }
  .add-panel {
    display: block;
    padding: 9px;
    border: 1px dashed var(--line);
    border-radius: 10px;
    background: none;
    color: var(--muted);
    font-weight: 700;
  }
  .hint { font-size: 11px; }

  .players { order: 2; max-height: none; }
  .players-head { cursor: pointer; }
  .players-head::after { content: '▾'; margin-left: 6px; color: var(--muted); }
  .players.open .players-head::after { content: '▴'; }
  .players:not(.open) .players-sum, .players:not(.open) .players-cols, .players:not(.open) .players-list { display: none; }
  .players.open .players-list { max-height: 50vh; }

  .modal { align-items: end; }
  .modal-box { width: 100vw; max-height: 90vh; border-radius: 18px 18px 0 0; padding: 18px 14px calc(18px + env(safe-area-inset-bottom)); }
  .modal-box.wide, .share-box { width: 100vw; }
  .profile-ava { width: 84px; height: 84px; }
  .pstats { grid-template-columns: repeat(2, 1fr); }
  .looks { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 360px) {
  .balance span { display: none; }
  .amount-input { width: 64px; }
  .step { width: 34px; }
}
