/* Покерний стіл — оформлення під iPad */

:root {
  --cw: clamp(84px, 12.2vw, 158px);      /* ширина карти */
  --ch: calc(var(--cw) * 1.4);
  --gold: #e8c977;
  --gold-dim: #b99a4e;
  --ink: #0d2a1e;
  --panel: #12241c;
}

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

/* Атрибут hidden має вигравати в класів на кшталт .modal { display: flex }. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  color: #f4efe2;
  background: #1a120c;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ── стіл і сукно ─────────────────────────────────────── */

.table {
  height: 100%;
  padding: clamp(8px, 1.6vw, 22px);
  background:
    radial-gradient(circle at 50% 40%, #4a2f1c 0%, #2a1a0f 55%, #150d07 100%);
  padding-top: max(clamp(8px, 1.6vw, 22px), env(safe-area-inset-top));
  padding-bottom: max(clamp(8px, 1.6vw, 22px), env(safe-area-inset-bottom));
}

.felt {
  position: relative;
  height: 100%;
  border-radius: clamp(24px, 4vw, 56px);
  background:
    radial-gradient(ellipse at 50% 42%, #1f7a51 0%, #16603f 45%, #0e4128 78%, #0a3220 100%);
  box-shadow:
    inset 0 0 0 clamp(6px, 1vw, 12px) #6b4423,
    inset 0 0 0 clamp(8px, 1.2vw, 15px) #8a5a2f,
    inset 0 14px 60px rgba(0, 0, 0, .45),
    0 24px 60px rgba(0, 0, 0, .55);
  overflow: hidden;
}

/* Легка фактура сукна. */
.felt::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.018) 0 2px, transparent 2px 4px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.02) 0 2px, transparent 2px 4px);
  pointer-events: none;
}

/* ── екрани ──────────────────────────────────────────── */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(16px, 3vw, 40px);
}

body.phase-idle     .screen-idle,
body.phase-awaiting .screen-awaiting,
body.phase-playing  .screen-playing { display: flex; }

body.phase-idle .end-btn { display: none; }

/* ── кнопка START ────────────────────────────────────── */

.start-btn {
  position: relative;
  width: clamp(200px, 34vmin, 330px);
  height: clamp(200px, 34vmin, 330px);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .1em;
  color: #2b1c07;
  background: radial-gradient(circle at 35% 28%, #ffe9a8 0%, var(--gold) 45%, #c39b46 100%);
  box-shadow:
    0 0 0 clamp(6px, 1vw, 12px) rgba(232, 201, 119, .18),
    0 18px 40px rgba(0, 0, 0, .45),
    inset 0 -8px 22px rgba(120, 80, 10, .35),
    inset 0 6px 18px rgba(255, 255, 255, .5);
  animation: pulse 2.6s ease-in-out infinite;
  transition: transform .12s ease;
}
.start-btn:active { transform: scale(.96); }

.start-suit { font-size: clamp(38px, 7vmin, 68px); line-height: 1; opacity: .8; }
.start-word {
  font-size: clamp(30px, 6.2vmin, 58px);
  font-weight: 800;
  letter-spacing: .14em;
  text-indent: .14em;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 clamp(6px,1vw,12px) rgba(232,201,119,.18), 0 18px 40px rgba(0,0,0,.45), inset 0 -8px 22px rgba(120,80,10,.35), inset 0 6px 18px rgba(255,255,255,.5); }
  50%      { box-shadow: 0 0 0 clamp(14px,2.4vw,30px) rgba(232,201,119,.06), 0 18px 40px rgba(0,0,0,.45), inset 0 -8px 22px rgba(120,80,10,.35), inset 0 6px 18px rgba(255,255,255,.5); }
}

.idle-hint {
  margin-top: clamp(20px, 3.4vh, 42px);
  color: rgba(244, 239, 226, .55);
  font-size: clamp(13px, 1.8vw, 18px);
  letter-spacing: .06em;
}

/* ── панелі (форма, очікування) ──────────────────────── */

.panel {
  width: min(620px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: clamp(20px, 3.4vw, 38px);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(18, 36, 28, .96), rgba(9, 24, 18, .97));
  border: 1px solid rgba(232, 201, 119, .28);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .55);
  text-align: center;
}

