/* --- ГЛОБАЛЬНЫЕ НАСТРОЙКИ --- */
*, *::before, *::after {
  box-sizing: border-box;
}

/* --- ОБЩИЕ СТИЛИ И ПЕРЕМЕННЫЕ --- */
:root {
  --primary-blue: #007aff;
  --secondary-gold: #D4AF37;
  --dark-bg: #000;
  --dark-surface: #1c1c1e;
  --dark-border: #3a3a3c;
  --text-primary: #fff;
  --text-secondary: #8e8e93;
}

/* Общее скрытие, используется для элементов, которые должны быть полностью убраны из DOM */
.hidden {
  display: none !important;
}

html, body {
  /* Запрещаем прокрутку всего документа (как горизонтальную, так и вертикальную).
     Все, что выходит за пределы окна просмотра, будет обрезано и не будет скроллиться. */
  overflow: hidden; 
  /* Убеждаемся, что HTML и Body занимают всю доступную высоту и ширину.
     width: 100% здесь гарантирует, что они не будут шире viewport. */
  height: 100%;
  width: 100%; 
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--dark-bg);
  color: var(--text-primary);
  display: flex;
  justify-content: center; /* Центрируем содержимое по горизонтали */
  align-items: center; /* Центрируем содержимое по вертикали */
  min-height: 100dvh; /* Минимальная высота viewport для вертикального центрирования */
}

/* --- Новый элемент для баланса вверху справа --- */
.top-balance-display {
  position: absolute; /* Позиционирование относительно .app-container */
  top: 5px;
  right: 5px;
  background-color: var(--dark-surface); /* Использован основной фон для контраста */
  padding: 5px 10px;
  border-radius: 20px; /* Скругленные углы */
  display: flex; /* Flexbox для выравнивания содержимого */
  flex-direction: row; /* Явно указываем направление */
  justify-content: center; /* Центрируем содержимое по горизонтали внутри flex-контейнера */
  align-items: center; /* Выравнивание элементов по центру по вертикали */
  gap: 5px;
  font-size: 20px; /* Размер шрифта */
  font-weight: bold; /* Жирный шрифт */
  color: var(--text-primary); /* Цвет текста */
  z-index: 40; /* ИСПРАВЛЕНО: Установили z-index ниже, чем у profileScreen (50) */

  /* Начальные состояния для анимации видимости (скрыто по умолчанию) */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease; /* Плавное появление/исчезание */
}

.top-balance-display.visible {
  opacity: 1;
  visibility: visible;
}

.top-current-stars {
  white-space: nowrap; /* Запрещаем перенос строки для баланса */
}

.top-delta-stars {
  position: absolute; /* Дельта будет двигаться относительно родительского элемента (.top-balance-display) */
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  font-size: 16px;
  font-weight: bold;
  opacity: 0;
  transition: opacity 0.5s ease-out, transform 0.5s ease-out;
  white-space: nowrap;
}

/* Цвет для положительного изменения (выигрыша) */
.top-delta-stars.positive {
  color: var(--secondary-gold);
}

/* Класс для запуска анимации дельты */
.top-delta-stars.animate-in {
  opacity: 1;
  transform: translateY(-80%);
}

/* --- ЭКРАН АВТОРИЗАЦИИ --- */
.auth-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.auth-form-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.auth-icon {
  width: 100px;
  height: 100px;
  margin-bottom: 20px;
  filter: invert(1) drop-shadow(0 0 5px rgba(255, 255, 255, 0.3));
}

#authTitle {
  font-size: 24px;
  font-weight: 600;
  margin: 0;
}

#authForm {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

#authForm input {
  background-color: var(--dark-surface);
  border: 1px solid var(--dark-border);
  border-radius: 12px;
  padding: 15px;
  font-size: 16px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

#authForm input:focus {
  border-color: var(--primary-blue);
}

.auth-button {
  border: none;
  border-radius: 12px;
  padding: 15px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.1s ease, opacity 0.2s;
}
.auth-button:active {
  transform: scale(0.98);
}

.auth-button.primary {
  background-color: var(--primary-blue);
  color: white;
}

