/* ==========================================================================
   SimpleGames — общие стили. Файл собирается из sg/css/src/*.css: python3 tools/build.py
   ========================================================================== */

/* ---------- tokens.css ---------- */

/* Дизайн-токены. Тёмная тема — по умолчанию; светлая задаётся одним блоком
   :root[data-theme="light"], а сборка (tools/build.py) повторяет его для системной светлой темы. */

:root {
  /* поверхности и текст */
  --bg: #0d0e1a;
  --bg-2: #141528;
  --surface: #1a1c33;
  --surface-2: #23264a;
  --border: #2c2f55;
  --text: #ecedf7;
  --muted: #9a9cc0;
  --on-accent: #fff;

  /* акценты и состояния */
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-3: #ff5c93;
  --success: #34d399;
  --danger: #f87171;
  --warning: #fbbf24;
  --gold: #facc15;

  /* цвета игроков: 1 — синий, 2 — красный, дальше — для игр на компанию */
  --p1: #3b82f6;
  --p2: #ef4444;
  --p3: #22c55e;
  --p4: #f59e0b;
  --p5: #a855f7;
  --p6: #ec4899;
  --p7: #14b8a6;
  --p8: #f97316;

  /* игровые поля */
  --board-bg: #12132a;
  --board-cell: #1b1d3a;
  --board-line: #2a2d57;

  /* фон страницы */
  --glow-1: rgba(124, 92, 255, 0.18);
  --glow-2: rgba(34, 211, 238, 0.12);

  /* тени */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 16px 40px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.45);

  /* скругления */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  /* отступы */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  /* шрифт и размеры текста */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.6rem;
  --fs-2xl: 2.2rem;

  /* движение */
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 0.15s;
  --dur: 0.25s;
  --dur-slow: 0.4s;

  /* слои */
  --z-raised: 2;
  --z-overlay: 5;
  --z-header: 20;
  --z-pop: 50;
  --z-float: 200;
  --z-modal: 900;
  --z-toast: 1000;

  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f5fb;
    --bg-2: #eceefa;
    --surface: #ffffff;
    --surface-2: #f0f1fa;
    --border: #dfe1f0;
    --text: #191a2e;
    --muted: #62648a;
    --accent: #6a48f5;
    --accent-2: #0ea5c6;
    --accent-3: #e0407a;
    --shadow-sm: 0 2px 8px rgba(40, 40, 90, 0.08);
    --shadow: 0 10px 30px rgba(40, 40, 90, 0.12);
    --shadow-pop: 0 16px 40px rgba(40, 40, 90, 0.18);
    --shadow-lg: 0 24px 60px rgba(40, 40, 90, 0.22);
    --glow-1: rgba(106, 72, 245, 0.12);
    --glow-2: rgba(14, 165, 198, 0.1);
    --board-bg: #dfe2f3;
    --board-cell: #eef0fa;
    --board-line: #cdd1ea;
    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg: #f4f5fb;
  --bg-2: #eceefa;
  --surface: #ffffff;
  --surface-2: #f0f1fa;
  --border: #dfe1f0;
  --text: #191a2e;
  --muted: #62648a;
  --accent: #6a48f5;
  --accent-2: #0ea5c6;
  --accent-3: #e0407a;
  --shadow-sm: 0 2px 8px rgba(40, 40, 90, 0.08);
  --shadow: 0 10px 30px rgba(40, 40, 90, 0.12);
  --shadow-pop: 0 16px 40px rgba(40, 40, 90, 0.18);
  --shadow-lg: 0 24px 60px rgba(40, 40, 90, 0.22);
  --glow-1: rgba(106, 72, 245, 0.12);
  --glow-2: rgba(14, 165, 198, 0.1);
  --board-bg: #dfe2f3;
  --board-cell: #eef0fa;
  --board-line: #cdd1ea;
  color-scheme: light;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0s;
    --dur: 0s;
    --dur-slow: 0s;
  }
}

