:root {
  --card-w: 68px;
  --card-h: 100px;
  --gold: #f4c430;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family: "Segoe UI", Arial, sans-serif;
  color: #fff;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.10), transparent 30%),
    radial-gradient(circle at 50% 30%, #1b7c43 0%, #0d4526 55%, #062815 100%);
}

.hidden {
  display: none !important;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 800;
  color: #2a1c00;
  cursor: pointer;
  background: linear-gradient(180deg, #ffd85e, #d99a00);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28);
  transition: transform 0.18s ease, filter 0.18s ease;
}

button:not(:disabled):hover {
  transform: translateY(-2px);
  filter: brightness(1.06);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(8px);
}

.panel {
  width: min(92vw, 430px);
  padding: 30px 28px;
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.07));
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.panel h1,
.panel h2 {
  margin: 0 0 10px;
}

.panel p {
  margin: 0 0 22px;
  color: rgba(255, 255, 255, 0.82);
}

.panel label {
  display: block;
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.86);
}

.panel select {
  width: 100%;
  margin-bottom: 18px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.26);
  color: #fff;
  outline: none;
  font-size: 16px;
}

.panel select option {
  color: #000;
}

#game {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ── Lobby / multiplayer … ─────────────────────────── */
.panel-section {
  margin-top: 6px;
}

.panel-section h3 {
  margin: 0 0 10px;
  color: rgba(255, 255, 255, 0.92);
}

.lobby-name {
  margin-bottom: 12px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
}

.lobby-msg {
  min-height: 18px;
  margin-top: 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}

.lobby-msg.error {
  color: #ff9c9c;
}

.row {
  display: flex;
  gap: 8px;
}

.row select {
  flex: 1;
  margin-bottom: 8px;
}

.row button {
  flex: 1;
  margin-bottom: 8px;
  white-space: nowrap;
}

.join-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.join-row input {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.26);
  color: #fff;
  outline: none;
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 3px;
  text-align: center;
}

.join-row input::placeholder {
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.55;
}

button.ghost {
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: none;
}

button.ghost:hover {
  background: rgba(255, 255, 255, 0.16);
}

button.mini {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.divider {
  height: 1px;
  margin: 18px 0;
  background: rgba(255, 255, 255, 0.14);
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  max-height: 190px;
  overflow-y: auto;
}

.room-list:empty::after {
  content: "Столов пока нет";
  display: block;
  padding: 14px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
}

.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.10);
  cursor: pointer;
  transition: background 0.15s ease;
}

.room-item:hover {
  background: rgba(255, 255, 255, 0.13);
}

.room-item .code {
  font-weight: 900;
  letter-spacing: 1px;
}

.room-item .meta {
  flex: 1;
  text-align: right;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
}

.room-item .room-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.75);
}

.room-item .room-status.playing {
  background: rgba(255, 209, 102, 0.18);
  color: #ffd166;
}

.login-hint {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.55);
  text-align: center;
  margin-top: 6px;
}

.room-code {
  display: inline-block;
  padding: 14px 22px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.30);
  border: 1px solid rgba(244, 196, 48, 0.55);
  color: #ffd85e;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: 7px;
}

.room-link {
  display: block;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.30);
  border: 1px solid rgba(244, 196, 48, 0.35);
  color: #ffd85e;
  font-size: 12px;
  font-family: inherit;
  word-break: break-all;
  user-select: all;
  margin: 8px 0 4px;
}

.room-list-empty {
  padding: 14px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.18);
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
  text-align: left;
}

.member-item {
  padding: 9px 13px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.10);
  font-size: 14px;
}

.member-item .tag {
  margin-left: 8px;
  font-size: 11px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(244, 196, 48, 0.25);
  color: #ffd85e;
}

.member-item.ai {
  color: rgba(255, 255, 255, 0.55);
}

.member-item.me {
  border-color: rgba(244, 196, 48, 0.55);
  color: #ffd85e;
}

