:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel2: #24282f;
  --line: #32373f;
  --text: #e8e6e1;
  --muted: #8f949c;
  --accent: #d4a23c;
  --accent2: #4b8f6b;
  --danger: #c05a55;
}

* {
  box-sizing: border-box;
}

:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

::selection {
  background: #4b8f6b55;
}

img {
  max-width: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0%, #1d222a 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

#app {
  flex: 1 1 auto;
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 16px 40px;
}

h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin: 6px 0 4px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.muted {
  color: var(--muted);
}

.card-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

input,
select {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
}

.btn {
  background: var(--accent);
  color: #1a1408;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 500;
}

.btn.ok {
  background: var(--accent2);
  color: #0d1712;
}

.btn.tiny {
  margin-left: auto;
  padding: 4px 11px;
  font-size: 12px;
  border-radius: 7px;
}

.status-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.status-actions .btn.tiny {
  margin-left: 0;
}

.btn[hidden] {
  display: none;
}

.code {
  font-family: "Consolas", ui-monospace, monospace;
  font-size: 26px;
  letter-spacing: 0.18em;
  color: var(--accent);
}

.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.players li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel2);
  border-radius: 8px;
  padding: 8px 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
  background: var(--accent2);
}

.dot.off {
  background: #555;
}

/* --- стол --- */

.status {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
}

.status b {
  color: var(--accent);
}

