:root {
  color-scheme: dark;
  --app-width: 460px;
  --app-min-width: 420px;
  --app-current-width: min(var(--app-width), max(var(--app-min-width), 100vw));
  --app-height: 100dvh;
  --app-min-height: 720px;
  --app-layout-height: max(var(--app-height), var(--app-min-height));
  --bg: #050612;
  --bg-2: #0b1024;
  --panel: rgba(18, 22, 42, 0.78);
  --panel-strong: rgba(23, 28, 54, 0.94);
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(151, 132, 255, 0.32);
  --text: #f7f3ea;
  --muted: #98a2bd;
  --blue: #406dff;
  --violet: #9a7cff;
  --gold: #d7b46a;
  --green: #36d48a;
  --red: #ff5d6c;
  --black-card: #172033;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
  --tg-safe-top: 0px;
  --tg-safe-bottom: 0px;
  --tg-content-safe-top: 0px;
  --tg-content-safe-bottom: 0px;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-top), var(--tg-content-safe-top));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom), var(--tg-content-safe-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: var(--app-min-width);
  min-height: 100%;
}

html {
  overflow-x: auto;
}

body {
  min-height: var(--app-layout-height);
  overflow-x: auto;
  background:
    radial-gradient(circle at 20% -10%, rgba(154, 124, 255, 0.22), transparent 34%),
    radial-gradient(circle at 100% 18%, rgba(64, 109, 255, 0.18), transparent 32%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 58%);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: inherit;
}

button,
input {
  font: inherit;
}

button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  padding: 0 14px;
  font-weight: 800;
  text-transform: uppercase;
}

.app {
  width: var(--app-current-width);
  min-width: var(--app-min-width);
  min-height: var(--app-layout-height);
  margin: 0 auto;
  padding: calc(12px + var(--safe-top)) 12px calc(78px + var(--safe-bottom));
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0 10px;
}

.eyebrow {
  display: block;
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1;
}

h2 {
  font-size: 24px;
}

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 14px rgba(54, 212, 138, 0.7);
}

.screen {
  display: none;
}

.screen.active {
  display: grid;
  gap: 14px;
}

body[data-screen="game"] .app {
  width: var(--app-current-width);
  min-width: var(--app-min-width);
  min-height: var(--app-layout-height);
  padding: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 38%, rgba(38, 122, 78, 0.34), transparent 48%),
    radial-gradient(circle at 15% 8%, rgba(24, 88, 58, 0.55), transparent 35%),
    linear-gradient(145deg, #0f5137, #083322 58%, #061f18);
}

body[data-screen="game"] .bottom-nav {
  display: none;
}

body[data-screen="game"] .app-header {
  display: none;
}

body[data-screen="game"] .app-header .eyebrow {
  display: none;
}

body[data-screen="game"] h1 {
  font-size: 22px;
}

