/* ==========================================================================
   GridArena Gomoku · Modern Aesthetic Dark Theme
   ========================================================================== */

:root {
  --bg-primary: #0d1117;  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --border-subtle: #30363d;
  --border-focus: #58a6ff;
  
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --text-dim: #6e7681;
  
  --accent-blue: #388bfd;
  --accent-blue-hover: #1f6feb;
  --accent-emerald: #238636;
  --accent-emerald-hover: #2ea043;
  --accent-gold: #f59e0b;
  --accent-purple: #8957e5;
  --accent-red: #da3633;

  /* Основное действие (primary). Раньше это была заливка #388bfd → #1f6feb —
     ярче любого элемента интерфейса, из-за чего кнопка «выпадала» из тёмной
     графитовой гаммы доски. Теперь это приглушённый сапфир в тон сетке
     (#3e4858) и светлому акценту (#58a6ff). */
  --btn-primary-grad: linear-gradient(135deg, #31608a 0%, #1a344d 100%);
  --btn-primary-grad-hover: linear-gradient(135deg, #3a6d9b 0%, #21405c 100%);
  --btn-primary-border: rgba(88, 166, 255, 0.45);
  --btn-primary-text: #e8f2fd;
  --btn-primary-shadow: 0 4px 14px rgba(9, 28, 46, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.07);
  --btn-primary-shadow-hover: 0 6px 18px rgba(12, 38, 62, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.1);

  --stone-black: radial-gradient(circle at 35% 35%, #555 0%, #1a1a1a 60%, #000 100%);
  --stone-white: radial-gradient(circle at 35% 35%, #ffffff 0%, #e6e6e6 55%, #b5b5b5 100%);
  
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-stone: 0 4px 8px rgba(0, 0, 0, 0.6);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  /* Единая ширина контента: карточка матча, доска и нижние плашки
     должны совпадать по краям. Раньше у доски и плашек стоял свой
     max-width: 440px, и они были на 12px уже карточки. */
  --app-max-width: 480px;
  --app-pad-x: 14px;
  /* Единая шкала отступов: 4 / 6 / 8 / 12 / 16 */
  --sp-1: 4px;
  --sp-2: 6px;
  --sp-3: 8px;
  --sp-4: 12px;
  --sp-5: 16px;
  /* Внутри карточек: тот же инсет, что у внешних блоков */
  --card-pad-x: var(--app-pad-x);
  --card-pad-y: var(--sp-4);
  --stack-gap: 10px;
  --content-width: calc(min(100%, var(--app-max-width)) - var(--app-pad-x) * 2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html {
  overscroll-behavior: none;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: clip;
  overscroll-behavior: none;
  line-height: 1.4;
}

/* Контейнер приложения */
.app-container {
  width: 100%;
  max-width: var(--app-max-width);
  min-height: 100vh;
  min-height: 100dvh;
  /* В Telegram-полноэкранном режиме высота окна точнее, чем 100dvh:
     её отдаёт WebApp.viewportStableHeight (--app-vh из game.js). */
  min-height: var(--app-vh, 100dvh);
  display: flex;
  flex-direction: column;
  /* --tg-inset-* приходят из Telegram WebApp: системный вырез + панель
     самого Telegram (кнопки «Закрыть»/«Свернуть» в полноэкранном режиме) */
  padding:
    calc(max(env(safe-area-inset-top, 0px), var(--tg-inset-top, 0px)) + 10px)
    var(--app-pad-x)
    calc(max(env(safe-area-inset-bottom, 0px), var(--tg-inset-bottom, 0px)) + 16px);
  /* В горизонтальной ориентации iPhone вырез слева/справа: не даём
     контенту уехать под него. */
  padding-left: max(var(--app-pad-x), env(safe-area-inset-left, 0px),
                    var(--tg-inset-left, 0px));
  padding-right: max(var(--app-pad-x), env(safe-area-inset-right, 0px),
                     var(--tg-inset-right, 0px));
  position: relative;
}

/* Полноэкранный режим на мобильных: тело и контейнер занимают всю
   видимую область, без «окна» с полями. На ПК этот класс не включается. */
html.tg-fullscreen,
body.tg-fullscreen {
  /* Тот же запас под кнопки Telegram, что у шапки приложения. */
  --modal-top-gap: max(
    calc(env(safe-area-inset-top, 0px) + 56px),
    calc(var(--tg-inset-top, 0px) + 10px)
  );
  height: 100%;
  min-height: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
}

html.tg-fullscreen .app-container,
body.tg-fullscreen .app-container {
  height: var(--app-vh, 100dvh);
  min-height: 0;
  max-height: var(--app-vh, 100dvh);
  overflow: hidden;
}

/* Скроллится только контент экрана, шапка остаётся над ним и не может
   уехать под кнопки «Закрыть»/«Свернуть». */
html.tg-fullscreen .screen-view,
body.tg-fullscreen .screen-view {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
html.tg-fullscreen .screen-view > *,
body.tg-fullscreen .screen-view > * {
  flex-shrink: 0;
}

html.tg-fullscreen .app-container,
body.tg-fullscreen .app-container {
  max-width: none;
  min-height: var(--app-vh, 100dvh);
  /* Даже если Telegram ещё не прислал contentSafeAreaInset, шапка не должна
     уезжать под «Закрыть»/«Свернуть». После события остаётся точное значение. */
  padding-top: max(
    calc(env(safe-area-inset-top, 0px) + 56px),
    calc(var(--tg-inset-top, 0px) + 10px)
  );
}

/* Верхняя панель */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 10px;
}

/* Бренд в шапке: Фрагменты темной доски (Dark Goban Board Fragments) */
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Кнопка "Домой" в виде стилизованного логотипа GA */
.ga-home-btn {
  background: linear-gradient(145deg, #18202c 0%, #0f141d 100%);
  border: 1px solid rgba(88, 166, 255, 0.28);
  border-radius: 9px;
  height: 36px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 2px 6px rgba(0, 0, 0, 0.45);
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  flex-shrink: 0;
}

.ga-home-arrow {
  font-size: 15px;
  line-height: 1;
  color: #8b949e;
  margin-right: 4px;
  font-weight: 700;
  transition: transform 0.15s ease, color 0.15s ease;
}

.ga-home-btn:hover {
  background: linear-gradient(145deg, #222d3e 0%, #141c28 100%);
  border-color: rgba(88, 166, 255, 0.55);
  box-shadow: 
    0 0 12px rgba(56, 139, 253, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.ga-home-btn:hover .ga-home-arrow {
  color: #58a6ff;
  transform: translateX(-2px);
}

.ga-home-btn:active {
  transform: translateY(0.5px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.ga-logo-monogram {
  display: inline-flex;
  align-items: baseline;
  gap: 1px;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-weight: 900;
  font-size: 14.5px;
  letter-spacing: 0.5px;
  line-height: 1;
}

.ga-m-g {
  background: 
    radial-gradient(circle at 3px 3px, #bae6fd 0.9px, transparent 1.1px),
    linear-gradient(to right, rgba(88, 166, 255, 0.65) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(88, 166, 255, 0.65) 1px, transparent 1px),
    linear-gradient(135deg, #ffffff 0%, #93c5fd 50%, #2563eb 100%);
  background-size: 5px 5px, 5px 5px, 5px 5px, 100% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0 0 1px rgba(147, 197, 253, 0.8));
}

.ga-m-a {
  background: 
    radial-gradient(circle at 3px 3px, #fef08a 0.9px, transparent 1.1px),
    linear-gradient(to right, rgba(245, 158, 11, 0.7) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(245, 158, 11, 0.7) 1px, transparent 1px),
    linear-gradient(135deg, #ffffff 0%, #fde047 50%, #d97706 100%);
  background-size: 5px 5px, 5px 5px, 5px 5px, 100% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  filter: drop-shadow(0 0 1px rgba(253, 224, 71, 0.8));
}

/* Логотип Grid Arena: строчные буквы, богатая заливка цветом и сетка доски */
.brand-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.brand-title.hidden {
  display: none !important;
}

.brand-title:hover {
  opacity: 0.92;
  transform: translateY(-0.5px);
}

.brand-letter-mask {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 21.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: none; /* Строчные буквы Grid Arena */
  display: inline-block;
  line-height: 1;
  position: relative;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* Grid: сочный сапфирово-синий градиент + сетка доски */
.brand-word-grid {
  background-color: #1d4ed8;
  background-image:
    radial-gradient(circle at 4px 4px, #ffffff 1.2px, transparent 1.4px),
    linear-gradient(to right, rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    linear-gradient(135deg, #dbeafe 0%, #60a5fa 35%, #2563eb 70%, #1e40af 100%);
  background-size: 8px 8px, 8px 8px, 8px 8px, 100% 100%;
  background-position: 0 0;
  filter: drop-shadow(0 0 4px rgba(59, 130, 246, 0.75)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.85));
  -webkit-text-stroke: 0.35px rgba(255, 255, 255, 0.45);
}

/* Arena: сочный янтарно-золотой градиент + сетка доски */
.brand-word-arena {
  background-color: #d97706;
  background-image:
    radial-gradient(circle at 4px 4px, #ffffff 1.2px, transparent 1.4px),
    linear-gradient(to right, rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    linear-gradient(135deg, #fef9c3 0%, #fbbf24 35%, #f59e0b 70%, #b45309 100%);
  background-size: 8px 8px, 8px 8px, 8px 8px, 100% 100%;
  background-position: 0 0;
  filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.75)) drop-shadow(0 2px 4px rgba(0, 0, 0, 0.85));
  -webkit-text-stroke: 0.35px rgba(255, 255, 255, 0.45);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-main);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  border-color: rgba(240, 246, 252, 0.25);
  background: var(--bg-tertiary);
}

.icon-btn:active {
  transform: scale(0.92);
  background: var(--bg-tertiary);
}

/* Статус-карточка игроков */
.status-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 14px 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.match-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.player-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  transition: opacity 0.2s ease;
}

.player-head.right {
  justify-content: flex-end;
}

.player-head.inactive {
  opacity: 0.4;
}

.player-avatar-wrap {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.player-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.player-avatar-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: #bae6fd;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  background: linear-gradient(135deg, #1e293b, #0f172a);
  user-select: none;
}

.player-avatar-fallback.bot-fallback {
  background: linear-gradient(135deg, #1e293b, #090d16);
  border-color: rgba(56, 139, 253, 0.45);
  box-shadow: 0 0 8px rgba(56, 139, 253, 0.25);
  font-size: 18px;
}

.stone-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  z-index: 2;
}

.stone-badge.black {
  background: radial-gradient(circle at 35% 35%, #475569 0%, #0f172a 70%, #020617 100%);
}

.stone-badge.white {
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #e2e8f0 60%, #94a3b8 100%);
}

.stone-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: var(--shadow-stone);
}

.stone-icon.black {
  background: var(--stone-black);
  border: 1px solid #333;
}

.stone-icon.white {
  background: var(--stone-white);
  border: 1px solid #ddd;
}

.p-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.player-head.right .p-name {
  text-align: right;
}

/* Центральное табло счёта личных встреч (Head-to-Head) */
.match-score-center {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 2px 10px;
  background: rgba(13, 17, 23, 0.75);
  border: 1px solid rgba(240, 246, 252, 0.1);
  border-radius: 8px;
  flex-shrink: 0;
  margin: 0 8px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.score-digit {
  font-family: 'JetBrains Mono', 'SF Pro Display', -apple-system, monospace;
  font-size: 15px;
  font-weight: 800;
  color: var(--accent-gold, #f1c40f);
  min-width: 12px;
  text-align: center;
  line-height: 1.1;
}

.score-colon {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  line-height: 1.1;
  margin-top: -1px;
}

/* Вспомогательная нижняя строка: Рейтинг | Ход | Сложность */
.match-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.sub-col {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}

.sub-col.left {
  padding-left: 2px;
}

.sub-col.right {
  justify-content: flex-end;
  padding-right: 2px;
}

.p-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-col {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.turn-bubble {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-main);
  animation: pulse-glow 2s infinite ease-in-out;
  white-space: nowrap;
}

.diff-badge-btn {
  background: rgba(56, 139, 253, 0.12);
  border: 1px solid rgba(88, 166, 255, 0.35);
  color: #79c0ff;
  border-radius: 13px;
  padding: 3px 10px;
  height: 26px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.diff-badge-btn:hover {
  background: rgba(56, 139, 253, 0.24);
  border-color: #58a6ff;
  color: #ffffff;
}

.diff-badge-btn:active {
  transform: scale(0.94);
}

@keyframes pulse-glow {
  0%, 100% { border-color: var(--border-subtle); }
  50% { border-color: var(--accent-blue); box-shadow: 0 0 10px rgba(56, 139, 253, 0.25); }
}

/* Игровое поле */
.board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.canvas-container {
  width: 100%;
  aspect-ratio: 1 / 1;
  /* Доска ровно по ширине карточки матча. min() со 70dvh — только страховка
     для низких/альбомных экранов, чтобы квадрат не вылезал по высоте:
     на телефоне 390×844 и на десктопе 70dvh заведомо больше ширины контента. */
  max-width: min(100%, 70dvh);
  background: #191e26;
  border: 2px solid #2f3642;
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  position: relative;
  overflow: hidden;
  touch-action: none;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Метка последнего хода: лёгкий пульс, не перекрывает камень */
.last-move-pulse {
  position: absolute;
  left: 0;
  top: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 2;
  background: var(--pulse-color);
  animation: last-move-pulse 2.2s ease-in-out infinite;
}
.last-move-pulse.black { --pulse-color: #f59e0b; --pulse-rgb: 245, 158, 11; }
.last-move-pulse.white { --pulse-color: #58a6ff; --pulse-rgb: 88, 166, 255; }
.last-move-pulse.hidden { display: none; }

@keyframes last-move-pulse {
  0%, 100% { box-shadow: 0 0 4px 1px rgba(var(--pulse-rgb), 0.16); opacity: 0.92; }
  50%      { box-shadow: 0 0 9px 2.5px rgba(var(--pulse-rgb), 0.42); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .last-move-pulse { animation: none; }
}

/* Оверлей размышлений AI */
.thinking-overlay {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(22, 27, 34, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  padding: 6px 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-blue);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: opacity 0.2s ease;
}

.thinking-overlay.hidden {
  display: none;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent-blue);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Панель управления */
.game-controls {
  display: flex;
  gap: 10px;
}

.action-btn {
  flex: 1;
  height: 44px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.action-btn:active {
  transform: scale(0.97);
}

.action-btn.primary {
  background: var(--btn-primary-grad);
  color: var(--btn-primary-text);
  border-color: var(--btn-primary-border);
  box-shadow: var(--btn-primary-shadow);
}

.action-btn.primary:hover {
  background: var(--btn-primary-grad-hover);
  border-color: rgba(88, 166, 255, 0.7);
  box-shadow: var(--btn-primary-shadow-hover);
}

.action-btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.action-btn.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.action-btn.full-width {
  width: 100%;
}

/* Модальные окна */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-card);
  animation: modal-pop 0.2s ease-out;
}

/* Все модалки в fullscreen начинаются ниже кнопок «Закрыть»/«Свернуть». */
html.tg-fullscreen .modal-backdrop,
body.tg-fullscreen .modal-backdrop {
  padding-top: var(--modal-top-gap);
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

html.tg-fullscreen .modal-card,
body.tg-fullscreen .modal-card {
  max-height: calc(var(--app-vh, 100dvh) - var(--modal-top-gap) - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

@keyframes modal-pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.close-btn:hover {
  color: var(--text-main);
}

/* Выбор режима */
.mode-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.mode-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-card.active {
  border-color: var(--accent-blue);
  background: rgba(56, 139, 253, 0.08);
}

.mode-icon {
  font-size: 24px;
  display: flex;
  align-items: center;
}

.mode-content {
  flex: 1;
}

.mode-content h4 {
  font-size: 14.5px;
  font-weight: 600;
  margin-bottom: 2px;
}

.mode-content p {
  font-size: 12px;
  color: var(--text-muted);
}

.mode-subsettings {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-muted);
}

.custom-select {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  outline: none;
}

.btn-group {
  display: flex;
  gap: 6px;
  width: 100%;
}

.btn-toggle {
  flex: 1;
  height: 36px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-toggle:hover {
  border-color: rgba(240, 246, 252, 0.2);
  color: var(--text-main);
}

.btn-toggle.active {
  background: var(--btn-primary-grad);
  border-color: var(--btn-primary-border);
  color: var(--btn-primary-text);
  box-shadow: var(--btn-primary-shadow);
}

/* Выбор уровня сложности */
.difficulty-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.diff-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.diff-card:hover {
  border-color: rgba(56, 139, 253, 0.4);
}

.diff-card.active {
  background: rgba(56, 139, 253, 0.12);
  border-color: var(--accent-blue);
  box-shadow: 0 0 10px rgba(56, 139, 253, 0.15);
}

.diff-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.diff-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.diff-elo {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.1);
  padding: 1px 6px;
  border-radius: 10px;
}

.diff-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}

.brand-badge.clickable {
  cursor: pointer;
  transition: all 0.15s ease;
}

.brand-badge.clickable:hover {
  background: rgba(56, 139, 253, 0.25);
  border-color: var(--accent-blue);
}

/* PvP Действия */
.pvp-actions {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ==========================================================================
   Онлайн-лобби: счётчики, пулы, список ожидающих
   ========================================================================== */
.online-stats {
  display: flex;
  gap: var(--sp-3);
  margin-bottom: 0;
}

.stat-pill {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 7px 8px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-pill b {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.pool-switch {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-1);
  margin-bottom: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.pool-btn {
  flex: 1;
  min-width: 0;
  padding: 7px 6px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pool-btn:hover {
  color: var(--text-main);
}

.pool-btn.active {
  background: var(--btn-primary-grad);
  color: var(--btn-primary-text);
  box-shadow: var(--btn-primary-shadow);
}

.seek-find-btn {
  margin-top: 0;
}

.action-btn:disabled,
.tourney-btn:disabled {
  opacity: 0.45;
  cursor: default;
  filter: grayscale(0.3);
}

.seek-block {
  margin-top: 0;
}

.seek-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.seek-refresh {
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: color 0.15s ease, transform 0.2s ease;
}

.seek-refresh:hover {
  color: var(--text-main);
  transform: rotate(90deg);
}

.seek-list {
  /* Высота строки и зазор вынесены в переменные: по ним считается окно
     фиксированной высоты на 5 игроков (обычный матч). 49px — фактическая
     высота строки с ником и мета-строкой; min-height не даёт ей сжаться. */
  --seek-row-h: 49px;
  --seek-row-gap: 6px;
  display: flex;
  flex-direction: column;
  gap: var(--seek-row-gap);
}

.seek-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  min-width: 0;
  min-height: var(--seek-row-h);
  box-sizing: border-box;
}

.seek-row.mine {
  background: rgba(56, 139, 253, 0.12);
  border-color: rgba(88, 166, 255, 0.45);
}

.seek-avatar {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-main);
  background: rgba(88, 166, 255, 0.14);
  border: 1px solid rgba(88, 166, 255, 0.28);
  overflow: hidden;
}

.seek-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.seek-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.seek-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seek-meta {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seek-streak-fire {
  font-size: 10px;
  filter: drop-shadow(0 0 3px rgba(245, 158, 11, 0.8));
}

.seek-accept,
.seek-cancel {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seek-accept {
  background: var(--btn-primary-grad);
  border: 1px solid var(--btn-primary-border);
  color: var(--btn-primary-text);
}

.seek-accept:hover {
  background: var(--btn-primary-grad-hover);
  border-color: rgba(88, 166, 255, 0.75);
}

.seek-cancel {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.35);
  color: #f87171;
}

.seek-cancel:hover {
  background: rgba(248, 81, 73, 0.22);
  border-color: rgba(248, 81, 73, 0.7);
}

.seek-empty,
.seek-blocked {
  font-size: 11.5px;
  line-height: 1.45;
  border-radius: 9px;
  padding: 12px 10px;
}

.seek-empty {
  text-align: center;
  color: var(--text-dim);
}

/* Обычный матч: окно ровно на 5 строк, дальше — внутренняя прокрутка.
   Высота не зависит от того, сколько заявок пришло или ушло. */
.seek-list--fixed {
  height: calc(5 * var(--seek-row-h) + 4 * var(--seek-row-gap));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding-right: 2px;
}

.seek-list--fixed .seek-row {
  flex: 0 0 auto;
}

.seek-list--fixed .seek-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.seek-list--fixed::-webkit-scrollbar {
  width: 6px;
}

.seek-list--fixed::-webkit-scrollbar-track {
  background: transparent;
}

.seek-list--fixed::-webkit-scrollbar-thumb {
  background: rgba(139, 148, 158, 0.35);
  border-radius: 999px;
}

.seek-list--fixed::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 148, 158, 0.55);
}

.seek-blocked {
  color: var(--text-muted);
  background: rgba(240, 136, 62, 0.1);
  border: 1px solid rgba(240, 136, 62, 0.35);
}

.duel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin-top: 0;
  padding: 9px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.duel-toggle:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-main);
}

.btn-sub {
  height: 42px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-sub:active {
  transform: scale(0.97);
}

.btn-sub.primary {
  background: var(--btn-primary-grad);
  color: var(--btn-primary-text);
  border-color: var(--btn-primary-border);
  box-shadow: var(--btn-primary-shadow);
}

.btn-sub.primary:hover {
  background: var(--btn-primary-grad-hover);
  border-color: rgba(88, 166, 255, 0.7);
  box-shadow: var(--btn-primary-shadow-hover);
}

.btn-sub.secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn-sub.secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.join-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.join-row input {
  flex: 1;
  height: 42px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-main);
  padding: 0 12px;
  font-size: 14px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 1.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.join-row input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(56, 139, 253, 0.2);
}

.join-row .btn-sub {
  flex-shrink: 0;
}

/* Форма в модальных окнах (подпись к карточке партии) */
.modal-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 12px;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Реванш: две равноправные кнопки, чтобы выбор был очевиден */
.rematch-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Всплывающая плашка завершения игры (In-Game Floating Banner) */
.game-over-banner {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  /* Ровно по краям карточки матча и доски (см. --content-width).
     100% у fixed-элемента не учитывает полосу прокрутки, а 100vw — учитывает. */
  width: calc(100% - var(--app-pad-x) * 2);
  max-width: calc(var(--app-max-width) - var(--app-pad-x) * 2);
  background: rgba(22, 27, 34, 0.97);
  /* Без backdrop-filter: размытие 18px поверх анимированного canvas
     на iOS останавливало огонь ровно в момент появления плашки. */
  border: 1px solid rgba(88, 166, 255, 0.38);
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.65), 0 0 24px rgba(56, 139, 253, 0.25);
  /* Текст результата — сверху на всю ширину, кнопки — отдельной строкой снизу.
     Раньше текст делил строку с кнопками и на победе обрезался многоточием. */
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  z-index: 95;
  animation: banner-pop-up 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}

.game-over-banner.hidden {
  display: none;
}

@keyframes banner-pop-up {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(32px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

.banner-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
}

.banner-badge {
  font-size: 26px;
  line-height: 1;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 8px rgba(245, 158, 11, 0.45));
}

.game-over-banner.loss .banner-badge {
  filter: drop-shadow(0 2px 8px rgba(239, 68, 68, 0.45));
}

.banner-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.banner-title {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  background: linear-gradient(135deg, #ffffff 40%, #f59e0b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.game-over-banner.loss .banner-title {
  background: none;
  -webkit-text-fill-color: #f87171;
  color: #f87171;
}

.banner-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.35;
  margin-top: 3px;
}

.banner-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  width: 100%;
}

.banner-btn-rematch {
  height: 38px;
  min-height: 38px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 10px;
  gap: 6px;
  white-space: nowrap;
  flex: 1;
}

/* Кнопки плашки: селекторы с .action-btn, иначе их перебивает
   более специфичный .action-btn.secondary */
.action-btn.banner-btn-share {
  height: 38px;
  min-height: 38px;
  width: 38px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 38px;
  background: linear-gradient(145deg, #182838 0%, #0f1d2c 100%);
  border: 1px solid rgba(42, 171, 238, 0.45);
  color: #2aabee;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn.banner-btn-share:hover {
  background: linear-gradient(145deg, #1f364d 0%, #13273c 100%);
  border-color: #2aabee;
  color: #55c4ff;
  box-shadow: 0 0 14px rgba(42, 171, 238, 0.5);
  transform: translateY(-0.5px);
}

.action-btn.banner-btn-share:active {
  transform: translateY(0.5px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.tg-share-arrow-svg {
  display: block;
  width: 19px;
  height: 19px;
  fill: currentColor;
  transition: transform 0.15s ease;
}

.tg-share-arrow-svg.inline {
  display: inline-block;
  vertical-align: middle;
  margin-right: 6px;
}

.banner-btn-share:hover .tg-share-arrow-svg {
  transform: scale(1.08);
}

.action-btn.banner-btn-replay {
  height: 38px;
  min-height: 38px;
  width: 38px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 38px;
  background: linear-gradient(145deg, #2a2213 0%, #1a1509 100%);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #f5b942;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn.banner-btn-replay:hover {
  background: linear-gradient(145deg, #3a2f18 0%, #241d0c 100%);
  border-color: #f59e0b;
  color: #ffce6a;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.45);
  transform: translateY(-0.5px);
}

.action-btn.banner-btn-replay:active {
  transform: translateY(0.5px);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

.replay-icon-svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: currentColor;
  margin-left: 2px;
  transition: transform 0.15s ease;
}

.banner-btn-replay:hover .replay-icon-svg {
  transform: scale(1.08);
}

/* Панель покадрового повтора партии */
.replay-bar {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  /* Та же ширина, что у карточки матча, доски и плашки финала */
  width: calc(100% - var(--app-pad-x) * 2);
  max-width: calc(var(--app-max-width) - var(--app-pad-x) * 2);
  background: rgba(22, 27, 34, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(245, 158, 11, 0.38);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.65), 0 0 24px rgba(245, 158, 11, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 96;
  animation: banner-pop-up 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.replay-bar.hidden {
  display: none;
}

.replay-nav-btn {
  height: 40px;
  min-height: 40px;
  width: 44px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.replay-nav-btn:hover:not(.disabled) {
  background: rgba(88, 166, 255, 0.14);
  border-color: rgba(88, 166, 255, 0.55);
}

.replay-nav-btn:active:not(.disabled) {
  transform: translateY(1px);
}

.replay-nav-btn.disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

.replay-counter {
  min-width: 74px;
  text-align: center;
  font-size: 13.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-gold);
  letter-spacing: 0.3px;
}

.replay-close-btn {
  height: 40px;
  min-height: 40px;
  width: 40px;
  padding: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid rgba(248, 81, 73, 0.35);
  color: #f87171;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.replay-close-btn:hover {
  background: rgba(248, 81, 73, 0.22);
  border-color: rgba(248, 81, 73, 0.7);
}

/* Комната PvP лобби */
.room-details {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.room-lbl {
  font-size: 13px;
  color: var(--text-muted);
}

.room-code-badge {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--accent-gold);
  background: var(--bg-tertiary);
  border: 2px dashed var(--accent-gold);
  padding: 8px 24px;
  border-radius: var(--radius-md);
}

.room-players-status {
  width: 100%;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.room-p-line {
  display: flex;
  justify-content: space-between;
}

.room-share-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Диагностика */
.diag-card {
  max-height: 85vh;
  overflow-y: auto;
}

.diag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-bottom: 14px;
}

.diag-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border-subtle);
}

.diag-table td.k {
  color: var(--text-muted);
  width: 45%;
}

.diag-table td.v {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  color: var(--text-main);
  word-break: break-all;
}

.diag-test-buttons {
  margin-bottom: 14px;
}

.test-title {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.test-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  cursor: pointer;
}

.test-btn:active {
  background: var(--btn-primary-grad);
  color: var(--btn-primary-text);
}

.diag-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.diag-link {
  font-size: 12px;
  color: var(--accent-blue);
  text-decoration: none;
}

.diag-link:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Спринт 1.4: Стартовое лобби (Home Screen) и Шахматные часы
   ========================================================================== */

/* Переключение экранов */
.screen-view {
  display: flex;
  flex-direction: column;
  width: 100%;
  animation: screenFadeIn 0.25s ease-out;
}

.screen-view.hidden {
  display: none !important;
}

/* Экран лобби: единый ритм 12px между карточками */
#screenLobby {
  gap: var(--sp-4);
}

@keyframes screenFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.back-lobby-btn {
  font-size: 18px;
  margin-right: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.back-lobby-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
}

.hidden {
  display: none !important;
}

.ga-home-btn.hidden,
.back-lobby-btn.hidden {
  display: none !important;
}

/* Карточка профиля игрока в лобби:
   слева — аватар с ником и строкой рангов, справа — график ELO на всю высоту.
   Раньше ранги стояли третьей колонкой и на узких экранах вылезали за границы. */
.lobby-profile-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(96px, 1.05fr);
  grid-template-areas:
    "head  chart"
    "ranks chart";
  align-items: center;
  gap: var(--sp-2) 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px var(--card-pad-x);
  margin-bottom: 0;
  box-shadow: var(--shadow-card);
}

.profile-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Строка рангов: три равные плитки, значения до четырёх знаков */
.profile-ranks {
  grid-area: ranks;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--sp-1);
  min-width: 0;
}

.prank {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  padding: 2px 3px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.user-avatar-wrap {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1.5px solid rgba(88, 166, 255, 0.4);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #bae6fd;
  user-select: none;
}

.profile-info-block {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.profile-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.profile-elo-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-gold);
  background: rgba(240, 136, 62, 0.12);
  border: 1px solid rgba(240, 136, 62, 0.3);
  padding: 1px 6px;
  border-radius: 6px;
  margin-top: 3px;
  width: fit-content;
}

/* Правая колонка: график ELO на всю высоту карточки */
.profile-chart-block {
  grid-area: chart;
  align-self: stretch;
  display: flex;
  align-items: stretch;
  min-width: 0;
  padding: 0;
  cursor: pointer;
}

.sparkline-container {
  position: relative;
  width: 100%;
  min-height: 72px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.profile-chart-block:hover .sparkline-container {
  border-color: rgba(88, 166, 255, 0.45);
  background: rgba(56, 139, 253, 0.06);
  box-shadow: 0 0 12px rgba(56, 139, 253, 0.2);
}

.elo-sparkline-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

/* Точка текущего рейтинга: HTML, а не SVG — иначе при растяжении viewBox
   она превращалась в эллипс с жёсткой белой обводкой. */
.elo-tail {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: #9fd4ff;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.16), 0 0 8px rgba(88, 166, 255, 0.5);
  pointer-events: none;
  transition: left 0.25s ease, top 0.25s ease, background 0.2s ease;
}

.sparkline-container.negative .elo-tail {
  background: #ff9d9d;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.16), 0 0 8px rgba(248, 113, 113, 0.45);
}

/* Ранги: компактные плитки, читаемые при значениях вида #1234 */
.prank-lbl {
  font-size: 8.5px;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.2;
}

.prank-val {
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prank-val.gold {
  color: #f59e0b;
}

/* Карточки режимов в лобби */
.lobby-modes {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lobby-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.lobby-card.active, .lobby-card:hover {
  border-color: rgba(88, 166, 255, 0.4);
}

.lobby-card-header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--card-pad-y) var(--card-pad-x);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.015);
  user-select: none;
}

.lobby-card-header:hover {
  background: rgba(255, 255, 255, 0.04);
}

.lobby-card-icon {
  font-size: 26px;
  flex-shrink: 0;
}

.lobby-card-title-box {
  flex: 1;
  min-width: 0;
}

.lobby-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
}

.lobby-card-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.35;
  margin-top: 2px;
}

.lobby-card-arrow {
  font-size: 16px;
  color: var(--text-dim);
  transition: transform 0.2s ease;
}

.lobby-card.collapsed .lobby-card-arrow {
  transform: rotate(-90deg);
}

.lobby-card.collapsed .lobby-card-body {
  display: none;
}

.lobby-card-body {
  padding: var(--stack-gap) var(--card-pad-x) var(--card-pad-x);
  display: flex;
  flex-direction: column;
  gap: var(--stack-gap);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(13, 17, 23, 0.4);
}

.lobby-card-sm .lobby-card-header {
  padding: var(--card-pad-y) var(--card-pad-x);
}

/* Настройки внутри карточки лобби */
.config-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: 0;
}

.config-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.config-grid {
  display: grid;
  gap: 6px;
}

/* Диапазон рейтинга: два ползунка с числовыми значениями */
.rating-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 54px;
  align-items: center;
  gap: var(--sp-3);
}

.rating-lbl {
  font-size: 11px;
  color: var(--text-dim);
}

.rating-val {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rating-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;            /* зона захвата пальцем, дорожка рисуется ниже */
  background: transparent;
  outline: none;
  cursor: pointer;
}

.rating-slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(88, 166, 255, 0.35), rgba(255, 255, 255, 0.12));
}

.rating-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;      /* центрирование на дорожке 4px */
  border-radius: 50%;
  background: var(--btn-primary-grad);
  border: 1px solid rgba(150, 200, 255, 0.75);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45), 0 0 0 3px rgba(49, 96, 138, 0.22);
}

.rating-slider::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(88, 166, 255, 0.35), rgba(255, 255, 255, 0.12));
}

.rating-slider::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--btn-primary-grad);
  border: 1px solid rgba(150, 200, 255, 0.75);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
}

.rating-slider:focus-visible::-webkit-slider-thumb {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 4px rgba(88, 166, 255, 0.25);
}

.rating-hint {
  font-size: 10.5px;
  color: var(--text-dim);
  line-height: 1.3;
}

/* Кнопка приглашения: тот же вес, что у «В бой!», но с акцентным контуром */
.invite-btn {
  margin-top: var(--sp-1);
  border: 1px solid rgba(140, 190, 255, 0.45);
  box-shadow: var(--btn-primary-shadow), inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.invite-btn:active {
  transform: translateY(1px);
}

/* Подсказка в окне комнаты */
.room-wait-hint {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.35;
}

/* Плашка ожидания соперника по ссылке (игрок остаётся в лобби) */
.invite-wait-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px var(--card-pad-x);
  border-radius: var(--radius-md);
  background: rgba(56, 139, 253, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.35);
  box-shadow: 0 0 14px rgba(56, 139, 253, 0.12);
  animation: invitePulse 2.4s ease-in-out infinite;
}

@keyframes invitePulse {
  0%, 100% { border-color: rgba(88, 166, 255, 0.35); }
  50% { border-color: rgba(88, 166, 255, 0.6); }
}

.iwb-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.iwb-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
}

.iwb-sub {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
  margin-top: 1px;
}

.iwb-sub b {
  color: var(--accent-blue);
  letter-spacing: 1px;
}

.iwb-actions {
  display: flex;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.iwb-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: 1px solid rgba(88, 166, 255, 0.3);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.iwb-btn:hover {
  background: rgba(88, 166, 255, 0.16);
}

.iwb-btn.danger {
  border-color: rgba(248, 81, 73, 0.4);
  color: #ffb4ae;
}

.iwb-btn.danger:hover {
  background: rgba(248, 81, 73, 0.18);
}

.grid-4 {
  grid-template-columns: repeat(2, 1fr);
}

.grid-3 {
  grid-template-columns: 1fr;
}

.cfg-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: var(--text-muted);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cfg-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--text-main);
}

.cfg-btn.active {
  background: rgba(56, 139, 253, 0.16);
  border-color: var(--accent-blue);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 12px rgba(56, 139, 253, 0.25);
}

.lobby-start-btn {
  margin-top: 4px;
  height: 42px;
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* Баннер Ежедневного турнира */
.pvp-banner-tourney {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.14) 0%, rgba(217, 119, 6, 0.06) 100%);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  margin-top: 0;
}

.tourney-tag {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #f59e0b;
}

.tourney-title {
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
}

.tourney-desc {
  font-size: 11px;
  color: #d1d5db;
  line-height: 1.35;
}

.tourney-btn {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
  color: #000 !important;
  font-weight: 700 !important;
  border-color: #fbbf24 !important;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3) !important;
  height: 38px;
  margin-top: 4px;
}

.tourney-btn:hover {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%) !important;
}

/* ==========================================================================
   Шахматные часы в строке матча (Match Timer Row)
   ========================================================================== */
.match-timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 6px 0 4px;
  padding: 4px 6px;
  background: rgba(13, 17, 23, 0.45);
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  transition: all 0.2s ease;
}

.timer-box.active {
  background: rgba(56, 139, 253, 0.14);
  border-color: rgba(88, 166, 255, 0.5);
  box-shadow: 0 0 10px rgba(56, 139, 253, 0.25);
}

.timer-box.warning {
  background: rgba(248, 81, 73, 0.18) !important;
  border-color: rgba(248, 81, 73, 0.6) !important;
  animation: timerPulse 0.8s infinite alternate;
}

@keyframes timerPulse {
  from { box-shadow: 0 0 4px rgba(248, 81, 73, 0.3); }
  to { box-shadow: 0 0 14px rgba(248, 81, 73, 0.7); }
}

.timer-bank {
  font-family: ui-monospace, SFMono-Regular, "Roboto Mono", Consolas, monospace;
  font-size: 13.5px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
}

.timer-move {
  font-family: ui-monospace, SFMono-Regular, "Roboto Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-gold);
  background: rgba(240, 136, 62, 0.15);
  padding: 1px 4px;
  border-radius: 4px;
}

.timer-box.warning .timer-move {
  color: #ff6b6b;
  background: rgba(255, 0, 0, 0.2);
}

.time-ctrl-pill {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
  padding: 2px 8px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

/* ==========================================================================
   Модальное окно Лидерборда (Leaderboard Modal)
   ========================================================================== */
.leaderboard-modal-card {
  max-width: 440px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.lb-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-tertiary);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 12px;
}

.lb-tab {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 8px;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.lb-tab.active {
  background: var(--btn-primary-grad);
  color: var(--btn-primary-text);
  border-color: var(--btn-primary-border);
  box-shadow: var(--btn-primary-shadow);
}

.lb-info-bar {
  background: rgba(56, 139, 253, 0.08);
  border: 1px solid rgba(56, 139, 253, 0.2);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lb-info-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #fff;
}

.lb-info-sub {
  font-size: 11px;
  color: var(--accent-blue);
}

.lb-score-line {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.lb-streak-fire {
  font-size: 12px;
  line-height: 1;
  filter: drop-shadow(0 0 4px rgba(245, 158, 11, 0.8));
}

.lb-list-container {
  overflow-y: auto;
  max-height: 280px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}

.lb-loading {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 24px 0;
}

.lb-empty {
  text-align: center;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
  padding: 20px 8px;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}

/* Мой ряд: в разметке класс highlight (старый .me оставлен для совместимости) */
.lb-row.highlight,
.lb-row.me {
  background: rgba(56, 139, 253, 0.12);
  border-color: rgba(88, 166, 255, 0.4);
}

.lb-pos {
  flex: 0 0 22px;
  width: 22px;
  font-size: 13px;
  font-weight: 800;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.2;
}

/* За топ-3 приходят эмодзи-медали — держим их в тех же 22px */
.lb-pos.top {
  font-size: 14px;
}

.lb-pos.gold { color: #f59e0b; font-size: 16px; }
.lb-pos.silver { color: #94a3b8; font-size: 15px; }
.lb-pos.bronze { color: #b45309; font-size: 14px; }

/* Аватар — фиксированный круг, чтобы буква имени не наползала на текст */
.lb-avatar {
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-main);
  background: rgba(88, 166, 255, 0.14);
  border: 1px solid rgba(88, 166, 255, 0.28);
  overflow: hidden;
}

/* min-width: 0 обязателен: без него flex-элемент не сжимается ниже содержимого,
   и подпись строки наползала на колонку с очками */
.lb-name-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.lb-player-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-player-sub {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-score-col {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  min-width: 50px;
}

.lb-score-val {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--accent-gold);
  font-variant-numeric: tabular-nums;
}

.lb-score-lbl {
  font-size: 9px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.lb-my-rank {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-focus);
  border-radius: 10px;
  padding: 8px 12px;
  margin-top: 10px;
}

.my-rank-pos {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent-blue);
  width: 28px;
  text-align: center;
}

.my-rank-info {
  display: flex;
  justify-content: space-between;
  flex: 1;
  font-size: 12.5px;
  font-weight: 600;
}

/* ==========================================================================
   Модальное окно Настроек профиля и выбора аватара
   ========================================================================== */
.profile-settings-card {
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-5);
}

.avatar-preview-box {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

.avatar-preview-circle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 2px solid rgba(88, 166, 255, 0.6);
  box-shadow: 0 0 16px rgba(56, 139, 253, 0.35);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-avatar-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
  color: #bae6fd;
  user-select: none;
}

.avatar-preview-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.preview-meta-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-meta-elo {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-gold);
  margin-top: 2px;
}

.preview-meta-tip {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 4px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.2px;
}

/* Прокручиваемый контейнер пресетов эмодзи */
.avatar-preset-scroll {
  max-height: 250px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 6px 8px 4px;
  border-radius: var(--radius-md);
  background: rgba(13, 17, 23, 0.45);
  border: 1px solid rgba(255, 255, 255, 0.08);
  /* Кастомный гладкий скроллбар */
  scrollbar-width: thin;
  scrollbar-color: rgba(88, 166, 255, 0.45) rgba(255, 255, 255, 0.03);
}

.avatar-preset-scroll::-webkit-scrollbar {
  width: 6px;
}

.avatar-preset-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
}

.avatar-preset-scroll::-webkit-scrollbar-thumb {
  background: rgba(88, 166, 255, 0.4);
  border-radius: 4px;
}

.avatar-preset-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(88, 166, 255, 0.7);
}

/* Сетка пресетов эмодзи */
.avatar-preset-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px 8px;
}

.preset-avatar-btn {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.preset-avatar-btn:hover {
  transform: scale(1.12);
  border-color: rgba(88, 166, 255, 0.6);
  background: rgba(56, 139, 253, 0.18);
  box-shadow: 0 0 12px rgba(56, 139, 253, 0.4);
}

.preset-avatar-btn.active {
  border-color: #58a6ff;
  background: rgba(56, 139, 253, 0.25);
  box-shadow: 0 0 14px rgba(56, 139, 253, 0.7);
  transform: scale(1.08);
}

/* Язык интерфейса: строка с текущим значением и список в модалке */
.lang-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.lang-row:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
}

.lang-row-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-row-chevron {
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
}

.lang-card {
  max-width: 440px;
}

.lang-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(60vh, 420px);
  overflow-y: auto;
  padding-right: 2px;
}

.lang-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-main);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.lang-item:hover {
  background: rgba(255, 255, 255, 0.07);
}

.lang-item.active {
  background: rgba(56, 139, 253, 0.16);
  border-color: var(--accent-blue);
  font-weight: 600;
}

.lang-item-check {
  color: var(--accent-blue);
  font-weight: 700;
}

/* Группа языка не должна растягиваться и наезжать на кнопки действий */
.settings-group.lang-group {
  flex: 0 0 auto;
  margin: 4px 0 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

/* Кнопка «Готово» остаётся последней и не слипается с языком */
.settings-actions-final {
  margin-top: 0;
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}

/* ==========================================================================
   Модальное окно увеличенного интерактивного графика ELO
   ========================================================================== */
.elo-modal-card {
  max-width: 520px;
  width: 95%;
  background: rgba(22, 27, 34, 0.96);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(88, 166, 255, 0.35);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.7), 0 0 30px rgba(56, 139, 253, 0.15);
}

.elo-stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 14px;
}

.elo-stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.estat-lbl {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.estat-val {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 2px;
}

.estat-val.highlight {
  color: #58a6ff;
}

.estat-val.gold {
  color: #f59e0b;
}

.estat-val.muted {
  color: #8b949e;
}

.elo-chart-interactive-container {
  position: relative;
  width: 100%;
  height: 250px;
  background: linear-gradient(180deg, rgba(13, 17, 23, 0.95) 0%, rgba(22, 27, 34, 0.9) 100%);
  border: 1px solid rgba(88, 166, 255, 0.22);
  border-radius: 12px;
  overflow: visible;
  cursor: crosshair;
  touch-action: none;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
}

.elo-big-chart-svg {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 11px;
  overflow: hidden;
}

/* Линии сетки и оси в SVG */
.chart-grid-line {
  stroke: rgba(255, 255, 255, 0.07);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

.chart-grid-line-v {
  stroke: rgba(255, 255, 255, 0.05);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-axis-line {
  stroke: rgba(255, 255, 255, 0.16);
  stroke-width: 1.2;
}

.chart-tick-text {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 10px;
  fill: #8b949e;
  font-weight: 500;
}

.chart-tick-text-x {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 10px;
  fill: #8b949e;
  font-weight: 500;
}

/* Интерактивный визир и точка активного замера */
.big-chart-crosshair {
  stroke: rgba(88, 166, 255, 0.75);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.big-chart-active-dot {
  fill: #58a6ff;
  stroke: #ffffff;
  stroke-width: 2.2;
  filter: drop-shadow(0 0 6px #388bfd);
  pointer-events: none;
}

/* Плавающий интерактивный тултип */
.elo-chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(22, 27, 34, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(88, 166, 255, 0.5);
  border-radius: 8px;
  padding: 5px 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65), 0 0 12px rgba(56, 139, 253, 0.35);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
}

.elo-chart-tooltip.hidden {
  display: none !important;
}

.etip-game {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.etip-elo {
  font-size: 14.5px;
  color: #58a6ff;
  font-weight: 800;
}

.etip-delta {
  font-size: 11px;
  font-weight: 600;
}

.etip-delta.positive {
  color: #3fb950;
}

.etip-delta.negative {
  color: #f85149;
}

.etip-delta.muted {
  color: var(--text-dim);
}

.elo-axis-label-x {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 10px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

/* ==========================================================================
   UI/UX audit fixes (22.10.2026)
   Findings F1–F15: see cover_art/ui_audit/report.html
   ========================================================================== */

:root {
  --text-dim: #9aa5b1;      /* F3: was #6e7681 (3.3–3.8:1) */
  --text-muted: #aab4c0;
  --accent-gold: #f59e0b;   /* F5: match the logo amber */
  --player-black: #f59e0b;
  --player-white: #58a6ff;
}

body { overflow-x: clip; } /* F15: do not hide layout bugs behind a scrollbar */

/* F5: inline SVG icon system */
.ui-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ico {
  width: 20px;
  height: 20px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -4px;
}
.ico-sm { width: 15px; height: 15px; vertical-align: -2px; }
.ico-lg { width: 30px; height: 30px; }
.ico-fill { fill: currentColor; stroke: none; }
.ico-title { width: 18px; height: 18px; margin-right: 6px; vertical-align: -3px; }
.lobby-card-icon { display: flex; align-items: center; justify-content: center; }
.lobby-card-icon .ico { vertical-align: 0; width: 22px; height: 22px; }
.action-btn .ico { margin-right: 2px; }
.cfg-btn .ico { margin-right: 4px; }

/* F5/F6: stones and online status as CSS, not emoji */
.stone-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  margin-right: 5px;
  vertical-align: -2px;
}
.stone-dot.black {
  background: radial-gradient(circle at 35% 30%, #64748b 0%, #111827 55%, #020617 100%);
  border: 1px solid rgba(148, 163, 184, 0.55);
}
.stone-dot.white {
  background: radial-gradient(circle at 35% 30%, #ffffff 0%, #e2e8f0 60%, #94a3b8 100%);
  border: 1px solid rgba(148, 163, 184, 0.7);
}
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3fb950;
  box-shadow: 0 0 6px rgba(63, 185, 80, 0.55);
  margin-right: 6px;
  vertical-align: 1px;
}

/* F4: 44×44 hit areas without changing the visual size */
.icon-btn { position: relative; }
.icon-btn::after {
  content: "";
  position: absolute;
  inset: -3px;
  min-width: 44px;
  min-height: 44px;
}
.close-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: -6px -6px 0 0;
}
.seek-refresh {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: -12px -10px -12px 0;
}
.lb-tab { min-height: 40px; }
.cfg-btn { min-height: 38px; }

/* F3: legible micro-type */
.prank-lbl, .lb-score-lbl { font-size: 10px; letter-spacing: 0.3px; }
.config-label, .rating-lbl, .time-ctrl-pill { font-size: 11.5px; }
.lb-player-sub { font-size: 11px; }
.estat-lbl { font-size: 11px; white-space: normal; line-height: 1.2; }
.lb-info-sub { color: var(--text-muted); }

/* F6: one colour per player; active timer follows the turn */
.score-digit { color: var(--text-main); }
/* Сложность в матче — только индикатор, менять её на ходу нельзя. */
.diff-badge-btn {
  pointer-events: none;
  cursor: default;
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}
.diff-badge-btn:hover,
.diff-badge-btn:active {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
  transform: none;
}
.timer-box.left .timer-move { color: var(--player-black); }
.timer-box.right .timer-move { color: var(--player-white); }
.status-card[data-turn="black"] .timer-box.active {
  background: rgba(245, 158, 11, 0.14);
  border-color: var(--player-black);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.28);
}
.status-card[data-turn="white"] .timer-box.active {
  background: rgba(88, 166, 255, 0.14);
  border-color: var(--player-white);
  box-shadow: 0 0 10px rgba(88, 166, 255, 0.28);
}
.status-card[data-turn="black"] .turn-bubble {
  color: var(--player-black);
  border-color: rgba(245, 158, 11, 0.45);
  background: rgba(245, 158, 11, 0.12);
}
.status-card[data-turn="white"] .turn-bubble {
  color: var(--player-white);
  border-color: rgba(88, 166, 255, 0.45);
  background: rgba(88, 166, 255, 0.12);
}

/* F2: статус и доска прижаты к верхним кнопкам, без «плавающего» блока */
#screenGame { flex: 1; min-height: 0; justify-content: flex-start; }
#screenGame .board-wrapper { flex: 0 0 auto; align-items: center; }

/* F13: место под меню результата зарезервировано всегда.
   Доска не меняет ширину/высоту при появлении баннера. */
.game-over-slot {
  flex: 0 0 auto;
  height: 118px;
  margin-top: 8px;
}
.game-over-slot .game-over-banner {
  position: static;
  left: auto;
  bottom: auto;
  transform: none;
  width: 100%;
  max-width: none;
  height: 100%;
  margin: 0;
  animation: banner-in-flow 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes banner-in-flow {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.app-container.game-over .timer-box.active { opacity: 0.55; box-shadow: none; }

/* F1: 320 px status row — never overlap the timer */
@media (max-width: 359px) {
  .match-sub-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "elo diff" "time time";
    gap: 6px 8px;
    align-items: center;
  }
  .match-sub-row .sub-col.left  { grid-area: elo;  min-width: 0; justify-self: start; }
  .match-sub-row .sub-col.right { grid-area: diff; min-width: 0; justify-self: end; }
  .match-sub-row .time-ctrl-col { grid-area: time; justify-self: start; min-width: 0; }
  #btnDifficultySelect { max-width: 132px; overflow: hidden; text-overflow: ellipsis; }
  .match-main-row .match-score-center { margin: 0 2px; padding: 2px 5px; gap: 3px; }
  .match-main-row .score-digit { font-size: 13.5px; min-width: 10px; }
  .player-head .p-name { font-size: 13px; }
}

/* F7: compact lobby settings and one open accordion */
#seekColorPicker, #lobbyColorPicker, #inviteColorPicker,
#seekTimePicker, #lobbyTimerPicker, #inviteTimePicker {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
#lobbyDiffPicker,
#lobbyTimerPicker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cfg-btn { font-size: 11.5px; padding: 8px 4px; white-space: nowrap;
           overflow: hidden; text-overflow: ellipsis; }
.lobby-card-body { gap: 8px; }
@media (max-width: 360px) {
  .lobby-card-body { padding-bottom: 8px; }
}

/* F8: leaderboard mobile */
.lb-tab { white-space: nowrap; font-size: 11.5px; padding: 7px 6px; }
.lb-avatar { display: none; }
.lb-list-container, #lbList { padding-right: 8px; scrollbar-width: thin; }
.lb-player-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-pos.p1 { color: #f59e0b; }
.lb-pos.p2 { color: #cbd5e1; }
.lb-pos.p3 { color: #d97706; }
.lb-row { gap: 8px; padding: 8px 9px; }
@media (max-width: 360px) {
  .lb-tab { padding: 7px 4px; }
  .lb-score-col { min-width: 44px; }
}

/* F9: settings — one scroll area, selected avatar visible */
.profile-settings-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: calc(100dvh - 24px);
}
.profile-settings-card .modal-header,
.profile-settings-card .avatar-preview-box { flex: 0 0 auto; }
.profile-settings-card .settings-group { flex: 1; min-height: 0; }
.avatar-preset-scroll { flex: 1; min-height: 0; max-height: none; }
.settings-actions {
  flex: 0 0 auto;
  padding-top: 0;
  background: none;
}

/* Карточка настроек прокручивается целиком: раньше «липкая» панель действий
   перекрывала строку языка, и кнопка «Готово» наезжала на «Русский». */
.profile-settings-card {
  overflow-y: auto;
  overflow-x: hidden;
  gap: var(--sp-3);
}

.profile-settings-card .settings-group {
  flex: 0 0 auto;
}

/* Сетка аватаров прокручивается внутри себя и не выдавливает нижние блоки */
.avatar-preset-scroll {
  flex: 0 1 auto;
  max-height: 38vh;
}
.preset-avatar-btn.active {
  outline: 2px solid var(--accent-blue);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(56, 139, 253, 0.18);
}
/* soft fade: a partial next row reads as "scroll", not as a broken crop */
.avatar-preset-scroll {
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(180deg, #000 calc(100% - 26px), transparent 100%);
}
.preset-avatar-btn { font-size: 21px; }

/* F10: ELO modal */
.elo-stats-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; }
.elo-modal-card {
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.7);
}
.elo-chart-interactive-container {
  position: relative;
  border: 1px solid var(--border-subtle);
}
.elo-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
  background: rgba(13, 17, 23, 0.55);
  border-radius: 10px;
}
.elo-empty.hidden { display: none; }

/* F12: profile card — name gets room, chart has an empty state */
.lobby-profile-card { grid-template-columns: minmax(0, 1fr) 128px; }
.profile-chart-block { min-width: 0; }
.spark-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9.5px;
  color: var(--text-dim);
  text-align: center;
  padding: 4px;
}
.spark-empty.hidden { display: none; }
.sparkline-container { position: relative; }
.sparkline-container.empty .elo-sparkline-svg,
.sparkline-container.empty .elo-tail { display: none; }
@media (max-width: 360px) {
  .lobby-profile-card { grid-template-columns: minmax(0, 1fr) 104px; }
}
@media (max-width: 340px) {
  .lobby-profile-card { grid-template-columns: minmax(0, 1fr) 84px; }
  .profile-name { font-size: 13px; }
}

/* F13: win banner buttons and connection to the board */
.banner-actions .banner-btn-replay,
.banner-actions .banner-btn-share {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}
.banner-actions .banner-btn-replay:hover,
.banner-actions .banner-btn-share:hover {
  color: var(--text-main);
  border-color: rgba(88, 166, 255, 0.45);
}
.game-over-banner.loss .banner-badge { color: #f87171; }
.banner-badge .ico { stroke-width: 1.8; }

/* F15: focus, safe area, mono font fallback */
:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 2px; }
.modal-card { padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.timer-bank, .timer-move, .score-digit {
  font-family: ui-monospace, SFMono-Regular, "Roboto Mono", Consolas, monospace;
}

/* Small screens: keep the brand usable next to 3 header actions */
@media (max-width: 340px) {
  .brand-title { font-size: 18px; }
  .top-bar { gap: 6px; }
}



/* --- Блок «Игра с компьютером»: раскладка по макету --- */
#aiConfigBody { gap: 16px; }
#aiConfigBody .config-section { gap: 0; }
#aiConfigBody .config-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 8px;
}

/* Сетки задаём по id: старые правила вида #lobbyTimerPicker специфичнее классов */
.difficulty-grid,
#lobbyDiffPicker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.color-grid,
#lobbyColorPicker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.time-grid,
#lobbyTimerPicker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

/* Уровень: аватар 32px + название в одну строку */
.cfg-btn.difficulty-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  min-height: 48px;
  padding: 6px 10px 6px 8px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}

.difficulty-btn-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex: 0 0 auto;
  object-fit: cover;
}

.difficulty-btn span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cfg-btn.difficulty-btn.active .difficulty-btn-avatar {
  box-shadow: 0 0 0 1px rgba(43, 127, 255, 0.5), 0 0 10px rgba(43, 127, 255, 0.35);
}

/* Цвет: 3 кнопки в ряд, иконка крупнее камня */
.cfg-btn.color-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  min-height: 44px;
  padding: 0 8px;
  border-radius: 10px;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.color-btn-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  /* символ i-dice нарисован линиями: заливка закрасила бы его квадратом */
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cfg-btn.color-btn .stone-dot {
  width: 14px;
  height: 14px;
  margin: 0;
  flex: 0 0 auto;
  vertical-align: 0;
}

/* Контроль времени: 4 равные колонки */
.cfg-btn.time-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  min-height: 44px;
  padding: 0 4px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

.time-btn-infinity {
  font-size: 22px;
  line-height: 1;
}

/* Кнопка старта: flex: 1 от .action-btn перебивает height, поэтому фиксируем */
#btnStartAiGame {
  flex: 0 0 auto;
  height: 48px;
  margin-top: 4px;
  font-size: 15px;
  font-weight: 700;
  gap: 8px;
}

#btnStartAiGame .ico {
  width: 14px;
  height: 14px;
}

/* Узкие экраны: «Гроссмейстер» должен помещаться в одну строку */
@media (max-width: 375px) {
  .cfg-btn.difficulty-btn {
    gap: 6px;
    padding: 6px 8px;
    font-size: 13px;
  }
  .cfg-btn.difficulty-btn .difficulty-btn-avatar {
    width: 28px;
    height: 28px;
  }
}


/* --- Онлайн-раздел по макету --- */

/* Вкладка «Турнир дня» в золоте турнирного блока (не синяя) */
.pool-btn.active[data-pool="tournament"] {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #1a1205;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.28);
}

/* Кубок — тот же золотой, что у трофея в плашке победы */
.ico-gold {
  color: #f59e0b;
  filter: drop-shadow(0 0 5px rgba(245, 158, 11, 0.45));
}

.tourney-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tourney-tag-ico {
  width: 13px;
  height: 13px;
}

/* Разделитель «или» между приглашением и поиском соперника */
.or-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 2px 0;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.or-divider::before,
.or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.14), transparent);
}

