:root {
  --bg: #0b0e11;
  --panel: #151a1f;
  --panel-2: #1d242b;
  --line: rgba(255, 255, 255, .08);
  --text: #f3f5f7;
  --muted: #8d98a3;
  --gold: #f2c14e;
  --gold-2: #c9962a;
  --red: #d64541;
  --green: #2fa866;
  --amber: #e8962e;
  --felt-1: #2f9a62;
  --felt-2: #1c6e44;
  --felt-3: #0e4329;
  --rail: #2b1b11;
  --card-red: #d42a2a;
  --card-black: #15181c;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body {
  font: 15px/1.25 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-variant-numeric: tabular-nums;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  background:
    radial-gradient(120% 60% at 50% 35%, #12261c 0%, transparent 70%),
    var(--bg);
}

/* ---------- шапка ---------- */
#top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 4px;
  min-height: 44px;
}
#top .title { flex: 1; min-width: 0; }
#top .title b { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .title span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .title span { color: var(--muted); font-size: 12px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--panel-2); color: var(--text); font-size: 13px; font-weight: 600;
}
.pill.tap { box-shadow: inset 0 0 0 1px var(--line); }
.pill.tap::after { content: '↻'; color: var(--muted); font-weight: 400; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--panel-2); font-size: 20px; line-height: 36px; text-align: center;
}

/* ---------- стол ---------- */
#table {
  position: relative;
  flex: 1 1 auto;
  min-height: 300px;
  margin: 2px 6px 0;
}
.felt {
  position: absolute;
  inset: 7% 11% 6%;
  border-radius: 9999px;
  background: var(--rail);
  box-shadow:
    0 18px 40px rgba(0, 0, 0, .55),
    inset 0 2px 0 rgba(255, 255, 255, .08),
    inset 0 -3px 6px rgba(0, 0, 0, .5);
}
.felt::before {
  content: '';
  position: absolute;
  inset: 11px;
  border-radius: inherit;
  background:
    radial-gradient(ellipse 70% 55% at 50% 45%, var(--felt-1) 0%, var(--felt-2) 55%, var(--felt-3) 100%);
  box-shadow: inset 0 0 0 2px rgba(242, 193, 78, .22), inset 0 0 40px rgba(0, 0, 0, .45);
}
.felt::after {
  content: '♠ ПОКЕРОК ♠';
  position: absolute;
  left: 50%; top: 73%;
  transform: translate(-50%, -50%);
  font-size: 11px; letter-spacing: .35em; font-weight: 700;
  color: rgba(255, 255, 255, .09);
  white-space: nowrap;
}

.center {
  position: absolute;
  left: 50%; top: 47%;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: 70%;
  z-index: 2;
}
.pot {
  padding: 4px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, .38);
  font-size: 13px; color: #dfe6e2;
}
.pot b { color: var(--gold); font-size: 15px; }
.pot.bump { animation: bump .45s ease; }
.board { display: flex; gap: 4px; }
.slot {
  width: var(--cw); height: calc(var(--cw) * 1.4);
  border-radius: calc(var(--cw) * .12);
  border: 1.5px dashed rgba(255, 255, 255, .14);
}
.status {
  min-height: 18px;
  font-size: 12px; color: rgba(255, 255, 255, .7);
  text-align: center;
}