/* ---------- base.css ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  line-height: 1.55;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 500px at 10% -10%, var(--glow-1), transparent 60%),
    radial-gradient(700px 500px at 100% 0%, var(--glow-2), transparent 60%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- layout.css ---------- */

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  gap: 12px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.logo b {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.logo-mark {
  width: 34px;
  height: 34px;
  flex: none;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: transform var(--dur-fast), background var(--dur-fast);
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 22px 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.site-footer a {
  color: var(--muted);
}

/* ---------- 404 ---------- */

.not-found {
  text-align: center;
  padding: 90px 16px;
}

.not-found .code {
  font-size: clamp(5rem, 20vw, 9rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.05em;
}

/* на телефоне шапка ниже, а на странице игры не прилипает к верху: при прокрутке к полю ему достаётся весь экран */
@media (max-width: 640px) {
  .header-inner {
    height: 52px;
  }

  .logo {
    font-size: 1.05rem;
  }

  .logo-mark {
    width: 28px;
    height: 28px;
  }

  .page-game .site-header {
    position: relative;
  }
}

/* ---------- buttons.css ---------- */

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  transition: transform var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast), opacity var(--dur-fast);
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--accent-2)));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 55%, transparent);
}

.btn-ghost {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

/* Сегментированный переключатель */
.seg {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.seg button {
  border: 0;
  background: transparent;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.seg button:hover {
  color: var(--text);
}

.seg button.active {
  background: var(--accent);
  color: var(--on-accent);
}

/* сколько раз брали подсказку (SG.hintCount) */
.hint-count {
  min-width: 1.5em;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: var(--warning);
  color: #1a1400;
  font-size: 0.8em;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
}

.hint-count[hidden] {
  display: none;
}

/* «Новая партия» / «Новое слово»: спокойная кнопка со значком, чтобы её не путали с «Ввод» или «Ход» */
.btn-new::before {
  content: '↻';
  font-size: 1.1em;
  line-height: 1;
}

/* ---------- home.css ---------- */

/* ---------- Home ---------- */

.hero {
  padding: 64px 16px 36px;
  text-align: center;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 20px;
}

.hero-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 25%, transparent);
}

.hero h1 {
  margin: 0 0 16px;
  font-size: clamp(2.1rem, 6.5vw, 3.8rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 800;
}

.grad {
  background: linear-gradient(90deg, var(--accent), var(--accent-2) 55%, var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  max-width: 620px;
  margin: 0 auto;
  color: var(--muted);
  font-size: clamp(1rem, 2.4vw, 1.15rem);
}

.section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 18px;
}

.search {
  flex: 1 1 200px;
  max-width: 320px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.no-results {
  padding: 24px 0 56px;
  color: var(--muted);
  text-align: center;
}

.install-btn {
  min-height: 40px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.section-title h2 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.section-title span {
  color: var(--muted);
  font-size: 0.9rem;
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  padding-bottom: 56px;
}

.game-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform var(--dur), border-color var(--dur), box-shadow var(--dur);
}

.game-card[hidden] {
  display: none;
}

.game-card:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--g1) 60%, var(--border));
  box-shadow: 0 16px 40px color-mix(in srgb, var(--g1) 25%, transparent);
}

.game-card .thumb {
  position: relative;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.18), transparent 55%),
    linear-gradient(135deg, var(--g1), var(--g2));
  overflow: hidden;
}

.game-card .thumb svg,
.game-card .thumb img {
  width: 72%;
  height: auto;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.25));
  transition: transform var(--dur-slow);
}

.game-card:hover .thumb svg,
.game-card:hover .thumb img {
  transform: scale(1.05) rotate(-1deg);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px 18px;
  flex: 1;
}

.card-body h3 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.card-body p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  flex: 1;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-top: 8px;
  font-size: 0.8rem;
}

.tag {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
}

.card-meta .best {
  margin-left: auto;
}

.tag-online {
  background: color-mix(in srgb, var(--success) 18%, var(--surface-2));
  color: color-mix(in srgb, var(--success) 70%, var(--text));
}

.tag-party {
  background: color-mix(in srgb, var(--accent-2) 18%, var(--surface-2));
  color: color-mix(in srgb, var(--accent-2) 70%, var(--text));
}