.profile-card,
.join-card,
.waiting-card,
.panel,
.opponent-zone,
.table-status,
.deck-row,
.game-log,
.shop-hero,
.shop-grid > div {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.profile-card {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.profile-card span,
.join-card span,
.table-status span,
.deck-row span,
.hand-zone > span,
.opponent-zone span,
.stats-grid span,
.shop-grid span {
  color: var(--muted);
  font-size: 12px;
}

.profile-card strong {
  font-size: 22px;
}

.profile-metrics,
.table-status,
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.profile-metrics > div,
.table-status > div,
.stats-grid > div {
  min-width: 0;
  padding: 11px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

.profile-metrics strong,
.table-status strong,
.stats-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.menu-grid,
.quick-links,
.waiting-actions,
.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.primary {
  border-color: rgba(154, 124, 255, 0.55);
  background: linear-gradient(180deg, #a995ff, #416dff);
  color: #070912;
}

.cta {
  grid-column: 1 / -1;
  min-height: 62px;
  font-size: 18px;
}

.danger {
  border-color: rgba(255, 93, 108, 0.35);
  color: #ffb5be;
}

.mini {
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
}

.join-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.join-row {
  display: grid;
  grid-template-columns: 1fr 94px;
  gap: 8px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: var(--app-current-width);
  min-width: var(--app-min-width);
  transform: translateX(-50%);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(8, 10, 22, 0.92);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.bottom-nav button.active {
  background: rgba(154, 124, 255, 0.16);
  color: var(--text);
}

.waiting-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  text-align: center;
}

.waiting-card h2 {
  font-size: 44px;
  letter-spacing: 0;
}

.players-list,
.leaderboard-list,
.matches-list,
.log-list {
  display: grid;
  gap: 8px;
}

.player-row,
.leaderboard-row,
.match-row,
.log-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}

.player-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.player-row em,
.leaderboard-row em {
  color: var(--gold);
  font-style: normal;
  font-weight: 800;
}

.game-screen {
  position: relative;
  display: none;
  min-height: var(--app-layout-height);
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 42%, rgba(58, 138, 90, 0.24), transparent 44%),
    repeating-linear-gradient(28deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 9px),
    linear-gradient(155deg, #0e5136, #073820 56%, #052318);
}

.game-screen.active {
  display: block;
}

.game-topbar {
  position: absolute;
  top: calc(8px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.game-topbar > div {
  display: grid;
  gap: 2px;
}

.game-topbar strong {
  font-size: 15px;
}

.game-topbar span {
  color: rgba(235, 255, 241, 0.62);
  font-size: 11px;
}

.game-topbar button {
  pointer-events: auto;
}

.opponent-zone {
  position: absolute;
  top: calc(42px + var(--safe-top));
  left: 88px;
  right: 10px;
  z-index: 12;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.opponent-zone > div:first-child {
  min-width: 0;
}

.opponent-zone span,
.table-status span {
  color: rgba(235, 255, 241, 0.6);
  font-size: 11px;
}

.opponent-zone strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opponent-meta {
  display: none;
}

.opponent-hand {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 108px;
  padding-right: 4px;
}

.opponent-mini-card {
  width: 22px;
  height: 32px;
  margin-left: -9px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 5px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.1), transparent),
    repeating-linear-gradient(45deg, #26376b 0 4px, #18284f 4px 8px);
  box-shadow: 0 8px 12px rgba(0,0,0,0.22);
}

.opponent-count-badge {
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 22px;
  margin-left: 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  color: rgba(235, 255, 241, 0.86);
  font-size: 11px;
  font-weight: 900;
}

.table-status {
  position: absolute;
  top: calc(92px + var(--safe-top));
  left: 86px;
  right: 10px;
  z-index: 11;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.table-status > div {
  min-width: 0;
  padding: 6px 7px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.16);
}

.table-status strong {
  display: block;
  overflow: hidden;
  margin-top: 2px;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-surface {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.deck-area {
  position: absolute;
  top: calc(clamp(76px, 12dvh, 112px) + var(--safe-top));
  left: calc(var(--card-w) * -0.46);
  z-index: 6;
  width: var(--card-w);
  height: var(--card-h);
}

.draw-pile,
.trump-card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
}

.draw-pile {
  left: 0;
  top: 0;
  z-index: 2;
}

.trump-card {
  left: calc(var(--card-w) * 0.46);
  top: calc(var(--card-h) * 0.12);
  z-index: 1;
  transform: rotate(90deg);
  transform-origin: center;
}

.trump-card .card {
  box-shadow: 0 10px 22px rgba(0,0,0,0.26);
}

.card-back {
  width: var(--card-w);
  height: var(--card-h);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 9px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.09), transparent),
    repeating-linear-gradient(45deg, #26376b 0 5px, #192955 5px 10px);
  box-shadow: 0 10px 24px rgba(0,0,0,0.32);
}

.draw-pile .layer {
  position: absolute;
  left: 0;
  top: 0;
}

.draw-pile .layer-1 { transform: translate(0, 0); z-index: 5; }
.draw-pile .layer-2 { transform: translate(1px, 1px); z-index: 4; }
.draw-pile .layer-3 { transform: translate(2px, 2px); z-index: 3; }
.draw-pile .layer-4 { transform: translate(3px, 3px); z-index: 2; }
.draw-pile .layer-5 { transform: translate(4px, 4px); z-index: 1; }

.deck-count {
  position: absolute;
  right: -10px;
  top: -8px;
  z-index: 6;
  display: grid;
  place-items: center;
  min-width: 25px;
  height: 25px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.48);
  color: rgba(235, 255, 241, 0.92);
  font-size: 12px;
  font-weight: 900;
}

.battle-table {
  position: absolute;
  left: 12px;
  right: 12px;
  top: clamp(152px, 23dvh, 190px);
  bottom: calc(218px + var(--safe-bottom));
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  place-content: center;
  gap: 12px 8px;
  min-height: 230px;
  padding: 4px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.battle-table.pairs-1,
.battle-table.pairs-2 {
  grid-template-columns: repeat(2, minmax(0, 118px));
}

.battle-table.pairs-3,
.battle-table.pairs-4 {
  grid-template-columns: repeat(2, minmax(0, 118px));
}

.battle-table.pairs-5,
.battle-table.pairs-6 {
  grid-template-columns: repeat(3, minmax(0, 104px));
}

.attack-pair {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: calc(var(--card-h) + 30px);
}

.attack-pair .card:first-child {
  transform: rotate(-4deg) translate(-8px, 8px);
}

.attack-pair .card:nth-child(2),
.attack-pair .defense-slot {
  position: absolute;
  transform: rotate(7deg) translate(18px, -8px);
}

.empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 160px;
  color: rgba(235, 255, 241, 0.28);
  border: 0;
  border-radius: 0;
  font-weight: 800;
}

.defense-slot {
  display: grid;
  place-items: center;
  width: var(--card-w);
  height: var(--card-h);
  border: 1px dashed rgba(235, 255, 241, 0.18);
  border-radius: 9px;
  color: rgba(235, 255, 241, 0.32);
  font-size: 10px;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.08);
}

.card {
  display: grid;
  align-content: space-between;
  flex: 0 0 var(--card-w);
  width: var(--card-w);
  height: var(--card-h);
  min-height: var(--card-h);
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 9px;
  background:
    linear-gradient(145deg, #fffaf0, #e8e0d3);
  color: var(--black-card);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
}

.card strong {
  font-size: 19px;
  line-height: 1;
}

.card span {
  font-size: 24px;
  line-height: 1;
}

.card.red {
  color: #bf2034;
}

.card.black {
  color: #141a28;
}

.card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(215, 180, 106, 0.3), 0 0 24px rgba(215, 180, 106, 0.38);
  transform: translateY(-10px);
}

.card:disabled {
  opacity: 1;
}

.hand-zone {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(104px + var(--safe-bottom));
  z-index: 8;
  display: block;
  padding: 0 0 4px;
  overflow: hidden;
  background: none;
}

.hand {
  display: flex;
  gap: 0;
  min-height: calc(var(--card-h) + 22px);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 18px 14px 8px;
  scrollbar-width: none;
}

.hand::-webkit-scrollbar {
  display: none;
}

.hand .card {
  flex: 0 0 var(--card-w);
  margin-right: calc(var(--card-w) * -0.26);
  transform-origin: center 120%;
}

.hand .card:nth-child(6n+1) { transform: rotate(-4deg); }
.hand .card:nth-child(6n+2) { transform: rotate(-2deg); }
.hand .card:nth-child(6n+3) { transform: rotate(-1deg); }
.hand .card:nth-child(6n+4) { transform: rotate(1deg); }
.hand .card:nth-child(6n+5) { transform: rotate(2deg); }
.hand .card:nth-child(6n+6) { transform: rotate(4deg); }

.hand .card.selected {
  transform: translateY(-14px) rotate(0deg);
}

.game-log {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(202px + var(--safe-bottom));
  z-index: 7;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.game-log summary {
  display: block;
  overflow: hidden;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  color: rgba(235, 255, 241, 0.58);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-log .log-list {
  max-height: 104px;
  overflow-y: auto;
  padding-top: 6px;
}

.action-dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9;
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  gap: 10px;
  height: calc(96px + var(--safe-bottom));
  padding: 12px 14px calc(12px + var(--safe-bottom));
  background: rgba(2, 12, 9, 0.72);
  backdrop-filter: blur(14px);
}

.table-icon-btn {
  display: grid;
  place-items: center;
  min-height: 46px;
  width: 46px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.24);
  color: rgba(235, 255, 241, 0.86);
  font-size: 22px;
  font-weight: 900;
}

.table-icon-btn.secondary-action {
  width: auto;
  min-width: 58px;
  padding: 0 10px;
  border-radius: 20px;
  font-size: 13px;
}

.primary-action {
  min-height: 58px;
  border: 0;
  border-radius: 22px;
  background: #2fba6f;
  color: #03130c;
  font-size: 18px;
  font-weight: 900;
}

.primary-action:disabled {
  background: rgba(235, 255, 241, 0.14);
  color: rgba(235, 255, 241, 0.42);
  opacity: 1;
}

.legacy-actions {
  display: none;
}

.is-hidden {
  display: none !important;
}

.screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel,
.compact {
  padding: 14px;
}

.panel-title {
  display: block;
  margin-bottom: 10px;
}

.leaderboard-row {
  grid-template-columns: 34px 1fr auto;
  align-items: center;
}

.leaderboard-row.current {
  border: 1px solid rgba(215, 180, 106, 0.42);
  background: rgba(215, 180, 106, 0.11);
}

.leaderboard-row small {
  color: var(--muted);
}

.stats-grid {
  grid-template-columns: repeat(2, 1fr);
}

.shop-hero {
  display: grid;
  gap: 8px;
  padding: 18px;
}

.shop-grid {
  display: grid;
  gap: 10px;
}

.shop-grid > div {
  display: grid;
  gap: 4px;
  padding: 14px;
}

.toast {
  position: fixed;
  right: max(12px, calc((100vw - var(--app-width)) / 2 + 12px));
  bottom: calc(16px + var(--safe-bottom));
  z-index: 30;
  width: min(360px, calc(100% - 24px));
  padding: 12px 14px;
  border: 1px solid rgba(255, 93, 108, 0.35);
  border-radius: 14px;
  background: rgba(35, 14, 25, 0.94);
  color: #ffd6dc;
  box-shadow: var(--shadow);
  transform: translateY(140%);
  transition: transform 160ms ease;
}

.toast.visible {
  transform: translateY(0);
}

.inactive-screen,
.result-overlay {
  position: fixed;
  inset: 0;
  min-width: var(--app-min-width);
  overflow-x: auto;
  z-index: 40;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(2, 3, 10, 0.72);
  backdrop-filter: blur(10px);
}

.inactive-screen.visible,
.result-overlay.visible {
  display: grid;
}

.modal-card,
.result-card {
  width: min(390px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.result-card {
  display: grid;
  gap: 12px;
}

.rating-change {
  color: var(--gold);
  font-size: 18px;
  font-weight: 900;
}

@media (min-width: 760px) {
  body {
    display: grid;
    justify-items: center;
  }

  .app {
    border-inline: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(5, 6, 18, 0.38);
  }
}

select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  padding: 0 14px;
  font-weight: 800;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  min-width: var(--app-min-width);
  overflow-x: auto;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(10px);
}

.settings-overlay.visible {
  display: grid;
}

.settings-card {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.field-label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.field-label small,
.stake-range small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.stake-range {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.stake-range small {
  grid-column: 1 / -1;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.toggle-row span {
  display: grid;
  gap: 3px;
}

.toggle-row small {
  color: var(--muted);
  font-size: 11px;
}

.toggle-row input[type="checkbox"] {
  width: 24px;
  height: 24px;
  min-height: 24px;
  accent-color: var(--gold);
}

.room-flags,
.match-flags,
.room-card-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.match-flags {
  padding: 0 12px;
}

.flag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 26px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
}

.flag-chip.off {
  color: var(--muted);
  opacity: 0.72;
}

.room-filter-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.rooms-list {
  display: grid;
  gap: 10px;
}

.room-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.room-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.room-card-head strong {
  font-size: 18px;
}

.room-card-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.room-card-meta b {
  display: block;
  color: var(--text);
  font-size: 14px;
}

.room-card-actions {
  display: grid;
  grid-template-columns: 1fr;
}

/* Fixed 6-slot hand layout. Cards beyond the current slot page are handled from the "Мои карты" panel. */
.hand {
  justify-content: center;
  overflow: hidden;
  padding-inline: 10px;
}

.hand-slot {
  position: relative;
  flex: 0 0 var(--card-w);
  width: var(--card-w);
  min-height: calc(var(--card-h) + 20px);
  margin-right: calc(var(--card-w) * -0.31);
  display: grid;
  place-items: end center;
}

.hand-slot:last-child {
  margin-right: 0;
}

.hand-slot .card {
  flex: 0 0 auto;
  width: var(--card-w);
  margin-right: 0;
}

.hand .hand-slot:nth-child(6n+1) .card { transform: rotate(-4deg); }
.hand .hand-slot:nth-child(6n+2) .card { transform: rotate(-2deg); }
.hand .hand-slot:nth-child(6n+3) .card { transform: rotate(-1deg); }
.hand .hand-slot:nth-child(6n+4) .card { transform: rotate(1deg); }
.hand .hand-slot:nth-child(6n+5) .card { transform: rotate(2deg); }
.hand .hand-slot:nth-child(6n+6) .card { transform: rotate(4deg); }
.hand .hand-slot .card.selected { transform: translateY(-14px) rotate(0deg); }

.hand-slot-empty {
  width: calc(var(--card-w) * 0.82);
  height: calc(var(--card-h) * 0.86);
  display: grid;
  place-items: center;
  border: 1px dashed rgba(235, 255, 241, 0.18);
  border-radius: 12px;
  color: rgba(235, 255, 241, 0.32);
  font-size: 12px;
  font-weight: 900;
  background: rgba(0, 0, 0, 0.12);
}

.action-dock {
  grid-template-columns: 52px minmax(0, 1fr) minmax(82px, 112px) 52px;
}

.hand-slots-button {
  min-height: 50px;
  padding: 0 10px;
  border: 1px solid rgba(235, 255, 241, 0.16);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(235, 255, 241, 0.92);
  font-size: 12px;
  font-weight: 950;
  line-height: 1.1;
}

.hand-slots-button[data-has-more="true"] {
  border-color: rgba(215, 180, 106, 0.46);
  color: #f3d79b;
}

.hand-slots-button span,
.hand-slots-button small {
  display: block;
}

.hand-slots-button small {
  margin-top: 2px;
  font-size: 10px;
  font-weight: 850;
  opacity: 0.78;
}

.hand-slots-button:disabled {
  opacity: 0.56;
}

.hand-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(8px);
}

.hand-overlay.visible {
  display: flex;
}

.hand-panel {
  width: min(100%, 520px);
  max-height: min(82dvh, 620px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(235, 255, 241, 0.14);
  border-radius: 26px 26px 0 0;
  background: rgba(6, 18, 14, 0.98);
  box-shadow: 0 -24px 70px rgba(0, 0, 0, 0.45);
  color: rgba(235, 255, 241, 0.94);
}

.hand-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
}

.hand-panel-head h2 {
  margin: 2px 0 0;
  font-size: 20px;
}

.hand-panel-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  padding: 0 16px 10px;
}

.hand-panel-controls button {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 14px;
  font-size: 12px;
}

.hand-panel-controls strong {
  min-width: 58px;
  text-align: center;
  color: #f3d79b;
}

.hand-panel-hint {
  margin: 0;
  padding: 0 16px 10px;
  color: rgba(235, 255, 241, 0.62);
  font-size: 12px;
  line-height: 1.35;
}

.hand-panel-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 6px;
  max-height: min(54dvh, 420px);
  overflow-y: auto;
  padding: 10px 16px calc(16px + var(--safe-bottom));
}

.hand-picker-card {
  position: relative;
  display: grid;
  place-items: center;
  min-height: calc(var(--card-h) + 10px);
  border: 1px solid transparent;
  border-radius: 16px;
  cursor: pointer;
}

.hand-picker-card::before {
  content: attr(data-card-index);
  position: absolute;
  left: 4px;
  top: 4px;
  z-index: 2;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.42);
  color: rgba(235, 255, 241, 0.84);
  font-size: 10px;
  font-weight: 950;
}

.hand-picker-card.selected {
  border-color: rgba(215, 180, 106, 0.62);
  background: rgba(215, 180, 106, 0.12);
}

.hand-picker-card .card {
  pointer-events: none;
  transform: none;
}


/* Hand slots v2 fallback. ui-kit.css is loaded after this file, but these rules also protect old cached layouts. */
body[data-screen="game"] .hand.hand-slots-active {
  --slot-card-w: clamp(48px, calc(var(--app-current-width) * 0.162), var(--card-w));
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  justify-items: center;
  align-items: end;
  gap: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  padding: 16px 4px 8px;
}

body[data-screen="game"] .hand.hand-slots-active > .card {
  display: none;
}

body[data-screen="game"] .hand.hand-slots-active .hand-slot {
  width: 100%;
  min-width: 0;
  margin: 0;
}

body[data-screen="game"] .hand.hand-slots-active .hand-slot .card {
  width: var(--slot-card-w);
  flex-basis: var(--slot-card-w);
  height: calc(var(--slot-card-w) * 1.435);
  min-height: calc(var(--slot-card-w) * 1.435);
  margin: 0;
}


/* Casino visual refresh: shell, menus, overlays. Logic-facing ids/classes are unchanged. */
:root {
  --casino-black: #06030b;
  --casino-ink: #0f0715;
  --casino-wine: #320814;
  --casino-wine-2: #5d1023;
  --casino-gold: #f5cf7a;
  --casino-gold-soft: rgba(245, 207, 122, 0.68);
  --casino-gold-line: rgba(245, 207, 122, 0.28);
  --casino-red: #ff3f64;
  --casino-green: #22c16b;
  --casino-panel: rgba(16, 7, 20, 0.82);
  --casino-panel-strong: rgba(22, 9, 25, 0.96);
  --casino-glass: rgba(255, 255, 255, 0.07);
  --casino-shadow: 0 24px 70px rgba(0, 0, 0, 0.5), 0 0 34px rgba(245, 207, 122, 0.08);
  --line: rgba(245, 207, 122, 0.16);
  --line-strong: rgba(245, 207, 122, 0.34);
  --panel: var(--casino-panel);
  --panel-strong: var(--casino-panel-strong);
  --gold: var(--casino-gold);
  --blue: #b41f3c;
  --violet: #f5cf7a;
  --green: var(--casino-green);
  --red: var(--casino-red);
  --shadow: var(--casino-shadow);
}

body {
  background:
    radial-gradient(circle at 12% -6%, rgba(245, 207, 122, 0.18), transparent 30%),
    radial-gradient(circle at 92% 10%, rgba(255, 63, 100, 0.2), transparent 28%),
    radial-gradient(circle at 50% 118%, rgba(24, 143, 82, 0.16), transparent 35%),
    linear-gradient(180deg, #120714 0%, #08030b 58%, #030205 100%);
}

body::before {
  background:
    linear-gradient(90deg, rgba(245, 207, 122, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(245, 207, 122, 0.026) 1px, transparent 1px),
    inherit;
  background-size: 34px 34px, 34px 34px, auto;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 28%, transparent 0 20%, rgba(0, 0, 0, 0.22) 52%, rgba(0, 0, 0, 0.68) 100%),
    repeating-conic-gradient(from 8deg at 50% -8%, rgba(245, 207, 122, 0.045) 0 7deg, transparent 7deg 14deg);
  opacity: 0.75;
}

.app {
  position: relative;
}

.app-header {
  position: relative;
  align-items: center;
  padding: 10px 2px 14px;
}

.app-header::before {
  content: "♠ ♥ ♦ ♣";
  position: absolute;
  left: 2px;
  top: -1px;
  color: rgba(245, 207, 122, 0.42);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.42em;
  pointer-events: none;
}

h1,
h2 {
  letter-spacing: -0.03em;
  text-shadow: 0 2px 22px rgba(245, 207, 122, 0.12);
}

h1 {
  padding-top: 8px;
  color: #fff7df;
}

.eyebrow {
  color: var(--casino-gold);
  letter-spacing: 0.12em;
}

.connection-pill,
.flag-chip,
.bottom-nav,
.settings-card,
.modal-card,
.result-card,
.profile-card,
.join-card,
.waiting-card,
.panel,
.shop-hero,
.shop-grid > div,
.room-card,
.leaderboard-row,
.match-row,
.log-row,
.player-row,
.stats-grid > div,
.profile-metrics > div {
  border-color: var(--casino-gold-line);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025)),
    linear-gradient(180deg, rgba(45, 12, 27, 0.92), rgba(13, 6, 18, 0.9));
  box-shadow: var(--casino-shadow);
}

.profile-card,
.waiting-card,
.join-card,
.settings-card,
.result-card,
.room-card,
.shop-hero {
  position: relative;
  overflow: hidden;
}

.profile-card::before,
.waiting-card::before,
.join-card::before,
.settings-card::before,
.result-card::before,
.room-card::before,
.shop-hero::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, rgba(245, 207, 122, 0.22), transparent 22%, transparent 72%, rgba(255, 63, 100, 0.1)),
    radial-gradient(circle at 92% 10%, rgba(245, 207, 122, 0.14), transparent 24%);
  opacity: 0.72;
}