/* Топ-3 таблицы лидеров: вся строка в золоте, серебре и бронзе */
.lb-row.rank-1 {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.16) 0%, rgba(245, 158, 11, 0.04) 70%);
  border-color: rgba(245, 158, 11, 0.45);
}

.lb-row.rank-2 {
  background: linear-gradient(90deg, rgba(203, 213, 225, 0.14) 0%, rgba(203, 213, 225, 0.03) 70%);
  border-color: rgba(203, 213, 225, 0.35);
}

.lb-row.rank-3 {
  background: linear-gradient(90deg, rgba(180, 83, 9, 0.18) 0%, rgba(180, 83, 9, 0.04) 70%);
  border-color: rgba(217, 119, 6, 0.4);
}

.lb-row.rank-1 .lb-player-name { color: #fde68a; }
.lb-row.rank-2 .lb-player-name { color: #e2e8f0; }
.lb-row.rank-3 .lb-player-name { color: #fdba74; }

.lb-row.rank-1 .lb-pos,
.lb-row.rank-2 .lb-pos,
.lb-row.rank-3 .lb-pos { font-size: 14px; }


/* Кубок внутри золотой кнопки — тёмный, чтобы читался на градиенте */
.tourney-btn .ico-gold {
  color: #1a1205;
  filter: none;
}

/* Разделителю «или» нужно немного воздуха */
.or-divider {
  margin: 6px 0 8px;
}

/* Вторичная кнопка приглашения сохраняет свой акцент, но не спорит с поиском */
.action-btn.secondary.invite-btn {
  color: #cfe6ff;
}


/* --- Онлайн-раздел: шапка со счётчиками --- */
.pvp-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}

.pvp-status .status-dot {
  flex: 0 0 auto;
}

.pvp-status b {
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.pvp-status-lbl {
  color: var(--text-muted);
}

/* --- Пулы: две кнопки, как в макете --- */
.pool-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: #0c1018;
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.pool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  background: #161c28;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #94a3b8;
}

.pool-btn .ico {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

.pool-btn:hover {
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.16);
}

.pool-btn.active[data-pool="casual"] {
  background: var(--btn-primary-grad);
  border-color: transparent;
  color: var(--btn-primary-text);
  box-shadow: var(--btn-primary-shadow);
}

/* --- Турнирный блок по макету --- */
.pvp-banner-tourney {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 14px;
}

.tourney-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tourney-timer {
  font-size: 12px;
  font-weight: 500;
  color: #e5e7eb;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.tourney-timer span {
  color: #9ca3af;
}

.tourney-timer b {
  font-weight: 700;
}

.tourney-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tourney-streak-note {
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--text-muted);
  margin-top: -2px;
}

.tourney-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 7px;
  border-radius: 7px;
  background: rgba(12, 16, 24, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
  font-weight: 600;
  color: #f3f4f6;
  white-space: nowrap;
}

.tourney-points {
  gap: 6px;
}

.tp-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.tp-sep {
  width: 1px;
  height: 12px;
  background: rgba(255, 255, 255, 0.16);
}

.pvp-banner-tourney .tourney-title {
  margin: 0;
}

/* --- Таблица лидеров: прокрутка и нейтральное выделение игрока --- */
.lb-list-container {
  overflow-y: auto;
  max-height: 340px;
  scrollbar-width: thin;
}

.lb-row.highlight {
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.38);
}

