:root {
  /* Единая фикс-палитра классического стола: тема Telegram больше не влияет на цвета */
  --tg-bg: oklch(25% 0.018 78);
  --tg-secondary-bg: rgb(46 39 30 / 58%);
  --tg-text: #f3ede2;
  --tg-hint: #b3a68f;
  --tg-link: #e2cf9f;
  --tg-button: #ece1cb;
  --tg-button-text: #2f281e;
  --surface-raised: rgb(48 41 32 / 78%);
  --surface-soft: rgb(54 46 36 / 66%);
  --line: color-mix(in srgb, var(--tg-text) 12%, transparent);
  --felt: oklch(34% 0.02 80);
  --felt-deep: oklch(22% 0.018 80);
  --felt-line: oklch(55% 0.03 80);
  --card-red: #c62828;
  --card-black: #171918;
  /* Единые акценты: красный (CTA/опасность), зелёный (деньги/успех) — по одному на роль */
  --danger: #c9463c;
  --red-soft: #d7554b;
  --green-fill: #96762e;
  --warning: #d29b4a;
  --success: #d9b856;
  --radius-sm: 10px;
  --radius-md: 14px;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --nav-height: 72px;
  --z-sticky: 20;
  --z-backdrop: 40;
  --z-modal: 50;
  --z-toast: 60;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--tg-text);
  background: var(--tg-bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--tg-bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--tg-text);
  /* Та же джинсовая ткань, что и на игровом столе — единая среда во всём аппе */
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.2'/%3E%3C/svg%3E") repeat fixed,
    repeating-linear-gradient(45deg, rgb(243 234 214 / 3%) 0 1px, transparent 1px 5px) fixed,
    repeating-linear-gradient(-45deg, rgb(20 17 13 / 6%) 0 1px, transparent 1px 5px) fixed,
    radial-gradient(ellipse at 50% 30%, var(--felt) 0%, oklch(28% 0.02 80) 58%, var(--felt-deep) 100%) fixed;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* Ненавязчивый живой фон: полупрозрачные масти медленно плывут по диагонали */
@keyframes suits-drift {
  to {
    transform: translate(260px, 260px);
  }
}

body::before {
  position: fixed;
  z-index: -1;
  inset: -260px 0 0 -260px;
  content: "";
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cg fill='%23f3ede2' fill-opacity='.045' font-size='36'%3E%3Ctext x='26' y='58' transform='rotate(-14 40 46)'%3E%E2%99%A0%3C/text%3E%3Ctext x='168' y='84' transform='rotate(11 180 70)'%3E%E2%99%A5%3C/text%3E%3Ctext x='62' y='190' transform='rotate(8 76 176)'%3E%E2%99%A6%3C/text%3E%3Ctext x='190' y='224' transform='rotate(-9 204 210)'%3E%E2%99%A3%3C/text%3E%3C/g%3E%3C/svg%3E") repeat;
  animation: suits-drift 90s linear infinite;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button,
label,
[role="button"] {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--tg-link);
  outline-offset: 3px;
}

button:disabled {
  cursor: default;
  opacity: .46;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
}

.main-content {
  min-height: 100dvh;
}

.screen {
  width: 100%;
}

/* Мягкое появление экрана при переключении вкладок */
@keyframes screen-in {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
}

.screen.is-active {
  animation: screen-in 180ms var(--ease-out);
}

.game-screen.is-active {
  animation: none; /* стол фиксированный — не дёргаем */
}

.screen-page {
  max-width: 720px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 18px calc(var(--nav-height) + 32px + env(safe-area-inset-bottom));
}

.page-header,
.profile-identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.page-header h1,
.room-header h1,
.profile-identity h1 {
  margin: 2px 0 0;
  font-size: 1.75rem;
  line-height: 1.15;
  letter-spacing: -.025em;
  text-wrap: balance;
}

.page-context,
.result-context {
  margin: 0;
  color: var(--tg-hint);
  font-size: .8125rem;
  font-weight: 650;
  letter-spacing: .025em;
}

.balance-chip {
  display: inline-flex;
  min-width: 72px;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--tg-text);
  background: var(--tg-secondary-bg);
  font-size: .9375rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.balance-chip {
  gap: 7px;
}

.profile-balance-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.primary-button,
.secondary-button,
.game-action,
.text-button,
.close-button {
  min-height: 48px;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 720;
  transition: transform 180ms var(--ease-out), background-color 180ms var(--ease-out), opacity 180ms ease-out;
}

.primary-button {
  color: var(--tg-button-text);
  background: var(--tg-button);
}

.primary-button:active,
.secondary-button:active,
.game-action:active,
.text-button:active {
  transform: scale(.98);
}

.secondary-button {
  color: var(--tg-text);
  background: var(--tg-secondary-bg);
}

.create-table-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 30px;
  background: var(--danger); /* CTA создания — красный, в один тон с вкладкой ♦ */
}

.button-mark {
  position: relative;
  width: 18px;
  height: 18px;
}

.button-mark::before,
.button-mark::after {
  position: absolute;
  top: 8px;
  left: 2px;
  width: 14px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
}

.button-mark::after {
  transform: rotate(90deg);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.3;
}

.quiet-count {
  min-width: 32px;
  color: var(--tg-hint);
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.room-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px 16px;
  min-height: 82px;
  align-items: center;
  padding: 14px 14px 14px 16px;
  border: 0;
  border-radius: var(--radius-md);
  color: var(--tg-text);
  background: var(--tg-secondary-bg);
  cursor: pointer;
  text-align: left;
  transition: background-color 180ms var(--ease-out), transform 180ms var(--ease-out);
}

.room-item:active {
  transform: scale(.99);
}

.room-item-main {
  min-width: 0;
}

