:root {
  --bg: #14110f;
  --bg-soft: #1c1815;
  --panel: #221d19;
  --panel-2: #2a241f;
  --line: #3a312a;
  --text: #ece3d8;
  --muted: #9d9186;
  --gold: #e8c07d;
  --gold-dim: #b8945c;
  --accent: #5a8f6f;
  --danger: #c05b4a;
  --white-chip: #efe3cd;
  --black-chip: #2f2a26;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 700px at 50% -10%, #241e19 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0 0 12px; font-weight: 650; letter-spacing: .2px; }
h1 { font-size: 27px; }
h2 { font-size: 16px; color: var(--gold); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 1px; }
.hidden { display: none !important; }
.grow { flex: 1 1 auto; }

/* ── Экраны ─────────────────────────────────────────────── */
.screen { display: none; min-height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* ── Авторизация ───────────────────────────────────────── */
#screen-auth { align-items: center; justify-content: center; padding: 24px; }

.auth-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel) 0%, #1e1a16 100%);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 30px 28px 24px;
  box-shadow: var(--shadow);
}

.brand { text-align: center; margin-bottom: 22px; }
.brand-dice { font-size: 34px; letter-spacing: 6px; color: var(--gold); }
.brand p { margin: 6px 0 0; font-size: 14px; }

.tabs { display: flex; gap: 6px; background: var(--bg-soft); padding: 4px; border-radius: 12px; margin-bottom: 18px; }
.tab {
  flex: 1; padding: 9px; border: 0; border-radius: 9px; cursor: pointer;
  background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  transition: .15s;
}
.tab.active { background: var(--panel-2); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.3); }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form.compact { gap: 10px; margin-top: 10px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }

input, select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  min-width: 0;
}
input:focus, select:focus { border-color: var(--gold-dim); box-shadow: 0 0 0 3px rgba(232,192,125,.12); }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--gold); padding: 0; }
input[type="color"] { padding: 2px; height: 36px; width: 56px; cursor: pointer; }

.btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--gold-dim); transform: translateY(-1px); }
.btn:disabled { opacity: .38; filter: grayscale(.4); cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, var(--gold) 0%, var(--gold-dim) 100%); color: #241c10; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { color: #ffc9be; border-color: #5a332c; }
.btn.danger:hover:not(:disabled) { border-color: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; }

.error { color: #ff9d8a; min-height: 20px; font-size: 13px; margin: 12px 0 0; }

/* ── Верхняя панель ────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px;
  background: rgba(28, 24, 21, .8);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.logo { font-size: 16px; display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.pill {
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 4px 11px; border-radius: 999px; font-size: 13px;
}
.pill.gold { color: var(--gold); border-color: var(--gold-dim); }

/* ── Лобби ─────────────────────────────────────────────── */
.lobby {
  display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 18px; padding: 18px; max-width: 1180px; margin: 0 auto; width: 100%;
}
.col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }

.row-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row-form .btn { height: 40px; }

.rooms { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.room {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: 11px;
  background: var(--bg-soft); border: 1px solid transparent;
  transition: .15s;
}
.room:hover { border-color: var(--gold-dim); }
.room .rname { font-weight: 600; }
.room .rmeta { color: var(--muted); font-size: 13px; }
.room .spacer { flex: 1; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: #2f3c33; color: #9ed7b4; border: 1px solid #3c5245;
}
.badge.playing { background: #3b2f26; color: #e0b27e; border-color: #55402f; }

/* ── Профиль ───────────────────────────────────────────── */
.profile-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.big { font-size: 18px; font-weight: 650; }
.chip-preview {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 -3px 6px rgba(0,0,0,.35), inset 0 3px 6px rgba(255,255,255,.28);
  border: 2px solid rgba(0,0,0,.35);
  flex: none;
}
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--bg-soft); border-radius: 10px; padding: 9px 6px; text-align: center; }
.stat b { display: block; font-size: 17px; color: var(--gold); }
.stat span { font-size: 11px; color: var(--muted); }
.color-row { flex-direction: row; align-items: center; justify-content: space-between; }
.pw summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 10px; }

