/* Коридор — Telegram Mini App styles. Palette and geometry: SPEC §8.3–8.4; skins, 4 players: SPEC §10.6, §10.8. */

:root {
  --wine-950: #2A0A11; --wine-900: #3A0D16; --wine-800: #521522; --wine-700: #6B1D2C;
  --wine-600: #7E2534; --wine-500: #93304A; --groove: #4A111C;
  --beech-100: #FBE6C2; --beech-200: #F4D29B; --beech-300: #EDBE78; --beech-400: #DDA35A; --beech-500: #C4873F;
  --amber: #E8962E; --amber-hi: #F9C877; --amber-lo: #A45E14;
  --plum: #4A1830; --plum-hi: #8C3F62; --plum-lo: #22081A; --ivory: #F2D7C0;
  --natural: #D9AE82; --crimson: #A3303F;

  --bg: #F6EFE6; --surface: #FFF9F1; --text: #2B0F16; --muted: #7A5A5F;
  --line: rgba(82, 21, 34, .12);
  --card-shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 6px 18px rgba(82, 21, 34, .10);
  --board-shadow: 0 18px 36px rgba(58, 13, 22, .30), 0 4px 10px rgba(58, 13, 22, .22);
  --danger: #C23B3B;
  --ok: #3E8E5A;

  --radius: 14px;
  --vh100: 100vh;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Noto Serif", "Times New Roman", serif;
  --safe-top: calc(env(safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px));
}
@supports (height: 100dvh) { :root { --vh100: 100dvh; } }

/* Board skins (SPEC §10.8): the SVG gradients are swapped by app.js; these variables cover the rest.
   Independent from the light/dark app theme. */
[data-skin] {
  --sk-dot: var(--ivory);                       /* legal-move dots, last-move ring */
  --sk-wall-edge: #B8793A; --sk-wall-glow: #FBE6C2;
  --sk-stick-a: var(--beech-200); --sk-stick-b: var(--beech-400); --sk-stick-edge: var(--beech-500);
}
[data-skin="walnut"] {
  --sk-wall-edge: #B89868; --sk-wall-glow: #FFF3DC;
  --sk-stick-a: #F8EBD0; --sk-stick-b: #E2CA9A; --sk-stick-edge: #A88C5E;
}
[data-skin="marble"] {
  --sk-dot: #3F3A36;
  --sk-wall-edge: #8E6B20; --sk-wall-glow: #F7E3A1;
  --sk-stick-a: #E9C967; --sk-stick-b: #C9A03C; --sk-stick-edge: #8E6B20;
}
[data-skin="winter"] {
  --sk-dot: #24557F;
  --sk-wall-edge: #9FB5CB; --sk-wall-glow: #FFFFFF;
  --sk-stick-a: #DDE8F3; --sk-stick-b: #A9BED3; --sk-stick-edge: #6F8BA8;   /* sticks must read on the light surface */
}

[data-theme="dark"] {
  --bg: #1A0A0F; --surface: #2A1118; --text: #F6E9DA; --muted: #B99A9F;
  --line: rgba(246, 233, 218, .10);
  --card-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset, 0 8px 20px rgba(0, 0, 0, .35);
  --board-shadow: 0 18px 40px rgba(0, 0, 0, .55), 0 4px 12px rgba(0, 0, 0, .45);
  --danger: #F07167;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font: 16px/1.4 var(--font);
  color: var(--text);
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(237, 190, 120, .22), transparent 60%),
    radial-gradient(90% 50% at 50% 110%, rgba(126, 37, 52, .10), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overflow: hidden;
}
[data-theme="dark"] body {
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(147, 48, 74, .30), transparent 60%),
    radial-gradient(90% 50% at 50% 110%, rgba(237, 190, 120, .06), transparent 70%),
    var(--bg);
}
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

.app {
  position: relative;
  height: var(--tg-viewport-stable-height, var(--vh100));
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  transition: height .2s ease;
}
.screens { position: relative; flex: 1 1 auto; min-height: 0; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: calc(var(--safe-top) + 14px) 16px calc(var(--safe-bottom) + 16px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: flex; animation: screen-in .24s cubic-bezier(.2, .8, .2, 1); }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.center-stack {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center;
}
.lead { font-size: 19px; font-weight: 650; margin: 6px 0 0; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.screen-title { margin: 2px 2px 0; font: 700 26px/1.2 var(--serif); letter-spacing: .01em; }

/* ---------- Top navigation (browser only; Telegram uses BackButton) ---------- */
.topnav {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 6px) 10px 0;
  min-height: 44px;
}
.topnav:not([hidden]) + .screens .screen { padding-top: 8px; }
.topnav-title { font-weight: 650; color: var(--muted); }
.icon-btn {
  position: relative;
  min-width: 44px; height: 44px; border-radius: 12px; border: 0;
  background: var(--surface); box-shadow: var(--card-shadow); color: var(--text);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn.small { min-width: 30px; height: 30px; font-size: 15px; border-radius: 9px; }
.icon-btn.small::after { content: ""; position: absolute; inset: -7px; } /* 44 px tap target */
.icon-btn:active { transform: translateY(1px); }

/* ---------- Connection banner ---------- */
.banner {
  position: absolute; z-index: 40; left: 12px; right: 12px; top: calc(var(--safe-top) + 8px);
  padding: 9px 14px; border-radius: 12px; text-align: center; font-size: 14px; font-weight: 600;
  color: var(--beech-100); background: var(--wine-800);
  box-shadow: 0 8px 20px rgba(42, 10, 17, .35);
  animation: banner-in .25s ease;
}
.banner::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px;
  background: var(--beech-300); vertical-align: 1px; animation: pulse 1.1s ease-in-out infinite;
}
@keyframes banner-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 50px; padding: 0 18px;
  border: 0; border-radius: var(--radius);
  font-size: 16px; font-weight: 650; letter-spacing: .01em;
  cursor: pointer; white-space: nowrap;
  transition: transform .08s ease, box-shadow .12s ease, filter .12s ease, opacity .15s ease;
}
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { cursor: default; opacity: .45; filter: saturate(.5); }
.btn:focus-visible, .segmented button:focus-visible, .room-row:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

