/* =========================================================================
   ХО-ИКС — крестики-нолики онлайн (PWA)
   Оформление под нативное мобильное приложение: тёмная тема, стекло,
   safe-area для iOS, отсутствие скролл-баунса, крупные тач-цели.
   ========================================================================= */

:root {
  --bg: #070b16;
  --bg-soft: #0d1424;
  --card: rgba(255, 255, 255, 0.045);
  --card-strong: rgba(255, 255, 255, 0.075);
  --stroke: rgba(255, 255, 255, 0.09);
  --text: #eef2ff;
  --muted: #8f9dc0;
  --x: #ff5c7a;
  --o: #7dffcd;
  --accent: #6a5cff;
  --accent-2: #00d8e8;
  --danger: #ff6b6b;
  --ok: #45e6a8;
  --radius: 20px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

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

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: -20% -20% auto -20%;
  height: 70%;
  background:
    radial-gradient(45% 55% at 20% 10%, rgba(106, 92, 255, 0.30), transparent 70%),
    radial-gradient(40% 50% at 85% 0%, rgba(0, 216, 232, 0.22), transparent 72%),
    radial-gradient(50% 40% at 50% 100%, rgba(255, 92, 122, 0.12), transparent 70%);
  filter: blur(10px);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  z-index: 1;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

/* ------------------------------- топбар -------------------------------- */

.topbar {
  flex: 0 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 0.4px; }
.brand-mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-size: 14px;
  box-shadow: 0 6px 16px rgba(106, 92, 255, 0.45);
}
.brand-mark i { font-style: normal; line-height: 1; }
.brand-mark .bx { color: #180a12; font-weight: 800; }
.brand-mark .bo { color: #04241c; margin-left: -2px; }
.brand-name { font-size: 15px; letter-spacing: 1.4px; color: #dfe6ff; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--stroke);
  background: var(--card);
  color: var(--text);
  border-radius: 13px;
  font-size: 17px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease;
}
.icon-btn:active { transform: scale(0.92); background: var(--card-strong); }
.icon-btn.small { width: 34px; height: 34px; font-size: 14px; border-radius: 11px; }

.conn-pill {
  /* высота как у кнопки звука (.icon-btn), чтобы шапка была ровной */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  height: 40px;
  padding: 0 12px;
  font-size: 11.5px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--card);
  color: var(--muted);
  white-space: nowrap;
}
.conn-pill[data-state="on"] { color: var(--ok); border-color: rgba(69, 230, 168, 0.35); }
.conn-pill[data-state="wait"] { color: #ffd166; border-color: rgba(255, 209, 102, 0.35); }
.conn-pill[data-state="off"] { color: var(--danger); border-color: rgba(255, 107, 107, 0.35); }

/* ------------------------------- экраны --------------------------------- */

.stage { position: relative; flex: 1 1 auto; min-height: 0; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translate3d(0, 12px, 0) scale(0.99);
  transition: opacity 0.24s ease, transform 0.28s cubic-bezier(0.22, 0.61, 0.36, 1), visibility 0.28s;
  overflow: hidden;
}
.screen.is-active { opacity: 1; visibility: visible; transform: none; }

/* --------------------------- главный экран ------------------------------ */

.home {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 22px 26px;
  text-align: center;
}

.hero-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: min(46vw, 168px);
  aspect-ratio: 1 / 1;
  padding: 8px;
  border-radius: 22px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
}
.hb {
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  font-size: clamp(18px, 7vw, 30px);
  font-weight: 800;
}
.hb.c1 { color: var(--x); text-shadow: 0 0 16px rgba(255, 92, 122, 0.55); }
.hb.c0 { color: var(--o); text-shadow: 0 0 16px rgba(125, 255, 205, 0.5); }

.hero-title {
  margin: 0;
  font-size: clamp(26px, 8.6vw, 38px);
  line-height: 1.05;
  letter-spacing: -0.6px;
  background: linear-gradient(120deg, #ffffff 10%, #b9c4ff 55%, #7ff0ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub { margin: -8px 0 0; color: var(--muted); font-size: 13.5px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  font-size: 12px;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--stroke);
}
.chip b { color: var(--text); font-size: 13px; }

.cta {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 19px 22px;
  border: 0;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06121c;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.3px;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 16px 34px rgba(64, 84, 255, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.09s ease, box-shadow 0.2s ease;
}
.cta:active { transform: scale(0.975); box-shadow: 0 8px 20px rgba(64, 84, 255, 0.4); }
.cta[disabled] { opacity: 0.55; }
.cta-label { position: relative; z-index: 2; }
.cta-pulse {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  transform: translateX(-120%);
  animation: sheen 3.4s ease-in-out infinite;
}
@keyframes sheen { 0%, 62% { transform: translateX(-120%); } 92%, 100% { transform: translateX(120%); } }

.profile-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--stroke);
  width: 100%;
  max-width: 420px;
  text-align: left;
}
.profile-text { min-width: 0; }
.profile-name { font-weight: 650; font-size: 14.5px; }
.profile-hint { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
  font-size: 24px;
  flex: 0 0 auto;
}
.avatar.big { width: 48px; height: 48px; font-size: 26px; border-radius: 16px; }

.footnote { color: #66739a; font-size: 11px; margin: 0; }

/* ------------------------------- поиск ---------------------------------- */

.search {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px 24px 40px;
  text-align: center;
}

.radar {
  position: relative;
  width: min(58vw, 230px);
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}
/* Круги «радара»: расходятся из центра и гаснут.
   Анимируются только transform и opacity — их считает композитор, поэтому на
   телефоне нет ни рывков, ни мерцания. Раньше анимация шла по inset (то есть
   по раскладке): браузер каждый кадр пересчитывал геометрию, а во время
   задержки круга (animation-delay) показывал его базовый стиль — opacity по
   умолчанию 1, без ключевых кадров. Отсюда и вспышка «большого непрозрачного»
   круга при входе на экран поиска.
   Теперь кольцо сразу имеет конечный размер (inset: 2% — это 96% радара) и
   уменьшается масштабом: scale(0.167) = 16% диаметра, scale(1) = 96%.
   opacity: 0 и fill-mode both держат круг невидимым до старта анимации, так что
   любой кадр до/вне анимации ничего не показывает. Пока круг ждёт своей
   задержки, он тоже прозрачный (0% кадра = opacity 0) — круги появляются по
   очереди, а не висят стопкой в центре. */
.radar-ring {
  position: absolute;
  inset: 2%;
  border-radius: 50%;
  border: 2px solid rgba(106, 92, 255, 0.75);
  opacity: 0;
  transform: scale(0.167);
  animation: radar 2.6s cubic-bezier(0.22, 0.61, 0.36, 1) infinite both;
  will-change: transform, opacity;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.radar-ring.d2 { animation-delay: 0.85s; border-color: rgba(0, 216, 232, 0.7); }
.radar-ring.d3 { animation-delay: 1.7s; border-color: rgba(255, 92, 122, 0.6); }
@keyframes radar {
  0% { transform: scale(0.167); opacity: 0; }
  8% { transform: scale(0.29); opacity: 0.9; }
  100% { transform: scale(1); opacity: 0; }
}
/* Пока экран поиска не активен, декоративные анимации стоят на паузе: они не
   крутятся впустую на других экранах и стартуют ровно с первого кадра, а не с
   случайной середины цикла. */
.screen:not(.is-active) .radar-ring,
.screen:not(.is-active) .radar-core { animation-play-state: paused; }
.radar-core {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 40px;
  font-weight: 800;
  animation: breathe 2.2s ease-in-out infinite;
}
.radar-core .bx { font-style: normal; color: var(--x); text-shadow: 0 0 22px rgba(255, 92, 122, 0.6); }
.radar-core .bo { font-style: normal; color: var(--o); text-shadow: 0 0 22px rgba(125, 255, 205, 0.55); }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }

.search-title { margin: 6px 0 0; font-size: 21px; }
.search-timer { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 1px; }
.muted { color: var(--muted); font-size: 13px; margin: 0; max-width: 320px; }
.search-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }

/* ------------------------------- кнопки --------------------------------- */

.btn {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--card-strong);
  color: var(--text);
  font-size: 15.5px;
  font-weight: 600;
  font-family: inherit;
  padding: 14px 20px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease, opacity 0.2s ease;
  min-height: 48px;
}
.btn:active { transform: scale(0.96); }
.btn[disabled] { opacity: 0.5; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #06121c;
  border: 0;
  font-weight: 800;
}
.btn-ghost { background: var(--card); }
.btn-ghost.danger { color: #ffb3b3; border-color: rgba(255, 107, 107, 0.3); }
.btn-link { background: none; border: 0; color: var(--muted); font-size: 13.5px; padding: 8px; min-height: 40px; }
.btn-small { padding: 9px 13px; font-size: 13px; border-radius: 12px; min-height: 38px; }

/* -------------------------------- матч ---------------------------------- */

.match {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 12px 10px;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--stroke);
  transition: box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  flex: 0 0 auto;
}
.player-card.active {
  border-color: rgba(106, 92, 255, 0.55);
  background: rgba(106, 92, 255, 0.10);
  box-shadow: 0 0 0 1px rgba(106, 92, 255, 0.25), 0 10px 26px rgba(64, 84, 255, 0.22);
}
.player-card.reacting { animation: cardFlash 0.6s ease; }
@keyframes cardFlash {
  0% { box-shadow: 0 0 0 0 rgba(125, 255, 205, 0.55); }
  100% { box-shadow: 0 0 0 18px rgba(125, 255, 205, 0); }
}
.player-card .pinfo { min-width: 0; flex: 1 1 auto; }
.pname { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pmeta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.pscore {
  font-size: 26px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 34px;
  text-align: center;
}
.mark-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px;
  padding: 0 5px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 800;
  background: rgba(255, 92, 122, 0.16);
  color: var(--x);
}
.mark-badge[data-mark="O"] { background: rgba(125, 255, 205, 0.15); color: var(--o); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px rgba(69, 230, 168, 0.8); }
.dot.off { background: #6b7699; box-shadow: none; }

.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  width: min(94%, 44svh, 420px);
  width: min(94%, 44vh, 420px);
  aspect-ratio: 1 / 1;
  padding: 10px;
  border-radius: 26px;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
}
@supports (height: 100svh) {
  .board { width: min(94%, 44svh, 420px); }
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.055);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.09s ease, box-shadow 0.25s ease;
  overflow: hidden;
}
/* Подсветка свободных клеток в свой ход — та же фиолетовая рамка, что и в
   начале раунда на пустой доске. Раньше её несла только пара `.hint`
   (первый ход раунда), поэтому со второго хода поле выглядело «погасшим».
   Теперь подсветку несёт `.playable` (это ровно те клетки, куда можно
   ходить), а `.hint` остался смысловым маркером пустой доски. */