.room-owner {
  display: block;
  overflow: hidden;
  margin-bottom: 5px;
  font-size: 1rem;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 10px;
  color: var(--tg-hint);
  font-size: .8125rem;
}

.room-tag {
  color: var(--tg-link);
}

.room-occupancy {
  min-width: 58px;
  font-size: 1rem;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.room-status {
  display: block;
  margin-top: 4px;
  color: var(--success);
  font-size: .75rem;
  font-weight: 650;
}

.empty-state {
  display: grid;
  min-height: 190px;
  place-items: center;
  padding: 32px 24px;
  border-radius: var(--radius-md);
  color: var(--tg-hint);
  background: var(--tg-secondary-bg);
  text-align: center;
}

.empty-state p {
  max-width: 28ch;
  margin: 0;
  line-height: 1.5;
  text-wrap: pretty;
}

.room-skeleton {
  display: flex;
  min-height: 82px;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  border-radius: var(--radius-md);
  background: var(--tg-secondary-bg);
  animation: skeleton-pulse 1.2s ease-in-out infinite alternate;
}

.room-skeleton span {
  width: 55%;
  height: 12px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--tg-text) 12%, transparent);
}

.room-skeleton span:last-child {
  width: 34%;
  height: 9px;
}

@keyframes skeleton-pulse {
  to { opacity: .52; }
}

.bottom-nav {
  position: fixed;
  z-index: var(--z-sticky);
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  grid-template-columns: repeat(4, 1fr);
  padding: 6px max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
  background: rgb(28 23 18 / 94%);
  border-top: 1px solid var(--line);
}

.nav-item {
  display: flex;
  min-height: 56px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 3px;
  border: 0;
  border-radius: 10px;
  color: var(--tg-hint);
  background: transparent;
  cursor: pointer;
  font-size: .72rem;
  font-weight: 650;
}

/* Иконки-масти в навигации, как в референсе */
.suit-icon {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: rgb(255 255 255 / 8%);
  font-size: 1.05rem;
  line-height: 1;
  transition: background-color 160ms ease-out, transform 160ms var(--ease-out);
}

.suit-red { color: var(--red-soft); }
.suit-black { color: #e6dcc6; }

.nav-item.is-active { color: #f3ede2; }
.nav-item.is-active .suit-icon {
  background: rgb(255 255 255 / 18%);
  transform: translateY(-1px);
}
.nav-item.is-active .suit-red { color: #e0584a; }
.nav-item.is-active .suit-black { color: #f6f0e4; }

/* «Создать» — акцентный красный, как + в референсе */
.nav-create .suit-icon {
  color: #f6f0e4;
  background: var(--danger);
}
.nav-create.is-active .suit-icon {
  background: var(--red-soft);
}

/* Кнопка «назад» на подстраницах (Правила, Настройки) */
.subpage-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.back-button {
  position: relative;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  min-height: 0;
  border: 0;
  border-radius: 10px;
  background: var(--surface-soft);
  cursor: pointer;
}

.back-button::before {
  position: absolute;
  top: 50%;
  left: 55%;
  width: 11px;
  height: 11px;
  border-left: 2px solid var(--tg-text);
  border-bottom: 2px solid var(--tg-text);
  content: "";
  transform: translate(-50%, -50%) rotate(45deg);
}

.connection-banner {
  position: fixed;
  z-index: var(--z-toast);
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  display: flex;
  min-height: 38px;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: 999px;
  color: #f3ede2;
  background: rgb(38 32 25 / 92%);
  font-size: .8125rem;
  font-weight: 680;
  transform: translateX(-50%);
  box-shadow: 0 4px 8px rgb(0 0 0 / 22%);
}

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  animation: reconnect-pulse 1s ease-in-out infinite alternate;
}

@keyframes reconnect-pulse {
  to { opacity: .35; }
}

/* Waiting room */

.waiting-room {
  max-width: 620px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(34px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}

.room-header {
  margin-bottom: 28px;
  text-align: center;
}

.room-header h1 {
  margin-top: 6px;
  font-size: 2rem;
}

.room-summary {
  margin: 8px 0 0;
  color: var(--tg-hint);
}

.room-code-block {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 3px 16px;
  margin-bottom: 28px;
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--tg-secondary-bg);
}

.room-code-block > span {
  grid-column: 1;
  color: var(--tg-hint);
  font-size: .8125rem;
}

.room-code-block strong {
  grid-column: 1;
  font-size: 2.25rem;
  line-height: 1.05;
  letter-spacing: .12em;
}

.text-button {
  grid-row: 1 / 3;
  grid-column: 2;
  min-height: 44px;
  padding: 0 12px;
  color: var(--tg-link);
  background: transparent;
}

.waiting-heading {
  margin-bottom: 10px;
}

.waiting-players {
  display: flex;
  min-height: 110px;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.waiting-player,
.waiting-slot {
  display: flex;
  min-height: 58px;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--tg-secondary-bg);
}

.waiting-slot {
  color: var(--tg-hint);
  background: color-mix(in srgb, var(--tg-secondary-bg) 58%, transparent);
}

.avatar {
  position: relative;
  display: grid;
  overflow: hidden;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  color: #f3ede2;
  background: #3f3628;
  font-size: .875rem;
  font-weight: 780;
  text-transform: uppercase;
}

/* Фото из Telegram поверх инициала */
.avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.waiting-player-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.host-label {
  color: var(--tg-hint);
  font-size: .75rem;
}

.waiting-actions {
  margin-top: 26px;
}

.waiting-actions .primary-button,
.waiting-actions .secondary-button {
  width: 100%;
}

.waiting-note {
  margin: 12px auto;
  max-width: 38ch;
  color: var(--tg-hint);
  font-size: .8125rem;
  line-height: 1.45;
  text-align: center;
  text-wrap: pretty;
}

/* Rules and profile */

.compact-header {
  margin-bottom: 22px;
}

.rules-copy {
  display: flex;
  flex-direction: column;
}

.rules-copy section {
  padding: 20px 2px;
  border-bottom: 1px solid var(--line);
}

.rules-copy section:first-child {
  padding-top: 0;
}

.rules-copy h2 {
  margin: 0 0 7px;
  font-size: 1rem;
}

.rules-copy p {
  max-width: 68ch;
  margin: 0;
  color: color-mix(in srgb, var(--tg-text) 82%, var(--tg-hint));
  font-size: .9375rem;
  line-height: 1.58;
  text-wrap: pretty;
}

.profile-avatar {
  position: relative;
  display: grid;
  overflow: hidden;
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  place-items: center;
  border: 3px solid var(--success);
  border-radius: 12px;
  color: #f3ede2;
  background: #3f3628;
  font-size: 1.25rem;
  font-weight: 790;
}

/* Профиль-хаб: светлая шапка + меню плитками на сукне (как в референсе) */
.profile-hub {
  max-width: 720px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 12px calc(var(--nav-height) + 26px + env(safe-area-inset-bottom));
}

/* Тёмная шапка профиля — в один тон с остальными панелями */
.hub-identity {
  padding: 14px 16px 16px;
  border-radius: 16px;
  color: var(--tg-text);
  background: rgb(40 34 26 / 92%);
  box-shadow: 0 6px 18px rgb(18 15 10 / 30%), inset 0 0 0 1px rgb(255 255 255 / 5%);
}

.hub-name {
  margin: 0 0 12px;
  color: var(--tg-text);
  font-size: 1.15rem;
  font-weight: 800;
  text-align: center;
}

.hub-id-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.profile-hub .profile-avatar {
  width: 68px;
  height: 68px;
}

.hub-currencies {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 8px;
}

.currency-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: rgb(243 237 226 / 7%);
  cursor: pointer;
}

.currency-value {
  flex: 1;
  color: var(--tg-text);
  font-size: 1.35rem;
  font-weight: 820;
  font-variant-numeric: tabular-nums;
  text-align: left;
}

.currency-row .chip-stack { width: 20px; height: 22px; }

.currency-plus {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 8px;
  background: var(--danger);
  color: #f6f0e4;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
}

.bonus-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--green-fill);
  color: #f8f0d8;
  cursor: pointer;
  text-align: left;
}

