:root {
  color-scheme: dark;
  --ink: #f6f4ec;
  --muted: #aeb8b3;
  --dark: #09120f;
  --panel: #101d18;
  --line: rgba(255, 255, 255, 0.12);
  --green: #21d07a;
  --green-dark: #0c7542;
  --yellow: #ffd33d;
  --red: #ff4b4b;
  --blue: #64a7ff;
  --card-width: 156px;
  --card-height: 219px;
}

.setup-modal {
  width: min(780px, calc(100% - 28px));
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 20px;
}

.setup-rules-link {
  margin-top: 10px;
  padding: 0;
  border: 0;
  color: var(--green);
  background: transparent;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: rgba(33, 208, 122, .45);
  text-underline-offset: 4px;
  cursor: pointer;
}

.setup-rules-link:hover {
  color: #7dffb5;
}

.setup-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, .035);
}

.setup-card h3 {
  margin-bottom: 8px;
}

.setup-card p {
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.45;
}

.player-count-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 4px;
}

.bot-count-button {
  display: grid;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  align-content: center;
  justify-items: center;
  gap: 2px;
  border-radius: 16px;
  line-height: 1;
}

.bot-count-button strong {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 900;
  letter-spacing: -.04em;
}

.bot-count-button span {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: .72;
}

.setup-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}

.setup-field input,
.setup-field select,
.online-join-row input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #0a1511;
  font: inherit;
}

.online-join-row,
.lobby-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  margin-top: 12px;
}

/* Кількість гравців — окремим рядком над `Create room`: у вузькій колонці
   випадний список поруч із кнопкою виглядав тісно. */
.online-create-row {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.online-join-row .button {
  flex: 1;
  white-space: nowrap;
}

/* Поле коду кімнати само по собі широке, тож кнопці лишається мало місця —
   даємо їй фіксовану частку, а полю дозволяємо стискатись. */
.online-join-row input {
  min-width: 0;
  flex: 1 1 auto;
}

.online-join-row .button {
  flex: 0 0 auto;
  padding: 0 16px;
}

.join-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: .72rem;
}

.join-divider::before,
.join-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.setup-error {
  min-height: 1.25em;
  margin: 10px 0 0;
  color: #ff8787 !important;
}

.lobby-modal {
  width: min(520px, calc(100% - 28px));
}

.room-code {
  padding: 4px 9px;
  border: 1px solid rgba(33, 208, 122, .45);
  border-radius: 8px;
  color: var(--green);
  background: rgba(33, 208, 122, .08);
  font-weight: 900;
  letter-spacing: .14em;
  cursor: pointer;
}

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

.online-players {
  display: grid;
  gap: 8px;
  margin: 18px 0;
}

.online-player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.035);
  font-weight: 800;
}

.online-player.offline {
  opacity: .5;
}

.online-player-seat {
  color: var(--muted);
  font-size: .72rem;
}

.lobby-actions {
  justify-content: flex-end;
}

@media (max-width: 680px) {
  .setup-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 14px;
  }

  .setup-modal {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  /* У стовпчик секції стають високими — тримаємо вікно в межах екрана:
     квадратні кнопки кількості гравців тут зайво високі. */
  .setup-card {
    padding: 14px;
  }

  .bot-count-button {
    aspect-ratio: 3 / 2;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 80% -10%, rgba(33, 208, 122, 0.17), transparent 32rem),
    var(--dark);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

.app {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar,
.controls,
.score-strip {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 6vw, 4.6rem);
  line-height: 0.8;
  letter-spacing: -0.07em;
}

/* Логотип заміняє текстовий заголовок. `h1` лишається заради семантики й
   читачів з екрана — текст у ньому просто став зображенням з alt. */
.wordmark {
  display: flex;
  line-height: 0;
}

.wordmark img {
  width: auto;
  height: clamp(30px, 6.4vw, 60px);
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.65rem);
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.topbar-actions,
.mode-switch,
.controls {
  display: flex;
  gap: 10px;
}

.mode-switch {
  align-items: center;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
}

.mode-switch > span {
  padding-left: 7px;
}

.mode-button {
  min-height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.mode-button.active {
  color: #06130d;
  background: var(--green);
}

.button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  transition: transform 150ms ease, opacity 150ms ease, background 150ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-2px);
}

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

.button-primary {
  color: #06130d;
  background: var(--green);
}

