/* Дворовий бридж — оформлення. Без зовнішніх ресурсів. */

:root {
  --felt-1: #10402c;
  --felt-2: #072016;
  --gold: #e3b95c;
  --gold-dim: #a5883f;
  --ink: #f2ece0;
  --ink-dim: #a9b5ad;
  --card-bg: #fbf8f1;
  --card-ink: #1d2320;
  --red: #c62d2d;
  --panel: rgba(0, 0, 0, .28);
  --line: rgba(227, 185, 92, .22);
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .45);

  /* Розмір карти — одна точка правди для CSS і для layoutHand() у js/ui.js,
     який читає його через getComputedStyle. На вузьких екранах меншає. */
  --card-w: 78px;
  --card-h: 112px;
  --card-rank: 17px;
  --card-suit: 34px;

  /* Колода і скид у центрі столу живуть окремо від руки: на телефоні
     рука мусить меншати, а от стіл читатись має добре. */
  --pile-w: var(--card-w);
  --pile-h: var(--card-h);
  --pile-rank: var(--card-rank);
  --pile-suit: var(--card-suit);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 30%, var(--felt-1) 0%, var(--felt-2) 78%),
    var(--felt-2);
  overflow: hidden;
}

/* ─────────────── каркас ─────────────── */

.table {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* мобільні браузери: без стрибків через адресний рядок */
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, .22);
  flex: 0 0 auto;
}

.brand {
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--gold);
  font-size: 15px;
}

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

.chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid var(--line);
  color: var(--ink-dim);
  white-space: nowrap;
}

.chip-mult { font-weight: 700; color: var(--ink); }
.chip-mult.hot {
  color: #1a1207;
  background: var(--gold);
  border-color: var(--gold);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(227, 185, 92, .55); }
  50%      { box-shadow: 0 0 0 7px rgba(227, 185, 92, 0); }
}

.board {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 260px;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 14px 18px;
  min-height: 0;
}

.opponents {
  grid-column: 1;
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  align-content: flex-start;
}

.center {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
}

.sidebar {
  grid-column: 2;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* ─────────────── суперники ─────────────── */

.opponent {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 12px;
  min-width: 132px;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}

.opponent.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold), 0 0 22px rgba(227, 185, 92, .28);
  transform: translateY(-2px);
}

.opponent.skipped { opacity: .45; }

.opp-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.opp-name { font-weight: 600; font-size: 14px; }
.opp-score { font-size: 12px; color: var(--gold); font-variant-numeric: tabular-nums; }

.opp-cards { display: flex; height: 34px; }

.mini-card {
  width: 22px;
  height: 32px;
  border-radius: 4px;
  background: linear-gradient(140deg, #234c8a, #16305a);
  border: 1px solid rgba(255, 255, 255, .22);
  margin-left: -12px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .4);
}
.mini-card:first-child { margin-left: 0; }

.opp-count { font-size: 12px; color: var(--ink-dim); margin-left: 8px; align-self: center; }

/* ─────────────── центр столу ─────────────── */

/* Колода і скид — поруч по центру столу, текстовий статус над ними. */
.pile-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 34px;
}

.pile { text-align: center; }

.pile-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-dim);
  margin-bottom: 6px;
}

.discard-slot {
  width: var(--pile-w);
  height: var(--pile-h);
  border-radius: 10px;
  border: 1px dashed rgba(255, 255, 255, .16);
  position: relative;
}

.pile .card,
.fly-layer .card {
  width: var(--pile-w);
  height: var(--pile-h);
}
.pile .card-rank,
.fly-layer .card-rank { font-size: var(--pile-rank); }
.pile .card-suit-lg { font-size: var(--pile-suit); }

/* Обгортка тримає «розкид» карти у стосі, щоб анімація приземлення
   могла вільно користуватись transform самої карти. */
.pile-card {
  position: absolute;
  inset: 0;
}
.pile-card .card {
  width: 100%;
  height: 100%;
}

.status {
  text-align: center;
  min-width: 240px;
  padding: 0 12px;
  min-height: 42px;
}

.status-main { font-size: 17px; font-weight: 600; }
.status-sub { font-size: 13px; color: var(--ink-dim); margin-top: 4px; min-height: 18px; }
.status-main.warn { color: var(--gold); }

.suit-indicator {
  font-size: 26px;
  line-height: 1;
  min-height: 30px;
}

/* ─────────────── карти ─────────────── */

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--card-ink);
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 7px 8px;
  user-select: none;
  border: 1px solid rgba(0, 0, 0, .18);
}

.card.red { color: var(--red); }

