/* ============== Themes ============== */

/* Fallback defaults (always defined, overridden by theme selectors below) */
:root {
  --bg-grad: radial-gradient(circle at center, #2a2a2a 0%, #181818 58%, #0c0c0c 100%);
  --board-grad: linear-gradient(180deg, rgba(28, 24, 16, 0.62) 0%, rgba(14, 12, 6, 0.68) 100%);
  --gold: #f1c968;
  --gold-soft: rgba(200, 168, 80, 0.32);
  --accent: #e8a531;
  --danger: #c4392a;
  --warn: #e8a531;
  --text: #f0e9d8;
}

:root[data-theme="gold"] {
  --bg-grad: radial-gradient(circle at center, #2a2a2a 0%, #181818 58%, #0c0c0c 100%);
  --board-grad: linear-gradient(180deg, rgba(28, 24, 16, 0.62) 0%, rgba(14, 12, 6, 0.68) 100%);
  --gold: #f1c968;
  --gold-soft: rgba(212, 172, 98, 0.32);
  --text: #f4e6bf;
  --accent: #e8be67;
  --danger: #c4392a;
  --success: #65a35a;
  --warn: #e8a531;
}

:root[data-theme="green"] {
  --bg-grad: radial-gradient(circle at center, #1f3a2a 0%, #122518 58%, #07140d 100%);
  --board-grad: radial-gradient(ellipse at center, rgba(42, 90, 58, 0.62) 0%, rgba(20, 56, 32, 0.68) 70%, rgba(12, 33, 20, 0.72) 100%);
  --gold: #d9c47a;
  --gold-soft: rgba(217, 196, 122, 0.32);
  --text: #f3eccb;
  --accent: #f4d774;
  --danger: #c4392a;
  --success: #6acb5a;
  --warn: #efad44;
}

:root[data-theme="amber"] {
  --bg-grad: radial-gradient(circle at center, #3a2a14 0%, #281a08 60%, #160e02 100%);
  --board-grad: linear-gradient(180deg, rgba(74, 50, 22, 0.62) 0%, rgba(38, 25, 6, 0.68) 100%);
  --gold: #ffd273;
  --gold-soft: rgba(255, 210, 115, 0.34);
  --text: #ffe6b8;
  --accent: #ffd273;
  --danger: #db5436;
  --success: #b1b35a;
  --warn: #f4b13b;
}

/* ============== Base ============== */

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  /* Подложка под градиентом: без неё Chrome/Linux иногда показывает «магентовый»
     слой при композитинге полупрозрачных фонов + backdrop-filter. */
  background-color: #141210;
  background-image: var(--bg-grad);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ============== Tavern background image ============== */

.bg-image {
  position: fixed;
  inset: 0;
  background-image: url('./beerguard-bg.png');
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  opacity: 0.38;
  z-index: 0;
  pointer-events: none;
}

/* Portrait phones: image is landscape, so cover zooms ~230%.
   Drop to 130% so the full composition (title + beer mugs) is visible. */
@media (orientation: portrait) and (max-width: 640px) {
  .bg-image {
    background-size: 130%;
    background-position: center 8%;
    opacity: 0.44;          /* slightly brighter since more is visible */
  }
}

/* Dark vignette at bottom so panels stay readable */
.bg-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom,
    transparent 35%,
    rgba(6, 4, 2, 0.65) 100%);
}

/* ============== Bubbles bg ============== */

.bg-bubbles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.bg-bubbles::before, .bg-bubbles::after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  background-image:
    radial-gradient(circle at 10% 100%, rgba(241, 201, 104, 0.07) 4px, transparent 5px),
    radial-gradient(circle at 30% 100%, rgba(241, 201, 104, 0.05) 6px, transparent 7px),
    radial-gradient(circle at 55% 100%, rgba(241, 201, 104, 0.06) 3px, transparent 4px),
    radial-gradient(circle at 75% 100%, rgba(241, 201, 104, 0.04) 5px, transparent 6px),
    radial-gradient(circle at 90% 100%, rgba(241, 201, 104, 0.05) 4px, transparent 5px);
  background-size: 100% 800px;
  animation: bubbleUp 16s linear infinite;
  opacity: 0.6;
}

.bg-bubbles::after {
  animation-duration: 22s;
  animation-delay: -8s;
  transform: scaleX(-1);
}

@keyframes bubbleUp {
  0% { transform: translateY(60%); }
  100% { transform: translateY(-100%); }
}

/* ============== Top bar (sticky) ============== */

.top-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  /* Непрозрачная панель без backdrop-filter — избегаем магентовых артефактов GPU */
  background: linear-gradient(180deg, rgb(18, 15, 10) 0%, rgb(12, 10, 7) 100%);
  border-bottom: 1px solid var(--gold-soft);
}

.badge {
  background: rgba(24, 24, 24, 0.84);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text);
}