.bonus-row:disabled {
  background: rgb(243 237 226 / 8%);
  color: var(--tg-hint);
  cursor: default;
}

.bonus-title { font-weight: 760; font-size: .92rem; }
.bonus-hint { font-size: .72rem; opacity: .85; }

.hub-username {
  margin: 12px 0 0;
  color: var(--tg-hint);
  font-size: .8rem;
  text-align: center;
}

.hub-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 12px 0 0;
  overflow: hidden;
  border-radius: 10px;
  background: rgb(243 237 226 / 6%);
}

.hub-stats div { min-width: 0; padding: 10px 8px; text-align: center; }
.hub-stats div + div { border-left: 1px solid rgb(243 237 226 / 10%); }
.hub-stats dt { color: var(--tg-hint); font-size: .7rem; }
.hub-stats dd { margin: 3px 0 0; color: var(--tg-text); font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.hub-menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.hub-cell {
  display: flex;
  min-height: 78px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 12px;
  border: 0;
  border-radius: 14px;
  color: #f3ede2;
  background: rgb(44 37 29 / 72%);
  cursor: pointer;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-style: italic;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 6%);
  transition: transform 160ms var(--ease-out), background-color 160ms ease-out;
}

.hub-cell:active { transform: scale(.97); background: rgb(56 47 37 / 84%); }
.hub-cell-wide { grid-column: 1 / -1; min-height: 66px; flex-direction: row; gap: 10px; }

.hub-cell-icon {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  color: #e2cf9f;
  font-style: normal;
}

/* Иконки плиток — единый приглушённый голубой; красная только масть ♥ (осознанно) */
.hub-cell-icon.icon-play::before { content: "\25B6"; font-size: 1.05rem; }
.hub-cell-icon.icon-plus::before { content: "+"; font-size: 1.6rem; font-weight: 700; }
.hub-cell-icon.icon-cards::before { content: "\2665"; color: var(--red-soft); font-size: 1.35rem; }
.hub-cell-icon.icon-gear::before { content: "\2699"; font-size: 1.4rem; }
.hub-cell-icon.icon-info::before { content: "i"; font-family: Georgia, serif; font-style: italic; font-weight: 700; font-size: 1.25rem; }
.hub-cell-icon.icon-share::before { content: "\2197"; font-size: 1.4rem; }
.hub-cell-icon.icon-skins::before { content: "\2666"; color: var(--red-soft); font-size: 1.3rem; }

/* Раздел «Скины» */
.skin-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 26px;
}

.skins-emoji-heading { margin-top: 4px; }

.skin-item {
  display: flex;
  min-width: 108px;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 12px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--surface-soft);
  color: var(--tg-text);
  cursor: pointer;
}

.skin-item.is-selected {
  border-color: var(--success);
  background: var(--surface-raised);
}

.skin-preview {
  display: flex;
  gap: 6px;
}

.skin-card-mini {
  display: block;
  width: 44px;
  height: 62px;
  overflow: hidden;
  border-radius: 5px;
  box-shadow: 0 2px 5px rgb(10 8 5 / 35%);
}

.skin-card-mini svg {
  width: 100%;
  height: 100%;
}

.skin-preview-emoji {
  font-size: 1.6rem;
  line-height: 1.3;
}

.skin-name {
  font-size: .85rem;
  font-weight: 700;
}

/* Настройки */
.settings-list { display: flex; flex-direction: column; gap: 8px; }
.settings-row { margin: 0; padding: 10px 14px; border-radius: var(--radius-sm); background: var(--surface-soft); }