.profile-card > *,
.waiting-card > *,
.join-card > *,
.settings-card > *,
.result-card > *,
.room-card > *,
.shop-hero > * {
  position: relative;
  z-index: 1;
}

.profile-card strong,
.stats-grid strong,
.profile-metrics strong,
.rating-change,
.waiting-card h2,
.room-card-head strong {
  color: #fff1bf;
  text-shadow: 0 0 18px rgba(245, 207, 122, 0.18);
}

button,
select,
input {
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease, background 150ms ease, color 150ms ease;
}

button:not(:disabled):hover,
button:not(:disabled):focus-visible,
input:focus,
select:focus {
  border-color: rgba(245, 207, 122, 0.58);
  box-shadow: 0 0 0 3px rgba(245, 207, 122, 0.12), 0 12px 30px rgba(0, 0, 0, 0.24);
  outline: none;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(1px) scale(0.99);
}

.primary,
.primary-action,
#joinRoomButton,
#setBalanceButton,
#deltaBalanceButton,
#saveSettingsButton {
  border-color: rgba(255, 224, 143, 0.7);
  background:
    linear-gradient(180deg, #fff0b6 0%, #f5c75e 46%, #a46422 100%);
  color: #19070a;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3), inset 0 1px rgba(255, 255, 255, 0.52);
}