.lb-row.highlight .lb-player-name {
  color: var(--text-main);
  font-weight: 700;
}

.lb-row.highlight .lb-pos {
  color: #cbd5e1;
}


/* Онлайн-раздел: воздух между блоками, как в макете */
#pvpConfigBody {
  gap: 14px;
}

#pvpConfigBody .config-section {
  gap: 8px;
}

#pvpConfigBody .seek-block {
  margin-top: 2px;
  padding-top: 4px;
}

#pvpConfigBody .or-divider {
  margin: 4px 0;
}


/* Карточки лобби не сжимаются: раньше flex-сжатие сплющивало тело карточки
   и блоки наезжали друг на друга */
.lobby-modes,
.lobby-card,
.lobby-card-body {
  flex: 0 0 auto;
}


/* Плашка «ждём соперника» теперь живёт внутри карточки, под кнопкой приглашения */
#pvpConfigBody .invite-wait-bar {
  margin: 0;
  padding: 9px 12px;
  background: rgba(88, 166, 255, 0.08);
}

/* Кнопка создания игры: иконка мечей вместо лупы */
.seek-find-btn .ico {
  width: 15px;
  height: 15px;
}

/* В лидерборде очки без подписи — выравниваем по правому краю */
.lb-score-col {
  justify-content: flex-end;
}