.btn-primary {
  color: var(--wine-800);
  background:
    repeating-linear-gradient(92deg, rgba(196, 135, 63, 0) 0 9px, rgba(196, 135, 63, .10) 9px 10px, rgba(196, 135, 63, 0) 10px 23px),
    linear-gradient(180deg, var(--beech-100) 0%, var(--beech-200) 38%, var(--beech-300) 100%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset, 0 -2px 0 rgba(196, 135, 63, .35) inset,
              0 3px 0 var(--beech-500), 0 6px 14px rgba(120, 70, 20, .28);
}
.btn-primary:active:not(:disabled) {
  box-shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 1px 0 var(--beech-500), 0 2px 6px rgba(120, 70, 20, .25);
}
.btn-secondary {
  color: var(--beech-100);
  background: linear-gradient(180deg, var(--wine-500) 0%, var(--wine-600) 45%, var(--wine-700) 100%);
  box-shadow: 0 1px 0 rgba(255, 200, 200, .22) inset, 0 3px 0 var(--wine-900), 0 6px 14px rgba(58, 13, 22, .28);
}
.btn-secondary:active:not(:disabled) { box-shadow: 0 1px 0 rgba(255, 200, 200, .2) inset, 0 1px 0 var(--wine-900); }
.btn-ghost { background: transparent; color: var(--muted); box-shadow: none; }
/* Dark emoji (👥…) get lost on the wine buttons: a thin beech outline keeps them readable. */
.btn-secondary .emo { filter: drop-shadow(0 0 1px rgba(251, 230, 194, .95)) drop-shadow(0 0 .5px rgba(251, 230, 194, .95)); }
/* Plus drawn in the text colour (the ➕ emoji is a dark glyph). */
.i-plus {
  flex: 0 0 auto; width: 14px; height: 14px; border-radius: 1px;
  background:
    linear-gradient(currentColor, currentColor) center / 100% 3px no-repeat,
    linear-gradient(currentColor, currentColor) center / 3px 100% no-repeat;
}
.btn-ghost.danger { color: var(--danger); }
.btn-lg { min-height: 56px; font-size: 17px; }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn-xs { min-height: 34px; padding: 0 10px; font-size: 14px; border-radius: 10px; }
.btn-wide { min-width: 200px; margin-top: 10px; }
.grow { flex: 1 1 auto; }

/* ---------- Inputs ---------- */
.input {
  width: 100%; height: 50px; padding: 0 14px;
  border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--text);
  font: 16px var(--font);
  box-shadow: 0 2px 4px rgba(42, 10, 17, .06) inset;
  outline: none; -webkit-appearance: none; appearance: none;
}
.input:focus { border-color: var(--beech-400); box-shadow: 0 0 0 3px rgba(237, 190, 120, .35); }
.input::placeholder { color: var(--muted); opacity: .7; }
.input-sm { height: 34px; font-size: 15px; padding: 0 10px; border-radius: 10px; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 52px; }
.pw-toggle {
  position: absolute; right: 4px; top: 4px; width: 44px; height: 42px; border: 0; border-radius: 10px;
  background: transparent; font-size: 18px; cursor: pointer; opacity: .55;
}
.pw-toggle.on { opacity: 1; }

.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.label { font-size: 14px; font-weight: 650; color: var(--muted); padding-left: 2px; }
.opt { font-weight: 400; }
.hint { font-size: 13px; color: var(--muted); padding-left: 2px; }
.field-error { color: var(--danger); font-size: 14px; margin: 0; }

/* ---------- Segmented control ---------- */
.segmented {
  display: flex; padding: 4px; gap: 4px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--wine-900), var(--wine-800));
  box-shadow: 0 2px 5px rgba(0, 0, 0, .35) inset, 0 1px 0 rgba(255, 255, 255, .5);
}
[data-theme="dark"] .segmented { box-shadow: 0 2px 5px rgba(0, 0, 0, .5) inset, 0 1px 0 rgba(255, 255, 255, .05); }
.segmented button {
  flex: 1 1 0; min-height: 42px; border: 0; border-radius: 10px; padding: 0 8px;
  background: transparent; color: rgba(251, 230, 194, .72);
  font-weight: 650; font-size: 15px; cursor: pointer; white-space: nowrap;
  transition: background .15s ease, color .15s ease, transform .08s ease;
}
.segmented button[aria-checked="true"] {
  color: var(--wine-800);
  background: linear-gradient(180deg, var(--beech-100), var(--beech-300));
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset, 0 2px 0 var(--beech-500), 0 3px 8px rgba(0, 0, 0, .3);
}
.segmented button:disabled { opacity: .35; cursor: default; }
.segmented button:active:not(:disabled) { transform: translateY(1px); }

/* ---------- Menu ---------- */
.menu { gap: 12px; }
.hero { display: flex; flex-direction: column; align-items: center; padding-top: 4px; flex: 0 1 auto; }
.hero-board {
  width: min(88%, 330px); height: auto; aspect-ratio: 762 / 274;
  transform: perspective(520px) rotateX(22deg);
  transform-origin: 50% 80%;
  filter: drop-shadow(0 14px 14px rgba(58, 13, 22, .28));
  margin-bottom: -2px;
}
[data-theme="dark"] .hero-board { filter: drop-shadow(0 14px 16px rgba(0, 0, 0, .55)); }
.wordmark {
  margin: 10px 0 0;
  font: 800 44px/1 var(--serif);
  letter-spacing: .16em; padding-left: .16em;
  color: transparent;
  background:
    repeating-linear-gradient(100deg, rgba(164, 94, 20, 0) 0 6px, rgba(164, 94, 20, .22) 6px 7px, rgba(164, 94, 20, 0) 7px 15px),
    linear-gradient(180deg, var(--beech-100) 0%, var(--beech-300) 55%, var(--beech-500) 100%);
  -webkit-background-clip: text; background-clip: text;
  filter: drop-shadow(0 1px 0 var(--wine-700)) drop-shadow(0 2px 0 var(--wine-800)) drop-shadow(0 6px 8px rgba(58, 13, 22, .35));
}
.wordmark-sub { margin-top: 4px; font: italic 500 15px var(--serif); letter-spacing: .3em; color: var(--muted); padding-left: .3em; }