/* ---------- карты ---------- */
.board { --cw: clamp(32px, 9.6vw, 46px); }
.card {
  --cw: 40px;
  position: relative;
  flex: none;
  width: var(--cw); height: calc(var(--cw) * 1.4);
  border-radius: calc(var(--cw) * .12);
  background: linear-gradient(160deg, #ffffff 0%, #f1f1ee 100%);
  color: var(--card-black);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45), inset 0 0 0 1px rgba(0, 0, 0, .08);
  font-weight: 800;
  overflow: hidden;
}
.board .card { --cw: inherit; }
.card.red { color: var(--card-red); }
.card .r { position: absolute; left: 9%; top: 4%; font-size: calc(var(--cw) * .38); letter-spacing: -.04em; line-height: 1; }
.card .s { position: absolute; left: 10%; top: 34%; font-size: calc(var(--cw) * .26); line-height: 1; }
.card .c { position: absolute; right: 6%; bottom: 2%; font-size: calc(var(--cw) * .62); line-height: 1; }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .12) 0 3px, transparent 3px 7px),
    linear-gradient(160deg, #c0392b, #8e1f16);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45), inset 0 0 0 2px #fff, inset 0 0 0 3px rgba(0, 0, 0, .15);
}
.card.dim { filter: brightness(.55) saturate(.6); }
.card.win { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(242, 193, 78, .8); transform: translateY(-4px); }
.card.deal { animation: flip .45s cubic-bezier(.2, .8, .3, 1) both; }
.board .card.deal:nth-child(2) { animation-delay: .08s; }
.board .card.deal:nth-child(3) { animation-delay: .16s; }

