/* =============================================================
   FjordFish — Стили
   Пастельная палитра, мягкие тени, скруглённые углы
   ============================================================= */

/* --- Сброс и базовые настройки --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Пастельная палитра */
  --bg: #faf5eb;
  --lake-blue: #a8d8ea;
  --lake-deep: #7ec8d8;
  --shore-green: #c5e6c0;
  --shore-sand: #f2e8d0;
  --text: #4a4a4a;
  --text-light: #8a8a8a;
  --accent: #f4978e;
  --accent-hover: #f07167;
  --accent-active: #d95f55;
  --card-bg: #ffffffdd;
  --shadow: rgba(0, 0, 0, 0.08);
  --shadow-strong: rgba(0, 0, 0, 0.15);

  /* Палитра игроков (пастельные) */
  --player-0: #f4978e;
  --player-1: #a8d8ea;
  --player-2: #c5b4e3;
  --player-3: #f8c291;
  --player-4: #b5ead7;
  --player-5: #ffd3b6;

  /* Размеры */
  --radius: 16px;
  --radius-sm: 10px;
  --btn-height: 48px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Comfortaa', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

/* --- Экраны (показываем по одному) --- */
.screen {
  display: none;
  position: fixed;
  inset: 0;
  justify-content: center;
  align-items: center;
  z-index: 1;
}

.screen.active {
  display: flex;
}

/* Финальный экран длинный (рейтинг + донат) — разрешаем скролл,
   карточка центрируется по горизонтали и прижимается к верху, чтобы
   на маленьких экранах не обрезалась снизу. */
#screen-final.active {
  overflow-y: auto;
  align-items: flex-start;
  padding: 24px 16px 40px;
}

/* =========================================
   ЛОББИ
   ========================================= */
/* Постер 1:1 (2048×2048) с Муми-семьёй внизу и башней справа сверху.
   Карточка с формой ложится в верхний-левый угол — там небо над озером,
   свободное от персонажей. */
#screen-lobby {
  background-image: url('../assets/lobby_poster.png');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-color: #f6efe1;
  /* Карточка прижата к верхнему-левому углу */
  justify-content: flex-start;
  align-items: flex-start;
  padding: 4vh 0 0 4vw;
}

@media (max-width: 720px) {
  #screen-lobby {
    /* На мобильных постер обрезается, карточка едет вниз */
    justify-content: center;
    align-items: flex-end;
    padding: 0 0 4vh 0;
    background-position: 50% 70%;
  }
}

.lobby-card {
  /* Чуть теплее и плотнее, чтобы хорошо читалось на кремовой панели */
  background: rgba(255, 252, 246, 0.96);
  backdrop-filter: blur(6px);
  border-radius: var(--radius);
  padding: 28px 26px;
  width: 92%;
  max-width: 340px;
  box-shadow: 0 10px 32px rgba(120, 90, 60, 0.18);
  text-align: center;
  border: 1px solid rgba(180, 150, 110, 0.18);
}

.lobby-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

.lobby-subtitle {
  font-size: 0.95rem;
  color: var(--text-light);
  margin-bottom: 28px;
}

/* Форма */
.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 6px;
  text-align: left;
}

.form-input {
  width: 100%;
  height: var(--btn-height);
  padding: 0 16px;
  border: 2px solid #e0d8cc;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}

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

.form-input--code {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.lobby-form {
  margin-bottom: 24px;
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Опция «подождать друзей» — компактный чекбокс над кнопкой Create */
.lobby-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-light);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  padding: 4px 2px;
}
.lobby-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.lobby-join {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-light);
  font-size: 0.85rem;
  margin: 4px 0;
}

.lobby-divider::before,
.lobby-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e0d8cc;
}

.error-message {
  margin-top: 16px;
  padding: 10px 14px;
  background: #fde8e8;
  color: #c0392b;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

/* --- Кнопки --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--btn-height);
  padding: 0 28px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  user-select: none;
  -webkit-user-select: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(244, 151, 142, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--accent-active);
}

.btn-secondary {
  background: var(--lake-blue);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(168, 216, 234, 0.35);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--lake-deep);
  color: #fff;
}

/* =========================================
   ОЖИДАНИЕ В КОМНАТЕ
   ========================================= */
.waiting-card {
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 8px 32px var(--shadow);
  text-align: center;
}

.waiting-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.waiting-code {
  /* Крупный, выделенный код — чтобы успеть прочитать с другого устройства
     и набрать без перебивки на «Game starts in 5...» */
  display: inline-block;
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 3px;
  background: #fff7f0;
  padding: 10px 20px;
  border-radius: 12px;
  border: 2px dashed rgba(244, 151, 142, 0.4);
  margin-bottom: 8px;
}

.waiting-hint {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 24px;
}

.player-list-container h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.player-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: #f7f3ec;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.player-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.player-host-badge {
  font-size: 0.75rem;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 8px;
  margin-left: auto;
}