.panel-title {
  margin: 0 0 .5em;
  font-size: clamp(21px, 3.2vw, 32px);
  font-weight: 700;
  letter-spacing: .01em;
}

.panel-note {
  margin: 1.2em 0 0;
  color: rgba(244, 239, 226, .5);
  font-size: clamp(12px, 1.7vw, 15px);
  line-height: 1.5;
}

.bot-link {
  display: inline-block;
  margin-bottom: 1.1em;
  padding: .5em 1.1em;
  border-radius: 999px;
  font-size: clamp(17px, 2.6vw, 26px);
  font-weight: 700;
  color: #0e2a1e;
  text-decoration: none;
  background: linear-gradient(180deg, #ffe9a8, var(--gold));
  box-shadow: 0 8px 22px rgba(0, 0, 0, .35);
}

/* ── список гравців ──────────────────────────────────── */

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

.roster li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: .62em .95em;
  border-radius: 14px;
  background: rgba(255, 255, 255, .05);
  border: 1px solid rgba(255, 255, 255, .07);
  font-size: clamp(15px, 2.1vw, 20px);
  transition: background .25s ease, border-color .25s ease;
}
.roster li.in {
  background: rgba(84, 214, 142, .14);
  border-color: rgba(84, 214, 142, .4);
}
.roster .mark { font-size: 1.1em; opacity: .85; }
.roster li.in .mark { opacity: 1; }

/* ── форма ніків ─────────────────────────────────────── */

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(4, 12, 8, .72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 20;
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.nick-list { display: grid; gap: 10px; margin-bottom: 12px; }

.nick-row { display: flex; align-items: center; gap: 8px; }

.nick-row input {
  flex: 1;
  padding: .7em .9em;
  font-size: clamp(16px, 2.2vw, 20px);
  font-family: inherit;
  color: #f4efe2;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 14px;
  outline: none;
  transition: border-color .18s ease, background .18s ease;
}
.nick-row input:focus {
  border-color: rgba(232, 201, 119, .65);
  background: rgba(255, 255, 255, .1);
}
.nick-row input::placeholder { color: rgba(244, 239, 226, .32); }

.nick-del {
  width: 2.2em;
  height: 2.2em;
  flex: none;
  border: none;
  border-radius: 12px;
  font-size: clamp(15px, 2vw, 18px);
  color: rgba(244, 239, 226, .55);
  background: rgba(255, 255, 255, .06);
  cursor: pointer;
}
.nick-del:active { background: rgba(255, 90, 90, .25); }

.form-error {
  margin: 4px 0 0;
  color: #ff9d9d;
  font-size: clamp(13px, 1.8vw, 16px);
}

.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

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

.primary-btn {
  padding: .72em 1.9em;
  font-family: inherit;
  font-size: clamp(16px, 2.2vw, 21px);
  font-weight: 700;
  color: #241804;
  background: linear-gradient(180deg, #ffe9a8, var(--gold));
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .4);
  transition: transform .12s ease, filter .12s ease;
}
.primary-btn:active { transform: translateY(1px) scale(.98); }
.primary-btn[disabled] { filter: grayscale(.5) brightness(.8); pointer-events: none; }

.ghost-btn {
  padding: .68em 1.5em;
  font-family: inherit;
  font-size: clamp(14px, 1.9vw, 18px);
  color: rgba(244, 239, 226, .78);
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 999px;
  cursor: pointer;
}
.ghost-btn:active { background: rgba(255, 255, 255, .13); }
.add-btn { width: 100%; }

.end-btn {
  position: absolute;
  top: clamp(12px, 2vw, 22px);
  right: clamp(12px, 2vw, 22px);
  z-index: 5;
  padding: .55em 1.15em;
  font-family: inherit;
  font-size: clamp(12px, 1.6vw, 15px);
  color: rgba(255, 226, 226, .8);
  background: rgba(120, 20, 20, .38);
  border: 1px solid rgba(255, 140, 140, .28);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.end-btn:active { background: rgba(160, 30, 30, .6); }
.end-btn.armed {
  color: #fff;
  background: rgba(190, 40, 40, .85);
  border-color: rgba(255, 180, 180, .6);
  animation: blink 1s ease-in-out infinite;
}

/* ── HUD ─────────────────────────────────────────────── */

.hud {
  position: absolute;
  top: clamp(12px, 2vw, 22px);
  left: clamp(16px, 2.4vw, 28px);
  display: flex;
  align-items: baseline;
  gap: .8em;
  font-size: clamp(13px, 1.8vw, 17px);
  color: rgba(244, 239, 226, .55);
  letter-spacing: .04em;
}
.hud-round b { color: var(--gold); font-size: 1.15em; }
.hud-stage { color: var(--gold-dim); }

/* ── колода і борд ───────────────────────────────────── */

.board-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 4vw, 56px);
  width: 100%;
}

