/* Telegram Dark Theme + Game UI */
:root {
  --bg: var(--tg-theme-bg-color, #0e1621);
  --bg-card: var(--tg-theme-secondary-bg-color, #182533);
  --bg-hover: #202f3f;
  --primary: var(--tg-theme-button-color, #2ea6ff);
  --primary-hover: var(--tg-theme-button-text-color, #57b8ff);
  --danger: #ff595a;
  --success: #5dc97a;
  --warning: #ffaa00;
  --text: var(--tg-theme-text-color, #f5f5f5);
  --text-secondary: var(--tg-theme-hint-color, #7d8b99);
  --border: #111921;
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.5);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Avatar wrapper для img fallback */
.avatar-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.avatar-wrapper .fallback-emoji {
  font-size: inherit;
  line-height: 1;
}

/* Верхняя панель */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.logo { font-weight: 800; font-size: 16px; letter-spacing: 0.5px; }
.currency { display: flex; gap: 12px; font-weight: 600; font-size: 14px; }
.corn { color: #ffcc4d; }
.crystal { color: #2ea6ff; }

/* Экраны */
.screen {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 80px;
  animation: fadeIn 0.25s ease;
}
.screen.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.section-header h2 { font-size: 20px; }
.hint { font-size: 12px; color: var(--text-secondary); }

/* Карточки петухов */
.rooster-list { display: flex; flex-direction: column; gap: 12px; }
.rooster-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.2s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.rooster-card:hover { transform: translateY(-2px); border-color: var(--bg-hover); }
.rooster-card.selected { border-color: var(--primary); }
.rooster-card.recovery { opacity: 0.6; border-color: var(--danger); }
.rooster-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  flex-shrink: 0;
  background: var(--bg-hover);
}
.rooster-info { flex: 1; min-width: 0; }
.rooster-name { font-weight: 700; font-size: 16px; margin-bottom: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rooster-meta { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.rarity-badge {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 2px 6px; border-radius: 4px; letter-spacing: 0.5px;
}
.recovery-badge {
  font-size: 10px; font-weight: 700;
  background: var(--danger); color: #fff;
  padding: 2px 6px; border-radius: 4px;
}
.fatigue-track {
  width: 100%;
  height: 5px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.fatigue-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.fatigue-text {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.stats-row {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.stat-pill {
  background: var(--bg);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  display: flex; align-items: center; gap: 4px;
}
.stat-pill .label { color: var(--text-secondary); }
.stat-pill .value { font-weight: 700; }

/* Арена */
.arena-layout { display: flex; flex-direction: column; gap: 16px; }
.arena-setup h2 { font-size: 18px; margin-bottom: 12px; }
.fighter-select {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 16px;
}
.fighter-box {
  flex: 1;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  min-height: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px;
  border: 2px dashed var(--bg-hover);
  cursor: pointer;
  transition: all 0.2s;
}
.fighter-box:hover { border-color: var(--primary); background: var(--bg-hover); }
.fighter-box .placeholder { color: var(--text-secondary); font-size: 13px; }
.fighter-box .f-avatar { font-size: 48px; width: 56px; height: 56px; margin: 0 auto; }
.fighter-box .f-name { font-weight: 700; font-size: 15px; }
.fighter-box .f-stats { font-size: 12px; color: var(--text-secondary); }
.vs-label {
  font-weight: 900; font-size: 20px; color: var(--danger);
  text-shadow: 0 0 10px rgba(255,89,90,0.4);
}

/* Режимы боя */
.mode-panel { margin-bottom: 12px; }
.mode-buttons { display: flex; flex-direction: column; gap: 10px; }
.mode-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 16px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}
.mode-btn:hover { border-color: var(--primary); background: var(--bg-hover); }
.mode-btn .mode-icon { font-size: 28px; }
.mode-btn .mode-title { font-weight: 700; font-size: 15px; }
.mode-btn .mode-desc { font-size: 12px; color: var(--text-secondary); }

/* Поиск */
.search-panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
}
.searching-animation { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 16px; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--bg-hover);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* PvP список */
.pvp-panel { background: var(--bg-card); border-radius: var(--radius); padding: 16px; }
.pvp-panel h3 { font-size: 16px; margin-bottom: 12px; }
.user-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.user-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); padding: 10px; border-radius: var(--radius-sm);
  cursor: pointer; border: 2px solid transparent;
}
.user-row:hover { border-color: var(--primary); }
.user-avatar { font-size: 24px; }
.user-info { flex: 1; }
.user-name { font-weight: 700; font-size: 14px; }
.user-meta { font-size: 12px; color: var(--text-secondary); }
.btn-challenge {
  background: var(--success); color: #fff; border: none;
  padding: 6px 12px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 12px; cursor: pointer;
}

/* Кнопки */
.btn-primary {
  width: 100%;
  margin-top: 14px;
  padding: 14px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: var(--bg-hover); color: var(--text-secondary); cursor: not-allowed; }

.btn-secondary {
  padding: 10px 18px;
  background: var(--bg-hover);
  color: var(--text);
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
}

/* Игровой контейнер */
.game-container {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0b1219;
}
#phaser-game canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  border-radius: var(--radius);
}
.fight-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 12px;
  background: linear-gradient(transparent, rgba(14,22,33,0.95));
  pointer-events: none;
}
.fight-overlay > * { pointer-events: auto; }
.fight-log {
  max-height: 90px;
  overflow-y: auto;
  font-size: 13px;
  display: flex; flex-direction: column; gap: 4px;
  margin-bottom: 8px;
}
.log-entry { opacity: 0.9; }
.log-entry.crit { color: var(--danger); font-weight: 700; }
.log-entry.dodge { color: var(--primary); }
.log-entry.heal { color: var(--success); }

/* Маркет */
.market-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.market-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  border: 2px solid transparent;
  transition: transform 0.15s;
}
.market-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.market-card .m-avatar { font-size: 40px; margin-bottom: 6px; width: 48px; height: 48px; margin-left: auto; margin-right: auto; }
.market-card .m-name { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.market-card .m-stats { font-size: 11px; color: var(--text-secondary); margin-bottom: 10px; }
.price-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-weight: 700; font-size: 13px;
  background: var(--bg); padding: 4px 10px; border-radius: 20px;
}
.btn-buy {
  margin-top: 10px; width: 100%;
  padding: 8px;
  background: var(--success);
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-weight: 700; cursor: pointer;
}
.btn-buy:disabled { background: var(--bg-hover); color: var(--text-secondary); cursor: not-allowed; }

/* Модалки */
.modal {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal.open { display: flex; }
.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%; max-width: 420px;
  max-height: 75vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: popIn 0.2s ease;
}
.modal-room { max-width: 440px; }
@keyframes popIn { from { transform: scale(0.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close { background: none; border: none; color: var(--text); font-size: 24px; cursor: pointer; }
.modal-body { overflow-y: auto; padding: 14px; }

/* Комната петуха */
.room-preview {
  text-align: center; margin-bottom: 16px;
}
.room-avatar {
  font-size: 64px; margin-bottom: 6px;
  width: 80px; height: 80px;
  margin-left: auto;
  margin-right: auto;
}
.room-name { font-weight: 800; font-size: 18px; }
.room-recovery { font-size: 13px; color: var(--danger); margin-top: 4px; font-weight: 700; }

.room-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.room-stat {
  background: var(--bg); padding: 10px; border-radius: var(--radius-sm);
  text-align: center;
}
.room-stat .label { font-size: 11px; color: var(--text-secondary); }
.room-stat .value { font-size: 18px; font-weight: 800; }

.upgrades-list { display: flex; flex-direction: column; gap: 10px; }
.upgrade-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); padding: 10px; border-radius: var(--radius-sm);
}
.upgrade-info { flex: 1; }
.upgrade-name { font-weight: 700; font-size: 14px; }
.upgrade-desc { font-size: 12px; color: var(--text-secondary); }
.upgrade-btn {
  background: var(--success); color: #fff; border: none;
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-weight: 700; font-size: 13px; cursor: pointer;
  white-space: nowrap;
}
.upgrade-btn:disabled { background: var(--bg-hover); color: var(--text-secondary); cursor: not-allowed; }

.selectable-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); padding: 10px; border-radius: var(--radius-sm);
  margin-bottom: 8px; cursor: pointer;
  border: 2px solid transparent;
}
.selectable-card:hover { border-color: var(--primary); }
.selectable-card .s-avatar { font-size: 28px; width: 32px; height: 32px; }
.selectable-card .s-info { flex: 1; }
.selectable-card .s-name { font-weight: 700; font-size: 14px; }
.selectable-card .s-stats { font-size: 11px; color: var(--text-secondary); }

/* Навигация */
.bottom-nav {
  position: absolute; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
}
.nav-btn {
  background: none; border: none;
  color: var(--text-secondary);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex: 1; cursor: pointer;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-size: 11px; font-weight: 600; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 4px; }

/* Canvas контейнер точные размеры */
#phaser-game { width: 100%; min-height: 280px; aspect-ratio: 4/3; }