.member-item.free {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.member-item.free button {
  padding: 6px 14px;
  border-radius: 999px;
  border: none;
  background: #f4c430;
  color: #1a1408;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}

.member-item.free button:hover {
  filter: brightness(1.1);
}

.table-lobby {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
}

.table-lobby .panel {
  max-width: 380px;
  width: 100%;
  position: static;
  transform: none;
}

.btn-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

#roomBar {
  position: absolute;
  bottom: 18px;
  left: 18px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

#roomBar #roomCodeLabel {
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: #ffd85e;
}

#status {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(92vw, 780px);
  padding: 11px 18px;
  text-align: center;
  font-weight: 700;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18);
}

#controls {
  position: absolute;
  top: 27px;
  right: 18px;
  z-index: 50;
  display: flex;
  gap: 10px;
}

#table-area {
  position: absolute;
  inset: 0;
}

#table {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: min(780px, 84vw);
  min-height: 200px;
  padding: 22px;
  border-radius: 38px;
  background:
    radial-gradient(circle at 50% 35%, rgba(255,255,255,0.09), transparent 42%),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.045), rgba(0,0,0,0.10));
  border: 2px solid rgba(255, 255, 255, 0.09);
  box-shadow:
    inset 0 0 70px rgba(0, 0, 0, 0.18),
    0 18px 45px rgba(0, 0, 0, 0.18);
}

.table-empty {
  opacity: 0.28;
  font-weight: 800;
  letter-spacing: 0.4px;
  user-select: none;
}

.table-pair {
  position: relative;
  width: calc(var(--card-w) + 30px);
  height: calc(var(--card-h) + 36px);
  animation: pairIn 0.28s ease;
}

.table-pair .card.attack {
  position: absolute;
  left: 0;
  top: 0;
}

.table-pair .card.defense {
  position: absolute;
  left: 24px;
  top: 24px;
  transform: rotate(9deg);
  animation: defenseIn 0.28s ease;
}

.table-pair.selected .card.attack {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
}

.table-pair.undefended .card.attack {
  box-shadow:
    0 0 0 3px rgba(255, 86, 86, 0.42),
    0 10px 20px rgba(0, 0, 0, 0.28);
  animation: pulseAttack 1.2s infinite;
}

#table.taking .card {
  animation: takePulse 0.5s ease;
}

#table.bito .card {
  animation: bitoFade 0.5s ease forwards;
}

#deck-area {
  position: absolute;
  left: 26px;
  top: 76px;
  width: 130px;
  height: 170px;
  z-index: 8;
}

.deck-pile {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 12px;
  background:
    linear-gradient(135deg, #2d567e, #10233a);
  border: 2px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.30);
  z-index: 2;
}

.deck-pile::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 8px;
  background:
    repeating-linear-gradient(45deg,
      transparent 0 14px,
      rgba(255, 255, 255, 0.05) 14px 15px),
    repeating-linear-gradient(-45deg,
      transparent 0 14px,
      rgba(255, 255, 255, 0.05) 14px 15px),
    repeating-linear-gradient(45deg,
      rgba(255, 255, 255, 0.14) 0 6px,
      transparent 6px 12px);
  background-blend-mode: screen;
}

.trump-card {
  position: absolute;
  left: 34px;
  top: 16px;
  transform: rotate(90deg);
  z-index: 1;
}

.trump-card.only {
  left: 0;
  top: 0;
  transform: none;
  z-index: 2;
}

.deck-count {
  position: absolute;
  right: -4px;
  top: -10px;
  z-index: 3;
  min-width: 32px;
  padding: 5px 9px;
  text-align: center;
  font-weight: 900;
  color: #231800;
  background: var(--gold);
  border-radius: 999px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.24);
}

#opponents {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
}

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  text-align: center;
  transition: opacity 0.25s ease, filter 0.25s ease;
}

.pos-top {
  left: 50%;
  top: 13%;
}

.pos-left {
  left: 12%;
  top: 42%;
}

