:root {
  --cw: 48px;
  --felt: #0b5d3b;
  --felt-dark: #073d27;
  --panel: rgba(0, 0, 0, .4);
  --gold: #f5c542;
  --text: #f4f7f5;
  --muted: #a9c9b8;
  --danger: #b3261e;
  --tap: 44px;
}
@media (min-width: 480px) { :root { --cw: 56px; } }
@media (min-width: 720px) { :root { --cw: 78px; } }

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% 30%, #12804f 0%, var(--felt) 45%, var(--felt-dark) 100%) fixed;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.3em; margin: .4rem 0 0; }
h1, h2, h3 { margin: 0 0 .5rem; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
small { color: var(--muted); }

#app { max-width: 1100px; margin: 0 auto; padding: 12px 16px 72px 16px; }
.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 16px;
  padding: 14px;
  backdrop-filter: blur(4px);
}
@media (min-width: 720px) { .panel { padding: 18px; } }
.login { max-width: 420px; margin: 6vh auto 0; text-align: center; }
.login label { display: block; text-align: left; margin: 14px 0 0; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=password] {
  width: 100%; margin-top: 4px; padding: 12px; font-size: 16px;
  border-radius: 10px; border: 1px solid rgba(255, 255, 255, .25);
  background: rgba(0, 0, 0, .3); color: var(--text);
}
input:focus { outline: 2px solid var(--gold); }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.login .row { margin-top: 16px; justify-content: center; }
.btn {
  appearance: none; border: 1px solid rgba(255, 255, 255, .3); cursor: pointer;
  background: rgba(255, 255, 255, .1); color: var(--text);
  padding: 12px 16px; min-height: 48px; font-size: 1rem; border-radius: 10px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  transition: background .15s, transform .1s; box-sizing: border-box;
}
.btn:hover:not(:disabled) { background: rgba(255, 255, 255, .2); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #3a2a00; border-color: var(--gold); }
.btn.primary:hover:not(:disabled) { background: #ffd666; }
.btn.danger { background: #b3261e; border-color: #b3261e; }
.btn.small { padding: 8px 10px; font-size: .9rem; min-height: 36px; }
.btn.wide { width: 100%; }

/* Одинаковые кнопки в лобби строго одинаковой высоты */
.propose .row { margin-top: 12px; gap: 8px; display: flex; align-items: stretch; }
.propose .row .btn { flex: 1; margin: 0; }
.btn.active-choice { background-color: #2e7d32 !important; border-color: #4caf50 !important; color: #fff !important; font-weight: bold; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 14px; }
.chip { background: rgba(255, 255, 255, .12); border-radius: 999px; padding: 4px 10px; font-size: .8rem; }
.plist { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.plist li {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-wrap: wrap;
  background: rgba(0, 0, 0, .25); border-radius: 12px; border: 1px solid transparent;
}
.plist li.you { border-color: var(--gold); }
.plist li.off { opacity: .5; }
.plist .nm { flex: 1; font-weight: 600; word-break: break-word; min-width: 40%; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: #888; flex: 0 0 auto; }
.dot.on { background: #4cd964; box-shadow: 0 0 8px #4cd964; }
.punish { color: var(--gold); font-weight: 700; }
.propose { margin-top: 12px; }
.vote-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.tie { display: grid; gap: 8px; margin-top: 12px; }

.card {
  width: var(--cw); height: calc(var(--cw) * 1.45); flex: 0 0 auto;
  background: #fff; color: #15181c; border-radius: calc(var(--cw) * .1);
  position: relative; font-weight: 700; user-select: none; -webkit-user-select: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .45); transition: transform .12s, box-shadow .12s;
}
.card.red { color: #d32f2f; }
.card .corner {
  position: absolute; top: 4%; left: 7%; display: flex; flex-direction: column; align-items: center;
  line-height: 1; font-size: calc(var(--cw) * .26);
}
.card .corner i { font-style: normal; font-size: .9em; }
.card .corner.br { top: auto; left: auto; bottom: 4%; right: 7%; transform: rotate(180deg); }
.card .pip { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--cw) * .58); }
.card.joker { background: linear-gradient(135deg, #fff 0%, #ffe9a8 100%); color: #7b1fa2; }
.card.joker-red { color: #c62828; }
.card.joker-black { background: linear-gradient(135deg, #fff 0%, #cfd8dc 100%); color: #212121; }
.card.back {
  background: repeating-linear-gradient(45deg, #1f3a93 0 6px, #2f53c9 6px 12px);
  border: 3px solid #fff;
}
.card.small { --cw: 34px; }
.card.mini { --cw: 22px; }
.card.rot { transform: rotate(90deg); margin: calc(var(--cw) * .2) calc(var(--cw) * .2); }
.card.selected { transform: translateY(-18px); box-shadow: 0 0 0 4px #4cd9ff, 0 6px 14px rgba(0, 0, 0, .6); }

.topbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.trump {
  display: flex; align-items: center; gap: 8px; background: var(--panel);
  padding: 6px 12px; border-radius: 12px; border: 1px solid var(--gold);
}
.trump.no-trump { border-color: #90caf9; }
.trump-sym { font-size: 1.6rem; line-height: 1; }
.trump.red .trump-sym { color: #ff6b6b; }
.trump-name { font-weight: 700; font-size: .85rem; }
.pile { display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; font-size: .72rem; }
.pile .cnt {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -75%);
  background: rgba(0, 0, 0, .7); color: #fff; padding: 1px 8px; border-radius: 999px; font-size: .85rem;
}
.slot { width: calc(var(--cw) * .7); height: calc(var(--cw) * 1.0); border: 2px dashed rgba(255, 255, 255, .3); border-radius: 8px; }

.seats { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.seat {
  background: var(--panel); border: 2px solid transparent; border-radius: 12px;
  padding: 8px 10px; min-width: 42%; max-width: 100%; text-align: center;
}
.seat.attacking { border-color: var(--gold); }
.seat.defending, .seat.took { border-color: #ff6b6b; }
.seat.out { opacity: .45; }
.seat .sname { font-weight: 700; word-break: break-word; font-size: .9rem; }
.seat .hcount { display: flex; gap: 6px; justify-content: center; align-items: center; margin: 4px 0; }
.stumps { display: flex; gap: 4px; justify-content: center; align-items: center; font-size: .72rem; color: var(--muted); margin: 2px 0; }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700;
  background: rgba(255, 255, 255, .15);
}
.badge.attacking { background: var(--gold); color: #3a2a00; }
.badge.defending { background: #ff6b6b; color: #3b0000; }
.badge.took { background: #b3261e; }
.badge.passed { background: #5d6d7e; }
.badge.support { background: #4a90d9; }
.badge.out { background: #2e7d32; }

.table {
  min-height: calc(var(--cw) * 1.45 + 32px); margin: 6px 0; padding: 12px 8px;
  border-radius: 18px; background: rgba(0, 0, 0, .18); border: 2px dashed rgba(255, 255, 255, .18);
  display: flex; flex-wrap: wrap; gap: 12px 14px; justify-content: center; align-items: center;
}
.pair { position: relative; width: calc(var(--cw) * 1.35); height: calc(var(--cw) * 1.45 + 14px); }
.pair .atk { position: absolute; left: 0; top: 14px; }
.pair .def { position: absolute; left: calc(var(--cw) * .35); top: 0; transform: rotate(7deg); }
.pair.target { cursor: pointer; }
.pair.target .atk { box-shadow: 0 0 0 4px #4cd9ff, 0 0 14px #4cd9ff; }

.hint { text-align: center; margin: 10px 0 6px; font-weight: 600; min-height: 1.4em; font-size: .95rem; }
.actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.actions .btn { flex: 1 1 30%; max-width: 150px; }
.me-line { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.sticky-actions {
  position: sticky; bottom: calc(8px + env(safe-area-inset-bottom));
  z-index: 8; padding: 8px; background: rgba(7, 61, 39, .88);
  border-radius: 12px; backdrop-filter: blur(6px);
}

.hand {
  display: flex; padding: 22px 8px 8px; overflow-x: auto; justify-content: safe center;
  -webkit-overflow-scrolling: touch; touch-action: pan-x;
}
.hand .card + .card { margin-left: calc(var(--cw) * -.32); }
.hand .card.selected { transform: translateY(-22px); z-index: 2; }

details.log { margin-top: 10px; background: var(--panel); border-radius: 12px; padding: 8px 12px; font-size: .88rem; }
details.log summary { cursor: pointer; font-weight: 600; }
details.log .lines { max-height: 160px; overflow-y: auto; margin-top: 6px; display: grid; gap: 2px; }

.final { text-align: center; max-width: 560px; margin: 5vh auto 0; }
.loser-card { margin: 18px 0; padding: 18px; border-radius: 16px; background: rgba(179, 38, 30, .35); border: 2px solid #ff7b72; }
.loser-card .big { font-size: 3.5rem; line-height: 1; }
.loser-card .nick { font-size: 1.35rem; font-weight: 800; color: var(--gold); margin: 6px 0; word-break: break-word; }
.standings { text-align: left; margin: 14px auto; max-width: 340px; padding-left: 1.4rem; }

#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none;
  transition: .25s; z-index: 50; max-width: 90vw; text-align: center; border: 1px solid #555;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.rules-fab {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 40;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  background: rgba(11, 93, 59, 0.95);
  color: var(--gold);
  font-size: 1.1rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

.modal {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.55);
  display: grid; place-items: end center; padding: 12px;
}
@media (min-width: 720px) { .modal { place-items: center; } }
.modal-card {
  background: #0d3d28; color: var(--text); border: 1px solid rgba(255,255,255,.18);
  border-radius: 18px 18px 12px 12px; padding: 16px; max-width: 520px; width: 100%;
  max-height: min(80vh, 640px); overflow: auto;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.rules-list { margin: 0; padding-left: 1.1rem; display: grid; gap: 10px; font-size: .95rem; line-height: 1.4; }