/* ==========================================================================
   Games — Swiss Minimalist Dark Mode Design System
   Matches Aegis Vault visual aesthetic: #090a0d, tactile micro-interactions,
   Apple / Emil Kowalski spring motion, crisp typography, clean 1px borders.
   ========================================================================== */

:root {
  --bg-root: #090a0d;
  --bg-surface: #101217;
  --bg-surface-subtle: #14171e;
  --bg-input: #0c0e12;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(255, 255, 255, 0.09);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --border-focus: #ffffff;

  --text-primary: #f4f4f6;
  --text-secondary: #8b92a0;
  --text-muted: #525866;
  --text-danger: #f87171;
  --text-success: #34d399;

  --accent: #ffffff;
  --accent-inverted: #090a0d;

  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;

  --c4-yellow: #fbbf24;
  --c4-red: #ef4444;
  --c4-board: #14171e;

  --chess-light: #e4e7eb;
  --chess-dark: #3a4150;
  --chess-highlight: rgba(255, 255, 255, 0.22);
  --chess-selected: rgba(245, 158, 11, 0.35);

  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --transition-fast: 0.12s cubic-bezier(0.16, 1, 0.3, 1);
  --transition-smooth: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  --spring-press: cubic-bezier(0.2, 0, 0, 1);
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

.pointer-events-none {
  pointer-events: none !important;
}

html, body {
  height: 100%;
}

body {
  background-color: var(--bg-root);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Aegis Vault Minimalist Grid Background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.app-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 580px;
  margin: 0 auto;
  background-color: var(--bg-root);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Header Navbar
   ========================================================================== */
.app-header {
  height: 54px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  flex-shrink: 0;
  z-index: 30;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

.app-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.2px;
  color: var(--text-primary);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  background-color: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--color-success);
  box-shadow: 0 0 6px var(--color-success);
}

.status-pill.disconnected .status-dot {
  background-color: var(--color-danger);
  box-shadow: 0 0 6px var(--color-danger);
}

/* Language Dropdown */
.lang-dropdown-wrapper {
  position: relative;
}

.lang-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.lang-pill-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.lang-pill-btn:active {
  transform: scale(0.95);
}

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 60;
  min-width: 140px;
  animation: fadeIn 0.15s ease;
}

.lang-option {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all var(--transition-fast);
}

.lang-option:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.lang-option.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  font-weight: 600;
}

.lang-flag {
  font-size: 14px;
}

/* Buttons */
.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

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

/* Sound Toggle Button SVG States */
#btnSoundToggle .sound-icon-on {
  display: block;
}
#btnSoundToggle .sound-icon-off {
  display: none;
}

#btnSoundToggle.muted {
  color: var(--text-muted);
  border-color: var(--border-subtle);
  opacity: 0.75;
}
#btnSoundToggle.muted:hover {
  opacity: 1;
  color: var(--text-secondary);
}
#btnSoundToggle.muted .sound-icon-on {
  display: none;
}
#btnSoundToggle.muted .sound-icon-off {
  display: block;
  color: var(--text-danger);
}

/* General Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.1s var(--spring-press), background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-inverted);
  border-color: var(--accent);
}
.btn-primary:hover {
  opacity: 0.92;
}

.btn-outline {
  background-color: var(--bg-surface-subtle);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-outline:hover {
  background-color: var(--bg-hover);
}

.btn-outline-danger {
  background-color: rgba(239, 68, 68, 0.08);
  color: var(--text-danger);
  border-color: rgba(239, 68, 68, 0.25);
}
.btn-outline-danger:hover {
  background-color: rgba(239, 68, 68, 0.18);
  border-color: var(--text-danger);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: var(--radius-xs);
}

.text-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  transition: all var(--transition-fast);
}
.text-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}
.text-btn:active {
  transform: scale(0.96);
}

/* ==========================================================================
   Views & Layout
   ========================================================================== */
.view {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.view.hidden {
  display: none !important;
}

/* ==========================================================================
   Lobby View
   ========================================================================== */
.lobby-banner {
  padding: 16px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.user-greeting {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar-badge {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1c2331, #101520);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
}

.user-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.user-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.greeting-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.2px;
}

.btn-inline-edit {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}
.btn-inline-edit:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.btn-inline-edit:active {
  transform: scale(0.92);
}

.user-badges-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-subtle);
  color: var(--text-secondary);
}

.user-pill.telegram {
  color: #38bdf8;
  border-color: rgba(56, 189, 248, 0.3);
  background: rgba(56, 189, 248, 0.08);
}

.btn-link-action {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 0;
  transition: color var(--transition-fast);
}
.btn-link-action:hover {
  color: var(--text-primary);
}

.btn-create {
  flex-shrink: 0;
  padding: 9px 16px;
  box-shadow: 0 4px 14px rgba(255, 255, 255, 0.08);
}

/* Filter Bar */
.filter-bar {
  padding: 10px 16px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-root);
  scrollbar-width: none;
}
.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-tab {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition-fast);
}

