:root {
  --bg: #0c1119;
  --panel: #151d29;
  --panel2: #1d2735;
  --line: #2a3849;
  --text: #e8eef5;
  --muted: #8898ac;
  --gold: #e0b055;
  --gold-dim: #8d7030;
  --red: #e05c57;
  --green: #46c463;
  --blue: #56a8ff;
  --radius: 12px;

  /* стол */
  --felt-1: #1d6b4f;
  --felt-2: #11402f;
  --felt-edge: #4a3320;

  /* кубики */
  --die-top: #ffffff;
  --die-front: #eceff3;
  --die-right: #c3cad3;
  --die-left: #b6bec8;
  --die-back: #d6dbe2;
  --die-bottom: #a7b0bb;
  --pip: #1b2027;
  --pip-hi: rgba(255, 255, 255, .55);
  --die-edge: rgba(0, 0, 0, .22);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  overflow: hidden;
}

#app { height: 100%; }
.view { display: none; height: 100%; }
.view.active { display: block; }
.view.active.centered { display: flex; align-items: center; justify-content: center; }
.view#view-game.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2f3f52; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3f536b; }

/* ============ КНОПКИ ============ */
.btn {
  font: inherit; font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: filter .15s, transform .08s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.18); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, #e6bd63, #bf8f2f);
  border-color: #6f551c;
  color: #241c05;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .28);
}
.btn-danger { background: linear-gradient(180deg, #e46a65, #b03a37); border-color: #7c2422; color: #fff; }
.btn-ghost { background: transparent; }
.btn-big { width: 100%; padding: 14px; font-size: 17px; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-xs { padding: 3px 9px; font-size: 12px; border-radius: 7px; }

.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  width: 32px; height: 32px; border-radius: 9px; cursor: pointer; font-size: 15px;
  display: grid; place-items: center; transition: filter .15s, background .15s;
}
.icon-btn:hover { filter: brightness(1.25); background: var(--panel2); }
.icon-btn.off { opacity: .4; }
.icon-btn.on { color: var(--gold); border-color: var(--gold-dim); }

/* ============ ГЛАВНЫЙ ЭКРАН ============ */
.home-card {
  width: min(440px, 94vw);
  padding: 28px 26px;
  background: linear-gradient(180deg, var(--panel), #101825);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, .6);
  max-height: 94%; overflow-y: auto;
}
.logo {
  font-size: 38px; letter-spacing: 4px; text-align: center;
  background: linear-gradient(180deg, #f6dc9d, #c69a37);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.tagline { text-align: center; color: var(--muted); margin: 6px 0 20px; font-size: 14px; }

.avatar-pick { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.avatar-big {
  width: 62px; height: 62px; flex: 0 0 auto;
  border-radius: 16px; font-size: 32px; cursor: pointer;
  background: linear-gradient(160deg, #2c3d54, #18212e);
  border: 1px solid var(--line);
  display: grid; place-items: center;
  transition: transform .12s, border-color .15s;
}
.avatar-big:hover { transform: scale(1.06); border-color: var(--gold); }
.avatar-meta { flex: 1; min-width: 0; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .6px; }
.field input {
  width: 100%; padding: 12px 14px; font: inherit;
  background: #0d141d; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.field input:focus { border-color: var(--gold); }
.field.compact { margin-bottom: 0; }
#input-code { text-transform: uppercase; letter-spacing: 6px; font-size: 20px; text-align: center; font-weight: 700; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 10px; cursor: pointer; }
.check input { accent-color: var(--gold); width: 15px; height: 15px; }

.lbl-short { display: none; }

.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 16px 0; font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.error { color: var(--red); min-height: 18px; font-size: 13px; text-align: center; margin-top: 8px; }
.home-actions { display: flex; gap: 8px; margin-top: 14px; }
.home-actions .btn { flex: 1; }

/* список публичных комнат на главной */
.rooms-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.rooms-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.room-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; font: inherit; cursor: pointer;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; color: var(--text);
  transition: border-color .15s, background .15s;
}
.room-item:hover { border-color: var(--gold); background: #26324a; }
.room-code-sm { font-size: 16px; font-weight: 800; letter-spacing: 3px; color: var(--gold); }
.room-who { display: flex; align-items: baseline; gap: 9px; min-width: 0; }
.room-host { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-players { font-size: 12px; color: var(--muted); }

/* ============ ЛОББИ ============ */
.lobby-card {
  width: min(560px, 94vw); margin: 3% auto; padding: 24px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, .55); max-height: 92%; overflow-y: auto;
}
.room-code-box {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #0d141d; border: 1px dashed var(--gold-dim);
  border-radius: 12px; padding: 13px 16px;
}
.label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.room-code { font-size: 32px; font-weight: 800; letter-spacing: 8px; color: var(--gold); line-height: 1.15; }
.small-code { font-size: 17px; letter-spacing: 4px; }

.lobby-heads { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; }
.section-title { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.bot-controls { display: flex; gap: 6px; align-items: center; }
.mini-field {
  display: inline-flex; align-items: center; gap: 7px;
  background: #0d141d; border: 1px solid var(--line); border-radius: 8px;
  padding: 0 6px 0 10px; height: 32px;
}
.mini-field-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); }
.mini-select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 5px 26px 5px 4px; margin: 0;
  background: transparent; color: var(--text); border: 0; outline: none; cursor: pointer;
  /* своя стрелка: нативная вылезала за границы кнопки */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%23e0b055' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 6px center; background-size: 11px;
}
.mini-select option { background: #0d141d; color: var(--text); }
.mini-field:focus-within { border-color: var(--gold-dim, var(--gold)); }

.player-list { list-style: none; display: flex; flex-direction: column; gap: 7px; min-height: 50px; }
.player-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 12px;
}
.player-item .pname { flex: 1; font-weight: 600; font-size: 14px; }
.player-item .tag { font-size: 11px; padding: 2px 8px; border-radius: 20px; background: #0d141d; color: var(--muted); border: 1px solid var(--line); }
.player-item .tag.host { color: var(--gold); border-color: var(--gold-dim); }
.player-item .tag.bot { color: #b98cff; border-color: #5b3d8a; }
.player-item.off { opacity: .45; }
.lobby-actions { margin-top: 18px; }
.lobby-foot { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }

.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 19px;
  background: linear-gradient(160deg, var(--av1, #2c3d54), var(--av2, #18212e));
  border: 1px solid var(--line);
}
.avatar.sm { width: 28px; height: 28px; font-size: 15px; border-radius: 8px; }
.avatar.lg { width: 42px; height: 42px; font-size: 23px; border-radius: 12px; }

.spectators { margin-top: 16px; }
.spec-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.spec-list.inline { flex-direction: row; flex-wrap: wrap; }
.spec-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; color: #a9b7c8; padding: 5px 9px; background: #0f1722; border-radius: 9px; border: 1px solid var(--line); }

/* ============ ИГРА: каркас ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 14px; background: #0a1017; border-bottom: 1px solid var(--line);
  flex: 0 0 auto; height: 52px;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-center { flex: 1; text-align: center; }
.status-chip {
  display: inline-block; padding: 5px 15px; border-radius: 20px;
  background: var(--panel2); border: 1px solid var(--line); font-size: 13px; font-weight: 600;
}
.turn-clock { color: var(--gold); font-variant-numeric: tabular-nums; }
.turn-clock.low { color: var(--red); }

.game-layout {
  flex: 1; display: grid;
  grid-template-columns: 244px minmax(0, 1fr) 292px;
  min-height: 0; overflow: hidden;
}

.panel { background: #0b1119; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }
.panel-title {
  padding: 9px 13px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); background: #0e151e; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.panel-subtitle { padding: 8px 13px; font-size: 10.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); border-top: 1px solid var(--line); }

/* ---- список игроков ---- */
.players-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.pl-card {
  display: flex; align-items: center; gap: 9px; position: relative;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 10px;
  transition: border-color .2s, box-shadow .2s, opacity .2s;
}
.pl-card.turn { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 20px rgba(224, 176, 85, .3); }
.pl-card.out { opacity: .34; filter: grayscale(1); }
.pl-card.me { background: #1a2534; }
/* игрок только что потерял кость — заметная одиночная вспышка в списке */
.pl-card.lost {
  border-color: var(--red);
  box-shadow: 0 0 0 1px var(--red), 0 0 24px rgba(224, 92, 87, .38);
  animation: lostPulse 1.3s ease-in-out infinite;
}
@keyframes lostPulse {
  50% { box-shadow: 0 0 0 1px var(--red), 0 0 34px rgba(224, 92, 87, .62); }
}
.pl-card.lost .pl-nm { color: #ffb6b2; }
.pl-card .lose-tag {
  flex: 0 0 auto; white-space: nowrap;
  font-size: 10px; font-weight: 800; letter-spacing: .3px; color: #fff;
  background: var(--red); border-radius: 20px; padding: 1px 7px;
  box-shadow: 0 0 8px rgba(224, 92, 87, .6);
  animation: losePop .3s ease;
}
@keyframes losePop { from { transform: scale(.5); opacity: 0; } }
/* реплика игрока: фиксированный слой над интерфейсом, иначе верх списка её режет */
.bubble {
  position: fixed; z-index: 80; max-width: 240px; pointer-events: none;
  padding: 6px 10px; border-radius: 10px;
  background: #f3e6c8; color: #241d10; font-size: 12.5px; font-weight: 600; line-height: 1.25;
  border: 1px solid #c9b184; box-shadow: 0 8px 22px rgba(0, 0, 0, .5);
  word-break: break-word; animation: bubbleIn .16s ease;
}
.bubble .bub-who {
  display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .6px;
  color: #8a6f3f; margin-bottom: 2px;
}
.bubble::after { content: ''; position: absolute; border: 6px solid transparent; }
.bubble[data-side="left"]::after   { left: -11px; top: 50%; margin-top: -6px; border-right-color: #f3e6c8; }
.bubble[data-side="bottom"]::after { left: 14px; bottom: -11px; border-top-color: #f3e6c8; }
.bubble[data-side="top"]::after    { left: 14px; top: -11px; border-bottom-color: #f3e6c8; }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(5px) scale(.94); } }
.pl-info { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.pl-nm { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-sub { font-size: 10.5px; color: var(--muted); display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.pl-dice { display: flex; gap: 2px; flex-wrap: wrap; }
/* наблюдателю — реальные кости игрока (мини-кубики) */
.pl-dice.god { align-items: center; gap: 3px; }
.pl-dice.god .die3d { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5)); }
.pl-dot { width: 7px; height: 7px; border-radius: 2px; background: var(--gold); box-shadow: 0 0 5px rgba(224, 176, 85, .6); }
.pl-dot.last { background: var(--red); box-shadow: 0 0 6px rgba(224, 92, 87, .8); animation: pulse 1.1s infinite; }

/* ---- лента игроков (узкий экран): компактные карточки-чипы ---- */
.players-strip { display: none; }
.players-strip .pl-card { flex: 0 0 auto; padding: 5px 8px; gap: 7px; max-width: 150px; }
.players-strip .pl-info { min-width: 0; }
.players-strip .pl-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players-strip .pl-badge { top: -5px; right: 6px; }
.players-strip .players-btn { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 980px) {
  .players-strip {
    display: flex; gap: 8px; align-items: center; padding: 2px 2px 6px;
    flex: 0 0 auto;
  }
}
#players-modal-list { max-height: 62vh; overflow-y: auto; }
@keyframes pulse { 50% { opacity: .35; } }
.pl-badge { position: absolute; right: 8px; top: -6px; font-size: 10px; background: #3a2a5c; color: #d5b9ff; border: 1px solid #5b3d8a; padding: 1px 7px; border-radius: 20px; }
.pl-badge.obs { background: #1f3348; color: #9fd0ff; border-color: #2f4f70; }

/* ---- центр ---- */
.table-area {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  padding: 14px 18px; gap: 12px; overflow-y: auto;
}

/* сцена стола: фельт + слой мест игроков вокруг него */
.table-stage { position: relative; flex: 1 1 0; min-height: 0; display: flex; }
/* flex-basis: 0 — высота стола считается от свободного места, а не от
   содержимого (иначе стол прыгал, когда ставка переносилась на 2 строки) */
.table-stage > .felt { flex: 1 1 0; }

/* ---- посадка игроков за столом ---- */
.seat-ring { position: absolute; inset: 0; z-index: 6; pointer-events: none; }
.seat {
  position: absolute; transform: translate(-50%, -50%);
  pointer-events: auto; max-width: 168px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .45);
}
.seat .pl-sub { font-size: 10px; }
/* в режиме посадки левая колонка больше не нужна — стол занимает её место */
.view.seats .game-layout { grid-template-columns: minmax(0, 1fr) 292px; }
.view.seats .panel-left { display: none; }
/* над столом и под ним резервируем полосы под места; min-height задан явно,
   чтобы высота не зависела от содержимого (ставка) */
.view.seats .table-stage { padding: 78px 0 64px; min-height: 258px; }
.view.seats .table-stage > .felt { min-height: 134px; }
/* 7–10 игроков: места по кольцу, стол уже, по бокам тоже полосы */
.view.seats.seats-many .table-stage { padding: 76px 132px 64px; }
.view.seats-many .seat { max-width: 124px; }
.view.seats-many .seat .pl-nm { font-size: 12px; }
.view.seats-many .seat .pl-sub { font-size: 9.5px; }
/* своё место — у нижней кромки стола */
.view.seats .seat-me { box-shadow: 0 0 0 1px var(--gold), 0 6px 20px rgba(0, 0, 0, .5); }
.view.seats .table-area { padding: 12px 18px 14px; }

/* ставка живёт прямо на сукне — стол не пустует */
.felt-bid {
  position: relative; z-index: 2; flex-direction: column; gap: 8px;
  font-size: clamp(28px, 4.4vw, 58px); font-weight: 900; text-align: center;
  letter-spacing: .5px; line-height: 1.1;
  color: #fff; text-shadow: 0 3px 14px rgba(0, 0, 0, .75), 0 1px 0 rgba(0, 0, 0, .5);
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  padding: 4px 10px; margin-bottom: 4px;
  max-width: 100%;
}
.felt-bid .hi { color: var(--gold); text-shadow: 0 3px 16px rgba(224, 176, 85, .5), 0 1px 0 rgba(0, 0, 0, .6); }
.felt-bid .hi { white-space: nowrap; }
.felt-bid .who {
  font-size: clamp(12px, 1.4vw, 20px); font-weight: 700; color: rgba(255, 255, 255, .68);
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 12px; border-radius: 20px; background: rgba(0, 0, 0, .22);
}
.felt-bid.idle { font-size: clamp(16px, 2.2vw, 30px); font-weight: 700; color: rgba(255, 255, 255, .45); text-shadow: 0 2px 10px rgba(0, 0, 0, .6); }
.felt-bid .maputo-tag {
  font-size: clamp(10px, .9vw, 14px); font-weight: 900; letter-spacing: 1.5px; color: #2a1200;
  background: linear-gradient(180deg, #ffb347, #ff8c00);
  padding: 4px 12px; border-radius: 20px; box-shadow: 0 0 18px rgba(255, 140, 0, .6);
}

.felt {
  position: relative; flex: 1 1 auto; min-height: 220px;
  border-radius: 26px;
  background:
    radial-gradient(ellipse at 50% 38%, var(--felt-1) 0%, var(--felt-2) 72%),
    /* ткань: мелкое переплетение нитей */
    repeating-linear-gradient(0deg, rgba(0,0,0,.05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(255,255,255,.03) 0 1px, transparent 1px 3px);
  /* деревянный борт: доски с тёмными швами, как обшивка корабля */
  border: 13px solid transparent;
  border-image: repeating-linear-gradient(90deg,
      var(--felt-edge) 0 25px,
      rgba(0, 0, 0, .55) 25px 28px,
      color-mix(in srgb, var(--felt-edge) 78%, #fff) 28px 51px,
      rgba(0, 0, 0, .5) 51px 54px) 13;
  box-shadow:
    inset 0 0 90px rgba(0, 0, 0, .62),
    inset 0 0 0 2px rgba(255, 255, 255, .05),
    0 14px 40px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 18px; overflow: hidden;
}
/* канатная прошивка по внутреннему краю борта */
.felt::before {
  content: ''; position: absolute; inset: 6px; border-radius: 17px;
  border: 2px dashed rgba(20, 12, 4, .5);
  box-shadow: inset 0 0 0 1px rgba(255, 236, 190, .09), 0 0 0 1px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.center-dice {
  display: flex; flex-wrap: wrap; gap: 2px 4px; justify-content: center; align-content: center;
  flex: 0 1 auto; min-height: 72px; max-height: 48%; overflow-y: auto; position: relative; z-index: 1;
  /* 3D-куб выступает за свою рамку примерно на 17% с каждой стороны */
  padding: 14px 10px;
  margin: -8px -6px;
  /* без видимой полосы прокрутки: один кубик не должен давать «полоску» */
  scrollbar-width: none;
}
.center-dice::-webkit-scrollbar { display: none; }

/* всплывающие реакции — фиксированный слой поверх всего, иначе на вскрытии
   результат перекрывал бы их */
.float-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
/* счётчик костей в центре нужен только там, где сам стол скрыт (телефон) */
.center-count { display: none; }

/* ---- реакции (Clash of Clans) ---- */
.float-emote {
  position: absolute; display: flex; flex-direction: column; align-items: center; gap: 2px;
  animation: floatUp 2.4s ease-out forwards; will-change: transform, opacity;
}
.float-emote .fe-emoji { font-size: 40px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .6)); animation: emotePop .45s cubic-bezier(.2, 1.4, .4, 1); }
.float-emote .fe-text {
  font-size: 11.5px; font-weight: 700; color: #fff; background: rgba(12, 18, 26, .88);
  padding: 3px 10px; border-radius: 20px; white-space: nowrap; border: 1px solid rgba(255, 255, 255, .14);
}
@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(.5); opacity: 0; }
  15% { transform: translate(-50%, -14px) scale(1.1); opacity: 1; }
  30% { transform: translate(-50%, -22px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -160px) scale(.85); opacity: 0; }
}
@keyframes emotePop { from { transform: scale(0) rotate(-25deg); } to { transform: scale(1) rotate(0); } }

/* пузырь над аватаркой */
.speech-bubble {
  position: absolute; z-index: 30; white-space: nowrap;
  top: -11px; left: 10px;
  background: linear-gradient(180deg, #fff, #e7ecf2); color: #10151c;
  font-size: 11.5px; font-weight: 700; padding: 4px 10px; border-radius: 14px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .55); pointer-events: none;
  animation: bubblePop .25s cubic-bezier(.2, 1.4, .4, 1) forwards;
}
.speech-bubble::after {
  content: ''; position: absolute; bottom: -5px; left: 14px;
  border: 5px solid transparent; border-top-color: #e7ecf2; border-bottom: 0;
}
@keyframes bubblePop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.react-bar { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; flex: 0 0 auto; }
.react-btn {
  width: 42px; height: 42px; border-radius: 12px; cursor: pointer; font-size: 21px;
  background: var(--panel2); border: 1px solid var(--line);
  display: grid; place-items: center; padding: 0;
  transition: transform .12s, border-color .15s, background .15s;
}
.react-btn:hover { transform: translateY(-3px) scale(1.08); border-color: var(--gold); background: #26324a; }
.react-btn:active { transform: scale(.94); }

/* ---- вскрытие ---- */
.reveal-box {
  flex: 0 0 auto;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; text-align: center;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(14px); opacity: 0; } }
.reveal-box .verdict { font-size: 19px; font-weight: 800; margin-bottom: 6px; letter-spacing: .3px; }
.reveal-box .verdict.lost { color: var(--red); }
.reveal-box .verdict.won { color: var(--green); }
.reveal-box .count-line {
  font-size: 13.5px; color: var(--muted); margin-bottom: 12px;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.lose-chip {
  font-size: 12px; font-weight: 700; color: #ffc9c6;
  background: rgba(224, 92, 87, .16); border: 1px solid rgba(224, 92, 87, .4);
  padding: 2px 10px; border-radius: 20px;
}
.reveal-box .count-line .bid-was { color: #ffd98a; }
.reveal-box .count-line .bid-was b { color: #fff2cf; }
.reveal-hands { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; padding: 6px 4px; }
.reveal-hand { text-align: center; }
.reveal-hand .hname { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.reveal-hand.loser .hname { color: var(--red); font-weight: 800; }
.reveal-hand .hand-dice { display: flex; gap: 0 4px; justify-content: center; }

.next-round {
  display: flex; flex-direction: column; align-items: center; gap: 9px; margin-top: 12px;
}
.next-btn { min-width: 190px; }
.next-btn:disabled { opacity: .75; cursor: default; }
.count-wrap { width: min(100%, 340px); display: flex; flex-direction: column; gap: 5px; }
.count-bar {
  height: 7px; border-radius: 20px; background: #0d141d;
  border: 1px solid var(--line); overflow: hidden;
}
.count-bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #e0b055, #f2d489); transition: width .1s linear; }
.count-text { font-size: 11.5px; color: var(--muted); text-align: center; min-height: 1em; }

/* Пока идёт вскрытие, ставка крупно показана в панели результатов,
   поэтому на сукне она лишняя — освобождаем место костям в центре. */
.table-area:has(#reveal-box:not(.hidden)) .felt-bid { display: none; }
.table-area:has(#reveal-box:not(.hidden)) .felt { min-height: 132px; }
.table-area:has(#reveal-box:not(.hidden)) .center-dice { max-height: 62%; }

/* ---- моя зона ---- */
.my-area { flex: 0 0 auto; display: flex; flex-direction: column; gap: 9px; }
.my-head { display: flex; align-items: center; justify-content: center; gap: 10px; }
.my-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.my-dice { display: flex; gap: 2px 6px; justify-content: center; flex-wrap: wrap; min-height: 58px; padding: 4px 6px; }

.action-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}
/* Панель хода держит постоянную высоту: иначе стол пересчитывал бы размер
   каждый ход то под большие контролы, то под строчку «Ходит X». */
#action-panel { min-height: 206px; display: flex; flex-direction: column; justify-content: center; }
.action-panel.waiting { text-align: center; color: var(--muted); padding: 18px; font-size: 14px; }
/* наблюдателю панель хода не нужна */
.view.observer #action-panel { display: none; }

.bid-row { display: flex; gap: 9px; align-items: center; justify-content: center; flex-wrap: wrap; }
.qty-stepper {
  display: inline-flex; align-items: stretch; gap: 0;
  border: 1px solid var(--line); border-radius: 11px; overflow: hidden; background: #0d141d;
}
.step-btn {
  font: inherit; font-size: 19px; font-weight: 700; line-height: 1;
  width: 40px; border: none; background: var(--panel2); color: var(--text);
  cursor: pointer; transition: background .12s, filter .12s;
}
.step-btn:hover { background: #2b3a4d; filter: brightness(1.2); }
.step-btn:active { transform: translateY(1px); }
.step-btn:disabled { opacity: .3; cursor: not-allowed; }
.qty-stepper input {
  width: 62px !important; padding: 8px 4px !important; font-size: 18px !important; font-weight: 800;
  text-align: center; border: none !important; border-left: 1px solid var(--line) !important;
  border-right: 1px solid var(--line) !important; border-radius: 0 !important; background: transparent;
  -moz-appearance: textfield;
}
.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.bid-row input {
  width: 76px; padding: 9px; font: inherit; font-size: 18px; font-weight: 800; text-align: center;
  background: #0d141d; color: var(--text); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
.bid-row input:focus { border-color: var(--gold); }
.bid-row .lbl { color: var(--muted); font-size: 14px; }

.face-picker { display: flex; gap: 7px; justify-content: center; margin: 10px 0; }
.face-btn {
  position: relative; color: #8c9bad;
  width: 46px; height: 46px; border-radius: 12px; cursor: pointer; padding: 3px;
  background: var(--panel2); border: 2px solid var(--line);
  display: grid; place-items: center;
  transition: border-color .15s, background .15s, transform .12s, opacity .15s;
}
.face-btn:hover { transform: translateY(-2px); }
.face-btn.tight { opacity: .42; }
.face-btn.tight:hover { opacity: .75; }
.face-btn.on { border-color: var(--gold); background: #2e2716; color: var(--gold); box-shadow: 0 0 14px rgba(224, 176, 85, .4); }
.face-btn.ban { opacity: .34; cursor: not-allowed; }
.face-btn.ban:hover { transform: none; opacity: .34; }
.face-btn.ban::after {
  content: ''; position: absolute; inset: 6px;
  background: linear-gradient(to top right, transparent calc(50% - 1px), rgba(220, 90, 90, .8) calc(50% - 1px), rgba(220, 90, 90, .8) calc(50% + 1px), transparent calc(50% + 1px));
  pointer-events: none;
}
.face-btn:disabled { opacity: .25; cursor: not-allowed; }

/* значок номинала: плоский и монохромный, чтобы не путать со своими костями */
.face-glyph {
  width: 100%; height: 100%; display: grid; place-items: center;
  border-radius: 9px;
  background: rgba(255, 255, 255, .05);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .09);
}
.face-glyph .pips {
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  width: 66%; height: 66%; gap: 4%;
}
.face-glyph .pip {
  border-radius: 50%; align-self: center; justify-self: center;
  width: 68%; height: 68%;
}
.face-glyph .pip.on { background: currentColor; box-shadow: 0 0 6px currentColor; }

.hint-row { font-size: 12px; color: var(--muted); text-align: center; line-height: 1.55; }
.hint-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 8px; }
.hint-toggle {
  font: inherit; font-size: 11.5px; color: var(--muted); cursor: pointer;
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 3px 11px; display: inline-flex; gap: 5px; align-items: center;
  transition: color .15s, border-color .15s, background .15s;
}
.hint-toggle:hover { color: var(--text); border-color: var(--gold); }
.hint-toggle.on { color: var(--gold); border-color: var(--gold); background: #2e2716; }
.maputo-warn { color: #ff9a3c; font-weight: 700; }

/* ---- чат / события ---- */
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; font-size: 13.5px; line-height: 1.55; }
.chat-msg { margin-bottom: 6px; word-break: break-word; }
.chat-msg.fresh { animation: slideUp .18s ease; }
.chat-msg .who { font-weight: 700; }
.chat-msg.sys { color: var(--muted); font-style: italic; font-size: 12.5px; }
.chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); flex: 0 0 auto; }
.chat-form input { flex: 1; min-width: 0; padding: 9px 11px; font: inherit; font-size: 13px; background: #0d141d; border: 1px solid var(--line); border-radius: 9px; color: var(--text); outline: none; }
.chat-form input:focus { border-color: var(--gold); }

.event-log { max-height: 38%; overflow-y: auto; padding: 10px 12px; font-size: 12.5px; line-height: 1.55; color: #9fb0c4; }
.event-log div { margin-bottom: 5px; padding-left: 9px; border-left: 2px solid var(--line); }
.event-log div:last-child { border-color: var(--gold); color: var(--text); }

/* ============ 3D КУБИКИ ============ */
.die3d { position: relative; flex: 0 0 auto; perspective: 420px; }
/* мягкая тень под костью — «приземляет» кубик на стол */
.die3d::before {
  content: ''; position: absolute; left: 50%; bottom: 2%; z-index: 0;
  width: 64%; height: 14%; transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, .5), rgba(0, 0, 0, 0) 72%);
  border-radius: 50%; pointer-events: none;
}
.die3d .tilt {
  position: absolute; inset: 0; z-index: 1;
  transform-style: preserve-3d;
  /* лёгкий наклон, чтобы куб читался объёмным, а не плоской картинкой */
  transform: rotateX(-14deg) rotateZ(-3deg);
}
.die3d .cube {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transform: var(--rot);
}
.die3d .face {
  position: absolute; inset: 0;
  border-radius: calc(var(--size) * .22);
  backface-visibility: hidden;
  box-shadow: inset 0 0 0 1px var(--die-edge);
  display: grid; place-items: center;
}
.die3d .f-top { background: var(--die-top, #fff); }
.die3d .f-front { background: var(--die-front, #eceff3); }
.die3d .f-right { background: var(--die-right, #c6ccd4); }
.die3d .f-left { background: var(--die-left, #b8c0c9); }
.die3d .f-back { background: var(--die-back, #d7dce2); }
.die3d .f-bottom { background: var(--die-bottom, #a9b2bc); }

/* блик и мягкая тень на гранях */
.die3d .face::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(150deg, rgba(255, 255, 255, .34), rgba(255, 255, 255, 0) 46%, rgba(0, 0, 0, .12));
}
.die3d .f-right::after, .die3d .f-bottom::after { background: linear-gradient(150deg, rgba(0, 0, 0, .16), rgba(0, 0, 0, .3)); }
.die3d .f-back::after, .die3d .f-left::after { background: linear-gradient(150deg, rgba(0, 0, 0, .06), rgba(0, 0, 0, .22)); }

.die3d .pips {
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  width: 74%; height: 74%; gap: 4%;
}
.die3d .pip {
  border-radius: 50%; align-self: center; justify-self: center;
  width: calc(var(--size) * .17); height: calc(var(--size) * .17);
}
.die3d .pip.on {
  background: radial-gradient(circle at 34% 30%, var(--pip-hi), transparent 58%), var(--pip);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .25), 0 1px 1px rgba(255, 255, 255, .35);
}
/* единица — одна крупная глазка, как на настоящих костях */
.die3d .face[data-face="1"] .pip.on { width: calc(var(--size) * .26); height: calc(var(--size) * .26); }

.die3d.spin .cube { animation: spin .6s cubic-bezier(.25, .9, .3, 1) both; }
@keyframes spin {
  from { transform: rotateX(1080deg) rotateY(1440deg) var(--rot); }
  to { transform: rotateX(0deg) rotateY(0deg) var(--rot); }
}

/* рубашка (скрытая кость) */
.die-back .back-face {
  position: absolute; inset: 0; border-radius: calc(var(--size) * .22);
  background:
    linear-gradient(150deg, rgba(255, 255, 255, .3), rgba(0, 0, 0, .18)),
    repeating-linear-gradient(45deg, #6d4a26 0 6px, #5b3d1f 6px 12px);
  border: 1px solid #3a2612;
  display: grid; place-items: center;
  box-shadow: inset 0 0 14px rgba(0, 0, 0, .5), 0 3px 8px rgba(0, 0, 0, .45);
  cursor: pointer; transition: transform .14s;
}
.die-back .back-face:hover { transform: scale(1.07) rotate(-3deg); }
.die-back .back-face span { font-size: calc(var(--size) * .38); color: rgba(255, 226, 170, .55); }

.die3d.blank .pips { visibility: hidden; }
/* гладкие кубы чуть сплющены по бликам, чтобы не выглядели пустыми */
.die3d.blank .face::after {
  background: linear-gradient(150deg, rgba(255, 255, 255, .3), rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, .16));
}

.die3d.tiny { --size: 26px; }
.die3d.small { --size: 34px; }

/* ============ СКИНЫ КОСТЕЙ ============ */
.die3d[data-skin="classic"] { --die-top:#fff; --die-front:#eceff3; --die-right:#c6ccd4; --die-left:#b8c0c9; --die-back:#d7dce2; --die-bottom:#a9b2bc; --pip:#1b2027; --pip-hi:rgba(255,255,255,.55); }

.die3d[data-skin="gold"] { --die-top:#ffe9a8; --die-front:#f0c95e; --die-right:#cf9f38; --die-left:#bd8f2e; --die-back:#e0b64c; --die-bottom:#a87b26; --pip:#3a2606; --pip-hi:rgba(255,255,255,.4); }

.die3d[data-skin="obsidian"] { --die-top:#4a5563; --die-front:#313b47; --die-right:#222a34; --die-left:#1c232c; --die-back:#2a333e; --die-bottom:#151b22; --pip:#eaf0f7; --pip-hi:rgba(255,255,255,.75); --die-edge:rgba(255,255,255,.09); }
.die3d[data-skin="obsidian"] .face::after { background: linear-gradient(150deg, rgba(255,255,255,.16), rgba(0,0,0,.34)); }

.die3d[data-skin="bone"] { --die-top:#f6efdd; --die-front:#e8dfc7; --die-right:#cfc3a6; --die-left:#c2b599; --die-back:#dcd1b5; --die-bottom:#b0a488; --pip:#4a3c22; --pip-hi:rgba(255,255,255,.4); }
.die3d[data-skin="bone"] .pip.on { border-radius: 40%; }

.die3d[data-skin="blood"] { --die-top:#ff9d9d; --die-front:#d94141; --die-right:#a82a2a; --die-left:#962424; --die-back:#c03535; --die-bottom:#7d1d1d; --pip:#2a0505; --pip-hi:rgba(255,255,255,.3); --die-edge:rgba(0,0,0,.3); }
.die3d[data-skin="blood"] .pip.on { box-shadow: inset 0 0 0 1px rgba(0,0,0,.3), 0 0 8px rgba(255,80,80,.7); }

.die3d[data-skin="ice"] { --die-top:#e8fbff; --die-front:#a5e4f5; --die-right:#6ec5de; --die-left:#5cb0c9; --die-back:#8ed4e8; --die-bottom:#489aae; --pip:#06303d; --pip-hi:rgba(255,255,255,.6); }
.die3d[data-skin="ice"] .face { box-shadow: inset 0 0 0 1px rgba(255,255,255,.35), 0 0 14px rgba(120,220,255,.28); }

.die3d[data-skin="neon"] { --die-top:#e9ffe0; --die-front:#8ef56b; --die-right:#39c04a; --die-left:#2ba53c; --die-back:#63d95f; --die-bottom:#1f8a33; --pip:#06300f; --pip-hi:rgba(255,255,255,.5); --die-edge:rgba(0,0,0,.25); }
.die3d[data-skin="neon"] .face { box-shadow: inset 0 0 0 1px rgba(0,0,0,.2), 0 0 16px rgba(90,240,120,.55); }

.die3d[data-skin="pirate"] { --die-top:#d9a55e; --die-front:#b8813f; --die-right:#8f6129; --die-left:#7d551f; --die-back:#a57438; --die-bottom:#653f15; --pip:#2a1a06; --pip-hi:rgba(255,235,190,.35); --die-edge:rgba(0,0,0,.3); }
.die3d[data-skin="pirate"] .face::after {
  background:
    radial-gradient(circle at 26% 24%, rgba(255,255,255,.25), transparent 42%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M2 12c6 3 10-3 16 0s10-3 20 0' stroke='rgba(0,0,0,.22)' fill='none' stroke-width='2'/%3E%3C/svg%3E");
}

/* ============ СТОЛЫ (фоны стола) ============ */
/* пиратские столы: палуба, трюм, таверна, остров */
[data-table="planks"] { --felt-1:#a8794a; --felt-2:#5b3a1c; --felt-edge:#6b4a26; }
[data-table="hold"]   { --felt-1:#3a352c; --felt-2:#141210; --felt-edge:#2b2620; }
[data-table="tavern"] { --felt-1:#8a4b26; --felt-2:#44200f; --felt-edge:#5a2f18; }
[data-table="island"] { --felt-1:#2f8f7a; --felt-2:#12463a; --felt-edge:#7a5a30; }

[data-table="deep"]   { --felt-1:#1d6b4f; --felt-2:#0f3b2b; --felt-edge:#4a3320; }
[data-table="ocean"]  { --felt-1:#1b5f86; --felt-2:#0d2f47; --felt-edge:#1d3a4d; }
[data-table="ember"]  { --felt-1:#8a3320; --felt-2:#4a1610; --felt-edge:#3a2418; }
[data-table="royal"]  { --felt-1:#5a2d7a; --felt-2:#2c1245; --felt-edge:#3b2352; }
[data-table="night"]  { --felt-1:#1f2430; --felt-2:#0c0f16; --felt-edge:#2a3040; }
[data-table="sand"]   { --felt-1:#a8804a; --felt-2:#6b4a22; --felt-edge:#4a3418; }

/* текстура нового стола ложится между сукном и костями */
.felt::after { content: ''; position: absolute; inset: 0; pointer-events: none; background-size: cover; }
[data-table="planks"] .felt::after {
  background-image:
    repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 2px, transparent 2px 32px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.16) 0 2px, transparent 2px 140px);
}
[data-table="hold"] .felt::after {
  background-image:
    radial-gradient(circle at 22% 26%, rgba(255,200,120,.07), transparent 42%),
    radial-gradient(circle at 78% 72%, rgba(255,180,90,.06), transparent 46%),
    repeating-linear-gradient(90deg, rgba(0,0,0,.34) 0 3px, transparent 3px 46px);
}
[data-table="tavern"] .felt::after {
  background-image: radial-gradient(ellipse at 50% 0%, rgba(255,170,80,.16), transparent 62%);
}
[data-table="island"] .felt::after {
  background-image:
    radial-gradient(circle at 68% 28%, rgba(255,240,190,.16), transparent 32%),
    repeating-radial-gradient(circle at 30% 72%, rgba(255,255,255,.05) 0 2px, transparent 2px 14px);
}

/* ============ ФОНЫ СТРАНИЦЫ ============ */
[data-bg="deep"]   { background: radial-gradient(circle at 50% 0%, #1b2635 0%, #0c1119 55%); }
[data-bg="ocean"]  { background: radial-gradient(circle at 50% 0%, #16354a 0%, #08131c 55%); }
[data-bg="ember"]  { background: radial-gradient(circle at 50% 0%, #3d2118 0%, #150c08 55%); }
[data-bg="royal"]  { background: radial-gradient(circle at 50% 0%, #2e1c44 0%, #120b1c 55%); }
[data-bg="forest"] { background: radial-gradient(circle at 50% 0%, #16321f 0%, #08120c 55%); }
[data-bg="mono"]   { background: radial-gradient(circle at 50% 0%, #23262b 0%, #0b0d10 55%); }

/* ============ МОДАЛКИ ============ */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(5, 8, 13, .78); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .16s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-card {
  width: min(560px, 100%); max-height: 88%; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7);
  animation: slideUp .22s ease;
}
.modal-card.narrow { width: min(400px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px; border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 18px; overflow-y: auto; }
.confirm-text { margin: 0 0 16px; font-size: 14px; line-height: 1.55; color: #c3ceda; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.setting-row { margin-bottom: 20px; }
.setting-row:last-child { margin-bottom: 0; }
/* свои реакции в настройках */
.custom-reactions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.custom-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 20px;
  padding: 3px 4px 3px 10px; font-size: 12.5px;
}
.custom-del { border: none; background: transparent; color: var(--red); cursor: pointer; font-size: 12px; padding: 0 3px; }
.custom-add { display: flex; gap: 6px; }
.custom-add input {
  padding: 7px 9px; font: inherit; font-size: 13px;
  background: #0d141d; border: 1px solid var(--line); border-radius: 9px; color: var(--text); outline: none;
}
.custom-add input:focus { border-color: var(--gold); }
.custom-add #custom-emoji { width: 54px; text-align: center; }
.custom-add #custom-text { flex: 1; min-width: 0; }

/* ---- тумблеры (меню создания комнаты) ---- */
.toggle-list { display: flex; flex-direction: column; gap: 8px; }
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; cursor: pointer;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 13px;
  transition: border-color .15s, background .15s;
}
.toggle:hover { border-color: #4a5f7a; }
.toggle-select { cursor: default; }
.toggle-select .mini-select { flex: 0 0 auto; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.tgl-label { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tgl-title { font-size: 14px; font-weight: 600; color: var(--text); }
.tgl-desc { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.switch {
  position: relative; flex: 0 0 auto; width: 46px; height: 27px; border-radius: 999px;
  background: #2a3849; border: 1px solid var(--line); transition: background .18s, border-color .18s;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%;
  background: #e8eef5; box-shadow: 0 2px 5px rgba(0, 0, 0, .4); transition: transform .18s;
}
.toggle input:checked ~ .switch { background: var(--gold); border-color: var(--gold); }
.toggle input:checked ~ .switch::after { transform: translateX(19px); background: #fff; }
.toggle input:focus-visible ~ .switch { box-shadow: 0 0 0 3px rgba(224, 176, 85, .35); }
.toggle:has(input:checked) { border-color: rgba(224, 176, 85, .5); background: #20283a; }
.lobby-settings { margin-top: 14px; }
.setting-label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 9px; }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 7px; }
.avatar-grid.big { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
.avatar-opt {
  aspect-ratio: 1; border-radius: 12px; cursor: pointer; font-size: 23px;
  background: linear-gradient(160deg, var(--av1, #2c3d54), var(--av2, #18212e));
  border: 2px solid var(--line); display: grid; place-items: center;
  transition: transform .12s, border-color .15s;
}
.avatar-opt:hover { transform: scale(1.1); border-color: var(--gold); }
.avatar-opt.on { border-color: var(--gold); box-shadow: 0 0 12px rgba(224, 176, 85, .5); }

.skin-row { display: flex; gap: 10px; flex-wrap: wrap; }
.skin-opt {
  width: 56px; height: 56px; border-radius: 14px; cursor: pointer; padding: 5px;
  background: #0d141d; border: 2px solid var(--line);
  display: grid; place-items: center;
  transition: transform .12s, border-color .15s;
}
.skin-opt:hover { transform: translateY(-2px); }
.skin-opt.on { border-color: var(--gold); box-shadow: 0 0 14px rgba(224, 176, 85, .45); }
.skin-opt .die3d { pointer-events: none; }

.table-row, .bg-row { display: flex; gap: 8px; flex-wrap: wrap; }
.bg-opt {
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600;
  border: 2px solid var(--line); background: #0d141d; color: var(--text);
  transition: border-color .15s, transform .12s;
}
.bg-opt:hover { transform: translateY(-2px); }
.bg-opt.on { border-color: var(--gold); }
.bg-opt .swatch { display: block; width: 26px; height: 12px; border-radius: 4px; margin: 0 auto 5px; }
.bg-opt.felt-opt { display: flex; align-items: center; gap: 7px; }

.reveal-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.reveal-opt { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; text-align: left; padding: 9px 12px; }
.reveal-opt small { font-size: 10.5px; color: var(--muted); font-weight: 500; line-height: 1.3; }

.sound-row { display: flex; align-items: center; gap: 12px; }
.sound-row input[type=range] { flex: 1; accent-color: var(--gold); }

.rules-body { font-size: 14px; color: #c2cddb; line-height: 1.65; }
.rules-body h4 { color: var(--gold); margin: 14px 0 6px; font-size: 14px; }
.rules-body ul { margin: 6px 0 10px 18px; }
.rules-body li { margin-bottom: 5px; }
.rules-body p { margin-bottom: 9px; }

/* ============ ПАНЕЛЬ ЭМОДЗИ ============ */
.emote-pad {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 55; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 12px; box-shadow: 0 18px 50px rgba(0, 0, 0, .65);
  animation: slideUp .2s ease;
}
.emote-grid { display: grid; grid-template-columns: repeat(6, 54px); gap: 8px; }
.emote-opt {
  width: 54px; height: 54px; border-radius: 13px; cursor: pointer; font-size: 24px;
  background: var(--panel2); border: 1px solid var(--line);
  display: grid; place-items: center; padding: 0; position: relative;
  transition: transform .12s, border-color .15s, background .15s;
}
.emote-opt:hover { transform: translateY(-3px) scale(1.1); border-color: var(--gold); background: #26324a; }
.emote-opt small {
  position: absolute; bottom: -17px; left: 50%; transform: translateX(-50%);
  font-size: 9.5px; color: var(--muted); white-space: nowrap;
}
.emote-wrap { position: relative; }

/* ============ ФИНАЛ ============ */
.game-over {
  position: fixed; inset: 0; z-index: 70;
  background: radial-gradient(circle at 50% 40%, rgba(20, 30, 45, .93), rgba(5, 8, 13, .97));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  text-align: center; padding: 20px; animation: fadeIn .3s ease;
}
.game-over .crown { font-size: 72px; animation: emotePop .6s cubic-bezier(.2, 1.4, .4, 1); }
.game-over .winner { font-size: 34px; font-weight: 800; color: var(--gold); }
.game-over .win-avatar { font-size: 46px; }
.game-over .sub { color: var(--muted); font-size: 14px; max-width: 430px; line-height: 1.6; }
.game-over .btn { width: auto; padding: 13px 34px; font-size: 16px; margin-top: 6px; }

/* ============ ТОСТЫ / АНИМАЦИИ ============ */
.home-banner {
  background: #2c1a1a; border: 1px solid var(--red); color: #ffb4b1;
  padding: 11px 16px; border-radius: 10px; font-size: 13.5px; line-height: 1.5;
  margin-bottom: 16px; text-align: left;
  animation: slideUp .22s ease;
}
.home-banner b { color: #ffd0ce; }
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #2c1a1a; border: 1px solid var(--red); color: #ffb4b1;
  padding: 11px 20px; border-radius: 10px; font-size: 14px; z-index: 90;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55);
  animation: slideUp .18s ease;
}
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
.pop { animation: pop .3s ease backwards; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
.shake { animation: shake .3s; }

/* «тряска костей» — анимация стола при броске */
.felt.shaking { animation: feltShake .5s ease; }
@keyframes feltShake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  15% { transform: translate(-3px, 2px) rotate(-.35deg); }
  30% { transform: translate(3px, -2px) rotate(.35deg); }
  45% { transform: translate(-2px, -1px) rotate(-.2deg); }
  60% { transform: translate(2px, 1px) rotate(.2deg); }
  80% { transform: translate(-1px, 1px) rotate(-.1deg); }
}
.die3d.drop { animation: dropIn .42s cubic-bezier(.2, 1.5, .4, 1) backwards; }
.die3d.drop::before { content: ''; position: absolute; left: 18%; right: 18%; bottom: 6px; height: 5px; border-radius: 50%; background: rgba(0, 0, 0, .45); filter: blur(3px); z-index: -1; }
@keyframes dropIn { from { transform: translateY(-42px) scale(.5); opacity: 0; } }

/* режим без анимаций */
[data-anim="off"] .felt.shaking, [data-anim="off"] .die3d.spin .cube, [data-anim="off"] .die3d.drop { animation: none !important; }
[data-anim="off"] .float-emote { animation-duration: 1.2s; }

/* ============ КРУПНЫЕ ЭКРАНЫ (2K, 4K) ============
   Интерфейс свёрстан в «пикселях дизайна», поэтому на больших мониторах
   масштабируем весь документ через zoom: это поднимает и шрифты, и отступы,
   и размеры 3D-костей разом, ничего не разъезжаясь. */
@media (min-width: 1700px) { html { zoom: 1.1; } }
@media (min-width: 2000px) { html { zoom: 1.24; } }
@media (min-width: 2400px) { html { zoom: 1.4; } }
@media (min-width: 3200px) { html { zoom: 1.7; } }

/* но на низких широких экранах не раздуваем */
@media (min-width: 1700px) and (max-height: 800px) { html { zoom: 1; } }
@media (min-width: 2000px) and (max-height: 950px) { html { zoom: 1.05; } }

/* ============ АДАПТИВ ============ */
@media (max-width: 1180px) {
  .game-layout { grid-template-columns: 210px minmax(0, 1fr) 250px; }
}
@media (max-width: 980px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 250px; }
  .panel-left { display: none; }
  .table-area { padding: 10px 12px; }
}
@media (max-width: 760px) {
  /* Вертикальный бюджет телефона (проверено на 320×568 … 430×932):
     топбар 42 + стол ~80 + кости 44 + панель ~140 + реакции 38 + чат ~104.
     Всё обязано помещаться без прокрутки — иначе кнопку «Сказать» не достать. */
  .game-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .panel-right { border-left: none; border-top: 1px solid var(--line); min-height: 0; }
  .panel-right .panel-title { padding: 6px 10px; }
  /* события на телефоне прячем под кнопку, чат при этом крупнее */
  #events-title { cursor: pointer; }
  #events-title::after { content: ' ▾'; color: var(--muted); }
  .panel-right.events-open #events-title::after { content: ' ▴'; }
  .chat-log { flex: 1 1 auto; min-height: 60px; height: auto; padding: 6px 9px; font-size: 12.5px; }
  .event-log { display: none; }
  .panel-right.events-open .event-log {
    display: block; flex: 1 1 auto; min-height: 0; max-height: none; padding: 6px 9px; font-size: 11.5px;
  }
  .chat-form { padding: 5px 6px; }
  .chat-form input { padding: 7px 9px; }

  .table-area { padding: 6px; gap: 6px; }

  /* стол на телефоне убираем — вместо него тонкая строка ставки */
  .felt {
    flex: 0 0 auto; height: 46px; min-height: 0;
    border: 1px solid var(--line); border-image: none; border-radius: 12px;
    background: var(--panel); box-shadow: inset 0 0 30px rgba(0, 0, 0, .35);
    padding: 4px 12px; overflow: visible;
  }
  .felt::before, .felt::after { display: none; }
  .felt-bid { flex-wrap: nowrap; gap: 8px; margin: 0; padding: 0; font-size: clamp(16px, 4.8vw, 22px); }
  .felt-bid .who { font-size: 11px; padding: 2px 9px; }
  .felt-bid .maputo-tag { font-size: 9px; padding: 2px 8px; letter-spacing: .5px; }
  .center-dice { display: none; }
  .center-count {
    display: block; position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    font-size: 10.5px; color: var(--muted); white-space: nowrap;
  }
  /* стол убран — сцена не растягивается, контент собираем плотно сверху,
     а лишнюю высоту забирает чат (иначе оставались пустые дыры) */
  .table-stage { flex: 0 0 auto; }
  .table-stage > .felt { flex: 1 1 auto; }
  .my-area { flex: 0 0 auto; justify-content: flex-start; }
  /* реакции всплывают поверх всего экрана, а не внутри узкой строки ставки */
  .float-layer { position: fixed; inset: 0; overflow: hidden; z-index: 90; }
  .felt.shaking { animation: none; }

  .my-head { display: none; }
  .my-dice { gap: 5px; min-height: 0; }
  .my-dice .die3d { width: 46px !important; height: 46px !important; --size: 46px !important; }
  .my-dice .die-back { width: 46px !important; height: 46px !important; }

  .action-panel { padding: 7px 8px; }
  .face-picker { margin: 6px 0; gap: 4px; }
  .face-btn { width: 36px; height: 36px; padding: 2px; }
  .face-btn .die3d { width: 28px !important; height: 28px !important; --size: 28px !important; }
  .bid-row { gap: 6px; }
  .qty-stepper {
  display: inline-flex; align-items: stretch; gap: 0;
  border: 1px solid var(--line); border-radius: 11px; overflow: hidden; background: #0d141d;
}
.step-btn {
  font: inherit; font-size: 19px; font-weight: 700; line-height: 1;
  width: 40px; border: none; background: var(--panel2); color: var(--text);
  cursor: pointer; transition: background .12s, filter .12s;
}
.step-btn:hover { background: #2b3a4d; filter: brightness(1.2); }
.step-btn:active { transform: translateY(1px); }
.step-btn:disabled { opacity: .3; cursor: not-allowed; }
.qty-stepper input {
  width: 62px !important; padding: 8px 4px !important; font-size: 18px !important; font-weight: 800;
  text-align: center; border: none !important; border-left: 1px solid var(--line) !important;
  border-right: 1px solid var(--line) !important; border-radius: 0 !important; background: transparent;
  -moz-appearance: textfield;
}
.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.bid-row input { width: 54px; padding: 6px; font-size: 15px; }
  .action-panel .btn { padding: 8px 11px; font-size: 13.5px; }
  .hint-row { font-size: 10.5px; margin-top: 4px; line-height: 1.4; }

  /* реакции в одну прокручиваемую строку — экономим целый ряд */
  .react-bar {
    flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
    gap: 5px; padding-bottom: 2px; scrollbar-width: none;
  }
  .react-bar::-webkit-scrollbar { display: none; }
  .react-btn { width: 36px; height: 36px; font-size: 17px; flex: 0 0 auto; }

  /* вскрытие не должно выпихивать кнопку «Продолжить»:
     стол ужимается до минимума, результаты скроллятся внутри своей панели */
  .table-area:has(#reveal-box:not(.hidden)) .felt { display: none; }
  /* во вскрытии своя кнопка «Дальше» — пустая панель хода на телефоне лишняя */
  .table-area:has(#reveal-box:not(.hidden)) #action-panel { display: none; }
  .table-area:has(#reveal-box:not(.hidden)) .reveal-box {
    flex: 1 1 auto; min-height: 0; overflow-y: auto;
  }
  .reveal-box { padding: 8px 10px; }
  .reveal-box .verdict { font-size: 14px; }
  .reveal-box .count-line { font-size: 11.5px; margin-bottom: 8px; }
  .reveal-hands { gap: 10px; }
  .reveal-hand .die3d { width: 26px !important; height: 26px !important; --size: 26px !important; }

  .topbar { height: auto; padding: 5px 8px; gap: 5px; flex-wrap: nowrap; }
  .topbar .label { display: none; }
  .topbar-left { gap: 5px; }
  #btn-copy-game { display: none; }
  .small-code { font-size: 14px; letter-spacing: 2px; }
  .status-chip { font-size: 11px; padding: 3px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
  .topbar-left { min-width: 0; }
  .topbar-right { flex: 0 0 auto; }
  .topbar-center { min-width: 0; }
  .icon-btn { width: 28px; height: 28px; font-size: 13px; }
  #btn-leave { padding: 5px 9px; font-size: 12px; }

  .emote-grid { grid-template-columns: repeat(4, 50px); }
  .emote-opt { width: 50px; height: 50px; }
  /* настройки на телефоне компактнее, чтобы меньше крутить */
  .modal-card { max-height: 92%; }
  .modal-body { padding: 12px; }
  .avatar-grid { grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 5px; }
  .avatar-grid.big { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); }
  .setting-row { margin-bottom: 14px; }
  .logo { font-size: 30px; }
  .room-code { font-size: 25px; letter-spacing: 5px; }
  .player-item { padding: 8px 10px; }
  .room-code-box { padding: 11px 13px; gap: 8px; }
  .room-code { font-size: 24px; letter-spacing: 4px; }
  #btn-copy { padding: 9px 13px; white-space: nowrap; }
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .bot-controls { gap: 5px; }
  .mini-select { padding: 5px 6px; font-size: 12px; }
  .avatar-big { width: 54px; height: 54px; font-size: 27px; }
}

/* телефоны в ландшафте и прочие низкие экраны: вертикали почти нет,
   поэтому жёсткий бюджет — стол 70px, панель ~130px, остальное прячем */
@media (max-height: 500px) {
  .felt { flex: 0 0 auto; height: 70px; min-height: 0; border-width: 5px; border-radius: 12px; padding: 6px; }
  .felt-bid { font-size: clamp(15px, 3.2vw, 26px); margin-bottom: 0; }
  .felt-bid.idle { font-size: clamp(12px, 2vw, 17px); }
  .center-dice { max-height: 30%; gap: 4px; }

  .table-area { padding: 5px; gap: 5px; }
  .my-dice { min-height: 0; }
  .my-dice .die3d { width: 32px !important; height: 32px !important; --size: 32px !important; }

  .action-panel { padding: 5px 7px; }
  .face-picker { margin: 4px 0; gap: 3px; }
  .face-btn { width: 30px; height: 30px; padding: 1px; }
  .face-btn .die3d { width: 23px !important; height: 23px !important; --size: 23px !important; }
  .bid-row { gap: 5px; }
  .qty-stepper {
  display: inline-flex; align-items: stretch; gap: 0;
  border: 1px solid var(--line); border-radius: 11px; overflow: hidden; background: #0d141d;
}
.step-btn {
  font: inherit; font-size: 19px; font-weight: 700; line-height: 1;
  width: 40px; border: none; background: var(--panel2); color: var(--text);
  cursor: pointer; transition: background .12s, filter .12s;
}
.step-btn:hover { background: #2b3a4d; filter: brightness(1.2); }
.step-btn:active { transform: translateY(1px); }
.step-btn:disabled { opacity: .3; cursor: not-allowed; }
.qty-stepper input {
  width: 62px !important; padding: 8px 4px !important; font-size: 18px !important; font-weight: 800;
  text-align: center; border: none !important; border-left: 1px solid var(--line) !important;
  border-right: 1px solid var(--line) !important; border-radius: 0 !important; background: transparent;
  -moz-appearance: textfield;
}
.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.bid-row input { width: 46px; padding: 5px; font-size: 14px; }
  .action-panel .btn { padding: 6px 9px; font-size: 12.5px; }

  .react-bar { display: none; }
  .hint-wrap { margin-top: 4px; gap: 4px; }
  .hint-toggle { font-size: 11px; padding: 2px 9px; }
  .hint-row { font-size: 10.5px; line-height: 1.4; }
  .panel-title { display: none; }
  .chat-log { height: auto; }

  .reveal-box { padding: 6px 8px; }
  .reveal-box .verdict { font-size: 13px; }
  .reveal-box .count-line { font-size: 11px; margin-bottom: 6px; }
  .reveal-hand .die3d { width: 22px !important; height: 22px !important; --size: 22px !important; }
}

/* низкие экраны — компактный режим */
@media (max-height: 720px) and (min-width: 761px) {
  .felt { min-height: 130px; border-width: 9px; }
  .my-dice { min-height: 0; }
  .react-btn { width: 36px; height: 36px; font-size: 17px; }
  .die3d { --size: 40px !important; width: 40px !important; height: 40px !important; }
  .face-btn { width: 40px; height: 40px; }
}