.badge.badge-mode { font-weight: 700; color: var(--accent); }
.badge.badge-trump { color: var(--accent); }
.badge.badge-timer {
  font-weight: 700;
  color: var(--accent);
  background: rgba(40, 30, 0, 0.85);
}
.badge.badge-timer .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 5px;
  vertical-align: middle;
}
.badge.badge-timer.warn { background: rgba(70, 50, 0, 0.85); }
.badge.badge-timer.warn .dot { background: var(--warn); }
.badge.badge-timer.danger { background: rgba(80, 20, 0, 0.85); }
.badge.badge-timer.danger .dot { background: var(--danger); animation: tickPulse 1s linear infinite; }

@keyframes tickPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.7; }
}

/* ============== Main ============== */

.table-screen {
  padding: 12px 12px 110px;
  max-width: 960px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.table-board {
  background: var(--board-grad);
  border: 1px solid var(--gold-soft);
  border-radius: 14px;
  padding: 12px;
  position: relative;
  overflow: visible; /* player seats extend past ring edge; avoid clipping avatars */
}

/* ============== Players ring ============== */

.players-ring {
  position: relative;
  height: 250px;
  margin: 6px 0 14px;
  border-radius: 999px;
  border: 1px dashed var(--gold-soft);
  overflow: visible;
  background:
    radial-gradient(circle at center, rgba(60, 60, 60, 0.32) 0%, rgba(22, 22, 22, 0.22) 70%),
    radial-gradient(ellipse at center, rgba(0,0,0,0) 40%, rgba(0,0,0,0.2) 100%);
  /* Единая шкала карточек мест: и CSS, и JS (readPlayerSeatMetrics) */
  --seat-stack-gap: 8px;
  --seat-card-w: 100px;
  --seat-estimate-h: 118px;
  --seat-fan-w: 66px;
  --seat-fan-h: 28px;
  --seat-mini-w: 12px;
  --seat-mini-h: 19px;
  --seat-pad-x: 7px;
  --seat-pad-y: 9px;
  --seat-inner-gap: 7px;
  --seat-top-gap: 5px;
  --seat-avatar-size: 36px;
  --seat-name-fs: 11px;
  --seat-meta-fs: 10px;
  --seat-count-fs: 10px;
  --seat-online-fs: 10px;
  --seat-meta-gap: 2px;
}

.ring-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  color: var(--accent);
  opacity: 0.85;
}

.player-seat {
  width: var(--seat-card-w);
  min-height: 0;
  box-sizing: border-box;
  background: rgba(23, 23, 23, 0.82);
  border: 1px solid var(--gold-soft);
  border-radius: 2px;
  padding: var(--seat-pad-y) var(--seat-pad-x);
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: var(--seat-inner-gap);
  align-items: stretch;
  justify-content: flex-start;
  text-align: center;
  transition: transform 400ms cubic-bezier(.25,.46,.45,.94), box-shadow 400ms ease;
}

.player-seat:not(.player-seat--stacked-ring) {
  min-height: var(--seat-estimate-h);
  justify-content: center;
}

.player-seat.player-seat--stacked-ring {
  height: calc((100% - var(--seat-stack-gap)) / 2);
  max-height: calc((100% - var(--seat-stack-gap)) / 2);
  gap: 0;
  justify-content: space-between;
  overflow: hidden;
}

.player-seat.player-seat--stacked-ring .player-seat-top {
  flex-shrink: 0;
  min-height: 0;
}

.player-seat.player-seat--stacked-ring .player-cards-fan {
  height: var(--seat-fan-h);
  width: var(--seat-fan-w);
  flex-shrink: 0;
}

.player-seat.player-seat--stacked-ring .player-cards-fan .mini-back {
  width: var(--seat-mini-w);
  height: var(--seat-mini-h);
  border-radius: 2px;
}

.player-seat--top-cap {
  transform: translate(-50%, 0);
}

.player-seat--bottom-cap {
  top: auto;
  transform: translate(-50%, 0);
}

.player-seat-top {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--seat-top-gap);
  width: 100%;
  min-width: 0;
}

.player-seat-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.player-seat-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--seat-meta-gap);
  font-size: var(--seat-meta-fs);
  line-height: 1.2;
  opacity: 0.95;
  flex-shrink: 0;
}

.player-seat.you {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 0 14px rgba(241,201,104,0.3);
}

.player-seat.left {
  opacity: 0.45;
  filter: grayscale(0.6);
}

.player-seat.attacker {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold) inset, 0 0 14px rgba(241,201,104,0.4);
  animation: glowGold 6s ease-in-out infinite alternate;
}

.player-seat.defender {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px var(--danger) inset, 0 0 14px rgba(196,57,42,0.4);
  animation: glowRed 6s ease-in-out infinite alternate;
}

@keyframes glowGold {
  from { box-shadow: 0 0 0 2px var(--gold) inset, 0 0 8px rgba(241,201,104,0.35); }
  to { box-shadow: 0 0 0 2px var(--gold) inset, 0 0 18px rgba(241,201,104,0.75); }
}