/* --- Звук в настройках профиля --- */
.settings-group.sound-group {
  flex: 0 0 auto;
  margin: 0 0 4px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.sound-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 44px;
  margin-top: 6px;
  padding: 0 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
}

.sound-row:hover {
  border-color: rgba(255, 255, 255, 0.16);
}

.sound-row-icon {
  display: flex;
  align-items: center;
  color: var(--text-muted);
}

.sound-row-icon .ico {
  width: 18px;
  height: 18px;
}

.sound-row-label {
  flex: 1;
  text-align: left;
  font-weight: 500;
}

.sound-switch {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: rgba(148, 163, 184, 0.28);
  transition: background 0.18s ease;
  flex: 0 0 auto;
}

.sound-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e5e7eb;
  transition: transform 0.18s ease;
}

.sound-row[aria-checked="true"] .sound-switch {
  background: var(--accent-blue, #388bfd);
}

.sound-row[aria-checked="true"] .sound-knob {
  transform: translateX(18px);
}

.sound-row[aria-checked="true"] .sound-row-icon {
  color: var(--accent-blue, #388bfd);
}


/* Ряд выбора цвета в обычном матче — те же размеры, что у блока с ботом */
#seekColorPicker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}


/* Своя строка в таблице лидеров, когда игрок вне топ-20 */
.lb-row-separator {
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
  font-size: 12px;
  padding: 2px 0;
}

.lb-row.rank-me {
  background: rgba(148, 163, 184, 0.16);
  border-color: rgba(148, 163, 184, 0.45);
}

/* Ник в шапке партии: не обрезаем по половине слова и не срезаем подчёркивания */
.player-head .p-name {
  line-height: 1.35;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  word-break: break-word;
}


/* Таблица лидеров: аватар в строке, ник и ELO в одну строку */
.lb-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex: 0 0 auto;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  overflow: hidden;
}

.lb-avatar-emoji {
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.25));
}

.lb-avatar-initial {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  background: rgba(88, 166, 255, 0.14);
}

.lb-player-meta {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Позиция без «#» — уже компактнее */
.lb-pos {
  flex: 0 0 26px;
  width: 26px;
  font-size: 13px;
  font-weight: 700;
}


/* Подсказка в таблице: игрок ещё не играл турнир */
.lb-row-note {
  justify-content: center;
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
  padding: 10px 12px;
  text-align: center;
}

.lb-note-text {
  display: block;
}