.opponents {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.opponent {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.opponent.turn {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.opponent .name {
  font-weight: 600;
}

.opponent .meta {
  color: var(--muted);
  font-size: 13px;
}

.center {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}

.trick {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Взятка крестом: каждая карта идёт от своего игрока к центру */

.trick-cross {
  position: relative;
  width: 130px;
  height: 160px;
  margin: 0 auto;
}

.trick-slot {
  position: absolute;
  width: 42px;
  height: 58px;
}

.slot-top {
  left: 44px;
  top: 22px;
}

.slot-bottom {
  left: 44px;
  top: 80px;
}

.slot-left {
  left: 23px;
  top: 51px;
}

.slot-right {
  left: 65px;
  top: 51px;
}

.trick div {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.hand {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  width: 100%;
  justify-content: center;
  margin-bottom: 12px;
}

.card {
  width: 46px;
  height: 66px;
  border-radius: 7px;
  border: 1px solid #0003;
  background: #f7f5ef;
  color: #17181a;
  font: 600 15px/1 "Segoe UI", system-ui, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.card.red {
  color: #b3261e;
}

.card:hover:not(:disabled) {
  transform: translateY(-6px);
  box-shadow: 0 6px 14px #0006;
}

.card:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.card.small {
  width: 38px;
  height: 54px;
  font-size: 13px;
}

/* --- игральные карты --- */

.pcard {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 62px;
  height: 88px;
  padding: 0;
  border: 1px solid #cfc9bb;
  border-radius: 7px;
  background: linear-gradient(160deg, #fffefb 0%, #f6f3ea 100%);
  color: #17181a;
  box-shadow: 0 1px 2px #0003;
  font-family: "Segoe UI", system-ui, sans-serif;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.pcard.red {
  color: #b3261e;
}

button.pcard {
  cursor: pointer;
}

button.pcard:hover:not(:disabled) {
  transform: translateY(-7px);
  box-shadow: 0 9px 16px #0007;
}

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

.pc-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-size: 12px;
  font-weight: 700;
}

.pc-corner i {
  font-style: normal;
  font-size: 11px;
  margin-top: 2px;
}

.pc-corner.tl {
  left: 5px;
  top: 4px;
}

.pc-corner.br {
  right: 5px;
  bottom: 4px;
  transform: rotate(180deg);
}

.pc-pips {
  position: absolute;
  inset: 17px 12px;
}

.pc-pip {
  position: absolute;
  transform: translate(-50%, -50%);
  font-style: normal;
  font-size: 14px;
  line-height: 1;
}

.pc-pip.flip {
  transform: translate(-50%, -50%) rotate(180deg);
}

.pc-ace {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
}

.pc-court {
  position: absolute;
  inset: 16px 13px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid currentColor;
  border-radius: 3px;
  opacity: 0.92;
}

.pc-half {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
}

.pc-half i {
  font-style: normal;
  font-size: 11px;
}

.pc-half.flip {
  transform: rotate(180deg);
  border-top: 1px solid currentColor;
}

.pcard.small {
  width: 42px;
  height: 58px;
  border-radius: 5px;
}

.pcard.small .pc-corner {
  font-size: 9px;
}

.pcard.small .pc-corner i {
  font-size: 8px;
  margin-top: 1px;
}

.pcard.small .pc-corner.tl {
  left: 3px;
  top: 2px;
}

.pcard.small .pc-corner.br {
  right: 3px;
  bottom: 2px;
}

.pcard.small .pc-pips {
  inset: 12px 8px;
}

.pcard.small .pc-pip {
  font-size: 9px;
}

.pcard.small .pc-ace {
  font-size: 22px;
}

.pcard.small .pc-court {
  inset: 11px 8px;
}

.pcard.small .pc-half {
  font-size: 9px;
}

.pcard.small .pc-half i {
  font-size: 8px;
}

/* --- карты: изображения колоды --- */

.pcard {
  width: 62px;
  height: auto;
  aspect-ratio: 5 / 7;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
}

.pcard.small {
  width: 42px;
  height: auto;
}

.pc-img {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 1px 2px #0006);
}

button.pcard:hover:not(:disabled) {
  box-shadow: none;
}

button.pcard:hover:not(:disabled) .pc-img {
  filter: drop-shadow(0 8px 14px #0009);
}

/* --- зелёное сукно --- */

.felt {
  position: relative;
  display: grid;
  grid-template-areas:
    "top top top"
    "left center right"
    "self self self";
  grid-template-columns: minmax(0, 220px) minmax(240px, 1fr) minmax(0, 220px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 6px 10px;
  /* Стол подгоняем под высоту экрана, чтобы панель торговли была видна без прокрутки */
  height: clamp(520px, calc(100vh - 260px), 820px);
  overflow: hidden;
  padding: 14px 18px 10px;
  border: 1px solid #0c2f1f;
  border-radius: 20px;
  background: radial-gradient(ellipse at 50% 38%, #246c46 0%, #17522f 46%, #0d3722 100%);
  box-shadow: inset 0 0 80px #0008, 0 8px 28px #0007;
}

.seat {
  display: flex;
}

.seat-top {
  grid-area: top;
  justify-content: center;
}

.seat-left {
  grid-area: left;
  align-items: center;
  justify-content: flex-start;
}

.seat-right {
  grid-area: right;
  align-items: center;
  justify-content: flex-end;
}

.seat-self {
  grid-area: self;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-top: 6px;
}

.table-center {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.seat-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-radius: 12px;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.seat-block.turn {
  background: #ffffff0e;
  box-shadow: 0 0 0 1px #ffd47a55;
}

.seat-name {
  color: #e7f0e7;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 3px #0009;
}

.seat-block.turn .seat-name {
  color: #ffd47a;
}

.seat-tag {
  color: #9fc0a9;
  font-size: 11px;
  font-weight: 400;
  margin-left: 6px;
}

.bid-bubble {
  position: relative;
  display: inline-block;
  padding: 1px 9px;
  border-radius: 10px;
  background: #f3efe3;
  color: #22302a;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 1px 3px #0007;
}

.bid-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 8px;
  height: 8px;
  margin-left: -4px;
  background: inherit;
  border-radius: 1px;
  transform: rotate(45deg);
}

.bid-bubble.pass {
  background: #d8d5cb;
  color: #6d6d64;
}

.bid-bubble.nopass {
  background: #ffd47a;
  color: #3a2a08;
}

@keyframes bubblePop {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  65% {
    transform: scale(1.12);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

.bid-bubble.pop {
  animation: bubblePop 0.32s ease-out;
}

.seat-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.trick-pile {
  display: flex;
  align-items: center;
  gap: 4px;
}

.trick-stack {
  position: relative;
  width: 34px;
  height: 44px;
}

.trick-back {
  position: absolute;
  top: 0;
  left: calc(var(--i) * 2px);
  width: 28px;
  height: 40px;
  border: 2px solid #efe7d6;
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, #7d2330 0 5px, #8f2b39 5px 10px);
  box-shadow: 0 1px 3px #0006, inset 0 0 0 1px #5a1723;
}

.tricks-count {
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid #3f7355;
  border-radius: 8px;
  background: #0b2b1cbb;
  color: #ffd47a;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.self-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 62px;
  padding: 2px 10px;
  border-radius: 12px;
  background: #f2eee2;
  color: #1c2a22;
  line-height: 1.15;
  box-shadow: 0 2px 5px #0006;
}

.score-badge b {
  font-size: 15px;
}

.score-badge span {
  font-size: 9.5px;
  color: #5c6b60;
}

.fan {
  position: relative;
}

.fan-row {
  --step: 12px;
}

.fan-column {
  --step: 7px;
}

.card-back {
  position: absolute;
  width: 40px;
  height: 58px;
  border: 3px solid #efe7d6;
  border-radius: 5px;
  background: repeating-linear-gradient(45deg, #7d2330 0 7px, #8f2b39 7px 14px);
  box-shadow: 0 2px 4px #0007, inset 0 0 0 1px #5a1723;
}

.fan-row .card-back {
  left: calc(20px + var(--i) * var(--step));
  top: 50%;
  transform: translate(-50%, -50%);
}

.fan-column .card-back {
  left: 50%;
  top: calc(20px + var(--i) * var(--step));
  transform: translate(-50%, -50%) rotate(90deg);
}

.card-back::after {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid #e5cdb099;
  border-radius: 2px;
}

.contract-chip {
  padding: 4px 14px;
  border: 1px solid #3f7355;
  border-radius: 999px;
  background: #0b2b1cbb;
  color: #d6e7da;
  font-size: 13px;
}

.trick-result {
  color: #ffd47a;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.trick-shown {
  display: flex;
  gap: 4px;
  padding: 4px 5px;
  border-radius: 8px;
  background: #0003;
  box-shadow: inset 0 0 0 1px #ffffff1a;
  animation: bubblePop 0.25s ease-out;
}

.tricks-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 10px 0 0;
  color: #cfe0d3;
  font-size: 12px;
}

/* --- оболочка и чат --- */

.shell {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  max-width: 1440px;
  margin: 0 auto;
}

.chat {
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 36px);
  max-height: 760px;
  margin: 18px 16px 0 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.chat-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 10px 12px;
}

.chat-item {
  font-size: 13px;
  line-height: 1.35;
}

.chat-item b {
  color: var(--accent);
  font-weight: 600;
}

.chat-item .time {
  margin-left: 6px;
  color: var(--muted);
  font-size: 11px;
}

.chat-item .text {
  margin-top: 2px;
  word-break: break-word;
}

.chat-empty {
  color: var(--muted);
  font-size: 12px;
}

.chat-form {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.chat-form input {
  flex: 1;
  min-width: 0;
}

.chat-form .btn {
  padding: 6px 12px;
}

@media (max-width: 1100px) {
  .shell {
    flex-direction: column;
  }

  .chat {
    flex: 1 1 auto;
    width: calc(100% - 32px);
    height: 320px;
    max-height: 320px;
    margin: 0 16px 24px;
  }
}

.table-actions {
  display: flex;
  justify-content: center;
  margin: 4px 0 10px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000a;
  backdrop-filter: blur(2px);
}

.overlay-card {
  max-width: min(92vw, 560px);
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 18px 50px #000b;
}

.overlay-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.trick-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 16px;
}

.trick-row {
  display: flex;
  gap: 6px;
}

.seat-self .hand {
  justify-content: center;
  margin: 0;
  gap: 18px;
}

.hand-group {
  display: flex;
  gap: 4px;
}

.self-name {
  color: #cfe0d3;
  font-weight: 500;
}

.self-name b {
  color: #ffd47a;
}

@media (max-width: 900px) {
  .score-row {
    flex-wrap: wrap;
  }

  .ledger-col,
  .totals-box {
    flex: 1 1 100%;
    min-width: 0;
    max-width: none;
  }
}

@media (max-width: 860px) {
  .felt {
    height: auto;
    grid-template-areas:
      "top top"
      "left right"
      "center center"
      "self self";
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto auto;
  }

  .seat-left,
  .seat-right {
    justify-content: center;
  }
}

/* --- рубашки из колоды --- */

.card-back {
  border: 0;
  border-radius: 4px;
  background: #7d2330 var(--card-back, url("deck/back.svg")) center / cover no-repeat;
  box-shadow: 0 1px 3px #0007;
}

.card-back::after {
  display: none;
}

.trick-back {
  border: 0;
  border-radius: 4px;
  background: #7d2330 url("deck/back.svg") center / cover no-repeat;
  box-shadow: 0 1px 3px #0007;
}

.panel {
  position: sticky;
  bottom: 8px;
  z-index: 20;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  box-shadow: 0 8px 24px #0006;
}

.strains {
  display: flex;
  gap: 6px;
}

.strain {
  width: 46px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.strain.red {
  color: #e0736c;
}

.strain:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* --- запись на бумаге --- */

.sheet {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* --- таблица записи --- */

.sheet-box {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.sheet-box.mine {
  border-color: var(--accent2);
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.sheet-table th {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}

.sheet-table td {
  padding: 5px 12px;
  border-bottom: 1px solid #23272e;
  color: var(--muted);
  font-size: 13px;
}

/* сетка таблицы: вертикальные и горизонтальные линии */

.sheet-table th,
.sheet-table td {
  border: 1px solid #2f353d;
}

.sheet-table td.num {
  color: var(--text);
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

.sheet-table tbody.under tr:first-child td {
  border-top: 3px double #3a4048;
  color: var(--text);
  font-weight: 600;
}

.sheet-table .chain {
  padding-top: 2px;
  border-bottom: 0;
  color: var(--muted);
  font-size: 11.5px;
}

.sheet-table tfoot td {
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  background: #ffffff06;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

/* Таблица по партиям: строка — партия, четыре колонки очков */

.scores th,
.scores td {
  text-align: right;
}

.scores th:first-child,
.scores td:first-child {
  width: 120px;
  text-align: left;
}

.scores .row-label {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

.scores .row-label .sub {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.scores tr.cur {
  background: #ffffff08;
}

.scores .win {
  color: var(--accent);
  font-weight: 600;
}

.cell-num {
  display: block;
  font-size: 12px;
  line-height: 1.25;
  color: var(--text);
}

.ledger th,
.ledger td {
  text-align: right;
  padding: 4px 10px;
}

.ledger th {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
  white-space: nowrap;
}

.ledger th .sub {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--muted);
  white-space: normal;
}

.ledger td.bomb {
  font-size: 12px;
  line-height: 1.1;
  word-break: break-all;
}

.ledger-col {
  flex: 1 1 440px;
  min-width: 350px;
  max-width: 456px;
}

.score-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 16px;
  align-items: flex-start;
}

.totals-box {
  flex: 0 1 auto;
  min-width: 300px;
  max-width: 380px;
}

.totals-title {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.totals-grid {
  display: grid;
  grid-template-columns: 96px 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-variant-numeric: tabular-nums;
}

.tg-head {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel2);
  color: var(--muted);
  font-size: 11.5px;
  text-align: right;
}

.tg-head:first-child {
  color: var(--muted);
  text-align: left;
}

.tg-label {
  padding: 6px 10px;
  border-bottom: 1px solid #23272e;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.tg-label .sub {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.tg-num {
  padding: 6px 10px;
  border-bottom: 1px solid #23272e;
  border-left: 1px solid #23272e;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-align: right;
}

.tg-num.win {
  color: var(--accent);
  font-weight: 600;
}

.totals-grid .cur {
  background: #ffffff08;
}

.ledger tfoot .subtotal-label td {
  padding-top: 8px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ledger tfoot .subtotal td {
  padding-bottom: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.ledger .game-row td {
  padding-top: 10px;
  background: #ffffff05;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.ledger .game-row td.num {
  color: var(--text);
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
}

.ledger-legend {
  max-width: 456px;
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.6;
}

.ledger .cell-num {
  font-size: 11.5px;
  line-height: 1.35;
  white-space: nowrap;
}

/* Итог сыгранной раздачи — прямо на поле */

.hand-result {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 6;
  min-width: 280px;
  padding: 12px 16px;
  border: 1px solid #3a4150;
  border-radius: 12px;
  background: #0d1117f2;
  box-shadow: 0 12px 32px #000a;
  transform: translate(-50%, -50%);
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.55;
  text-align: center;
}

.hand-result-title {
  margin-bottom: 3px;
  font-weight: 600;
}

.hand-result-row {
  color: var(--muted);
}

/* Жеребьёвка перед первой раздачей */

.draw-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 7;
  min-width: 300px;
  padding: 14px 18px;
  border: 1px solid #3a4150;
  border-radius: 12px;
  background: #0d1117f5;
  box-shadow: 0 14px 36px #000b;
  transform: translate(-50%, -50%);
  cursor: pointer;
  font-size: 13px;
}

.draw-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 10px 0;
}

.draw-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.draw-row .draw-name {
  flex: 1;
  white-space: nowrap;
}

.draw-row.self .draw-name {
  color: var(--accent);
  font-weight: 600;
}

.draw-seat {
  font-size: 11.5px;
  white-space: nowrap;
}

.draw-row .pcard {
  width: 30px;
  height: 42px;
}

/* Веер карт на зелёном столе */

.fan-deck {
  position: relative;
  height: 250px;
  margin: 14px 0;
  overflow: hidden;
  border: 1px solid #2b4a38;
  border-radius: 14px;
  background:
    radial-gradient(120% 150% at 50% 120%, #1f5a3a 0%, #143b27 65%, #0c2517 100%);
  box-shadow: inset 0 0 60px #0006;
}

.fan-card {
  position: absolute;
  top: 46px;
  left: 50%;
  width: 40px;
  height: 56px;
  margin-left: -20px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform: rotate(var(--angle));
  transform-origin: 50% 200px;
  transition: transform 0.12s ease;
}

.fan-card img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 4px;
  box-shadow: 0 2px 6px #0009;
}

.fan-card:hover {
  z-index: 60;
  transform: rotate(var(--angle)) translateY(-14px);
}

.fan-card.closed {
  cursor: default;
  opacity: 0.55;
}

.my-pick {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
}

.my-pick .pcard {
  width: 40px;
  height: 56px;
}

.draw-picks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.draw-pick {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  font-size: 11.5px;
  text-align: center;
}

.draw-pick.self {
  border-color: var(--accent2);
}

.draw-pick .pcard {
  width: 30px;
  height: 42px;
}

.draw-pick-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--text);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draw-pick-card {
  font-size: 10.5px;
}

.ledger tbody tr:nth-child(even) {
  background: #ffffff05;
}

.sheet-team {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-variant-numeric: tabular-nums;
}

.sheet-team.mine {
  border-color: var(--accent2);
}

.sheet-name {
  font-weight: 600;
  margin-bottom: 6px;
}

.sheet-above {
  max-height: 150px;
  overflow: auto;
}

.entry {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  padding: 2px 0;
  color: var(--muted);
}

.entry b {
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}

.sheet-rule {
  border-top: 2px solid var(--line);
  margin: 8px 0;
}

.sheet-total {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-weight: 600;
}

.race {
  height: 4px;
  background: #2c313a;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}

.history {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  word-break: break-word;
}

.auction-log {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.chip.nopass {
  border-color: var(--accent);
  color: var(--accent);
}

.race span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.score {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.score.mine {
  border-color: var(--accent2);
}

.score .num {
  font-size: 20px;
  font-weight: 600;
}

.score .sub {
  color: var(--muted);
  font-size: 13px;
}

.log {
  font-family: "Consolas", ui-monospace, monospace;
  font-size: 12px;
  color: var(--muted);
  max-height: 120px;
  overflow: auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #2b3038;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.big {
  font-size: 19px;
  font-weight: 600;
}

.spacer {
  height: 12px;
}

.build { margin-left: auto; color: #4b8f6b; font-size: 11px; }

/* мобильные правила — в конце файла, чтобы перекрывать базовые */
@media (max-width: 700px) {
  /* Веер жеребьёвки компактнее, чтобы не выходил за карточку стола */
  .fan-deck {
    height: 165px;
    margin: 10px 0;
  }

  .fan-card {
    top: 30px;
    transform-origin: 50% 106px;
  }

  #app {
    padding: 8px 8px 24px;
  }

  .status {
    gap: 6px;
    padding: 7px 9px;
    font-size: 12px;
    margin-bottom: 8px;
  }

  .status-actions {
    width: 100%;
    justify-content: flex-end;
  }

  /* Поле занимает 80% экрана, расстановка как на десктопе */
  .felt {
    display: grid;
    grid-template-areas:
      "top top top"
      "left center right"
      "self self self";
    grid-template-columns: 62px minmax(0, 1fr) 62px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 2px;
    height: calc(86vh - 42px);
    min-height: 0;
    padding: 8px;
    overflow: hidden;
    border-radius: 14px;
  }

  .seat-top {
    justify-content: center;
  }

  .seat-left {
    justify-content: flex-start;
  }

  .seat-right {
    justify-content: flex-end;
  }

  .seat-self {
    margin-top: 0;
    padding-top: 0;
  }

  .table-center {
    min-height: 70px;
    gap: 6px;
  }

  .hand {
    gap: 3px;
    margin-bottom: 6px;
  }

  .hand .pcard {
    width: 40px;
  }

  .self-line {
    font-size: 11.5px;
  }

  /* Панель торговли — нижние 20% экрана */
  .panel:not(.panel-inline) {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    max-height: 14vh;
    overflow: auto;
    gap: 6px;
    padding: 8px 10px;
    margin: 0;
    border-width: 1px 0 0;
    border-radius: 12px 12px 0 0;
    font-size: 12.5px;
  }

  .panel-inline {
    position: fixed;
    right: 8px;
    bottom: calc(20vh + 8px);
    left: 8px;
    z-index: 29;
    padding: 8px 10px;
    margin: 0;
    font-size: 12.5px;
  }

  /* Итоги раздачи и жеребьёвка — поверх стола, но в пределах экрана */
  .hand-result,
  .draw-overlay {
    position: fixed;
    top: 68px;
    right: 8px;
    left: 8px;
    z-index: 40;
    min-width: 0;
    max-width: none;
    max-height: 60vh;
    overflow: auto;
    transform: none;
  }

  .draw-row {
    font-size: 12px;
  }

  .draw-row .pcard {
    width: 26px;
    height: 36px;
  }

  .draw-list {
    gap: 4px;
  }

  /* Рука компактнее: 13 карт в два ряда */
  /* Рука веером в один ряд: карты с нахлёстом, чтобы 13 штук влезали по ширине */
  .hand {
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0;
    overflow: visible;
  }

  .hand .pcard {
    width: 54px;
    margin-left: -28px;
  }

  .hand .pcard:first-child {
    margin-left: 0;
  }

  .hand .pcard:hover,
  .hand .pcard:focus-visible {
    z-index: 8;
    transform: translateY(-12px);
  }

  .auction-log {
    font-size: 11px;
  }

  #app {
    padding-bottom: 12px;
  }

  /* На телефоне чат сразу за столом, без пустого разрыва */
  .chat {
    margin-top: 8px;
  }

  .sheet-table th,
  .sheet-table td {
    padding: 4px 8px;
    font-size: 12px;
  }
}

/* Счёт по запросу — всплывающее окно */
.score-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #000a;
  backdrop-filter: blur(3px);
}

.score-sheet {
  width: min(820px, 100%);
  max-height: 88vh;
  overflow: auto;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  box-shadow: 0 24px 60px #000b;
}

.score-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.score-head h2 { margin: 0; }

.score-sheet .score-row { gap: 12px; }

.score-sheet .ledger-col {
  flex: 1 1 340px;
  min-width: 280px;
  max-width: none;
}

.score-sheet .totals-box {
  flex: 0 1 320px;
  min-width: 260px;
  max-width: none;
}

/* Запись: шапка и данные в одних столбцах */
.ledger th,
.ledger td {
  vertical-align: middle;
}

.ledger thead th {
  height: 46px;
}

  .seat-block {
    padding: 2px 4px;
    gap: 2px;
  }

  .seat-name {
    font-size: 12px;
  }

  .bid-bubble {
    padding: 0 7px;
    font-size: 11px;
  }

/* =====================  ДИЗАЙН-ПРОХОД: токены, стол, панели  ===================== */

:root {
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --shadow-panel: 0 10px 26px #00000066;
  --shadow-card: 0 2px 6px #00000066, 0 6px 18px #00000033;
  --ring: 0 0 0 1px #ffd47a66, 0 0 22px #ffd47a2e;
}

/* стол: подсветка «от лампы» + виньетка + тень по краю */
.felt {
  background:
    radial-gradient(120% 90% at 50% -10%, #2f7f52 0%, #246c46 32%, #17522f 62%, #0d3722 100%),
    radial-gradient(60% 40% at 50% 8%, #ffffff14, transparent 70%);
  background-blend-mode: screen, normal;
  box-shadow:
    inset 0 0 90px #000000aa,
    inset 0 1px 0 #ffffff1a,
    0 18px 40px #00000066;
  border: 1px solid #0a2b1c;
}

/* единые панели */
.status,
.card-panel,
.panel,
.sheet-box,
.score-sheet {
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
}

.panel {
  backdrop-filter: blur(6px);
}

/* =====================  КАРТЫ  ===================== */

.pcard {
  border-radius: 8px;
  box-shadow: var(--shadow-card);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.hand .pcard:hover,
.hand .pcard:focus-visible {
  transform: translateY(-10px);
  box-shadow: 0 10px 22px #00000080;
  z-index: 6;
}

.trick-slot {
  animation: slotIn 0.22s ease-out both;
}

@keyframes slotIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* =====================  ТИПОГРАФИКА  ===================== */

body {
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: 0.01em;
}

.sheet-table,
.scores,
.ledger,
.totals-grid,
.status,
.self-line {
  font-variant-numeric: tabular-nums;
}

h2 {
  letter-spacing: 0.1em;
}

/* =====================  МИКРОАНИМАЦИИ  ===================== */

.seat-block.turn {
  box-shadow: var(--ring);
  animation: turnPulse 2.4s ease-in-out infinite;
}

@keyframes turnPulse {
  0%, 100% { box-shadow: 0 0 0 1px #ffd47a55, 0 0 18px #ffd47a22; }
  50% { box-shadow: 0 0 0 1px #ffd47a99, 0 0 30px #ffd47a44; }
}

.bid-bubble {
  animation: bubblePop 0.18s ease-out both;
}

@keyframes bubblePop {
  from { opacity: 0; transform: scale(0.7) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.panel {
  animation: panelIn 0.18s ease-out both;
}

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

/* =====================  ПАНЕЛЬ ТОРГОВЛИ  ===================== */

.strain {
  width: 54px;
  height: 46px;
  font-size: 22px;
  border-radius: var(--radius-sm);
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

.strain:hover:not(:disabled) {
  border-color: #ffd47a88;
  background: #2c313a;
  transform: translateY(-2px);
}

.strain:active:not(:disabled) {
  transform: translateY(0);
}

#lvl {
  height: 42px;
  border-radius: var(--radius-sm);
  font-size: 15px;
}

/* =====================  СВЕТЛАЯ ТЕМА  ===================== */

body.light {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --panel2: #f3efe6;
  --line: #d8d1c2;
  --text: #23262b;
  --muted: #6f736f;
  --accent: #a9761c;
  --accent2: #2f7a55;
  background: radial-gradient(circle at 50% 0%, #ffffff 0%, #efeae0 70%);
}

body.light .felt {
  background:
    radial-gradient(120% 90% at 50% -10%, #63a97a 0%, #4e9268 34%, #3a7a53 66%, #2c6042 100%),
    radial-gradient(60% 40% at 50% 8%, #ffffff26, transparent 70%);
  background-blend-mode: screen, normal;
  border-color: #2b6042;
  box-shadow:
    inset 0 0 70px #00000055,
    inset 0 1px 0 #ffffff33,
    0 14px 32px #00000033;
}

body.light .panel,
body.light .status,
body.light .card-panel,
body.light .sheet-box {
  box-shadow: 0 8px 22px #0000001f;
}

body.light .bid-bubble {
  background: #ffffff;
  color: #22302a;
}

body.light .seat-name {
  color: #123521;
  text-shadow: 0 1px 2px #ffffffaa;
}

body.light .btn.ghost.tiny,
body.light .btn.ghost {
  color: var(--text);
}

/* =====================  Крупные карты в центре  ===================== */

.trick-cross {
  width: 170px;
  height: 190px;
  margin: 4px auto 2px;
}

.trick-slot {
  width: 56px;
  height: 78px;
}

.trick-slot .pcard,
.trick-slot .pcard.small {
  width: 56px;
  height: 78px;
}

.slot-top {
  left: 57px;
  top: 17px;
}

.slot-bottom {
  left: 57px;
  top: 95px;
}

.slot-left {
  left: 29px;
  top: 56px;
}

.slot-right {
  left: 85px;
  top: 56px;
}

.table-center {
  gap: 8px;
}

.trick-result {
  margin-top: 2px;
}

/* =====================  Показанные взятки: компактно рядом с игроком  ===================== */

.trick-shown-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: center;
  mask-image: none;
}

.trick-shown {
  display: flex;
  gap: 2px;
  padding: 3px 4px;
  border-radius: 8px;
  background: #00000055;
  box-shadow: inset 0 0 0 1px #ffffff1f;
  animation: bubblePop 0.22s ease-out;
}

.trick-shown .pcard,
.trick-shown .pcard.small {
  width: 30px;
  height: 42px;
  border-radius: 5px;
}

.seat {
  gap: 8px;
}

/* =====================  Центр: заявка не прячется под веером  ===================== */

@media (min-width: 701px) {
  .felt {
    height: clamp(600px, calc(100vh - 200px), 900px);
  }
}

.contract-chip {
  position: relative;
  z-index: 4;
  background: #0b2b1cf5;
  box-shadow: 0 2px 10px #0007;
}

.table-center {
  min-height: 0;
  padding-top: 10px;
}

/* =====================  Плашка заявки во время торговли  ===================== */

.contract-chip.is-auction {
  border-color: #ffd47a;
  background: linear-gradient(180deg, #3a2c10f5, #241a08f5);
  color: #ffe6a6;
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: 0 0 0 1px #ffd47a88, 0 6px 22px #ffd47a33;
  animation: chipPulse 2.4s ease-in-out infinite;
}

@keyframes chipPulse {
  0%, 100% { box-shadow: 0 0 0 1px #ffd47a88, 0 6px 22px #ffd47a2e; }
  50% { box-shadow: 0 0 0 1px #ffd47acc, 0 8px 28px #ffd47a55; }
}

/* =====================  Кнопки «Пас» и «Без паса»  ===================== */

.btn-pass {
  border-color: #c05a55aa;
  color: #f2b7b3;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease,
    box-shadow 0.12s ease;
}

.btn-pass:hover:not(:disabled) {
  border-color: #e57a72;
  background: #3a1f1e;
  box-shadow: 0 0 0 1px #c05a5566, 0 6px 18px #c05a5540;
  transform: translateY(-1px);
}

.btn-pass:active:not(:disabled) {
  transform: translateY(0);
}

.btn-nopass {
  border-color: #4b8f6baa;
  color: #bfe3cd;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease,
    box-shadow 0.12s ease;
}

.btn-nopass:hover:not(:disabled) {
  border-color: #6fbf93;
  background: #16301f;
  box-shadow: 0 0 0 1px #4b8f6b66, 0 6px 18px #4b8f6b40;
  transform: translateY(-1px);
}

.btn-nopass:active:not(:disabled) {
  transform: translateY(0);
}

/* =====================  Меню оформления карт  ===================== */

.design-sheet {
  max-width: 520px;
}

.design-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.design-choice {
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}

.design-choice:hover {
  border-color: var(--accent2);
  transform: translateY(-1px);
}

.design-choice.active {
  border-color: var(--accent);
  color: #ffe6a6;
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.back-choice {
  display: flex;
  width: 84px;
  height: 112px;
  padding-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  align-items: flex-end;
  justify-content: center;
  color: #fff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  text-shadow: 0 1px 3px #000c;
  transition: transform 0.12s ease, outline-color 0.12s ease;
}

.back-choice:hover {
  transform: translateY(-3px);
}

.back-choice.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.back-choice.back-crimson {
  background: repeating-linear-gradient(45deg, #7d2330 0 7px, #8f2b39 7px 14px);
}

.back-choice.back-ocean {
  background: repeating-linear-gradient(45deg, #16375f 0 7px, #1f4a7d 7px 14px);
}

.back-choice.back-forest {
  background: repeating-linear-gradient(45deg, #14482c 0 7px, #1c5c3a 7px 14px);
}

.back-choice.back-gold {
  background: repeating-linear-gradient(45deg, #4a3a12 0 7px, #6a5318 7px 14px);
}

/* рубашки на столе */
body.back-ocean .card-back,
body.back-ocean .trick-back {
  background: repeating-linear-gradient(45deg, #16375f 0 6px, #1f4a7d 6px 12px);
}

body.back-forest .card-back,
body.back-forest .trick-back {
  background: repeating-linear-gradient(45deg, #14482c 0 6px, #1c5c3a 6px 12px);
}

body.back-gold .card-back,
body.back-gold .trick-back {
  background: repeating-linear-gradient(45deg, #4a3a12 0 6px, #6a5318 6px 12px);
}

/* классическое лицо карт */
.pcard.classic {
  position: relative;
  display: inline-block;
  aspect-ratio: 5 / 7;
  border: 1px solid #cfc9bb;
  border-radius: 7px;
  background: linear-gradient(160deg, #fffefb 0%, #f4f0e6 100%);
  color: #17181a;
  box-shadow: var(--shadow-card);
}

.pcard.classic.red {
  color: #c0392b;
}

.pcard.classic .pc-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.pcard.classic .pc-corner i {
  margin-top: 2px;
  font-size: 12px;
  font-style: normal;
}

.pcard.classic .pc-corner.tl {
  top: 5px;
  left: 6px;
}

.pcard.classic .pc-corner.br {
  right: 6px;
  bottom: 5px;
  transform: rotate(180deg);
}

.pcard.classic .pc-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
}

.pcard.classic .pc-center i {
  margin-top: 2px;
  font-size: 18px;
  font-style: normal;
}

.pcard.classic.small {
  aspect-ratio: 5 / 7;
}

.pcard.classic.small .pc-corner {
  font-size: 10px;
}

.pcard.classic.small .pc-corner i {
  font-size: 9px;
}

.pcard.classic.small .pc-center {
  font-size: 18px;
}

.pcard.classic.small .pc-center i {
  font-size: 12px;
}

/* =====================  Собственные стили лиц карт  ===================== */

.pcard.drawn {
  position: relative;
  display: inline-block;
  aspect-ratio: 5 / 7;
  border-radius: 7px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
  user-select: none;
}

.pcard.drawn .pc-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-weight: 700;
  line-height: 1;
  z-index: 2;
}

.pcard.drawn .pc-corner i {
  margin-top: 2px;
  font-style: normal;
}

.pcard.drawn .pc-corner.tl {
  top: 5px;
  left: 6px;
}

.pcard.drawn .pc-corner.br {
  right: 6px;
  bottom: 5px;
  transform: rotate(180deg);
}

.pcard.drawn .pc-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.pcard.drawn .pc-center i {
  margin-top: 2px;
  font-style: normal;
}

/* --- Классика --- */
.pcard.face-classic {
  border: 1px solid #cfc9bb;
  background: linear-gradient(160deg, #fffefb 0%, #f4f0e6 100%);
  color: #17181a;
}

.pcard.face-classic.red {
  color: #c0392b;
}

.pcard.face-classic .pc-corner {
  font-size: 13px;
}

.pcard.face-classic .pc-corner i {
  font-size: 12px;
}

.pcard.face-classic .pc-center {
  font-size: 26px;
}

.pcard.face-classic .pc-center i {
  font-size: 18px;
}

/* --- Минимал --- */
.pcard.face-minimal {
  border: 1px solid #d5d2cc;
  background: #ffffff;
  color: #1a1c1f;
}

.pcard.face-minimal.red {
  color: #b03a2e;
}

.pcard.face-minimal .pc-corner {
  font-size: 12px;
  font-weight: 600;
}

.pcard.face-minimal .pc-corner i {
  font-size: 10px;
}

.pcard.face-minimal .pc-center {
  font-size: 30px;
  opacity: 0.9;
}

.pcard.face-minimal .pc-center i {
  font-size: 16px;
}

/* --- Неон --- */
.pcard.face-neon {
  border: 1px solid #2a3550;
  background: radial-gradient(120% 120% at 50% 0%, #1b2440 0%, #0d1220 70%);
  color: #7fd4ff;
  box-shadow: 0 0 10px #2f8fd433, 0 4px 14px #00000088;
}

.pcard.face-neon.red {
  color: #ff7ba8;
  box-shadow: 0 0 10px #ff4f8b33, 0 4px 14px #00000088;
}

.pcard.face-neon .pc-corner {
  font-size: 12px;
  text-shadow: 0 0 6px currentColor;
}

.pcard.face-neon .pc-corner i {
  font-size: 11px;
}

.pcard.face-neon .pc-center {
  font-size: 30px;
  text-shadow: 0 0 14px currentColor;
}

.pcard.face-neon .pc-center i {
  font-size: 18px;
}

/* --- Пиксель --- */
.pcard.face-pixel {
  border: 2px solid #2b2b2b;
  border-radius: 3px;
  background: #f6f3e6;
  color: #232323;
  font-family: "Consolas", ui-monospace, monospace;
  box-shadow: 3px 3px 0 #00000033;
}

.pcard.face-pixel.red {
  color: #b02b2b;
}

.pcard.face-pixel .pc-corner {
  font-size: 13px;
  letter-spacing: -0.04em;
}

.pcard.face-pixel .pc-corner i {
  font-size: 11px;
}

.pcard.face-pixel .pc-center {
  font-size: 30px;
}

.pcard.face-pixel .pc-center i {
  font-size: 16px;
}

/* --- Ретро --- */
.pcard.face-retro {
  border: 1px solid #b9a888;
  background:
    radial-gradient(120% 120% at 30% 10%, #fbf3dd 0%, #efe3c4 60%, #e3d3ae 100%);
  color: #3a2a18;
}

.pcard.face-retro.red {
  color: #8f2f21;
}

.pcard.face-retro .pc-corner {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
}

.pcard.face-retro .pc-corner i {
  font-size: 12px;
}

.pcard.face-retro .pc-center {
  font-size: 28px;
  text-shadow: 1px 1px 0 #ffffff88;
}

.pcard.face-retro .pc-center i {
  font-size: 17px;
}

/* уменьшенные карты */
.pcard.drawn.small .pc-corner {
  font-size: 10px;
}

.pcard.drawn.small .pc-corner i {
  font-size: 9px;
}

.pcard.drawn.small .pc-center {
  font-size: 18px;
}

.pcard.drawn.small .pc-center i {
  font-size: 12px;
}

/* =====================  Анимация раздачи от сдающего  ===================== */

.deal-overlay {
  position: absolute;
  inset: 0;
  z-index: 26;
  pointer-events: none;
  overflow: hidden;
}

.deal-card {
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 33px;
  margin: -16px 0 0 -12px;
  border-radius: 4px;
  background: #7d2330 var(--card-back, url("deck/back.svg")) center / cover no-repeat;
  box-shadow: 0 3px 10px #000a, 0 0 0 1px #ffffff22;
  opacity: 0;
  animation: dealFly 480ms cubic-bezier(0.3, 0.7, 0.4, 1) both;
}

@keyframes dealFly {
  0% {
    left: calc(var(--sx) * 1%);
    top: calc(var(--sy) * 1%);
    opacity: 0;
    transform: scale(0.8) rotate(-8deg);
  }
  14% {
    opacity: 1;
  }
  100% {
    left: calc(var(--tx) * 1%);
    top: calc(var(--ty) * 1%);
    opacity: 0;
    transform: scale(1) rotate(10deg);
  }
}

/* пока карты раздаются, руки и веера скрыты, потом проявляются */
.hand,
.fan {
  transition: opacity 0.28s ease;
}

.felt.dealing .hand,
.felt.dealing .fan,
.felt.dealing .seat-info,
.felt.dealing .contract-chip {
  opacity: 0;
}

/* =====================  Мобильная раскладка: карты, панель, отступы  ===================== */

@media (max-width: 700px) {
  /* место под фиксированную панель торговли */
  #app {
    padding: 8px 8px 132px;
  }

  /* стол не заезжает под панель */
  .felt {
    height: calc(100vh - 168px);
    min-height: 380px;
  }

  /* рука: все 13 карт влезают по ширине, с перекрытием */
  .hand {
    gap: 0;
    justify-content: center;
    flex-wrap: nowrap;
    max-width: 100%;
    margin-bottom: 4px;
  }

  .hand .pcard {
    width: 46px;
    margin-left: -22px;
    flex: 0 0 auto;
  }

  .hand .pcard:first-child {
    margin-left: 0;
  }

  /* панель торговли: два ряда */
  .panel:not(.panel-inline) {
    max-height: 30vh;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 10px;
  }

  .panel:not(.panel-inline) > b {
    order: 1;
    flex: 0 0 auto;
  }

  #lvl {
    order: 1;
    flex: 1 1 70px;
    min-width: 0;
    height: 36px;
    font-size: 13px;
  }

  .btn-nopass,
  .btn-pass {
    order: 2;
    flex: 0 0 auto;
    padding: 8px 12px;
    font-size: 13px;
  }

  .strains {
    order: 3;
    flex: 1 0 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .strain {
    flex: 1 1 0;
    width: auto;
    height: 36px;
    font-size: 19px;
  }

  /* история торговли и строка партий — с отступом от панели */
  .auction-log {
    margin: 6px 0 2px;
  }

  .auction-log .log-chip {
    font-size: 11px;
    padding: 2px 7px;
  }
}

/* =====================  Рука в два ряда (мобильная версия)  ===================== */

@media (max-width: 700px) {
  .hand {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 3px;
    width: 100%;
    max-width: 100%;
    margin-bottom: 2px;
  }

  .hand .pcard {
    flex: 0 0 calc((100% - 20px) / 7);
    width: auto;
    max-width: 56px;
    margin-left: 0;
    border-radius: 6px;
  }

  .hand .pcard:hover {
    transform: none;
  }

  /* центр чуть компактнее, чтобы два ряда карт поместились */
  .table-center {
    min-height: 56px;
    gap: 4px;
  }

  .trick-cross {
    transform: scale(0.88);
    transform-origin: 50% 50%;
    margin: 0 auto -8px;
  }

  .self-line {
    margin-top: 2px;
  }
}

/* =====================  Рука: сетка 7 колонок, два ряда  ===================== */

@media (max-width: 700px) {
  .seat-self .hand,
  .hand {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    max-width: 100%;
    justify-content: stretch;
    align-items: start;
    margin: 0 0 4px;
  }

  .seat-self .hand .pcard,
  .hand .pcard {
    width: 100%;
    max-width: none;
    min-width: 0;
    margin-left: 0;
    flex: none;
    border-radius: 6px;
  }

  .hand .pcard:hover {
    transform: none;
  }

  /* стол: высота от динамического вьюпорта, но не меньше разумного */
  .felt {
    height: calc(100dvh - 175px);
    min-height: 430px;
  }

  .table-center {
    min-height: 52px;
    gap: 3px;
  }

  .trick-cross {
    transform: scale(0.84);
    transform-origin: 50% 50%;
    margin: 0 auto -10px;
  }
}

/* =====================  Мобильная рука: карты внутри групп  ===================== */

@media (max-width: 700px) {
  /* группы по мастям перестают быть контейнерами — карты идут прямо в сетку */
  .hand .hand-group {
    display: contents;
  }

  .seat-self .hand,
  .hand {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    width: 100%;
    max-width: 100%;
    margin: 0 0 4px;
  }

  .hand .pcard {
    width: 100%;
    max-width: none;
    min-width: 0;
    margin-left: 0;
    border-radius: 6px;
  }

  /* страница — колонка, стол занимает свободное место и не уезжает под панель */
  #app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    padding: 8px 8px 132px;
    box-sizing: border-box;
  }

  .felt {
    flex: 1 1 auto;
    height: auto;
    min-height: 340px;
  }
}

/* =====================  Мобильная рука: масти отдельными группами  ===================== */

@media (max-width: 700px) {
  .seat-self .hand,
  .hand {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    align-items: flex-start;
    gap: 8px 12px;
    width: 100%;
    max-width: 100%;
    margin: 0 0 4px;
  }

  /* группа = одна масть, карты внутри неё идут вплотную */
  .hand .hand-group {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    max-width: 100%;
    padding: 3px 4px 4px;
    border-radius: 8px;
    background: #00000033;
    box-shadow: inset 0 0 0 1px #ffffff17;
  }

  .hand .pcard {
    width: 44px;
    max-width: none;
    min-width: 0;
    margin: 0;
    flex: 0 0 auto;
    border-radius: 6px;
  }

  .hand .pcard:hover {
    transform: none;
  }
}

/* =====================  Мобильная рука: финальный размер карт  ===================== */

@media (max-width: 700px) {
  .seat-self .hand {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    align-items: flex-start;
    gap: 8px 12px;
    width: 100%;
    max-width: 100%;
    margin: 0 0 4px;
  }

  .seat-self .hand .hand-group {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    max-width: 100%;
    padding: 3px 4px 4px;
    border-radius: 8px;
    background: #00000033;
    box-shadow: inset 0 0 0 1px #ffffff17;
  }

  .seat-self .hand .pcard {
    display: block;
    width: 44px;
    max-width: 44px;
    min-width: 0;
    margin: 0;
    flex: 0 0 auto;
    border-radius: 6px;
    transform: none;
  }

  .seat-self .hand .pcard:hover,
  .seat-self .hand .pcard:focus-visible {
    transform: none;
    box-shadow: var(--shadow-card);
  }
}

/* =====================  Убираем мерцание: анимации, которые перезапускаются при перерисовке  ===================== */

.bid-bubble,
.panel,
.trick-slot,
.fan-card,
.hand-result,
.draw-overlay {
  animation: none !important;
}

/* =====================  Подсказки во время розыгрыша  ===================== */

.led-line {
  font-size: 12px;
  color: #cfe3d6;
  opacity: 0.85;
}

.void-hint {
  padding: 2px 10px;
  border-radius: 999px;
  background: #ffd47a1f;
  border: 1px solid #ffd47a55;
  color: #ffe6a6;
  font-size: 12px;
}


/* =====================  Защита от принудительной тёмной темы (Samsung, MIUI)  ===================== */

:root {
  color-scheme: dark;
}

body.light {
  color-scheme: light;
}

/* карты — это SVG-картинки: браузер не должен их перекрашивать */
.pc-img,
.fan-card img,
.deal-card {
  filter: none !important;
  forced-color-adjust: none;
}

.pcard,
.pcard.drawn,
.trick-slot .pcard {
  forced-color-adjust: none;
}

/* карты вне хода не должны выглядеть «выключенными» и темнеть */
.pcard:disabled,
.pcard[disabled] {
  opacity: 1;
  cursor: default;
  filter: none;
}


/* =====================  Недоступная карта: без затемнения  ===================== */

.pcard[data-locked="1"] {
  opacity: 1 !important;
  filter: none !important;
  pointer-events: none;
  cursor: default;
}

.pcard {
  background-color: #ffffff;
}

/* =====================  Кнопка «убрать» в лобби  ===================== */

.list-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn.kick {
  margin-left: 0;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.4;
  border-color: #c05a5566;
  color: #f2b7b3;
}

.btn.kick:hover {
  border-color: #e57a72;
  background: #3a1f1e;
}

/* =====================  Подсветка хода и окно торговли  ===================== */

.turn-banner {
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.turn-banner.play {
  background: #2f7a55;
  color: #eafff2;
  box-shadow: 0 0 0 1px #7fe0ad66, 0 6px 20px #2f7a5566;
}

.turn-banner.bid {
  background: #a9761c;
  color: #fff6df;
  box-shadow: 0 0 0 1px #ffd47a80, 0 6px 20px #a9761c66;
}

.panel.panel-turn {
  border-color: #ffd47a;
  box-shadow: 0 0 0 1px #ffd47a66, 0 10px 30px #ffd47a33;
}

.auction-sheet {
  max-width: 520px;
}

.auction-log-list {
  max-height: 55vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auction-log-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #ffffff0a;
}

.bid-strong {
  color: #ffd47a;
  font-weight: 600;
}

.bot-tag {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #ffffff14;
  color: #b9c6bd;
  font-size: 11px;
}

/* подсветка своей руки, когда мой ход */
.seat-self.my-turn .hand {
  filter: drop-shadow(0 0 12px #ffd47a55);
}

/* =====================  Лобби как стол  ===================== */

.lobby {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lobby-table {
  position: relative;
  display: grid;
  grid-template-areas:
    "top top top"
    "left center right"
    "self self self";
  grid-template-columns: minmax(0, 1fr) minmax(160px, 1.4fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(120px, 1fr) auto;
  gap: 10px;
  padding: 18px 14px;
  border-radius: 18px;
  background:
    radial-gradient(120% 90% at 50% -10%, #2f7f52 0%, #246c46 34%, #17522f 64%, #0d3722 100%);
  box-shadow:
    inset 0 0 80px #000000aa,
    inset 0 1px 0 #ffffff1a,
    0 16px 36px #00000055;
  border: 1px solid #0a2b1c;
}

.lobby-seat {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #0b2b1c66;
  box-shadow: inset 0 0 0 1px #ffffff1a;
  min-height: 64px;
  justify-content: center;
}

.lobby-seat.empty {
  background: #0b2b1c33;
  border: 1px dashed #ffffff26;
}

.seat-top { grid-area: top; justify-self: center; min-width: 160px; }
.seat-left { grid-area: left; justify-self: start; align-self: center; min-width: 130px; }
.seat-right { grid-area: right; justify-self: end; align-self: center; min-width: 130px; }
.seat-self { grid-area: self; justify-self: center; min-width: 180px; }

.lobby-seat-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lobby-name {
  color: #eaf5ec;
  font-weight: 600;
}

.lobby-role {
  font-size: 11px;
  color: #b9c6bd;
  letter-spacing: 0.03em;
}

.lobby-empty {
  color: #ffffff59;
  font-size: 13px;
}

.lobby-center {
  grid-area: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}

.lobby-code-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #b9c6bd;
}

.lobby-center .code {
  font-size: 30px;
  color: #ffd47a;
}

.lobby-count {
  font-size: 12px;
  color: #b9c6bd;
}

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

@media (max-width: 700px) {
  .lobby-table {
    grid-template-columns: minmax(0, 1fr) minmax(120px, 1.2fr) minmax(0, 1fr);
    grid-template-rows: auto minmax(96px, 1fr) auto;
    gap: 6px;
    padding: 12px 8px;
  }

  .lobby-seat {
    padding: 6px 7px;
    min-height: 54px;
  }

  .lobby-center .code {
    font-size: 24px;
  }

  .lobby-name {
    font-size: 13px;
  }
}

/* =====================  Итог жеребьёвки  ===================== */

.seating-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000000aa;
  backdrop-filter: blur(3px);
  padding: 20px;
}

.seating-card {
  width: min(420px, 92vw);
  padding: 20px 22px;
  border-radius: 16px;
  background: linear-gradient(180deg, #14362600, #0b2b1c) , #10301f;
  border: 1px solid #ffd47a44;
  box-shadow: 0 20px 50px #000a;
  text-align: center;
  animation: seatingIn 0.25s ease-out;
}

@keyframes seatingIn {
  from { transform: scale(0.94) translateY(10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.seating-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: #ffd47a;
  margin-bottom: 12px;
}

.seating-team {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: #ffffff0d;
  color: #eaf5ec;
  font-size: 15px;
  text-align: left;
}

.seating-tag {
  flex: 0 0 auto;
  padding: 2px 9px;
  border-radius: 999px;
  background: #ffd47a1f;
  border: 1px solid #ffd47a55;
  color: #ffe6a6;
  font-size: 11px;
  letter-spacing: 0.04em;
}

.seating-foot {
  margin-top: 10px;
  font-size: 12px;
  color: #b9c6bd;
}

/* =====================  Стабильный размер стола на мобильном  ===================== */

@media (max-width: 700px) {
  /* возвращаем обычный поток: стол больше не тянется по содержимому */
  #app {
    display: block;
    min-height: 0;
    padding: 8px 8px 132px;
  }

  .felt {
    flex: none;
    height: calc(100dvh - 170px);
    min-height: 360px;
    max-height: calc(100dvh - 170px);
  }

  /* место под два ряда карт держим всегда, даже когда карт осталось мало */
  .seat-self .hand {
    min-height: 148px;
    align-content: flex-start;
  }

  /* центр стола фиксированной высоты: подсказки не двигают крест */
  .table-center {
    min-height: 176px;
    justify-content: center;
  }

  /* плашки выхода и подсказки не должны менять высоту центра */
  .led-line,
  .void-hint {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
  }

  .table-center {
    position: relative;
  }
}

/* =====================  Рука: группы не сжимаются, карты одного размера  ===================== */

@media (max-width: 700px) {
  .seat-self .hand .hand-group {
    flex: 0 0 auto;
    max-width: 100%;
    gap: 2px;
  }

  .seat-self .hand .pcard {
    width: clamp(38px, 10.5vw, 46px);
    max-width: none;
    flex: 0 0 auto;
  }

  .seat-self .hand {
    gap: 6px 10px;
  }

  /* когда карт мало, рука прижимается к низу и не «прыгает» */
  .seat-self .hand {
    justify-content: center;
    align-content: flex-start;
  }
}

/* =====================  Мобильный: убираем разрыв перед чатом  ===================== */

@media (max-width: 700px) {
  #app {
    padding: 8px 8px 92px;
  }

  .chat {
    width: auto;
    height: 220px;
    max-height: 220px;
    margin: 0 8px 96px;
  }

  .chat-head {
    padding: 8px 12px;
  }

  .chat-list {
    padding: 8px 10px;
    gap: 8px;
  }
}

/* =====================  Жёсткий сброс отступов карт в руке  ===================== */

@media (max-width: 700px) {
  .hand .pcard,
  .hand .pcard:not(:first-child),
  .seat-self .hand .pcard,
  .seat-self .hand .pcard:not(:first-child) {
    margin: 0 !important;
    width: clamp(36px, 10vw, 44px) !important;
    max-width: clamp(36px, 10vw, 44px) !important;
    flex: 0 0 auto !important;
  }

  .hand .hand-group,
  .seat-self .hand .hand-group {
    gap: 3px !important;
    flex: 0 0 auto !important;
    padding: 3px 4px 4px !important;
  }

  .seat-self .hand {
    gap: 6px 8px !important;
  }
}

/* =====================  Компактная шапка на мобильном  ===================== */

.status-actions .btn {
  white-space: nowrap;
}

@media (max-width: 700px) {
  .status {
    padding: 6px 8px;
    font-size: 11.5px;
  }

  .status-actions {
    gap: 5px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .status-actions::-webkit-scrollbar {
    display: none;
  }

  .status-actions .btn.tiny {
    padding: 5px 9px;
    font-size: 11.5px;
    white-space: nowrap;
    flex: 0 0 auto;
  }
}

/* =====================  Яркая плашка хода  ===================== */

.turn-banner {
  position: relative;
  z-index: 8;
  padding: 6px 18px;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.07em;
  border-radius: 999px;
  text-shadow: none;
}

.turn-banner.play {
  background: linear-gradient(180deg, #ffe27a, #ffc73d);
  color: #241a05;
  box-shadow: 0 0 0 2px #fff6cf, 0 8px 26px #00000088, 0 0 22px #ffd54a55;
}

.turn-banner.bid {
  background: linear-gradient(180deg, #a9e2ff, #6cc3f5);
  color: #06202e;
  box-shadow: 0 0 0 2px #e8f7ff, 0 8px 26px #00000088, 0 0 22px #6cc3f566;
}

/* =====================  Стабильная высота экрана на мобильном  ===================== */

@media (max-width: 700px) {
  /* svh не меняется при скрытии адресной строки — экран не скачет */
  .felt {
    height: calc(100vh - 170px);
    height: calc(100svh - 170px);
    min-height: 360px;
    max-height: calc(100vh - 170px);
    max-height: calc(100svh - 170px);
  }

  /* шапка и панель фиксированной высоты: кнопки не двигают стол */
  .status {
    min-height: 86px;
  }

  .panel:not(.panel-inline) {
    min-height: 92px;
  }

  /* рука не меняет высоту при уменьшении числа карт */
  .seat-self .hand {
    min-height: 132px;
  }
}

/* =====================  Компактный режим: экран без прокрутки  ===================== */

@media (max-width: 700px) {
  body.compact {
    overflow: hidden;
  }

  body.compact .shell {
    height: 100svh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  body.compact #app {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 6px 8px 104px;
    overflow: hidden;
  }

  body.compact .status {
    min-height: 0;
    flex: 0 0 auto;
  }

  body.compact .felt {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    max-height: none;
  }

  /* в компактном режиме лишние блоки под столом не нужны */
  body.compact .auction-log,
  body.compact #app > p.muted {
    display: none;
  }

  /* чат — выезжающая панель поверх стола */
  body.compact .chat {
    display: none;
  }

  body.compact .chat.open {
    display: flex;
    position: fixed;
    inset: 10px;
    z-index: 80;
    width: auto;
    height: auto;
    max-height: none;
    margin: 0;
    box-shadow: 0 24px 60px #000c;
  }

  /* в обычном режиме крестик чата не нужен */
  .chat-close {
    display: none;
  }

  body.compact .chat-close {
    display: inline-flex;
    margin-left: auto;
    padding: 2px 8px;
    font-size: 12px;
  }

  body.compact .chat-head {
    display: flex;
    align-items: center;
    gap: 8px;
  }
}

/* =====================  Счётчик непрочитанных в кнопке «Чат»  ===================== */

.chat-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chat-badge {
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #e05a4f;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}

.chat-badge[hidden] {
  display: none;
}

/* =====================  Голосовые сообщения и реакции  ===================== */

.chat-mic {
  padding: 6px 10px;
  font-size: 15px;
  line-height: 1;
}

.chat-mic.recording {
  border-color: #e05a4f;
  background: #3a1f1e;
  color: #ffd0cc;
  animation: micPulse 1s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 1px #e05a4f66; }
  50% { box-shadow: 0 0 0 3px #e05a4f33; }
}

.chat-audio {
  width: 100%;
  max-width: 240px;
  height: 34px;
  margin-top: 2px;
}

/* реакции */

.reaction-sheet {
  max-width: 380px;
}

.reaction-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.reaction-btn {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel2);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.1s ease;
}

.reaction-btn:hover {
  transform: translateY(-2px) scale(1.05);
  border-color: var(--accent);
}

.reaction-bubble {
  position: fixed;
  z-index: 90;
  transform: translate(-50%, 0);
  font-size: 38px;
  line-height: 1;
  pointer-events: none;
  filter: drop-shadow(0 4px 10px #000a);
  animation: reactionFloat 2.6s ease-out forwards;
}

@keyframes reactionFloat {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -6px) scale(1.15); }
  30% { transform: translate(-50%, -10px) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(0.95); }
}

/* =====================  Telegram Mini App  ===================== */

/* внутри Telegram адресной строки нет — можно отдать больше места столу */
body.telegram {
  overscroll-behavior: none;
}

@media (max-width: 700px) {
  body.telegram .status {
    min-height: 0;
  }
}

/* =====================  Компактный режим: убираем наезды  ===================== */

@media (max-width: 700px) {
  /* веер верхнего игрока меньше — не залезает на боковых */
  body.compact .seat-top .fan {
    transform: scale(0.82);
    transform-origin: 50% 0;
  }

  body.compact .seat-left .fan,
  body.compact .seat-right .fan {
    transform: scale(0.9);
    transform-origin: 50% 0;
  }

  /* карты в руке мельче: 13 карт точно влезают в ширину */
  body.compact .hand .pcard,
  body.compact .seat-self .hand .pcard {
    width: 36px !important;
    max-width: 36px !important;
  }

  /* панель: учитываем нижний отступ телефона, чтобы кнопки не обрезались */
  body.compact .panel:not(.panel-inline) {
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }

  body.compact #app {
    padding-bottom: calc(112px + env(safe-area-inset-bottom, 0px));
  }

  /* верхний ряд стола не должен наезжать на средний */
  body.compact .seat-top {
    min-height: 118px;
  }

  /* строка «Имя · 0 / 500» держится отдельно от карт */
  body.compact .seat-self {
    gap: 4px;
  }
}

/* =====================  Компактный режим: стол целиком влезает  ===================== */

@media (max-width: 700px) {
  body.compact .felt {
    padding: 6px;
    gap: 2px;
  }

  /* центр и верх ужимаются — освобождают высоту под руку */
  body.compact .table-center {
    min-height: 124px;
    gap: 2px;
  }

  body.compact .seat-top {
    min-height: 84px;
  }

  body.compact .seat-self {
    gap: 2px;
  }

  body.compact .seat-self .hand {
    min-height: 0;
  }

  body.compact .hand .pcard,
  body.compact .seat-self .hand .pcard {
    width: 34px !important;
    max-width: 34px !important;
  }

  body.compact .hand .hand-group,
  body.compact .seat-self .hand .hand-group {
    padding: 2px 3px !important;
    gap: 2px !important;
  }

  body.compact .self-line {
    font-size: 11px;
    margin-top: 2px;
  }

  /* плашка контракта и подписи — компактнее */
  body.compact .contract-chip {
    padding: 2px 10px;
    font-size: 12px;
  }

  body.compact .trick-cross {
    transform: scale(0.72);
    transform-origin: 50% 50%;
    margin: 0 auto -18px;
  }
}

/* =====================  Компактный режим: розыгрыш тоже влезает  ===================== */

@media (max-width: 700px) {
  /* сам блок взятки получает фиксированную высоту: крест больше не растягивает центр */
  body.compact .trick {
    height: 118px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    overflow: visible;
  }

  body.compact .trick-cross {
    transform: scale(0.62);
    transform-origin: 50% 0;
    margin: 0;
  }

  body.compact .table-center {
    min-height: 0;
    justify-content: flex-start;
    padding-top: 0;
    gap: 1px;
  }

  body.compact .hand .pcard,
  body.compact .seat-self .hand .pcard {
    width: 32px !important;
    max-width: 32px !important;
  }

  body.compact .led-line,
  body.compact .turn-banner {
    font-size: 11px;
    padding: 3px 10px;
  }

  body.compact .seat-self {
    gap: 0;
  }
}

/* =====================  Компактная шапка  ===================== */

.status-main {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 700px) {
  .status-main {
    font-size: 11.5px;
  }

  /* карты в руке чуть крупнее — запас по высоте появился */
  body.compact .hand .pcard,
  body.compact .seat-self .hand .pcard {
    width: 34px !important;
    max-width: 34px !important;
  }
}

/* =====================  Красные масти в заявках  ===================== */

.suit-red {
  color: #e2564a;
  font-weight: 700;
}

.suit-black {
  color: inherit;
}

.bid-bubble .suit-red,
.contract-chip .suit-red,
.chip .suit-red,
.auction-log-list .suit-red {
  color: #ff6b5e;
}

/* =====================  Итог раздачи выше плашки хода  ===================== */

/* Плашка «ваш ход» / «ваша заявка» не должна наезжать на карточку итога. */
.hand-result {
  z-index: 30;
}

.turn-banner {
  z-index: 10;
}

/* =====================  Мобильный стол: меньше пустоты, крупнее карты  ===================== */

@media (max-width: 700px) {
  /* 1. Убираем служебные подписи у имён — они не несут информации в игре. */
  body.compact .seat-tag {
    display: none;
  }

  /* 2. Счёт — одной строкой: только пуля. */
  body.compact .score-badge {
    padding: 1px 8px;
    gap: 0;
  }

  body.compact .score-badge span {
    display: none;
  }

  body.compact .score-badge b {
    font-size: 14px;
  }

  /* 3. Верхний партнёр — тонкая полоса, веер меньше. */
  body.compact .seat-top {
    min-height: 0;
  }

  body.compact .seat-top .fan {
    transform: scale(0.55);
    transform-origin: top center;
    margin-bottom: -22px;
  }

  /* 4. Центр стола не растягивается: всё свободное место уходит руке. */
  body.compact .table-center {
    flex: 0 0 auto;
    gap: 2px;
  }

  body.compact .felt {
    justify-content: space-between;
  }

  /* 5. Карты в руке — крупнее. */
  body.compact .hand .pcard,
  body.compact .seat-self .hand .pcard {
    width: 44px !important;
    max-width: 44px !important;
  }

  body.compact .hand .hand-group,
  body.compact .seat-self .hand .hand-group {
    padding: 2px 4px !important;
    gap: 3px !important;
  }

  /* 6. Боковые соперники: карты-рубашки уже, чтобы не отнимали высоту. */
  body.compact .seat-left .fan,
  body.compact .seat-right .fan {
    transform: scale(0.9);
    transform-origin: top center;
  }
}

/* =====================  Мобильный стол: крупнее карты взятки  ===================== */

@media (max-width: 700px) {
  body.compact .trick {
    height: 156px;
  }

  body.compact .trick-cross {
    transform: scale(0.88);
    transform-origin: 50% 0;
  }

  /* подписи под взяткой — чуть заметнее */
  body.compact .led-line,
  body.compact .trick-result {
    font-size: 12px;
  }

  /* рука остаётся крупной: 44 px */
  body.compact .hand .pcard,
  body.compact .seat-self .hand .pcard {
    width: 44px !important;
    max-width: 44px !important;
  }
}