.auth-button.secondary {
  background: linear-gradient(145deg, #f0c14b, #D4AF37);
  color: #111;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.error-message {
  color: #ff3b30;
  text-align: center;
  margin: 0;
  min-height: 20px;
  opacity: 0;
  transition: opacity 0.3s;
}
.error-message.visible {
  opacity: 1;
}


/* --- ОСНОВНОЕ ПРИЛОЖЕНИЕ --- */
.app-container {
  width: 100%; /* Убедимся, что он занимает максимум доступного пространства, но не более max-width */
  max-width: 400px;
  background-color: var(--dark-bg);
  border-radius: 20px;
  overflow: hidden; 
  position: relative; /* Убедимся, что это родительский контекст для absolute потомков */
  height: 610px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 0 1px #0a0a0a;

  /* Сдвигаем весь app-container чуточку вниз */
  transform: translateY(10px); 
}

.screen {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  overflow-y: auto; /* Включаем вертикальный скролл, если контент не помещается */
  padding-top: 80px;
  /* scrollbar-width: none; */
  /* -ms-overflow-style: none; */
}
/* .screen::-webkit-scrollbar {
  display: none;
} */

/* Экран профиля, который накладывается поверх игрового */
#profileScreen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%; /* Ширина 100% от app-container */
  height: calc(100% - 60px);
  background-color: var(--dark-bg);
  transform: translateX(100%); 
  transition: transform 0.35s ease-in-out;
  z-index: 50;
}

#profileScreen.active {
  transform: translateX(0);
}

/* Обертка для карусели, содержит указатель */
.item-carousel-wrapper {
  height: 180px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: -10px; /* Сдвинуто выше по предыдущим запросам */
  border-bottom: none;
  padding: 30px 0;
  box-sizing: content-box;
  z-index: 1;
}

/* Контейнер карусели, который будет двигаться */
.item-carousel {
  display: flex;
  gap: 20px;
  position: absolute;
  left: 0;
  margin-top: 0;
  z-index: 2;
}

.carousel-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 120px;
  height: 120px;
  background-color: var(--dark-surface);
  border-radius: 15px;
  padding: 15px 10px;
  box-sizing: border-box;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.6);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.carousel-item.winning-item {
  box-shadow: 0 0 50px 20px rgba(0, 122, 255, 1), 0 0 20px rgba(0, 122, 255, 0.8) inset;
  transform: scale(1.15);
  transition: box-shadow 0.3s ease-out, transform 0.3s ease-out;
  z-index: 2;
}
.carousel-item .emoji {
  font-size: 70px;
  line-height: 1;
  margin-bottom: 10px;
}
.carousel-item .payout-value {
  font-size: 14px;
  font-weight: bold;
  color: var(--text-secondary);
}

.pointer {
  position: absolute;
  left: 50%;
  transform: translateX(-50%); /* Оставляем только горизонтальное центрирование */
  /* НОВОЕ ИСПРАВЛЕНИЕ: Опустили указатель еще на 5px ниже */
  top: 60px; 
  height: 130px;
  width: 2px;
  background-color: var(--primary-blue);
  z-index: 5;
}

.demo-mode-section, .prizes-section {
  padding-left: 20px;
  padding-right: 20px;
}
.demo-mode-section {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 15px;
  padding-bottom: 15px;
  margin-top: 5px;
}