.history { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.hrow {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 9px; background: var(--bg-soft); font-size: 13px;
}
.hrow .res { font-weight: 700; width: 26px; flex: none; }
.hrow .win { color: #96d5ae; }
.hrow .lose { color: #e09184; }
.hrow .spacer { flex: 1; }
.hrow.casual { opacity: .66; }
.badge.bot { background: #2f2f3c; color: #b9bcd6; border-color: #414055; }

/* ── Игра ──────────────────────────────────────────────── */
.game {
  display: grid; grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px; padding: 16px; flex: 1; max-width: 1400px; margin: 0 auto; width: 100%;
}
.board-wrap { min-width: 0; display: flex; align-items: flex-start; justify-content: center; }
.board-stage { position: relative; margin: 0 auto; }
#board {
  display: block; border-radius: var(--radius); box-shadow: var(--shadow);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}

.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.players { display: flex; flex-direction: column; gap: 8px; }
.player {
  display: grid; grid-template-columns: auto 1fr auto auto; grid-template-rows: auto auto;
  column-gap: 10px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  transition: .2s;
}
.player.active { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(232,192,125,.14); }
/* Карточка кликабельна: открывает рейтинг, историю и (у себя) настройки */
.player[role="button"] { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.player[role="button"]:hover { border-color: #55483c; }
.player[role="button"]:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.player[role="button"]:active { transform: scale(.985); }
.player .dot {
  grid-row: 1 / 3; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,.4);
  box-shadow: inset 0 -2px 5px rgba(0,0,0,.4), inset 0 2px 5px rgba(255,255,255,.25);
}
.player .pname { font-weight: 600; }
.player .pclock {
  grid-row: 1 / 3; grid-column: 3;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 15px; color: var(--muted); padding-left: 10px; white-space: nowrap;
}
.player.active .pclock { color: var(--text); }
.player .pclock.low { color: #e09184; }
.player.offline { opacity: .55; }

.timer-wrap { height: 6px; background: var(--panel); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.timer-bar { height: 100%; width: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); transition: width .25s linear; }
.timer-bar.low { background: linear-gradient(90deg, #b5563f, #e08a5a); }

.turn-line {
  display: flex; align-items: baseline; justify-content: center; gap: 10px;
  min-height: 21px; flex-wrap: wrap;
}
.turn-label { font-size: 14px; color: var(--muted); }
.turn-label b { color: var(--gold); }
.main-clock {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 17px; color: var(--text); letter-spacing: .5px;
}
.main-clock.low { color: #e09184; }
.main-clock:empty { display: none; }

/* Вкладки выбора игры */
.game-tabs {
  display: flex; gap: 10px; max-width: 1180px;
  margin: 14px auto 0; padding: 0 16px; width: 100%;
}
.gtab {
  flex: 1; display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  padding: 11px 16px; border-radius: 14px; cursor: pointer; text-align: left;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--muted);
  font: inherit; transition: border-color .15s, background .15s, color .15s;
}
.gtab b { font-size: 15px; color: var(--text); }
.gtab span { font-size: 12px; line-height: 1.3; }
.gtab:hover { border-color: rgba(232,192,125,.4); }
.gtab.active {
  border-color: var(--gold); background: rgba(232,192,125,.10);
  box-shadow: inset 0 0 0 1px rgba(232,192,125,.22);
}
.gtab.active b { color: var(--gold); }

.vtag { font-size: 12px; font-weight: 500; color: var(--muted); }
.vtag:empty { display: none; }

/* Матч и куб удвоения */
/* Шапка матча стоит над списком игроков: только формат и текущая партия,
   сам счёт — в карточках игроков, чтобы не гадать, чьи это очки. */
.match-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 9px 12px; border-radius: 12px;
  background: linear-gradient(180deg, rgba(232,192,125,.10), rgba(232,192,125,.03));
  border: 1px solid rgba(232,192,125,.35);
}
.mb-title {
  font-size: 12px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); white-space: nowrap;
}
.mb-title b { color: var(--gold); font-size: 14px; letter-spacing: 0; }
.mb-game { font-size: 13px; color: var(--text); white-space: nowrap; }
.mb-game::before {
  content: ''; display: inline-block; width: 4px; height: 4px; border-radius: 50%;
  background: var(--muted); margin: 0 8px 2px 2px;
}
.mb-game:empty { display: none; }

.mb-tag {
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  white-space: nowrap; background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--muted);
}
.mb-tag.warn { color: #e0c184; border-color: rgba(232,192,125,.45); }
.mb-tag.cube {
  font-variant-numeric: tabular-nums;
  background: #efe7d6; color: #2a2118; border-color: rgba(0,0,0,.4);
  box-shadow: 0 2px 5px rgba(0,0,0,.4);
}
.mb-tag.cube.mine { outline: 2px solid var(--gold); outline-offset: 1px; }
.mb-tag.cube.theirs { opacity: .7; }

/* Очки матча в карточке игрока */
.player .pscore {
  grid-row: 1 / 3; grid-column: 4;
  min-width: 34px; text-align: center; padding-left: 10px;
  font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--muted); border-left: 1px solid var(--line);
}
.player .pscore.hidden { display: none; }
.player .pscore.lead { color: var(--gold); }

.cube-offer {
  padding: 10px 12px; border-radius: 12px; display: flex; flex-direction: column; gap: 8px;
  background: rgba(232,192,125,.10); border: 1px solid var(--gold);
}
.cube-offer > div:first-child { font-size: 13px; line-height: 1.4; }

.opts-short { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; flex: 1 1 100%; }

/* Настройки комнаты */
.room-opts { flex: 1 1 100%; margin-top: 4px; }
.room-opts summary {
  cursor: pointer; color: var(--gold); font-size: 13px; font-weight: 600;
  padding: 6px 0; user-select: none;
}
.opts-grid {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-top: 6px;
}
.opts-hint { flex: 1 1 100%; margin: 0; line-height: 1.4; }

.controls { display: flex; flex-direction: column; gap: 8px; }
.control-row { display: flex; gap: 8px; }
.control-row .btn { flex: 1; }

/* Подтверждение хода (когда авто-применение выключено) */
.confirm-row {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--gold-dim); border-radius: 12px;
  padding: 8px 10px; animation: die-in .2s ease forwards;
}
.confirm-row .ctext { flex: 1; font-size: 13px; color: var(--gold); font-weight: 600; }

/* Переключатель */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  flex-direction: row; cursor: pointer; user-select: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 12px; font-size: 13px; color: var(--text);
}
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-row .switch {
  flex: none; width: 40px; height: 22px; border-radius: 999px;
  background: #3a312a; border: 1px solid var(--line); position: relative; transition: .18s;
}
.switch-row .switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--muted); transition: .18s;
}
.switch-row input:checked + .switch { background: linear-gradient(180deg, var(--gold), var(--gold-dim)); border-color: transparent; }
.switch-row input:checked + .switch::after { left: 20px; background: #241c10; }
.switch-row input:focus-visible + .switch { box-shadow: 0 0 0 3px rgba(232,192,125,.25); }

.chat { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 160px; }
.chat-log {
  flex: 1; overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px; font-size: 13px;
  display: flex; flex-direction: column; gap: 6px; max-height: 320px;
}
.msg .who { color: var(--gold); font-weight: 600; }
.msg.system { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; }

/* ── Кости ─────────────────────────────────────────────── */
/* Размеры слоя задаёт board.js — так кости оказываются по центру игрового поля */
.dice-layer {
  position: absolute; left: 0; top: 0; display: flex; align-items: center; justify-content: center;
  gap: 14px; pointer-events: none;
}
.die {
  width: 56px; height: 56px; border-radius: 12px;
  background: linear-gradient(155deg, #fbf5e8 0%, #ddd0b6 100%);
  box-shadow: 0 8px 20px rgba(0,0,0,.5), inset 0 -3px 6px rgba(0,0,0,.18);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 7px; opacity: 0; transform: scale(.4);
}
.die.show { animation: die-in .35s cubic-bezier(.2,1.5,.5,1) forwards; }
.die.rolling { animation: die-roll .45s linear infinite; opacity: 1; transform: none; }
.die.used { opacity: .3 !important; filter: grayscale(.7); }
.die .pip { width: 9px; height: 9px; border-radius: 50%; background: #2a2118; align-self: center; justify-self: center; box-shadow: inset 0 1px 1px rgba(255,255,255,.35); }
.die.small { width: 38px; height: 38px; border-radius: 9px; padding: 5px; }
.die.small .pip { width: 6px; height: 6px; }

@keyframes die-in { from { opacity: 0; transform: scale(.4) rotate(-40deg); } to { opacity: 1; transform: none; } }
@keyframes die-roll {
  0%   { transform: rotate(0deg)   translateY(0)     scale(1); }
  25%  { transform: rotate(90deg)  translateY(-14px) scale(1.06); }
  50%  { transform: rotate(180deg) translateY(0)     scale(1); }
  75%  { transform: rotate(270deg) translateY(-9px)  scale(1.04); }
  100% { transform: rotate(360deg) translateY(0)     scale(1); }
}

.banner {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%);
  background: rgba(22, 18, 15, .94); border: 1px solid var(--gold-dim);
  padding: 22px 34px; border-radius: 16px; text-align: center;
  box-shadow: var(--shadow); animation: die-in .3s ease forwards; z-index: 5;
}
.banner .title { font-size: 24px; font-weight: 700; color: var(--gold); }
.banner .sub { color: var(--muted); margin-top: 6px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--gold-dim); color: var(--text);
  padding: 11px 20px; border-radius: 12px; box-shadow: var(--shadow); z-index: 100;
  animation: die-in .25s ease forwards; max-width: 90vw;
}

/* ── Модальное окно ────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 8, 6, .72); backdrop-filter: blur(4px);
  padding: 20px; overflow-y: auto;
}
.modal-card {
  width: min(430px, 100%);
  background: linear-gradient(180deg, var(--panel) 0%, #1e1a16 100%);
  border: 1px solid var(--line); border-radius: 18px;
  padding: 20px 22px 18px; box-shadow: var(--shadow);
  animation: die-in .2s ease forwards;
  max-height: 92vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-card .sep { border: 0; border-top: 1px solid var(--line); margin: 18px 0 14px; }
.modal-card .sub-h { margin: 0 0 4px; font-size: 14px; color: var(--muted); font-weight: 600; }
.modal-card input:disabled { opacity: .6; cursor: not-allowed; }
.modal-card .color-row { align-items: center; }

/* Карточка игрока из партии */
#modal-player .profile-head { margin-bottom: 12px; }
#modal-player .history { max-height: 240px; margin-bottom: 12px; }
#modal-player .sub-h { margin-top: 14px; }
/* Кнопка возврата всегда на виду, даже если история длинная */
#modal-player .pl-foot {
  position: sticky; bottom: -18px; z-index: 1;
  margin: 10px -22px -18px; padding: 10px 22px 18px;
  background: #1e1a16; border-top: 1px solid var(--line);
}
#modal-player .pl-foot p { margin: 0 0 8px; }
.pl-settings { margin: 4px 0 2px; }
.pl-settings .switch-row { margin: 6px 0; }
.pl-settings p { margin: 0; }