.filter-tab:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.filter-tab.active {
  background: var(--text-primary);
  color: var(--accent-inverted);
  border-color: var(--text-primary);
  font-weight: 600;
}

/* Rooms Section */
.rooms-section {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title-group h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.rooms-count-pill {
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  color: var(--text-muted);
}

.rooms-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Room Card */
.room-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: border-color var(--transition-smooth), transform var(--transition-fast), background-color var(--transition-smooth);
  animation: cardEntrance 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes cardEntrance {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.room-card:hover {
  border-color: var(--border-strong);
  background-color: var(--bg-surface-subtle);
  transform: translateY(-1px);
}

.room-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

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

.game-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  text-transform: uppercase;
}

.room-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}

.room-players-text {
  display: flex;
  align-items: center;
  gap: 4px;
}

.room-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-top: 10px;
}

.empty-icon {
  color: var(--text-muted);
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.empty-state small {
  font-size: 12px;
  color: var(--text-muted);
}

/* ==========================================================================
   Arena View
   ========================================================================== */
.arena-bar {
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.arena-match-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.arena-match-info h3 {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arena-right-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.spectator-counter {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

/* Versus Card */
.versus-card {
  margin: 10px 16px 6px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.player-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  overflow: hidden;
}

.player-slot.active {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-strong);
}

.player-slot.p2 {
  justify-content: flex-end;
}

.player-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.player-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}
.player-details.text-right {
  text-align: right;
  align-items: flex-end;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
}
.player-name-row.justify-end {
  justify-content: flex-end;
}

.player-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 105px;
}

#btnShareRoom {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

@media (max-width: 500px) {
  #txtBtnShareRoom {
    display: none;
  }
  #btnShareRoom {
    padding: 6px 8px;
  }
}

.player-symbol {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.player-turn-tag {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.player-slot.active .player-turn-tag {
  color: var(--color-success);
}

.versus-divider {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Waiting Opponent Banner in Arena */
.waiting-opponent-banner {
  margin: 4px 16px 10px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: fadeIn 0.25s ease-out;
}

.waiting-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.waiting-radar {
  position: relative;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.radar-circle {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid rgba(56, 189, 248, 0.45);
  animation: radarPulse 1.8s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}

.radar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
}

@keyframes radarPulse {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.waiting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.waiting-info h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.waiting-info p {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.35;
}

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

.btn-telegram {
  background: #229ed9;
  color: #ffffff;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-telegram:hover {
  background: #1b8ec5;
  box-shadow: 0 2px 10px rgba(34, 158, 217, 0.3);
}

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

.btn-share-room-card {
  padding: 5px 8px;
  color: var(--text-secondary);
}

.btn-share-room-card:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* Captured Tray (Chess) */
.captured-tray {
  margin: 0 16px 8px;
  padding: 4px 10px;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  min-height: 28px;
}
.captured-row {
  display: flex;
  align-items: center;
  gap: 2px;
  letter-spacing: -2px;
}

/* ==========================================================================
   Board Wrapper & STRICT Reaction Overlay
   ========================================================================== */
.board-wrapper {
  position: relative;
  overflow: hidden;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  touch-action: manipulation;
}

.board-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
}

/* Reactions Overlay: STRICTLY INSIDE BOARD WRAPPER, never clips header */
.reactions-overlay {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none !important;
  z-index: 20;
}

.floating-reaction {
  position: absolute;
  bottom: 12px;
  font-size: 28px;
  user-select: none;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.6));
  animation: floatReaction 1.8s cubic-bezier(0.18, 0.89, 0.32, 1) forwards;
}

@keyframes floatReaction {
  0% {
    opacity: 0;
    transform: translateY(15px) scale(0.6);
  }
  15% {
    opacity: 1;
    transform: translateY(0) scale(1.2);
  }
  80% {
    opacity: 0.9;
    transform: translateY(-160px) scale(1.05);
  }
  100% {
    opacity: 0;
    transform: translateY(-220px) scale(0.75);
  }
}

/* ==========================================================================
   Game Boards
   ========================================================================== */

/* 1. Tic-Tac-Toe Board */
.ttt-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 320px;
  aspect-ratio: 1;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.ttt-cell {
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.ttt-cell:hover:not(.taken) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: scale(1.02);
}

.ttt-cell:active:not(.taken) {
  transform: scale(0.95);
}

.ttt-cell.x {
  color: var(--accent);
}
.ttt-cell.o {
  color: #38bdf8;
}

.ttt-cell.winning-cell {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--color-success);
  animation: pulseWin 1s infinite alternate;
}

@keyframes pulseWin {
  from { transform: scale(1); }
  to { transform: scale(1.04); }
}

/* 2. Connect 4 Board */
.c4-board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 12px;
  background: var(--c4-board);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  width: 100%;
  max-width: 390px;
}

.c4-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
}

.c4-col:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

.c4-cell {
  aspect-ratio: 1;
  background: var(--bg-root);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.06);
  position: relative;
  overflow: hidden;
}

