:root {
  --felt: #1f6a42;
  --felt-dark: #123d26;
  --felt-line: rgba(255, 255, 255, .14);
  --panel: #fffdf7;
  --panel-2: #f6f2e8;
  --ink: #1d1d1f;
  --muted: #6b6f76;
  --accent: #e08a2e;
  --blue: #4aa3ef;
  --red: #d32f2f;
  --green: #66bb6a;
  --purple: #7b1fa2;
  --card-w: 76px;
  --card-h: calc(var(--card-w) * 1.4);
  --radius: 8px;
  --fast: 160ms;
  --med: 260ms;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--felt-dark);
  overflow: hidden;
}

body { background: radial-gradient(ellipse at 50% 45%, var(--felt) 0%, var(--felt-dark) 85%); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.screen { height: 100%; }

/* ---------- Общие элементы ---------- */
.panel {
  background: var(--panel);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .35);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: pop-in var(--med) ease-out;
}

h1,
h2,
h3 { margin: 0 0 4px; }
h1 span { color: var(--accent); font-weight: 500; }
h3 { font-size: 16px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }

input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #cfd3d8;
  border-radius: var(--radius);
  min-width: 0;
  flex: 1;
}

button {
  font: inherit;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid #cfd3d8;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  transition: transform var(--fast), background var(--fast), box-shadow var(--fast), opacity var(--fast);
}