.settings-link {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--tg-text);
  background: var(--surface-soft);
  cursor: pointer;
  font-weight: 640;
  font-size: .95rem;
}

.settings-link .chevron { position: relative; width: 9px; height: 9px; }
.settings-link .chevron::before {
  position: absolute;
  inset: 0;
  border-top: 2px solid var(--tg-hint);
  border-right: 2px solid var(--tg-hint);
  content: "";
  transform: rotate(45deg);
}

.settings-meta {
  margin: 18px 2px 0;
  color: var(--tg-hint);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}

/* Приватная игра — ввод кода */
.join-code { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }

.code-input {
  width: 100%;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--tg-text);
  background: var(--surface-soft);
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: .35em;
  text-align: center;
  text-transform: uppercase;
}

.code-input:focus-visible { outline: 2px solid var(--tg-link); border-color: transparent; }

.hub-note { margin: 0; color: var(--tg-hint); font-size: .9rem; line-height: 1.5; }

/* Покупка монет */
.buy-note { padding: 0 20px; }

.buy-packs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 20px 22px;
}

.buy-pack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px;
  border: 0;
  border-radius: 14px;
  color: var(--tg-text);
  background: var(--surface-soft);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 6%);
  transition: transform 160ms var(--ease-out);
}

.buy-pack:active { transform: scale(.97); }
.buy-pack-coins { display: flex; align-items: center; gap: 6px; font-size: 1.25rem; font-weight: 820; font-variant-numeric: tabular-nums; }
.buy-pack-coins .chip-stack { width: 18px; height: 20px; }

.buy-pack-price {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  color: #2f281e;
  background: var(--success);
  font-weight: 720;
  font-size: .9rem;
}

/* Bottom sheet */

.bottom-sheet {
  z-index: var(--z-modal);
  top: auto;
  bottom: 0;
  width: min(100%, 620px);
  max-height: min(92dvh, 780px);
  margin: auto auto 0;
  padding: 0;
  overflow: auto;
  border: 0;
  border-radius: 16px 16px 0 0;
  color: var(--tg-text);
  background: rgb(40 34 26 / 97%);
  box-shadow: 0 -8px 24px rgb(0 0 0 / 25%);
}

.bottom-sheet[open] {
  animation: sheet-in 220ms var(--ease-out);
}

.bottom-sheet::backdrop {
  background: rgb(0 0 0 / 54%);
  animation: backdrop-in 180ms ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(100%); }
}

@keyframes backdrop-in {
  from { opacity: 0; }
}

.sheet-form {
  padding: 8px 18px max(20px, env(safe-area-inset-bottom));
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 2px auto 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tg-text) 22%, transparent);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.sheet-header h2 {
  margin: 2px 0 0;
  font-size: 1.35rem;
}

.close-button {
  position: relative;
  width: 44px;
  min-height: 44px;
  border-radius: 50%;
  background: var(--tg-secondary-bg);
}

.close-button::before,
.close-button::after {
  position: absolute;
  top: 21px;
  left: 13px;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  transform: rotate(45deg);
}

.close-button::after {
  transform: rotate(-45deg);
}

.form-group {
  margin: 0 0 22px;
  padding: 0;
  border: 0;
}

.form-group legend {
  margin-bottom: 10px;
  font-size: .875rem;
  font-weight: 700;
}

.segment-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-sm);
  background: var(--tg-secondary-bg);
}

.segment-control input,
.bet-presets input,
.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segment-control span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border-radius: 7px;
  color: var(--tg-hint);
  cursor: pointer;
  font-weight: 720;
  transition: color 180ms ease-out, background-color 180ms ease-out;
}

.segment-control input:checked + span {
  color: var(--tg-text);
  background: var(--surface-soft);
}

.segment-control input:focus-visible + span,
.bet-presets input:focus-visible + span,
.switch-row input:focus-visible ~ .switch-control {
  outline: 2px solid var(--tg-link);
  outline-offset: 2px;
}

.bet-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bet-presets span {
  display: grid;
  min-width: 66px;
  min-height: 44px;
  place-items: center;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--tg-hint);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 680;
}

.bet-presets input:checked + span {
  border-color: var(--tg-link);
  color: #f6f0e4;
  background: color-mix(in srgb, var(--tg-link) 18%, transparent);
  font-weight: 760;
}

.custom-bet {
  display: block;
  margin-top: 12px;
}

.custom-bet > span {
  display: block;
  margin: 0 0 7px 2px;
  color: var(--tg-hint);
  font-size: .75rem;
}

.custom-bet input {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--tg-text);
  background: var(--tg-secondary-bg);
}

.custom-bet input::placeholder {
  color: color-mix(in srgb, var(--tg-hint) 88%, var(--tg-text));
}

.switch-row {
  position: relative;
  display: flex;
  min-height: 66px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 22px;
  cursor: pointer;
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row strong {
  margin-bottom: 3px;
  font-size: .9375rem;
}

.switch-row small {
  color: var(--tg-hint);
  font-size: .75rem;
}

.switch-control {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tg-hint) 40%, transparent);
  transition: background-color 180ms ease-out;
}

.switch-control::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  content: "";
  transition: transform 180ms var(--ease-out);
}

.switch-row input:checked ~ .switch-control {
  background: var(--green-fill); /* «включено» — зелёный, как принято в тумблерах */
}

.switch-row input:checked ~ .switch-control::after {
  transform: translateX(20px);
}

.sheet-submit {
  width: 100%;
}

/* Game table — синее «джинсовое» сукно */