.card-rank { font-size: var(--card-rank); font-weight: 700; line-height: 1; }
.card-suit-lg {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: var(--card-suit);
  opacity: .9;
  pointer-events: none;
}
.card-corner-b { align-self: flex-end; transform: rotate(180deg); }

.card-back {
  background:
    repeating-linear-gradient(45deg, #23508f 0 6px, #1a3d6e 6px 12px);
  border: 1px solid rgba(255, 255, 255, .25);
  color: #dce7f7;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.card.qs-mark::after {
  content: "50";
  position: absolute;
  right: 5px;
  bottom: 5px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
  border-radius: 999px;
  padding: 1px 5px;
}

/* ─────────────── анімації карт ─────────────── */

/* Шар, у якому летять карти при доборі з колоди */
.fly-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.fly-layer .card {
  position: absolute;
  margin: 0;
  transition: transform .68s cubic-bezier(.22, .61, .36, 1), opacity .68s ease-out;
}

/* Зіграна карта «прилітає» у скид з боку того, хто її поклав */
@keyframes card-land {
  from {
    transform: translate(var(--dx, 0px), var(--dy, 0px)) scale(.78) rotate(var(--rot, 0deg));
    opacity: .25;
  }
  to { transform: none; opacity: 1; }
}

.discard-slot .card.land {
  animation: card-land .58s cubic-bezier(.2, .7, .3, 1);
}

/* Нова карта на руці м'яко виїжджає знизу */
@keyframes hand-enter {
  from { transform: translateY(28px) scale(.9); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.hand .card.enter { animation: hand-enter .46s ease-out backwards; }

/* Колода реагує на те, що з неї взяли */
@keyframes deck-bump {
  0%, 100% { transform: none; }
  45%      { transform: translateY(-5px) scale(1.04); }
}

.card-back.bump { animation: deck-bump .44s ease-out; }

@media (prefers-reduced-motion: reduce) {
  .discard-slot .card.land,
  .hand .card.enter,
  .card-back.bump { animation: none; }
  .fly-layer { display: none; }
}

/* ─────────────── рука гравця ─────────────── */

.handbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px 16px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, .24);
  min-height: calc(var(--card-h) + 44px);
}

.hand-meta { width: 92px; flex: 0 0 auto; }
.you { display: block; font-weight: 700; color: var(--gold); }
.hand-points { font-size: 12px; color: var(--ink-dim); }

.hand {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  min-height: calc(var(--card-h) + 12px);
  padding-top: 14px;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Відступ між картами задає layoutHand() у js/ui.js: поки карти вміщаються —
   лежать із просвітом, і лише коли місця забракло, починають накладатись. */
.hand .card {
  cursor: default;
  transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
  flex: 0 0 auto;
}
.hand .card:first-child { margin-left: 0 !important; }

.hand .card.playable {
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--gold), var(--shadow);
}
@media (hover: hover) {
  .hand .card.playable:hover { transform: translateY(-16px); z-index: 5; }
}

.hand .card.dim { filter: brightness(.62) saturate(.7); }

.hand .card.selected {
  transform: translateY(-22px);
  box-shadow: 0 0 0 3px var(--gold), 0 14px 26px rgba(0, 0, 0, .5);
  z-index: 6;
}

.hand .card.shake { animation: shake .32s; }

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

.hand-actions { display: flex; flex-direction: column; gap: 8px; width: 132px; flex: 0 0 auto; }

/* ─────────────── бічна панель ─────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 0;
  flex: 0 0 auto; /* рахунок тримає свою висоту — інакше лог наїжджає на нього */
}

.panel h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--gold-dim);
  font-weight: 700;
}

.panel-log { flex: 1 1 0; min-height: 120px; display: flex; flex-direction: column; }

.log {
  flex: 1 1 auto;
  overflow-y: auto;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-dim);
}
.log div { padding: 2px 0; border-bottom: 1px solid rgba(255, 255, 255, .05); }
.log .lg-you { color: var(--ink); }
.log .lg-hot { color: var(--gold); }

