/* ========== МИНИ-ИГРЫ ==========
   Оверлей — тот же паттерн, что battlepass_styles.css. Игровое поле — canvas 360×600,
   масштабируется под экран (на телефоне занимает всю доступную высоту). */

#minigamesOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1200;
}

#minigamesWindow {
  background: white;
  width: 96%;
  max-width: 760px;
  max-height: 94vh;
  max-height: 94dvh;
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.5);
}

#minigamesBody {
  padding: 16px;
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.mg-intro { margin: 0 0 6px; color: #444; }
.mg-coins-today { margin: 0 0 6px; font-weight: 600; color: #7b5b00; }
.mg-controls { margin: 0 0 14px; color: #777; font-size: 13px; }

.mg-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }

.mg-card {
  border: 1px solid #e3e3f0;
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #f8f8ff, #fff);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mg-card-icon { font-size: 34px; line-height: 1; }
.mg-card-body h3 { margin: 0 0 4px; }
.mg-card-body p { margin: 0 0 8px; color: #555; font-size: 13px; }
.mg-best { font-size: 13px; font-weight: 600; margin-bottom: 8px; }

.mg-top { border-top: 1px dashed #ddd; padding-top: 8px; font-size: 13px; }
.mg-top-title { font-weight: 700; margin-bottom: 4px; }
.mg-top-row { display: flex; gap: 6px; align-items: center; padding: 2px 0; }
.mg-top-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-top-empty { color: #999; }

/* Игра */
#minigamesGameView { display: flex; flex-direction: column; align-items: center; }

.mg-hud {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  align-self: stretch;
}
.mg-hud-item { font-size: 15px; }
.mg-exit-btn { padding: 6px 12px; }

.mg-canvas-wrap {
  position: relative;
  align-self: center;
  /* Точный размер (с сохранением пропорций 360×600) выставляет fitMgCanvas() в js/minigames.js */
  width: 360px;
  height: 600px;
  border-radius: 14px;
  overflow: hidden;
  background: #111;
}
#mgCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;           /* палец двигает персонажа, а не прокручивает страницу */
  user-select: none;
  -webkit-user-select: none;
}

.mg-result {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  padding: 12px;
}
.mg-result-card {
  background: white;
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  width: 100%;
  max-width: 280px;
}
.mg-result-card h3 { margin: 0 0 4px; }
.mg-result-score { font-size: 44px; font-weight: 800; color: #667eea; line-height: 1.1; }
.mg-new-best { color: #b8860b; font-weight: 700; margin: 4px 0; }
.mg-reward { margin: 6px 0; font-weight: 600; }
.mg-no-reward { color: #999; font-weight: 400; }
.mg-coins-left { margin: 0 0 8px; color: #777; font-size: 12px; }
.mg-result-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

@media (max-width: 600px) {
  #minigamesWindow { width: 100%; max-height: 100vh; max-height: 100dvh; border-radius: 0; }
  #minigamesBody { padding: 10px; }
  .mg-cards { grid-template-columns: 1fr; }
}

/* Игра на телефоне: во весь экран, без шапки окна; счёт/выход — поверх поля; снизу кнопки ◀ ▶.
   Класс вешается на оверлей только во время игры на сенсорном устройстве (см. setMgMobileMode). */
#minigamesOverlay.mg-mobile-game { background: #111; }
.mg-mobile-game #minigamesWindow {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border-radius: 0;
  background: #111;
  box-shadow: none;
}
.mg-mobile-game #minigamesWindow > .admin-header { display: none; }
.mg-mobile-game #minigamesBody { padding: 0; flex: 1; overflow: hidden; }
/* min-height:0 — БЕЗ него flex-элемент по умолчанию (min-height:auto) отказывается
   сжиматься ниже высоты своего содержимого (тут — стол, размер которого считает JS,
   см. fitPoolCanvas), даже когда flex:1 отдаёт ему меньше места, чем контент просит.
   В альбомной ориентации (низкий экран) это и раздвигало #minigamesGameView выше
   реального viewport'а — абсолютно спозиционированная снизу панель силы (см.
   .pool-controls ниже) съезжала за пределы экрана вместе с ним (см. чат — "штуку
   снизу... никак не нажать"). overflow:hidden — подстраховка на случай, если стол
   всё равно окажется чуть больше отведённого места: обрежется сам стол, а не
   вытолкнет панель управления за экран. */
.mg-mobile-game #minigamesGameView { position: relative; flex: 1; min-height: 0; overflow: hidden; justify-content: center; }
.mg-mobile-game .mg-canvas-wrap { border-radius: 0; }
.mg-mobile-game .mg-hud {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 8px;
  right: 8px;
  z-index: 4;
  margin: 0;
  gap: 8px;
  pointer-events: none;
}
.mg-mobile-game .mg-hud > * {
  pointer-events: auto;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 15px;
}
.mg-mobile-game .mg-exit-btn { border: none; }

.mg-arrows {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: flex;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: none;
}
.mg-arrow-btn {
  pointer-events: auto;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(2px);
}
.mg-arrow-btn.pressed { background: rgba(255, 255, 255, 0.55); transform: scale(0.94); }
.mg-hud > *:empty { display: none; }

/* Игровой уровень */
.mg-level { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center; margin-bottom: 10px; padding: 8px 12px; border-radius: 10px; background: #efeefb; }
.mg-level-bar { grid-column: 1 / -1; height: 8px; border-radius: 6px; background: #d8d6f0; overflow: hidden; }
.mg-level-fill { height: 100%; background: linear-gradient(90deg, #667eea, #764ba2); }

/* Прогресс ранга в бильярде — та же полоска (.mg-level-bar/.mg-level-fill), что у
   общего игрового уровня наверху меню, просто в компактном виде внутри карточки. */
.mg-pool-rank { margin-bottom: 8px; }
.mg-pool-rank-label { display: flex; justify-content: space-between; align-items: baseline; font-size: 12px; margin-bottom: 4px; }
.mg-pool-rank-label b { font-size: 13px; }
.mg-pool-rank-label span { color: #777; }
.mg-pool-rank .mg-level-fill { background: linear-gradient(90deg, #2f6b3a, #4a9c5c); }
.mg-card-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

/* Дуэли */
.duel-picker h3 { margin: 10px 0; }
.duel-stake { margin-bottom: 10px; }
.duel-stake label { font-weight: 700; display: block; margin-bottom: 4px; }
.duel-stake input { width: 110px; padding: 8px; border: 1px solid #ccc; border-radius: 8px; font-size: 16px; }
.duel-chips { display: inline-flex; gap: 6px; margin-left: 8px; flex-wrap: wrap; }
.duel-chip { padding: 6px 10px; border: 1px solid #d8d6f0; border-radius: 999px; background: #fff; cursor: pointer; font-weight: 700; }
.duel-chip:hover { background: #f5f6ff; }
.duel-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.duel-player-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border: 1px solid #e3e3f0; border-radius: 10px; background: #fafaff; }
.duel-player-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.duel-waiting { text-align: center; padding: 30px 10px; }
.duel-waiting-icon { font-size: 54px; animation: duel-pulse 1s infinite; }
@keyframes duel-pulse { 50% { transform: scale(1.15); } }

#duelInviteBox {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2500;
  width: min(92vw, 380px);
  padding: 14px 16px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  border: 2px solid #667eea;
  text-align: center;
}
.duel-invite-title { font-weight: 700; margin-bottom: 4px; }
.duel-invite-stake { color: #7b5b00; font-weight: 600; margin-bottom: 10px; font-size: 14px; }
.duel-invite-buttons { display: flex; gap: 8px; justify-content: center; }

/* Соперник в дуэли теперь рисуется ПРЯМО в своём канвасе (см. _drawGhost в
   js/minigames.js, идёт вместе со своей игрой) — счёт/жизни просто ещё один
   .mg-hud-item в общем HUD, отдельная раскладка на 2 окна больше не нужна. */
.mg-hud-opp { margin-left: auto; }
.mg-duel-note { min-height: 18px; margin-top: 6px; font-size: 13px; font-weight: 600; color: #b8860b; text-align: center; }
.mg-countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 90px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 3;
}
.duel-result-scores { display: flex; justify-content: space-around; margin: 8px 0; font-size: 15px; }
.duel-result.win h3 { color: #b8860b; }
.duel-result.lose h3 { color: #c0392b; }

/* Дуэль на телефоне: свой экран крупно, окошко соперника — в углу поверх поля */
.mg-mobile-game .mg-duel-row.mobile { position: relative; justify-content: center; }
.mg-mobile-game .mg-duel-row.mobile .mg-duel-opp {
  position: absolute;
  top: 46px;
  right: 6px;
  z-index: 3;
  pointer-events: none;
}
.mg-mobile-game .mg-duel-row.mobile .mg-duel-opp .mg-duel-name {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border-radius: 8px;
  padding: 2px 6px;
  font-size: 11px;
  max-width: 100%;
}
.mg-mobile-game .mg-duel-row.mobile .mg-duel-col:first-child .mg-duel-name { display: none; }
.mg-mobile-game .mg-duel-note { position: absolute; bottom: 120px; left: 0; right: 0; color: #ffd54f; text-shadow: 0 1px 4px #000; z-index: 4; }

/* Бильярд */
.mg-pool-diff { margin-bottom: 8px; padding: 6px 8px; border-radius: 8px; border: 1px solid #ccc; font-size: 13px; }
.pool-players { display: flex; gap: 8px; width: 100%; margin-bottom: 6px; }
.pool-player { flex: 1; min-width: 0; padding: 6px 10px; border-radius: 10px; background: #f0f0f6; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 13px; border: 2px solid transparent; }
.pool-player.active { border-color: #667eea; background: #efeefb; }
/* Ранг в бильярде (растёт от побед, см. poolLevelFromWins в server.js) — свой,
   зелёный (в тон сукну стола), не путать с обычным жёлтым .level-tag (общий
   уровень персонажа, тот не отсюда, см. levelTagHtml в js/socket.js). */
.pool-level-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  height: 15px;
  border-radius: 4px;
  font-size: 9px;
  font-weight: 800;
  background: #2f6b3a;
  color: white;
}
.pool-group { color: #666; font-size: 12px; }
.pool-tray { display: inline-flex; gap: 2px; }
.pool-mini { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.4); display: inline-block; }
.pool-status { font-weight: 700; margin: 2px 0 6px; text-align: center; min-height: 20px; }
.pool-wrap { background: transparent; border-radius: 0; max-width: 100%; }
.pool-wrap canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.pool-controls { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 640px; margin-top: 8px; }
.pool-controls label { font-size: 13px; white-space: nowrap; }
.pool-controls input[type=range] { flex: 1; min-width: 0; height: 28px; }
.pool-controls.disabled { opacity: 0.45; pointer-events: none; }
.pool-controls .item-btn { padding: 10px 20px; font-size: 15px; }
.mg-mobile-game .pool-players { position: absolute; top: calc(52px + env(safe-area-inset-top, 0px)); left: 6px; right: 6px; width: auto; z-index: 3; }
.mg-mobile-game .pool-status { position: absolute; top: calc(104px + env(safe-area-inset-top, 0px)); left: 0; right: 0; z-index: 3; color: #fff; text-shadow: 0 1px 4px #000; }
.mg-mobile-game .pool-wrap { margin-top: 20px; }
.mg-mobile-game .pool-controls { position: absolute; left: 10px; right: 10px; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); width: auto; max-width: none; background: rgba(0,0,0,0.55); border-radius: 14px; padding: 8px 12px; color: #fff; z-index: 4; }

/* Бильярд: широкое окно без шапки — стол занимает максимум места */
.mg-pool-game #minigamesWindow { max-width: 1180px; width: 98%; max-height: 98vh; max-height: 98dvh; }
.mg-pool-game #minigamesWindow > .admin-header { display: none; }
.mg-pool-game #minigamesBody { padding: 10px 14px; align-items: center; }
.mg-pool-game #minigamesGameView { width: 100%; }
.mg-pool-game .pool-controls { max-width: 900px; }
.mg-pool-game .pool-players { max-width: 900px; }
.mg-pool-game.mg-mobile-game .pool-players { max-width: none; }
/* Телефон: сверху одна тонкая строка (выход + игроки), снизу тонкая панель силы, весь остальной экран — стол */
.mg-pool-game.mg-mobile-game .mg-hud { top: calc(6px + env(safe-area-inset-top, 0px)); left: 6px; right: auto; }
.mg-pool-game.mg-mobile-game .mg-exit-btn { padding: 5px 9px; font-size: 12px; }
.mg-pool-game.mg-mobile-game #poolTimer { display: none; }
.mg-pool-game.mg-mobile-game .pool-players { top: calc(6px + env(safe-area-inset-top, 0px)); left: 92px; right: 6px; width: auto; max-width: none; margin: 0; gap: 4px; }
.mg-pool-game.mg-mobile-game .pool-player { padding: 3px 6px; font-size: 11px; gap: 0 5px; min-height: 30px; align-content: center; }
.mg-pool-game.mg-mobile-game .pool-group { display: none; }
.mg-pool-game.mg-mobile-game .pool-mini { width: 9px; height: 9px; }
.mg-pool-game.mg-mobile-game .pool-status { display: none; }
.mg-pool-game.mg-mobile-game .pool-wrap { margin: 0; }
.mg-pool-game.mg-mobile-game #minigamesBody { padding: 0; }
.mg-pool-game.mg-mobile-game .pool-controls { bottom: calc(6px + env(safe-area-inset-bottom, 0px)); left: 6px; right: 6px; padding: 5px 10px; gap: 8px; border-radius: 12px; }
.mg-pool-game.mg-mobile-game .pool-controls .item-btn { padding: 8px 16px; font-size: 14px; }

.pool-hint { font-size: 12px; color: #777; text-align: center; margin: 0 0 6px; max-width: 900px; }
.mg-mobile-game .pool-hint { display: none; }