.danger,
button.danger {
  border-color: rgba(255, 63, 100, 0.55);
  background: linear-gradient(180deg, rgba(111, 19, 39, 0.92), rgba(48, 8, 20, 0.92));
  color: #ffd3dc;
}

.menu-grid button,
.quick-links button,
.bottom-nav button,
.waiting-actions button,
.result-actions button,
.room-card-actions button {
  position: relative;
  overflow: hidden;
}

.menu-grid button::before,
.quick-links button::before,
.bottom-nav button::before,
.room-card-actions button::before,
.waiting-actions button::before,
.result-actions button::before {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 8px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.16);
  color: #fff5c7;
  font-size: 13px;
  line-height: 1;
  vertical-align: -2px;
}

#resumeActiveMatchButton::before { content: "↺"; }
#quickGameButton::before { content: "⚡"; }
#createRoomButton::before { content: "♛"; }
#roomsListButton::before { content: "♣"; }
#joinRoomButton::before { content: "➜"; }
.quick-links [data-nav="leaderboard"]::before { content: "★"; }
.quick-links [data-nav="profile"]::before { content: "●"; }
.quick-links [data-nav="shop"]::before { content: "♦"; }
.bottom-nav [data-nav="home"]::before { content: "♠"; }
.bottom-nav [data-nav="leaderboard"]::before { content: "★"; }
.bottom-nav [data-nav="shop"]::before { content: "♦"; }
.bottom-nav [data-nav="profile"]::before { content: "●"; }
.room-card-actions button::before { content: "♣"; }
#copyRoomButton::before { content: "⧉"; }
#leaveWaitingButton::before,
#resultHomeButton::before { content: "⌂"; }
#playAgainButton::before { content: "↻"; }