.waiting-status {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-top: 12px;
}

.btn-start {
  width: 100%;
  font-size: 1.1rem;
  height: 54px;
}

/* =========================================
   ИГРОВОЙ ЭКРАН
   ========================================= */
#screen-game {
  background: var(--shore-sand);
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* --- HUD (интерфейс поверх canvas) --- */
.hud {
  position: absolute;
  z-index: 10;
  pointer-events: none;
}

.hud * {
  pointer-events: auto;
}

/* Таймер + кнопка звука — компактно в левом верхнем углу,
   чтобы не закрывать верхнего игрока в центре */
.hud-top {
  top: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Кнопка mute: круглая, в стиле таймера */
.btn-mute {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--card-bg);
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px var(--shadow);
  cursor: pointer;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn-mute:hover { transform: scale(1.06); }
.btn-mute:active { transform: scale(0.96); }

.btn-mute.muted {
  background: rgba(220, 220, 220, 0.92);
  opacity: 0.7;
}

.timer-display {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  backdrop-filter: blur(8px);
  padding: 8px 16px;
  border-radius: 24px;
  box-shadow: 0 4px 16px var(--shadow);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.timer-icon {
  font-size: 1.2rem;
}

/* Таймер мигает когда мало времени */
.timer-display.urgent {
  color: #c0392b;
  animation: pulse 0.8s ease-in-out infinite;
}

/* Счёт справа */
.hud-right {
  top: 16px;
  right: 16px;
  background: var(--card-bg);
  backdrop-filter: blur(8px);
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px var(--shadow);
  min-width: 160px;
  max-width: 200px;
}

.hud-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 8px;
  text-align: center;
}

.scoreboard-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.scoreboard-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

.score-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.score-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-value {
  font-weight: 700;
  color: var(--accent);
}

/* --- Кнопка "Тяни!" --- */
/* Центрируем через translateX(-50%) — работает независимо от ширины
   (важно для мобильных, где ширина меняется в медиа-запросе).
   Сдвиг по X хранится в --pull-shift, чтобы анимация scale при клёве
   не дёргала кнопку влево. */
.btn-pull {
  --pull-shift: -50%;
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(var(--pull-shift));
  z-index: 20;
  width: 180px;
  height: 72px;
  border-radius: 36px;
  background: var(--accent);
  color: #fff;
  font-size: 1.6rem;
  font-weight: 700;
  box-shadow: 0 6px 24px rgba(244, 151, 142, 0.5);
  display: flex;
  flex-direction: column;
  gap: 0;
  transform-origin: 50% 50%;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-pull .pull-text {
  line-height: 1;
}

.btn-pull .pull-hint {
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.7;
}

/* Когда клюёт — мягкий пульс на месте, цвет мигает, без сдвига */
.btn-pull.biting {
  animation: pullPulse 0.5s ease-in-out infinite alternate;
  background: #e74c3c;
  box-shadow: 0 0 30px rgba(231, 76, 60, 0.7), 0 0 60px rgba(231, 76, 60, 0.3);
}

@keyframes pullPulse {
  0%   { transform: translateX(-50%) scale(1);    background: #e74c3c; }
  100% { transform: translateX(-50%) scale(1.12); background: #ff6b6b; }
}

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

/* --- Всплывающее сообщение при поимке (мой улов) --- */
/* Расположен рядом с кнопкой "Тяни" внизу — чтобы не загораживать озеро */
.catch-popup {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: 14%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(255, 252, 246, 0.94);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(120, 90, 60, 0.18);
  border: 1px solid rgba(180, 150, 110, 0.18);
  pointer-events: none;
}

.catch-popup.show {
  animation: catchFloat 1.4s ease-out forwards;
}

.catch-emoji {
  font-size: 2rem;
  display: flex;
  align-items: center;
}

.catch-emoji img {
  width: 48px !important;
  height: 48px !important;
}

.catch-text {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  background: var(--card-bg);
  padding: 4px 14px;
  border-radius: 20px;
  box-shadow: 0 2px 10px var(--shadow);
  white-space: nowrap;
}

@keyframes catchFloat {
  0% {
    opacity: 0;
    transform: translateX(-50%) scale(0.6);
  }
  15% {
    opacity: 1;
    transform: translateX(-50%) scale(1.08);
  }
  30% {
    transform: translateX(-50%) scale(1);
  }
  85% {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) scale(0.95) translateY(-20px);
  }
}

/* =========================================
   ФИНАЛЬНЫЙ ЭКРАН
   ========================================= */
.final-card {
  background: var(--card-bg);
  backdrop-filter: blur(10px);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 90%;
  max-width: 480px;
  box-shadow: 0 8px 32px var(--shadow);
  text-align: center;
}

.final-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.final-trophy {
  font-size: 3.5rem;
  margin: 12px 0 20px;
}

.final-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 0.95rem;
}

.final-table th {
  font-weight: 600;
  color: var(--text-light);
  padding: 8px 6px;
  border-bottom: 2px solid #e0d8cc;
  text-align: left;
}

.final-table td {
  padding: 10px 6px;
  border-bottom: 1px solid #f0eae0;
  text-align: left;
}

.final-table tr:first-child td {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
}

.final-table .place-1 { color: #d4a017; }
.final-table .place-2 { color: #8a8a8a; }
.final-table .place-3 { color: #b87333; }

#btn-restart {
  width: 100%;
  font-size: 1.1rem;
  height: 54px;
}

/* =========================================
   ДОНАТНАЯ ПЛАШКА (на финальном экране)
   ========================================= */
.donate-card {
  margin-top: 28px;
  padding: 22px 20px 18px;
  background: linear-gradient(180deg, #fff8eb 0%, #fff3df 100%);
  border-radius: var(--radius);
  border: 1px solid rgba(220, 170, 90, 0.25);
  box-shadow: 0 4px 14px rgba(180, 130, 60, 0.10);
  text-align: center;
}

.donate-emoji {
  font-size: 1.8rem;
  margin-bottom: 6px;
  filter: drop-shadow(0 1px 1px rgba(180, 80, 80, 0.15));
}

.donate-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #6a4a2a;
  margin: 0 0 8px 0;
}

.donate-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: #7a5a3a;
  margin: 0 0 16px 0;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

.btn-donate {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 22px;
  background: #f4a93d;
  color: #ffffff !important;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(220, 150, 50, 0.32);
  transition: transform 0.15s, box-shadow 0.15s, background 0.15s;
}

.btn-donate:hover {
  background: #f5b554;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(220, 150, 50, 0.42);
}

.btn-donate:active {
  transform: translateY(0);
  box-shadow: 0 3px 8px rgba(220, 150, 50, 0.32);
}

.donate-btn-emoji {
  font-size: 1.2rem;
}

.donate-hint {
  font-size: 0.78rem;
  color: #a08868;
  margin: 12px 0 0 0;
}

/* =========================================
   Адаптивность
   ========================================= */

/* Мобильные устройства */
@media (max-width: 480px) {
  .lobby-card,
  .waiting-card,
  .final-card {
    padding: 28px 20px;
  }

  .lobby-title {
    font-size: 1.6rem;
  }

  /* Мобильный счёт: компактная плашка в правом нижнем углу,
     чтобы не перекрывать персонажа внизу-в-центре. Нет min-width —
     ширина по содержимому, плюс ограничиваем максимум. */
  .hud-right {
    top: auto;
    bottom: 12px;
    right: 8px;
    min-width: 0;
    max-width: 110px;
    padding: 6px 8px;
    font-size: 0.7rem;
    border-radius: 12px;
    /* Полупрозрачнее — пропускаем фон, не отвлекаем взгляд */
    background: rgba(255, 252, 246, 0.78);
  }
  .hud-right .hud-title {
    font-size: 0.65rem;
    margin-bottom: 4px;
  }
  .hud-right .scoreboard-list { gap: 2px; }
  .hud-right .scoreboard-list li { font-size: 0.7rem; gap: 4px; }
  .hud-right .score-dot { width: 7px; height: 7px; }

  .timer-display {
    font-size: 1.2rem;
    padding: 8px 18px;
  }

  .btn-pull {
    width: 150px;
    height: 60px;
    font-size: 1.3rem;
    bottom: 24px;
  }
}

/* Планшеты */
@media (min-width: 481px) and (max-width: 768px) {
  .hud-right {
    min-width: 150px;
  }
}

/* Широкие экраны */
@media (min-width: 1280px) {
  .hud-right {
    min-width: 200px;
  }
}
