/* =========================================================
   Async Duel — style.css
   Кроссплатформенные стили (Browser / Telegram / Android)
   ========================================================= */

:root {
  --bg-primary: #1a1a2e;
  --bg-surface: #16213e;
  --bg-surface-elevated: #0f3460;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --text-main: #eaeaea;
  --text-muted: #8e92a8;
  --color-p1: #00f0ff;
  --color-p2: #ff2a70;
  --color-gold: #ffd166;
  --color-success: #06d6a0;
  --radius-btn: 10px;
  --radius-card: 14px;
  --btn-min-h: 42px; /* Уменьшено с 56px */
  --font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --header-h: 60px;
  
  /* Переменные для масштабирования интерфейса */
  --ui-scale: 1;
  
  --spacing-base: 12px;
  --space-xs: calc(var(--spacing-base) * 0.5);   /* 6px */
  --space-sm: calc(var(--spacing-base) * 0.75);  /* 9px */
  --space-md: var(--spacing-base);               /* 12px */
  --space-lg: calc(var(--spacing-base) * 1.5);   /* 18px */
  --space-xl: calc(var(--spacing-base) * 2.5);   /* 30px */

  --font-size-base: 14px;
  --fs-xs: calc(var(--font-size-base) * 0.8);    /* 11px */
  --fs-sm: calc(var(--font-size-base) * 0.9);    /* 12.5px */
  --fs-md: var(--font-size-base);                /* 14px */
  --fs-lg: calc(var(--font-size-base) * 1.3);    /* 18px */
  --fs-xl: calc(var(--font-size-base) * 1.7);    /* 24px */
  --fs-xxl: calc(var(--font-size-base) * 2.7);   /* 38px */
  
  --font-size-h1: var(--fs-xl);
  --font-size-h2: var(--fs-lg);
}

/* Пресеты масштаба */
body.scale-small {
  --ui-scale: 0.85;
  --spacing-base: 10px;
  --font-size-base: 13px;
  --btn-min-h: 36px;
  --radius-card: 12px;
  --radius-btn: 8px;
}
body.scale-medium {
  --ui-scale: 1;
  --spacing-base: 12px;
  --font-size-base: 14px;
  --btn-min-h: 42px;
  --radius-card: 14px;
  --radius-btn: 10px;
}
body.scale-large {
  --ui-scale: 1.15;
  --spacing-base: 15px;
  --font-size-base: 16px;
  --btn-min-h: 50px;
  --radius-card: 16px;
  --radius-btn: 12px;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-size: var(--font-size-base);
}

#app-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at 50% 30%, #1f1f3a 0%, #1a1a2e 100%);
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.game-wrapper {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  max-height: 100vh;
  aspect-ratio: 9 / 16;
  margin: auto;
  display: flex;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

@media (max-aspect-ratio: 9/16) {
  .game-wrapper {
    height: 100%;
    width: 100%;
    aspect-ratio: auto;
    border: none;
    box-shadow: none;
  }
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
}

#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

/* Элементы внутри UI-слоя интерактивны */
#ui-layer button,
#ui-layer .interactive {
  pointer-events: auto;
}

/* Базовые стили кнопок */
.game-btn {
  min-height: var(--btn-min-h);
  padding: 8px 16px; /* Уменьшено с 14/28 */
  border-radius: var(--radius-btn);
  background-color: var(--accent);
  color: #ffffff;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: calc(16px * var(--ui-scale));
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.3);
  text-decoration: none;
}

.game-btn:hover {
  background-color: var(--accent-hover);
  box-shadow: 0 6px 16px rgba(233, 69, 96, 0.5);
}

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