.button-ghost {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.button-dark {
  background: #26342e;
}

.score-strip {
  gap: 24px;
  margin-bottom: 14px;
  padding: 10px 14px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.score-strip strong {
  color: var(--ink);
}

/* Фінал партії — накриття на весь стіл. Перемога й поразка навмисно різні за
   характером: перемога вибухає назовні, поразка осідає всередину. Елементи
   зʼявляються по черзі, бо одночасна поява читається як статична картинка. */
/* 🔴 Вікно з турнірною таблицею вище за звичайне, і на невисокому столі його
   нижні рядки разом із кнопками просто зрізало. Тепер накриття скролить, а не
   ховає вміст, і картка ніколи не перевищує висоти столу. */
.winner-banner {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow-y: auto;
  background: radial-gradient(circle at 50% 42%, rgba(4, 12, 9, .55), rgba(4, 12, 9, .9));
  animation: winner-veil .4s ease both;
}

.winner-banner[hidden] {
  display: none;
}

.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.winner-card {
  position: relative;
  display: flex;
  width: min(360px, 100%);
  max-height: 100%;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 30px 26px 24px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 22px;
  background: linear-gradient(170deg, #13261e, #0a1511);
  box-shadow: 0 26px 70px rgba(0, 0, 0, .55);
  text-align: center;
}

.winner-mark {
  position: relative;
  display: grid;
  width: 74px;
  height: 74px;
  place-items: center;
  border-radius: 50%;
  font-size: 2.2rem;
  line-height: 1;
}

.winner-title {
  font-size: 1.75rem;
  font-weight: 900;
  letter-spacing: -.03em;
  line-height: 1.05;
}

.winner-detail {
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.45;
}

.winner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.winner-replay {
  min-height: 40px;
  padding: 0 22px;
  border-radius: 999px;
}

/* Другорядний вихід — «змінити налаштування». Тихіший за повтор, бо
   найчастіше хочеться просто зіграти ще раз тим самим складом. */
.winner-replay-secondary {
  border-color: rgba(255,255,255,.22);
  background: transparent !important;
  color: var(--ink) !important;
}

/* ── Перемога ─────────────────────────────────────────────────────────── */
.winner-banner.is-win .winner-card {
  border-color: rgba(33, 208, 122, .5);
  box-shadow: 0 26px 70px rgba(0, 0, 0, .55), 0 0 60px rgba(33, 208, 122, .18);
  animation: winner-pop .6s cubic-bezier(.16, 1.5, .4, 1) both;
}

.winner-banner.is-win .winner-mark {
  color: #06130d;
  background: var(--green);
  animation: mark-burst .7s cubic-bezier(.16, 1.6, .4, 1) .12s both, mark-breathe 2.4s ease-in-out 1s infinite;
}

/* Ударна хвиля з-під кубка */
.winner-banner.is-win .winner-mark::before,
.winner-banner.is-win .winner-mark::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--green);
  border-radius: 50%;
  animation: shockwave 1.9s cubic-bezier(.2, .7, .3, 1) infinite;
}

.winner-banner.is-win .winner-mark::after {
  animation-delay: .75s;
}

.winner-banner.is-win .winner-title {
  color: var(--green);
  animation: rise-in .5s cubic-bezier(.2, .9, .3, 1) .3s both;
}

.winner-banner.is-win .winner-detail {
  animation: rise-in .5s ease .44s both;
}

.winner-banner.is-win .winner-replay {
  color: #06130d;
  background: var(--green);
  animation: rise-in .5s ease .6s both;
}

/* ── Поразка ──────────────────────────────────────────────────────────── */
.winner-banner.is-loss .winner-card {
  border-color: rgba(255, 255, 255, .09);
  animation: loser-sink .85s cubic-bezier(.25, .6, .3, 1) both;
}

.winner-banner.is-loss .winner-mark {
  color: #9fb0a8;
  background: rgba(255, 255, 255, .06);
  animation: loser-drop .8s cubic-bezier(.3, .5, .4, 1) .1s both, loser-slump 3.2s ease-in-out 1s infinite;
}

.winner-banner.is-loss .winner-title {
  color: #c8d3ce;
  animation: fade-in .8s ease .35s both;
}

.winner-banner.is-loss .winner-detail {
  animation: fade-in .8s ease .5s both;
}

.winner-banner.is-loss .winner-replay {
  color: var(--ink);
  background: rgba(255, 255, 255, .1);
  animation: fade-in .8s ease .7s both;
}

@keyframes winner-veil {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes winner-pop {
  0% { opacity: 0; transform: scale(.6) translateY(40px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes mark-burst {
  0% { opacity: 0; transform: scale(0) rotate(-160deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

@keyframes mark-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

@keyframes shockwave {
  0% { opacity: .75; transform: scale(1); }
  100% { opacity: 0; transform: scale(2.6); }
}

@keyframes rise-in {
  0% { opacity: 0; transform: translateY(16px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@keyframes loser-sink {
  0% { opacity: 0; transform: translateY(-26px) scale(1.03); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes loser-drop {
  0% { opacity: 0; transform: translateY(-18px) scale(.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes loser-slump {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(5px) rotate(-5deg); }
}

/* Промені з-під картки — головне джерело відчуття свята. */
.winner-banner.is-win::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 150vmax;
  height: 150vmax;
  pointer-events: none;
  background: repeating-conic-gradient(
    from 0deg,
    rgba(33, 208, 122, .24) 0deg 11deg,
    transparent 11deg 30deg,
    rgba(255, 211, 61, .17) 30deg 41deg,
    transparent 41deg 60deg
  );
  -webkit-mask-image: radial-gradient(circle, #000 7%, rgba(0, 0, 0, .5) 24%, transparent 60%);
          mask-image: radial-gradient(circle, #000 7%, rgba(0, 0, 0, .5) 24%, transparent 60%);
  animation: rays-in .8s ease-out both, rays-spin 26s linear .5s infinite;
}

/* Спалах у момент перемоги */
.winner-banner.is-win::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 44%, rgba(255, 255, 255, .8), rgba(33, 208, 122, .3) 34%, transparent 64%);
  animation: flash .7s ease-out both;
}

@keyframes rays-in {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.35) rotate(0deg); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

@keyframes rays-spin {
  from { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  to { transform: translate(-50%, -50%) scale(1) rotate(360deg); }
}

@keyframes flash {
  0% { opacity: 0; }
  14% { opacity: 1; }
  100% { opacity: 0; }
}

/* Роздача: картки прилітають зверху по черзі, і поки летять — рука не клікається. */
.app.dealing .hand {
  pointer-events: none;
}

.app.dealing .hand .card {
  animation: deal-in .44s cubic-bezier(.18, .9, .28, 1) both;
  animation-delay: calc(var(--deal-i, 0) * 75ms);
}

.app.dealing .opponent {
  animation: opponent-in .5s ease both;
}

.app.dealing .opponent-left { animation-delay: .1s; }
.app.dealing .opponent-top { animation-delay: .2s; }
.app.dealing .opponent-right { animation-delay: .3s; }

@keyframes deal-in {
  0% { opacity: 0; transform: translate(30px, -300px) rotate(-16deg) scale(.55); }
  55% { opacity: 1; }
  100% { opacity: 1; transform: translate(0, 0) rotate(0deg) scale(1); }
}

/* Тільки прозорість: transform тут зайнятий позиціюванням панелей
   (translateX(-50%) для верхньої, translateY(-50%) для бічних). */
@keyframes opponent-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Режим зменшеного руху гасить настирливий і нескінченний рух, але не забирає
   святкування: одноразові появи лишаються, циклічні обертання зупиняються. */
@media (prefers-reduced-motion: reduce) {

  .winner-banner.is-win::before {
    animation: rays-in .8s ease-out both;
  }

  .winner-banner.is-win .winner-mark {
    animation: mark-burst .7s cubic-bezier(.16, 1.6, .4, 1) .12s both;
  }

  .winner-banner.is-win .winner-mark::before,
  .winner-banner.is-win .winner-mark::after,
  .winner-banner.is-loss .winner-mark {
    animation: none;
  }

  .app.dealing .hand .card,
  .app.dealing .opponent {
    animation-duration: .28s;
  }
}

.table {
  position: relative;
  min-height: 480px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  background:
    linear-gradient(90deg, transparent 49.8%, rgba(255,255,255,.11) 50%, transparent 50.2%),
    repeating-linear-gradient(90deg, #0e6b3f 0, #0e6b3f 72px, #0c6239 72px, #0c6239 144px);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.32);
}

.pitch-lines {
  position: absolute;
  inset: 22px;
  border: 2px solid rgba(255,255,255,.13);
  border-radius: 12px;
  pointer-events: none;
}

.pitch-lines::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 128px;
  height: 128px;
  border: 2px solid rgba(255,255,255,.13);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.opponent {
  position: absolute;
  z-index: 2;
  width: min(245px, 24vw);
  min-width: 150px;
  padding: 10px 13px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 14px;
  background: rgba(4, 18, 11, 0.72);
  backdrop-filter: blur(10px);
}

.opponent-top {
  top: 22px;
  left: 50%;
  transform: translateX(-50%);
}

.opponent-left {
  top: 50%;
  left: 22px;
  transform: translateY(-50%);
}

.opponent-right {
  top: 50%;
  right: 22px;
  transform: translateY(-50%);
}

/* Чий хід — видно по контуру, що дихає, а не по підпису «TURN»: підпис
   перекривав корисне поле панелі. */
.opponent.active {
  background: rgba(4, 30, 17, .94);
  outline: 4px solid rgba(125, 255, 181, .9);
  outline-offset: 4px;
  animation: opponent-active-pulse 1.25s ease-in-out infinite alternate;
}

@keyframes opponent-active-pulse {
  from {
    outline-color: rgba(125, 255, 181, .45);
    box-shadow: 0 0 12px rgba(33, 208, 122, .25);
  }
  to {
    outline-color: rgba(125, 255, 181, 1);
    box-shadow: 0 0 40px rgba(33, 208, 122, .65);
  }
}

.opponent-top.active {
  transform: translateX(-50%);
}

.game-finished .opponent:not(.winner),
.game-finished .center-zone,
.game-finished .match-log,
.game-finished .turn-banner,
.game-finished .player-zone:not(.winner) {
  opacity: .28;
  filter: saturate(.45);
  transition: opacity 220ms ease, filter 220ms ease;
}

.opponent.winner,
.player-zone.winner {
  border-color: var(--yellow);
  box-shadow:
    0 0 0 4px rgba(255, 211, 61, .3),
    0 18px 45px rgba(0, 0, 0, .35);
}

.winning-card {
  animation: winning-card-pulse 1.2s ease-in-out infinite alternate;
}

@keyframes winning-card-pulse {
  from {
    filter: brightness(1);
  }
  to {
    filter: brightness(1.22);
    box-shadow: 0 0 0 3px var(--yellow), 0 0 18px rgba(255, 211, 61, .75);
  }
}

.opponent-name {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 0.82rem;
  font-weight: 800;
}

.opponent-meta {
  display: grid;
  justify-items: end;
  color: var(--muted);
  font-size: .58rem;
  line-height: 1.05;
}

.opponent-meta strong {
  color: var(--green);
  font-size: .78rem;
}

.app.no-win-chance .win-chance {
  display: none;
}

/* Налаштування — прості перемикачі, тому й вигляд простий: чекбокс,
   назва, пояснення під нею. */
.setting-row {
  display: flex;
  align-items: start;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.035);
  cursor: pointer;
}

.setting-row input {
  width: 20px;
  height: 20px;
  margin: 2px 0 0;
  accent-color: var(--green);
  cursor: pointer;
}

.setting-row span {
  display: grid;
  gap: 3px;
}

.setting-row strong {
  font-size: .96rem;
}

.setting-row small {
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.4;
}

.settings-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: .76rem;
}

/* Кількість карт квадратиками — базовий вигляд руки суперника. Самі карти
   відкриває лише налаштування «Show opponents' cards», і лише на десктопі:
   на телефоні рука суперника не показується ніколи. */
.opponent-card-pips {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
}

.opponent-card-pips > span {
  width: 12px;
  height: 17px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 3px;
  background: repeating-linear-gradient(45deg, #14251e 0 3px, #1d392d 3px 6px);
}

.mini-cards {
  display: none;
  flex-wrap: wrap;
  gap: 4px;
}

.mini-card-open {
  position: relative;
  width: 31px;
  height: 43px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 5px;
  box-shadow: 0 3px 7px rgba(0,0,0,.22);
}

.mini-card-open .card-face {
  padding: 3px;
}

.mini-card-open .card-league {
  display: none;
}

/* Міні-картка відкритої руки бота — 31x43px. Позначки по кутах там не
   помістяться, а портрет перетворився б на кашу, тож лишається компактний
   центрований стек без фото. */
.mini-card-open .card-photo {
  display: none;
}

.mini-card-open .position-icon,
.mini-card-open .club-crest {
  position: static;
  width: auto;
  height: auto;
  margin: 2px auto 1px;
  text-shadow: none;
}

.mini-card-open .position-icon {
  font-size: .5rem;
  letter-spacing: .02em;
}

.mini-card-open .club-crest img {
  width: 17px;
  height: 17px;
  filter: none;
}

.mini-card-open .special-symbol {
  font-size: 1rem;
}

.mini-card-open.bot-card-playing {
  z-index: 3;
  animation: bot-card-playing 500ms ease-in-out infinite alternate;
}

@keyframes bot-card-playing {
  from {
    transform: translateY(0) scale(1);
    box-shadow: 0 3px 7px rgba(0,0,0,.22);
  }
  to {
    transform: translateY(-7px) scale(1.12);
    box-shadow: 0 0 0 3px var(--yellow), 0 0 22px rgba(255, 211, 61, .9);
  }
}

.center-zone {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  display: flex;
  gap: 22px;
  transform: translate(-50%, -50%);
}

.pile-block {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 7px;
}

.card {
  position: relative;
  width: var(--card-width);
  height: var(--card-height);
  flex: 0 0 auto;
  overflow: hidden;
  border: 0;
  border-radius: 14px;
  color: #0b1310;
  background: #f5f2e9;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22);
}

button.card {
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.card-back {
  display: grid;
  place-items: center;
  border: 5px solid #e8e2d4;
  color: var(--ink);
  font-size: 1.55rem;
  font-weight: 900;
  background:
    radial-gradient(circle at center, #182b23 0 22%, transparent 23%),
    repeating-linear-gradient(45deg, #14251e 0 8px, #1d392d 8px 16px);
}

.card-back::before {
  content: "S";
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid var(--green);
  border-radius: 50%;
  color: var(--green);
}

.card-back span {
  position: absolute;
  right: 8px;
  bottom: 6px;
  padding: 2px 6px;
  border-radius: 99px;
  color: #07130d;
  background: var(--green);
  font-size: .72rem;
}

.card-face {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 10px;
  border: 0;
  background: #f0eee7;
}

/* Портрет легенди лежить над кольором країни, але під позначками. Знебарвлення
   плюс soft-light зводять знімки різних епох в один тон, тож чорно-білий кадр
   70-х і сучасне HD-фото читаються як одна колода. */
.card-photo {
  position: absolute;
  inset: 0;
  background-position: center 8%;
  background-size: cover;
  opacity: .9;
  filter: grayscale(1) contrast(1.3) brightness(1.05);
  mix-blend-mode: soft-light;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to top, #000 30%, rgba(0, 0, 0, .45) 100%);
          mask-image: linear-gradient(to top, #000 30%, rgba(0, 0, 0, .45) 100%);
}

/* На світлих фонах soft-light майже нічого не дає — там множення. */
.card-country-eng .card-photo {
  opacity: .62;
  filter: grayscale(1) contrast(1.12);
  mix-blend-mode: multiply;
}

.card-country-ger .card-photo {
  opacity: .74;
  filter: grayscale(1) contrast(1.22);
  mix-blend-mode: multiply;
}

.card-league {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  color: #4b5752;
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* Позиція і клуб рознесені в протилежні кути, щоб центр картки лишався
   обличчю. Позиція — словом без плашки: на 88px слово читається впевненіше
   за піктограму, а рамка навколо нього змагалася б із гербом за увагу. */
.position-icon {
  position: absolute;
  z-index: 2;
  top: 7px;
  left: 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: calc(var(--card-width) * .125);
  font-weight: 800;
  letter-spacing: .05em;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}

.club-crest {
  position: absolute;
  z-index: 2;
  right: 8px;
  bottom: 7px;
  display: grid;
  width: calc(var(--card-width) * .31);
  height: calc(var(--card-width) * .31);
  place-items: center;
}

.club-crest img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, .4));
}

.card-club {
  overflow: hidden;
  margin-top: auto;
  font-size: .88rem;
  font-weight: 900;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-face.card-country-ita,
.card-face.card-country-esp,
.card-face.card-country-eng,
.card-face.card-country-ger {
  display: flex;
  flex-direction: column;
}

.card-country-ita {
  color: white;
  background: linear-gradient(145deg, #23945d, #11683e);
}

.card-country-ger {
  color: #17140b;
  background: linear-gradient(145deg, #ffd947, #e7ae13);
}

.card-country-esp {
  color: white;
  background: linear-gradient(145deg, #ef4b45, #b91f2b);
}

.card-country-eng {
  color: #18211d;
  background: #f4f1e9;
}

.card-country-ita .card-league,
.card-country-esp .card-league {
  color: rgba(255,255,255,.78);
}

.card-country-ger .card-league,
.card-country-eng .card-league {
  color: rgba(0,0,0,.58);
}

.card-special .card-face {
  display: grid;
  align-content: center;
  justify-items: center;
  border-top: 0;
  text-align: center;
}

.card-special .special-symbol {
  font-size: 2.4rem;
  font-weight: 1000;
}

/* Жовта й червона показують намальовану картку свого кольору: фон трохи
   глибший за саму картку, тож вона читається як предмет, а не як пляма.
   Розміри у відсотках, щоб однаково працювало і в руці, і в мініатюрі. */
.card-yellow .card-face {
  background: #d9a913;
}

.card-red .card-face {
  background: #bf2f2e;
}

.card-emblem {
  width: 36%;
  aspect-ratio: 2 / 3;
  border-radius: 11%;
  transform: rotate(-9deg);
  box-shadow:
    0 0 0 max(1px, .012em) rgba(0, 0, 0, .55),
    0 .06em .16em rgba(0, 0, 0, .35);
}

.card-yellow .card-emblem { background: var(--yellow); }
.card-red .card-emblem { background: var(--red); }

.card-joker .card-face {
  color: white;
  background: linear-gradient(150deg, #8b6bff, #2a1b4d 78%);
}

/* Банер унизу столу вимкнено: те саме речення тепер живе в хроніці (хто ходить)
   і в заголовку руки (що робити далі), а зі збільшеними картами він ще й ліг на
   скидання. Розмітку й запис у нього лишено — вмикається одним рядком. */
.turn-banner {
  display: none;
  position: absolute;
  bottom: 18px;
  left: 50%;
  z-index: 3;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 99px;
  color: white;
  background: rgba(2, 12, 7, .78);
  font-size: .8rem;
  font-weight: 800;
  text-align: center;
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
}

/* Хроніка партії. Постійне місце й на десктопі, і на телефоні: спливний тост,
   що був тут раніше, зникав швидше, ніж гравці встигали прочитати, хто походив. */
/* 🔴 Висота фіксована. Події різної довжини (з наслідком і без, в один рядок і
   у два), і без фіксації рядок стрибав угору-вниз на кожному ході, зсуваючи
   разом із собою руку. Текст, що не вліз, обрізається — не розсуває блок. */
.match-log {
  display: flex;
  align-items: stretch;
  gap: 10px;
  height: clamp(64px, 11vh, 84px);
  margin-top: 10px;
  padding: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 14px;
  background: rgba(2, 12, 7, .72);
}

.match-log-turn {
  display: grid;
  flex: 0 0 auto;
  place-content: center;
  width: 215px;
  padding: 7px 10px;
  overflow: hidden;
  border-radius: 9px;
  color: var(--ink);
  background: rgba(255,255,255,.08);
  font-size: .85rem;
  font-weight: 900;
  letter-spacing: .03em;
  line-height: 1.2;
  text-align: center;
  text-transform: uppercase;
}

/* Свій хід світиться, чужий — ні: це головна відповідь на питання «а мені
   зараз ходити?», і вона має читатись боковим зором. */
.match-log-turn.own-turn {
  color: #06170e;
  background: var(--green);
  box-shadow: 0 0 22px rgba(33, 208, 122, .45);
}

/* Найновіша подія — ліворуч і найбільша, старіші згасають праворуч. Рядок,
   а не стовпчик: під столом висота коштує дорого, ширина — ні. */
.match-log-list {
  display: flex;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.match-log-entry {
  display: grid;
  gap: 1px;
  align-content: center;
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 9px;
  border-left: 3px solid rgba(255,255,255,.14);
  border-radius: 0 8px 8px 0;
  background: rgba(255,255,255,.05);
  color: var(--muted);
  font-size: .74rem;
  line-height: 1.25;
}

.match-log-entry.latest {
  border-left-color: var(--green);
  flex: 1.5 1 0;
  background: rgba(33, 208, 122, .13);
  color: var(--ink);
  font-size: .84rem;
  animation: log-entry-in 320ms ease-out;
}

.match-log-entry:nth-child(3) {
  opacity: .62;
}

.match-log-move b {
  font-weight: 900;
}

/* Обидва рядки запису мають сталу висоту незалежно від тексту: рух — рівно два
   рядки, наслідок — рівно один, навіть коли його нема. Саме змінна кількість
   рядків і смикала хроніку вгору-вниз на кожному ході. */
.match-log-move {
  display: -webkit-box;
  min-height: 2.5em;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.match-log-effect {
  display: -webkit-box;
  min-height: 1.3em;
  overflow: hidden;
  color: var(--yellow);
  font-size: .92em;
  font-weight: 700;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.match-log-entry:not(.latest) .match-log-effect {
  color: rgba(255, 211, 61, .62);
}

.card-flash {
  animation: card-flash 620ms ease-out;
}

@keyframes log-entry-in {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: none; }
}

@keyframes card-flash {
  0% { transform: scale(.82) rotate(-3deg); filter: brightness(1.8); }
  60% { transform: scale(1.08) rotate(1deg); }
  100% { transform: scale(1); filter: brightness(1); }
}

.player-zone {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
}

.player-zone.active-turn {
  outline: 4px solid rgba(125, 255, 181, .85);
  outline-offset: 4px;
  box-shadow: 0 0 30px rgba(33, 208, 122, .16);
}

.hand {
  display: flex;
  /* Проміжок розрахований під клубну рамку: вона виступає на 5px з кожного
     боку, тож при меншому проміжку рамки сусідніх карток злипались. */
  gap: 14px;
  min-height: calc(var(--card-height) + 8px);
  padding: 4px 8px 8px;
  overflow-x: auto;
  scrollbar-color: #426453 transparent;
}

.hand .card {
  overflow: visible;
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.hand .card > .card-face {
  overflow: hidden;
  border-radius: inherit;
}

/* Рамка одноклубників. Товщина й підсвіт — щоб зв'язок читався одразу:
   тонка лінія на темному фоні втрачалась навіть у яскравому кольорі. */
.hand .card.club-grouped::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: -5px;
  padding: 3px;
  filter: drop-shadow(0 0 5px var(--group-ring));
  border-radius: inherit;
  background: var(--group-ring);
  pointer-events: none;
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.hand .card.connect-card::after {
  animation: connect-card-pulse 780ms ease-in-out infinite alternate;
}

@keyframes connect-card-pulse {
  from {
    inset: -5px;
    filter: brightness(.9);
  }
  to {
    inset: -11px;
    filter: brightness(1.45);
  }
}

/* Картки не підстрибують ні на наведення, ні на вибір: підйом вимагав
   ~30px запасу над рукою, а `.hand` зі скролом його ще й підрізав. Вибір
   і так видно по зеленій рамці та номеру в пакеті.
   🔴 `hover: hover` обов'язковий: на тачскріні :hover залипає на останній
   тапнутій картці, і вона лишалась із зеленим контуром без жодної причини. */
@media (hover: hover) {
  .hand .card:hover {
    box-shadow: 0 0 0 2px rgba(125, 255, 181, .7);
  }
}

.hand .card.unplayable {
  opacity: .48;
}

.hand .card.selected {
  box-shadow: 0 0 0 4px var(--green), 0 8px 18px rgba(0,0,0,.3);
}

.selection-order {
  position: absolute;
  top: 10px;
  right: 8px;
  z-index: 2;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: #05120b;
  background: var(--green);
  font-size: .72rem;
  font-weight: 900;
}

.controls {
  justify-content: space-between;
  flex-wrap: wrap;
}

.action-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-meta {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.win-chance {
  padding: 6px 10px;
  border: 1px solid rgba(33,208,122,.32);
  border-radius: 99px;
  color: var(--muted);
  background: rgba(33,208,122,.08);
  font-size: .76rem;
  font-weight: 700;
}

.win-chance strong {
  margin-left: 4px;
  color: var(--green);
}

.modal {
  width: min(760px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  padding: 26px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--ink);
  background: #101d18;
  box-shadow: 0 28px 80px rgba(0,0,0,.65);
}

.modal::backdrop {
  background: rgba(0, 0, 0, .75);
  backdrop-filter: blur(5px);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-size: 2rem;
  cursor: pointer;
}

.rules-modal {
  width: min(980px, calc(100% - 32px));
}

.rules-intro {
  max-width: 720px;
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.rules-guide {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.rule-section {
  display: grid;
  grid-template-columns: minmax(260px, .9fr) minmax(330px, 1.1fr);
  gap: 20px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255,255,255,.025);
}

.rule-copy {
  display: flex;
  gap: 13px;
  align-items: flex-start;
}

.rule-number {
  display: grid;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: #07130d;
  background: var(--green);
  font-weight: 900;
}

.rule-copy h3 {
  margin: 3px 0 8px;
  color: var(--green);
}

.rule-copy p,
.rule-copy li,
.rule-note {
  color: var(--muted);
  line-height: 1.5;
}

.rule-copy p {
  margin: 0 0 8px;
}

.rule-copy ul {
  margin: 8px 0 0;
  padding-left: 19px;
}

.rule-copy li + li {
  margin-top: 4px;
}

.rule-visual {
  display: flex;
  min-height: 154px;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 16px;
  border-radius: 14px;
  background: rgba(0,0,0,.2);
}

.rule-card {
  position: relative;
  display: flex;
  width: 88px;
  height: 124px;
  padding: 9px;
  flex: 0 0 88px;
  flex-direction: column;
  justify-content: space-between;
  overflow: visible;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: 12px;
  color: #07130d;
  box-shadow: 0 8px 18px rgba(0,0,0,.24);
}

.rule-card.country-ita,
.mini-rule-card.country-ita {
  background: #218e5d;
}

.rule-card.country-ger,
.mini-rule-card.country-ger {
  background: #ffd23f;
}

.rule-card.country-esp,
.mini-rule-card.country-esp {
  background: #e53c40;
}

.rule-card.country-eng,
.mini-rule-card.country-eng {
  background: #f4f1e9;
}

.rule-card-country {
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .08em;
}

/* Ілюстрації правил повторюють розкладку справжньої картки: позиція словом
   у лівому верхньому куті, портрет легенди по центру, герб — у правому
   нижньому. Тримати синхронно з .card-photo вище. */
.rule-card-photo {
  position: absolute;
  inset: 0;
  border-radius: 11px;
  background-position: center 8%;
  background-size: cover;
  opacity: .9;
  filter: grayscale(1) contrast(1.3) brightness(1.05);
  mix-blend-mode: soft-light;
  -webkit-mask-image: linear-gradient(to top, #000 30%, rgba(0, 0, 0, .45) 100%);
          mask-image: linear-gradient(to top, #000 30%, rgba(0, 0, 0, .45) 100%);
}

.rule-card-icon {
  position: relative;
  align-self: flex-start;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .69rem;
  font-weight: 800;
  letter-spacing: .05em;
  line-height: 1;
}

.rule-club-crest {
  position: relative;
  display: block;
  width: 30px;
  height: 30px;
  margin: auto 0 0 auto;
  object-fit: contain;
}

.rule-card strong {
  overflow: hidden;
  font-size: .78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.anatomy-labels {
  display: grid;
  height: 112px;
  align-content: space-between;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.match-example small {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  text-align: center;
  font-weight: 900;
}

.rule-arrow,
.rule-plus,
.link-chain {
  color: var(--green);
  font-size: 1.25rem;
  font-weight: 900;
}

.legal-options {
  display: flex;
  gap: 10px;
}

.legal-card {
  box-shadow: 0 0 0 3px var(--green), 0 8px 18px rgba(0,0,0,.24);
}

.club-ring-blue {
  box-shadow: 0 0 0 4px #3d7cff, 0 8px 18px rgba(0,0,0,.24);
}

.club-ring-red {
  box-shadow: 0 0 0 4px #ff4f72, 0 8px 18px rgba(0,0,0,.24);
}

.rule-card.special-joker,
.mini-rule-card.special-joker {
  color: white;
  background: linear-gradient(145deg, #6e48e8, #24103e);
}

.rule-card.special-yellow {
  background: #ffd23f;
}

.rule-card.special-red {
  color: white;
  background: #ff4c52;
}

.rule-card-joker {
  margin: auto;
  font-size: 2rem;
  font-weight: 900;
}

.link-example {
  position: relative;
}

.link-chain {
  padding: 6px 9px;
  border: 1px solid rgba(33,208,122,.45);
  border-radius: 99px;
  font-size: .75rem;
}

.skip-badge {
  width: 100%;
  color: var(--green);
  text-align: center;
  font-size: .78rem;
  font-weight: 900;
}

.turn-flow span {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  text-align: center;
  font-size: .8rem;
  font-weight: 800;
}

.winning-section {
  grid-template-columns: 1fr;
}

.winning-examples {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.winning-example {
  display: grid;
  min-height: 135px;
  gap: 8px;
  align-content: center;
  justify-items: center;
  padding: 12px;
  border-radius: 12px;
  color: var(--muted);
  background: rgba(0,0,0,.2);
  text-align: center;
  font-size: .72rem;
}

.winning-example > strong {
  color: var(--ink);
  font-size: .8rem;
}

.empty-hand-icon {
  display: grid;
  width: 48px;
  height: 62px;
  place-items: center;
  border: 2px dashed var(--green);
  border-radius: 9px;
  color: var(--green);
  font-size: 1.25rem;
  font-weight: 900;
}

.mini-combo {
  display: flex;
  gap: 3px;
}

.mini-rule-card {
  display: grid;
  width: 28px;
  height: 40px;
  place-items: center;
  border-radius: 5px;
  color: #07130d;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .5rem;
  font-weight: 800;
}

.rule-note {
  padding: 14px 16px;
  border: 1px solid rgba(33,208,122,.35);
  border-radius: 14px;
  background: rgba(33,208,122,.08);
}

.rule-note strong {
  color: var(--green);
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.rules-grid article {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.035);
}

.rules-grid h3 {
  margin-bottom: 7px;
  color: var(--green);
}

.rules-grid p,
.result-modal p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.result-modal {
  text-align: center;
}

.result-modal .button {
  margin-top: 24px;
}

.result-icon {
  margin-bottom: 10px;
  font-size: 4rem;
}

@media (max-width: 760px) {
  :root {
    --card-width: 132px;
    --card-height: 186px;
  }

  .app {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

  .topbar {
    align-items: flex-end;
    flex-wrap: wrap;
  }

  .mode-switch {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .topbar-actions {
    gap: 6px;
  }

  .button {
    min-height: 40px;
    padding: 0 13px;
    font-size: .82rem;
  }

  .table {
    min-height: 430px;
  }

  .opponent {
    min-width: 105px;
  }

  .opponent-left {
    top: 44%;
    left: 10px;
  }

  .opponent-right {
    top: 44%;
    right: 10px;
  }

  .center-zone {
    top: 61%;
    gap: 12px;
  }

  .player-zone {
    padding: 14px 10px;
  }

  .player-meta {
    justify-items: end;
  }

  .controls,
  .action-controls {
    align-items: stretch;
  }

  .controls {
    gap: 12px;
  }

  .action-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .position-icon,
  .club-crest {
    width: 42px;
    height: 42px;
  }

  .position-icon {
    margin: 4px auto 3px;
    border-radius: 13px;
    font-size: 1.35rem;
  }

  .club-crest {
    margin: auto auto 1px;
  }

  .club-crest img {
    width: 35px;
    height: 35px;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .rule-section {
    grid-template-columns: 1fr;
  }

  .winning-examples {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .topbar .eyebrow {
    display: none;
  }

  .score-strip {
    gap: 14px;
  }

  .opponent-top {
    top: 12px;
  }

  .mini-card:nth-child(n + 6) {
    display: none;
  }

  .rules-modal {
    width: calc(100% - 16px);
    padding: 18px 14px;
  }

  .rule-section {
    padding: 14px;
  }

  .rule-visual {
    padding: 13px 8px;
  }

  .legal-options {
    gap: 7px;
  }

  .winning-examples {
    grid-template-columns: 1fr;
  }
}

/* На десктопі вся партія вміщується у видиму висоту без прокрутки. */
/* 🔴 Поріг висоти — 560px, а не 680px. При 680 вікно заввишки, скажімо, 660px
   не діставало компактної розкладки й падало в базову: там найбільші картки й
   жодної підгонки під екран, тож кнопки під рукою йшли за межі вікна. */
@media (min-width: 900px) and (min-height: 560px) {
  :root {
    /* Картка тягнеться від висоти вікна й упирається в стелю +50%: у низькому
       вікні вона зменшується, замість того щоб виштовхнути кнопки за екран.
       Пропорція картки — 104:146, звідси множник .712. */
    --card-height: clamp(118px, 22vh, 177px);
    --card-width: calc(var(--card-height) * .712);
  }

  body {
    overflow: hidden;
  }

  .app {
    display: flex;
    flex-direction: column;
    height: 100svh;
    padding: 10px 0;
  }

  .topbar {
    margin-bottom: 7px;
  }

  .topbar .eyebrow {
    margin-bottom: 4px;
  }

  /* Заголовок теж міряється висотою вікна: у низькому вікні 3,4rem коштували
     рівно того рядка, якого бракувало кнопкам під рукою. */
  h1 {
    font-size: clamp(1.7rem, 4.4vh, 3.4rem);
  }

  .wordmark img {
    height: clamp(24px, 4.6vh, 46px);
  }

  .button {
    min-height: 36px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: .78rem;
  }

  .score-strip {
    min-height: 32px;
    margin-bottom: 7px;
    padding: 6px 12px;
  }

  /* Мінімум теж тягнеться від висоти вікна: фіксовані 340px на низькому екрані
     з'їдали рівно ту висоту, якої бракувало кнопкам під рукою. */
  .table {
    min-height: clamp(168px, 32vh, 520px);
    flex: 1 1 auto;
    border-radius: 18px;
  }

  /* Висота — по вмісту: панель із квадратиками низька, панель із відкритими
     картами вища, і жодна не має фіксованого запасу, який нема чим заповнити. */
  .opponent {
    width: min(320px, 28vw);
    min-width: 180px;
    padding: 8px 10px;
  }

  /* Відкриті руки — лише десктопний тренувальний режим. Карти лежать одним
     рядком зі скролом, а не в кілька рядів: у кілька рядів верхня панель
     доростала до колоди й накривала її. */
  .app.open-hands .mini-cards {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 3px;
    scrollbar-width: thin;
  }

  .app.open-hands .mini-card-open {
    width: 36px;
    height: 50px;
    flex: 0 0 auto;
  }

  .app.open-hands .mini-card-open .position-icon,
  .app.open-hands .mini-card-open .club-crest {
    width: 23px;
    height: 23px;
  }

  .app.open-hands .mini-card-open .position-icon {
    font-size: .78rem;
  }

  .app.open-hands .mini-card-open .club-crest img {
    width: 19px;
    height: 19px;
  }

  /* Ціна тренувального режиму: три відкриті руки й колода повного розміру не
     вміщуються у 800px висоти разом, тож у ньому колода й скидання менші.
     У звичайній грі вони лишаються збільшеними. */
  .app.open-hands .center-zone .card {
    width: 100px;
    height: 140px;
  }

  .app.open-hands .opponent-card-pips {
    display: none;
  }

  .mini-card-open {
    width: 42px;
    height: 58px;
    border-radius: 7px;
  }

  .mini-card-open .position-icon,
  .mini-card-open .club-crest {
    width: 27px;
    height: 27px;
    margin: 1px auto;
  }

  .mini-card-open .position-icon {
    border-radius: 8px;
    font-size: .92rem;
  }

  .mini-card-open .club-crest img {
    width: 23px;
    height: 23px;
  }

  .mini-card-open .special-symbol {
    font-size: 1.35rem;
  }

  .center-zone {
    top: 64%;
    gap: 16px;
  }

  .position-icon,
  .club-crest {
    width: 40px;
    height: 40px;
  }

  .position-icon {
    margin: 3px auto 2px;
    border-radius: 12px;
    font-size: 1.3rem;
  }

  .club-crest {
    margin: auto auto 1px;
  }

  .club-crest img {
    width: 33px;
    height: 33px;
  }

  .player-zone {
    flex: 0 0 auto;
    margin-top: 7px;
    padding: 10px 12px;
    border-radius: 16px;
  }

  .hand {
    min-height: calc(var(--card-height) + 8px);
    padding: 3px 4px 8px;
  }

  .controls {
    margin-top: -2px;
  }

  .match-log {
    flex: 0 0 auto;
    margin-top: 7px;
    padding: 7px;
  }

  .match-log-turn {
    width: 168px;
    font-size: .84rem;
  }
}

/* Окреме компактне компонування лише для мобільних екранів. */
@media (max-width: 760px) {
  /* Як і на десктопі, картка тягнеться від висоти екрана й упирається в стелю
     +50%: на невисокому телефоні (або коли панелі браузера розгорнуті) фіксовані
     147px виштовхували руку й кнопки за межі екрана. */
  :root {
    --card-height: clamp(112px, 17.5vh, 147px);
    --card-width: calc(var(--card-height) * .712);
  }

  body {
    overflow: hidden;
  }

  /* Гра тримається в межах одного екрана: стіл розтягується, рука не скролить сторінку.
     100dvh, а не 100svh: сторінка не скролить, тож панелі браузера не ховаються
     і svh лишав би мертву смугу внизу.
     Відступи безпечної зони — обовʼязкові: у edge-to-edge браузері (Android 15,
     iOS з viewport-fit=cover) сторінка малюється під системним рядком, і кнопки
     топбару опиняються під годинником, де тап перехоплює система.
     🔴 `max(..., 26px)` — не перестраховка: браузер може малювати під системним
     рядком і при цьому віддавати `env(safe-area-inset-top)` = 0 (перевірено на
     живому телефоні). Тоді відступ лишався 8px і шапка ховалась під годинником,
     тож знизу мусить бути гарантований мінімум, а не лише значення від браузера. */
  .app {
    display: flex;
    flex-direction: column;
    width: calc(100% - 12px);
    height: 100dvh;
    min-height: 0;
    padding:
      calc(8px + max(env(safe-area-inset-top, 0px), 26px))
      env(safe-area-inset-right, 0px)
      calc(12px + env(safe-area-inset-bottom, 0px))
      env(safe-area-inset-left, 0px);
  }

  .topbar {
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 6px;
  }

  .topbar .eyebrow {
    display: none;
  }

  h1 {
    font-size: 2.2rem;
    line-height: .85;
  }

  .wordmark img {
    height: 30px;
  }

  .topbar-actions {
    margin-left: auto;
    gap: 4px;
  }

  .topbar-actions .button {
    min-height: 30px;
    padding: 0 7px;
    border-radius: 9px;
    font-size: .66rem;
    white-space: nowrap;
  }

  .score-strip {
    min-height: 28px;
    gap: 12px;
    margin-bottom: 6px;
    padding: 5px 9px;
    border-radius: 10px;
    font-size: .68rem;
  }

  .table {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 6px;
    height: auto;
    min-height: max(200px, 26vh);
    flex: 1 1 auto;
    padding: 10px;
    border-radius: 18px;
  }

  .pitch-lines {
    inset: 12px;
    border-width: 1px;
  }

  .pitch-lines::after {
    width: 86px;
    height: 86px;
    border-width: 1px;
  }

  /* Суперники — один рядок угорі столу, а не три плаваючі панелі:
     карток на мобільному не показуємо, тож центр столу лишається вільним. */
  .opponent {
    position: static;
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: 33%;
    height: auto;
    padding: 6px 8px;
    border-radius: 11px;
    transform: none;
  }

  .opponent-left { order: 1; }
  .opponent-top { order: 2; }
  .opponent-right { order: 3; }

  .opponent-top.active {
    transform: none;
  }

  .opponent.active {
    outline-width: 2px;
    outline-offset: 2px;
  }

  .opponent-name {
    align-items: center;
    margin-bottom: 0;
    font-size: .68rem;
    line-height: 1.05;
    white-space: nowrap;
  }

  .opponent-meta {
    display: block;
  }

  .opponent-meta strong {
    font-size: .68rem;
  }

  .opponent-meta > span {
    display: none;
  }

  .opponent-card-pips {
    display: flex;
    gap: 2px;
    width: 100%;
    margin-top: 7px;
  }

  .opponent-card-pips > span {
    width: 7px;
    min-width: 3px;
    max-width: 7px;
    height: 7px;
    flex: 1 1 7px;
    border: 1px solid rgba(255, 255, 255, .42);
    border-radius: 2px;
    background: rgba(33, 208, 122, .72);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  }

  .mini-cards {
    display: none;
  }

  /* 🔴 Не просто 52% висоти столу: на невисокому екрані стіл короткий, і
     половина стопки (~74px) залазила на рядок суперників угорі. `max()` тримає
     нижню межу — центр стопок ніколи не підіймається вище, ніж рядок панелей
     плюс зазор, — а на високому екрані 52% більші за неї, тож вигляд той самий. */
  .center-zone {
    top: max(52%, 138px);
    gap: 9px;
  }

  .pile-block {
    gap: 4px;
  }

  .card {
    border-radius: 10px;
  }

  .card-back {
    border-width: 4px;
    font-size: 1.1rem;
  }

  .card-back::before {
    width: 34px;
    height: 34px;
  }

  .card-face {
    padding: 6px;
  }

  .card-league {
    font-size: .42rem;
  }

  .position-icon,
  .club-crest {
    width: 26px;
    height: 26px;
  }

  .position-icon {
    margin: 2px auto 1px;
    border-radius: 8px;
    font-size: .82rem;
  }

  .club-crest {
    margin: auto auto 0;
  }

  .club-crest img {
    width: 22px;
    height: 22px;
  }

  .card-special .special-symbol {
    font-size: 1.6rem;
  }

  /* На телефоні рядок із трьох подій став би трьома нечитними стовпчиками:
     хроніка складається в стовпчик — хід зверху, під ним остання подія.
     Висота під рівно один запис, і вона стала: більше подій сюди не влізе,
     тож решту явно ховаємо, а не підрізаємо на півслові. */
  .match-log {
    height: 112px;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 5px;
    margin-top: 6px;
    padding: 7px;
    border-radius: 11px;
  }

  /* Висота плашки теж стала: статус ходу буває і в один рядок («YOUR TURN»),
     і у два («YOUR TURN · PLAY OR END TURN»), і без цього блок стрибав би. */
  .match-log-turn {
    width: auto;
    min-height: 34px;
    padding: 5px 8px;
    border-radius: 7px;
    font-size: .74rem;
  }

  .match-log-list {
    flex-direction: column;
    gap: 3px;
  }

  .match-log-entry {
    padding: 5px 8px 6px;
    font-size: .68rem;
  }

  .match-log-entry:not(.latest) {
    display: none;
  }

  .match-log-entry.latest {
    font-size: .72rem;
  }

  /* Наслідок події мав рівно 1.3em і сідав упритул до нижнього краю блоку —
     тут йому потрібен власний повітряний зазор. */
  .match-log-effect {
    min-height: 0;
    margin-top: 2px;
  }

  .player-zone {
    flex: 0 0 auto;
    margin-top: 6px;
    padding: 8px;
    border-radius: 15px;
  }

  .player-zone.active-turn {
    outline-width: 2px;
    outline-offset: 2px;
  }

  .player-meta {
    width: auto;
    margin-left: auto;
    justify-items: end;
  }

  .win-chance {
    padding: 4px 7px;
    font-size: .6rem;
  }

  /* Один ряд із горизонтальним скролом, як на десктопі: другий ряд карток унизу
     з'їдав висоту екрана, а рука все одно лишалась неповною. */
  .hand {
    display: flex;
    gap: 10px;
    min-height: 0;
    max-height: none;
    padding: 4px 7px 7px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  /* Вужча рамка: на телефоні картки стоять щільніше, і 5px з кожного боку
     з'їдали б проміжок разом із рамкою сусіда. */
  .hand .card.club-grouped::after {
    inset: -4px;
    padding: 3px;
  }

  .hand .card {
    width: var(--card-width);
    height: var(--card-height);
    flex: 0 0 auto;
  }

  .hand .card.selected {
    box-shadow: 0 0 0 3px var(--green), 0 8px 16px rgba(0,0,0,.3);
    transform: none;
  }

  .controls {
    display: grid;
    gap: 6px;
  }
  .action-controls {
    width: 100%;
  }

  .action-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .action-controls .button {
    min-height: 31px;
    padding: 2px 4px;
    border-radius: 8px;
    font-size: .58rem;
    line-height: 1.05;
  }

  /* Банер — оверлей на весь стіл (inset: 0), тож ширину й bottom тут не чіпаємо. */
  .winner-banner {
    gap: 7px;
    padding: 10px;
    font-size: .65rem;
  }

  .winner-replay {
    min-height: 27px;
    padding: 0 9px;
    font-size: .61rem;
  }

  .winner-actions {
    gap: 6px;
    margin-top: 6px;
  }
}

/* Малий телефон (або розгорнуті панелі браузера): найжорсткіші блоки —
   хроніка й мінімальна висота столу — тиснуться ще на 68px разом, інакше
   `overflow: hidden` на body просто зрізав би кнопки під рукою. Висота тут
   так само стала, просто менша. */
@media (max-width: 760px) and (max-height: 660px) {
  .match-log {
    height: 84px;
  }

  .match-log-move {
    min-height: 0;
    -webkit-line-clamp: 1;
  }

  .table {
    min-height: max(160px, 22vh);
  }
}

/* ── Турнір ─────────────────────────────────────────────────────────────── */

/* Заклик до турніру у вікні нової гри: головна дія блоку гри з ботами. */
.tournament-cta {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 60px;
  margin-bottom: 12px;
  padding: 10px 16px;
  text-align: center;
}
.tournament-cta strong { font-size: 1.02rem; letter-spacing: -.01em; }
.tournament-cta span { font-size: .72rem; font-weight: 700; letter-spacing: .05em; opacity: .72; }

.setup-or {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.game-counter {
  color: var(--green);
  font-weight: 800;
}

/* Таблиця в фінальному вікні партії. Ширина обмежена карткою переможця, тож
   назви місць короткі, а числа вирівняні по розряду. */
.tournament-panel {
  width: 100%;
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.14);
}

.tournament-panel-title {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.tournament-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
  font-variant-numeric: tabular-nums;
}

.tournament-table th {
  padding: 0 6px 6px;
  color: var(--muted);
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.tournament-table th:first-child,
.tournament-table td:first-child { text-align: left; width: 22px; }
.tournament-table th:nth-child(2),
.tournament-table td:nth-child(2) { text-align: left; }
.tournament-table th:nth-child(n+3),
.tournament-table td:nth-child(n+3) { text-align: right; width: 52px; }

.tournament-table td {
  padding: 5px 6px;
  border-top: 1px solid rgba(255,255,255,.08);
}

.tournament-table .t-place { color: var(--muted); font-weight: 800; }
.tournament-table .t-earned { color: var(--green); }
.tournament-table .t-total { font-weight: 900; }
.tournament-table .is-you td { color: var(--ink); }
.tournament-table tr:not(.is-you) td { color: var(--muted); }

/* Нічия — третій стан фіналу: без святкування й без жалю. */
.winner-banner.is-draw .winner-card {
  border-color: rgba(255,255,255,.2);
  animation: fade-in .5s ease both;
}
.winner-banner.is-draw .winner-mark { color: var(--muted); }
.winner-banner.is-draw .winner-replay {
  color: var(--ink);
  background: rgba(255, 255, 255, .1);
}

/* Очки турніру — чорний кружок перед іменем. Так вони не займають правого
   поля, де живе шанс на перемогу, і читаються однаково в усіх учасників. */
.opponent-id {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.pts-dot {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 99px;
  background: #05100b;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* Мій бейдж у рядку кнопок — той самий вигляд, що й у суперників. */
.controls-side {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: .8rem;
  font-weight: 800;
}

/* 🔴 Турнірне вікно несе ще й таблицю й у межах столу просто не вміщується:
   на невисокому екрані нижні рядки з кнопками опинялись за обрізаним краєм.
   Тому воно накриває весь екран, а не лише стіл, і святкова частина в ньому
   тісніша. `fixed` вириває його з `overflow: hidden` столу. */
.winner-banner.has-standings {
  position: fixed;
  padding: 16px;
}

.winner-banner.has-standings .winner-card {
  gap: 7px;
  padding: 18px 20px 16px;
}
.winner-banner.has-standings .winner-mark {
  width: 50px;
  height: 50px;
  font-size: 1.5rem;
}
.winner-banner.has-standings .winner-title { font-size: 1.3rem; }
.winner-banner.has-standings .winner-detail { font-size: .82rem; }

/* 🔴 Має стояти ПІСЛЯ `.opponent.active`, інакше однакова специфічність
   вирішується порядком у файлі й пульсація не гаситься. Гасимо циклічний рух,
   але контур лишаємо яскравим — це єдина позначка того, чий зараз хід (D-013). */
@media (prefers-reduced-motion: reduce) {
  .opponent.active {
    animation: none;
    outline-color: rgba(125, 255, 181, 1);
    box-shadow: 0 0 34px rgba(33, 208, 122, .55);
  }
}

/* Ілюстрації правил повторюють гру: жовта й червона з намальованою карткою,
   джокер — сама зірка. Тримати синхронно з `.card-emblem` вище. */
.rule-card.special-yellow { background: #d9a913; }
.rule-card.special-red { background: #bf2f2e; }
.rule-card.special-yellow,
.rule-card.special-red,
.rule-card.special-joker {
  display: grid;
  place-items: center;
}
.rule-card .card-emblem { display: block; }
.rule-card.special-yellow .card-emblem { background: var(--yellow); }
.rule-card.special-red .card-emblem { background: var(--red); }

/* Спалах кружка в момент, коли балів побільшало. */
.pts-dot.pts-bump {
  animation: pts-bump 900ms cubic-bezier(.25, 1.4, .45, 1) both;
}

@keyframes pts-bump {
  0% { transform: scale(1); background: #05100b; }
  22% { transform: scale(1.55); background: var(--green); color: #05100b; box-shadow: 0 0 16px rgba(33,208,122,.8); }
  55% { transform: scale(1.12); background: var(--green); color: #05100b; }
  100% { transform: scale(1); background: #05100b; }
}

@media (prefers-reduced-motion: reduce) {
  /* Рух гасимо, але сам факт зміни лишається помітним — коротке підсвічування. */
  .pts-dot.pts-bump {
    animation: pts-flash 900ms ease both;
  }
  @keyframes pts-flash {
    0%, 100% { background: #05100b; }
    30% { background: var(--green); color: #05100b; }
  }
}

.tournament-table .t-star {
  margin-left: 5px;
  color: var(--yellow);
  font-size: .8em;
}

/* Таблиця нарахування в екранних правилах. */
.rule-scoring {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}
.rule-scoring td {
  padding: 7px 4px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.rule-scoring tr:last-child td { border-bottom: 0; }
.rule-scoring-value {
  width: 42px;
  color: var(--green);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
}
.rule-scoring-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.5;
}