.best {
  color: color-mix(in srgb, var(--warning) 75%, var(--text));
  font-weight: 700;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding-bottom: 64px;
}

.feature {
  padding: 18px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.feature h3 {
  margin: 8px 0 4px;
  font-size: 1rem;
}

.feature p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.feature-icon {
  font-size: 1.6rem;
}

/* ---------- Избранное, недавние, «Игра дня» ---------- */

.game-card {
  position: relative;
}

.fav-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: var(--z-raised);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur), transform var(--dur-fast), background var(--dur);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.game-card:hover .fav-btn,
.fav-btn:focus-visible,
.fav-btn.on {
  opacity: 1;
}

.fav-btn.on {
  color: #fde047;
}

.fav-btn:hover {
  transform: scale(1.12);
  background: rgba(0, 0, 0, 0.45);
}

@media (hover: none) {
  .fav-btn {
    opacity: 0.85;
  }
}

.daily-card {
  display: flex;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--g1, var(--accent)) 45%, var(--border));
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.daily-thumb {
  display: grid;
  flex: 0 0 38%;
  place-items: center;
  min-height: 170px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.18), transparent 55%),
    linear-gradient(135deg, var(--g1, var(--accent)), var(--g2, var(--accent-2)));
}

.daily-thumb svg,
.daily-thumb img {
  width: 82%;
  height: auto;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.25));
}

.daily-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 18px 20px;
}

.daily-label {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.daily-body h2 {
  margin: 0;
  font-size: 1.5rem;
}

.daily-goal {
  margin: 0;
  color: var(--muted);
}

.daily-card.done .daily-goal {
  color: var(--success);
  font-weight: 600;
}

.daily-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: auto;
  padding-top: 8px;
}

.daily-streak {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

@media (max-width: 520px) {
  .daily-thumb {
    flex-basis: 34%;
    min-height: 0;
  }

  .daily-body {
    padding: var(--sp-3) var(--sp-4);
  }

  .daily-body h2 {
    font-size: 1.2rem;
  }

  .daily-goal {
    font-size: var(--fs-sm);
  }

  .daily-streak {
    display: none;
  }
}

.mini-list {
  display: grid;
  grid-auto-columns: minmax(130px, 160px);
  grid-auto-flow: column;
  gap: var(--sp-3);
  overflow-x: auto;
  padding-bottom: var(--sp-2);
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

.mini-list > * {
  scroll-snap-align: start;
}

.mini-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  text-decoration: none;
  transition: transform var(--dur-fast), border-color var(--dur-fast);
}

.mini-card:hover {
  transform: translateY(-2px);
  border-color: var(--g1, var(--accent));
}

.mini-thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  background: linear-gradient(135deg, var(--g1, var(--accent)), var(--g2, var(--accent-2)));
}

.mini-thumb svg,
.mini-thumb img {
  width: 70%;
  height: auto;
}

.mini-title {
  overflow: hidden;
  padding: 6px 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- главная: герой с «Игрой дня» ---------- */

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: var(--sp-6);
  align-items: center;
  padding-top: var(--sp-6);
  padding-bottom: var(--sp-6);
}

.home-hero .hero-badge {
  margin-bottom: var(--sp-4);
}

.home-hero h1 {
  margin: 0 0 var(--sp-3);
  font-size: clamp(2rem, 4.6vw, 3.3rem);
  line-height: 1.06;
  letter-spacing: -0.035em;
  font-weight: 800;
}

.home-hero p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.1rem);
}

.hero-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-5);
}

.home-hero .daily-card {
  min-height: 200px;
}

@media (max-width: 900px) {
  .home-hero {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--sp-5);
    padding-top: var(--sp-5);
    padding-bottom: var(--sp-4);
  }

  .home-hero .daily-card {
    min-height: 0;
  }
}