.menu-grid .cta {
  min-height: 68px;
  border-radius: 20px;
  font-size: 18px;
  letter-spacing: 0.01em;
  animation: casinoCtaGlow 3.2s ease-in-out infinite;
}

.quick-links button,
.bottom-nav button {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 3px;
}

.quick-links button::before,
.bottom-nav button::before {
  margin: 0;
}

.bottom-nav {
  border-top-color: rgba(245, 207, 122, 0.24);
  background:
    linear-gradient(180deg, rgba(36, 9, 21, 0.88), rgba(8, 4, 12, 0.96));
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.38);
}

.bottom-nav button.active {
  background: rgba(245, 207, 122, 0.14);
  color: #fff0b4;
  box-shadow: inset 0 0 0 1px rgba(245, 207, 122, 0.28);
}

.flag-chip {
  color: #ffe6a0;
  box-shadow: none;
}

.flag-chip.off {
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 240, 190, 0.54);
}

.toast {
  border-color: rgba(245, 207, 122, 0.42);
  background:
    linear-gradient(135deg, rgba(65, 14, 30, 0.96), rgba(16, 7, 20, 0.96));
  color: #fff0c1;
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.48), 0 0 24px rgba(245, 207, 122, 0.12);
}

.toast.visible {
  animation: casinoToastIn 220ms ease both;
}