/* ---------- места игроков ---------- */
.seat {
  position: absolute;
  width: 78px;
  transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center;
  z-index: 3;
  transition: opacity .3s;
}
.seat.folded .ava-wrap, .seat.folded .plate { opacity: .42; }
.seat.out .ava-wrap, .seat.out .plate { opacity: .55; }
.ava-wrap {
  --p: 0;
  position: relative;
  width: 50px; height: 50px;
  border-radius: 50%;
  padding: 3px;
  background: rgba(0, 0, 0, .35);
}
.active .ava-wrap {
  background: conic-gradient(var(--ring, var(--green)) calc(var(--p) * 360deg), rgba(255, 255, 255, .12) 0);
  box-shadow: 0 0 16px rgba(47, 168, 102, .55);
}
.ava {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: grid; place-items: center;
  background: hsl(var(--h, 200) 45% 38%);
  color: #fff; font-weight: 700; font-size: 16px;
  border: 2px solid #0b0e11;
}
.plate {
  margin-top: -6px;
  min-width: 70px; max-width: 86px;
  padding: 4px 8px 3px;
  border-radius: 10px;
  background: rgba(10, 13, 16, .88);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4), inset 0 0 0 1px var(--line);
  text-align: center;
  position: relative;
}
.plate .nm { font-size: 11px; color: #cfd6dc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plate .st { font-size: 13px; font-weight: 700; color: var(--gold); }
.active .plate { box-shadow: 0 0 0 1.5px var(--green), 0 2px 8px rgba(0, 0, 0, .4); }
.winner .plate { box-shadow: 0 0 0 1.5px var(--gold), 0 0 18px rgba(242, 193, 78, .65); }
.winner .ava-wrap { background: var(--gold); animation: glow 1.4s ease-in-out infinite; }

.mini {
  position: absolute;
  top: 2px; left: 50%;
  display: flex;
  transform: translateX(15px);
  z-index: -1;
}
.mini .card { --cw: 22px; border-radius: 3px; }
.mini .card + .card { margin-left: -9px; transform: rotate(8deg) translateY(1px); }
.mini .card:first-child { transform: rotate(-4deg); }
.mini.open { transform: translateX(-50%); left: 50%; top: -2px; z-index: 1; }
.mini.open .card { --cw: 31px; }
.mini.open .card + .card { margin-left: 2px; transform: none; }
.mini.open .card:first-child { transform: none; }

.tag {
  position: absolute;
  top: -8px; left: 50%; transform: translateX(-50%);
  padding: 1px 6px; border-radius: 6px;
  font-size: 9px; font-weight: 800; letter-spacing: .06em;
  background: #2a3138; color: #c9d1d8;
  white-space: nowrap;
}
.tag.win { background: var(--gold); color: #1b1404; font-size: 11px; top: -12px; }
.plate .allin { color: #ff6b62; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.plate .muted { color: var(--muted); font-weight: 600; font-size: 12px; }
.your-turn { color: var(--gold); font-size: 13px; }
.dealer {
  position: absolute;
  right: 2px; top: 30px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; color: #111;
  font-size: 11px; font-weight: 900; line-height: 20px; text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .6), inset 0 0 0 2px #ddd;
  z-index: 4;
}
.blind {
  position: absolute; left: 2px; top: 32px;
  font-size: 9px; font-weight: 800; color: #0b0e11;
  background: #cfd6dc; border-radius: 6px; padding: 1px 4px;
}

.bet {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; gap: 4px;
  padding: 2px 8px 2px 3px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .42);
  font-size: 12px; font-weight: 700; color: #fff;
  z-index: 2;
  animation: pop .25s ease;
}
.chip {
  width: 16px; height: 16px; border-radius: 50%;
  background:
    radial-gradient(circle, transparent 0 4px, #fff 4px 5px, transparent 5px),
    repeating-conic-gradient(#e74c3c 0 30deg, #fff 30deg 45deg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}
.chip.big { width: 18px; height: 18px; background:
    radial-gradient(circle, transparent 0 4px, #fff 4px 5px, transparent 5px),
    repeating-conic-gradient(#2c6fd6 0 30deg, #fff 30deg 45deg); }

.banner {
  position: absolute;
  left: 50%; top: 22%;
  transform: translate(-50%, -50%);
  z-index: 5;
  padding: 8px 14px;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(20, 16, 6, .92), rgba(12, 10, 4, .92));
  box-shadow: 0 0 0 1.5px var(--gold), 0 10px 30px rgba(0, 0, 0, .6);
  text-align: center;
  white-space: nowrap;
  animation: pop .35s cubic-bezier(.2, .9, .3, 1.3);
}
.banner b { color: var(--gold); font-size: 16px; }
.banner div { font-size: 12px; color: #e9dcc0; margin-top: 2px; }

/* ---------- мои карты ---------- */
#hero {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 6px 16px 8px;
  min-height: 112px;
}
.hero-seat { position: relative; display: flex; flex-direction: column; align-items: center; width: 74px; }
.hero-seat .ava-wrap { width: 56px; height: 56px; }
.hero-seat .dealer { right: 0; top: 34px; }
.hero-cards { flex: 1; display: flex; justify-content: center; gap: 6px; }
.hero-cards .card { --cw: clamp(58px, 17vw, 76px); }
.hero-cards .card:first-child { transform: rotate(-5deg) translateY(3px); }
.hero-cards .card:last-child { transform: rotate(5deg) translateY(3px); }
.hero-cards .card.deal { animation: deal .5s cubic-bezier(.2, .8, .3, 1) both; }
.hero-cards .card.deal:last-child { animation-delay: .1s; }
.hero-cards .placeholder {
  width: clamp(58px, 17vw, 76px); height: calc(clamp(58px, 17vw, 76px) * 1.4);
  border-radius: 9px; border: 1.5px dashed rgba(255, 255, 255, .1);
}
.hero-info { width: 92px; text-align: right; }
.hero-info .hn { font-size: 13px; font-weight: 700; color: var(--gold); }
.hero-info .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- кнопки действий ---------- */
#actions {
  flex: none;
  padding: 8px 12px calc(12px + var(--safe-b));
  background: linear-gradient(180deg, rgba(21, 26, 31, 0), var(--panel) 30%);
  min-height: 84px;
}
.row { display: flex; gap: 8px; }
.row + .row { margin-top: 8px; }
.btn {
  flex: 1;
  height: 52px;
  border-radius: 14px;
  font-size: 16px; font-weight: 700;
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px var(--line), 0 2px 0 rgba(0, 0, 0, .35);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.1;
  transition: transform .08s, filter .15s;
}
.btn:active { transform: translateY(1px) scale(.98); }
.btn small { font-size: 12px; font-weight: 600; opacity: .85; }
.btn.fold { background: linear-gradient(180deg, #d9534f, #b33a36); }
.btn.call { background: linear-gradient(180deg, #34b56f, #23874f); }
.btn.raise { background: linear-gradient(180deg, #f0a43a, #c97a17); }
.btn.primary { background: linear-gradient(180deg, #f5cd62, #d9a537); color: #1b1404; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16); font-size: 14px; flex: 0 0 auto; padding: 0 16px; }
.btn[disabled] { filter: grayscale(.8) brightness(.6); pointer-events: none; }
.wait {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  height: 52px;
  color: var(--muted); font-size: 14px;
}
.wait b { color: var(--text); }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 8px; }

.raise-panel { margin-bottom: 8px; padding: 10px; border-radius: 16px; background: var(--panel-2); animation: up .2s ease; }
.presets { display: flex; gap: 6px; }
.presets button {
  flex: 1; padding: 6px 2px; border-radius: 10px;
  background: #273039; font-size: 11px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center;
}
.presets button b { font-size: 13px; color: var(--text); }
.presets button.on { background: #3a2f17; box-shadow: inset 0 0 0 1.5px var(--gold); }
.slider-row { display: flex; align-items: center; gap: 10px; margin: 12px 2px 4px; }
.slider-row button { width: 34px; height: 34px; border-radius: 50%; background: #273039; font-size: 20px; font-weight: 700; }
input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 6px; border-radius: 3px; background: #2c353e; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 28px; height: 28px; border-radius: 50%; background: var(--gold); box-shadow: 0 2px 6px rgba(0, 0, 0, .5); }
input[type=range]::-moz-range-thumb { width: 28px; height: 28px; border: 0; border-radius: 50%; background: var(--gold); }

/* ---------- чат за столом ---------- */
.chat-btn { position: relative; font-size: 17px; }
.badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff;
  font-size: 11px; font-style: normal; font-weight: 800; line-height: 18px;
}
#chat {
  position: fixed; inset: 0; z-index: 25;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .45);
  animation: fade .2s ease;
}
.chat-body {
  width: 100%; max-width: 560px;
  height: min(72dvh, 560px);
  display: flex; flex-direction: column;
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  animation: up .25s ease;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 6px 18px; font-size: 16px; font-weight: 700; }
.chat-head .icon-btn { font-size: 15px; }
#chat-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 6px;
  padding: 6px 12px;
  user-select: text; -webkit-user-select: text;
}
.msg {
  align-self: flex-start;
  max-width: 82%;
  padding: 7px 11px 8px;
  border-radius: 14px 14px 14px 4px;
  background: var(--panel-2);
  font-size: 15px; line-height: 1.3;
  overflow-wrap: anywhere;
}
.msg b { display: block; margin-bottom: 2px; font-size: 12px; color: hsl(var(--h) 70% 68%); }
.msg time { margin-left: 4px; font-weight: 400; color: var(--muted); }
.msg.mine { align-self: flex-end; border-radius: 14px 14px 4px 14px; background: #24402f; }
.quick { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 4px; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }
.quick button { flex: none; padding: 7px 12px; border-radius: 999px; background: #273039; font-size: 14px; }
.chat-input { display: flex; gap: 8px; padding: 6px 12px calc(10px + var(--safe-b)); }
.chat-input input {
  flex: 1; min-width: 0; height: 44px;
  padding: 0 16px; border: 0; border-radius: 22px;
  background: #0f1317; color: var(--text);
  font: inherit; font-size: 16px; /* меньше 16px — iOS приближает страницу */
  box-shadow: inset 0 0 0 1px var(--line); outline: none;
  user-select: text; -webkit-user-select: text;
}
.chat-input button { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--gold); color: #1b1404; font-size: 18px; font-weight: 800; }
.bubble {
  position: absolute; bottom: calc(100% + 4px); left: 50%;
  transform: translateX(-50%);
  width: max-content; max-width: 132px;
  padding: 5px 9px; border-radius: 12px;
  background: #fff; color: #111;
  font-size: 12px; font-weight: 600; line-height: 1.25; text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
  z-index: 6; pointer-events: none;
  animation: bubble 4.5s ease forwards;
}
.bubble::after { content: ''; position: absolute; top: 100%; left: 50%; margin-left: -5px; border: 5px solid transparent; border-top-color: #fff; }
.bubble.l { left: 0; transform: none; }
.bubble.r { left: auto; right: 0; transform: none; }
.bubble.l::after { left: 30px; }
.bubble.r::after { left: auto; right: 25px; }
.bubble.l, .bubble.r { animation-name: bubble-side; }
@keyframes bubble-side { 0% { opacity: 0; } 8% { opacity: 1; } 85% { opacity: 1; } 100% { opacity: 0; } }
@keyframes bubble {
  0% { opacity: 0; transform: translateX(-50%) translateY(6px) scale(.9); }
  8% { opacity: 1; transform: translateX(-50%); }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- шторка, подсказки, заставка ---------- */
#sheet {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
.sheet-body {
  width: 100%; max-width: 560px;
  padding: 18px 16px calc(16px + var(--safe-b));
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  animation: up .25s ease;
}
.sheet-body h3 { margin: 0 0 10px; font-size: 17px; }
.standings { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 14px; }
.standings td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.standings td:last-child { text-align: right; font-weight: 700; }
.plus { color: var(--green); }
.minus { color: var(--red); }
.sheet-body .btn { margin-top: 8px; width: 100%; flex: none; }
.sheet-body { max-height: 86dvh; display: flex; flex-direction: column; }
.sheet-scroll { overflow-y: auto; min-height: 120px; max-height: 46dvh; }
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 10px; border-radius: 12px; background: #0f1317; }
.tabs button { flex: 1; padding: 8px 4px; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }
.tabs button.on { background: var(--panel-2); color: var(--text); }
.sheet-body .sub { margin: 2px 0 8px; color: var(--muted); font-size: 13px; }
.standings tr.th td { color: var(--muted); font-size: 12px; padding-top: 0; }
.standings td:nth-child(2) { text-align: right; color: var(--muted); padding-right: 10px; }
.standings tr.me td:first-child { color: var(--gold); font-weight: 700; }
.game-card { padding: 10px 12px; margin-bottom: 8px; border-radius: 12px; background: var(--panel-2); font-size: 14px; }
.game-card .gh { display: flex; justify-content: space-between; margin-bottom: 6px; }
.game-card .gh span { color: var(--muted); font-size: 12px; }
.game-card .gr { display: flex; justify-content: space-between; padding: 2px 0; }
.bank-line { margin: 10px 0 2px; font-size: 14px; color: var(--muted); }
.bank-line b { color: var(--gold); }

#toast {
  position: fixed; left: 50%; top: 14px; z-index: 30;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 10px 16px; border-radius: 12px;
  background: rgba(30, 36, 42, .96); box-shadow: 0 8px 24px rgba(0, 0, 0, .5), inset 0 0 0 1px var(--line);
  font-size: 14px; text-align: center;
  animation: drop .25s ease;
}

#splash {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg); color: var(--muted);
  transition: opacity .3s;
}
#splash.gone { opacity: 0; pointer-events: none; }
#splash .logo { font-size: 54px; color: var(--gold); animation: glow 1.4s ease-in-out infinite; border-radius: 50%; }
#splash p { margin: 0; padding: 0 30px; text-align: center; line-height: 1.4; }

@keyframes flip { from { transform: rotateY(90deg) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes deal { from { transform: translateY(-120px) rotate(-20deg); opacity: 0; } }
@keyframes pop { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }
@keyframes bump { 50% { transform: scale(1.12); } }
@keyframes glow { 50% { box-shadow: 0 0 22px rgba(242, 193, 78, .85); } }
@keyframes up { from { transform: translateY(16px); opacity: 0; } }
@keyframes drop { from { transform: translate(-50%, -12px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

@media (max-height: 680px) {
  #hero { min-height: 96px; }
  .hero-cards .card, .hero-cards .placeholder { --cw: 54px; width: 54px; height: 76px; }
  .ava-wrap { width: 44px; height: 44px; }
  .btn { height: 46px; }
}
