:root {
  --tg-theme-bg-color: #1a1a2e;
  --tg-theme-text-color: #e0e0e0;
  --tg-theme-hint-color: #888;
  --tg-theme-link-color: #6c9bd2;
  --tg-theme-button-color: #3a7bd5;
  --tg-theme-button-text-color: #fff;
  --tg-theme-secondary-bg-color: #16213e;
  --tg-theme-header-bg-color: #0f3460;
  --tg-theme-section-bg-color: #1a1a2e;
  --tg-theme-section-header-text-color: #6c9bd2;
  --tg-theme-subtitle-text-color: #999;
  --tg-theme-destructive-text-color: #e74c3c;

  --board-dark: #5D4037;
  --board-light: #FFCC80;
  --piece-white: #F5F5F5;
  --piece-black: #212121;
  --piece-white-border: #BDBDBD;
  --piece-black-border: #424242;
  --selected-glow: rgba(58, 123, 213, 0.8);
  --valid-move: rgba(76, 175, 80, 0.5);
  --capture-move: rgba(244, 67, 54, 0.4);
  --last-move-highlight: rgba(255, 235, 59, 0.35);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --transition: 0.2s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background-color: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.header {
  background-color: var(--tg-theme-header-bg-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--tg-theme-text-color);
}

.back-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--tg-theme-text-color);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.back-btn:hover, .back-btn:active {
  background: rgba(255,255,255,0.1);
}

.content {
  flex: 1;
  padding: 16px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.games-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 8px;
}

.game-card {
  background-color: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  border: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.game-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.game-card:active {
  transform: scale(0.98);
}

.game-card-icon {
  font-size: 48px;
  text-align: center;
  line-height: 1;
}

.game-card-title {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  color: var(--tg-theme-text-color);
}

.game-card-desc {
  font-size: 14px;
  color: var(--tg-theme-subtitle-text-color);
  text-align: center;
  line-height: 1.5;
}

.game-card-meta {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
  color: var(--tg-theme-hint-color);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
  text-decoration: none;
  color: var(--tg-theme-button-text-color);
  background-color: var(--tg-theme-button-color);
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  opacity: 0.9;
}

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

.btn-secondary {
  background-color: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  border: 1px solid rgba(255,255,255,0.12);
}

.btn-secondary:hover {
  background-color: rgba(255,255,255,0.08);
}

.btn-danger {
  background-color: var(--tg-theme-destructive-text-color);
  color: #fff;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
  min-height: 36px;
}

.btn-block {
  width: 100%;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-group .btn {
  flex: 1;
  min-width: 0;
}

.game-status {
  text-align: center;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  background: rgba(255,255,255,0.05);
}

.game-status .status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  animation: pulse 1.5s infinite;
}

.game-status .status-dot.online {
  background: #4caf50;
}

.game-status .status-dot.offline {
  background: #f44336;
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.game-info-item {
  font-size: 13px;
  color: var(--tg-theme-hint-color);
  display: flex;
  align-items: center;
  gap: 6px;
}

.game-info-item strong {
  color: var(--tg-theme-text-color);
}

.canvas-container {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  margin: 0 auto;
}

.canvas-container canvas {
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-width: 100%;
  height: auto;
}

.room-section {
  background-color: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 12px;
}

.room-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--tg-theme-section-header-text-color);
}

.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.12);
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 15px;
  outline: none;
  transition: border var(--transition);
}

.input:focus {
  border-color: var(--tg-theme-button-color);
}

.input::placeholder {
  color: var(--tg-theme-hint-color);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 360px;
  text-align: center;
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 12px;
}

.modal p {
  font-size: 14px;
  color: var(--tg-theme-subtitle-text-color);
  margin-bottom: 16px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--tg-theme-button-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

.captured-pieces {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.captured-piece-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.3);
}

.captured-piece-dot.white { background: var(--piece-white); }
.captured-piece-dot.black { background: var(--piece-black); }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 300;
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

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

.opponent-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opponent-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}

.opponent-color-dot.white { background: var(--piece-white); }
.opponent-color-dot.black { background: var(--piece-black); }

.lobby-title {
  font-size: 24px;
  font-weight: 700;
  text-align: center;
  margin: 24px 0 8px;
  color: var(--tg-theme-text-color);
}

.lobby-subtitle {
  font-size: 14px;
  text-align: center;
  color: var(--tg-theme-subtitle-text-color);
  margin-bottom: 20px;
}

/* Layout utilities */
.container {
  max-width: 100%;
  padding: 0 12px;
  margin: 0 auto;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin: 0 -6px;
}

.col-6 {
  flex: 0 0 50%;
  max-width: 50%;
  padding: 0 6px;
  box-sizing: border-box;
}

.col-12 {
  flex: 0 0 100%;
  max-width: 100%;
  padding: 0 6px;
  box-sizing: border-box;
}

/* Flex utilities */
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-center { justify-content: center; }

/* Gap utilities */
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 16px; }

/* Text utilities */
.text-center { text-align: center; }

/* Width utilities */
.w-100 { width: 100%; }

/* Margin helpers */
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }

/* Accent button */
.btn-accent {
  background: linear-gradient(135deg, #f0a500, #e6a400);
  color: #1a1a2e;
  border: none;
}

.btn-accent:hover {
  opacity: 0.9;
}

.btn-accent:active {
  transform: scale(0.96);
  opacity: 0.8;
}

@media (min-width: 600px) {
  .games-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 400px) {
  .content {
    padding: 12px;
  }
  .game-card {
    padding: 16px;
  }
  .btn {
    padding: 10px 18px;
    font-size: 14px;
  }
}