/* Масті в тексті: червоні — червоним, чорні — світлим (на темному фоні) */
.lg-card { font-weight: 600; }
.lg-card.c-red,
.s-red { color: #ff7b7b; }
.lg-card.c-black,
.s-black { color: #e8eeea; }
.log .lg-dim { color: #7d8a83; font-size: 11.5px; }

.score-row { margin-bottom: 9px; }

.score-line {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 3px;
}
.score-line .sc-name.me { color: var(--gold); font-weight: 600; }
.score-line .sc-val { font-variant-numeric: tabular-nums; }

.bar {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5fb37a, var(--gold));
  transition: width .4s ease;
}
.bar > i.danger { background: linear-gradient(90deg, var(--gold), #d9534f); }

/* ─────────────── кнопки ─────────────── */

.btn {
  font: inherit;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .08);
  color: var(--ink);
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .15); border-color: var(--gold-dim); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .35; cursor: default; }

.btn-primary {
  background: linear-gradient(180deg, var(--gold), var(--gold-dim));
  border-color: var(--gold);
  color: #1a1207;
  font-weight: 700;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(180deg, var(--gold), var(--gold-dim)); }

.btn-ghost { background: transparent; font-size: 13px; padding: 7px 12px; }
.btn-big { width: 100%; padding: 13px; font-size: 16px; margin-top: 6px; }

/* «Правила» в меню — окремою дією, тому відділяємо від головної кнопки */
#btn-menu-rules { display: block; margin: 12px auto 0; }

/* ─────────────── модалки ─────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 12, 8, .78);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.overlay.show { display: flex; }

.modal {
  background: linear-gradient(180deg, #123a2a, #0a2318);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
  padding: 26px 28px;
  width: min(520px, 100%);
  max-height: 88vh;
  overflow-y: auto;
}

.modal h1 { margin: 0 0 6px; font-size: 30px; color: var(--gold); letter-spacing: .02em; }
.modal h2 { margin: 0 0 14px; font-size: 22px; color: var(--gold); }
.modal h3 { margin: 18px 0 6px; font-size: 14px; color: var(--gold-dim); }
.tagline { margin: 0 0 22px; color: var(--ink-dim); font-size: 14px; }

.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-dim);
  margin-bottom: 7px;
}

.segmented { display: flex; gap: 6px; flex-wrap: wrap; }

.seg {
  flex: 1 1 auto;
  min-width: 52px;
  padding: 9px 10px;
  text-align: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .05);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  transition: background .15s, border-color .15s;
}
.seg:hover { background: rgba(255, 255, 255, .12); }
.seg.on {
  background: var(--gold);
  border-color: var(--gold);
  color: #1a1207;
  font-weight: 700;
}

/* Вибір масті — компактна панель прямо над рукою, щоб не затуляла карти.
   Фон прозорий: стіл видно, але кліки повз панель не проходять. */
#overlay-suit {
  background: transparent;
  backdrop-filter: none;
  align-items: flex-end;
  padding: 0 0 calc(var(--card-h) + 56px);
  pointer-events: auto;
}

.modal-suit {
  width: auto;
  max-width: none;
  padding: 10px 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 12px 34px rgba(0, 0, 0, .6);
  animation: suit-pop .16s ease-out;
}

@keyframes suit-pop {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.suit-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  white-space: nowrap;
}

.suit-picker { display: flex; gap: 8px; }

.suit-btn {
  width: 46px;
  height: 46px;
  font-size: 26px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card-bg);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  line-height: 1;
}
.suit-btn:hover { transform: translateY(-3px); box-shadow: 0 0 0 2px var(--gold); }
.suit-btn.red { color: var(--red); }
.suit-btn.black { color: #14181a; }

/* підсумки */

.result-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.result-table th, .result-table td { padding: 7px 6px; text-align: left; }
.result-table th { font-size: 11px; text-transform: uppercase; color: var(--gold-dim); letter-spacing: .06em; }
.result-table tr + tr td { border-top: 1px solid rgba(255, 255, 255, .08); }
.result-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.result-table tr.win td { color: var(--gold); font-weight: 600; }
.result-table .cards-mini { color: var(--ink-dim); font-size: 12px; }
.note { font-size: 13px; color: var(--ink-dim); margin: 12px 0 0; }
.big-verdict { font-size: 17px; margin: 0 0 14px; }

.bridge-text { font-size: 14.5px; line-height: 1.6; color: #ddd8cc; margin: 0 0 10px; }
.bridge-hint { font-size: 13px; color: var(--ink-dim); margin: 0 0 16px; }
.modal-bridge .btn-big + .btn-big { margin-top: 8px; }

.rules-body { font-size: 14px; line-height: 1.6; color: #ddd8cc; }
.rules-body p { margin: 8px 0; }
.rules-table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13.5px; }
.rules-table td, .rules-table th { padding: 6px 8px; vertical-align: top; border-top: 1px solid rgba(255, 255, 255, .08); }
.rules-table .rk { width: 66px; font-weight: 700; color: var(--gold); white-space: nowrap; }
.rules-points { text-align: center; }
.rules-points th { color: var(--gold-dim); font-size: 12px; }
.modal-rules { width: min(660px, 100%); }

/* ─────────────── планшет ─────────────── */

@media (max-width: 1100px) and (min-width: 861px) {
  .board { grid-template-columns: 1fr 220px; }
}

/* ─────────────── телефон і вузькі екрани ─────────────── */

#btn-side { display: none; }
.mobile-only { display: none; }

/* Модалка «Рахунок і хід гри» лягає поверх підсумку роздачі,
   щоб його не доводилось закривати заради логу. */
.overlay-top { z-index: 55; }
/* Висота задана явно, а не «за вмістом» — інакше лог не має куди рости */
.modal-info {
  display: flex;
  flex-direction: column;
  height: min(86vh, 760px);
  max-height: 86vh;
}
#info-body { flex: 1 1 auto; min-height: 0; display: flex; }
#info-body .sidebar {
  display: flex;
  position: static;
  transform: none;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  overflow: visible;
}
#info-body .panel-log { flex: 1 1 auto; min-height: 140px; }

@media (max-width: 860px) {
  :root {
    --card-w: 54px;
    --card-h: 78px;
    --card-rank: 12px;
    --card-suit: 22px;
    /* стіл лишається великим і читабельним */
    --pile-w: 86px;
    --pile-h: 124px;
    --pile-rank: 19px;
    --pile-suit: 38px;
  }

  #btn-side { display: inline-block; }
  .mobile-only { display: block; }

  /* На місці панель не показуємо — вона живе в модалці */
  .board .sidebar { display: none; }

  /* Верхня смуга має лишатись одним рядком: назва гри й номер роздачі
     на телефоні не потрібні — номер усе одно видно в лозі. */
  .topbar { gap: 6px; padding: 7px 8px; flex-wrap: nowrap; }
  .brand { display: none; }
  #chip-round { display: none; }
  .chip { font-size: 11px; padding: 3px 7px; }
  .topbar-info { gap: 5px; }
  .topbar-actions { gap: 4px; }
  .btn-ghost { font-size: 12px; padding: 6px 7px; white-space: nowrap; }

  .board {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    padding: 8px 10px;
    gap: 8px;
  }

  /* Суперники — компактні плашки без «віяла» сорочок */
  .opponents { gap: 6px; }
  .opponent { min-width: 0; padding: 5px 8px; flex: 0 1 auto; }
  .opp-head { margin-bottom: 0; gap: 6px; }
  .opp-name { font-size: 12px; }
  .opp-score { font-size: 11px; }
  .mini-card { display: none; }
  .opp-cards { height: auto; }
  .opp-count { margin-left: 0; font-size: 11px; }

  .pile-row { gap: 12px; }
  .status { min-width: 0; padding: 0 4px; }
  .status-main { font-size: 14px; }
  .status-sub { font-size: 11.5px; }
  .suit-indicator { font-size: 22px; min-height: 24px; }
  .pile-label { font-size: 10px; }

  .panel-log { min-height: 220px; }

  /* Рука на всю ширину, кнопки — рядком під нею */
  .handbar {
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px 10px;
    min-height: 0;
  }
  .hand-meta {
    width: auto;
    order: 1;
    flex: 1 1 auto;
    display: flex;
    align-items: baseline;
    gap: 8px;
  }
  .you { display: inline; font-size: 13px; }
  .hand-points { font-size: 11px; }
  .hand {
    order: 3;
    flex: 1 0 100%;
    min-height: calc(var(--card-h) + 10px);
    padding-top: 10px;
    justify-content: flex-start;
  }
  .hand-actions {
    order: 2;
    flex-direction: row;
    width: auto;
    gap: 6px;
  }
  .hand-actions .btn { padding: 8px 14px; font-size: 13px; }

  /* Обрана карта підіймається менше — інакше вилазить за край */
  .hand .card.selected { transform: translateY(-12px); }

  /* Модалки */
  .overlay { padding: 12px; }
  .modal { padding: 18px 16px; border-radius: 14px; }
  .modal h1 { font-size: 22px; }
  .modal h2 { font-size: 18px; }
  .tagline { font-size: 13px; margin-bottom: 16px; }
  .seg { min-width: 44px; padding: 8px 6px; font-size: 13px; }
  .btn-big { padding: 12px; font-size: 15px; }
  .result-table { font-size: 12.5px; }
  .result-table th, .result-table td { padding: 5px 4px; }
  .rules-body { font-size: 13px; }
  .rules-table td, .rules-table th { padding: 5px 6px; font-size: 12.5px; }
  .rules-table .rk { width: 48px; }

  .suit-btn { width: 52px; height: 52px; font-size: 28px; }
  .suit-label { font-size: 13px; }
}

/* Дуже вузькі екрани — ще трохи менші карти */
@media (max-width: 370px) {
  :root {
    --card-w: 46px;
    --card-h: 67px;
    --card-rank: 11px;
    --card-suit: 18px;
    --pile-w: 74px;
    --pile-h: 106px;
    --pile-rank: 17px;
    --pile-suit: 32px;
  }
}