.me-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px 10px 14px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--card-shadow);
}
.me { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.me-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-form { display: flex; gap: 6px; flex: 1; min-width: 0; }
.online { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(62, 142, 90, .18); }
.menu-buttons { display: flex; flex-direction: column; gap: 11px; margin-top: 2px; }
/* Small secondary actions under the main buttons: profile, leaderboard, rules. */
.menu-icons { display: flex; gap: 8px; flex: 0 0 auto; }
.icon-tile {
  flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; cursor: pointer; white-space: nowrap;
  background: var(--surface); box-shadow: var(--card-shadow); color: var(--text);
  font-size: 14.5px; font-weight: 650;
  transition: transform .08s ease;
}
.icon-tile:active { transform: translateY(1px); }
.icon-tile:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.icon-tile .emo { font-size: 16px; line-height: 1; }

/* First-launch card «Впервые здесь? Обучение за минуту» (SPEC §10.7). */
.tut-card {
  flex: 0 0 auto; display: flex; align-items: stretch; border-radius: var(--radius);
  background: var(--surface); border-left: 5px solid var(--amber);
  box-shadow: var(--card-shadow), 0 0 0 1.5px rgba(232, 150, 46, .45), 0 0 16px rgba(232, 150, 46, .18);
  animation: screen-in .3s ease both;
}
.tut-go {
  flex: 1; min-width: 0; min-height: 58px; display: flex; align-items: center; gap: 12px;
  padding: 8px 4px 8px 12px; border: 0; background: transparent; text-align: left; cursor: pointer;
}
.tut-go:active { transform: translateY(1px); }
.tut-go:disabled { opacity: .6; cursor: default; }
.tut-ico { font-size: 28px; line-height: 1; }
.tut-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.tut-title { font: 700 17px/1.2 var(--serif); }
.tut-sub { font-size: 13.5px; color: var(--muted); }
.tut-arrow { font-size: 24px; line-height: 1; color: var(--beech-500); }
.tut-close {
  flex: 0 0 44px; border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 22px; line-height: 1;
}

/* ---------- Pawn icons & idle animations ---------- */
.pawn-ico { width: 44px; height: 53px; overflow: visible; }
.pawn-duo { display: flex; gap: 18px; align-items: flex-end; height: 80px; }
.pawn-duo .pawn-ico { width: 52px; height: 62px; }
.pawn-duo.small { height: 64px; margin-top: 4px; }
.pawn-duo.small .pawn-ico { width: 40px; height: 48px; }
.hop-a { animation: idle-hop 1.2s ease-in-out infinite; }
.hop-b { animation: idle-hop 1.2s ease-in-out .6s infinite; }
.ghost-pawn { opacity: .28; filter: grayscale(.4); animation: breathe 1.8s ease-in-out infinite; }
@keyframes idle-hop {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  12% { transform: translateY(0) scale(1.06, .94); }
  45% { transform: translateY(-16px) scale(.98, 1.03); }
  80% { transform: translateY(0) scale(1.04, .96); }
}
@keyframes breathe { 0%, 100% { opacity: .22; } 50% { opacity: .45; } }
@keyframes pulse { 0%, 100% { opacity: .4; } 50% { opacity: 1; } }

.dots i { font-style: normal; animation: dot-blink 1.4s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes dot-blink { 0%, 60%, 100% { opacity: .15; } 30% { opacity: 1; } }

.seek { position: relative; width: 120px; height: 120px; display: grid; place-items: center; margin-bottom: 6px; }
.seek-pawn { width: 60px; height: 72px; animation: idle-hop 1.2s ease-in-out infinite; position: relative; z-index: 1; }
.seek-ring, .seek::before, .seek::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid var(--beech-400); opacity: 0; animation: ripple 2.4s ease-out infinite;
}
.seek::before { animation-delay: .8s; }
.seek::after { animation-delay: 1.6s; }
@keyframes ripple { 0% { transform: scale(.35); opacity: .8; } 100% { transform: scale(1.15); opacity: 0; } }

/* ---------- Lobby ---------- */
.code-form { display: flex; gap: 8px; }
.code-input {
  flex: 0 0 118px; text-align: center; text-transform: uppercase;
  font: 700 20px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .18em;
}
.code-input::placeholder { letter-spacing: .05em; font: 500 15px var(--font); text-transform: none; }
.code-form .btn { flex: 1 1 auto; }
.room-list { display: flex; flex-direction: column; gap: 9px; }
.room-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 62px; padding: 10px 14px; border: 0; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--card-shadow);
  text-align: left; cursor: pointer; animation: screen-in .25s ease both;
  border-left: 5px solid var(--beech-300);
}
.room-row:active { transform: translateY(1px); }
.room-row.four { border-left-color: var(--crimson); }
.room-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.room-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-host { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-side { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; font-size: 14px; color: var(--muted); }
.room-lock { font-size: 16px; }
.empty {
  margin: 8px 0; padding: 26px 18px; text-align: center; color: var(--muted);
  border: 2px dashed var(--line); border-radius: var(--radius);
}

/* ---------- Game against the computer: level cards ---------- */
.ai-sub { margin: -6px 2px 2px; }
.level-list { display: flex; flex-direction: column; gap: 11px; }
.level-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  min-height: 76px; padding: 12px 12px 12px 14px; border: 0; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--card-shadow);
  border-left: 5px solid var(--beech-300);
  text-align: left; cursor: pointer; animation: screen-in .25s ease both;
  transition: transform .08s ease, box-shadow .2s ease, border-color .2s ease, opacity .15s ease;
}
/* 2 / 4 players toggle above the level cards. */
.ai-players { flex: 0 0 auto; }
.level-card:nth-child(2) { animation-delay: 40ms; }
.level-card:nth-child(3) { animation-delay: 80ms; }
.level-card:active:not(:disabled) { transform: translateY(1px); }
.level-card:disabled { cursor: default; opacity: .6; }
.level-card:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
/* The level chosen last time. */
.level-card.last {
  border-left-color: var(--amber);
  box-shadow: var(--card-shadow), 0 0 0 2px rgba(232, 150, 46, .55), 0 0 16px rgba(232, 150, 46, .22);
}
/* Difficulty as rising beech sticks (same look as the walls-left sticks). */
.level-pips { flex: 0 0 auto; display: flex; gap: 4px; align-items: flex-end; height: 26px; padding-left: 2px; }
.level-pips i {
  width: 6px; border-radius: 2px;
  background: linear-gradient(90deg, var(--beech-200), var(--beech-400));
  box-shadow: 0 1px 0 var(--beech-500);
}
.level-pips i:nth-child(1) { height: 12px; }
.level-pips i:nth-child(2) { height: 18px; }
.level-pips i:nth-child(3) { height: 24px; }
.level-pips i.off { opacity: .18; box-shadow: none; }
.level-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.level-name { display: flex; align-items: center; gap: 8px; font: 700 19px/1.2 var(--serif); }
.level-tag {
  display: none; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
  font: 650 11.5px/1.3 var(--font); color: var(--amber-lo); background: rgba(232, 150, 46, .16);
}
[data-theme="dark"] .level-tag { color: var(--beech-300); }
.level-card.last .level-tag { display: inline-block; }
.level-desc { font-size: 14px; line-height: 1.3; color: var(--muted); }
.level-go { flex: 0 0 auto; font-size: 26px; line-height: 1; color: var(--beech-500); }