.cell.playable, .cell.hint { box-shadow: inset 0 0 0 1px rgba(106, 92, 255, 0.35); }
.cell.playable:active {
  transform: scale(0.95);
  background: rgba(106, 92, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(106, 92, 255, 0.6);
}
.cell:not(.playable) { cursor: default; }
.cell.pending .sym { opacity: 0.55; }
.cell.win {
  background: rgba(106, 92, 255, 0.16);
  border-color: rgba(125, 255, 205, 0.45);
  animation: winPulse 1.2s ease-in-out infinite;
}
@keyframes winPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(125, 255, 205, 0.0); }
  50% { box-shadow: 0 0 26px 2px rgba(125, 255, 205, 0.32); }
}
.cell.shake { animation: shake 0.32s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.sym { width: 72%; height: 72%; overflow: visible; }
.sym path, .sym circle { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.sym.x path { stroke: var(--x); stroke-width: 9; filter: drop-shadow(0 0 10px rgba(255, 92, 122, 0.5)); }
.sym.o circle { stroke: var(--o); stroke-width: 9; filter: drop-shadow(0 0 10px rgba(125, 255, 205, 0.45)); }
/* По умолчанию символ статичен: контур уже нарисован целиком. */
.sym.x .s1, .sym.x .s2 { stroke-dasharray: 82; stroke-dashoffset: 0; }
.sym.o circle { stroke-dasharray: 182; stroke-dashoffset: 0; }
/* Анимация рисования — только у нового хода: класс `draw` вешает клиент и
   снимает его, когда штрих дорисован. Символы, которые уже были на доске,
   не перерисовываются, поэтому ни одного повтора анимации не происходит. */
.sym.x.draw .s1 { stroke-dashoffset: 82; animation: draw 0.18s ease forwards; }
.sym.x.draw .s2 { stroke-dashoffset: 82; animation: draw 0.18s ease 0.13s forwards; }
.sym.o.draw circle { stroke-dashoffset: 182; animation: draw 0.32s ease forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.sym.pop { animation: symPop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1); }
@keyframes symPop { 0% { transform: scale(0.72); } 100% { transform: scale(1); } }

.turn-banner {
  font-size: 13px;
  font-weight: 650;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: var(--card);
  color: var(--muted);
  transition: color 0.2s ease, background 0.2s ease;
}
.turn-banner[data-turn="me"] { color: #d8e0ff; background: rgba(106, 92, 255, 0.16); border-color: rgba(106, 92, 255, 0.4); }
.turn-banner[data-turn="win"] { color: #06231a; background: linear-gradient(135deg, var(--o), #b6ffe6); border-color: transparent; }
.turn-banner[data-turn="lose"] { color: #2a0a12; background: linear-gradient(135deg, var(--x), #ffb3c2); border-color: transparent; }

/* ---------------------------- эмодзи-панель ----------------------------- */

.emoji-bar {
  flex: 0 0 auto;
  /* Ровно 6 кнопок в ряду, два ряда — все 12 эмодзи видны сразу и по центру.
     Прокрутки вбок нет: раньше часть кнопок уезжала за правый край экрана. */
  display: grid;
  grid-template-columns: repeat(6, var(--emoji-size, 44px));
  justify-content: center;
  gap: var(--emoji-gap, 5px);
  padding: 6px 2px 2px;
}
.emoji-btn {
  width: var(--emoji-size, 44px);
  height: var(--emoji-size, 44px);
  display: grid;
  place-items: center;
  padding: 0; /* глиф строго по центру кнопки */
  font-size: 24px;
  line-height: 1;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: var(--card);
  cursor: pointer;
  transition: transform 0.09s ease, background 0.18s ease, opacity 0.2s ease;
}
.emoji-btn:active { transform: scale(0.9); background: var(--card-strong); }
.emoji-btn.cool { opacity: 0.4; }

/* --------------------------- всплывающие эмодзи -------------------------- */

.fx-layer {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none; /* слой только показывает: нажатия проходят сквозь него */
  overflow: hidden;
}
.fx-emoji {
  position: absolute;
  font-size: 34px;
  line-height: 1;
  pointer-events: none; /* и сам глиф не перехватывает тап по доске и кнопкам */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  will-change: transform, opacity;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.45));
  animation: floatUp var(--dur, 2600ms) cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
}
/* Одна кривая на оба направления: сторону полёта задаёт знак --rise
   (свои — вверх, чужие — сверху вниз), а размер за полёт плавно растёт
   ровно вдвое: 0.5× → 2× к последнему кадру. */
@keyframes floatUp {
  0% { transform: translate3d(0, 0, 0) scale(0.5) rotate(0deg); opacity: 0; filter: blur(4px); }
  10% { transform: translate3d(calc(var(--dx) * 0.06), calc(var(--rise) * 0.10), 0) scale(0.92) rotate(calc(var(--rot) * 0.25)); opacity: 1; filter: blur(0); }
  38% { transform: translate3d(calc(var(--dx) * 0.34), calc(var(--rise) * 0.40), 0) scale(1.34) rotate(calc(var(--rot) * 0.55)); opacity: 1; }
  72% { transform: translate3d(calc(var(--dx) * 0.74), calc(var(--rise) * 0.78 + var(--dy) * 0.55), 0) scale(1.72) rotate(calc(var(--rot) * 0.82)); opacity: 0.9; }
  100% { transform: translate3d(var(--dx), calc(var(--rise) + var(--dy)), 0) scale(2) rotate(var(--rot)); opacity: 0; }
}

/* -------------------------------- модалки ------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(4, 6, 14, 0.62);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  width: 100%;
  max-width: 520px;
  padding: 24px 20px calc(20px + var(--sab));
  border-radius: 28px 28px 0 0;
  background: linear-gradient(180deg, #131b32, #0b1020);
  border: 1px solid var(--stroke);
  border-bottom: 0;
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  animation: sheetUp 0.32s cubic-bezier(0.22, 0.61, 0.36, 1);
}
@keyframes sheetUp { from { transform: translateY(30%); opacity: 0.4; } to { transform: none; opacity: 1; } }

@media (min-width: 560px) {
  .modal { align-items: center; }
  .modal-card { border-radius: 28px; border-bottom: 1px solid var(--stroke); padding-bottom: 22px; }
  /* на широком экране лист итога тоже прижимаем к низу: иначе он оказывается
     ровно на доске и победной линии не видно */
  body.result-open .modal { align-items: flex-end; }
}

.result-emoji { font-size: 54px; line-height: 1; animation: symPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
.result-title { margin: 0; font-size: 25px; }
.result-sub { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.result-why { margin: -4px 0 6px; color: var(--muted); font-size: 12.5px; opacity: 0.85; }
.result-why:empty { display: none; }

/* ------------------- итог раунда: доска остаётся видна ------------------- */
/* Раньше лист результата накрывал доску целиком, и проигравший не понимал,
   из-за какой линии проиграл. Пока итог открыт (`body.result-open`), поле
   уменьшается и поднимается вверх, фон затемняется слабее, а клетки вне
   победной линии притухают — победная линия читается даже за листом. */
body.round-over .cell:not(.win) { opacity: 0.45; }
body.round-over .board { border-color: rgba(125, 255, 205, 0.28); }
body.result-open .board-wrap { justify-content: flex-start; padding-top: 2px; }
body.result-open .board { width: min(62%, 30svh, 300px); transition: width 0.32s cubic-bezier(0.22, 0.61, 0.36, 1); }
body.result-open .player-card { padding: 6px 10px; }
body.result-open .modal-card { padding-top: 18px; gap: 8px; }
body.result-open .result-emoji { font-size: 42px; }
body.result-open #resultModal {
  background: rgba(4, 6, 14, 0.34);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(4, 6, 14, 0.7);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  animation: fadeIn 0.2s ease;
}
.overlay-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 22px 26px;
  border-radius: 22px;
  background: #101830;
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  max-width: 340px;
  text-align: center;
  font-size: 14.5px;
}
.spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-2);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------ установка ------------------------------- */

.install-bar {
  position: fixed;
  left: calc(12px + var(--sal));
  right: calc(12px + var(--sar));
  bottom: calc(12px + var(--sab));
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(19, 27, 50, 0.94);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  animation: sheetUp 0.3s ease;
}
.install-icon { font-size: 20px; }
.install-text { flex: 1 1 auto; font-size: 12.5px; color: #cfd8f5; line-height: 1.35; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--sab));
  transform: translateX(-50%);
  z-index: 100;
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(23, 32, 58, 0.96);
  border: 1px solid var(--stroke);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: toastIn 0.24s ease;
  max-width: 86vw;
  text-align: center;
  /* Уведомление только сообщает — оно не должно перехватывать нажатия.
     Под ним бывают кнопки (модалка результата, подсказка установки), и
     тап обязан проходить сквозь тост в любом случае. */
  pointer-events: none;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Место тоста, когда внизу есть панели: правила идут от низкой позиции к
   высокой, чтобы при нескольких открытых панелях побеждала самая высокая. */

/* Подсказка установки — фиксированная панель внизу, на Android в ней кнопка
   «Установить»: пока панель видна, тост поднимаем над ней. */
body.install-open .toast { bottom: calc(84px + var(--sab)); }

/* в матче тост поднимаем выше панели эмодзи, чтобы не перекрывать её
   (панель теперь в два ряда и стала выше) */
body.in-match .toast { bottom: calc(160px + var(--sab)); }

/* Пока открыта модалка результата (bottom sheet с кнопками «Играть снова» /
   «Новый противник» / «На главную») или оверлей ожидания соперника, тост
   уезжает наверх, под шапку: внизу он ложился ровно на эти кнопки и закрывал
   их. Это правило последнее — оно перебивает `bottom` предыдущих. */
body.overlay-open .toast {
  top: calc(60px + var(--sat));
  bottom: auto;
  animation: toastInTop 0.24s ease;
}
@keyframes toastInTop { from { opacity: 0; transform: translate(-50%, -12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* --------------------------- адаптив и мелочи ---------------------------- */

@media (max-height: 700px) {
  /* компактный режим для невысоких экранов (iPhone SE/13 mini и т.п.):
     уменьшаем декор, но тач-цели держим не меньше 44px */
  .hero-board { width: min(38vw, 132px); }
  /* счётчики не прячем: в Safari у iPhone 13 видимая высота ~664px, и именно
     там «Игроков онлайн / Игр сейчас / В поиске» нужны — просто делаем строку
     плотнее, чтобы главный экран по-прежнему помещался без прокрутки */
  .chips { gap: 6px; }
  .chip { font-size: 11px; padding: 5px 9px; }
  .chip b { font-size: 12px; }
  .cta { padding: 17px 20px; font-size: 17.5px; }
  .footnote { display: none; }
  .board { gap: 6px; padding: 8px; }
  /* размер кнопок задаёт сетка панели (--emoji-size), здесь только глиф и
     промежуток — тач-цель остаётся не меньше 44px */
  .emoji-bar { --emoji-gap: 4px; }
  .emoji-btn { font-size: 22px; }
  .player-card { padding: 7px 10px; }
  .avatar.big { width: 44px; height: 44px; font-size: 23px; border-radius: 14px; }
  /* итог раунда: на низком экране лист занимает больше половины высоты,
     поэтому поле ужимается сильнее — иначе победная линия уедет под него */
  body.result-open .board { width: min(50%, 26svh, 240px); }
  body.result-open .emoji-bar { --emoji-size: 40px; }
}
@media (min-height: 820px) {
  .board { width: min(94%, 46svh, 440px); }
  body.result-open .board { width: min(58%, 32svh, 340px); }
}

/* совсем низкие экраны (iPhone SE в Safari, ландшафт): ради кнопки «Найти
   противника!» жертвуем строкой счётчиков */
@media (max-height: 560px) {
  .chips { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  /* без движения «радар» остаётся читаемым: три статичных кольца разного
     размера вместо расходящихся волн */
  .radar-ring { animation: none !important; opacity: 0.5; transform: scale(1); }
  .radar-ring.d2 { opacity: 0.36; transform: scale(0.72); }
  .radar-ring.d3 { opacity: 0.24; transform: scale(0.45); }
}