@media (max-width: 520px) {
  .home-hero .hero-badge {
    font-size: 0.75rem;
  }

  .hero-links {
    flex-wrap: nowrap;
    margin-top: var(--sp-4);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .hero-links .btn {
    flex: none;
    min-height: 38px;
    padding: 0 var(--sp-3);
    font-size: var(--fs-sm);
  }
}

/* ---------- полки ---------- */

.shelf {
  margin-bottom: var(--sp-5);
}

.shelf-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.shelf-head h2,
.shelf-head h3 {
  margin: 0;
  font-size: var(--fs-lg);
}

.shelf-all {
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.shelf-all:hover {
  text-decoration: underline;
}

.shelf-nav {
  display: flex;
  gap: var(--sp-2);
  margin-left: auto;
}

.shelf-nav .icon-btn {
  width: 36px;
  height: 36px;
  font-size: 1.3rem;
}

@media (hover: none), (max-width: 640px) {
  .shelf-nav {
    display: none;
  }
}

.shelf-row {
  display: grid;
  grid-auto-columns: minmax(220px, 250px);
  grid-auto-flow: column;
  gap: var(--sp-4);
  overflow-x: auto;
  margin: 0 calc(var(--sp-4) * -1);
  padding: var(--sp-1) var(--sp-4) var(--sp-5);
  scroll-padding: 0 var(--sp-4);
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.shelf-row::-webkit-scrollbar {
  display: none;
}

.shelf-row > .game-card {
  scroll-snap-align: start;
}

.shelf-row .card-body p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

/* ---------- каталог: панель фильтров ---------- */

.catalog {
  margin-top: var(--sp-4);
}

.catalog-bar {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-5);
}

.catalog-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.catalog-top h2 {
  margin: 0;
  font-size: var(--fs-xl);
  letter-spacing: -0.02em;
}

.catalog-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}

.catalog-filters #view-toggle {
  margin-left: auto;
}

@media (max-width: 640px) {
  .catalog-top .search {
    max-width: none;
  }

  .catalog-filters .seg {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .catalog-filters .seg button {
    flex: none;
    white-space: nowrap;
  }

  .catalog-filters #view-toggle {
    display: none;
  }
}

/* компактная сетка: больше игр на экране */
.games-grid.compact {
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--sp-3);
}

.games-grid.compact .card-body {
  padding: var(--sp-3);
}

.games-grid.compact .card-body h3 {
  font-size: var(--fs-md);
}

.games-grid.compact .card-body p,
.games-grid.compact .card-meta .tag:not(:first-child) {
  display: none;
}

.shelf-row > .game-card {
  box-shadow: var(--shadow-sm);
}

.shelf-row .card-body p {
  max-height: 3.1em;
}

/* раздел полки и так понятен — оставляем только метку «По сети» / «Компанией» и рекорд */
.shelf-row .card-meta .tag:first-child {
  display: none;
}

.hero-links .btn {
  min-height: 40px;
  padding: 0 var(--sp-4);
}

/* ---------- game.css ---------- */

/* ---------- Game pages ---------- */

main {
  flex: 1;
}

.game-page {
  padding-top: 20px;
  padding-bottom: 48px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 12px;
}

.back-link:hover {
  color: var(--text);
}

.game-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.game-head h1 {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  letter-spacing: -0.03em;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

/* табло: компактные «таблетки» — подпись и число в одну строку */
.stat {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-2);
  min-height: 36px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.stat-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

/* ---------- шапка страницы игры: назад, название, избранное, табло ---------- */

.page-head {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  grid-template-areas:
    "back back back"
    "title fav stats";
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-5);
}

.page-head .back-link {
  grid-area: back;
  justify-self: start;
  margin: 0;
}