.game-screen {
  position: fixed;
  inset: 0;
  isolation: isolate;
  display: grid;
  height: 100dvh;
  grid-template-rows: auto minmax(120px, 1fr) auto;
  /* minmax(0,1fr): иначе рука (width: max-content) распирает колонку своим min-content */
  grid-template-columns: minmax(0, 1fr);
  overflow: hidden;
  color: #f3ede2;
  background: var(--felt-deep);
}

/* Ткань: шум (feTurbulence) + диагональная фактура + тёплая виньетка */
.felt-vignette {
  position: absolute;
  z-index: -1;
  inset: 0;
  overflow: hidden;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.2'/%3E%3C/svg%3E") repeat,
    repeating-linear-gradient(45deg, rgb(243 234 214 / 3%) 0 1px, transparent 1px 5px),
    repeating-linear-gradient(-45deg, rgb(20 17 13 / 6%) 0 1px, transparent 1px 5px),
    radial-gradient(ellipse at 50% 42%, var(--felt) 0%, oklch(28% 0.02 80) 58%, var(--felt-deep) 100%);
}

/* Те же плывущие масти и на игровом столе */
.felt-vignette::after {
  position: absolute;
  inset: -260px 0 0 -260px;
  content: "";
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260'%3E%3Cg fill='%23f3ede2' fill-opacity='.035' font-size='36'%3E%3Ctext x='26' y='58' transform='rotate(-14 40 46)'%3E%E2%99%A0%3C/text%3E%3Ctext x='168' y='84' transform='rotate(11 180 70)'%3E%E2%99%A5%3C/text%3E%3Ctext x='62' y='190' transform='rotate(8 76 176)'%3E%E2%99%A6%3C/text%3E%3Ctext x='190' y='224' transform='rotate(-9 204 210)'%3E%E2%99%A3%3C/text%3E%3C/g%3E%3C/svg%3E") repeat;
  animation: suits-drift 90s linear infinite;
}

.game-topbar {
  display: flex;
  min-height: 118px;
  flex-direction: column;
  gap: 0;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 2px max(10px, env(safe-area-inset-left));
}

.topbar-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.flag-button {
  width: 40px;
  height: 34px;
  min-height: 0;
  padding: 3px;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 1px 2px rgb(22 18 12 / 50%));
}

.flag-button svg {
  display: block;
  width: 100%;
  height: 100%;
}