@keyframes glowRed {
  from { box-shadow: 0 0 0 2px var(--danger) inset, 0 0 8px rgba(196,57,42,0.35); }
  to { box-shadow: 0 0 0 2px var(--danger) inset, 0 0 18px rgba(196,57,42,0.7); }
}

.player-avatar {
  width: var(--seat-avatar-size);
  height: var(--seat-avatar-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold) 0%, #8b5e1a 100%);
  border: 1px solid var(--gold-soft);
  color: #1c1404;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--seat-avatar-size) * 0.33);
  overflow: hidden;
  flex-shrink: 0;
}

.player-avatar img { width: 100%; height: 100%; object-fit: cover; }

.player-name {
  font-size: var(--seat-name-fs);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  width: 100%;
  text-align: left;
}

.player-online { font-size: var(--seat-online-fs); opacity: 0.88; white-space: nowrap; }

.player-cards-fan {
  position: relative;
  height: var(--seat-fan-h);
  width: var(--seat-fan-w);
  margin: 0 auto;
  display: block;
  transform-origin: center top;
}

.player-cards-fan .mini-back {
  position: absolute;
  width: var(--seat-mini-w);
  height: var(--seat-mini-h);
  border-radius: 2px;
  border: 1px solid var(--gold-soft);
  background:
    repeating-linear-gradient(45deg, #3f3f3f 0 2px, #292929 2px 4px),
    linear-gradient(145deg, #4a4a4a 0%, #1f1f1f 100%);
  top: 50%;
  left: 50%;
  transform-origin: bottom center;
}

.player-cards-count {
  font-size: var(--seat-count-fs);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1px;
  white-space: nowrap;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 10px;
}
.typing-dots .dot {
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: tDot 1s ease-in-out infinite;
}
.typing-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dots .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes tDot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-3px); opacity: 1; }
}

/* ============== Deck / Bito ============== */

.deck-zone {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  position: relative;
}

.deck-pile {
  position: relative;
  width: 80px;
  height: 110px;
}

.deck-stack {
  position: absolute;
  inset: 0;
}

.deck-stack .deck-card {
  position: absolute;
  width: 62px;
  height: 86px;
  border-radius: 8px;
  border: 1px solid var(--gold-soft);
  background:
    repeating-linear-gradient(45deg, rgba(241,201,104,0.06) 0 3px, transparent 3px 6px),
    linear-gradient(145deg, #444 0%, #1f1f1f 100%);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.32);
}

.trump-peek {
  position: absolute;
  bottom: -2px;
  left: 30px;
  width: 86px;
  height: 60px;
  border-radius: 8px;
  background: linear-gradient(180deg, #fffdf6 0%, #f7f1e5 100%);
  border: 1px solid #cbb98d;
  transform: rotate(90deg);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: #b32525;
  z-index: 0;
}

.deck-left-badge {
  position: absolute;
  right: -10px;
  top: -8px;
  min-width: 24px;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  background: var(--gold);
  color: #1c1404;
  border-radius: 999px;
  padding: 2px 6px;
}

.bito-zone {
  position: relative;
  margin-left: auto;
  min-width: 96px;
  text-align: center;
  padding: 6px 10px;
  color: var(--text);
}

.bito-stack {
  position: relative;
  height: 64px;
  margin: 0 auto;
  width: 56px;
}
.bito-stack .b-card {
  position: absolute;
  width: 38px; height: 54px;
  border-radius: 6px;
  border: 1px solid var(--gold-soft);
  background:
    repeating-linear-gradient(45deg, rgba(241,201,104,0.06) 0 3px, transparent 3px 6px),
    linear-gradient(145deg, #444 0%, #1f1f1f 100%);
  left: 50%; top: 50%;
  transform-origin: center;
}
.bito-title { font-size: 11px; opacity: 0.8; }
.bito-count { font-size: 18px; font-weight: 700; color: var(--accent); }

/* ============== Table cards ============== */

.table-cards {
  min-height: 96px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  background: rgba(0,0,0,0.18);
}

.pair {
  background: rgba(31, 31, 31, 0.82);
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  padding: 8px;
  font-size: 14px;
  transition: box-shadow 400ms ease;
}

.pair.uncovered {
  box-shadow: 0 0 0 2px var(--warn) inset, 0 0 14px rgba(232,165,49,0.35);
  animation: uncoveredPulse 5s ease-in-out infinite;
}

@keyframes uncoveredPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--warn) inset, 0 0 8px rgba(232,165,49,0.25); }
  50% { box-shadow: 0 0 0 2px var(--warn) inset, 0 0 18px rgba(232,165,49,0.55); }
}