.spin-button {
  background-color: var(--primary-blue);
  color: white;
  border: none;
  border-radius: 15px;
  padding: 15px 20px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  margin: 0 20px 20px;
  transition: background-color 0.2s, opacity 0.2s;
  width: calc(100% - 40px);
}
.spin-button.free-mode { background-color: #34c759; }
.spin-button:disabled {
  background-color: var(--dark-surface);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.switch { position: relative; display: inline-block; width: 50px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #3a3a3c; transition: 0.4s; border-radius: 30px; }
.slider:before { position: absolute; content: ""; height: 22px; width: 22px; left: 4px; bottom: 4px; background-color: white; transition: 0.4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary-blue); }
input:checked + .slider:before { transform: translateX(20px); }

.prizes-section .section-title { font-size: 17px; font-weight: 600; margin-bottom: 15px; }
.prize-list {
  display: flex;
  overflow-x: auto; /* Горизонтальный скролл */
  scroll-snap-type: x mandatory;
  gap: 15px;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  /* scrollbar-width: none; */
  /* -ms-overflow-style: none; */
}
/* .prize-list::-webkit-scrollbar {
  display: none;
} */


.prize-card {
  flex: 0 0 auto;
  background-color: var(--dark-surface);
  border-radius: 15px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  min-width: 120px;
  scroll-snap-align: start;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.prize-card .probability { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.prize-card .probability::after { content: ' ⭐'; font-size: 10px; vertical-align: super; }
.prize-card .prize-icon { font-size: 40px; margin-bottom: 8px; }
.prize-card .prize-value { font-size: 15px; font-weight: 500; color: var(--text-secondary); }
.rare-tag {
  position: absolute;
  top: 5px;
  right: 5px;
  background-color: #ff3b30;
  color: white;
  font-size: 9px;
  font-weight: bold;
  padding: 2px 5px;
  border-radius: 5px;
  transform: rotate(15deg);
  z-index: 4;
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(5px);
}
.modal-overlay.visible { opacity: 1; visibility: visible; }
.modal {
  background-color: var(--dark-bg);
  border-radius: 20px;
  padding: 30px;
  text-align: center;
  box-shadow: 0 0 30px rgba(0,122,255,0.5);
  transform: scale(0.9);
}
.modal-overlay.visible .modal { transform: scale(1); }
.modal p { font-size: 20px; font-weight: 600; margin: 0; white-space: nowrap; }
.won-item-modal { font-size: 100px; line-height: 1; }
.modal-close-button {
  background-color: var(--dark-surface);
  color: var(--text-primary);
  border: 1px solid var(--dark-border);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 10px;
  transition: background-color 0.2s;
}
.modal-close-button:hover {
  background-color: var(--dark-border);
}

/* Профиль пользователя */
.profile-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: 20px;
  padding-right: 20px;
  padding-bottom: 120px;
}
.profile-avatar img { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; margin-bottom: 20px; border: 4px solid var(--dark-border); }
.profile-name { font-size: 20px; font-weight: 600; margin-bottom: 10px; }
.profile-balance { font-size: 17px; color: var(--text-secondary); margin-bottom: 30px; }
.profile-balance #userSparks { font-weight: bold; color: var(--secondary-gold); }
.inventory-section { width: 100%; margin-top: 20px; }
.inventory-title { font-size: 18px; font-weight: 600; margin-bottom: 15px; text-align: center; }
.inventory-list { list-style: none; padding: 0; margin: 0; }
.inventory-item { display: flex; align-items: center; background-color: var(--dark-surface); border-radius: 15px; padding: 15px; margin-bottom: 10px; box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
.inventory-item .item-icon { font-size: 50px; margin-right: 15px; flex-shrink: 0; }
.inventory-item .item-details { flex-grow: 1; }
.inventory-item .item-name { font-size: 16px; font-weight: 500; }
.inventory-item .item-payout { font-size: 14px; color: var(--text-secondary); }
.inventory-item .sell-button { background-color: #34c759; color: white; border: none; border-radius: 12px; padding: 8px 15px; font-size: 15px; cursor: pointer; transition: background-color 0.2s; font-weight: bold; margin-left: 15px; flex-shrink: 0; white-space: nowrap; }
.no-gifts-message { font-size: 16px; color: var(--text-secondary); text-align: center; margin-top: 30px; background-color: var(--dark-surface); border-radius: 15px; padding: 30px; line-height: 1.5; display: flex; flex-direction: column; align-items: center; list-style: none; }
.no-gifts-message .folder-icon { font-size: 60px; margin-bottom: 15px; }

/* Кнопка "Обновить баланс" */
.refresh-button {
  background-color: var(--primary-blue);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  margin-top: 20px;
  transition: background-color 0.2s, opacity 0.2s;
}
.refresh-button:disabled {
  background-color: var(--dark-surface);
  color: var(--text-secondary);
  cursor: not-allowed;
}

.logout-button { background-color: #ff3b30; color: white; border: none; border-radius: 12px; padding: 10px 20px; font-size: 16px; font-weight: bold; cursor: pointer; margin-top: 15px; transition: background-color 0.2s; }

/* Нижняя навигация */
.bottom-nav {
  flex-shrink: 0;
  width: 100%;
  background-color: #1a1a1a;
  border-top: 1px solid var(--dark-border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -5px 10px rgba(0,0,0,0.3);
  z-index: 60;
  padding-top: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.nav-button { background: none; border: none; display: flex; flex-direction: column; align-items: center; color: var(--text-secondary); font-size: 12px; cursor: pointer; padding: 5px; flex: 1; }
.nav-button.active { color: var(--primary-blue); }
.nav-icon { font-size: 24px; margin-bottom: 3px; }
.nav-text { font-weight: 500; }