/* ── Адаптив ───────────────────────────────────────────── */
@media (max-width: 1040px) {
  .lobby, .game { grid-template-columns: 1fr; }
  .game { padding: 10px; grid-template-rows: auto auto; align-content: start; }
  .side { flex-direction: column; }
  .chat-log { max-height: 180px; }
  .die { width: 42px; height: 42px; border-radius: 9px; padding: 5px; }
  .die .pip { width: 7px; height: 7px; }
}
/* Узкий экран: панель сжимается в одну колонку под доской, чат — по кнопке,
   чтобы всё помещалось на экран без прокрутки. */
.only-compact { display: none; }

@media (max-width: 720px) {
  /* Экран игры ровно в высоту окна: панель занимает сколько нужно, доска —
     всё остальное. Высоту доске отдаёт раскладка, а не арифметика в JS. */
  #screen-game.active { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
  .game {
    display: flex; flex-direction: column; min-height: 0;
    padding: 6px; gap: 7px;
  }
  .board-wrap { flex: 1 1 auto; min-height: 0; align-items: center; }
  .side { flex: 0 0 auto; gap: 7px; }
  .only-compact { display: block; }

  /* Карточка игрока должна влезать в экран телефона целиком —
     вместе с кнопкой возврата в игру. */
  #modal-player .modal-card { padding: 14px 16px 12px; }
  #modal-player .profile-head { margin-bottom: 10px; }
  #modal-player .chip-preview { width: 32px; height: 32px; }
  #modal-player .stats { gap: 6px; margin-bottom: 8px; }
  #modal-player .stat { padding: 6px 4px; }
  #modal-player .stat b { font-size: 15px; }
  #modal-player .sub-h { margin-top: 10px; }
  #modal-player .history { max-height: 132px; margin-bottom: 8px; }
  #modal-player .pl-settings p { font-size: 11px; }
  #modal-player #pl-warn { font-size: 11px; }
  #modal-player .pl-foot { bottom: -12px; margin: 8px -16px -12px; padding: 8px 16px 12px; }

  /* шапка и элементы панели ужимаются: каждый выигранный по высоте пиксель
     уходит доске, а на коротких экранах их считанные десятки */
  .topbar { padding: 7px 10px; }
  .topbar .logo { font-size: 14px; }
  .topbar .btn.small { padding: 6px 10px; }
  .pill { padding: 4px 9px; font-size: 12px; }

  /* Два игрока в ряд: имя и очки сверху, мелочь и часы — второй строкой.
     Все ячейки расставлены явно, иначе авторазмещение ломает порядок. */
  .players { flex-direction: row; gap: 6px; }
  .players .player {
    flex: 1 1 0; min-width: 0; padding: 7px 9px; column-gap: 7px; row-gap: 2px;
    grid-template-columns: auto minmax(0, 1fr) auto;
  }
  .player .dot { grid-row: 1; grid-column: 1; width: 18px; height: 18px; }
  .player .pname {
    grid-row: 1; grid-column: 2; font-size: 13px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .player .pscore {
    grid-row: 1; grid-column: 3; font-size: 16px; min-width: 0;
    padding-left: 7px; border-left: 1px solid var(--line);
  }
  .player .pmeta { grid-row: 2; grid-column: 1 / 3; font-size: 11px; line-height: 1.25; }
  .player .pclock {
    grid-row: 2; grid-column: 3; padding-left: 7px; font-size: 12px; border: 0;
  }

  .match-bar { padding: 6px 10px; gap: 6px; }
  .mb-title { font-size: 11px; }

  /* Строка хода в одну линию, кнопки — в ряд: высота панели не должна
     прыгать от состояния партии, иначе доска скачет между ходами. */
  .turn-line { font-size: 14px; flex-wrap: nowrap; gap: 8px; }
  .turn-label { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  /* место под кнопки резервируем всегда — иначе панель дышит, а доска скачет */
  .controls { flex-direction: row; flex-wrap: wrap; gap: 6px; min-height: 86px; align-content: start; }
  /* переключатель «завершать ход сразу» живёт в настройках профиля */
  .controls > .switch-row { display: none; }
  .controls > .btn.wide { flex: 1 1 140px; padding: 10px; }
  .controls > #btn-rematch, .controls > .switch-row,
  .controls > .control-row, .controls > .cube-offer { flex: 1 1 100%; }
  .controls .btn.small { padding: 9px 10px; }
  .switch-row { padding: 6px 10px; font-size: 12px; }
  .timer-wrap { height: 5px; }

  /* чат открывается кнопкой «Чат» */
  .chat { display: none; }
  .chat.open { display: flex; }
  .chat-log { max-height: 130px; }
  .btn.active { border-color: var(--gold); color: var(--gold); }
}

/* Совсем низкие экраны (iPhone SE и подобные) — режем ещё плотнее */
@media (max-width: 720px) and (max-height: 720px) {
  .game { padding: 4px; gap: 5px; }
  .side { gap: 5px; }
  .topbar { padding: 5px 9px; }
  .players .player { padding: 4px 8px; }
  .player .pname { font-size: 12px; }
  .player .pmeta { font-size: 10px; }
  .player .pscore { font-size: 15px; }
  .match-bar { padding: 3px 9px; }
  .mb-title { font-size: 10px; }
  .mb-game, .mb-tag { font-size: 11px; }
  .switch-row { padding: 5px 9px; }
  .controls .btn.wide { padding: 9px; }
  .controls .btn.small { padding: 8px 9px; }
}

@media (max-width: 560px) {
  .game-tabs { padding: 0 12px; gap: 8px; }
  .gtab { padding: 9px 12px; }
  .gtab span { display: none; }
  .panel { padding: 13px 14px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dice-layer { gap: 8px; }
  .die { width: 34px; height: 34px; border-radius: 8px; padding: 4px; }
  .die .pip { width: 5px; height: 5px; }
}
