:root {
  --bg: #171310;
  --panel: #221b16;
  --panel-2: #2c231c;
  --line: #3d3128;
  --text: #f0e6d8;
  --muted: #a8998a;
  --gold: #e0b048;
  --wood-1: #6a4326;
  --wood-2: #40281a;
  --tri-light: #caa06b;
  --tri-dark: #8a4a2b;
  --white-checker: radial-gradient(circle at 32% 28%, #fffdf6, #e6d5b2 62%, #c2ab84);
  --black-checker: radial-gradient(circle at 32% 28%, #6a6a74, #26262c 62%, #101014);
  --radius: 14px;
  font-family: "Segoe UI", "Inter", system-ui, sans-serif;
}

/* Club uses the same warm palette; its scroll stays inside the modal. */
dialog.club { width: min(820px, calc(100vw - 24px)); max-width: 820px; max-height: calc(100dvh - 24px); padding: clamp(16px, 3vw, 28px); overflow: auto; }
.club-header, .club-tournament-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.club-header h2 { margin: 6px 0; }
.club-eyebrow { color: var(--gold); letter-spacing: .16em; font-size: 11px; font-weight: 700; }
.club-muted, .club p { color: var(--muted); line-height: 1.55; }
.club-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 20px 0; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.club-tabs [aria-selected="true"] { background: var(--gold); color: var(--bg); border-color: var(--gold); }
.club progress { width: 100%; height: 8px; accent-color: var(--gold); }
.club-levels { display: grid; gap: 10px; margin-top: 22px; }
.club-level { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.club-level.is-locked { opacity: .6; }
.club-level-number { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid var(--gold); color: var(--gold); border-radius: 50%; }
.club h4 { margin: 0; font-size: 17px; }
.club-level p { margin: 5px 0 0; font-size: 13px; }
.club form:not([method="dialog"]) { display: grid; gap: 14px; max-width: 460px; margin: 18px 0; }
.club label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; }
.club input, .club select { width: 100%; min-height: 44px; padding: 10px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.club input:focus-visible, .club select:focus-visible, .club button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.club-auth-switch, .club-form-row { display: flex; flex-wrap: wrap; gap: 12px; }
.club-form-row label { flex: 1; }
.club details { border: 1px solid var(--line); padding: 16px; border-radius: 12px; margin: 18px 0; }
.club summary { cursor: pointer; color: var(--gold); }
.club-tournament { border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-top: 16px; background: var(--panel-2); }
.club-tournament-heading span { color: var(--gold); font-size: 12px; white-space: nowrap; }
.club-round { padding: 12px; border-left: 2px solid var(--gold); margin: 12px 0; background: var(--panel); }
.club-round p { margin: 6px 0 0; }
.club .club-winner { color: var(--gold); font-weight: bold; }
.club-table-wrap { overflow-x: auto; }
.club table { width: 100%; border-collapse: collapse; text-align: left; }
.club th, .club td { padding: 12px 8px; border-bottom: 1px solid var(--line); }
.club th { font-size: 12px; color: var(--muted); }
.club .is-me { background: var(--panel-2); color: var(--gold); }
.club-empty { padding: 24px 0; }
#clubStatus { color: var(--gold); min-height: 1.5em; }
@media(max-width: 520px) {
  .club-level { grid-template-columns: 30px 1fr; gap: 10px; }
  .club-level button { grid-column: 2; justify-self: start; }
  .club-tournament-heading { align-items: start; flex-direction: column; gap: 6px; }
  .club-tabs { gap: 6px; }
  .club-tabs .btn { padding: 9px; font-size: 12px; }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(1200px 700px at 50% -10%, #2b2119, transparent),
    var(--bg);
  color: var(--text);
}

.app {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px clamp(12px, 2vw, 28px) 32px;
}

/* ---------- шапка ---------- */

.topbar {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand__dice { font-size: 30px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.3px; }
.brand__sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); text-transform: lowercase; }

.score {
  display: flex;
  gap: 10px;
  margin-inline: auto;
  align-items: center;
}

.score__side {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-variant-numeric: tabular-nums;
}
.score__side.is-turn { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(224, 176, 72, 0.35); }
.score__dot { width: 14px; height: 14px; border-radius: 50%; border: 1px solid #0006; }
.score__dot--white { background: var(--white-checker); }
.score__dot--black { background: var(--black-checker); }
.score__value { font-weight: 700; font-size: 17px; }
.score__match { font-size: 12px; color: var(--muted); align-self: center; }

.menu-toggle { display: none; font-size: 20px; line-height: 1; padding: 6px 12px; }

.setup { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.setup label { display: grid; gap: 4px; font-size: 11px; color: var(--muted); }
.setup__check {
  display: flex !important;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
}
.setup__check input { accent-color: var(--gold); cursor: pointer; margin: 0; }

select, .btn {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
}
select { font-size: 13px; }
.btn:hover:not(:disabled), select:hover { border-color: #5c4a3b; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn--primary { background: linear-gradient(#e6bb59, #c8912c); color: #2a1d06; border-color: #b7842a; font-weight: 600; }
.btn--primary:disabled { background: #453718; color: #9b8657; border-color: #5b4a24; }
.btn--ghost { background: transparent; }
.btn--pulse { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224, 176, 72, 0); }
  50% { box-shadow: 0 0 0 5px rgba(224, 176, 72, 0.22); }
}

/* ---------- стол ---------- */

.table {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  gap: 22px;
  margin-top: 20px;
  align-items: start;
}

.board-shell {
  display: grid;
  grid-template-columns: clamp(34px, 4.4%, 58px) minmax(0, 1fr) clamp(34px, 4.4%, 58px);
  gap: 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #3a2a1e, #241811);
  border: 1px solid #4a382a;
  box-shadow: 0 18px 40px #0009;
}

.board {
  position: relative;
  touch-action: manipulation; /* без двойного тапа на зум */
  user-select: none;
  aspect-ratio: 1.3;
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--wood-1), var(--wood-2));
  box-shadow: inset 0 0 40px #0007, inset 0 0 0 2px #00000033;
}

.row { display: flex; flex: 1 1 0; min-height: 0; }
.row--bottom { align-items: flex-end; }
.hinge {
  height: 3%;
  margin: 0 -8px;
  background: linear-gradient(90deg, #1c120b, #2f1e13 12%, #2f1e13 88%, #1c120b);
  border-top: 1px solid #00000055;
  border-bottom: 1px solid #ffffff10;
}
.gap {
  flex: 0 0 2.2%;
  align-self: stretch; /* в нижнем ряду align-items: flex-end схлопывал планку */
  background: linear-gradient(90deg, #1c120b, #2f1e13);
}

/* ---------- пункты ---------- */

.point {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  container-type: size;
  cursor: default;
  /* Шашка ограничена и шириной пункта, и его высотой: на широкой доске
     (телефон в альбоме) пять шашек по ширине пункта в стопку не влезли бы. */
  --checker: min(84cqw, 19cqh);
  --step: calc(var(--checker) * 0.97);
}
.point.is-clickable { cursor: pointer; }

.point__tri {
  position: absolute;
  inset: 0;
  background: var(--tri-dark);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transition: filter 0.15s ease;
}
.point--light .point__tri { background: var(--tri-light); }
.row--bottom .point__tri { clip-path: polygon(0 100%, 100% 100%, 50% 0); }

.point__label {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(8px, 9cqw, 12px);
  color: #ffffff5c;
  pointer-events: none;
}
.row--top .point__label { top: 1px; }
.row--bottom .point__label { bottom: 1px; }

.point.is-movable .point__tri { filter: brightness(1.18) saturate(1.1); }

.point.is-idle .checker { opacity: 0.35; }
.point.is-idle .point__tri { filter: brightness(0.8) saturate(0.7); }

.point.is-selected .point__tri {
  background: #f2c766;
  filter: none;
}
.point.is-selected .checker {
  box-shadow: 0 0 0 2px var(--gold), 0 0 10px 2px rgba(224, 176, 72, 0.55), 0 2px 4px #0007;
  z-index: 3;
}
.point.is-target .point__tri {
  background: #d8a44b;
  filter: none;
  animation: glow 1.1s ease-in-out infinite;
}
@keyframes glow {
  0%, 100% { opacity: 0.72; }
  50% { opacity: 1; }
}

.point__die {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  min-width: calc(var(--checker) * 0.62);
  height: calc(var(--checker) * 0.62);
  padding: 0 calc(var(--checker) * 0.1);
  display: grid;
  place-items: center;
  white-space: nowrap;
  border-radius: 6px;
  background: #2a1c0d;
  color: var(--gold);
  border: 1px solid var(--gold);
  font-size: calc(var(--checker) * 0.36);
  font-weight: 700;
  z-index: 4;
  pointer-events: none;
}
.row--top .point__die { top: 8%; }
.row--bottom .point__die { bottom: 8%; }

/* ---------- шашки ---------- */

.checker {
  position: absolute;
  left: 50%;
  width: var(--checker);
  aspect-ratio: 1;
  transform: translateX(-50%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: calc(var(--checker) * 0.4);
  font-weight: 700;
  box-shadow: 0 2px 4px #0007, inset 0 -2px 5px #00000040;
  z-index: 2;
}
.checker--white { background: var(--white-checker); color: #5d4a24; border: 1px solid #00000030; }
.checker--black { background: var(--black-checker); color: #e6dcc6; border: 1px solid #00000060; }

.row--top .checker { top: calc(var(--i) * var(--step)); }
.row--bottom .checker { bottom: calc(var(--i) * var(--step)); }

/* ---------- лотки для вынесенных шашек ---------- */

.tray {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 5px;
  border-radius: 8px;
  background: linear-gradient(180deg, #2a1b12, #1b110b);
  box-shadow: inset 0 0 18px #0008;
  container-type: inline-size;
}
.tray--black { justify-content: flex-start; }
.tray--white { justify-content: flex-end; }
.tray.is-target { outline: 2px solid var(--gold); cursor: pointer; }
/* Чей ход: светится лоток ходящей стороны. Счёт и подсказка в узкой раскладке
   спрятаны, а лотки по краям доски видны всегда. */
.tray { transition: box-shadow 0.2s ease; }
body[data-turn="white"] .tray--white,
body[data-turn="black"] .tray--black {
  box-shadow: inset 0 0 18px #0008, 0 0 0 2px #e0b04877, 0 0 16px #e0b04855;
}
/* Свой ход заметнее: медленное дыхание вместо ровного свечения. */
body[data-mine="1"][data-turn="white"] .tray--white,
body[data-mine="1"][data-turn="black"] .tray--black {
  animation: trayBreathe 2s ease-in-out infinite;
}
@keyframes trayBreathe {
  0%, 100% { box-shadow: inset 0 0 18px #0008, 0 0 0 2px #e0b048aa, 0 0 12px #e0b04866; }
  50% { box-shadow: inset 0 0 18px #0008, 0 0 0 2px var(--gold), 0 0 24px #e0b048aa; }
}
@media (prefers-reduced-motion: reduce) {
  body[data-mine="1"] .tray { animation: none; }
}
.tray.is-clickable { cursor: pointer; }

.tray__count {
  font-size: 11px;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.tray--black .tray__count { order: 2; }

.tray__checker {
  width: 100%;
  aspect-ratio: 3.2;
  border-radius: 4px;
  flex: 0 0 auto;
}
.tray__checker--white { background: linear-gradient(#f4ead2, #cdb98f); }
.tray__checker--black { background: linear-gradient(#55555f, #17171c); }

/* ---------- панель справа ---------- */

.side { display: grid; gap: 14px; }

.turn-card {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
}
.turn-card__title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.turn-card__hint { margin-top: 6px; font-size: 13px; color: var(--muted); line-height: 1.45; }
.turn-card.is-over .turn-card__title { color: var(--gold); }

.dice { display: flex; gap: 10px; justify-content: center; min-height: 54px; }

.die {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: linear-gradient(160deg, #fbf3e2, #d9c9a8);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 6px;
  box-shadow: 0 4px 10px #0007;
}
.die.is-used { opacity: 0.28; }
/* Кубики — цвета того, кто ими играет: они в центре доски и видны всегда. */
body[data-turn="black"] .die { background: linear-gradient(160deg, #55555f, #1b1b21); }
body[data-turn="black"] .die__pip { background: #efe6d4; }
.die__pip { width: 9px; height: 9px; border-radius: 50%; background: #241a10; align-self: center; justify-self: center; }

/* Обёртка кубиков и кнопок. Вне альбома она ничего не меняет: дети
   остаются прямыми элементами панели, порядок и отступы прежние. */
.play { display: contents; }

.actions { display: flex; flex-direction: column; gap: 8px; }
.actions .btn[hidden] { display: none; }

.log {
  height: 260px;
  overflow-y: auto;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12.5px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.log__row { color: var(--muted); }
.log__row--white { color: #f3e8d2; }
.log__row--black { color: #b9b6c9; }

/* ---------- правила ---------- */

.rules {
  max-width: 620px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 24px;
}
.rules::backdrop { background: #000a; }
.rules h2 { margin-top: 0; }
.rules ol { padding-left: 20px; line-height: 1.6; font-size: 14px; }
.rules li { margin-bottom: 7px; }
.rules__hint { font-size: 13px; color: var(--muted); }
.export__actions { display: flex; gap: 10px; margin-top: 12px; }
.export__actions form { margin: 0; }

/* ---------- игра с людьми: лобби и строка комнаты ---------- */

.online { width: min(94vw, 560px); max-height: 88vh; overflow: auto; }
.online h3 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.online__block { margin-top: 16px; }
.online__row { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.online__field { display: grid; gap: 4px; font-size: 11px; color: var(--muted); flex: 1 1 160px; }
.online__field--narrow { flex: 0 0 auto; }
.online input {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 12px;
  min-width: 0;
}
.online input:focus { outline: none; border-color: var(--gold); }
#inpCode { width: 6.5em; text-transform: uppercase; letter-spacing: 0.18em; text-align: center; }
.online__list { display: grid; gap: 8px; margin-bottom: 10px; }
.online__room {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.online__room-name { font-size: 14px; font-weight: 600; }
.online__room-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.online__code { font-family: ui-monospace, "Cascadia Mono", monospace; color: var(--gold); letter-spacing: 0.1em; }
.online__empty { font-size: 13px; color: var(--muted); padding: 6px 0; }
.online__status { font-size: 13px; color: var(--muted); min-height: 1.2em; margin: 12px 0 0; }
.online__status.is-bad { color: #e79a7a; }

/* Комната живёт в панели настроек, а не над доской: в компактной раскладке
   панель — прозрачный слой поверх поля, и любая строка в нём закрывает игру. */
.setup__room {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.setup__room-code { color: var(--gold); font-weight: 600; }
.setup__room[hidden] { display: none; }
.setup__room-alert { color: #e79a7a; flex-basis: 100%; }

@media (max-width: 900px) {
  .table { grid-template-columns: minmax(0, 1fr); }
  .log { height: 160px; }
}

/* ---------- телефон ---------- */

@media (max-width: 760px) {
  .app { padding: 10px 10px 20px; }

  .topbar { gap: 8px 12px; padding-bottom: 10px; }
  .brand__dice { font-size: 24px; }
  .brand h1 { font-size: 17px; }
  .brand__sub { display: none; }
  .score { gap: 6px; }
  .score__side { padding: 5px 10px; font-size: 13px; }
  .score__match { display: none; }

  .menu-toggle { display: block; }

  /* Настройки уезжают под кнопку меню — на экране остаётся доска. */
  .setup {
    display: none;
    position: absolute;
    top: calc(100% - 4px);
    right: 0;
    z-index: 30;
    flex-direction: column;
    /* Базовое правило ставит flex-wrap: wrap. Пока высота не ограничена, это
       незаметно, но с max-height колонка начинает переноситься во второй
       столбец и пункты уезжают вбок за край панели. */
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 10px;
    min-width: 210px;
    padding: 14px;
    /* Высота ограничена остатком экрана, иначе при крупном системном шрифте
       нижние пункты уезжают за край и добраться до них нечем. Процент здесь
       разрешается по высоте .topbar — это containing block панели. */
    max-height: calc(100vh - 100% - 16px);
    max-height: calc(100dvh - 100% - 16px);
    overflow-y: auto;
    overscroll-behavior: contain;

    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 16px 40px #000b;
  }
  .setup.is-open { display: flex; }
  .setup > * { flex: 0 0 auto; }

  .table { gap: 10px; margin-top: 10px; }
  .board-shell {
    padding: 6px;
    gap: 4px;
    grid-template-columns: clamp(22px, 6%, 34px) minmax(0, 1fr) clamp(22px, 6%, 34px);
  }
  /* На телефоне доску вытягиваем: по ширине она упирается в экран,
     а свободная высота как раз даёт место стопкам шашек. */
  .board { aspect-ratio: 1.02; padding: 6px 4px; }
  .side { gap: 10px; }

  /* Кубики — сразу под доской и по центру. */
  .dice { order: -1; min-height: 0; }
  .die { width: 54px; height: 54px; }

  .turn-card { padding: 10px 12px; }
  .turn-card__title { font-size: 15px; }
  .turn-card__hint { font-size: 12.5px; }

  .btn, select { padding: 10px 14px; } /* пальцем попасть */
  .log { height: 130px; font-size: 12px; }

  .rules { padding: 18px; margin: 10px; }
  .rules ol { font-size: 13px; padding-left: 18px; }
}

/* ---------- телефон в альбоме: единственный режим приложения ----------
   Доска занимает весь экран, кубики лежат в её центре — там, где проходит
   разделительная планка и никогда не бывает шашек. Всё остальное убрано с
   глаз: настройки под кнопкой «☰», отмена шага появляется только когда есть
   что отменять, итог партии — карточкой поверх доски. */

/* Та же раскладка и на планшете в альбоме: экран у него выше 620px, и без
   второго условия он получал десктопную — настройки строкой над доской, доска
   за краем экрана и никакой кнопки меню. Отличаем его от компьютера по
   сенсорному экрану. */
@media (orientation: landscape) and (max-height: 620px),
       (orientation: landscape) and (pointer: coarse) {
  html, body { height: 100%; overflow: hidden; }

  /* WebView рисует поверх доски свою полосу прокрутки. Прокручивать здесь
     нечего, поэтому убираем полосы совсем — только в этом режиме. */
  * { scrollbar-width: none; }
  *::-webkit-scrollbar { width: 0; height: 0; }

  .app {
    position: relative;
    display: block;
    height: 100dvh;
    max-width: none;
    padding:
      calc(2px + env(safe-area-inset-top))
      calc(2px + env(safe-area-inset-right))
      calc(2px + env(safe-area-inset-bottom))
      calc(2px + env(safe-area-inset-left));
  }

  .table { display: contents; }

  /* Шапка сжимается до одной кнопки меню в углу поверх доски. */
  .topbar {
    position: absolute;
    top: calc(4px + env(safe-area-inset-top));
    right: calc(4px + env(safe-area-inset-right));
    z-index: 20;
    width: auto;
    padding: 0;
    gap: 0;
    border-bottom: none;
  }
  .brand, .score { display: none; }
  .menu-toggle {
    display: block;
    padding: 3px 9px;
    font-size: 15px;
    opacity: 0.55;
    background: #241a13cc;
  }
  .menu-toggle:hover { opacity: 1; }

  /* Доска на весь экран: соотношение сторон больше не навязываем. */
  .board-shell {
    display: flex;
    align-items: stretch;
    height: 100%;
    padding: 4px;
    gap: 3px;
    border-radius: 10px;
  }
  .board {
    flex: 1 1 auto;
    width: auto;
    height: auto;
    aspect-ratio: auto;
    padding: 4px 3px;
  }
  .tray { flex: 0 0 auto; width: clamp(14px, 2vw, 24px); padding: 4px 2px; }
  .tray__count { font-size: 8px; }
  .hinge { height: 4%; }

  /* Панель превращается в прозрачный слой поверх доски. */
  .side {
    position: absolute;
    inset: 0;
    display: block;
    z-index: 10;
    pointer-events: none;
  }

  /* Кубики — по центру доски, на разделительной планке. */
  .play {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
  }
  .dice {
    min-height: 0;
    gap: 8px;
    padding: 6px 9px;
    border-radius: 12px;
    background: #140e0aa8;
  }
  .die { width: 38px; height: 38px; padding: 4px; border-radius: 8px; }
  .die__pip { width: 6px; height: 6px; }
  body[data-phase="over"] .dice { display: none; }

  /* Во время партии подсказка и журнал не нужны — остаётся только доска. */
  .turn-card, .log { display: none; }

  .turn-card.is-over {
    display: block;
    position: absolute;
    left: 50%;
    top: 42%;
    transform: translate(-50%, -50%);
    min-width: 230px;
    padding: 12px 16px;
    text-align: center;
    pointer-events: auto;
    box-shadow: 0 18px 40px #000c;
  }
  .turn-card__title { font-size: 15px; justify-content: center; }
  .turn-card__hint { font-size: 12px; margin-top: 4px; }

  /* Кнопки — справа от кубиков; видны только те, которыми сейчас можно
     пользоваться. Позиционируются от обёртки, а не занимают в ней место:
     кубиков бывает два или четыре, и центр доски не должен из-за кнопки
     съезжать. */
  .actions {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 10px;
    width: auto;
    gap: 6px;
    white-space: nowrap;
    pointer-events: auto;
  }
  .actions .btn { padding: 6px 12px; font-size: 12px; }
  .actions .btn:disabled { display: none; }

  /* Партия окончена: кубиков нет, кнопка «Следующая партия» встаёт под
     карточкой итога по центру. */
  body[data-phase="over"] .play { top: 62%; }
  body[data-phase="over"] .actions {
    position: static;
    transform: none;
    margin-left: 0;
  }

  /* Настройки под кнопкой меню. */
  .setup {
    display: none;
    position: absolute;
    top: calc(100% + 5px);
    right: 0;
    z-index: 30;
    flex-direction: column;
    /* Базовое правило ставит flex-wrap: wrap. Пока высота не ограничена, это
       незаметно, но с max-height колонка начинает переноситься во второй
       столбец и пункты уезжают вбок за край панели. */
    flex-wrap: nowrap;
    align-items: stretch;
    min-width: 190px;
    padding: 10px;
    gap: 8px;
    /* Высота ограничена остатком экрана, иначе при крупном системном шрифте
       нижние пункты уезжают за край и добраться до них нечем. Процент здесь
       разрешается по высоте .topbar — это containing block панели. */
    max-height: calc(100vh - 100% - 16px);
    max-height: calc(100dvh - 100% - 16px);
    overflow-y: auto;
    overscroll-behavior: contain;

    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: 0 16px 40px #000b;
  }
  .setup.is-open { display: flex; }
  .setup > * { flex: 0 0 auto; }
  .setup label { font-size: 10px; }
  .setup .btn, .setup select { padding: 7px 10px; font-size: 12.5px; }

  .rules { max-height: 86dvh; overflow: auto; padding: 14px; margin: 0; }
  .rules ol { font-size: 12px; padding-left: 16px; line-height: 1.45; }
  .rules li { margin-bottom: 4px; }
  .rules__hint { font-size: 11px; }
}

/* ---------- планшет в альбоме ----------
   Раскладка та же, что у телефона, но экран крупнее: телефонные кубики,
   кнопки и меню на нём мелкие, пальцем в них не попасть. */
@media (orientation: landscape) and (pointer: coarse) and (min-height: 621px) {
  .menu-toggle { padding: 6px 13px; font-size: 22px; }
  .tray { width: clamp(20px, 2.2vw, 32px); }
  .tray__count { font-size: 11px; }
  .dice { gap: 12px; padding: 9px 13px; border-radius: 16px; }
  .die { width: 58px; height: 58px; padding: 6px; border-radius: 11px; }
  .die__pip { width: 9px; height: 9px; }
  .actions { margin-left: 14px; gap: 8px; }
  .actions .btn { padding: 10px 18px; font-size: 16px; }
  .setup { min-width: 250px; padding: 14px; gap: 10px; }
  .setup label { font-size: 12px; }
  .setup .btn, .setup select { padding: 11px 14px; font-size: 16px; }
  .setup__check { font-size: 15px; }
  .turn-card.is-over { min-width: 300px; padding: 16px 22px; }
  .turn-card__title { font-size: 19px; }
  .turn-card__hint { font-size: 15px; }
}

/* Safe touch controls, shared by Android WebView and phone browsers. */
.mobile-status { display: none; }
.bear-off-button { display: none; }
@media (pointer: coarse), (max-width: 700px), (max-height: 620px) {
  .btn, select, input { min-height: 48px; }
  .menu-toggle { min-width: 100px; min-height: 48px; opacity: 1; }
  .bear-off-button { display: inline-flex; align-items: center; justify-content: center; min-width: 96px; min-height: 48px; touch-action: manipulation; }
  .bear-off-button:disabled { opacity: .35; }
  .club-tabs .btn { min-height: 48px; }
}
@media (orientation: landscape) and (max-height: 620px),
       (orientation: landscape) and (pointer: coarse) {
  .app {
    display: grid; grid-template-rows: 52px minmax(0, 1fr); gap: 6px;
    padding: max(12px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  }
  .topbar {
    position: relative; inset: auto; width: 100%; height: 52px;
    display: flex; align-items: center; gap: 16px; padding: 0 4px;
    border-radius: 10px; background: var(--panel); z-index: 20;
  }
  .menu-toggle { padding: 8px 16px; font-size: 16px; background: var(--panel-2); }
  .mobile-status { display: block; font-size: 13px; color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .table { display: block; position: relative; min-height: 0; margin-top: 0; }
  .board-shell { height: 100%; }
  .board { display: flex; flex-direction: column; }
  .board .row { flex: 1 1 0; min-height: 0; height: auto; }
  .hinge { flex: 0 0 60px; height: 60px; }
  .side { inset: 0; }
  .play { top: 50%; }
  .dice { padding: 4px; background: #140e0acc; }
  .actions { left: auto; right: 100%; margin-left: 0; margin-right: 12px; }
  .actions .btn { min-height: 48px; padding: 8px 12px; font-size: 13px; }
  .bear-off-button {
    position: absolute; top: 50%; right: 38px; transform: translateY(-50%);
    z-index: 12; pointer-events: auto; font-size: 15px; padding: 8px 14px;
  }
  .bear-off-button[data-color="black"] { right: auto; left: 38px; }
  body[data-turn="black"][data-mine="1"] .actions { right: auto; left: 100%; margin-right: 0; margin-left: 12px; }
  body[data-phase="over"] .bear-off-button { display: none; }
  .setup { left: 0; right: auto; width: min(340px, calc(100vw - 56px)); max-height: calc(100dvh - 90px); }
  .setup .btn, .setup select { min-height: 48px; padding: 10px 12px; font-size: 15px; }
  .setup label { font-size: 13px; }
  .setup__check input { min-height: auto; }
  .setup__check { min-height: 40px; }
  .rules { margin: auto; max-height: calc(100dvh - 24px); }
  body[data-phase="over"] .actions { margin: 0; }
}
@media (orientation: portrait) and (max-width: 700px) {
  .app { padding-left: max(20px, env(safe-area-inset-left)); padding-right: max(20px, env(safe-area-inset-right)); }
  .menu-toggle { margin-right: 8px; }
  .bear-off-button { align-self: flex-end; }
}
