* { box-sizing: border-box; }

:root {
  /* Адаптивные цвета для рулетки */
  --roulette-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --roulette-border: var(--tg-theme-hint-color, rgba(0, 0, 0, 0.1));
  --roulette-segment-1: color-mix(in srgb, var(--tg-theme-bg-color, #ffffff) 90%, var(--tg-theme-text-color, #000) 10%);
  --roulette-segment-2: color-mix(in srgb, var(--tg-theme-bg-color, #ffffff) 80%, var(--tg-theme-text-color, #000) 20%);
  --roulette-pointer: var(--tg-theme-button-color, #5488ff);
  --text-hint: var(--tg-theme-hint-color, rgba(0, 0, 0, 0.5));
  --card-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --border: var(--tg-theme-hint-color, rgba(0, 0, 0, 0.1));
  --toast-bg: color-mix(in srgb, var(--tg-theme-bg-color, #ffffff) 80%, var(--tg-theme-text-color, #000) 20%);
}

body {
  padding-bottom: 60px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  margin: 0;
  padding: 12px;
  background: var(--tg-theme-bg-color, #ffffff);
  color: var(--tg-theme-text-color, #000);
  min-height: 100vh;
}

button {
  background: var(--tg-theme-button-color, #5488ff);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  transition: transform 0.1s, background 0.2s, box-shadow 0.2s;
  padding: 14px 24px;
  font-size: 18px;
}
button:hover:not(:disabled) { filter: brightness(1.1); box-shadow: 0 8px 26px rgba(0, 0, 0, 0.15); }
button:active:not(:disabled) { transform: scale(0.96); }
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

#app { max-width: 400px; margin: 0 auto; }
.screen { display: block; }
.screen.hidden { display: none !important; }

/* Рулетка */
.wheel-wrap {
  margin: 16px auto 8px;
  max-width: 360px;
}

.wheel-title {
  margin: 0 0 16px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
}

.maintenance-banner {
  margin: 0 auto 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 222, 222, 0.95);
  border: 1px solid rgba(255, 100, 100, 0.8);
  color: #7a0e0e;
  text-align: center;
  font-weight: 600;
  line-height: 1.4;
}

.maintenance-banner.hidden { display: none; }

.roulette-container {
  position: relative;
  width: 100%;
  height: 250px;
  background: var(--roulette-bg);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  border: 2px solid var(--roulette-border);
}

.roulette-inner {
  position: absolute;
  inset: 16px;
  border-radius: 14px;
  overflow: hidden;
}

.roulette-pointer {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 100%;
  background: var(--roulette-pointer);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

.roulette-pointer::after {
  content: '▼';
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--roulette-pointer);
  font-size: 20px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.roulette-track {
  display: flex;
  height: 100%;
  align-items: center;
  will-change: transform;
}

#wheel-spins {
  text-align: center;
  margin: 8px 0 0;
  font-size: 14px;
  color: var(--text-hint);
}

#btn-spin {
  display: block;
  width: 100%;
  max-width: 200px;
  margin: 16px auto;
  padding: 14px 24px;
  font-size: 18px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  text-transform: uppercase;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
  transition: transform 0.1s, background 0.2s, box-shadow 0.2s;
}

#btn-spin:hover:not(:disabled) {
  filter: brightness(1.1);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.15);
}

#btn-spin:active:not(:disabled) {
  transform: scale(0.96);
}

#btn-spin:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.item-card {
  min-width: 140px;
  height: 200px;
  margin: 0 5px;
  background: var(--roulette-segment-1);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  font-weight: 500;
  font-size: 1rem;
  border: 1px solid var(--roulette-segment-2);
  padding: 12px 10px;
}

.item-img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin: 0;
  border-radius: 8px;
  background-color: #1a1a1a;
  flex-shrink: 0;
}

.item-card > div {
  margin-top: 0;
  text-align: center;
}

/* Список призов под рулеткой */
.wheel-prizes {
  margin-top: 20px;
  margin-bottom: 200px;
  width: 70vw;
  max-width: 70vw;
  margin-left: 50%;
  transform: translateX(-50%);
  padding: 0 8px;
}

.wheel-prizes-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  color: var(--tg-theme-text-color, #000);
}

/* Динамическая сетка */
.wheel-prizes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

/* Карточка */
.wheel-prize-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 10px;
  border-radius: 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  min-height: 110px; /* одинаковый минимальный размер */
}

/* Иконка */
.wheel-prize-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: 8px;
  border-radius: 8px; /* 8px как просили */
  overflow: hidden;
  background: rgba(0,0,0,0.04);
}

.wheel-prize-img {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

/* Текст переносится полностью */
.wheel-prize-name {
  width: 100%;
  line-height: 1.25;
  word-break: break-word;
}

.result {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
  background: var(--card-bg);
  text-align: center;
}
.result.hidden { display: none; }

.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tabs button { 
  padding: 8px 16px; 
  border-radius: 8px; 
  border: 1px solid var(--border); 
  background: transparent; 
  color: inherit; 
  cursor: pointer; 
}
.tabs button.active { 
  background: var(--tg-theme-button-color, #5488ff); 
  border-color: transparent; 
  color: var(--tg-theme-button-text-color, #fff);
}
.inventory-card {
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  background: var(--card-bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.inventory-card.expired { opacity: 0.6; }
.inventory-card button { 
  padding: 6px 12px; 
  border-radius: 6px; 
  border: none; 
  background: var(--tg-theme-button-color, #5488ff); 
  color: var(--tg-theme-button-text-color, #fff); 
  cursor: pointer; 
}
.inventory-card button:disabled { opacity: 0.5; }
.empty { text-align: center; color: var(--text-hint); }
.ref-link { word-break: break-all; font-size: 14px; color: var(--text-hint); }
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 8px;
  background: var(--toast-bg);
  color: var(--tg-theme-text-color, #000);
  z-index: 100;
  transition: opacity 0.2s;
}
.toast.hidden { display: none; opacity: 0; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card-bg);
  padding: 8px 0;
  z-index: 50;
  border-top: 1px solid var(--border);
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px; /* расстояние между иконкой и текстом */
  flex: 1;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--text-hint);
  font-size: 14px;
  cursor: pointer;
}

.nav-btn.active {
  color: var(--tg-theme-button-color, #5488ff);
  font-weight: 600;
}
/* Тумблер уведомлений о бесплатном спине */
.notify-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px auto 4px;
  max-width: 360px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.notify-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.notify-slider {
  flex: 0 0 44px;
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--roulette-bg);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.2s;
}
.notify-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--tg-theme-bg-color, #fff);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}
.notify-toggle input:checked + .notify-slider {
  background: var(--tg-theme-button-color, #5488ff);
}
.notify-toggle input:checked + .notify-slider::after {
  transform: translateX(18px);
}
.notify-label {
  font-size: 14px;
  color: var(--text-hint);
  line-height: 1.3;
}

.wheel-hint {
  margin: 4px auto 10px;
  max-width: 360px;
  text-align: center;
  font-size: 13px;
  color: var(--text-hint);
  line-height: 1.4;
}

/* ===================== Модалка выигрыша ===================== */
.win-modal {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.win-modal.hidden { display: none; }

.win-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}

.win-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #000);
  border-radius: 24px;
  padding: 28px 22px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  animation: win-pop 0.4s cubic-bezier(0.18, 0.9, 0.3, 1.2);
}
@keyframes win-pop {
  0% { transform: scale(0.7); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.win-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  color: var(--tg-theme-hint-color, #888);
  font-size: 15px;
  line-height: 32px;
  box-shadow: none;
  text-transform: none;
}

.win-badge {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--tg-theme-hint-color, #888);
  margin-bottom: 10px;
}

.win-icon {
  font-size: 76px;
  line-height: 1;
  margin: 4px auto 12px;
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.win-icon-img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  border-radius: 16px;
}

.win-name {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 8px;
}
.win-ttl {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #888);
  margin-bottom: 18px;
  min-height: 16px;
}

.win-cta {
  width: 100%;
  margin: 0 0 10px;
  font-size: 17px;
}
.win-secondary {
  width: 100%;
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  color: var(--tg-theme-text-color, #000);
  box-shadow: none;
  font-size: 15px;
}
.win-secondary.hidden,
.win-invite.hidden { display: none; }

.win-invite {
  margin-top: 6px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.win-invite-text {
  font-size: 14px;
  line-height: 1.4;
  margin: 0 0 12px;
}
.win-invite-btns {
  display: flex;
  gap: 8px;
}
.win-invite-btns button {
  flex: 1;
  font-size: 13px;
  padding: 12px 8px;
  text-transform: none;
}

/* Редкий приз — золотое свечение и пульсация карточки */
.win-card.rare {
  background: linear-gradient(160deg,
    color-mix(in srgb, var(--tg-theme-bg-color, #fff) 82%, #FFD700 18%),
    var(--tg-theme-bg-color, #fff));
  box-shadow: 0 0 0 2px #FFD700, 0 0 40px rgba(255, 215, 0, 0.6),
    0 20px 60px rgba(0, 0, 0, 0.35);
  animation: win-pop 0.4s cubic-bezier(0.18, 0.9, 0.3, 1.2),
    rare-pulse 1.6s ease-in-out 0.4s infinite;
}
@keyframes rare-pulse {
  0%, 100% { box-shadow: 0 0 0 2px #FFD700, 0 0 30px rgba(255, 215, 0, 0.45), 0 20px 60px rgba(0, 0, 0, 0.35); }
  50% { box-shadow: 0 0 0 3px #FFE066, 0 0 55px rgba(255, 215, 0, 0.85), 0 20px 60px rgba(0, 0, 0, 0.35); }
}
.win-card.rare .win-badge { color: #C79200; }

/* Таймер бесплатной крутки + колокольчик */
.spin-timer-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 12px auto 4px;
  max-width: 360px;
}
.spin-timer {
  font-size: 13px;
  color: var(--text-hint);
  line-height: 1.3;
  text-align: center;
}
.notify-bell {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  font-size: 17px;
  line-height: 38px;
  box-shadow: none;
  text-transform: none;
}
.notify-bell.off { opacity: 0.55; }

/* Инвентарь: бейдж сгорания, статусы, пустое состояние */
.burn-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(235, 75, 75, 0.15);
  color: #EB4B4B;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  vertical-align: middle;
}
.inv-status { font-size: 18px; }
.inv-empty {
  text-align: center;
  padding: 40px 16px 20px;
}
.inv-empty.hidden { display: none; }
.inv-empty-emoji { font-size: 56px; margin-bottom: 8px; }
.inv-empty p { color: var(--text-hint); margin: 0 0 16px; }

/* ===================== Вкладка ТОП ===================== */
.nav-emoji { font-size: 22px; line-height: 24px; }

.top-ref-card {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
}
.top-ref-title { margin: 0 0 10px; font-size: 14px; line-height: 1.4; }
.top-ref-link {
  font-size: 12px;
  color: var(--text-hint);
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 10px;
  padding: 9px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 10px;
}
.top-ref-btns { display: flex; gap: 8px; }
.top-ref-btns button {
  flex: 1;
  font-size: 13px;
  padding: 11px 8px;
  text-transform: none;
}
.top-ref-note { margin: 10px 0 0; font-size: 13px; color: var(--text-hint); text-align: center; }

.top-tiles { display: flex; gap: 8px; margin-bottom: 16px; }
.top-tile {
  flex: 1;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 12px 6px;
  text-align: center;
}
.top-tile b { display: block; font-size: 22px; margin-bottom: 2px; }
.top-tile span { font-size: 11px; color: var(--text-hint); line-height: 1.2; display: block; }

.top-h { margin: 18px 0 6px; font-size: 16px; }
.top-prizes-note { margin: 0 0 10px; font-size: 12px; color: var(--text-hint); line-height: 1.4; }

.top-board { list-style: none; margin: 0 0 8px; padding: 0; }
.top-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 12px;
  margin-bottom: 4px;
  background: var(--card-bg);
  font-size: 14px;
}
.top-row.me {
  outline: 2px solid var(--tg-theme-button-color, #5488ff);
  font-weight: 700;
}
.top-row.top-empty { color: var(--text-hint); font-size: 13px; }
.top-pos { flex: 0 0 30px; text-align: center; }
.top-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-cnt { font-weight: 700; }
.top-me {
  margin: 4px 0 0;
  padding: 9px 12px;
  border-radius: 12px;
  background: var(--card-bg);
  outline: 2px solid var(--tg-theme-button-color, #5488ff);
  font-size: 14px;
  font-weight: 700;
}

.top-feed { list-style: none; margin: 0; padding: 0 0 20px; }
.feed-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.feed-text { flex: 1; line-height: 1.35; }
.feed-ago { flex: 0 0 auto; color: var(--text-hint); font-size: 11px; white-space: nowrap; }

/* ===================== Фаза 5 ===================== */
/* Safe area: нижняя навигация не перекрывается системной областью */
.bottom-nav { padding-bottom: env(safe-area-inset-bottom, 0px); }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }

.streak-row {
  margin: 6px auto 0;
  max-width: 360px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #EB4B4B;
}
.streak-row.hidden { display: none; }

.more-spins {
  display: block;
  margin: 10px auto 2px;
  background: transparent;
  color: var(--tg-theme-button-color, #5488ff);
  box-shadow: none;
  font-size: 14px;
  text-transform: none;
  padding: 8px 12px;
}

/* Шторка заданий */
.tasks-sheet { position: fixed; inset: 0; z-index: 9500; }
.tasks-sheet.hidden { display: none; }
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.sheet-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 78vh;
  overflow-y: auto;
  animation: sheet-up 0.25s ease-out;
}
@keyframes sheet-up {
  from { transform: translateY(40px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}
.sheet-title { margin: 0 0 12px; font-size: 18px; }

.tasks-streak {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.streak-num { font-weight: 800; font-size: 15px; margin-bottom: 4px; }
.streak-note { font-size: 13px; color: var(--text-hint); line-height: 1.4; }

.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.task-row.done { opacity: 0.65; }
.task-info { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 700; line-height: 1.3; }
.task-sub { font-size: 12px; color: var(--text-hint); margin-top: 2px; line-height: 1.3; }
.task-side { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; justify-content: flex-end; }
.task-reward { font-weight: 800; color: var(--tg-theme-button-color, #5488ff); }
.task-btn {
  font-size: 12px;
  padding: 8px 10px;
  text-transform: none;
  box-shadow: none;
}
.task-btn.open {
  background: var(--tg-theme-secondary-bg-color, #f0f0f0);
  color: var(--tg-theme-text-color, #000);
}
.task-done { font-size: 13px; color: var(--text-hint); }

/* Приз недели */
.wheel-prize-chip.featured {
  outline: 2px solid #FFD700;
  position: relative;
}
.featured-badge {
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: #FFD700;
  color: #5c4500;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 8px;
  white-space: nowrap;
}