.game-btn-secondary {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  box-shadow: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.game-btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.game-btn-p1 {
  background-color: var(--color-p1);
  color: #0b132b;
  box-shadow: 0 4px 14px rgba(0, 240, 255, 0.3);
}
.game-btn-p1:hover {
  background-color: #5cf5ff;
}

.game-btn-p2 {
  background-color: var(--color-p2);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(255, 42, 112, 0.3);
}
.game-btn-p2:hover {
  background-color: #ff528e;
}

/* Контейнеры экранов */
.screen-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--header-h) var(--space-md) var(--space-md) var(--space-md);
  opacity: 1;
  transition: opacity 0.25s ease;
}

/* На экране игры отступ не нужен, так как ResourceBar скрыт */
#screen-minigame.screen-container {
  padding-top: var(--space-md);
}

.screen-container.fading {
  opacity: 0;
}

/* Модальное окно правил */
.modal-backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(10, 10, 20, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 15px;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background-color: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-card);
  padding: 18px; /* Было 24 */
  color: var(--text-main);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-title {
  font-size: calc(20px * var(--ui-scale));
  font-weight: 800;
  color: var(--accent);
  text-align: center;
}

.modal-body {
  font-size: calc(13px * var(--ui-scale));
  line-height: 1.5;
  color: #d2d5e2;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.modal-body p {
  margin-bottom: 10px;
}

.modal-body ul {
  padding-left: 20px;
  margin-bottom: 10px;
}

.modal-body li {
  margin-bottom: 5px;
}

/* Скроллбар для модалки */
.modal-body::-webkit-scrollbar {
  width: 4px;
}
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

/* Анимация пульсации активных аватаров раунда */
@keyframes avatarPulse {
  0% {
    transform: scale(1);
    filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.3));
  }
  50% {
    transform: scale(1.08);
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8));
  }
  100% {
    transform: scale(1);
    filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.3));
  }
}

.avatar-pulsing {
  animation: avatarPulse 1.6s infinite ease-in-out;
}

/* Скроллбары для списков и сеток */
#ui-layer div::-webkit-scrollbar {
  width: 4px;
}
#ui-layer div::-webkit-scrollbar-track {
  background: transparent;
}
#ui-layer div::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

/* Инпуты */
#ui-layer input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

/* Вкладки и табы */
.tabs-container {
  display: flex;
  width: 100%;
  gap: var(--space-xs);
  padding: 2px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-btn);
  margin-bottom: var(--space-sm);
}

.tabs-vertical {
  display: flex;
  flex-direction: column;
  width: 68px;
  gap: var(--space-xs);
  padding: var(--space-xs);
  background: rgba(0, 0, 0, 0.2);
  border-right: 1px solid rgba(255, 255, 255, 0.05);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0; /* фикс скролла во flex-колонке */
}

.tab-item {
  flex: 1;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-btn) - 2px);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tab-vertical-item {
  width: 52px;
  height: 52px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-lg);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.tab-item.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(233, 69, 96, 0.3);
}

.tab-vertical-item.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(233, 69, 96, 0.4);
  transform: scale(1.05);
}

.tab-item:hover:not(.active),
.tab-vertical-item:hover:not(.active) {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.tab-content-area {
  flex: 1;
  min-height: 0; /* фикс скролла во flex-колонке */
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.form-input {
  width: 100%;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-btn);
  color: #fff;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--fs-md);
  font-family: inherit;
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
  touch-action: auto;
  outline: none;
  transition: border-color 0.2s ease;
}

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

.error-text {
  color: var(--color-p2);
  font-size: var(--fs-xs);
  margin-top: 4px;
  text-align: left;
}

.category-tab, .skin-item {
  transition: all 0.2s ease;
}
.category-tab:hover:not(.active) {
  background: rgba(255, 255, 255, 0.12) !important;
}
.skin-item:hover:not(.selected) {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}

/* Утилиты для компактности */
.compact-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(22, 33, 62, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px;
}

.stat-item {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  font-weight: 600;
}

.stat-value {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: #fff;
}

.section-title {
  font-size: var(--fs-xs);
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-xs);
}

html, body {
  overscroll-behavior: none;
  touch-action: none;
}

#game-canvas {
  touch-action: none;
}