.page-head h1 {
  grid-area: title;
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.3rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.page-head .fav-toggle {
  grid-area: fav;
  width: 38px;
  height: 38px;
  color: var(--muted);
}

.page-head .fav-toggle.on {
  color: var(--gold);
}

.page-head .stats {
  grid-area: stats;
  justify-content: flex-end;
}

.back-arrow {
  font-size: 1.05em;
}

@media (max-width: 640px) {
  .game-page {
    padding-top: var(--sp-3);
  }

  .page-head {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "back title fav"
      "stats stats stats";
    gap: var(--sp-3) var(--sp-2);
    margin-bottom: var(--sp-4);
  }

  /* на телефоне «назад» — круглая кнопка слева от названия */
  .page-head .back-link {
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
  }

  .page-head .back-text {
    display: none;
  }

  .page-head h1 {
    font-size: 1.45rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-head .stats {
    justify-content: flex-start;
  }

  .stat {
    min-height: 32px;
    padding: 4px 12px;
  }

  .stat-value {
    font-size: 1rem;
  }
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.game-layout.wide {
  grid-template-columns: minmax(0, 1fr);
}

.game-layout.wide .game-aside {
  position: static;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
}

.game-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.stage-wrap {
  position: relative;
  width: 100%;
  max-width: 520px;
}

.board-canvas {
  display: block;
  width: 100%;
  border-radius: var(--radius);
  background: var(--board-bg);
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.game-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 520px;
}

@media (max-width: 640px) {
  .game-controls {
    gap: var(--sp-2);
  }

  .game-controls .seg {
    flex-wrap: nowrap;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .game-controls .seg::-webkit-scrollbar {
    display: none;
  }

  .game-controls .seg {
    justify-content: center;
  }

  .game-controls .seg button {
    flex: 1 0 auto;
    padding: 6px 9px;
    font-size: 0.82rem;
    white-space: nowrap;
  }
}

/* место под две строки: длинная подсказка переносится, а поле под ней не прыгает */
.status-line {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.7em;
  font-weight: 700;
  text-align: center;
  font-size: 1.05rem;
  line-height: 1.35;
  text-wrap: balance;
}

@media (max-width: 640px) {
  .status-line {
    font-size: 0.95rem;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease;
}

.overlay[hidden] {
  display: none;
}

/* Оверлей поверх тёмного холста — светлый текст в любой теме */
.overlay.on-dark {
  background: rgba(8, 10, 24, 0.55);
  color: #fff;
}

.overlay.on-dark p {
  color: rgba(255, 255, 255, 0.82);
}

.overlay h2 {
  margin: 0;
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  letter-spacing: -0.02em;
}

.overlay p {
  margin: 0 0 8px;
  color: var(--muted);
  max-width: 340px;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.info-card {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.info-card h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.info-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

.info-card li + li {
  margin-top: 6px;
}

.info-card + .info-card {
  margin-top: 16px;
}

/* «Как играть» — раскрывающаяся панель: на телефоне свёрнута, чтобы поле было на первом экране */
.rules summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.rules summary::-webkit-details-marker {
  display: none;
}

.rules summary h2 {
  margin: 0;
}

.rules summary::after {
  content: "";
  flex: none;
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  transition: transform var(--dur-fast);
}

.rules[open] summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.rules[open] summary {
  margin-bottom: var(--sp-3);
}

.rules:not([open]) {
  padding-top: var(--sp-4);
  padding-bottom: var(--sp-4);
}

@media (min-width: 861px) {
  .game-aside {
    position: sticky;
    top: 84px;
  }
}

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: center;
}

/* Экранный крестик управления — только для сенсорных устройств */
.dpad {
  display: none;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(3, 60px);
  gap: 6px;
}

.dpad button {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-size: 1.4rem;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.dpad button:active {
  background: var(--accent);
  color: var(--on-accent);
}

.dpad [data-dir="up"] {
  grid-column: 2;
  grid-row: 1;
}

.dpad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.dpad [data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

/* Экранные кнопки для аркад — только для сенсорных устройств */
.touch-keys {
  display: none;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 600px;
}

.touch-keys button {
  flex: 1 1 0;
  max-width: 110px;
  height: 64px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 1.5rem;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-keys button.down {
  background: var(--accent);
  color: var(--on-accent);
}

.touch-keys .wide {
  flex-grow: 1.6;
  max-width: 160px;
}

@media (pointer: coarse) {
  .dpad {
    display: grid;
  }
  .touch-keys {
    display: flex;
  }
  .hide-touch {
    display: none;
  }
}

@media (pointer: fine) {
  .hide-desktop {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- components.css ---------- */

/* ---------- Уведомления (SG.toast) ---------- */

.sg-toasts {
  position: fixed;
  top: 76px;
  right: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

@media (max-width: 640px) {
  .sg-toasts {
    top: 72px;
    right: 50%;
    transform: translateX(50%);
  }
}

.sg-toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-left: 4px solid var(--tone, var(--accent));
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  color: var(--text);
  text-decoration: none;
  pointer-events: auto;
  animation: sg-toast-in var(--dur) var(--ease);
  transition: opacity var(--dur-slow), transform var(--dur-slow);
}

.sg-toast[data-tone="success"] {
  --tone: var(--success);
}

.sg-toast[data-tone="warning"] {
  --tone: var(--warning);
}

.sg-toast[data-tone="danger"] {
  --tone: var(--danger);
}

.sg-toast.out {
  opacity: 0;
  transform: translateY(-8px);
}

.sg-toast-icon {
  flex: none;
  font-size: 1.7rem;
  line-height: 1;
}

.sg-toast-body {
  flex: 1;
  min-width: 0;
}

.sg-toast b {
  display: block;
}

.sg-toast small {
  display: block;
  color: var(--muted);
}

.sg-toast-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

.sg-toast-actions .btn {
  min-height: 34px;
  padding: 0 var(--sp-3);
  font-size: var(--fs-sm);
}

@keyframes sg-toast-in {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.97);
  }
}

/* ---------- Модальное окно (SG.modal) ---------- */

.sg-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 6, 15, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: sg-fade-in var(--dur) var(--ease);
}

.sg-modal[hidden] {
  display: none;
}

.sg-modal-box {
  width: min(480px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: sg-pop-in var(--dur) var(--ease);
}

.sg-modal-box h2 {
  margin: 0 0 12px;
  font-size: 1.3rem;
}

@keyframes sg-fade-in {
  from {
    opacity: 0;
  }
}

@keyframes sg-pop-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* ---------- Эффекты итога партии (SG.fx) ---------- */

.sg-fx-confetti,
.sg-fx-flash {
  position: fixed;
  inset: 0;
  z-index: var(--z-toast);
  pointer-events: none;
}

.sg-fx-confetti {
  width: 100%;
  height: 100%;
}

/* свечение по краям экрана: золотое — победа, красное — поражение, голубое — ничья */
.sg-fx-flash {
  --fx-c: var(--gold);
  box-shadow: inset 0 0 120px 24px color-mix(in srgb, var(--fx-c) 55%, transparent);
  opacity: 0;
  animation: sg-fx-flash 1.4s ease-out;
}

.sg-fx-flash[data-kind='lose'] {
  --fx-c: var(--danger);
}

.sg-fx-flash[data-kind='draw'] {
  --fx-c: var(--accent-2);
}

@keyframes sg-fx-flash {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.sg-fx-shake {
  animation: sg-fx-shake 0.55s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes sg-fx-shake {
  10%,
  90% {
    transform: translateX(-2px);
  }
  20%,
  80% {
    transform: translateX(4px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-7px);
  }
  40%,
  60% {
    transform: translateX(7px);
  }
}

.sg-modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- achievements.css ---------- */

/* ---------- Страница достижений ---------- */

.ach-head {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 8px 0 24px;
}

.ach-total {
  flex: 1 1 260px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.ach-total b {
  font-size: 1.6rem;
}

.ach-total .ach-bar {
  margin-top: 10px;
}

.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.ach {
  display: flex;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.ach-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  background: var(--surface-2);
  font-size: 1.7rem;
  filter: grayscale(1);
  opacity: 0.45;
}

.ach.ok {
  border-color: color-mix(in srgb, var(--warning) 55%, var(--border));
}

.ach.ok .ach-icon {
  background: color-mix(in srgb, var(--warning) 22%, var(--surface));
  filter: none;
  opacity: 1;
}

.ach-body {
  flex: 1;
  min-width: 0;
}

.ach h3 {
  margin: 0 0 2px;
  font-size: 1rem;
}

.ach p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.ach small {
  color: var(--muted);
  font-size: 0.75rem;
}

.ach-bar {
  overflow: hidden;
  height: 6px;
  margin-bottom: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}

.ach-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.ach.ok .ach-bar i {
  background: var(--warning);
}

.ach-net {
  margin-top: 28px;
}

.ach-net[hidden] {
  display: none;
}

.ach-net h2 {
  margin: 0 0 12px;
  font-size: 1.3rem;
}

.ach-net h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.ach-net-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.ach-net ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ach-net li {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.ach-net li > :first-child {
  flex: 1;
  min-width: 0;
}

.ach-net li small,
.ach-net li.empty {
  color: var(--muted);
}

.ach-net a {
  color: inherit;
}

.ach-inbox {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------- net.css ---------- */

/* ---------- Игра по сети ---------- */

.net-mode-btn.active {
  background: linear-gradient(135deg, #10b981, #0ea5e9);
  color: var(--on-accent);
}

.sg-modal-box p {
  margin: 0 0 12px;
}

.net-label {
  display: block;
  margin: 12px 0 6px;
  font-size: 0.9rem;
  font-weight: 700;
}

.net-link {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.net-link input,
.net-textarea {
  flex: 1 1 180px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.net-textarea {
  display: block;
  width: 100%;
  resize: vertical;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  word-break: break-all;
}

.net-code b {
  padding: 2px 8px;
  border-radius: var(--radius-xs);
  background: var(--surface-2);
  font-family: ui-monospace, monospace;
  font-size: 1.1rem;
  letter-spacing: 0.12em;
}

.net-code,
.net-note,
.net-status {
  color: var(--muted);
  font-size: 0.9rem;
}

.net-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px !important;
}

.net-error {
  color: var(--warning);
  font-size: 0.85rem;
}

.net-spinner {
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: net-spin 0.8s linear infinite;
}

.net-join {
  margin: 4px 0 8px;
  font-size: 0.9rem;
}

.net-join summary {
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

.net-join .net-link {
  margin-top: 8px;
}

.net-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.net-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 620px;
  padding: 6px 6px 6px 14px;
  border: 1px solid color-mix(in srgb, var(--success) 50%, var(--border));
  /* не «таблетка»: в конце партии кнопок больше, и панель бывает в две строки */
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--success) 10%, var(--surface));
  font-size: 0.9rem;
  font-weight: 600;
}

.net-bar[hidden] {
  display: none;
}

.net-bar[data-state="off"] {
  border-color: color-mix(in srgb, var(--danger) 50%, var(--border));
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

/* у текста своя ширина: если всё не помещается в строку, на следующую уходят кнопки, а не буквы */
.net-bar .net-text {
  flex: 1 1 13em;
  min-width: 0;
}

.net-bar .btn {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.net-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 25%, transparent);
}

.net-bar[data-state="off"] .net-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 25%, transparent);
}

@keyframes net-spin {
  to {
    transform: rotate(360deg);
  }
}

.net-bar {
  position: relative;
  flex-wrap: wrap;
  row-gap: 6px;
  /* то, что перенеслось на следующую строку, прижимается вправо */
  justify-content: flex-end;
}

.net-score {
  flex: none;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
}

.net-score[hidden],
.net-bar .btn[hidden] {
  display: none;
}

.net-rematch.pulse {
  border-color: var(--success);
  animation: net-pulse 1s ease-in-out infinite alternate;
}

@keyframes net-pulse {
  to {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 35%, transparent);
  }
}

.net-react {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: var(--z-pop);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  width: min(300px, 90vw);
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
}

.net-react[hidden] {
  display: none;
}

.net-react button {
  padding: 4px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

.net-react button.phrase {
  font-size: 0.85rem;
}

.net-react button:hover {
  background: color-mix(in srgb, var(--accent) 25%, var(--surface-2));
}

.net-bubble {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: var(--z-pop);
  max-width: 90%;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1rem;
  white-space: nowrap;
  box-shadow: var(--shadow-pop);
  transform: translateX(-50%);
  animation: net-pop 0.25s ease-out;
  transition: opacity var(--dur-slow), transform var(--dur-slow);
  pointer-events: none;
}

.net-bubble.mine {
  background: var(--surface-2);
  color: var(--text);
}

.net-bubble.out {
  opacity: 0;
  transform: translate(-50%, -10px);
}

@keyframes net-pop {
  from {
    opacity: 0;
    transform: translate(-50%, 8px) scale(0.8);
  }
}

.net-lobby {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}

.net-lobby[hidden],
.net-public[hidden] {
  display: none;
}

.net-public {
  display: flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
}

.net-rooms {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.net-rooms li {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.net-rooms li.empty {
  padding: 8px 12px;
  color: var(--muted);
}

.net-rooms small {
  margin-left: 8px;
  color: var(--muted);
}

.net-rooms .btn {
  padding: 5px 12px;
  font-size: 0.85rem;
}

/* ---------- Зрители ---------- */

.net-watch {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: var(--z-pop);
  width: min(380px, 92vw);
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  font-weight: 400;
}

.net-watch[hidden] {
  display: none;
}

.net-watch p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.net-bar.watching {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.net-bar.watching .net-dot {
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent);
}

.net-bubble.watcher {
  background: var(--accent-2);
}

.net-watch-note {
  margin: 0;
  color: var(--muted);
  text-align: center;
}

body.sg-watching .game-stage > :not(.net-bar):not(.net-mirror):not(.net-watch-note) {
  display: none !important;
}

.net-mirror {
  display: flex;
  flex-direction: column;
  gap: inherit;
  align-items: center;
  width: 100%;
  pointer-events: none;
}

/* ---------- Профиль: соперник и рейтинг, приглашения ---------- */

.net-rival {
  flex: none;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.net-rival[hidden] {
  display: none;
}

.net-name {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

.net-name input {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}

.net-rivals ul {
  display: grid;
  gap: 6px;
  margin: 6px 0;
  padding: 0;
  list-style: none;
}

.net-rivals li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 4px 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.net-rivals small {
  color: var(--muted);
}

.net-rivals .btn {
  padding: 5px 12px;
  font-size: 0.85rem;
}


/* ---------- rt.css ---------- */

/* ---------- Экранный джойстик для игр в реальном времени ---------- */

.rt-pads {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  width: 100%;
  max-width: 720px;
  user-select: none;
  -webkit-user-select: none;
}

@media (hover: hover) and (pointer: fine) {
  .rt-pads {
    display: none;
  }
}

.rt-pad {
  display: flex;
  flex: 1;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.rt-pad[hidden] {
  display: none;
}

.rt-pad.side-1 {
  flex-direction: row-reverse;
}

.rt-pad-name {
  position: absolute;
  font-size: 0.75rem;
  color: var(--muted);
}

.rt-dpad {
  display: grid;
  grid-template-areas: ". u ." "l . r" ". d .";
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 4px;
}

.rt-dpad button,
.rt-fire {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.1rem;
  touch-action: none;
}

/* джойстик из одних нужных стрелок (padKeys): в ряд, кнопки размером с «огонь» */
.rt-dpad.rt-dpad-row {
  display: flex;
  gap: 12px;
}

.rt-dpad-row button {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  font-size: 1.3rem;
}

.rt-pad:has(.rt-dpad-row) .rt-fire {
  font-size: 1.3rem;
}

/* подпись «Игрок 1/2» — над круглыми кнопками, а не поверх них */
.rt-pad:has(.rt-dpad-row) {
  position: relative;
}

.rt-pad:has(.rt-dpad-row) .rt-pad-name {
  top: -16px;
  left: 4px;
}

.rt-pad.side-1:has(.rt-dpad-row) .rt-pad-name {
  right: 4px;
  left: auto;
}

.rt-dpad [data-k="u"] {
  grid-area: u;
}

.rt-dpad [data-k="d"] {
  grid-area: d;
}

.rt-dpad [data-k="l"] {
  grid-area: l;
}

.rt-dpad [data-k="r"] {
  grid-area: r;
}

.rt-fire {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 800;
}

.rt-fire.rt-extra {
  width: 52px;
  height: 52px;
  font-size: 1.1rem;
}

.rt-dpad button.on,
.rt-fire.on {
  background: var(--accent);
  color: var(--on-accent);
}