/* ---------- Waiting room ---------- */
.wait-card {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 18px 12px; border-radius: 20px;
  background: var(--surface); box-shadow: var(--card-shadow);
}
.wait-label { font-size: 14px; font-weight: 600; color: var(--muted); margin-bottom: -6px; }
.wait-title { font: 700 22px/1.25 var(--serif); overflow-wrap: anywhere; }
.code-tiles { display: flex; gap: 7px; border: 0; background: none; padding: 4px; cursor: pointer; }
.code-tile {
  width: 46px; height: 58px; display: grid; place-items: center; border-radius: 9px;
  font: 800 30px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; color: var(--wine-800);
  background:
    repeating-linear-gradient(90deg, rgba(196, 135, 63, 0) 0 5px, rgba(196, 135, 63, .14) 5px 6px, rgba(196, 135, 63, 0) 6px 11px),
    linear-gradient(180deg, var(--beech-100), var(--beech-300));
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset, 0 4px 0 var(--beech-500), 0 8px 14px rgba(120, 70, 20, .25);
  animation: tile-in .35s cubic-bezier(.2, .9, .3, 1.3) both;
}
@keyframes tile-in { from { transform: translateY(-14px) scale(.9); opacity: 0; } }
.badges { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.badge {
  padding: 5px 11px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: rgba(126, 37, 52, .10); color: var(--text);
}
[data-theme="dark"] .badge { background: rgba(246, 233, 218, .08); }
.note { margin: 0; font-size: 14px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* Seat list: 4-player rooms, challenges, the ready wait. */
.seat-list {
  list-style: none; margin: 0; padding: 0; width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 6px;
}
.seat-row {
  display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 4px 12px 4px 6px;
  border-radius: 12px; background: rgba(126, 37, 52, .07); text-align: left;
  animation: screen-in .25s ease both;
}
[data-theme="dark"] .seat-row { background: rgba(246, 233, 218, .06); }
.seat-token { width: 26px; height: 32px; flex: 0 0 auto; overflow: visible; }
.seat-row.free .seat-token { opacity: .25; filter: grayscale(.6); }
.seat-name { flex: 1; min-width: 0; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat-row.free .seat-name { color: var(--muted); font-weight: 500; font-style: italic; }
.seat-name .you { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 6px; }
.seat-state { flex: 0 0 auto; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seat-state.on { color: var(--ok); }
.seat-state.on::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px;
  background: var(--ok); vertical-align: 1px;
}
.seat-state.off { color: var(--danger); }
.seat-ai { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
/* With the seat list (4 players, challenges): a tighter card so the screen fits 375×667 without scrolling. */
.wait-card.seats { gap: 8px; padding: 12px 12px 14px; }
.wait-card.seats .wait-label { margin-bottom: -4px; }
.wait-card.seats .wait-title { font-size: 20px; }
.wait-card.seats .code-tile { width: 40px; height: 48px; font-size: 25px; }
.wait-card.seats .seat-list { gap: 5px; }
.wait-card.seats .lead { margin-top: 2px; font-size: 18px; }
.screen.seats .stack { gap: 8px; }
/* «Скопировать код» and «Закрыть комнату» side by side under the main invite button. */
.stack-row { display: flex; gap: 8px; }
.stack-row > .btn { flex: 1 1 0; min-width: 0; padding: 0 10px; }

/* ---------- Notice screen (challenge dead ends) ---------- */
.notice { gap: 12px; padding: 0 8px; }
.notice-icon { font-size: 56px; line-height: 1; filter: drop-shadow(0 6px 10px rgba(58, 13, 22, .22)); animation: pop-in .35s cubic-bezier(.2, .9, .3, 1.3); }
.notice-title { margin: 4px 0 0; font: 700 26px/1.2 var(--serif); }
.notice-text { max-width: 320px; font-size: 16px; line-height: 1.45; }

/* ---------- Rules ---------- */
.rules-body {
  flex: 1; padding: 6px 16px; border-radius: 18px; background: var(--surface); box-shadow: var(--card-shadow);
  font-size: 15.5px; line-height: 1.5;
}
.rules-body p { margin: 12px 0; }
.rules-body b { color: var(--wine-600); }
[data-theme="dark"] .rules-body b { color: var(--beech-300); }
.rules-body { flex: 0 0 auto; }
.section-title { margin: 6px 2px 0; font: 700 19px/1.2 var(--serif); }

/* ---------- Profile (SPEC §10.3, §10.4) ---------- */
.profile .section-title { margin-bottom: -4px; }
.prof-head {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 10px; border-radius: 18px; background: var(--surface); box-shadow: var(--card-shadow);
}
.prof-token { width: 40px; height: 48px; flex: 0 0 auto; overflow: visible; }
.prof-id { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.prof-name { font: 700 21px/1.2 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prof-rank { font-size: 13.5px; line-height: 1.3; color: var(--muted); }
.prof-rating {
  flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; padding: 7px 12px 6px;
  border-radius: 14px; color: var(--wine-800);
  background: linear-gradient(180deg, var(--beech-100), var(--beech-300));
  box-shadow: 0 1px 0 rgba(255, 255, 255, .8) inset, 0 2px 0 var(--beech-500);
}
.prof-rating-num { font: 800 24px/1 var(--serif); font-variant-numeric: tabular-nums; }
.prof-rating-label { margin-top: 2px; font-size: 11px; font-weight: 650; opacity: .75; }
.prof-provisional { margin: -6px 4px 0; font-size: 13.5px; line-height: 1.35; color: var(--muted); }
.stat-grid { flex: 0 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat {
  min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 9px 4px 8px; border-radius: 14px; text-align: center;
  background: var(--surface); box-shadow: var(--card-shadow);
}
.stat-value { font: 800 22px/1.15 var(--serif); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; font-weight: 600; line-height: 1.2; color: var(--muted); }
.stat-sub { font-size: 11.5px; line-height: 1.2; color: var(--muted); opacity: .85; }
.ai-record {
  flex: 0 0 auto; display: flex; flex-direction: column;
  padding: 2px 14px; border-radius: 16px; background: var(--surface); box-shadow: var(--card-shadow);
}
.ai-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 42px; }
.ai-row + .ai-row { border-top: 1px solid var(--line); }
.ai-level { display: flex; align-items: center; gap: 8px; font-weight: 650; }
.ai-fav {
  padding: 1px 8px; border-radius: 999px; white-space: nowrap;
  font-size: 11.5px; font-weight: 650; color: var(--amber-lo); background: rgba(232, 150, 46, .16);
}
[data-theme="dark"] .ai-fav { color: var(--beech-300); }
.ai-score { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ai-w { color: var(--ok); }
.ai-l { color: var(--danger); }
.ai-sep { color: var(--muted); }
.ai-none { padding: 11px 0; line-height: 1.35; }
.set-card {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 14px;
  padding: 14px; border-radius: 18px; background: var(--surface); box-shadow: var(--card-shadow);
}
.set-row { display: flex; align-items: center; gap: 12px; }
.set-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.set-title { font-size: 15.5px; font-weight: 700; }
.set-desc { font-size: 13px; line-height: 1.35; color: var(--muted); }
.set-row.off .set-title { color: var(--muted); }
.set-block { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
/* On/off switch (role="switch"). */
.switch {
  position: relative; flex: 0 0 auto; width: 52px; height: 32px; padding: 0; border: 0; border-radius: 999px;
  cursor: pointer; background: rgba(126, 37, 52, .22); transition: background .2s ease;
}
[data-theme="dark"] .switch { background: rgba(246, 233, 218, .18); }
.switch::after { content: ""; position: absolute; inset: -6px; } /* 44 px tap target */
.switch i {
  position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .3); transition: transform .2s ease;
}
.switch[aria-checked="true"] { background: linear-gradient(180deg, var(--amber-hi), var(--amber)); }
.switch[aria-checked="true"] i { transform: translateX(20px); }
.switch:disabled { opacity: .4; cursor: default; }
.switch:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
/* Skin tiles on the card: flat until chosen; a bit tighter (the card has its own padding). */
.set-card .skin-picker { gap: 6px; }
.set-card .skin-tile { padding: 6px 4px 7px; }
.set-card .skin-name { font-size: 12.5px; letter-spacing: -.01em; }
.set-card .skin-tile { background: var(--bg); box-shadow: 0 0 0 1px var(--line) inset; }
.set-card .skin-tile[aria-checked="true"] { box-shadow: 0 0 0 2.5px var(--amber), 0 0 14px rgba(232, 150, 46, .28); }

/* ---------- Leaderboard (SPEC §10.3) ---------- */
.lb-sub { margin: -6px 2px 0; font-size: 14px; }
.lb-card { flex: 0 0 auto; padding: 4px 6px 6px; border-radius: 18px; background: var(--surface); box-shadow: var(--card-shadow); }
.lb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.lb-row {
  display: grid; grid-template-columns: 36px minmax(0, 1fr) 62px 50px; align-items: center; gap: 6px;
  min-height: 42px; padding: 0 8px; border-radius: 10px;
  animation: screen-in .25s ease both;
}
.lb-list .lb-row + .lb-row { border-top: 1px solid var(--line); }
.lb-head { min-height: 30px; font-size: 12px; font-weight: 650; color: var(--muted); animation: none; }
.lb-rank { justify-self: center; font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-rank.top1, .lb-rank.top2, .lb-rank.top3 {
  width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%;
  font-size: 13.5px; color: var(--wine-900);
}
.lb-rank.top1 { background: linear-gradient(180deg, #FFE08A, #E8B33A); }
.lb-rank.top2 { background: linear-gradient(180deg, #F1F1F1, #BDBDBD); }
.lb-rank.top3 { background: linear-gradient(180deg, #F2C29A, #C98652); }
.lb-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 650; }
.lb-name-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-name .you { flex: 0 0 auto; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.lb-head .lb-name { font-weight: 650; }
.lb-rating { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.lb-games { text-align: right; font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.lb-head .lb-rating, .lb-head .lb-games { font-weight: 650; font-size: 12px; }
.lb-row.me { background: rgba(232, 150, 46, .16); box-shadow: 0 0 0 1.5px rgba(232, 150, 46, .55) inset; }
.lb-list .lb-row.me + .lb-row, .lb-list .lb-row + .lb-row.me { border-top-color: transparent; }
.lb-empty { margin: 14px 8px; text-align: center; font-size: 14.5px; line-height: 1.4; color: var(--muted); }
/* My row under the top list stays in view while the list scrolls. */
.lb-me {
  /* the screen's bottom padding is part of the sticky inset: pin to the real bottom edge */
  position: sticky; bottom: calc(-16px - var(--safe-bottom)); z-index: 1;
  margin: 0 -6px -6px; padding: 0 6px calc(6px + var(--safe-bottom));
  border-radius: 0 0 18px 18px; background: var(--surface);
}
.lb-gap { padding: 0 0 4px; text-align: center; line-height: 1; letter-spacing: .3em; color: var(--muted); }
.lb-me-text {
  margin: 6px 6px 4px; padding-top: 10px; border-top: 1px solid var(--line);
  text-align: center; font-size: 14px; line-height: 1.4; color: var(--muted);
}
.lb-note { margin: 0 4px; text-align: center; line-height: 1.35; }

/* ---------- Skin picker (profile) ---------- */
.skin-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.skin-tile {
  display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0;
  padding: 7px 6px 8px; border: 0; border-radius: 14px; cursor: pointer;
  background: var(--surface); box-shadow: var(--card-shadow);
  transition: transform .08s ease, box-shadow .2s ease;
}
.skin-tile:active { transform: translateY(1px); }
.skin-tile:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.skin-tile[aria-checked="true"] {
  box-shadow: var(--card-shadow), 0 0 0 2.5px var(--amber), 0 0 14px rgba(232, 150, 46, .28);
}
.skin-preview { display: block; width: 100%; height: auto; aspect-ratio: 132 / 96; border-radius: 9px; overflow: visible; }
.skin-name { font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.skin-tile[aria-checked="true"] .skin-name { color: var(--amber-lo); }
[data-theme="dark"] .skin-tile[aria-checked="true"] .skin-name { color: var(--beech-300); }

/* ---------- Game screen ---------- */
.screen.game {
  gap: 8px; overflow: hidden; justify-content: center;
  padding: calc(var(--safe-top) + 8px) 10px calc(var(--safe-bottom) + 10px);
}
.topnav:not([hidden]) + .screens .screen.game { padding-top: 4px; }

.pbar {
  flex: 0 0 auto; position: relative;
  display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 12px 0 8px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--card-shadow);
  border: 1.5px solid transparent;
  transition: border-color .25s ease, box-shadow .25s ease;
}
.pbar.turn { border-color: var(--seat-color); box-shadow: var(--card-shadow), 0 0 0 3px var(--seat-glow), 0 0 18px var(--seat-glow); }
/* Seat colours (bars, chips, pawns): amber / natural wood / plum / crimson (SPEC §10.6). */
.c-amber { --seat-color: var(--amber); --seat-glow: rgba(232, 150, 46, .35); }
.c-plum { --seat-color: var(--plum-hi); --seat-glow: rgba(140, 63, 98, .38); }
.c-natural { --seat-color: #B98A5E; --seat-glow: rgba(217, 174, 130, .5); }
.c-crimson { --seat-color: var(--crimson); --seat-glow: rgba(163, 48, 63, .35); }
[data-theme="dark"] .c-plum { --seat-color: #B8668C; --seat-glow: rgba(184, 102, 140, .35); }
[data-theme="dark"] .c-natural { --seat-color: var(--natural); --seat-glow: rgba(217, 174, 130, .35); }
[data-theme="dark"] .c-crimson { --seat-color: #D8606E; --seat-glow: rgba(216, 96, 110, .35); }
/* Eliminated (4p): no pawn on the board, greyed widget. */
.pbar.out .token, .pchip.out .token { opacity: .35; filter: grayscale(1); }
.pbar.out .pinfo, .pchip.out .cinfo { opacity: .5; }
.pbar .token { width: 34px; height: 41px; flex: 0 0 auto; overflow: visible; transition: filter .25s ease; }
/* The side to move: a steady glow in the seat colour, no motion. */
.pbar.turn .token { filter: drop-shadow(0 0 2px var(--seat-color)) drop-shadow(0 0 7px var(--seat-glow)); }
.pinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.pname { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pname .you { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 6px; }
/* Computer level badge in the opponent bar (AI games). */
.pname .lvl {
  display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px; vertical-align: 1px;
  font-size: 11.5px; font-weight: 650; color: var(--muted); background: rgba(126, 37, 52, .10);
}
[data-theme="dark"] .pname .lvl { background: rgba(246, 233, 218, .08); }
/* Rating in rated games (random opponent). */
.pname .prating {
  display: inline-block; margin-left: 7px; padding: 1px 7px; border-radius: 999px; vertical-align: 1px;
  font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--amber-lo); background: rgba(232, 150, 46, .16);
}
.pname .prating::before { content: "🏆"; margin-right: 3px; font-size: 10px; }
[data-theme="dark"] .pname .prating { color: var(--beech-300); }

/* ---------- Tutorial coach (SPEC §10.7), in place of the opponent bar ---------- */
.coach {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 3px;
  padding: 8px 12px 10px; border-radius: 16px;
  background: var(--surface); box-shadow: var(--card-shadow); border-left: 5px solid var(--amber);
}
.coach.advance { animation: coach-advance .9s ease; }
@keyframes coach-advance {
  0% { box-shadow: var(--card-shadow), 0 0 0 0 rgba(232, 150, 46, 0); }
  30% { box-shadow: var(--card-shadow), 0 0 0 3px rgba(232, 150, 46, .6), 0 0 18px rgba(232, 150, 46, .35); }
  100% { box-shadow: var(--card-shadow), 0 0 0 0 rgba(232, 150, 46, 0); }
}
.coach-top { display: flex; align-items: center; gap: 10px; min-height: 26px; }
.coach-step { font-size: 12.5px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.coach-dots { flex: 1; display: flex; gap: 5px; align-items: center; }
.coach-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(126, 37, 52, .18); transition: background .3s ease, box-shadow .3s ease; }
[data-theme="dark"] .coach-dots i { background: rgba(246, 233, 218, .18); }
.coach-dots i.on { background: var(--amber); }
.coach-dots i.cur { background: var(--amber); box-shadow: 0 0 0 3px rgba(232, 150, 46, .28); }
.coach-skip {
  flex: 0 0 auto; min-height: 44px; margin: -9px -8px -9px 0; padding: 0 8px;
  border: 0; background: transparent; cursor: pointer;
  font-size: 14px; font-weight: 650; color: var(--muted);
}
.coach-title { font: 700 17px/1.2 var(--serif); }
.coach-text { font-size: 14px; line-height: 1.35; }
.coach-hint {
  margin-top: 4px; padding: 6px 10px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; line-height: 1.3;
  background: rgba(232, 150, 46, .18); animation: fade-in .25s ease;
}
.pmeta { display: flex; align-items: center; gap: 7px; height: 14px; }
.sticks { display: flex; gap: 3px; }
.stick {
  width: 5px; height: 14px; border-radius: 1.5px;
  background: linear-gradient(90deg, var(--sk-stick-a), var(--sk-stick-b));
  box-shadow: 0 1px 0 var(--sk-stick-edge);
  transition: opacity .3s ease, transform .3s ease;
}
.stick.used { opacity: .16; transform: scaleY(.7); box-shadow: none; }
.wcount { font-size: 13px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.clock {
  flex: 0 0 auto; min-width: 58px; padding: 6px 10px; border-radius: 10px; text-align: center;
  font: 700 17px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-variant-numeric: tabular-nums;
  background: rgba(126, 37, 52, .09); color: var(--text);
}
[data-theme="dark"] .clock { background: rgba(246, 233, 218, .08); }
.clock.low { color: #fff; background: var(--danger); animation: pulse-bg 1s ease-in-out infinite; }
[data-theme="dark"] .clock.low { color: var(--wine-950); } /* white on the light dark-theme red is unreadable */
@keyframes pulse-bg { 50% { filter: brightness(1.2); transform: scale(1.04); } }
.offline {
  flex: 0 0 auto; padding: 4px 8px; border-radius: 8px; font-size: 12.5px; font-weight: 650; white-space: nowrap;
  color: var(--danger); background: rgba(194, 59, 59, .10); font-variant-numeric: tabular-nums;
}
.offline.gone { color: var(--muted); background: rgba(126, 37, 52, .08); }
[data-theme="dark"] .offline.gone { background: rgba(246, 233, 218, .08); }

/* ---------- 4 players: compact opponent chips above the board ---------- */
.chips { flex: 0 0 auto; display: flex; gap: 6px; }
.pchip {
  position: relative; flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; gap: 4px;
  height: 46px; padding: 0 6px 0 3px; border-radius: 13px;
  background: var(--surface); box-shadow: var(--card-shadow);
  border: 1.5px solid transparent;
  transition: border-color .25s ease, box-shadow .25s ease;
}
/* The side to move: a steady glow, no motion (SPEC iteration 2). */
.pchip.turn { border-color: var(--seat-color); box-shadow: var(--card-shadow), 0 0 0 2px var(--seat-glow), 0 0 12px var(--seat-glow); }
.pchip .token { width: 22px; height: 27px; flex: 0 0 auto; overflow: visible; transition: filter .25s ease; }
.pchip.turn .token { filter: drop-shadow(0 0 2px var(--seat-color)) drop-shadow(0 0 5px var(--seat-glow)); }
.cinfo { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.cname { font-weight: 700; font-size: 12.5px; line-height: 1.15; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmeta { display: flex; align-items: center; gap: 4px; height: 13px; }
.cmeta .stick { width: 4px; height: 12px; }
.cmeta .wcount { font-size: 12px; }
.pchip .clock {
  min-width: 0; margin-left: auto; padding: 1px 5px; border-radius: 6px;
  font-size: 11.5px; line-height: 1.1;
}
/* Computer seat: a small robot where a human's clock would be. */
.cbot { margin-left: auto; font-size: 11px; line-height: 1; }
.pchip .offline {
  position: absolute; top: -8px; right: 4px; z-index: 1;
  padding: 1px 6px; border-radius: 7px; font-size: 10.5px; line-height: 1.35;
  color: #fff; background: var(--danger); box-shadow: 0 2px 5px rgba(0, 0, 0, .2);
}
[data-theme="dark"] .pchip .offline { color: var(--wine-950); }
.pchip .offline.gone { color: var(--surface); background: var(--muted); }
/* Hot-seat with 4: four narrow chips, stacked content. */
.chips.four .pchip { flex-direction: column; justify-content: center; height: 62px; gap: 1px; padding: 3px 4px; }
.chips.four .cinfo { align-items: center; width: 100%; gap: 2px; }
.chips.four .cname { max-width: 100%; text-align: center; }
.chips.four .pchip .token { width: 20px; height: 24px; }

.board-area { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; min-height: 0; }
.board-wrap {
  /* JS (layoutBoard) sets the exact square size; this is only the pre-layout guess */
  width: min(100%, 52vh); aspect-ratio: 1 / 1; border-radius: 3%;
  box-shadow: var(--board-shadow);
  position: relative;
}
.board { display: block; width: 100%; height: 100%; touch-action: none; overflow: visible; }
.board.can-act { cursor: pointer; }

.status {
  flex: 0 0 auto; height: 22px; text-align: center; font-size: 15px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
  transition: color .2s ease;
}
.status.turn { color: var(--wine-600); }
[data-theme="dark"] .status.turn { color: var(--beech-300); }
.status.bad { color: var(--danger); }
.status.quiet { color: var(--muted); font-weight: 500; }

.controls { flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; }
.ctl-row { display: flex; gap: 8px; align-items: stretch; height: 44px; }
.ctl-row .segmented { flex: 1 1 auto; padding: 3px; }
.ctl-row .segmented button { min-height: 38px; }
.hint-row { justify-content: center; align-items: center; font-size: 13.5px; color: var(--muted); text-align: center; }
.orient { min-width: 86px; gap: 4px; font-size: 20px; }
.orient .o-sep { opacity: .4; font-size: 15px; }
.orient .o-h, .orient .o-v { opacity: .45; transition: opacity .15s ease, transform .15s ease; }
.orient[data-o="h"] .o-h, .orient[data-o="v"] .o-v { opacity: 1; transform: scale(1.15); }

/* ---------- Board SVG pieces ---------- */
.pawn { transition: transform .26s cubic-bezier(.3, .7, .25, 1); }
.pawn.no-anim, .pawn.no-anim * { transition: none !important; }
.pawn-lift { transform-box: fill-box; transform-origin: 50% 100%; }
.pawn-lift.hop { animation: pawn-hop .3s cubic-bezier(.3, .7, .3, 1); }
@keyframes pawn-hop {
  0% { transform: translateY(0); }
  40% { transform: translateY(-26px) scale(.97, 1.04); }
  82% { transform: translateY(0) scale(1.07, .93); }
  100% { transform: translateY(0) scale(1, 1); }
}
.pawn.gone { opacity: 0; transform-origin: center; transition: opacity .45s ease; pointer-events: none; }
.pawn-halo { opacity: 0; transition: opacity .3s ease; }
.pawn.active .pawn-halo { opacity: 1; animation: halo 1.6s ease-in-out infinite; }
@keyframes halo { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

.wall.drop { animation: wall-drop .32s cubic-bezier(.2, .9, .3, 1.25) both; }
@keyframes wall-drop {
  0% { transform: translateY(-46px); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: none; opacity: 1; }
}
.wall .w-glow { opacity: 0; fill: var(--sk-wall-glow); }
.wall .w-top { stroke: var(--sk-wall-edge); }
.wall.fresh .w-glow { animation: wall-glow 1.8s ease-out; }
@keyframes wall-glow { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }

.ghost { pointer-events: none; animation: ghost-pulse 1.1s ease-in-out infinite; }
.ghost .w-shadow, .ghost .w-grain, .ghost .w-shine { display: none; }
.ghost .w-glow { opacity: .55; }
.ghost.ok .w-glow { fill: #FBE6C2; }
.ghost.ok .w-top { fill: rgba(244, 210, 155, .95); stroke: #FFF6E4; stroke-width: 3; stroke-opacity: 1; stroke-dasharray: 10 6; }
.ghost.ok .w-side { fill: rgba(196, 135, 63, .7); }
.ghost.bad .w-glow { fill: #FF5A4E; }
.ghost.bad .w-top { fill: rgba(226, 70, 60, .8); stroke: #FFD0C8; stroke-width: 3; stroke-opacity: 1; stroke-dasharray: 10 6; }
.ghost.bad .w-side { fill: rgba(140, 30, 30, .65); }
@keyframes ghost-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .7; } }

.dot { animation: dot-in .22s ease-out both; }
.dot-core { fill: var(--sk-dot); opacity: .92; }
.dot-ring { fill: none; stroke: var(--sk-dot); stroke-width: 3; opacity: .28; }
@keyframes dot-in { from { opacity: 0; } }
.from-ring { fill: none; stroke: var(--sk-dot); stroke-width: 3.5; opacity: .3; stroke-dasharray: 7 7; }
/* Tutorial: the move to make (a ring pulsing around its dot) and the gap to close with a wall. */
.dot-pulse {
  fill: none; stroke: var(--sk-dot); stroke-width: 5;
  transform-box: fill-box; transform-origin: center; animation: target-pulse 1.3s ease-out infinite;
}
@keyframes target-pulse { 0% { opacity: .9; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.15); } }
.dot.target .dot-ring { opacity: .6; }
.tut-gap {
  fill: var(--sk-dot); fill-opacity: .35; stroke: var(--sk-dot); stroke-width: 3; stroke-dasharray: 9 6;
  pointer-events: none; animation: gap-pulse 1.3s ease-in-out infinite;
}
@keyframes gap-pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
/* Tutorial wall steps: «Стенка» asks to be pressed. */
.segmented button.nudge:not(:disabled) {
  color: var(--beech-100);
  box-shadow: 0 0 0 2px var(--amber) inset;
  animation: nudge 1.3s ease-in-out infinite;
}
@keyframes nudge { 50% { background: rgba(232, 150, 46, .35); } }
.b-tex { pointer-events: none; }

/* ---------- Result sheet ---------- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 0 10px calc(var(--safe-bottom) + 10px);
  animation: sheet-in .38s cubic-bezier(.2, .9, .25, 1.05);
}
@keyframes sheet-in { from { transform: translateY(105%); } }
.sheet-card {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 14px 14px 12px; border-radius: 22px; text-align: center;
  background: var(--surface);
  box-shadow: 0 -2px 0 rgba(255, 255, 255, .5) inset, 0 -10px 40px rgba(42, 10, 17, .30), 0 0 0 1px var(--line);
}
.res-pawn { width: 46px; height: 56px; align-self: center; margin-top: -48px; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, .35)); animation: idle-hop 1.3s ease-in-out 3; }
.res-title { margin: 0; font: 800 28px/1.15 var(--serif); }
.res-title.win { color: var(--amber-lo); }
[data-theme="dark"] .res-title.win { color: var(--beech-300); }
.res-reason { margin: -4px 0 4px; color: var(--muted); }
.res-rating { margin: -6px 0 4px; font-weight: 700; font-variant-numeric: tabular-nums; }
.res-rating.up { color: var(--ok); }
.res-rating.down { color: var(--danger); }
.res-actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.res-actions .btn { padding: 0 10px; min-width: 0; white-space: normal; line-height: 1.15; }
/* AI games: «Ещё раз» on its own row, «Сменить уровень» + «В меню» below. */
.res-actions.ai { grid-template-columns: 1fr 1fr; }
.res-actions.ai #btnRematch { grid-column: 1 / -1; }
.res-actions.ai .btn-secondary { min-height: 46px; font-size: 15px; }
#btnRematch.two-line { flex-direction: column; gap: 2px; min-height: 56px; padding-top: 6px; padding-bottom: 6px; }
.btn-sub { font-size: 12.5px; font-weight: 550; letter-spacing: 0; opacity: .72; }
.res-offer {
  margin: 0; padding: 8px 12px; border-radius: 12px; font-weight: 650;
  background: rgba(232, 150, 46, .16); color: var(--text); animation: pulse-soft 1.6s ease-in-out infinite;
}
@keyframes pulse-soft { 50% { background: rgba(232, 150, 46, .30); } }

.confetti { position: absolute; inset: -60vh 0 0 0; pointer-events: none; overflow: hidden; }
.chip {
  position: absolute; top: -20px; width: 7px; height: 20px; border-radius: 2px;
  animation: chip-fall var(--dur, 2.4s) cubic-bezier(.25, .6, .4, 1) var(--delay, 0s) forwards;
}
@keyframes chip-fall {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx, 0), 75vh) rotate(var(--rot, 540deg)); opacity: 0; }
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(26, 10, 15, .55);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: fade-in .2s ease;
}
@keyframes fade-in { from { opacity: 0; } }
.modal-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px;
  padding: 20px 18px 16px; border-radius: 20px; background: var(--surface);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
  animation: pop-in .26s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes pop-in { from { transform: scale(.92); opacity: 0; } }
.modal-card.shake { animation: shake .4s ease; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }
.modal-title { margin: 0; font: 700 20px var(--serif); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn { flex: 1; }

/* ---------- Consent for bot messages (SPEC §10.4) ---------- */
.consent-card { text-align: center; }
.consent-ico { align-self: center; font-size: 40px; line-height: 1; animation: pop-in .35s cubic-bezier(.2, .9, .3, 1.3); }
.consent-text { margin: 0; font-size: 16px; line-height: 1.45; }
.consent-card .modal-actions .btn { padding: 0 10px; white-space: normal; line-height: 1.15; }

/* ---------- Choice sheet ---------- */
.choice-card { gap: 10px; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice-opt {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  min-height: 56px; padding: 9px 14px; border: 0; border-radius: var(--radius); text-align: left; cursor: pointer;
  background: var(--bg); box-shadow: 0 0 0 1px var(--line) inset;
  border-left: 5px solid var(--beech-300);
}
.choice-opt:active { transform: translateY(1px); }
.choice-opt:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.choice-opt.last { border-left-color: var(--amber); }
.choice-label { font: 700 17px/1.25 var(--serif); }
.choice-desc { font-size: 13.5px; color: var(--muted); line-height: 1.3; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  top: calc(var(--safe-top) + 12px); width: min(92vw, 420px);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  padding: 11px 16px; border-radius: 14px; font-size: 14.5px; font-weight: 600; text-align: center;
  color: var(--beech-100); background: rgba(42, 10, 17, .94);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .3);
  animation: toast-in .28s cubic-bezier(.2, .9, .3, 1.2);
}
.toast.error { background: linear-gradient(180deg, #8E2230, #6B1D2C); }
[data-theme="dark"] .toast { background: rgba(246, 233, 218, .96); color: var(--wine-900); }
[data-theme="dark"] .toast.error { background: #F3C6C0; color: #4A111C; }
.toast.out { opacity: 0; transform: translateY(-8px); transition: opacity .3s ease, transform .3s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.96); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Short screens (e.g. 375×667 inside Telegram): tighten the menu. */
@media (max-height: 640px) {
  .screen { gap: 10px; }
  .hero-board { width: min(76%, 280px); }
  .wordmark { font-size: 36px; margin-top: 6px; }
  .menu-buttons { gap: 9px; }
  .btn { min-height: 46px; }
  .btn-lg { min-height: 50px; }
  .btn-sm { min-height: 44px; }
  .btn-xs { min-height: 34px; }
  .pbar { height: 48px; }
  .pbar .token { width: 30px; height: 36px; }
  .pchip { height: 42px; }
  .chips.four .pchip { height: 56px; }
  .seat-row { min-height: 38px; }
  .tut-go { min-height: 52px; }
  .coach-title { font-size: 16px; }
  .coach-text { font-size: 13.5px; line-height: 1.3; }
}
@media (max-height: 560px) {
  .hero-board { display: none; }
}
/* First launch / «Вызвать друга» on a short phone: the card or the extra button takes the decorative board's place. */
@media (max-height: 740px) {
  .menu.has-tut .hero-board, .menu.has-ch .hero-board { display: none; }
  .menu.has-tut .wordmark, .menu.has-ch .wordmark { margin-top: 14px; }
}
@media (max-height: 860px) {
  .menu.has-tut.has-ch .hero-board { display: none; }
  .menu.has-tut.has-ch .wordmark { margin-top: 14px; }
}
/* Both at once on a small phone (e.g. 375×600 inside Telegram): tighter still. */
@media (max-height: 580px) {
  .menu.has-tut .wordmark-sub { display: none; }
}
@media (max-height: 700px) {
  .menu.has-tut.has-ch { gap: 9px; }
  .menu.has-tut.has-ch .wordmark { font-size: 32px; margin-top: 4px; }
  .menu.has-tut.has-ch .wordmark-sub { display: none; }
  .menu.has-tut.has-ch .tut-go { min-height: 48px; }
  .menu.has-tut.has-ch .me-row { padding-top: 6px; padding-bottom: 6px; }
}
