/* styles.css — кастомные стили, анимации, RTL и карточки редкости.
   Базовые цвета берём из палитры Telegram (тёмная) + акценты TON (сине-фиолетовые). */

:root {
  --bg:        #0e1621;   /* фон Telegram dark */
  --bg-2:      #17212b;   /* поверхности/шапка */
  --surface:   #1c2733;   /* карточки */
  --surface-2: #22303c;
  --text:      #eaf1f8;
  --muted:     #8aa0b3;
  --line:      #2a3947;

  /* Акценты TON */
  --ton:       #0098ea;   /* фирменный синий TON */
  --ton-2:     #7b61ff;   /* фиолетовый акцент */
  --grad:      linear-gradient(135deg, #0098ea 0%, #7b61ff 100%);

  /* Цвета редкости */
  --c-common:    #37c76a;
  --c-rare:      #3aa0ff;
  --c-epic:      #b061ff;
  --c-legendary: #ffca3a;
  --c-mythic:    #ff4d5e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Arabic", "Noto Sans Devanagari", sans-serif;
  overscroll-behavior-y: contain;
}

/* ---------- Прелоадер ---------- */
#preloader {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  transition: opacity .3s ease;
}
#preloader.hidden { opacity: 0; pointer-events: none; }
.spinner {
  width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--ton);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ---------- Каркас ---------- */
.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Шапка ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--grad);
  display: grid; place-items: center; font-size: 22px;
  box-shadow: 0 6px 18px rgba(123, 97, 255, .35);
}
.brand h1 { font-size: 17px; margin: 0; line-height: 1.1; font-weight: 700; }
.brand p  { font-size: 12px; margin: 2px 0 0; color: var(--muted); }

#lang-select {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 14px; outline: none;
}

#premium-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .3px;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(255, 202, 58, .15); color: var(--c-legendary);
  border: 1px solid rgba(255, 202, 58, .4);
}

/* ---------- Панель статистики ---------- */
.stats {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.stat {
  flex: 1 1 auto; min-width: 140px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px;
}
.stat .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat .value { font-size: 16px; font-weight: 700; margin-top: 4px; }

/* ---------- Карточка отмазки ---------- */
.excuse-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 18px;
  min-height: 130px;
  display: flex; flex-direction: column; justify-content: center; gap: 14px;
  transition: border-color .25s ease, box-shadow .25s ease;
}
.excuse-card #excuse-text {
  font-size: 19px; line-height: 1.45; font-weight: 600; margin: 0;
}
.excuse-card.rolling #excuse-text { opacity: .55; filter: blur(.3px); }
.excuse-card.revealed { animation: fade-in .35s ease; }

.excuse-meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta-pill {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
}

/* Подсветка карточки по редкости */
.rarity-common    { border-color: var(--c-common)   !important; box-shadow: 0 0 0 1px var(--c-common), 0 10px 30px rgba(55,199,106,.12); }
.rarity-rare      { border-color: var(--c-rare)     !important; box-shadow: 0 0 0 1px var(--c-rare), 0 10px 30px rgba(58,160,255,.14); }
.rarity-epic      { border-color: var(--c-epic)     !important; box-shadow: 0 0 0 1px var(--c-epic), 0 12px 34px rgba(176,97,255,.20); }
.rarity-legendary { border-color: var(--c-legendary)!important; box-shadow: 0 0 0 1px var(--c-legendary), 0 12px 40px rgba(255,202,58,.22); }
.rarity-mythic    { border-color: var(--c-mythic)   !important; box-shadow: 0 0 0 1px var(--c-mythic), 0 14px 44px rgba(255,77,94,.28); animation: pulse 1.4s ease-in-out infinite; }

/* ---------- Кнопки действий ---------- */
.excuse-actions { display: flex; gap: 10px; }
.excuse-actions .btn { flex: 1; }

.btn {
  appearance: none; border: none; cursor: pointer;
  font-size: 15px; font-weight: 600;
  padding: 14px 16px; border-radius: 14px;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line);
  transition: transform .08s ease, background .2s ease, opacity .2s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); border: none; color: #fff; box-shadow: 0 10px 26px rgba(0,152,234,.35); }
.btn.big { width: 100%; font-size: 17px; padding: 16px; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Легенда редкостей ---------- */
.rarity-legend { display: flex; flex-wrap: wrap; gap: 8px; }
.rarity-chip {
  font-size: 12px; padding: 5px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line);
}
.rarity-chip.rarity-common    { color: var(--c-common); }
.rarity-chip.rarity-rare      { color: var(--c-rare); }
.rarity-chip.rarity-epic      { color: var(--c-epic); }
.rarity-chip.rarity-legendary { color: var(--c-legendary); }
.rarity-chip.rarity-mythic    { color: var(--c-mythic); }

/* ---------- Секция монетизации ---------- */
.money-row { display: flex; gap: 10px; }
.money-row .btn { flex: 1; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.money-row .btn small { font-size: 11px; color: var(--muted); font-weight: 500; }

/* ---------- TON Connect ---------- */
.ton-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.ton-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.ton-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ton); }
#wallet-status { font-size: 13px; color: var(--muted); }
#ton-connect-button { display: flex; }

.section-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 4px 0 -4px; }

/* ---------- Нижние «шторки» (sheets) ---------- */
#sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  opacity: 0; pointer-events: none; transition: opacity .25s ease; z-index: 40;
}
#sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--bg-2); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  max-width: 520px; margin: 0 auto;
}
.sheet.open { transform: translateY(0); }
.sheet .grabber { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 0 auto 14px; }
.sheet h2 { font-size: 18px; margin: 0 0 6px; }
.sheet p  { font-size: 14px; color: var(--muted); margin: 0 0 16px; }
.sheet .feature-list { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sheet .feature-list li { font-size: 14px; display: flex; gap: 8px; align-items: center; }

.donate-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.donate-custom { display: flex; gap: 8px; }
.donate-custom input {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; color: var(--text); font-size: 15px; outline: none;
}

/* ---------- Анимации ---------- */
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse   { 0%,100% { box-shadow: 0 0 0 1px var(--c-mythic), 0 0 0 rgba(255,77,94,0); } 50% { box-shadow: 0 0 0 1px var(--c-mythic), 0 0 26px rgba(255,77,94,.5); } }

/* «Слот»-эффект лёгкого дрожания текста во время прокрутки */
.excuse-card.rolling #excuse-text { animation: slot-roll .12s linear infinite; }
@keyframes slot-roll { 0% { transform: translateY(-1px); } 50% { transform: translateY(1px); } 100% { transform: translateY(-1px); } }

/* ---------- RTL (арабский) ---------- */
[dir="rtl"] .brand { flex-direction: row-reverse; }
[dir="rtl"] .topbar { flex-direction: row-reverse; }
[dir="rtl"] .stat, [dir="rtl"] .excuse-card, [dir="rtl"] .sheet, [dir="rtl"] .ton-box { text-align: right; }
[dir="rtl"] .ton-head { flex-direction: row-reverse; }
[dir="rtl"] .donate-custom { flex-direction: row-reverse; }
[dir="rtl"] #excuse-text { direction: rtl; }

/* ---------- Доступность / уменьшенная анимация ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------- Фокус для клавиатуры ---------- */
.btn:focus-visible, #lang-select:focus-visible, input:focus-visible {
  outline: 2px solid var(--ton-2); outline-offset: 2px;
}

/* ---------- Мелкие экраны ---------- */
@media (max-width: 360px) {
  .excuse-card #excuse-text { font-size: 17px; }
  .stat { min-width: 120px; }
}