.c4-chip {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  position: absolute;
  inset: 0;
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.3), inset 0 3px 6px rgba(255, 255, 255, 0.25);
  animation: chipDrop 0.38s cubic-bezier(0.34, 1.25, 0.64, 1) both;
}

@keyframes chipDrop {
  from {
    transform: translateY(-200px);
    opacity: 0.3;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.c4-chip.red {
  background: radial-gradient(circle at 35% 35%, #f87171, #dc2626);
}

.c4-chip.yellow {
  background: radial-gradient(circle at 35% 35%, #fef08a, #eab308);
}

.c4-cell.winning-chip .c4-chip {
  box-shadow: 0 0 16px #ffffff, inset 0 0 8px rgba(255, 255, 255, 0.8);
  animation: pulseWin 0.8s infinite alternate;
}

/* 3. Chess Board */
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
}

.chess-square {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  user-select: none;
}

.chess-square.light {
  background-color: var(--chess-light);
  color: #1e293b;
}

.chess-square.dark {
  background-color: var(--chess-dark);
  color: #f8fafc;
}

.chess-square.selected {
  background-color: #f59e0b !important;
}

.chess-square.valid-move::after {
  content: '';
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.35);
}

.chess-square.dark.valid-move::after {
  background-color: rgba(255, 255, 255, 0.45);
}

.chess-piece {
  font-size: 34px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
  transition: transform 0.12s cubic-bezier(0.16, 1, 0.3, 1);
  display: inline-block;
}

.chess-square:hover .chess-piece {
  transform: translateY(-2px) scale(1.06);
}

/* 4. Gomoku Board */
.gomoku-board {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  width: 100%;
  max-width: 410px;
  aspect-ratio: 1;
  background: #a47843;
  padding: 6px;
  border-radius: var(--radius-md);
  border: 2px solid #573a16;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.6);
}

.gomoku-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

.gomoku-cell::before, .gomoku-cell::after {
  content: '';
  position: absolute;
  background: rgba(0, 0, 0, 0.4);
}
.gomoku-cell::before {
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
}
.gomoku-cell::after {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
}

.gomoku-stone {
  width: 82%;
  height: 82%;
  border-radius: 50%;
  z-index: 2;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
  animation: stonePlace 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes stonePlace {
  from { transform: scale(0.6); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.gomoku-stone.black {
  background: radial-gradient(circle at 35% 35%, #475569, #090a0d);
}

.gomoku-stone.white {
  background: radial-gradient(circle at 35% 35%, #ffffff, #cbd5e1);
}

/* ==========================================================================
   Arena Footer
   ========================================================================== */
.arena-footer {
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.turn-announcement {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
}

.turn-announcement.my-turn {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.05);
}

.reactions-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.emote-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s var(--spring-press), background-color 0.15s ease, border-color 0.15s ease;
}

.emote-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  transform: translateY(-2px) scale(1.1);
}

.emote-btn:active {
  transform: scale(0.92);
}

.rematch-bar {
  display: flex;
  justify-content: center;
  margin-top: 4px;
}

.btn-rematch {
  width: 100%;
  max-width: 280px;
  padding: 10px 16px;
}

/* ==========================================================================
   Modals & Dialogs (Aegis Vault Style)
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.2s ease;
}

.modal-content {
  position: relative;
  z-index: 1;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalScale 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-sm {
  max-width: 360px;
}

.modal-auth {
  max-width: 400px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalScale {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tg-logo-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #24a1de;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-surface-subtle);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.modal-step-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.step-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--border-strong);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.modal-step-item code {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
}

.modal-actions {
  padding: 0 20px 20px;
  display: flex;
  flex-direction: column;
}

.btn-tg-action {
  width: 100%;
  padding: 12px;
  font-size: 14px;
  text-decoration: none;
}

.input-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
}

.form-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-input:focus {
  border-color: var(--border-focus);
}

.game-select-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.game-radio-card {
  background: var(--bg-surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
}

.game-radio-card input {
  position: absolute;
  opacity: 0;
}

.game-radio-card.active, .game-radio-card:has(input:checked) {
  border-color: var(--border-focus);
  background: rgba(255, 255, 255, 0.06);
}

.game-card-icon {
  font-size: 20px;
  margin-bottom: 2px;
}

.game-radio-card strong {
  font-size: 13px;
  font-weight: 600;
}

.game-radio-card small {
  font-size: 11px;
  color: var(--text-muted);
}

.modal-footer {
  padding: 14px 20px;
  background: var(--bg-surface-subtle);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Game Over Modal Banner */
.game-over-banner {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.game-over-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: modalScale 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.trophy-icon {
  font-size: 48px;
  margin-bottom: 8px;
  animation: trophyBounce 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes trophyBounce {
  from { transform: scale(0.3) rotate(-15deg); opacity: 0; }
  to { transform: scale(1) rotate(0deg); opacity: 1; }
}

.game-over-box h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.game-over-box p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.go-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.go-actions .btn {
  width: 100%;
  padding: 11px;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  padding: 8px 16px;
  background: rgba(16, 18, 23, 0.96);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