.game-mode {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 1px;
  padding: 6px 12px;
  border-radius: 10px;
  color: #eadfc9;
  background: rgb(38 32 25 / 50%);
  font-size: .8rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.mode-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.mode-item svg {
  width: 17px;
  height: 17px;
}

.opponents {
  display: flex;
  min-width: 0;
  flex: 1;
  justify-content: center;
  gap: 20px;
  /* веер рубашек торчит над аватаром — место сверху, без overflow-обрезки */
  padding-top: 26px;
  overflow: visible;
}

.opponents::-webkit-scrollbar,
.hand-scroll::-webkit-scrollbar {
  display: none;
}

/* Оппонент: веер рубашек за квадратным аватаром, имя снизу */
.opponent {
  position: relative;
  display: flex;
  width: 68px;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  padding-top: 16px;
}

.opponent.is-out {
  opacity: .5;
}

.opp-fan {
  position: absolute;
  top: 10px;
  left: 50%;
  width: 0;
  height: 0;
}

.opp-mini {
  position: absolute;
  top: 0;
  left: 0;
  width: 34px;
  height: 47px;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgb(20 16 11 / 35%);
  transform-origin: 50% 100%;
}

.opp-mini .card-svg {
  width: 100%;
  height: 100%;
}

/* Веер заметно выглядывает над аватаром, как в референсе */
.opp-mini:nth-child(1) { transform: translate(-17px, -25px) rotate(-27deg); }
.opp-mini:nth-child(2) { transform: translate(-17px, -28px) rotate(-9deg); }
.opp-mini:nth-child(3) { transform: translate(-17px, -28px) rotate(9deg); }
.opp-mini:nth-child(4) { transform: translate(-17px, -25px) rotate(27deg); }

/* Квадратный аватар с цветной рамкой-состоянием: зелёная — ходит, красная — отбивается, серая — ждёт */
.opp-avatar {
  position: relative;
  z-index: 1;
  display: grid;
  width: 68px;
  height: 68px;
  place-items: center;
  border: 3px solid #8a7c66;
  border-radius: 8px;
  color: #f3ede2;
  background: #3f3628;
  font-size: 1.05rem;
  font-weight: 800;
  text-transform: uppercase;
  box-shadow: 0 2px 6px rgb(20 16 11 / 45%);
}

.opponent .opp-avatar { border-color: var(--danger); } /* не ходит — красная, как в референсе */
.opponent.is-turn .opp-avatar { border-color: var(--success); } /* ходит — зелёная */
.opponent.is-out .opp-avatar { border-color: #8a7c66; opacity: .72; }

.opp-count {
  position: absolute;
  z-index: 2;
  top: -10px;
  right: -11px;
  min-width: 20px;
  padding: 2px 5px;
  border-radius: 999px;
  color: #f0e8d8;
  background: rgb(31 26 20 / 88%);
  font-size: .66rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

/* Имя — тёмная полоска на нижней кромке аватара, как в референсе */
.opp-name-strip {
  position: absolute;
  z-index: 2;
  right: -1px;
  bottom: -1px;
  left: -1px;
  overflow: hidden;
  padding: 2px 3px;
  border-radius: 0 0 5px 5px;
  background: rgb(26 22 17 / 74%);
  color: #f3ede2;
  font-size: .58rem;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  text-transform: none; /* аватар капсит инициал — имя не трогаем */
  white-space: nowrap;
}

.opp-out-label {
  color: #b8c6d6;
  font-size: .62rem;
}

/* Баланс с фишками в правом верхнем углу */
/* Баланс как в референсе: число + фишки прямо на сукне, без подложки */
.game-balance {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
  margin-top: 2px;
  color: #f3f6fa;
  font-size: 1.2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 3px rgb(20 16 11 / 60%);
}

.chip-stack {
  width: 20px;
  height: 22px;
}

/* Колода у левого края между оппонентами и центром стола */
/* Колода полуторчит из левого края, как в референсе; счётчик — над ней */
.deck-column {
  position: absolute;
  z-index: 3;
  top: max(150px, 27%);
  left: -13px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}

.deck-area {
  position: relative;
  width: 100px;
  height: 100px;
  transform: rotate(-8deg);
}

.deck-stack {
  position: absolute;
  z-index: 2;
  top: 28px;
  left: 0;
  width: 47px;
  height: 67px;
  border-radius: 7px;
  color: #f3ede2;
  box-shadow: 2px 2px 0 rgb(24 20 14 / 55%), 4px 4px 0 rgb(24 20 14 / 35%);
}

.deck-back {
  display: block;
  width: 100%;
  height: 100%;
}

.deck-back .card-svg {
  width: 100%;
  height: 100%;
  border-radius: 7px;
}

/* Счётчик колоды — крупно над стопкой */
#deck-count {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 34px; /* видим полностью при колоде, срезанной краем экрана */
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 3px rgb(18 15 10 / 65%);
}

/* Козырь лежит под стопкой, повёрнут на 90° и выглядывает вправо */
.trump-card-slot {
  position: absolute;
  z-index: 1;
  top: 30px;
  left: 46px;
  width: 45px;
  height: 64px;
  transform: rotate(90deg);
  transform-origin: 50% 50%;
}

.trump-card-slot .playing-card {
  width: 45px;
  height: 64px;
  min-height: 0;
  border-radius: 7px;
  box-shadow: none;
}

.discard-counter {
  display: none; /* в референсе сброс не показывается */
  align-items: baseline;
  gap: 5px;
  margin-left: 2px;
  color: #b3a68f;
  font-size: .66rem;
}

.discard-counter strong {
  color: #f0e8d8;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
}

.table-zone {
  position: relative;
  min-height: 0;
  margin: 0 10px;
  border-radius: var(--radius-md);
  outline: none;
}

.table-zone.is-attack-target {
  background: rgb(243 237 226 / 8%);
  box-shadow: inset 0 0 0 1px rgb(243 237 226 / 38%);
}

.table-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  color: rgb(240 232 216 / 45%);
  font-size: .75rem;
  pointer-events: none;
}

.table-empty p {
  margin: 8px 0 0;
}

.table-target-mark {
  display: block;
  width: 42px;
  height: 58px;
  border: 1px dashed rgb(240 232 216 / 35%);
  border-radius: 7px;
}

.table-zone.is-attack-target .table-target-mark {
  border-color: #cfe3f5;
}

.card-pairs {
  display: grid;
  width: auto;
  height: 100%;
  grid-template-columns: repeat(3, minmax(102px, 1fr));
  align-content: center;
  justify-items: center;
  gap: 16px 6px; /* просторнее, пары не слипаются */
  margin: 0;
  /* слева зарезервирована полоса под абсолютную колоду — пары на неё не наезжают */
  padding: 5px 0 10px 74px;
}

.card-pair {
  position: relative;
  width: 118px;
  height: 150px;
  border-radius: 9px;
  /* лёгкий индивидуальный сдвиг пары — естественный развал стола */
  transform: translate(var(--pair-dx, 0px), var(--pair-dy, 0px));
}

.card-pair.is-defend-target::after {
  position: absolute;
  z-index: -1;
  inset: -5px;
  border: 1px solid rgb(240 231 210 / 65%);
  border-radius: 11px;
  content: "";
}

.playing-card {
  position: relative;
  display: block;
  width: 68px;
  height: 96px;
  min-height: 44px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: transparent;
  box-shadow: 0 3px 6px rgb(0 0 0 / 24%);
  cursor: pointer;
  user-select: none;
  transition: transform 200ms var(--ease-out), opacity 180ms ease-out, filter 180ms ease-out;
}

.card-svg {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

/* Пригашение нелегальных карт — мягкое затемнение, без серости */
/* Настройка «подсказки ходов» выключена — не подсвечиваем цели для хода */
body.no-hints .table-zone.is-attack-target,
body.no-hints .table-zone.is-drop-hover {
  background: none;
  box-shadow: none;
}

body.no-hints .card-pair.is-defend-target::after,
body.no-hints .card-pair.is-drop-hover::after {
  content: none;
}

/* --- Анимации карт --- */

/* Атакующая карта прилетает снизу (из руки) на стол */
@keyframes card-land {
  from {
    transform: translateY(36vh) scale(1.12) rotate(7deg);
    opacity: .45;
  }
}

.attack-card.card-land {
  animation: card-land 240ms var(--ease-out);
}

/* Защитная — с большим доворотом, ложится поверх (конечное положение — свой tilt карты) */
@keyframes card-land-def {
  from {
    transform: translate(26px, 30vh) rotate(70deg) scale(1.1);
    opacity: .45;
  }
}

.defense-card.card-land-def {
  animation: card-land-def 260ms var(--ease-out);
}

/* Добор: карта прилетает в руку от колоды (слева сверху) */
@keyframes card-draw {
  from {
    transform: translate(-34vw, -36vh) rotate(-24deg) scale(.72);
    opacity: 0;
  }
}

.hand-card.card-drawn {
  animation: card-draw 320ms var(--ease-out);
}

/* Улёт всего стола: клон поверх, живой DOM уже пуст */
.table-flyout {
  position: absolute;
  z-index: 5;
  inset: 0;
  pointer-events: none;
  transition: transform 400ms ease-in, opacity 400ms ease-in;
}

.table-flyout.fly-discard {
  transform: translate(72vw, -18vh) rotate(20deg) scale(.85);
  opacity: 0;
}

.table-flyout.fly-down {
  transform: translateY(58vh) scale(.82);
  opacity: 0;
}

.table-flyout.fly-up {
  transform: translateY(-58vh) scale(.82);
  opacity: 0;
}

.playing-card.is-selected {
  transform: translateY(-14px) rotate(var(--fan-rotation, 0deg));
}

.attack-card {
  position: absolute;
  top: 2px;
  left: 2px;
  transform: rotate(var(--tilt, -2deg));
}

/* Защитная карта поверх атакующей: сдвиг вправо-вниз и поворот ~13° */
.defense-card {
  position: absolute;
  z-index: 2;
  top: 16px;
  left: 34px;
  transform: rotate(var(--tilt-def, 35deg)); /* ~30–41°, у каждой карты свой */
}

/* Колода разобрана: на её месте остаётся только значок козырной масти */
.trump-suit-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  color: #33291d;
  background: rgb(246 240 228 / 92%);
  font-size: 1.3rem;
  line-height: 1;
  transform: rotate(-90deg); /* компенсирует поворот слота козыря */
}

.trump-suit-mark.red {
  color: #a51f27;
}

.card-pair .playing-card {
  width: 94px;
  height: 132px;
}

/* Нижняя зона без тёмной подложки — рука лежит прямо на сукне, как в референсе */
.player-zone {
  position: relative;
  padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
}

.turn-status-row {
  display: flex;
  min-height: 24px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.turn-status,
.hand-count-label {
  margin: 0;
  color: #e6dcc6;
  font-size: .72rem;
  font-weight: 650;
}

.turn-status {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hand-count-label {
  flex: 0 0 auto;
  color: #b3a68f;
  font-variant-numeric: tabular-nums;
}

.turn-timer {
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgb(255 255 255 / 12%);
}

.timer-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #e2cf9f;
  transform-origin: left;
  transition: width 160ms linear, background-color 180ms ease-out;
}

.timer-bar.is-low {
  background: var(--danger);
}

/* Белая подложка внизу: слева действия, в центре свой аватар, справа платные фишки */
.bottom-bar {
  position: relative;
  z-index: 4;
  display: grid;
  min-height: 78px;
  align-items: center;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  margin: 0 -10px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: rgb(241 233 218 / 97%);
  box-shadow: 0 -6px 18px rgb(18 15 10 / 35%);
}

.bar-actions {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
}

.bar-me {
  display: flex;
  justify-content: center;
}

/* Свой аватар — по центру бара по вертикали */
.me-avatar {
  width: 58px;
  height: 58px;
  border-width: 3px;
}

.bar-perks {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.perk-button {
  display: flex;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border: 0;
  border-radius: 10px;
  background: rgb(51 41 29 / 8%);
  color: #4a3d2c;
  cursor: pointer;
}

.perk-button:disabled {
  opacity: .38;
}

.perk-icon {
  display: grid;
  width: 26px;
  height: 24px;
  place-items: center;
}

.perk-icon svg {
  width: 22px;
  height: 22px;
}

.perk-cost {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: #7d6a4a;
  font-size: .66rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.perk-cost::after {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9a23e;
  content: "";
}

/* Рамка своего аватара: золото — мой ход, красная — нет */
.me-avatar { border-color: var(--danger); cursor: pointer; }
.bar-me.is-turn .me-avatar { border-color: var(--success); }

.bar-me { position: relative; }

/* Меню реакций над своим аватаром */
.emoji-menu {
  position: absolute;
  z-index: var(--z-modal);
  bottom: calc(100% + 10px);
  left: 50%;
  display: grid;
  width: max-content;
  max-width: 260px;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px;
  border-radius: 14px;
  background: rgb(40 34 26 / 97%);
  box-shadow: 0 10px 26px rgb(10 8 5 / 45%);
  transform: translateX(-50%);
  animation: peek-in 160ms var(--ease-out);
}

.emoji-item {
  display: grid;
  width: 44px;
  height: 44px;
  min-height: 0;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}

.emoji-item:active {
  background: rgb(243 237 226 / 12%);
  transform: scale(.92);
}

/* Реакция над аватаром: вспыхивает, держится, тает */
@keyframes reaction-pop {
  0% { transform: translate(-50%, -40%) scale(.3); opacity: 0; }
  12% { transform: translate(-50%, -100%) scale(1.25); opacity: 1; }
  20% { transform: translate(-50%, -100%) scale(1); }
  78% { transform: translate(-50%, -104%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -118%) scale(.85); opacity: 0; }
}

.reaction-burst {
  position: fixed;
  z-index: var(--z-toast);
  font-size: 46px;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 3px 6px rgb(10 8 5 / 45%));
  animation: reaction-pop 2.4s var(--ease-out) forwards;
}

.reaction-burst img {
  display: block;
  height: 74px;
}

.emoji-item img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.skin-preview-emoji img {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

/* Поп-ап подсмотренной карты */
@keyframes peek-in {
  from {
    transform: translate(-50%, -46%) scale(.9);
    opacity: 0;
  }
}

.peek-pop {
  position: fixed;
  z-index: var(--z-toast);
  top: 44%;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 18px 16px;
  border-radius: 14px;
  background: rgb(40 34 26 / 96%);
  box-shadow: 0 10px 30px rgb(10 8 5 / 50%);
  transform: translate(-50%, -50%);
  animation: peek-in 200ms var(--ease-out);
  pointer-events: none;
}

.peek-pop span {
  color: var(--tg-hint);
  font-size: .78rem;
  font-weight: 700;
}

.peek-pop .playing-card {
  width: 96px;
  height: 134px;
}

.game-action {
  min-width: 96px;
  min-height: 48px;
  padding: 0 18px;
  color: #f3ede2;
  background: #3a3227; /* тёмная на кремовой подложке */
  font-size: 1.02rem;
}

/* «Взять» — тёплый красный */
.game-action.danger-action {
  background: var(--danger);
}

.game-action:disabled {
  opacity: .36;
}

.action-hint {
  display: none; /* роль ясна из подсветки и кнопок; текст остаётся для aria в статусе */
}

.hand-scroll {
  width: 100%;
  height: 176px; /* низ карт мягко срезается краем экрана, как в референсе */
  overflow: hidden; /* рука всегда влезает целиком — перекрытие сжимает layoutHand() */
}

/* Рука: крупные карты почти прямой лентой с сильным перекрытием */
.player-hand {
  display: flex;
  width: max-content;
  min-width: 100%;
  align-items: flex-start;
  justify-content: center;
  padding: 44px 12px 0;
}

.hand-card {
  width: 141px;
  height: 198px;
  flex: 0 0 auto;
  margin-left: -54px; /* базовое перекрытие; фактическое ставит layoutHand() */
  /* естественный развал: у каждой карты свой лёгкий наклон и подъём */
  transform: rotate(var(--hand-tilt, 0deg)) translateY(var(--hand-rise, 0px));
  transform-origin: 50% 110%;
  touch-action: none; /* драг через Pointer Events без прокрутки */
  transition: transform 170ms var(--ease-out); /* живой отклик: плавный подъём */
}

/* Лёгкий приподъём при касании — тактильность до отпускания */
.hand-card:active:not(.is-selected) {
  transform: rotate(var(--hand-tilt, 0deg)) translateY(calc(var(--hand-rise, 0px) - 8px));
}

/* Кольцо фокуса не должно прятаться под соседней картой веера */
.hand-card:focus-visible {
  z-index: 2;
}

.hand-card:first-child {
  margin-left: 0;
}

.hand-card.is-selected {
  z-index: 1;
  transform: rotate(0deg) translateY(calc(var(--hand-rise, 0px) - 40px)); /* выбранная выпрямляется и поднимается */
}

.hand-card.is-dragging-source {
  opacity: .32;
}

/* Карта-призрак: следует за пальцем поверх всего, только transform. */
.card-ghost {
  position: fixed;
  z-index: var(--z-toast);
  top: 0;
  left: 0;
  width: 141px;
  height: 198px;
  pointer-events: none;
  box-shadow: 0 10px 22px rgb(0 0 0 / 42%);
  will-change: transform;
}

.card-ghost.is-returning {
  transition: transform 200ms var(--ease-out);
}

/* Подсветка цели под призраком. */
.table-zone.is-drop-hover {
  background: rgb(243 237 226 / 15%);
  box-shadow: inset 0 0 0 2px rgb(243 237 226 / 70%);
}

.card-pair.is-drop-hover::after {
  border-color: rgb(240 230 205 / 95%);
  border-width: 2px;
}

/* Result overlay and toast */

.game-over {
  position: fixed;
  z-index: var(--z-modal);
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
  background: rgb(4 10 8 / 74%);
}

.result-panel {
  width: min(100%, 420px);
  padding: 24px;
  border-radius: 16px;
  color: var(--tg-text);
  background: rgb(40 34 26 / 97%);
  box-shadow: 0 8px 24px rgb(0 0 0 / 30%);
  animation: result-in 220ms var(--ease-out);
}

@keyframes result-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
}

.result-panel h2 {
  margin: 5px 0 20px;
  font-size: 1.65rem;
  letter-spacing: -.025em;
}

.result-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--line);
}

.result-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 16px;
  padding: 12px 14px;
  background: var(--tg-secondary-bg);
}

