:root {
  --bg: #1b2430;
  --wood: #3b4a5e;
  --paper: #f5f7fa;
  --paper2: #e1e7ef;
  --ink: #1b2430;
  --muted: #5b6878;
  --red: #c62828;
  --gold: #f2b134;
  --blue: #1f5fa8;
  --green: #2e7d32;
  --shadow: 0 2px 6px rgba(0, 0, 0, .35);
  --card-w: 96px;
  --card-h: 136px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'PT Sans', system-ui, sans-serif;
  color: var(--paper);
  background: radial-gradient(ellipse at top, #2f3f55 0%, var(--bg) 60%) fixed var(--bg);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
}
button {
  font: inherit; font-weight: 700; cursor: pointer; position: relative;
  border: 2px solid var(--ink); border-radius: 8px; padding: 8px 14px;
  background: var(--gold); color: var(--ink); box-shadow: var(--shadow);
  transition: transform .1s, filter .1s;
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { transform: translateY(1px) scale(.98); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: var(--paper2); }
button.danger { background: var(--red); color: var(--paper); }
button.small { padding: 4px 10px; font-size: 13px; }
input {
  font: inherit; font-size: 16px; padding: 9px 12px; border-radius: 8px; border: 2px solid var(--ink);
  background: var(--paper); color: var(--ink); min-width: 0;
}
.hidden { display: none !important; }
.hint { color: var(--muted); font-size: 14px; }
.grow { flex: 1; }

.logo { font-family: 'Russo One', sans-serif; color: #fff; text-shadow: 3px 3px 0 var(--blue), 5px 5px 0 #000; letter-spacing: 2px; }
.logo.hero { animation: swing 3s ease-in-out infinite; transform-origin: 50% 0; display: inline-block; width: 100%; }
@keyframes swing { 0%, 100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }

/* ───── меню и лобби ───── */
.screen { max-width: 520px; margin: 0 auto; padding: 32px 16px calc(32px + env(safe-area-inset-bottom)); }
.screen .logo { font-size: 72px; text-align: center; margin: 8px 0 4px; }
.subtitle { text-align: center; color: var(--paper2); margin-bottom: 28px; }
.panel {
  background: var(--paper); color: var(--ink); border-radius: 12px; padding: 18px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45); border: 3px solid var(--wood); margin-bottom: 16px;
}
.screen.enter .panel { animation: rise .35s ease-out both; }
.screen.enter .panel:nth-child(3) { animation-delay: .05s; } .screen.enter .panel:nth-child(4) { animation-delay: .1s; } .screen.enter .panel:nth-child(5) { animation-delay: .15s; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
.panel h2 { font-family: 'PT Serif', serif; margin: 0 0 12px; font-size: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; }
.code { font-family: 'Russo One', sans-serif; font-size: 40px; letter-spacing: 6px; color: var(--red); }
.members { list-style: none; padding: 0; margin: 12px 0; }
.members li {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px;
  background: var(--paper2); margin-bottom: 6px;
}
.badge { font-size: 12px; padding: 2px 7px; border-radius: 10px; background: var(--wood); color: var(--paper); white-space: nowrap; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); display: inline-block; }
.dot.off { background: #999; }

/* ───── игровой стол ───── */
.game {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto auto 1fr auto;
  gap: 10px; padding: 10px; min-height: 100vh;
  grid-template-areas: "top side" "opp side" "center side" "mine side";
}
.topbar { grid-area: top; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar .logo { font-size: 28px; }
.status { font-weight: 700; color: var(--paper); }
.status.mine-turn { color: var(--gold); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.icon-btn { line-height: 1.2; }
.unread { position: absolute; top: -7px; right: -7px; background: var(--red); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 5px; min-width: 18px; }
.mobile-only { display: none; }

.opponents { grid-area: opp; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.pl {
  background: var(--paper); color: var(--ink); border-radius: 10px; padding: 8px 10px; width: 190px;
  border: 3px solid var(--wood); box-shadow: var(--shadow); position: relative; cursor: pointer;
  transition: transform .15s, box-shadow .2s, border-color .2s, opacity .3s;
}
.pl.turn { border-color: var(--gold); animation: glow 1.6s ease-in-out infinite; }
@keyframes glow { 0%, 100% { box-shadow: 0 0 0 2px var(--gold), var(--shadow); } 50% { box-shadow: 0 0 0 4px var(--gold), 0 0 16px var(--gold); } }
.pl.dead { opacity: .5; filter: grayscale(.85); }
.dead-mark { position: absolute; right: 8px; bottom: 6px; font-size: 22px; }
.pl.targetable { border-color: var(--red); box-shadow: 0 0 0 3px var(--red), var(--shadow); animation: target 1s ease-in-out infinite; }
@keyframes target { 50% { transform: translateY(-3px); box-shadow: 0 0 0 3px var(--red), 0 0 18px var(--red); } }
.pl.untargetable { opacity: .55; }
.pl.attacker { box-shadow: 0 0 0 3px var(--red), 0 0 18px var(--red); }
.pl-top { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.pl-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role { font-size: 12px; white-space: nowrap; font-weight: 700; }
.role.sheriff { color: #9a6a00; } .role.deputy { color: var(--blue); } .role.bandit { color: var(--red); } .role.renegade { color: #6b3fa0; }
.pl-char { font-size: 13px; color: var(--muted); border-bottom: 1px dotted var(--muted); display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp { font-size: 15px; letter-spacing: 1px; margin: 3px 0; color: var(--red); }
.hp .lost { color: #c9b48d; }
.pl-meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.inplay { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 5px; }
.waiting-tag { position: absolute; top: -10px; right: 8px; background: var(--gold); color: var(--ink); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 8px; animation: pulse 1.2s ease-in-out infinite; white-space: nowrap; }
.offline-tag { background: #999; animation: none; }

.center {
  grid-area: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(ellipse, #8d6e52 0%, #6b5039 75%); border: 6px solid #2a3442; border-radius: 28px;
  padding: 16px; min-height: 220px;
}
.piles { display: flex; gap: 22px; align-items: center; }
.pile-label { font-size: 12px; text-align: center; margin-top: 4px; color: var(--paper2); }
.card-back {
  width: 78px; height: 112px; border-radius: 8px; flex-shrink: 0; position: relative;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .2 0 0 0 0 .08 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"), radial-gradient(ellipse at center, #2f74c0 0%, #1d5296 75%, #143c70 100%);
  box-shadow: inset 0 0 0 3px #dfe8f3, inset 0 0 0 5px #143c70, inset 0 0 0 7px #dfe8f3, var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Russo One', sans-serif; color: #fff; font-size: 18px; text-shadow: 1px 1px 0 #0c2240;
}
.card-back.small { width: 56px; height: 80px; font-size: 14px; }
.card-back.empty { opacity: .3; }
.card-back.pickable { cursor: pointer; transition: transform .12s; font-size: 22px; }
.card-back.pickable:hover { transform: translateY(-8px) rotate(-2deg); box-shadow: 0 0 0 3px var(--gold), var(--shadow); }
.ticker { font-size: 13px; color: var(--paper2); text-align: center; min-height: 18px; max-width: 560px; }
.ticker div:last-child { color: var(--paper); }
.prompt {
  background: var(--paper); color: var(--ink); border-radius: 10px; padding: 10px 16px; max-width: 640px; text-align: center;
  border: 3px solid var(--gold); box-shadow: var(--shadow); animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.92); opacity: 0; } }
.prompt.urgent { border-color: var(--red); animation: pop .25s ease-out, urgent 1s ease-in-out infinite .25s; }
@keyframes urgent { 50% { box-shadow: 0 0 0 3px rgba(179, 38, 30, .5), 0 0 18px rgba(179, 38, 30, .6); } }
.prompt-title { font-weight: 700; font-size: 16px; }
.prompt .row { justify-content: center; margin-top: 8px; }
.timer { font-size: 12px; color: var(--muted); }
.timer.low { color: var(--red); font-weight: 700; }
.store { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.waiting-line { color: var(--paper2); }
.prompt-mine { display: none; }

/* ───── мои карты ───── */
.mine { grid-area: mine; background: rgba(0, 0, 0, .25); border-radius: 12px; padding: 10px; }
.mine-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.mine-head .pl { width: auto; min-width: 230px; }
.me-info .hint { color: var(--paper2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; min-height: 4px; margin-top: 6px; }
.actions:empty { display: none; }
.hand { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; min-height: calc(var(--card-h) + 16px); padding-top: 14px; }
.hand .hint { color: var(--paper2); align-self: center; }

/* ───── карты: пергамент, двойная рамка, заголовок, гравюра ───── */
.card {
  --frame: #3b4a5e;
  width: var(--card-w); height: var(--card-h); border-radius: 7% / 5%; color: #1b2430; position: relative; flex-shrink: 0;
  font-size: calc(var(--card-w) * .125);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32 0 0 0 0 .2 0 0 0 0 .08 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"), linear-gradient(180deg, #ffffff 0%, #f1f4f8 70%, #e2e8f0 100%);
  box-shadow: inset 0 0 0 1px rgba(40, 60, 90, .3), var(--shadow);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; transition: transform .15s, box-shadow .15s, opacity .2s;
}
.card.blue { --frame: #1f5fa8; background: linear-gradient(180deg, #f4f8fd 0%, #e3edf9 100%); }
.c-frame {
  position: absolute; inset: 5.5% 6.5%; border-radius: 3px; display: flex; flex-direction: column; padding: 4% 5% 3%;
  border: max(1.5px, .13em) solid var(--frame);
  box-shadow: inset 0 0 0 max(1px, .08em) #fff, inset 0 0 0 max(2px, .15em) var(--frame);
}
.c-title {
  font-family: 'PT Sans Narrow', 'PT Sans', sans-serif; font-weight: 700; font-size: 1.12em; line-height: 1.05; text-align: center; white-space: nowrap;
  letter-spacing: .01em; color: #1b2430; margin-top: .1em;
}
.card.blue .c-title { color: #174a85; }
.c-title { text-transform: uppercase; }
.c-title.t-long { font-size: .92em; }
.c-title.t-xlong { font-size: .78em; }
.c-title.t-wrap { font-size: .72em; white-space: normal; line-height: 1; }
.c-art { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4% 0; }
.c-art svg, .c-art img { width: 100%; height: 100%; object-fit: contain; display: block; }
.art-img { width: 100%; height: 100%; background: center / cover no-repeat; mix-blend-mode: multiply;
  -webkit-mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 55%, transparent 100%);
  mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 55%, transparent 100%); }
.mini-art .art-img { -webkit-mask-image: none; mask-image: none; border-radius: 2px; }
.c-art img {
  mix-blend-mode: multiply; object-fit: cover;
  -webkit-mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 55%, transparent 100%);
  mask-image: radial-gradient(ellipse 72% 70% at 50% 50%, #000 55%, transparent 100%);
}
.c-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: .2em; }
.c-rank { font-family: 'PT Sans Narrow', sans-serif; font-weight: 700; font-size: 1.05em; line-height: .9; text-align: center; color: #1b2430; }
.c-rank i { display: block; font-style: normal; font-size: .95em; }
.c-rank.red { color: var(--red); }
.c-eff { font-family: 'PT Sans Narrow', sans-serif; font-size: .7em; line-height: 1.05; text-align: right; color: #3b4a5e; }
.card.blue .c-eff { color: #1f5fa8; }
.card.playable, .card.pickable { cursor: pointer; }
.card.playable { box-shadow: 0 0 0 2px var(--gold), var(--shadow); }
@media (hover: hover) {
  .card.playable:hover, .card.pickable:hover { transform: translateY(-8px); }
}
.card.dim { opacity: .5; }
.card.selected { transform: translateY(-14px) !important; box-shadow: 0 0 0 4px var(--red), 0 10px 16px rgba(0, 0, 0, .5); }
.card.deal { animation: deal 1s cubic-bezier(.3, .7, .4, 1.3) both; }
@keyframes deal { from { transform: translateY(-40px) scale(.6) rotate(-10deg); opacity: 0; } }
.card.mini {
  width: auto; height: auto; display: inline-flex; align-items: center; gap: 3px; padding: 1px 6px 1px 3px; font-size: 12px; border-radius: 6px;
  box-shadow: inset 0 0 0 1.5px var(--frame), var(--shadow);
}
.mini-art { width: 22px; height: 16px; display: inline-flex; }
.mini-art svg, .mini-art img { width: 100%; height: 100%; object-fit: contain; }
.card.mini .c-name { font-family: 'PT Sans Narrow', sans-serif; font-weight: 700; font-size: 12px; color: #1b2430; }
.card.blue.mini .c-name { color: #174a85; }

/* ───── журнал и чат ───── */
.side { grid-area: side; display: flex; flex-direction: column; gap: 10px; min-height: 0; max-height: calc(100vh - 20px); position: sticky; top: 10px; }
.side-tabs { display: none; }
.box { background: rgba(0, 0, 0, .3); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; min-height: 0; }
.box h3 { margin: 0 0 6px; font-size: 14px; color: var(--gold); font-family: 'PT Serif', serif; }
.log { flex: 1; overflow-y: auto; font-size: 13px; line-height: 1.35; }
.log div { padding: 2px 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.log .turnline { color: var(--gold); font-weight: 700; margin-top: 4px; }
.log-box { flex: 2; }
.chat-box { flex: 1; }
.chat { flex: 1; overflow-y: auto; font-size: 13px; }
.chat b { color: var(--gold); }
.chat-form { display: flex; gap: 6px; margin-top: 6px; }
.chat-form input { padding: 5px 8px; font-size: 16px; flex: 1; }

/* ───── модальные окна ───── */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; animation: fade .2s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal-body {
  background: var(--paper); color: var(--ink); border-radius: 12px; padding: 20px; max-width: 720px; width: 100%;
  max-height: 90vh; overflow-y: auto; border: 4px solid var(--wood); animation: pop .25s ease-out;
}
.modal-body h2 { font-family: 'PT Serif', serif; margin-top: 0; }
.modal-body h4 { margin: 12px 0 4px; }
.modal-body .cards { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 12px 0; }
.modal-body .cards.fan { gap: 0; }
.modal-body .cards.fan .card-back { margin: 0 -6px; }
.modal-body .cards.fan .card-back:nth-child(odd) { transform: rotate(-3deg); }
.modal-body .cards.fan .card-back:nth-child(even) { transform: rotate(3deg); }
.modal-body .cards.fan .card-back:hover { transform: translateY(-10px) rotate(0); z-index: 1; }
.pick-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; max-width: 150px; cursor: pointer; }
.card-text { font-size: 12px; color: var(--muted); text-align: center; }
.choice { border: 3px solid var(--wood); border-radius: 10px; padding: 12px; cursor: pointer; background: var(--paper2); flex: 1; min-width: 200px; transition: transform .15s, border-color .15s; }
.choice:hover { border-color: var(--red); transform: translateY(-3px); }
.choice h3 { margin: 0 0 4px; font-family: 'PT Serif', serif; }
.choices { display: flex; gap: 12px; flex-wrap: wrap; }
.rules h3 { margin-bottom: 4px; }
.rules p, .rules li { font-size: 14px; line-height: 1.45; }
.final { list-style: none; padding: 0; }
.final li { padding: 6px 0; border-bottom: 1px solid var(--paper2); }

.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); background: var(--red); color: #fff;
  padding: 10px 18px; border-radius: 10px; z-index: 60; box-shadow: var(--shadow); font-weight: 700; max-width: 90vw; text-align: center;
  animation: pop .2s ease-out;
}

/* ───── эффекты ───── */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.fx { position: fixed; }
.fx.fly .card, .fx.fly .card-back { box-shadow: 0 10px 22px rgba(0, 0, 0, .55); }
.fx.float { font-weight: 700; font-size: 22px; white-space: nowrap; text-shadow: 0 2px 0 #000, 0 0 8px #000; }
.fx.float.red { color: #ff5a4f; }
.fx.float.green { color: #7be36f; }
.fx.float.blue { color: #8fc7ff; font-family: 'PT Serif', serif; }
.fx.float.gold { color: var(--gold); }
.fx.float.big { font-size: 34px; }
.fx.float.huge { font-size: 64px; }
.fx.flash { border-radius: 10px; }
.fx.heal-ring { border-radius: 50%; border: 4px solid #7be36f; box-shadow: 0 0 24px #7be36f, inset 0 0 18px rgba(123, 227, 111, .6); }
.fx.heal-heart { font-size: 18px; filter: drop-shadow(0 0 4px rgba(0, 0, 0, .6)); }
.fx.flash.red { background: rgba(255, 40, 30, .55); box-shadow: 0 0 30px rgba(255, 40, 30, .8); }
.fx.flash.green { background: rgba(90, 220, 90, .4); box-shadow: 0 0 24px rgba(90, 220, 90, .7); }
.fx.burst {
  width: 150px; height: 110px; display: flex; align-items: center; justify-content: center;
  background: #ffd23f; color: var(--red); font-family: 'Russo One', sans-serif; font-size: 26px;
  clip-path: polygon(50% 0, 61% 26%, 92% 10%, 76% 40%, 100% 52%, 72% 62%, 86% 94%, 56% 74%, 44% 100%, 38% 72%, 8% 90%, 24% 60%, 0 46%, 28% 38%, 12% 8%, 40% 26%);
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, .6));
}
.fx.burst span { text-shadow: 2px 2px 0 #000; transform: rotate(-4deg); }
.fx.banner {
  left: 50%; top: 42%; font-family: 'Russo One', sans-serif; font-size: clamp(36px, 9vw, 72px); color: var(--gold);
  text-shadow: 3px 3px 0 var(--red), 6px 6px 0 #000; white-space: nowrap;
}
.fx.banner.lose { color: #cfcfcf; text-shadow: 3px 3px 0 #444, 6px 6px 0 #000; }
.fx.check { display: flex; flex-direction: column; align-items: center; gap: 4px; perspective: 600px; }
.check-label { background: var(--ink); color: var(--paper); font-weight: 700; font-size: 13px; padding: 2px 10px; border-radius: 8px; }
.check-mark { font-size: 28px; font-weight: 700; text-shadow: 0 2px 0 #000; }
.check-mark.ok { color: #7be36f; } .check-mark.bad { color: #ff5a4f; }

/* порядок хода и уровни ботов */
.seat {
  position: absolute; top: -10px; left: -10px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--wood); color: var(--paper); font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--paper); box-shadow: var(--shadow); z-index: 1;
}
.pl.turn .seat { background: var(--gold); color: var(--ink); }
.pl.next .seat { background: #3f9d36; }
.pl.next:not(.turn) { border-color: #3f9d36; }
.next-tag { background: #3f9d36; color: #fff; animation: none; }
.pl-sub { display: flex; align-items: center; gap: 5px; min-width: 0; }
.pl-sub .pl-char { min-width: 0; }
.lvl { flex-shrink: 0; font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 6px; vertical-align: middle; white-space: nowrap; }
.lvl-hard { background: #8d1c16; color: #fff; }
.lvl-medium { background: #c98a1c; color: #fff; }
.lvl-easy { background: #3f7d3a; color: #fff; }
.lvl-select { font: inherit; font-size: 14px; padding: 6px 8px; border-radius: 8px; border: 2px solid var(--ink); background: var(--paper); color: var(--ink); }
.members .lvl-select { font-size: 13px; padding: 3px 6px; }
.order { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: center; font-size: 13px; max-width: 100%; }
.o-item { background: rgba(0, 0, 0, .35); color: var(--paper2); padding: 2px 8px; border-radius: 10px; white-space: nowrap; border: 2px solid transparent; }
.o-item b { color: var(--gold); }
.o-item.me { color: #fff; }
.o-item.cur { background: var(--gold); color: var(--ink); }
.o-item.cur b { color: var(--ink); }
.o-item.next { border-color: #7be36f; }
.o-item.dead { opacity: .4; text-decoration: line-through; }
.o-arrow { color: var(--paper2); opacity: .6; font-size: 12px; }

/* описание карты и выбор карты для проверки */
.card-info-row { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.card-info-big { --card-w: 170px; --card-h: 241px; flex-shrink: 0; margin: 0 auto; }
.card-info-row > div:last-child { flex: 1; min-width: 200px; }
.card-info p { line-height: 1.45; }
.check-pick .cards.fan { gap: 14px; margin: 18px 0; }
.check-pick .card-back { width: 92px; height: 132px; font-size: 34px; margin: 0 !important; }
.check-pick .card-back.chosen { transform: translateY(-12px) !important; box-shadow: 0 0 0 4px var(--gold), 0 0 18px var(--gold); }
.actions-hint { align-self: center; color: var(--paper2) !important; }

/* ожидание ответа сервера и автоигра */
.card.leaving { opacity: .25; transform: translateY(-20px) scale(.9) !important; pointer-events: none; transition: all .2s; }
.game.busy .actions button, .game.busy .prompt button, .game.busy .pl.targetable { pointer-events: none; opacity: .6; }
.autopilot-bar {
  display: flex; align-items: center; gap: 10px; justify-content: space-between; flex-wrap: wrap;
  background: #2f5d8a; color: #fff; border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; box-shadow: var(--shadow);
}
.autopilot-bar button { background: var(--gold); }
.auto-tag { background: #2f5d8a; color: #fff; animation: none; }
.icon-btn.auto-on { background: #2f5d8a; color: #fff; }

/* новые карты в руке */
.card.fresh { box-shadow: 0 0 0 3px #7be36f, 0 0 16px rgba(123, 227, 111, .8), var(--shadow); animation: fresh-glow 1.2s ease-in-out infinite; }
.card.fresh.deal { animation: deal 1s cubic-bezier(.3, .7, .4, 1.3) both, fresh-glow 1.2s ease-in-out 1s infinite; }
.card.fresh::after {
  content: 'новая'; position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  background: #3f9d36; color: #fff; font-size: 10px; font-weight: 700; padding: 0 6px; border-radius: 8px; white-space: nowrap;
}
@keyframes fresh-glow { 50% { box-shadow: 0 0 0 3px #7be36f, 0 0 26px rgba(123, 227, 111, 1), var(--shadow); } }
.card.fresh.selected { box-shadow: 0 0 0 4px var(--red), 0 10px 16px rgba(0, 0, 0, .5); }
.fx.flash.gold { background: rgba(224, 168, 62, .45); box-shadow: 0 0 26px rgba(224, 168, 62, .9); }

/* крупная проверка */
.check-overlay {
  position: fixed; inset: 0; z-index: 55; pointer-events: none; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(0, 0, 0, .45); animation: fade .2s ease-out; transition: opacity .3s;
}
.check-overlay.out { opacity: 0; }
.check-box {
  background: var(--paper); color: var(--ink); border: 4px solid var(--gold); border-radius: 16px; padding: 16px 22px;
  text-align: center; box-shadow: 0 12px 40px rgba(0, 0, 0, .7); max-width: 420px; width: 100%; animation: pop .3s ease-out;
  --card-w: 112px; --card-h: 160px;
}
.check-overlay.own .check-box { border-color: var(--red); }
.check-title { font-family: 'PT Serif', serif; font-weight: 700; font-size: 22px; }
.check-who { font-weight: 700; color: var(--muted); margin-top: 2px; }
.check-need { font-size: 14px; color: var(--muted); margin-top: 4px; }
.check-cards { display: flex; gap: 14px; justify-content: center; margin: 14px 0 10px; }
.flip { width: var(--card-w); height: var(--card-h); perspective: 700px; }
.flip-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transform: rotateY(180deg); transition: transform .5s cubic-bezier(.3, .7, .4, 1.2); }
.flip-front, .flip-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.flip-back { transform: rotateY(180deg); }
.flip-back .card-back { width: 100%; height: 100%; font-size: 40px; }
.check-overlay:not(.revealed) .flip-inner { animation: wobble .25s ease-in-out infinite; }
@keyframes wobble { 0%, 100% { transform: rotateY(180deg) rotate(-2deg); } 50% { transform: rotateY(180deg) rotate(2deg); } }
.check-overlay.revealed .flip-inner { transform: rotateY(0); }
.check-overlay.done .flip.other { opacity: .35; transform: scale(.9); transition: all .3s; }
.check-overlay.done .flip.chosen .card { box-shadow: 0 0 0 4px var(--gold), 0 0 20px var(--gold); }
.check-result { font-size: 20px; font-weight: 700; padding: 6px 10px; border-radius: 10px; opacity: 0; transform: scale(.6); transition: all .25s cubic-bezier(.3, .7, .4, 1.5); }
.check-overlay.done .check-result { opacity: 1; transform: scale(1); }
.check-result.ok { background: #d8f3d2; color: #1f6a17; }
.check-result.bad { background: #f9d6d3; color: #8d1c16; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ───── планшеты ───── */
@media (max-width: 1000px) {
  .game { grid-template-columns: minmax(0, 1fr) 240px; }
  .pl { width: 170px; }
}

/* ───── телефоны ───── */
@media all { /* раскладка одна — телефонная */
  :root { --card-w: 74px; --card-h: 106px; }
  .screen .logo { font-size: 56px; }
  .game {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto 1fr;
    grid-template-areas: "top" "opp" "center" "mine"; gap: 8px; padding: 6px 6px 0; min-height: 100dvh;
  }
  .mobile-only { display: inline-block; }
  .topbar { position: sticky; top: 0; z-index: 20; background: rgba(42, 27, 18, .95); margin: -6px -6px 0; padding: 6px 8px; flex-wrap: nowrap; gap: 6px; }
  .topbar .logo { font-size: 20px; text-shadow: 2px 2px 0 var(--red), 3px 3px 0 #000; }
  .topbar .lbl, .room-badge { display: none; }
  .topbar .status { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
  .topbar .grow { display: none; }
  .icon-btn { padding: 4px 7px; font-size: 15px; }

  .opponents { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .opponents[data-count="1"], .opponents[data-count="2"], .opponents[data-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .opponents .pl { width: auto; padding: 5px 6px; border-width: 2px; border-radius: 8px; }
  .opponents .pl-name { font-size: 13px; }
  .opponents .role-name { display: none; }
  .opponents .role { font-size: 14px; }
  .opponents .pl-char { font-size: 11px; }
  .opponents .hp { font-size: 12px; margin: 1px 0; letter-spacing: 0; }
  .opponents .pl-meta { font-size: 11px; gap: 5px; }
  .opponents .inplay { gap: 2px; margin-top: 3px; }
  .opponents .card.mini { padding: 1px 3px; }
  .opponents .card.mini .c-name { display: none; }
  .opponents .card.mini { padding: 1px 3px; }
  .opponents .waiting-tag { font-size: 10px; top: -8px; right: 4px; }
  .seat { width: 20px; height: 20px; font-size: 11px; top: -8px; left: -8px; }
  .opponents .lvl { font-size: 9px; padding: 0 3px; }
  .order { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; width: 100%; font-size: 12px; padding-bottom: 2px; scrollbar-width: none; }
  .o-item { padding: 1px 6px; }
  .dead-mark { font-size: 16px; right: 4px; bottom: 2px; }

  .center { border-radius: 22px; border-width: 4px; padding: 8px; min-height: 0; gap: 6px; }
  .center .card-back { width: 52px; height: 74px; font-size: 14px; border-width: 2px; }
  .center .card { --card-w: 52px; --card-h: 74px; }
  .piles { gap: 14px; }
  .pile-label { font-size: 11px; margin-top: 2px; }
  .ticker { font-size: 12px; }
  .prompt-center { display: none; }
  .prompt-mine { display: block; }
  .prompt-mine:empty { display: none; }
  .prompt-mine .prompt { max-width: none; padding: 8px 10px; margin-top: 6px; }
  .prompt-title { font-size: 14px; }
  .prompt .hint { font-size: 13px; }
  .prompt .row button { flex: 1; }

  .mine {
    position: sticky; bottom: 0; z-index: 15; border-radius: 14px 14px 0 0; margin: 0 -6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(30, 19, 12, .97); box-shadow: 0 -6px 20px rgba(0, 0, 0, .5); align-self: end;
  }
  .me-info { display: none; }
  .mine-head .pl { width: 100%; min-width: 0; display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "top top top" "char hp meta" "inplay inplay inplay"; column-gap: 8px; align-items: center; padding: 5px 8px; border-width: 2px; }
  .mine-head .pl-top { grid-area: top; }
  .mine-head .pl-sub { grid-area: char; }
  .mine-head .pl-char { font-size: 12px; }
  .mine-head .hp { grid-area: hp; margin: 0; font-size: 13px; }
  .mine-head .pl-meta { grid-area: meta; font-size: 12px; gap: 6px; }
  .mine-head .inplay { grid-area: inplay; margin-top: 3px; }
  .mine-head .inplay:empty { display: none; }
  .actions { margin-top: 6px; }
  .actions button { flex: 1; padding: 8px 6px; font-size: 14px; }
  .hand {
    flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; overflow-y: visible; gap: 6px;
    padding: 18px 4px 4px; min-height: calc(var(--card-h) + 22px); scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
  }
  .hand[data-count="1"], .hand[data-count="2"], .hand[data-count="3"], .hand[data-count="4"] { justify-content: center; }
  .hand .card { scroll-snap-align: center; }
  .card.selected { transform: translateY(-12px) !important; }

  .side {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 30; max-height: none; height: 65dvh;
    background: #24170f; border-radius: 16px 16px 0 0; padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .6); transform: translateY(105%); transition: transform .25s ease-out;
  }
  .side.open { transform: translateY(0); }
  .side-tabs { display: flex; gap: 6px; align-items: center; }
  .side .box { flex: 1; }
  .side.tab-log .chat-box, .side.tab-chat .log-box { display: none; }
  .side .box h3 { display: none; }

  .modal { padding: 0; align-items: flex-end; }
  .modal-body { border-radius: 16px 16px 0 0; max-height: 88dvh; padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); border-width: 3px 0 0; animation: sheet .25s ease-out; }
  @keyframes sheet { from { transform: translateY(40px); opacity: 0; } }
  .modal-body h2 { font-size: 19px; }
  .choice { min-width: 0; }
  .modal-body .row button { flex: 1; }
  .fx.burst { width: 110px; height: 80px; font-size: 19px; }
}

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

@media (max-width: 360px) {
  .opponents { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

.back-link { color: var(--paper2); text-decoration: none; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
.back-link:hover { color: var(--paper); background: rgba(255, 255, 255, .08); }

/* ───── перетаскивание карты ───── */
.hand .card.playable { touch-action: pan-x; }
.card.drag-src { opacity: .25; }
.drag-ghost { position: fixed; z-index: 60; pointer-events: none; transform-origin: 50% 80%; filter: drop-shadow(0 14px 18px rgba(0, 0, 0, .55)); }
.drag-ghost .card { width: 100%; height: 100%; box-shadow: 0 0 0 3px var(--gold), var(--shadow); }
body.dragging-card { cursor: grabbing; user-select: none; -webkit-user-select: none; }
body.drag-free .center { outline: 3px dashed rgba(255, 255, 255, .25); outline-offset: -10px; }
.center.drop-hot { outline: 3px dashed var(--gold) !important; box-shadow: inset 0 0 40px rgba(242, 177, 52, .35); }
.pl.drop-hot { transform: scale(1.07); box-shadow: 0 0 0 4px var(--gold), 0 0 22px var(--gold) !important; animation: none; }

/* Игра — телефонная колонка; на компьютере она по центру экрана. */
#app { max-width: 560px; margin: 0 auto; }
.side, .modal-body, .autopilot-bar { max-width: 560px; margin-left: auto; margin-right: auto; }
.screen { max-width: 520px; }

/* ───── экран как приложение: ровно по высоте телефона, без прокрутки ─────
   Telegram в полноэкранном режиме рисует свои кнопки («Закрыть», «⋯») поверх страницы
   и сообщает их высоту в --tg-content-safe-area-inset-top — верх игры опускаем под них. */
:root {
  --inset-top: calc(var(--tg-safe-area-inset-top, env(safe-area-inset-top, 0px)) + var(--tg-content-safe-area-inset-top, 0px));
  --inset-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  --app-h: var(--tg-viewport-stable-height, 100dvh);
}
body:has(#game) { overflow: hidden; overscroll-behavior: none; }
.game {
  height: var(--app-h); min-height: 0 !important; overflow: hidden;
  grid-template-rows: auto auto minmax(0, 1fr) auto !important;
}
.topbar { position: relative !important; padding-top: calc(6px + var(--inset-top)) !important; }
/* Стол забирает всё свободное место и сжимается первым; руку и кнопки ничто не сдвигает. */
.center { min-height: 0 !important; overflow: hidden; justify-content: flex-start; }
.center > * { flex-shrink: 0; }
.center .piles { margin: auto 0; } /* колоды по центру свободного места; при нехватке места обрезается лента событий снизу */
.center .ticker { overflow: hidden; flex-shrink: 1; min-height: 0; }
.center .store { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; justify-content: flex-start; scrollbar-width: none; }
/* Много карт перед игроком — лента в одну строку, листается вбок, а не раздувает карточку. */
.inplay { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; }
.inplay::-webkit-scrollbar, .center .store::-webkit-scrollbar { display: none; }
.mine { position: relative !important; align-self: stretch !important; padding-bottom: calc(8px + var(--inset-bottom)) !important; }
.modal-body { max-height: calc(var(--app-h) - var(--inset-top) - 8px) !important; overflow-y: auto; }
.side { height: min(65dvh, calc(var(--app-h) - var(--inset-top) - 8px)) !important; }
.screen { padding-top: calc(24px + var(--inset-top)) !important; }
/* Плашка автоигры — одна тонкая строка, чтобы не съедать стол на маленьких экранах. */
.autopilot-bar { flex-wrap: nowrap !important; padding: 5px 8px 5px 10px !important; margin-bottom: 6px !important; font-size: 13px; }
.autopilot-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.autopilot-bar button { flex: none !important; padding: 5px 10px; font-size: 13px; white-space: nowrap; }

/* ───── компактный стол: всё помещается без прокрутки ───── */
/* Соперник — три строки: имя и роль; персонаж и жизни; карты, дальность и карты на столе. */
.opponents { gap: 5px; }
.opponents .pl {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 6px; row-gap: 1px; align-items: center;
  grid-template-areas: "top top" "sub hp" "meta inplay"; padding: 4px 6px;
}
.opponents .pl-top { grid-area: top; }
.opponents .pl-sub { grid-area: sub; min-width: 0; overflow: hidden; white-space: nowrap; }
.opponents .hp { grid-area: hp; margin: 0; }
.opponents .pl-meta { grid-area: meta; gap: 4px; flex-wrap: nowrap; white-space: nowrap; }
.opponents .inplay { grid-area: inplay; margin-top: 0; justify-content: flex-end; max-width: 100%; }
.opponents .inplay:empty { display: none; }
.opponents .pl-name .pf-ava { width: 18px !important; height: 18px !important; }
/* Моя карточка и подсказка — плотнее. */
.mine { padding-top: 6px !important; }
.mine-head .pl { padding: 4px 8px; }
.prompt-mine .prompt { padding: 6px 10px !important; margin-top: 5px !important; }
.prompt-mine .prompt .hint { font-size: 12px; line-height: 1.25; }
.prompt-mine .timer { display: inline; margin-left: 4px; }
/* Магазин на столе — маленькие карты в одну строку рядом с колодами. */
.center .store .card { --card-w: 40px; --card-h: 57px; }
.center .store { gap: 4px; }
.center { gap: 4px !important; padding: 6px !important; }
/* Невысокие экраны (Telegram не на весь экран, маленькие телефоны) — карты чуть меньше. */
@media (max-height: 760px) {
  :root { --card-w: 66px; --card-h: 94px; }
  .center .card-back { width: 44px; height: 62px; }
  .center .card { --card-w: 44px; --card-h: 62px; }
  .hand { padding-top: 14px !important; min-height: calc(var(--card-h) + 18px) !important; }
}

/* Проверка: переворот без 3D. На iPhone (Telegram, Safari) рубашка с «?» оставалась поверх открытой карты —
   backface-visibility там ненадёжна. Теперь рубашка просто сменяется лицом карты с «переворотом» по ширине. */
.flip { perspective: none; }
.flip-inner { transform-style: flat; transform: none; transition: none; }
.flip-front, .flip-back { backface-visibility: visible; -webkit-backface-visibility: visible; }
.flip-back { transform: none; }
.flip-front { visibility: hidden; }
.check-overlay:not(.revealed) .flip-inner { animation: wobble2d .25s ease-in-out infinite; }
@keyframes wobble2d { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
.check-overlay.revealed .flip-inner { transform: none; }
.check-overlay.revealed .flip-back { visibility: hidden; }
.check-overlay.revealed .flip-front { visibility: visible; animation: flip2d .35s ease-out; }
@keyframes flip2d { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* Чей ход — зелёный (активный), кто следующий — жёлтый. */
.pl.turn { border-color: #3f9d36 !important; animation: glow-turn 1.6s ease-in-out infinite; }
@keyframes glow-turn { 0%, 100% { box-shadow: 0 0 0 2px #3f9d36, var(--shadow); } 50% { box-shadow: 0 0 0 4px #3f9d36, 0 0 16px #5fd055; } }
.pl.turn .seat { background: #3f9d36; color: #fff; }
.pl.turn .waiting-tag:not(.offline-tag):not(.auto-tag) { background: #3f9d36; color: #fff; }
.pl.next .seat { background: var(--gold); color: var(--ink); }
.pl.next:not(.turn) { border-color: var(--gold); }
.next-tag { background: var(--gold); color: var(--ink); }
.o-item.cur { background: #3f9d36; color: #fff; }
.o-item.cur b { color: #fff; }
.o-item.next { border-color: var(--gold); }
