:root {
  --felt: #0f5a3c;
  --felt-dark: #073323;
  --gold: #e8c26a;
  --gold-dark: #a8812f;
  --ink: #f3efe4;
  --muted: #a9c2b5;
  --panel: rgba(8, 28, 21, 0.86);
  --panel-border: rgba(232, 194, 106, 0.35);
  --red: #c4262e;
  --black: #1b1d22;
  --good: #6fdc8c;
  --bad: #ff7b7b;
  --cw: clamp(62px, 7.2vh, 92px);
  --ch: calc(var(--cw) * 1.42);
  font-family: "Segoe UI", "Sylfaen", "Noto Sans Georgian", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: #04140e;
  user-select: none;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 45%, #177a52 0%, var(--felt) 38%, var(--felt-dark) 78%, #031a11 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image: repeating-radial-gradient(circle at 30% 30%, rgba(255,255,255,0.05) 0 1px, transparent 1px 3px);
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 22px;
  background: linear-gradient(180deg, rgba(0,0,0,0.55), rgba(0,0,0,0.25));
  border-bottom: 1px solid var(--panel-border);
  z-index: 5;
}
.logo {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--gold);
  text-shadow: 0 2px 10px rgba(232,194,106,0.35);
}
.logo .crown { color: var(--red); margin-right: 6px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.chip b { color: var(--ink); }
.chip.contract { border-color: var(--gold-dark); color: var(--gold); }
.spacer { flex: 1; }
.btn {
  font: inherit;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.06);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:hover:not(:disabled) { background: rgba(232,194,106,0.16); border-color: var(--gold); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, #f1d38a, var(--gold-dark));
  color: #2a1d05;
  border-color: #f6dc9c;
  font-weight: 700;
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffe3a0, #b98f39); }
.btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- Layout ---------- */
.main { flex: 1; display: flex; min-height: 0; }
.table {
  position: relative;
  flex: 1;
  min-width: 0;
}
.sidebar {
  width: 310px;
  padding: 16px;
  background: rgba(0,0,0,0.32);
  border-left: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

/* ---------- Seats ---------- */
.seat {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 14px;
}
.seat.left { left: 24px; top: 46%; transform: translateY(-50%); flex-direction: column; }
.seat.right { right: 24px; top: 46%; transform: translateY(-50%); flex-direction: column; }
.seat.bottom { left: 50%; bottom: calc(var(--ch) + 40px); transform: translateX(-50%); }

.player-card {
  min-width: 170px;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: box-shadow 0.3s, border-color 0.3s;
}
.player-card.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(232,194,106,0.35), 0 0 28px rgba(232,194,106,0.45);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  50% { box-shadow: 0 0 0 4px rgba(232,194,106,0.15), 0 0 38px rgba(232,194,106,0.6); }
}
.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: 18px;
  color: #2a1d05;
  background: linear-gradient(135deg, #f6dc9c, var(--gold-dark));
  flex: none;
}
.avatar.p1 { background: linear-gradient(135deg, #9fd3ff, #3c7fb8); color: #061a2c; }
.avatar.p2 { background: linear-gradient(135deg, #ffb3c4, #b8456b); color: #2c0612; }
.pname { font-weight: 700; font-size: 15px; }
.pmeta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.pscore { margin-left: auto; text-align: right; }
.pscore .total { font-size: 20px; font-weight: 700; }
.pscore .deal { font-size: 12px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 6px;
  margin-left: 6px;
  background: rgba(232,194,106,0.18);
  color: var(--gold);
  vertical-align: 1px;
}

.backs { position: relative; width: calc(var(--cw) * 0.8); height: calc(var(--ch) * 1.25); }
.backs .card {
  position: absolute;
  left: 0;
  width: calc(var(--cw) * 0.8);
  height: calc(var(--ch) * 0.8);
}

/* ---------- Cards ---------- */
.card {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  border-radius: 9px;
  background: linear-gradient(160deg, #ffffff 0%, #f4f1ea 100%);
  box-shadow: 0 2px 4px rgba(0,0,0,0.35), 0 6px 14px rgba(0,0,0,0.25);
  color: var(--black);
  flex: none;
}
.card.red { color: var(--red); }
.card .corner {
  position: absolute;
  display: flex; flex-direction: column; align-items: center;
  line-height: 1;
  font-weight: 700;
  font-size: calc(var(--cw) * 0.21);
}
.card .corner small { font-size: calc(var(--cw) * 0.19); margin-top: 1px; }
.card .tl { top: 6px; left: 6px; }
.card .br { bottom: 6px; right: 6px; transform: rotate(180deg); }
.card .pip {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: calc(var(--cw) * 0.5);
}
.card .face {
  position: absolute;
  inset: 18% 16%;
  border-radius: 6px;
  border: 1.5px solid currentColor;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: linear-gradient(160deg, rgba(232,194,106,0.25), rgba(232,194,106,0.05));
}
.card .face .letter { font-size: calc(var(--cw) * 0.42); font-weight: 800; font-family: Georgia, serif; line-height: 1; }
.card .face .fs { font-size: calc(var(--cw) * 0.22); }
.card.back {
  background:
    repeating-linear-gradient(45deg, rgba(232,194,106,0.25) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(-45deg, rgba(232,194,106,0.25) 0 2px, transparent 2px 9px),
    linear-gradient(160deg, #7a1420, #3e0810);
  border: 3px solid #f4efe3;
}

/* ---------- Hand ---------- */
.hand {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  padding: 0 20px;
}
.hand .card {
  margin-left: calc(var(--cw) * -0.28);
  transition: transform 0.18s ease, box-shadow 0.18s, filter 0.18s, opacity 0.18s;
  transform-origin: 50% 120%;
}
.hand .card:first-child { margin-left: 0; }
.hand .card.playable { cursor: pointer; }
.hand .card.playable:hover { transform: translateY(-22px); box-shadow: 0 0 0 3px var(--gold), 0 14px 26px rgba(0,0,0,0.45); }
.hand .card.dim { filter: brightness(0.55) saturate(0.6); }
.hand .card.fresh::after {
  content: "★";
  position: absolute; top: -10px; right: -6px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 12px;
  background: var(--gold); color: #2a1d05;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.hand .card.selected { transform: translateY(-30px); box-shadow: 0 0 0 3px var(--bad), 0 14px 26px rgba(0,0,0,0.5); }
.hand .card.deal-in { animation: dealIn 0.4s ease-out backwards; }
@keyframes dealIn { from { opacity: 0; transform: translateY(-160px) scale(0.6); } }

/* ---------- Trick ---------- */
.trick {
  position: absolute;
  left: 50%; top: 44%;
  width: 0; height: 0;
}
.trick .card { position: absolute; transition: transform 0.45s ease-in, opacity 0.45s ease-in; }
.trick .s0 { left: calc(var(--cw) * -0.5); top: calc(var(--ch) * -0.1); animation: inBottom 0.32s ease-out; }
.trick .s1 { left: calc(var(--cw) * -1.45); top: calc(var(--ch) * -0.72); transform: rotate(-9deg); animation: inLeft 0.32s ease-out; }
.trick .s2 { left: calc(var(--cw) * 0.45); top: calc(var(--ch) * -0.72); transform: rotate(9deg); animation: inRight 0.32s ease-out; }
@keyframes inBottom { from { transform: translateY(240px) scale(0.8); opacity: 0.2; } }
@keyframes inLeft { from { transform: translateX(-360px) rotate(-30deg); opacity: 0.2; } }
@keyframes inRight { from { transform: translateX(360px) rotate(30deg); opacity: 0.2; } }
.trick.sweep-0 .card { transform: translateY(330px) scale(0.5); opacity: 0; }
.trick.sweep-1 .card { transform: translateX(-480px) scale(0.5); opacity: 0; }
.trick.sweep-2 .card { transform: translateX(480px) scale(0.5); opacity: 0; }

.trick-label {
  position: absolute;
  left: 50%; top: calc(44% + var(--ch) * 1.05);
  transform: translateX(-50%);
  font-size: 15px;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(0,0,0,0.45);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}
.trick-label.show { opacity: 1; }

/* ---------- Message ---------- */
.message {
  position: absolute;
  top: 18px; left: 50%;
  transform: translateX(-50%);
  padding: 9px 22px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 16px;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

/* ---------- Panels (declare / exchange / modals) ---------- */
.panel {
  position: absolute;
  left: 50%; top: 40%;
  transform: translate(-50%, -50%);
  width: min(620px, 90%);
  padding: 22px 24px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--gold-dark);
  box-shadow: 0 20px 60px rgba(0,0,0,0.55);
  z-index: 10;
  animation: pop 0.25s ease-out;
}
@keyframes pop { from { transform: translate(-50%, -46%) scale(0.95); opacity: 0; } }
.panel h2 { margin: 0 0 4px; color: var(--gold); font-size: 22px; }
.panel p { margin: 0 0 16px; color: var(--muted); }
.contracts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.contract-btn {
  font: inherit;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.14);
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.contract-btn:hover:not(:disabled) { border-color: var(--gold); background: rgba(232,194,106,0.12); transform: translateY(-2px); }
.contract-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.contract-btn .cn { font-size: 17px; font-weight: 700; display: block; }
.contract-btn .cd { font-size: 12.5px; color: var(--muted); }
.contract-btn.plus .cn { color: var(--good); }
.suits { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.suit-btn {
  font-size: 40px;
  width: 78px; height: 78px;
  border-radius: 14px;
  cursor: pointer;
  background: #f7f3ea;
  border: 3px solid transparent;
  transition: transform 0.12s, border-color 0.12s;
  line-height: 1;
}
.suit-btn:hover { transform: translateY(-3px); border-color: var(--gold); }
.suit-btn.red { color: var(--red); }
.suit-btn.black { color: var(--black); }
.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; align-items: center; }

.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  z-index: 20;
  display: grid; place-items: center;
}
.modal {
  width: min(640px, 92vw);
  max-height: 86vh;
  overflow: auto;
  padding: 24px 28px;
  border-radius: 18px;
  background: #0b2a1f;
  border: 1px solid var(--gold-dark);
  box-shadow: 0 24px 70px rgba(0,0,0,0.6);
  animation: pop2 0.25s ease-out;
}
@keyframes pop2 { from { transform: scale(0.95); opacity: 0; } }
.modal h2 { margin-top: 0; color: var(--gold); }
.modal table { width: 100%; border-collapse: collapse; margin: 8px 0 4px; }
.modal td, .modal th { padding: 7px 8px; border-bottom: 1px solid rgba(255,255,255,0.08); text-align: left; }
.modal th { color: var(--muted); font-weight: 600; font-size: 13px; }
.modal ul { padding-left: 20px; line-height: 1.6; }
.ranking { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.rank-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px; border-radius: 12px;
  background: rgba(255,255,255,0.05);
  font-size: 18px;
}
.rank-row.first { background: linear-gradient(90deg, rgba(232,194,106,0.3), rgba(232,194,106,0.06)); border: 1px solid var(--gold-dark); }
.rank-row .medal { font-size: 28px; }
.rank-row .score { margin-left: auto; font-weight: 700; }

/* ---------- Sidebar ---------- */
.sidebar h3 { margin: 0; font-size: 14px; letter-spacing: 1px; text-transform: uppercase; color: var(--gold); }
.board { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.board th, .board td { padding: 6px 4px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.07); }
.board th:first-child, .board td:first-child { text-align: left; color: var(--muted); }
.board .used { color: var(--gold); }
.board .free { color: rgba(255,255,255,0.25); }
.board .totals td { font-size: 17px; font-weight: 700; border-bottom: none; padding-top: 10px; }
.history { flex: 1; overflow: auto; display: flex; flex-direction: column-reverse; gap: 6px; padding-right: 4px; }
.hist {
  font-size: 12.5px;
  padding: 7px 9px;
  border-radius: 9px;
  background: rgba(255,255,255,0.04);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
}
.hist .pts { grid-column: 1 / -1; color: var(--muted); }
.history::-webkit-scrollbar { width: 6px; }
.history::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