.result-name {
  display: flex;
  overflow: hidden;
  align-items: center;
  gap: 8px;
  font-weight: 680;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-name .avatar {
  width: 24px;
  height: 24px;
  font-size: .6rem;
}

.result-delta {
  font-weight: 780;
  font-variant-numeric: tabular-nums;
}

.result-delta.positive { color: var(--success); }
.result-delta.negative { color: var(--danger); }

.result-balance {
  grid-column: 1 / -1;
  color: var(--tg-hint);
  font-size: .75rem;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 20px;
}

/* Тосты сверху — не заслоняют руку и стол */
.toast-region {
  position: fixed;
  z-index: var(--z-toast);
  top: calc(10px + env(safe-area-inset-top));
  right: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  width: min(100%, 440px);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: #f3ede2;
  background: rgb(38 32 25 / 94%);
  font-size: .875rem;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 4px 8px rgb(0 0 0 / 24%);
  animation: toast-in 180ms var(--ease-out);
}

.toast.is-error {
  background: #743d39;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@media (min-width: 640px) {
  .screen-page {
    padding-right: 26px;
    padding-left: 26px;
  }

  .rooms-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .game-topbar {
    padding-right: 22px;
    padding-left: 22px;
  }

  .opponents {
    gap: 32px;
  }

  .card-pairs {
    grid-template-columns: repeat(3, 150px);
    gap: 16px 12px;
  }

  .card-pair {
    transform: translate(var(--pair-dx, 0px), var(--pair-dy, 0px)) scale(1.06);
  }

  .card-pair .playing-card {
    width: 96px;
    height: 134px;
  }
}

@media (max-height: 660px) {
  .game-topbar {
    min-height: 92px;
  }

  .deck-column {
    top: 106px;
  }

  .deck-area {
    transform: scale(.86);
    transform-origin: top left;
  }

  .hand-scroll {
    height: 150px;
  }

  .player-hand {
    padding-top: 34px;
  }

  .hand-card,
  .card-ghost {
    width: 114px;
    height: 160px;
  }

  .hand-card {
    margin-left: -46px;
  }

  .card-pairs {
    transform: scale(.88);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