.inactive-screen,
.result-overlay,
.settings-overlay,
.hand-overlay {
  background:
    radial-gradient(circle at 50% 32%, rgba(245, 207, 122, 0.12), transparent 34%),
    rgba(3, 2, 6, 0.78);
}

.result-card h2,
.settings-card h2,
.modal-card h2 {
  color: #fff6d8;
}

.stake-range,
.toggle-row,
.room-filter-panel {
  border-color: rgba(245, 207, 122, 0.18);
  background: rgba(255, 255, 255, 0.055);
}

.toggle-row input[type="checkbox"] {
  accent-color: var(--casino-gold);
  filter: drop-shadow(0 0 7px rgba(245, 207, 122, 0.22));
}

.leaderboard-row.current {
  border-color: rgba(245, 207, 122, 0.5);
  background:
    linear-gradient(135deg, rgba(245, 207, 122, 0.17), rgba(65, 14, 30, 0.5));
}

.shop-grid > div::before {
  content: "♦";
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(245, 207, 122, 0.12);
  color: var(--casino-gold);
}

@keyframes casinoCtaGlow {
  0%, 100% { box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3), 0 0 0 rgba(245, 207, 122, 0); }
  50% { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.36), 0 0 26px rgba(245, 207, 122, 0.26); }
}

@keyframes casinoToastIn {
  from { opacity: 0; transform: translateY(140%) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