.pos-right {
  left: 88%;
  top: 42%;
}

.seat-info {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.16);
}

.seat.attacker .seat-info {
  box-shadow: 0 0 0 2px rgba(244, 196, 48, 0.9), 0 10px 22px rgba(0,0,0,0.16);
}

.seat.defender .seat-info {
  box-shadow: 0 0 0 2px rgba(94, 167, 255, 0.95), 0 10px 22px rgba(0,0,0,0.16);
}

.seat.out {
  opacity: 0.35;
  filter: grayscale(0.75);
}

.seat .name {
  font-weight: 800;
}

.seat .count {
  min-width: 26px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-weight: 900;
}

.role {
  padding: 3px 7px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.role.attack {
  background: rgba(244, 196, 48, 0.92);
  color: #271b00;
}

.role.defend {
  background: rgba(94, 167, 255, 0.92);
  color: #04172c;
}

.seat-cards {
  display: flex;
  justify-content: center;
  min-height: 62px;
}

.seat-cards .card.back {
  width: 40px;
  height: 58px;
  margin-left: -18px;
  border-radius: 7px;
}

.seat-cards .card.back:first-child {
  margin-left: 0;
}

.out-label {
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.22);
  color: rgba(255, 255, 255, 0.78);
  font-weight: 700;
}

.card {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  flex: 0 0 auto;
  border-radius: 12px;
  user-select: none;
  box-shadow: 0 9px 18px rgba(0, 0, 0, 0.24);
}

.card.face {
  color: #111;
  background: linear-gradient(180deg, #ffffff, #edf1f5);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.card.red {
  color: #c51f3d;
}

.card.back {
  background:
    linear-gradient(135deg, #8a2436, #4a0f19);
  border: 2px solid rgba(255, 255, 255, 0.34);
}

.back-inner {
  position: absolute;
  inset: 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    /* ромбовая сетка-филигрань */
    repeating-linear-gradient(45deg,
      transparent 0 15px,
      rgba(255, 255, 255, 0.05) 15px 16px),
    repeating-linear-gradient(-45deg,
      transparent 0 15px,
      rgba(255, 255, 255, 0.05) 15px 16px),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.06), transparent 60%),
    repeating-linear-gradient(45deg,
      rgba(255, 255, 255, 0.16) 0 6px,
      transparent 6px 12px);
  background-blend-mode: screen;
}

.corner {
  position: absolute;
  z-index: 2;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.06;
  text-align: center;
}

.corner.top {
  left: 6px;
  top: 6px;
}

.corner.bottom {
  right: 6px;
  bottom: 6px;
  transform: rotate(180deg);
}

.suit-big {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 37px;
  opacity: 0.92;
}

/* Подсветка козыря: золотая кантовка + лёгкое внутреннее свечение. */
.card.trump {
  outline: 2px solid rgba(244, 196, 48, 0.55);
  outline-offset: -2px;
  box-shadow:
    inset 0 0 10px rgba(244, 196, 48, 0.22),
    0 9px 18px rgba(0, 0, 0, 0.24);
}

#hand {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-end;
  gap: 10px;
  width: min(88vw, 1000px);
  min-height: 132px;
  padding: 8px 10px;
}

#hand .card {
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

#hand .card:hover {
  transform: translateY(-16px) scale(1.07);
  z-index: 10;
}

#hand .card.playable {
  box-shadow:
    0 0 0 3px rgba(244, 196, 48, 0.82),
    0 10px 20px rgba(0, 0, 0, 0.26);
}

#hand .card.invalid {
  animation: shake 0.35s ease;
}

.flying {
  position: fixed;
  z-index: 2000;
  pointer-events: none;
  box-shadow: 0 20px 35px rgba(0, 0, 0, 0.35);
}

#log {
  position: absolute;
  top: 96px;
  right: 18px;
  bottom: auto;
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: min(280px, 26vw);
  max-height: 220px;
  overflow: hidden;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