.deck {
  position: relative;
  flex: none;
  width: var(--cw);
  height: var(--ch);
  cursor: pointer;
  transition: transform .16s ease;
}
.deck:active { transform: scale(.97); }
.deck.done { pointer-events: none; opacity: .45; }

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

.deck-card {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--cw) * .075);
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .45));
}
.deck-card.d3 { transform: translate(6px, 6px) rotate(2.2deg); }
.deck-card.d2 { transform: translate(3px, 3px) rotate(-1.4deg); }
.deck .d1 { animation: breathe 3.4s ease-in-out infinite; }

@keyframes breathe {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-5px); }
}

.deck-hint {
  position: absolute;
  left: 50%;
  bottom: calc(-1 * clamp(26px, 4vh, 42px));
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: clamp(12px, 1.6vw, 16px);
  color: rgba(244, 239, 226, .45);
  animation: blink 2.4s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: .35 } 50% { opacity: .9 } }

.board {
  display: flex;
  gap: clamp(8px, 1.4vw, 18px);
  min-height: var(--ch);
  align-items: center;
}

/* Карта борду: 3D-переворот із сорочки в лице.
   Три рівні навмисно: .card тримає перспективу, .card-fly — приліт від колоди,
   .card-inner — сам переворот. Якби приліт анімував .card, його transform
   сплющив би 3D-контекст і задня грань перестала б ховатися. */
.card {
  width: var(--cw);
  height: var(--ch);
  perspective: 900px;
  flex: none;
}

.card-fly {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transform: rotateY(180deg);
  transition: transform .62s cubic-bezier(.3, .8, .3, 1);
}
.card.revealed .card-inner { transform: rotateY(0deg); }

/* Тінь тут навмисне box-shadow, а не filter: filter на грані вириває її
   з 3D-контексту, і переворот перестає працювати. */
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: calc(var(--cw) * .075);
  overflow: hidden;
  box-shadow: 0 12px 20px rgba(0, 0, 0, .45);
}
.card-face img { width: 100%; height: 100%; display: block; }
.card-back { transform: rotateY(180deg); }

/* Приліт карти від колоди. */
.card.dealing .card-fly {
  animation: deal .42s cubic-bezier(.2, .9, .3, 1) both;
  animation-delay: var(--delay, 0ms);
}
@keyframes deal {
  from { opacity: 0; transform: translateX(calc(-1 * var(--fly, 240px))) translateY(-8px) rotate(-9deg) scale(.9); }
  to   { opacity: 1; transform: none; }
}

.table-actions {
  position: absolute;
  bottom: clamp(22px, 5vh, 60px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
}
#newRoundBtn { animation: rise .32s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }

/* ── тост ────────────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 6vh;
  transform: translateX(-50%);
  z-index: 40;
  padding: .7em 1.3em;
  border-radius: 999px;
  font-size: clamp(13px, 1.8vw, 16px);
  color: #fff;
  background: rgba(20, 20, 20, .88);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
  animation: fade .2s ease;
}

/* Портретна орієнтація iPad: колода над бордом. */
@media (orientation: portrait) {
  /* Уся вулиця з п'яти карт має лишатися одним рядом. */
  :root { --cw: clamp(58px, 14vw, 122px); }
  .board-area { flex-direction: column; gap: clamp(22px, 5vh, 54px); }
  .board { gap: clamp(6px, 1.1vw, 12px); justify-content: center; max-width: 100%; }
  .deck-hint { bottom: calc(-1 * clamp(22px, 3.4vh, 34px)); }
}