button:active { transform: scale(.96); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #d27b1f; }
button.big { padding: 13px 18px; font-size: 17px; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 4px; }
button.ghost { background: rgba(255, 255, 255, .1); border: 1px solid rgba(255, 255, 255, .2); color: #e8f3ec; padding: 6px 12px; font-size: 14px; }
button.ghost:hover { background: rgba(255, 255, 255, .18); }
button.ghost.dark { color: var(--ink); background: transparent; border-color: transparent; font-size: 18px; }
button.ghost-light { background: var(--panel-2); border: 1px dashed #cfc6b0; color: var(--ink); }
button.ghost-light:hover { background: #efe8d6; }
button.grow { flex: 1; }

.row { display: flex; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.code { font-family: ui-monospace, Consolas, monospace; letter-spacing: 2px; color: var(--accent); }

.or { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.or::before,
.or::after { content: ""; flex: 1; height: 1px; background: #e3ddcd; }

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  white-space: nowrap;
  animation: pop-in var(--fast) ease-out;
}

.chip.attack { background: var(--accent); }
.chip.defend { background: var(--blue); }
.chip.take { background: var(--red); }
.chip.out { background: var(--green); }
.chip.fool { background: #6d4c41; }
.chip.passed { background: rgba(255, 255, 255, .22); }
.chip.thrower { background: #a0661f; }
.chip.cheat { background: var(--purple); }
.chip.empty { visibility: hidden; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #546e7a;
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  border: 2px solid rgba(255, 255, 255, .85);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.avatar.small { width: 26px; height: 26px; font-size: 13px; border-width: 1.5px; }
.avatar.empty { background: transparent; border: 2px dashed rgba(255, 255, 255, .5); box-shadow: none; color: rgba(255, 255, 255, .8); }

.topbar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  font-size: 14px;
  gap: 10px;
  color: #fff;
}
.room { color: #cfe3d6; white-space: nowrap; }
.room b { color: #fff; letter-spacing: 1px; }
.top-actions { display: flex; gap: 8px; margin-left: auto; }

/* ---------- Главная ---------- */
#home {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  overflow: auto;
}
#home > .panel { margin: auto 0; }
#home .muted.small { text-align: center; margin: 0; }

.invited {
  background: #fff3e0;
  border: 1px solid #ffcc80;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 15px;
}

/* ---------- Комната ---------- */
#lobby { display: flex; flex-direction: column; overflow: auto; }

.lobby-body {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  padding: 8px 20px 20px;
  align-items: start;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.lobby-tip { color: #d9ecdf; text-align: center; font-size: 14px; margin: 4px 0 8px; }

.seats {
  position: relative;
  width: 100%;
  max-width: 680px;
  margin: 56px auto 56px;
  aspect-ratio: 16 / 11;
}

.felt-oval {
  position: absolute;
  inset: 15% 15%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, #2a8a56 0%, #1a5a37 70%);
  border: 10px solid #6b4324;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, .45), 0 10px 30px rgba(0, 0, 0, .4), 0 0 0 3px #3f2714;
  display: flex;
  align-items: center;
  justify-content: center;
}

.oval-center { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; padding: 8px; color: #fff; }
.lobby-count { font-size: 15px; color: #d9ecdf; }
.lobby-hint { font-size: 13px; color: #cfe3d6; max-width: 240px; }

.seat {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 124px;
  min-height: 96px;
  padding: 8px 6px;
  border-radius: 14px;
  background: rgba(0, 0, 0, .3);
  border: 2px solid transparent;
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-align: center;
  animation: pop-in var(--med) ease-out;
  transition: background var(--fast), border-color var(--fast);
}
.seat-0 { left: 50%; top: 92%; }
.seat-1 { left: 9%; top: 72%; }
.seat-2 { left: 9%; top: 26%; }
.seat-3 { left: 50%; top: 8%; }
.seat-4 { left: 91%; top: 26%; }
.seat-5 { left: 91%; top: 72%; }

.seat.mine { border-color: var(--accent); background: rgba(224, 138, 46, .25); }
.seat.offline { opacity: .55; }
.seat.free { cursor: pointer; border: 2px dashed rgba(255, 255, 255, .3); background: rgba(0, 0, 0, .12); }
.seat.free:hover { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .7); }
.seat.free .seat-name { color: rgba(255, 255, 255, .75); font-weight: 500; }
.seat-name { font-weight: 700; font-size: 14px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-sub { font-size: 11px; color: #ffe0b2; min-height: 14px; }
.seat.free .seat-sub { color: rgba(255, 255, 255, .55); }
.seat-x,
.seat-bot {
  position: absolute;
  padding: 2px 7px;
  font-size: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .9);
  border: none;
}
.seat-x { right: 4px; top: 4px; }
.seat-bot { bottom: -12px; left: 50%; transform: translateX(-50%); white-space: nowrap; }
.seat-bot:active { transform: translateX(-50%) scale(.95); }

.lobby-side { display: flex; flex-direction: column; gap: 14px; }
.card-box {
  background: var(--panel);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  animation: pop-in var(--med) ease-out;
}
.card-box p { margin: 0; }
.card-box #invite { font-size: 13px; }
.qr { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; background: #fff; border-radius: var(--radius); }
.qr img,
.qr canvas { display: block; }
.note { margin: 0; font-size: 12px; background: #e3f2fd; color: #0d47a1; border-radius: var(--radius); padding: 8px 10px; line-height: 1.35; }

.select-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.select-row select { font: inherit; padding: 6px 8px; border-radius: var(--radius); border: 1px solid #cfd3d8; background: #fff; }
.select-row select:disabled { opacity: .7; }

.toggle { flex-direction: row; align-items: flex-start; gap: 10px; padding: 10px; background: var(--panel-2); border-radius: var(--radius); cursor: pointer; }
.toggle input { flex: none; width: 18px; height: 18px; margin-top: 2px; }
.toggle span { display: flex; flex-direction: column; gap: 4px; }
.toggle small { font-size: 12px; line-height: 1.35; }
.toggle.readonly { cursor: default; opacity: .85; }

/* ---------- Игровой экран ---------- */
#game {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  color: #fff;
  position: relative;
  overflow: hidden;
}

.trump-badge {
  background: rgba(0, 0, 0, .3);
  padding: 4px 10px;
  border-radius: 14px;
  white-space: nowrap;
  font-size: 14px;
}
.trump-badge b { font-size: 18px; font-family: "Segoe UI Symbol", "Noto Sans Symbols", serif; vertical-align: -1px; }

.trump-badge .lbl { color: #cfe3d6; }

/* Соперники — дугой, как за круглым столом */


@keyframes blink { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }

/* Середина стола */

.pile-area { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.pile-label { font-size: 12px; color: #cfe3d6; text-align: center; min-height: 16px; }

#deck { position: relative; width: calc(var(--card-w) * 1.7); height: var(--card-h); }
#deck .card.trump { position: absolute; left: calc(var(--card-w) * .5); top: 0; transform: rotate(90deg); }
#deck .back.stack { position: absolute; left: 0; top: 0; }
#deck .back.stack::after {
  content: attr(data-count);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: calc(var(--card-w) * .3);
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .7);
}

.trump-only {
  width: var(--card-w);
  height: var(--card-w);
  margin: calc((var(--card-h) - var(--card-w)) / 2) auto;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * .5);
}

#discard { position: relative; width: var(--card-w); height: var(--card-h); }
#discard .back { position: absolute; left: 0; top: 0; }

.table-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 0;
  align-self: stretch;
  justify-content: center;
  border-radius: 40px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--felt-line);
  padding: 10px;
}

#table {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 24px;
  justify-content: center;
  align-content: center;
  min-height: calc(var(--card-h) * 1.22);
}

.drop-hint {
  align-self: center;
  border: 2px dashed rgba(255, 255, 255, .25);
  border-radius: 12px;
  padding: 14px 18px;
  color: #cfe3d6;
  font-size: 14px;
  text-align: center;
  max-width: 260px;
  animation: fade-up var(--med) ease-out;
}
.drop-hint.mine { border-color: #ffe082; color: #ffe082; animation: fade-up var(--med) ease-out, breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { border-color: rgba(255, 224, 130, .35); } }

.table-info { font-size: 12px; color: #cfe3d6; min-height: 15px; text-align: center; }

.pair { position: relative; width: calc(var(--card-w) * 1.22); height: calc(var(--card-h) * 1.22); }
.pair .card { position: absolute; left: 0; top: 0; }
.pair .card.def { left: calc(var(--card-w) * .22); top: calc(var(--card-h) * .22); transform: rotate(8deg); }

/* Низ: подсказка, кнопки, рука */
.bottom { padding: 4px 16px max(8px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; }

.prompt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 760px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .3);
  border-left: 5px solid rgba(255, 255, 255, .35);
  animation: fade-up var(--fast) ease-out;
}
.p-icon { font-size: 26px; line-height: 1; flex: none; }
.p-text { flex: 1; min-width: 0; }
.p-title { font-weight: 800; font-size: 17px; }
.p-sub { font-size: 13px; color: #e0eee5; line-height: 1.35; }
.prompt.tone-attack { border-left-color: var(--accent); background: rgba(224, 138, 46, .22); }
.prompt.tone-defend { border-left-color: var(--blue); background: rgba(74, 163, 239, .2); }
.prompt.tone-accuse { border-left-color: #ef5350; background: rgba(239, 83, 80, .22); }
.prompt.tone-done { border-left-color: var(--green); background: rgba(102, 187, 106, .2); }

#actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#actions:empty { display: none; }
button.act {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  min-width: 120px;
  padding: 7px 16px;
  font-weight: 700;
  animation: pop-in var(--fast) ease-out;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
}
button.act .st { font-size: 11px; font-weight: 500; opacity: .8; }
button.act.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
button.act.take { background: #e53935; border-color: #e53935; color: #fff; }
button.act.pass { background: #fff; color: var(--ink); }
button.act.light { background: rgba(255, 255, 255, .15); color: #fff; border-color: rgba(255, 255, 255, .3); }
button.act.cheat { background: var(--purple); border-color: var(--purple); color: #fff; }
button.act.accuse { background: #b71c1c; border-color: #b71c1c; color: #fff; }

#hand {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 900px;
  padding-top: 16px;
  min-height: calc(var(--card-h) + 16px);
}

/* ---------- Карты ---------- */
.card {
  isolation: isolate; /* z-index внутри карты не должен вылезать поверх соседних карт */
  width: var(--card-w);
  height: calc(var(--card-w) * 1.4);
  border-radius: calc(var(--card-w) * .1);
  background: linear-gradient(160deg, #ffffff 0%, #f4f1ea 100%);
  color: #1f1f1f;
  border: 1px solid rgba(0, 0, 0, .25);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
  position: relative;
  user-select: none;
  flex: none;
  font-size: calc(var(--card-w) * .2);
  transition: transform var(--fast) ease, box-shadow var(--fast) ease, margin var(--med) ease, filter var(--fast);
}

.card .corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 700;
  width: 1.3em;
  z-index: 1;
}
.card .corner.tl { left: .15em; top: .22em; }
.card .corner.br { right: .15em; bottom: .22em; transform: rotate(180deg); }
.card .corner .r { letter-spacing: -.08em; font-weight: 800; font-size: .9em; }
.card .corner .s { font-size: .85em; margin-top: .05em; }

.s,
.center,
.trump-only,
.pip,
.pip-ace { font-family: "Segoe UI Symbol", "Noto Sans Symbols", "DejaVu Sans", serif; }
.r { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: lining-nums; }

.card .center { position: absolute; line-height: 1; }

/* Числовые: классическая раскладка значков */
.card .center.pips { inset: 27% 35%; }
.card .pip { position: absolute; transform: translate(-50%, -50%); font-size: .9em; }
.card .pip.flip { transform: translate(-50%, -50%) rotate(180deg); }

/* Туз: одна большая масть */
.card .center.ace { inset: 20% 16%; display: flex; align-items: center; justify-content: center; }
.card .pip-ace { font-size: 2.6em; }

/* Картинки: валет, дама, король */
.card .center.face { inset: 7% 14%; }
.card.face-card .corner { background: #fffdf8; border-radius: 0 0 .25em 0; padding: 0 .05em .1em; }
.card.face-card .corner.br { border-radius: 0 0 .25em 0; }
.card .face-art { width: 100%; height: 100%; display: block; }

/* Мини-карта (показанный козырь) */
.card.compact .center.simple { inset: 0; display: flex; align-items: center; justify-content: center; font-size: 2.2em; padding: 20% 0 0 20%; }
.card.compact .corner.br { display: none; }

.card.is-trump::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px rgba(224, 138, 46, .55);
  pointer-events: none;
  z-index: 2;
}

.back {
  width: var(--card-w);
  height: calc(var(--card-w) * 1.4);
  border-radius: calc(var(--card-w) * .1);
  border: 3px solid #fff;
  background: repeating-linear-gradient(45deg, #8e2430 0 6px, #a8323f 6px 12px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

#hand .card { cursor: pointer; }
#hand .card.playable { transform: translateY(-8px); box-shadow: 0 0 0 3px #ffe082, 0 6px 12px rgba(0, 0, 0, .4); }
#hand .card.dim { filter: brightness(.6) saturate(.6); }
@media (hover: hover) {
  #hand .card:hover { transform: translateY(-12px); z-index: 2; }
  #hand .card.playable:hover { transform: translateY(-16px); }
  #hand .card.dim:hover { transform: translateY(-4px); }
}
#hand .card.selected { transform: translateY(-24px); box-shadow: 0 0 0 4px var(--blue), 0 10px 18px rgba(0, 0, 0, .45); z-index: 3; filter: none; }

.pair .card.to-beat { box-shadow: 0 0 0 2px rgba(255, 255, 255, .6), 0 2px 6px rgba(0, 0, 0, .35); }
.pair .card.target { cursor: pointer; box-shadow: 0 0 0 3px var(--blue), 0 0 12px var(--blue); animation: glow 1s ease-in-out infinite alternate; }
.pair .card.target-cheat { cursor: pointer; box-shadow: 0 0 0 3px #ba68c8, 0 0 12px #ba68c8; }

/* ---------- Анимации ---------- */
.anim-from-me { animation: from-me var(--med) cubic-bezier(.2, .8, .3, 1); }
.anim-from-opp { animation: from-opp var(--med) cubic-bezier(.2, .8, .3, 1); }
.pair .card.def.anim-from-me { animation: def-from-me var(--med) cubic-bezier(.2, .8, .3, 1); }
.pair .card.def.anim-from-opp { animation: def-from-opp var(--med) cubic-bezier(.2, .8, .3, 1); }
.anim-draw { animation: draw-in var(--med) cubic-bezier(.2, .8, .3, 1) both; }

#table.sweep-discard .pair { transition: transform 280ms ease-in, opacity 280ms ease-in; transform: translateX(40vw) rotate(25deg) scale(.6); opacity: 0; }
#table.sweep-take-me .pair { transition: transform 280ms ease-in, opacity 280ms ease-in; transform: translateY(35vh) scale(.7); opacity: 0; }
#table.sweep-take-opp .pair { transition: transform 280ms ease-in, opacity 280ms ease-in; transform: translateY(-35vh) scale(.6); opacity: 0; }

@keyframes from-me { from { transform: translateY(40vh) scale(.8); opacity: 0; } }
@keyframes from-opp { from { transform: translateY(-30vh) scale(.6); opacity: 0; } }
@keyframes def-from-me { from { transform: translateY(40vh) rotate(8deg); opacity: 0; } }
@keyframes def-from-opp { from { transform: translateY(-30vh) rotate(8deg); opacity: 0; } }
@keyframes draw-in { from { transform: translate(-30vw, -30vh) rotate(-20deg) scale(.6); opacity: 0; } }
@keyframes pop-in { from { transform: scale(.85); opacity: 0; } }
@keyframes fade-up { from { transform: translateY(6px); opacity: 0; } }
@keyframes glow {
  from { box-shadow: 0 0 0 2px var(--blue), 0 0 6px var(--blue); }
  to { box-shadow: 0 0 0 3px var(--blue), 0 0 18px var(--blue); }
}

/* Места в комнате выезжают со своей позиции (translate уже занят центровкой). */
.seat { animation: none; }

@media (prefers-reduced-motion: reduce) {
  *,
*::before,
*::after { animation: none !important; transition: none !important; }
}

/* ---------- Журнал ---------- */
#side {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 90vw);
  background: var(--panel);
  color: var(--ink);
  box-shadow: -8px 0 30px rgba(0, 0, 0, .35);
  transform: translateX(105%);
  transition: transform var(--med) ease;
  display: flex;
  flex-direction: column;
  z-index: 5;
}
#side.open { transform: translateX(0); }
.side-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 0 10px; border-bottom: 1px solid #e6e1d4; }
.tabs { display: flex; gap: 2px; flex: 1; }
.tab {
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 8px 8px 0 0;
  background: transparent;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { background: var(--panel-2); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tab:active { transform: none; }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#log { list-style: none; margin: 0; padding: 8px 16px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; font-size: 14px; flex: 1; }
#log li { padding-bottom: 6px; border-bottom: 1px dashed #e6e1d4; }
#log li:last-child { font-weight: 600; border-bottom: none; }

.badge {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e53935;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  margin-left: 4px;
  animation: pop-in var(--fast) ease-out;
}

/* Чат */
.chat-list { list-style: none; margin: 0; padding: 10px 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.chat-list.light { max-height: 220px; min-height: 90px; padding: 6px 2px; background: var(--panel-2); border-radius: var(--radius); padding: 8px; }
.chat-empty { color: var(--muted); font-size: 13px; text-align: center; margin: auto 0; }
.msg { max-width: 85%; align-self: flex-start; background: #f1ede2; border-radius: 4px 12px 12px 12px; padding: 6px 10px; font-size: 14px; animation: fade-up var(--fast) ease-out; }
.msg.mine { align-self: flex-end; background: #ffe7c7; border-radius: 12px 4px 12px 12px; }
.chat-list.light .msg { background: #fff; }
.chat-list.light .msg.mine { background: #ffe7c7; }
.msg-head { display: flex; gap: 8px; align-items: baseline; font-size: 12px; }
.msg-head span { color: var(--muted); font-size: 11px; }
.msg-text { overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.35; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #e6e1d4; }
.card-box .chat-form { padding: 0; border: none; }
.chat-form input { padding: 8px 10px; }
.chat-form button { padding: 8px 14px; }

/* Облачко с сообщением над соперником */
.bubble {
  position: absolute;
  left: 50%;
  top: calc(100% + 6px);
  transform: translateX(-50%);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  width: max-content;
  max-width: 220px;
  overflow-wrap: anywhere;
  z-index: 4;
  animation: pop-in var(--fast) ease-out;
  pointer-events: none;
}
.bubble::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  margin-left: -6px;
  border: 6px solid transparent;
  border-top: none;
  border-bottom-color: #fff;
}

/* Широкий экран: панель чата/журнала всегда справа */
@media (min-width: 1150px) {
  #game { padding-right: 340px; }
  #side { transform: none; width: 340px; box-shadow: -4px 0 20px rgba(0, 0, 0, .25); }
  #side-close,
#side-toggle { display: none; }
  #game > .topbar { margin-right: 0; }
}

/* ---------- Оверлеи ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9;
  animation: fade-up var(--fast) ease-out;
}
.help-panel { max-width: 620px; max-height: calc(100dvh - 32px); padding: 0; gap: 0; }
.help-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 16px 10px 22px; border-bottom: 1px solid #e6e1d4; }
.help-head h2 { margin: 0; }
.help-body { overflow-y: auto; padding: 4px 22px 20px; font-size: 14px; line-height: 1.5; }
.help-body h3 { margin: 14px 0 4px; }
.help-body p { margin: 0; }
.help-body ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.help-body ul.legend { list-style: none; padding: 0; }
.help-body .chip { margin-right: 6px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  max-width: calc(100% - 32px);
  z-index: 10;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
  animation: fade-up var(--fast) ease-out;
}

/* ---------- Таймер, жульничество, счёт ---------- */
#timer { height: 5px; margin: 0 16px; border-radius: 3px; background: rgba(255, 255, 255, .12); overflow: hidden; }
#timer-fill { height: 100%; width: 100%; background: #a5d6a7; transform-origin: left; transition: background var(--med); }
#timer.low #timer-fill { background: #ef5350; }
.chip.timer { background: rgba(0, 0, 0, .3); font-variant-numeric: tabular-nums; font-size: 13px; flex: none; }
.chip.timer.low { background: #c62828; animation: tick 1s ease-in-out infinite; }
@keyframes tick { 50% { transform: scale(1.08); } }

#shown { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#shown:empty { display: none; }
.shown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, .25);
  border-radius: 10px;
  padding: 4px 10px 4px 4px;
  font-size: 13px;
  animation: pop-in var(--med) ease-out;
}
.shown-item .card { width: 36px; height: 50px; font-size: 9px; border-radius: 4px; }
.shown-item.accusable { cursor: pointer; }

.accusing .card.accusable,
.accusing .shown-item.accusable { cursor: crosshair; box-shadow: 0 0 0 3px #ef5350, 0 0 12px #ef5350; animation: suspect .7s ease-in-out infinite alternate; }
@keyframes suspect {
  from { box-shadow: 0 0 0 2px #ef5350, 0 0 4px #ef5350; }
  to { box-shadow: 0 0 0 3px #ef5350, 0 0 16px #ef5350; }
}

#notice {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  max-width: min(520px, calc(100% - 32px));
  padding: 14px 20px;
  border-radius: 14px;
  font-weight: 700;
  font-size: 16px;
  text-align: center;
  z-index: 7;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  animation: notice-in 260ms cubic-bezier(.2, .9, .3, 1.3);
  pointer-events: none;
}
#notice.caught { background: #fff3e0; color: #b71c1c; border: 3px solid #e53935; }
#notice.wrong { background: #eceff1; color: #37474f; border: 3px solid #90a4ae; }
#notice .big { display: block; font-size: 30px; margin-bottom: 4px; }
#notice.out { animation: notice-out 220ms ease-in both; }
@keyframes notice-in { from { transform: translate(-50%, -50%) scale(.6); opacity: 0; } }
@keyframes notice-out { to { transform: translate(-50%, -60%); opacity: 0; } }

#pogony { text-align: center; font-weight: 700; color: #6d4c41; animation: pop-in var(--med) ease-out; }

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
  .lobby-body { grid-template-columns: 1fr; max-width: 640px; }
}

@media (max-width: 760px) {
  :root { --card-w: 58px; }
  .topbar .lbl { display: none; }
  
  
  #deck { transform: scale(.8); transform-origin: left center; }
  
  
  
  
  
  #table { gap: 10px 14px; }
  .table-col { border-radius: 24px; padding: 6px; }
  .seat { width: 96px; min-height: 84px; padding: 6px 4px; }
  .seats { aspect-ratio: 1 / 1; }
  .felt-oval { inset: 18% 14%; }
  .seat-1,
.seat-2 { left: 13%; }
  .seat-4,
.seat-5 { left: 87%; }
  .lobby-body { padding: 4px 12px 16px; }
}

@media (max-width: 480px) {
  :root { --card-w: 50px; }
  .topbar { padding: 6px 10px; gap: 6px; font-size: 13px; }
  .topbar .room { display: none; }
  
  
  
  
  
  
  
  .bottom { padding-left: 8px; padding-right: 8px; }
  .p-title { font-size: 15px; }
  .p-icon { font-size: 22px; }
  button.act { min-width: 96px; padding: 6px 10px; }
  .seat { width: 84px; }
  .seat .avatar { width: 32px; height: 32px; font-size: 15px; }
  .seat-name { font-size: 12px; }
}

@media (max-height: 640px) {
  :root { --card-w: 46px; }
  .topbar { padding: 4px 12px; }
  
  
  
  
  
  
  
  #table { min-height: 0; gap: 8px 14px; }
  .bottom { gap: 4px; padding-top: 2px; padding-bottom: 4px; }
  .prompt { padding: 4px 10px; }
  .p-sub { font-size: 12px; }
  button.act { padding: 4px 12px; }
  #hand { padding-top: 10px; min-height: calc(var(--card-h) + 10px); }
  
}

@media (max-width: 480px) {
  #mode-badge { font-size: 0; padding: 2px 6px; }
  #mode-badge::after { content: "🤫"; font-size: 13px; }
  .trump-badge { padding: 3px 8px; }
  .top-actions { gap: 4px; }
  .top-actions button.ghost { padding: 5px 9px; }
  .seats { margin: 48px auto 40px; }
}

/* Низкий экран (телефон горизонтально): всё компактно в одну колонку. */
@media (max-height: 500px) {
  :root { --card-w: 44px; }
  .topbar { padding: 3px 10px; }
  #timer { height: 3px; }
  
  
  
  
  
  
  
  
  .table-info { display: none; }
  .table-col { padding: 2px; border-radius: 16px; }
  #shown .shown-item { padding: 2px 6px 2px 2px; font-size: 11px; }
  .shown-item .card { width: 26px; height: 36px; font-size: 7px; }
  .bottom { gap: 3px; }
  .prompt { padding: 2px 10px; gap: 8px; }
  .p-icon { font-size: 18px; }
  .p-title { font-size: 14px; }
  .p-sub { display: none; }
  button.act { padding: 3px 10px; min-width: 84px; }
  button.act .st { display: none; }
  #hand { padding-top: 8px; min-height: calc(var(--card-w) * 1.4 + 8px); }
  
}

/* ---------- Четыре цвета мастей ---------- */
.suit-spades { color: #1d1d1f; }
.suit-clubs { color: #15803d; }
.suit-diamonds { color: #1d5fd1; }
.suit-hearts { color: #d32f2f; }
.trump-badge b.suit-spades { color: #fff; }
.trump-badge b.suit-clubs { color: #6ee7a0; }
.trump-badge b.suit-diamonds { color: #8ab8ff; }
.trump-badge b.suit-hearts { color: #ff8a80; }
.trump-only.suit-spades { color: #fff; }
.trump-only.suit-clubs { color: #6ee7a0; }
.trump-only.suit-diamonds { color: #8ab8ff; }
.trump-only.suit-hearts { color: #ff8a80; }

/* Крупный угловой индекс: масть и достоинство видно даже в веере */
.card .corner { width: 1.4em; }
.card .corner .r { font-size: 1.12em; }
.card .corner .s { font-size: 1.05em; margin-top: 0; }

/* ---------- Игровой стол: игроки на своих местах ---------- */
.arena { position: relative; flex: 1; min-height: 0; margin: 2px 12px 0; }
.game-oval { inset: 13% 12%; }
.oval-inner {
  position: absolute;
  inset: 6% 7%;
  display: flex;
  align-items: center;
  gap: 12px;
}
.oval-inner .table-col { flex: 1; min-width: 0; align-self: center; background: none; border: none; padding: 0; border-radius: 0; }
.oval-inner .pile-area { --card-w: 58px; --card-h: calc(58px * 1.4); }
.pile-area #deck { height: calc(var(--card-w) * 1.4); }
.pile-area #discard { height: calc(var(--card-w) * 1.4); }
.pile-label { color: #d9ecdf; }

.gseat {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 118px;
  max-width: 170px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .5);
  border: 2px solid rgba(255, 255, 255, .08);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 3;
  transition: border-color var(--med), box-shadow var(--med), opacity var(--med);
}
.gseat-row { display: flex; align-items: center; gap: 6px; max-width: 100%; }
.gseat .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.gseat .cards {
  flex: none;
  background: repeating-linear-gradient(45deg, #8e2430 0 3px, #a8323f 3px 6px);
  border: 1.5px solid #fff;
  border-radius: 4px;
  min-width: 22px;
  height: 28px;
  padding: 0 3px;
  font-size: 13px;
  font-weight: 800;
  line-height: 25px;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .8);
}
.gseat .tag { font-size: 11px; color: #ffcc80; }
.gseat.mine { background: rgba(224, 138, 46, .28); border-color: rgba(255, 224, 178, .7); }
.gseat.role-attack { border-color: var(--accent); }
.gseat.role-defend { border-color: var(--blue); }
.gseat.role-take { border-color: var(--red); }
.gseat.role-thrower { border-color: rgba(224, 138, 46, .6); }
.gseat.waiting { box-shadow: 0 0 0 3px rgba(255, 224, 130, .55), 0 0 22px rgba(255, 224, 130, .55); animation: wait-pulse 1.6s ease-in-out infinite; }
.gseat.offline { opacity: .55; }
.gseat.done { opacity: .7; }
@keyframes wait-pulse { 50% { box-shadow: 0 0 0 3px rgba(255, 224, 130, .25), 0 0 8px rgba(255, 224, 130, .2); } }

/* Облачко чата: у верхних мест — вниз, у нижних — вверх */
.gseat .bubble { top: calc(100% + 8px); }
.gseat.seat-0 .bubble, .gseat.seat-1 .bubble, .gseat.seat-5 .bubble { top: auto; bottom: calc(100% + 8px); }
.gseat.seat-0 .bubble::before, .gseat.seat-1 .bubble::before, .gseat.seat-5 .bubble::before {
  top: auto; bottom: -6px; border-bottom: none; border-top: 6px solid #fff;
}

/* Итоги партии — внизу, ничего не перекрывают */
.results {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: space-between;
  width: 100%;
  max-width: 760px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .35);
  border-left: 5px solid var(--green);
  animation: fade-up var(--med) ease-out;
}
.res-title { font-size: 18px; font-weight: 800; }
.res-score { font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; margin-top: 2px; }
.res-score .sc b { color: #ffe082; }
.res-score .sc.loser { color: #ffcc80; font-weight: 700; }
.muted-light { color: #b9d3c2; }
#pogony { color: #ffcc80; font-weight: 700; font-size: 14px; }
.res-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.res-hint { font-size: 12px; color: #cfe3d6; }

#notice.end { background: #fffdf7; color: var(--ink); border: 3px solid var(--accent); }

button.act { min-width: 96px; padding: 9px 18px; font-size: 15px; }

@media (max-width: 760px) {
  .arena { margin: 0 4px; }
  .game-oval { inset: 12% 15%; }
  .oval-inner { inset: 8% 6%; gap: 6px; }
  .oval-inner .pile-area { --card-w: 40px; }
  .discard-area { display: none; }
  #deck { transform: none; }
  .gseat { min-width: 0; max-width: 92px; padding: 4px 6px; gap: 2px; }
  .gseat .name { font-size: 11px; }
  .gseat .chip { font-size: 9px; padding: 2px 5px; }
  .gseat .cards { height: 22px; line-height: 19px; font-size: 11px; min-width: 18px; }
  .gseat .avatar.small { display: none; }
  .gseat.seat-1, .gseat.seat-2 { left: 12%; }
  .gseat.seat-4, .gseat.seat-5 { left: 88%; }
  .gseat.seat-0 { top: 94%; }
  .gseat.seat-3 { top: 6%; }
  .results { gap: 8px; }
}

@media (max-height: 500px) {
  .game-oval { inset: 14% 13%; }
  .gseat { flex-direction: row; padding: 2px 8px; max-width: 220px; }
  .gseat .tag { display: none; }
  .gseat .cards { height: 20px; line-height: 17px; font-size: 11px; }
  .oval-inner .pile-area { --card-w: 34px; }
  .pile-label { display: none; }
  .results { padding: 4px 10px; }
  .res-title { font-size: 15px; }
  .res-score { display: none; }
}

/* Боковые места прижаты к краям стола — не обрезаются на узких экранах */
.gseat.seat-1, .gseat.seat-2 { left: 4px; transform: translateY(-50%); }
.gseat.seat-4, .gseat.seat-5 { left: auto; right: 4px; transform: translateY(-50%); }
.gseat .chip { white-space: normal; text-align: center; line-height: 1.2; }
.slot { width: var(--card-w); height: calc(var(--card-w) * 1.4); border-radius: 6px; border: 2px dashed rgba(255, 255, 255, .2); }
#score { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; }
@media (max-width: 760px) {
  .gseat.seat-1, .gseat.seat-2 { left: 2px; }
  .gseat.seat-4, .gseat.seat-5 { right: 2px; left: auto; }
}
@media (max-height: 500px) { .gseat .chip { white-space: nowrap; } }