#trumpBadge {
  position: absolute;
  right: 18px;
  bottom: 82px;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.30);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.trump-badge-card {
  width: 38px;
  height: 54px;
  font-size: 0.72em;
}

.trump-badge-suit {
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
  width: 34px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff, #edf1f5);
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.trump-badge-suit.red {
  color: #c51f3d;
}

.trump-badge-label {
  font-size: 12px;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.85);
  letter-spacing: 0.3px;
}

.trump-badge-card .corner {
  font-size: 10px;
}

.trump-badge-card .suit-big {
  font-size: 22px;
}

@media (max-width: 820px) {
  #trumpBadge {
    right: 12px;
    bottom: 120px;
  }
}

@keyframes pairIn {
  from {
    opacity: 0;
    transform: scale(0.55);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes defenseIn {
  from {
    opacity: 0;
    transform: translateY(-24px) rotate(14deg) scale(0.82);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(9deg) scale(1);
  }
}

@keyframes pulseAttack {
  0%, 100% {
    box-shadow:
      0 0 0 3px rgba(255, 86, 86, 0.42),
      0 10px 20px rgba(0, 0, 0, 0.28);
  }
  50% {
    box-shadow:
      0 0 0 6px rgba(255, 86, 86, 0.16),
      0 10px 20px rgba(0, 0, 0, 0.28);
  }
}

@keyframes takePulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08) rotate(2deg);
  }
}

@keyframes bitoFade {
  to {
    opacity: 0;
    transform: scale(0.72) translateY(24px);
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-7px);
  }
  75% {
    transform: translateX(7px);
  }
}

@media (max-width: 820px) {
  :root {
    --card-w: 54px;
    --card-h: 80px;
  }

  .suit-big {
    font-size: 28px;
  }

  #controls {
    gap: 8px;
    right: 12px;
    top: 20px;
  }

  #controls button {
    padding: 14px 20px;
    font-size: 16px;
    min-height: 52px;
  }

  #roomBar {
    bottom: 12px;
    left: 12px;
    padding: 5px 10px;
  }

  #roomBar button.mini {
    padding: 6px 12px;
  }

  #hand {
    bottom: 56px;
    width: 96vw;
  }

  #table {
    top: 44%;
    width: min(94vw, 700px);
    min-height: 160px;
    gap: 12px;
    padding: 14px;
  }

  .table-pair {
    width: calc(var(--card-w) + 22px);
    height: calc(var(--card-h) + 26px);
  }

  .table-pair .card.defense {
    left: 18px;
    top: 18px;
  }

  #deck-area {
    left: 12px;
    top: 56px;
    width: 116px;
    height: 106px;
    transform: none;
  }

  .pos-left {
    left: 16%;
    top: 40%;
  }

  .pos-right {
    left: 84%;
    top: 40%;
  }

  /* Боковые игроки на мобильном: карты вертикальной стопкой вниз */
  .pos-left .seat-cards,
  .pos-right .seat-cards {
    flex-direction: column;
    align-items: center;
  }

  .pos-left .seat-cards .card.back,
  .pos-right .seat-cards .card.back {
    margin-left: 0;
    margin-top: -46px;
  }

  .pos-left .seat-cards .card.back:first-child,
  .pos-right .seat-cards .card.back:first-child {
    margin-top: 0;
  }

  #log {
    display: none;
  }
}

/* Вертикальная стопка для боковых игроков на любом тач-устройстве
   (покрывает и ландшафтные телефоны с шириной > 820px). */
@media (hover: none) and (pointer: coarse) {
  .pos-left .seat-cards,
  .pos-right .seat-cards {
    flex-direction: column;
    align-items: center;
  }

  .pos-left .seat-cards .card.back,
  .pos-right .seat-cards .card.back {
    margin-left: 0;
    margin-top: -46px;
  }

  .pos-left .seat-cards .card.back:first-child,
  .pos-right .seat-cards .card.back:first-child {
    margin-top: 0;
  }
}