/* Defender's turn: uncovered cards need to be beaten — stronger highlight */
.pair.uncovered.needs-beat {
  box-shadow: 0 0 0 2px #e06060 inset, 0 0 18px rgba(224,82,82,0.55);
  animation: needsBeatPulse 4s ease-in-out infinite;
}
.pair.uncovered.needs-beat .pair-attack .card-face {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(224,82,82,0.45);
  transition: transform 500ms ease-in-out;
}
.pair.uncovered.needs-beat .pair-defense .unknown-card {
  background: rgba(224,82,82,0.12);
  border: 2px dashed rgba(224,82,82,0.55);
  color: rgba(224,82,82,0.7);
}
@keyframes needsBeatPulse {
  0%, 100% { box-shadow: 0 0 0 2px #e06060 inset, 0 0 10px rgba(224,82,82,0.4); }
  50% { box-shadow: 0 0 0 2px #e06060 inset, 0 0 24px rgba(224,82,82,0.75); }
}

.cards-pair {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.pair-arrow-svg {
  width: 36px; height: 24px;
  color: var(--accent);
}

.pair-arrow-svg path {
  stroke-dasharray: 6,4;
  animation: dashMove 1.4s linear infinite;
}
@keyframes dashMove { to { stroke-dashoffset: -20; } }

.pair-attack .card-face, .pair-defense .card-face {
  transition: transform 500ms cubic-bezier(.25,.46,.45,.94);
}

.pair-defense .flip-wrap {
  perspective: 900px;
}
.pair-defense .card-face.flip-in {
  animation: flipIn 520ms cubic-bezier(.25,.46,.45,.94) forwards;
}

/* Avoid heavy 3D: some Telegram/WebViews barely show rotateY(80deg) → "missing" defense. */
@keyframes flipIn {
  0% { transform: translateY(-14px) scale(0.94); opacity: 0.2; }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}

.suit-clubs, .suit-spades { color: #111; }
.suit-diamonds, .suit-hearts { color: #cf2f2f; }

/* ============== Status panel ============== */

.status-row {
  margin: 10px 0;
  padding: 10px 14px 10px 16px;
  background: linear-gradient(180deg, rgb(26, 20, 14) 0%, rgb(16, 13, 9) 100%);
  border: 1px solid rgba(200, 168, 80, 0.2);
  border-left: 3px solid rgba(200, 168, 80, 0.4);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 14px;
  color: var(--text);
  transition: border-left-color 600ms ease-in-out;
}
.status-row[data-role="attack"] { border-left-color: var(--gold); }
.status-row[data-role="defend"] { border-left-color: #e06060; }
.status-row[data-role="throw"]  { border-left-color: var(--accent); }
.status-row[data-role="wait"]   { border-left-color: rgba(255,255,255,0.15); }

#turn-status {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  transition: color 500ms ease;
}
#turn-status[data-role="attack"] { color: var(--gold); }
#turn-status[data-role="defend"] { color: #e06060; }
#turn-status[data-role="throw"]  { color: var(--accent); }
#turn-status[data-role="wait"]   { color: rgba(255,255,255,0.5); font-weight: 400; font-size: 14px; }

.turn-roles {
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}
.role-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.role-pill.attack-pill {
  background: rgba(241,201,104,0.14);
  color: var(--gold);
  border: 1px solid rgba(241,201,104,0.28);
}
.role-pill.defend-pill {
  background: rgba(224,82,82,0.14);
  color: #e06060;
  border: 1px solid rgba(224,82,82,0.28);
}
.role-pill.you-pill {
  font-weight: 700;
  filter: brightness(1.25);
}
.defend-hint {
  font-size: 12px;
  color: #e06060;
  background: rgba(224,82,82,0.12);
  border: 1px solid rgba(224,82,82,0.3);
  border-radius: 20px;
  padding: 3px 9px;
  font-weight: 600;
}

/* Role badges inside player seats (icon-only to save vertical space) */
.role-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 0 3px;
  border-radius: 6px;
  margin-top: 0;
  line-height: 1.2;
  align-self: flex-start;
}
.role-badge.attack { background: rgba(241,201,104,0.2); color: var(--gold); }
.role-badge.defend { background: rgba(224,82,82,0.25); color: #e06060; }

.rematch-section {
  margin: 12px 0;
  background: rgba(30, 22, 8, 0.92);
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 0 24px rgba(241, 201, 104, 0.25);
}
.rematch-section h3 {
  margin: 0 0 6px;
  color: var(--gold);
}
.rematch-status {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 10px;
}
.rematch-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.rematch-roster {
  font-size: 12px;
  color: var(--text);
  opacity: 0.95;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.rematch-roster .rematch-yes { color: var(--success); }
.rematch-roster .rematch-no { color: var(--danger); }
.rematch-roster .rematch-pending { opacity: 0.75; }
.rematch-deadline {
  margin-top: 8px;
  font-size: 11px;
  color: var(--accent);
  opacity: 0.85;
}

.game-result {
  margin-top: 8px;
  display: inline-block;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--gold-soft);
  background: rgba(22, 22, 22, 0.88);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.phase-banner {
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(40, 30, 0, 0.84);
  border: 1px solid var(--gold-soft);
  border-radius: 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

/* ============== Lobby ============== */

.lobby-section, .chat-section, .action-log-section {
  margin: 12px 0;
  background: linear-gradient(180deg, rgb(28, 22, 14) 0%, rgb(18, 14, 9) 100%);
  border: 1px solid var(--gold-soft);
  border-radius: 12px;
  padding: 12px;
}

.lobby-section h3, .chat-section h3, .action-log-section h3 {
  margin: 0 0 8px;
  font-size: 15px;
}

.spectator-vote-banner {
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--gold-soft);
  background: rgba(40, 34, 18, 0.75);
  font-size: 13px;
  color: var(--text);
}
.spectator-vote-banner.hidden { display: none; }
.spectator-vote-title { font-weight: 700; color: var(--accent); margin-bottom: 8px; }
.spectator-vote-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.spectator-vote-row .sv-name { font-weight: 600; }
.spectator-vote-row .sv-count { opacity: 0.75; font-size: 12px; }
.spectator-vote-row .sv-done { font-size: 12px; color: var(--success, #65a35a); }
.sv-btn {
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--gold-soft);
  background: rgba(28, 28, 28, 0.9);
  color: var(--text);
}
.sv-btn.yes { border-color: var(--success, #65a35a); }
.sv-btn.no { border-color: var(--danger); }

.lobby-players { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

.lobby-player {
  font-size: 14px;
  background: rgba(30, 24, 10, 0.55);
  border: 1px solid rgba(212, 172, 98, 0.18);
  border-radius: 8px;
  padding: 6px 8px;
}

.lobby-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ============== Action log (read-only move feed) ============== */

.action-log-note {
  margin: 0 0 10px;
  font-size: 12px;
  opacity: 0.78;
  line-height: 1.35;
  color: var(--text);
}

.action-log-list {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.action-log-empty {
  font-size: 13px;
  opacity: 0.65;
  padding: 8px 6px;
}

.action-log-entry {
  position: relative;
  background: rgba(35, 35, 35, 0.86);
  border: 1px solid rgba(212, 172, 98, 0.18);
  border-radius: 8px;
  padding: 8px 10px 8px 10px;
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
  line-height: 1.35;
}

.action-log-entry-latest {
  border-color: rgba(241, 201, 104, 0.55);
  background: rgba(55, 48, 22, 0.92);
  box-shadow:
    0 0 0 1px rgba(241, 201, 104, 0.2),
    0 4px 14px rgba(0, 0, 0, 0.35);
}

.action-log-latest-badge {
  display: inline-block;
  margin-bottom: 5px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #1a1406;
  background: linear-gradient(180deg, var(--gold) 0%, #c49a3a 100%);
  border-radius: 6px;
  padding: 2px 8px;
}

.action-log-line {
  padding-top: 1px;
}

.action-log-section.hidden {
  display: none;
}

/* ============== Chat ============== */

.chat-messages {
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
  padding-right: 4px;
}

.chat-message {
  background: rgba(35, 35, 35, 0.86);
  border: 1px solid rgba(212, 172, 98, 0.18);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
  animation: msgFade 400ms ease-out;
}

@keyframes msgFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.system {
  background: rgba(50, 40, 0, 0.5);
  color: var(--accent);
  border-color: var(--gold-soft);
  font-style: italic;
}

.chat-message.from-spectator {
  border-left: 3px solid var(--accent);
}

.chat-author { color: var(--accent); font-weight: 700; margin-right: 6px; }
.chat-meta { font-size: 10px; opacity: 0.7; margin-top: 2px; }

.chat-reactions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

.emoji-btn {
  border: 1px solid var(--gold-soft);
  background: rgba(28, 28, 28, 0.85);
  color: #fff;
  border-radius: 999px;
  font-size: 18px;
  padding: 6px 10px;
  cursor: pointer;
  transition: transform 280ms ease;
}
.emoji-btn:active { transform: scale(0.94); }

.chat-compose { display: flex; gap: 8px; }
.chat-input {
  flex: 1;
  border-radius: 10px;
  border: 1px solid var(--gold-soft);
  background: rgba(18, 18, 18, 0.9);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
}

/* ============== Hand ============== */

.hand-section {
  position: relative;
  margin-top: 12px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid var(--gold-soft);
  background: linear-gradient(180deg, rgb(26, 20, 10) 0%, rgb(16, 13, 8) 100%);
  transition: box-shadow 400ms ease;
}

.hand-section.your-turn {
  box-shadow: 0 0 0 2px var(--gold), 0 0 22px rgba(241,201,104,0.35);
  animation: yourTurnPulse 6s ease-in-out infinite;
}

@keyframes yourTurnPulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(241,201,104,0.28); }
  50% { box-shadow: 0 0 0 2px var(--gold), 0 0 28px rgba(241,201,104,0.55); }
}

.hand-section.transfer-mode { background: linear-gradient(180deg, rgb(48, 34, 14) 0%, rgb(28, 20, 10) 100%); }
.hand-section.transfer-mode .hand-toolbar h3::after { content: " — выберите карту для перевода"; color: var(--accent); font-size: 12px; }

.hand-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.hand-toolbar h3 { margin: 0; font-size: 15px; }

.sort-buttons { display: flex; gap: 5px; flex-wrap: wrap; }

.ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--gold-soft);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ghost-btn.active { background: rgba(212, 172, 98, 0.2); color: var(--accent); border-color: var(--accent); }
.ghost-btn:hover { background: rgba(212, 172, 98, 0.12); }

/* ============== Zoom levels ============== */
/* zoom on <html> scales the entire page — content, fixed bg, header — uniformly */
html { transition: zoom 350ms ease; }
html[data-zoom="65"]  { zoom: 0.65; }
html[data-zoom="75"]  { zoom: 0.75; }
html[data-zoom="85"]  { zoom: 0.85; }
html[data-zoom="100"] { zoom: 1.00; }
html[data-zoom="115"] { zoom: 1.15; }

.hand-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  perspective: 800px;
}

.transfer-hint {
  margin-top: 6px;
  text-align: center;
  font-size: 12px;
  color: var(--accent);
  padding: 4px;
  border-radius: 8px;
  background: rgba(241, 201, 104, 0.12);
}

.hand-card {
  position: relative;
  min-width: 80px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: 16px;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
  transition: transform 320ms cubic-bezier(.25,.46,.45,.94), filter 320ms ease;
  cursor: pointer;
}
.hand-card:hover { transform: translateY(-6px) scale(1.03); }
.hand-card:active { transform: translateY(-2px) scale(0.97); }
.hand-card.click { animation: cardClick 380ms ease-out; }

@keyframes cardClick {
  0% { transform: scale(1); }
  40% { transform: scale(0.94); }
  100% { transform: scale(1); }
}

.hand-card-disabled {
  filter: grayscale(35%) brightness(0.7);
  opacity: 0.55;
  cursor: not-allowed;
}
.hand-card-disabled:hover { transform: none; }

.hand-card-allowed {
  animation: cardGlow 5s ease-in-out infinite;
}

@keyframes cardGlow {
  0%, 100% { box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35), 0 0 4px rgba(241,201,104,0.35); }
  50% { box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35), 0 0 14px rgba(241,201,104,0.7); }
}

.hand-card.transfer-target { animation: transferGlow 2s ease-in-out infinite; }

@keyframes transferGlow {
  0%, 100% { box-shadow: 0 4px 10px rgba(0,0,0,0.35), 0 0 6px rgba(255,180,80,0.45); }
  50% { box-shadow: 0 4px 10px rgba(0,0,0,0.35), 0 0 20px rgba(255,180,80,0.9); }
}

/* Card face */

.card-face {
  width: 72px;
  height: 104px;
  border-radius: 10px;
  background: linear-gradient(180deg, #fffdf6 0%, #f7f1e5 100%);
  border: 1px solid #cbb98d;
  position: relative;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.card-corner {
  position: absolute;
  left: 6px;
  top: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-size: 15px;
}

.card-corner.bottom {
  left: auto;
  right: 6px;
  top: auto;
  bottom: 4px;
  transform: rotate(180deg);
}

.card-rank { font-size: 1em; font-weight: 800; }
.card-suit { font-size: 0.88em; }

.card-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.05;
}

.card-center-rank { font-size: 28px; font-weight: 800; }
.card-center-suit { font-size: 22px; }

.unknown-card {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  color: #445;
  background: linear-gradient(145deg, #e9edf3 0%, #d5dbe3 100%);
}

/* Card back (used in flying card) */
.card-back-mini {
  width: 56px; height: 80px;
  border-radius: 8px;
  border: 1px solid var(--gold-soft);
  background:
    repeating-linear-gradient(45deg, rgba(241,201,104,0.08) 0 3px, transparent 3px 6px),
    linear-gradient(145deg, #444 0%, #1f1f1f 100%);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-weight: 900; font-size: 18px;
  text-shadow: 0 0 4px rgba(0,0,0,0.5);
}

/* ============== Floating actions ============== */

.floating-actions {
  position: fixed;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Leave button always stays separated from action buttons */
#btn-leave {
  margin-left: 24px;
}

.action-btn {
  border: none;
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  transition: transform 280ms ease, box-shadow 280ms ease;
  box-shadow: 0 6px 14px rgba(0,0,0,0.35);
}
.action-btn:active { transform: scale(0.94); }
.action-btn:hover { box-shadow: 0 6px 18px rgba(0,0,0,0.5); }

.action-btn.take { background: linear-gradient(180deg, #c4392a 0%, #8a251b 100%); }
.action-btn.beat { background: linear-gradient(180deg, #7d6528 0%, #5d4a1d 100%); }
.action-btn.transfer { background: linear-gradient(180deg, #b78a2f 0%, #8f6a23 100%); }
.action-btn.cancel { background: linear-gradient(180deg, #383838 0%, #1f1f1f 100%); border: 1px solid var(--gold-soft); }

.hidden { display: none !important; }

/* ============== Flying card animations ============== */

/* Legacy generic fly (back side, small) */
.fly-card {
  position: fixed;
  border-radius: 8px;
  pointer-events: none;
  z-index: 9999;
  animation: flyMove 750ms cubic-bezier(.25,.46,.45,.94) forwards;
  box-shadow: 0 8px 16px rgba(0,0,0,0.45);
}
@keyframes flyMove {
  0%   { opacity: 1; transform: translate(0,0) rotate(0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot, 15deg)) scale(0.78); }
}

/* Full visible flying card face */
.fly-card-face {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 14px 36px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.15);
  animation: flyArc var(--fly-dur, 700ms) cubic-bezier(.25,.46,.45,.94) var(--fly-delay, 0ms) forwards;
}

/* Card back for deck-to-hand */
.fly-card-back-full {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  border-radius: 10px;
  background: linear-gradient(135deg, #1a0a2e 0%, #2d1a5e 100%);
  border: 1.5px solid rgba(212,175,55,0.5);
  box-shadow: 0 10px 26px rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: rgba(212,175,55,0.35);
  animation: flyArc var(--fly-dur, 700ms) cubic-bezier(.25,.46,.45,.94) var(--fly-delay, 0ms) forwards;
}

/* Parabolic arc: lifts at midpoint, lands at destination */
@keyframes flyArc {
  0%   {
    opacity: 1;
    transform: translate(0, 0) rotate(0deg) scale(1);
  }
  44%  {
    opacity: 1;
    transform:
      translate(calc(var(--dx) * 0.44), calc(var(--dy) * 0.44 + var(--arc-y, -55px)))
      rotate(calc(var(--rot, 0deg) * 0.45))
      scale(1.1);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) rotate(var(--rot, 0deg)) scale(0.6);
  }
}

.deck-pulse { animation: deckPulse 450ms ease-out; }
@keyframes deckPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

/* ============== Toast ============== */

.toast-host {
  position: fixed;
  top: 70px;
  left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: rgba(28,28,28,0.96);
  color: var(--text);
  border: 1px solid var(--gold-soft);
  border-left: 4px solid var(--accent);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  animation: toastIn 450ms ease-out, toastOut 500ms ease-in 3.5s forwards;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.warn { border-left-color: var(--warn); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-12px); }
}

/* ============== "Ваш ход" big badge ============== */

.big-turn-badge {
  position: fixed;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%) scale(0.6);
  background: rgba(0,0,0,0.85);
  color: var(--gold);
  padding: 18px 28px;
  border-radius: 16px;
  border: 2px solid var(--gold);
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1px;
  z-index: 1500;
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 0 12px rgba(241,201,104,0.7);
}

.big-turn-badge.show { animation: bigBadge 2400ms ease-out forwards; }

@keyframes bigBadge {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%,-50%) scale(1.1); }
  40% { transform: translate(-50%,-50%) scale(1); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(0.95); }
}

/* ============== Confetti canvas ============== */

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2000;
}

/* ============== Landscape ============== */

@media (orientation: landscape) and (max-height: 540px) {
  .top-bar { padding: 6px 8px; }
  .badge { padding: 4px 8px; font-size: 11px; }
  .table-board { padding: 8px; transform: none; }
  .players-ring {
    height: 180px;
    --seat-stack-gap: 6px;
    --seat-card-w: 72px;
    --seat-estimate-h: 88px;
    --seat-fan-w: 56px;
    --seat-fan-h: 20px;
    --seat-mini-w: 10px;
    --seat-mini-h: 15px;
    --seat-pad-x: 4px;
    --seat-pad-y: 3px;
    --seat-inner-gap: 2px;
    --seat-top-gap: 2px;
    --seat-avatar-size: 22px;
    --seat-name-fs: 9px;
    --seat-meta-fs: 8px;
    --seat-count-fs: 8px;
    --seat-online-fs: 7px;
    --seat-meta-gap: 0;
  }
  .card-face { width: 56px; height: 80px; }
  .card-center-rank { font-size: 22px; }
  .card-center-suit { font-size: 16px; }
  .chat-messages { max-height: 110px; }
  .hand-section .card-face { width: 60px; height: 84px; }
}

/* ============================================================
   MOBILE — portrait, max 600px
   Goal: everything fits without scrolling
   ============================================================ */

@media (max-width: 600px) {

  /* -- Top bar: hide less critical badges, shrink everything -- */
  .top-bar {
    padding: 5px 8px;
    gap: 4px;
  }
  .badge { padding: 3px 7px; font-size: 11px; }
  /* Hide deck count and room id badges to save space */
  .top-bar .badge:nth-child(1),   /* Комната */
  .top-bar .badge:nth-child(4) {  /* Колода */
    display: none;
  }

  /* -- Main container -- */
  .table-screen {
    padding: 5px 5px 90px;
  }

  /* -- Table board -- */
  .table-board {
    padding: 6px;
    border-radius: 10px;
    transform: none; /* remove perspective tilt on mobile */
    overflow: visible;
  }

  /* -- Players ring: те же пропорции, что на десктопе; масштаб через переменные -- */
  .players-ring {
    height: 176px;
    margin: 3px 0 6px;
    --seat-stack-gap: 6px;
    --seat-card-w: 72px;
    --seat-estimate-h: 88px;
    --seat-fan-w: 56px;
    --seat-fan-h: 20px;
    --seat-mini-w: 10px;
    --seat-mini-h: 15px;
    --seat-pad-x: 4px;
    --seat-pad-y: 3px;
    --seat-inner-gap: 2px;
    --seat-top-gap: 2px;
    --seat-avatar-size: 22px;
    --seat-name-fs: 9px;
    --seat-meta-fs: 8px;
    --seat-count-fs: 8px;
    --seat-online-fs: 7px;
    --seat-meta-gap: 0;
  }

  .player-name {
    max-width: none;
    line-height: 1.1;
  }
  .role-badge {
    font-size: 8px;
    padding: 0 1px;
    line-height: 1.1;
  }

  /* -- Deck zone -- */
  .deck-zone { gap: 8px; margin-bottom: 6px; }
  .deck-pile { width: 50px; }
  .trump-peek { width: 42px; height: 60px; }
  .deck-stack { width: 42px; height: 60px; }
  .deck-left-badge { font-size: 11px; }
  .bito-zone { gap: 2px; }
  .bito-stack { width: 36px; height: 52px; }
  .bito-title { font-size: 10px; }
  .bito-count { font-size: 11px; }

  /* -- Table cards: smaller pairs -- */
  .table-cards { gap: 4px; padding: 4px 0; }
  .pair { gap: 2px; padding: 3px 4px; }
  .pair .card-face { width: 40px; height: 56px; }
  .pair .card-face .card-corner { font-size: 9px; }
  .pair .card-face .card-center-rank { font-size: 16px; }
  .pair .card-face .card-center-suit { font-size: 11px; }

  /* -- Phase banner -- */
  .phase-banner { font-size: 12px; padding: 4px 8px; margin: 4px 0; }

  /* -- Status row -- */
  .status-row { margin: 5px 0; padding: 7px 10px 7px 12px; gap: 5px; }
  #turn-status { font-size: 14px; }
  .turn-roles { font-size: 11px; gap: 4px; }
  .role-pill { font-size: 10px; padding: 2px 7px; }
  .defend-hint { font-size: 10px; padding: 2px 7px; }

  /* -- Action log -- */
  .lobby-section { margin: 5px 0; padding: 8px; border-radius: 8px; }
  .lobby-section h3 { font-size: 13px; margin-bottom: 5px; }
  .lobby-player { font-size: 12px; padding: 4px 6px; }
  .lobby-actions { gap: 5px; margin-top: 5px; }
  .action-btn { padding: 9px 12px; font-size: 13px; }

  /* -- Chat: collapsible on mobile -- */
  .chat-section { margin: 5px 0; padding: 8px; border-radius: 8px; }
  .action-log-section { margin: 5px 0; padding: 8px; border-radius: 8px; }
  .action-log-section h3 { font-size: 13px; margin-bottom: 4px; }
  .action-log-note { font-size: 11px; margin-bottom: 6px; }
  .action-log-list { max-height: 120px; }
  .action-log-entry { font-size: 12px; padding: 6px 8px; }
  .chat-section h3 {
    font-size: 13px;
    margin-bottom: 0;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .chat-section h3::after {
    content: "▾";
    font-size: 14px;
    transition: transform 380ms cubic-bezier(.25,.46,.45,.94);
  }
  .chat-section.collapsed h3::after { transform: rotate(-90deg); }
  .chat-section.collapsed .chat-messages,
  .chat-section.collapsed .spectator-vote-banner,
  .chat-section.collapsed .chat-reactions,
  .chat-section.collapsed .chat-compose { display: none; }
  .chat-messages { max-height: 120px; }

  /* -- Hand section -- */
  .hand-section { margin-top: 5px; padding: 6px; border-radius: 10px; }
  .hand-toolbar h3 { font-size: 13px; }
  .hand-scroll { gap: 5px; }
  .hand-section .card-face { width: 52px; height: 73px; }
  .hand-section .card-face .card-corner { font-size: 9px; }
  .hand-section .card-face .card-center-rank { font-size: 18px; }
  .hand-section .card-face .card-center-suit { font-size: 12px; }

  /* -- Rematch section -- */
  .rematch-section { margin: 5px 0; padding: 8px; }
  .rematch-section h3 { font-size: 14px; }

  /* -- Floating action buttons -- */
  .floating-actions { bottom: 5px; gap: 5px; }
  .action-btn { padding: 10px 14px; font-size: 13px; border-radius: 999px; }
  #btn-leave { margin-left: 16px; }
}

/* ============== Shake on error ============== */

.shake { animation: shake 500ms; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}
