/* ============================================================
   Tarot Mini App — тёмный фэнтези-рестайл
   Референсы настроения: Diablo IV (мрак, золото на чёрном),
   Thronebreaker (живописные карты), Cosmic Wheel Sisterhood
   (мистика, фиолетовое свечение).
   Все эффекты — чистый CSS, ноль картинок в интерфейсе.
   ============================================================ */

:root {
  --bg-deep:   #07040f;             /* почти чёрный низ */
  --bg-mid:    #150b2a;             /* фиолетовая глубина */
  --ink:       #efe6d8;             /* тёплый светлый текст */
  --ink-dim:   rgba(239, 230, 216, 0.62);
  --gold:      #d8a948;             /* старое золото */
  --gold-soft: rgba(216, 169, 72, 0.45);
  --gold-faint:rgba(216, 169, 72, 0.18);
  --violet:    #8b5cf6;             /* магическое свечение */
  --violet-soft: rgba(139, 92, 246, 0.35);
  --panel:     rgba(21, 12, 40, 0.55);
  --serif: "Cormorant", Georgia, serif;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, system-ui, sans-serif;
  background: var(--bg-deep);
  color: var(--ink);
  overflow-x: hidden;
}

/* Фон: два слоя свечения + виньетка. fixed — не едет при скролле */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, rgba(139, 92, 246, 0.28), transparent 60%),
    radial-gradient(ellipse 70% 40% at 50% 110%, rgba(216, 110, 48, 0.12), transparent 60%),
    radial-gradient(ellipse 120% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.55) 100%),
    linear-gradient(180deg, var(--bg-mid), var(--bg-deep) 70%);
}

/* Звёздная пыль: точки рисуются тенями одного псевдоэлемента */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(239,230,216,.5), transparent 100%),
    radial-gradient(1px 1px at 78% 9%,  rgba(239,230,216,.35), transparent 100%),
    radial-gradient(1.5px 1.5px at 64% 31%, rgba(216,169,72,.4), transparent 100%),
    radial-gradient(1px 1px at 31% 44%, rgba(239,230,216,.3), transparent 100%),
    radial-gradient(1px 1px at 89% 52%, rgba(139,92,246,.45), transparent 100%),
    radial-gradient(1.5px 1.5px at 8% 67%,  rgba(239,230,216,.3), transparent 100%),
    radial-gradient(1px 1px at 47% 79%, rgba(216,169,72,.35), transparent 100%),
    radial-gradient(1px 1px at 70% 91%, rgba(239,230,216,.4), transparent 100%);
  animation: twinkle 7s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }

/* ---------- Экраны ---------- */
.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 28px 20px;
  box-sizing: border-box;
  text-align: center;
  animation: screenIn 0.5s ease both;
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.hidden { display: none; }

.moon { font-size: 52px; filter: drop-shadow(0 0 18px var(--violet-soft)); }

h1 {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.04em;
  margin: 0;
  color: var(--ink);
  text-shadow: 0 0 24px rgba(139, 92, 246, 0.35);
}

.hint { margin: 0; color: var(--ink-dim); font-size: 15px; max-width: 320px; }
/* Дисклеймер: едва заметная строка, прижатая к самому низу экрана */
.disclaimer {
  margin-top: auto;      /* уезжает в низ flex-колонки экрана */
  padding-top: 14px;
  opacity: 0.22;
  font-size: 9px;
  letter-spacing: 0.08em;
}

/* ---------- Формы ---------- */
form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 330px;
}
label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  font-size: 13px;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
}
input, select, textarea {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--gold-faint);
  background: rgba(13, 8, 28, 0.8);
  color: var(--ink);
  font-size: 16px; /* 16px+ чтобы iPhone не зумил поле при фокусе */
  font-family: inherit;
  transition: border-color 0.25s, box-shadow 0.25s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold-soft);
  box-shadow: 0 0 0 1px var(--gold-faint), 0 0 18px rgba(216, 169, 72, 0.12);
}
textarea { resize: none; }

/* ---------- Кнопки: орнаментная плашка (арт), сборка из 3 частей ----------
   Края с камнями не растягиваются, середина — бесшовный тайл,
   поэтому рамка верна при любой ширине кнопки. */
button {
  height: 54px;
  padding: 0 56px; /* не наезжать текстом на камни по краям */
  border: none;
  border-radius: 6px;
  background:
    url("btn/left.webp") left center / auto 100% no-repeat,
    url("btn/right.webp") right center / auto 100% no-repeat,
    url("btn/mid.webp") left center / auto 100% repeat-x;
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  cursor: pointer;
  filter: drop-shadow(0 0 10px rgba(139, 92, 246, 0.25));
  transition: filter 0.25s, transform 0.15s, opacity 0.25s;
}
button:active {
  transform: translateY(1px);
  filter: drop-shadow(0 0 16px rgba(216, 169, 72, 0.45));
}
button:disabled { opacity: 0.55; }

/* Вторичные кнопки — без плашки, тихие */
button.secondary {
  height: auto;
  padding: 12px 18px;
  background: transparent;
  border: 1px solid var(--gold-faint);
  border-radius: 8px;
  color: var(--ink-dim);
  font-weight: 400;
  filter: none;
  width: 100%;
  max-width: 330px;
}
button.secondary:active { border-color: var(--gold-soft); color: var(--ink); }

/* Хрустальный шар на главном экране: чёткий, без свечения, только парение */
.orb {
  width: 150px;
  animation: orbFloat 5.5s ease-in-out infinite;
}
@keyframes orbFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-7px); }
}

/* ============================================================
   КАРТЫ
   ============================================================ */
.cards {
  display: flex;
  gap: 12px;
  justify-content: center;
  perspective: 900px;
}

/* Карта крупнее прежнего: до 132px шириной, пропорция таро 2:3 */
.card {
  width: clamp(96px, 28vw, 132px);
  aspect-ratio: 2 / 3;
  perspective: 700px;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.9s cubic-bezier(0.25, 0.1, 0.2, 1);
  transform-style: preserve-3d;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 9px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

/* Рубашка: тёмный узор + золотая кайма + тлеющий глиф.
   Заменится файлом cards/back.webp, когда он появится */
.card-back {
  border: 1px solid var(--gold-soft);
  background:
    radial-gradient(circle at 50% 50%, rgba(139, 92, 246, 0.22), transparent 65%),
    repeating-conic-gradient(from 45deg at 50% 50%,
      #1b1135 0deg 22.5deg, #150b2a 22.5deg 45deg);
  box-shadow: inset 0 0 0 3px #0d0820, inset 0 0 0 4px var(--gold-faint);
  font-size: 30px;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(216, 169, 72, 0.8);
  background-size: cover;
  background-position: center;
}
.card-back .back-glyph { animation: glyphPulse 2.4s ease-in-out infinite; }
@keyframes glyphPulse {
  0%, 100% { opacity: 0.65; transform: scale(1); }
  50%      { opacity: 1;    transform: scale(1.12); }
}

/* Лицо карты */
.card-front {
  transform: rotateY(180deg);
  border: 1px solid var(--gold-soft);
  background: linear-gradient(165deg, #34225c, #170d2e 80%);
  box-shadow: inset 0 0 0 3px #0d0820, inset 0 0 0 4px var(--gold-faint);
  justify-content: flex-end;
}

/* Арт карты: подхватится автоматически, если файл cards/{id}.webp есть */
.card-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Заглушка (пока арта нет): крупный символ в свечении */
.card-front .card-emoji {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 40px;
  filter: drop-shadow(0 0 12px var(--violet-soft));
}
.card-front.has-art .card-emoji { display: none; }

/* Имя карты: плашка с градиентом поверх нижнего края арта */
.card-name {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 26px 6px 8px;
  box-sizing: border-box;
  background: linear-gradient(180deg, transparent, rgba(7, 4, 15, 0.88) 55%);
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  line-height: 1.2;
  color: var(--ink);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
.card-reversed-label {
  position: relative;
  z-index: 1;
  padding-bottom: 7px;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--gold);
  opacity: 0.85;
  background: rgba(7, 4, 15, 0.88);
  width: 100%;
}
.card-front.reversed .card-art,
.card-front.reversed .card-emoji { transform: rotate(180deg); }
.card-front.reversed .card-emoji { transform: translate(-50%, -50%) rotate(180deg); }

/* Появление карт: всплывают из тьмы с разлётом */
.card-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: cardArrive 0.7s ease both;
}
.card-wrap:nth-child(1) { animation-delay: 0.05s; }
.card-wrap:nth-child(2) { animation-delay: 0.2s; }
.card-wrap:nth-child(3) { animation-delay: 0.35s; }
@keyframes cardArrive {
  from { opacity: 0; transform: translateY(26px) scale(0.92); }
  to   { opacity: 1; transform: none; }
}

/* Вспышка-свечение в момент переворота */
.card.flipped { animation: revealGlow 1.6s ease 0.25s; }
@keyframes revealGlow {
  0%   { filter: drop-shadow(0 0 0 transparent); }
  35%  { filter: drop-shadow(0 0 26px rgba(216, 169, 72, 0.55)); }
  100% { filter: drop-shadow(0 0 10px rgba(139, 92, 246, 0.25)); }
}
.card.flipped { filter: drop-shadow(0 0 10px rgba(139, 92, 246, 0.25)); }

.card-position {
  margin-top: 9px;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.8;
}

/* Вопрос над раскладом */
#reading-question {
  font-family: var(--serif);
  font-style: italic;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
  text-shadow: 0 0 18px rgba(139, 92, 246, 0.35);
  max-width: 340px;
}

/* ---------- Толкование ---------- */
.interpretation {
  max-width: 350px;
  padding: 18px 20px;
  border-radius: 10px;
  border: 1px solid var(--gold-faint);
  background: var(--panel);
  backdrop-filter: blur(8px);
  font-size: 15px;
  line-height: 1.65;
  text-align: left;
  white-space: pre-wrap;
  opacity: 0;
  transition: opacity 1.4s;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.35);
}
.interpretation.visible { opacity: 1; }

/* ---------- История ---------- */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: 100%;
  max-width: 340px;
}
.history-item {
  height: auto;
  text-align: left;
  padding: 13px 14px;
  border-radius: 9px;
  border: 1px solid var(--gold-faint);
  background: var(--panel);
  color: var(--ink);
  font-size: 14px;
  font-weight: 400;
  letter-spacing: normal;
  filter: none;
}
.history-item:active { border-color: var(--gold-soft); }
.history-item .h-date { font-size: 11px; color: var(--ink-dim); margin-top: 4px; }

/* ---------- Кризисный экран ---------- */
.crisis-text { max-width: 320px; font-size: 16px; line-height: 1.65; }

/* ---------- Лайтбокс: карта на весь экран по тапу ---------- */
.card.flipped { cursor: pointer; }

#lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
  background: rgba(4, 2, 10, 0.92); /* без blur — бережём слабые андроиды */
  animation: lbIn 0.25s ease;
}
#lightbox.hidden { display: none; }
@keyframes lbIn { from { opacity: 0; } to { opacity: 1; } }

#lb-card {
  /* почти весь экран: упирается либо в ширину, либо в высоту (минус подпись) */
  width: min(94vw, 84vh * 2 / 3);
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--gold-soft);
  box-shadow:
    inset 0 0 0 3px #0d0820, inset 0 0 0 4px var(--gold-faint),
    0 0 50px rgba(139, 92, 246, 0.35);
  animation: lbCard 0.3s ease;
  position: relative;
}
@keyframes lbCard {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
#lb-art { width: 100%; height: 100%; object-fit: cover; display: block; }
#lb-art.hidden { display: none; }

/* Фолбэк, если арта у карты ещё нет */
#lb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 90px;
  background: linear-gradient(165deg, #34225c, #170d2e 80%);
  filter: drop-shadow(0 0 24px var(--violet-soft));
}
#lb-fallback.hidden { display: none; }

#lb-caption {
  /* подпись прижата к низу экрана, карте не мешает */
  position: fixed;
  bottom: 10px;
  left: 0;
  width: 100%;
  text-align: center;
  font-family: var(--serif);
  font-size: 18px;
  color: var(--ink);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 16px rgba(139, 92, 246, 0.5);
}
#lb-caption .lb-sub {
  display: block;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.85;
  margin-top: 4px;
}

.lb-arrow {
  /* стрелки поверх краёв карты — не отнимают ширину у самой карты */
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 61;
  height: auto;
  background: none;
  border: none;
  filter: none;
  color: var(--gold);
  font-size: 44px;
  padding: 14px 10px;
  opacity: 0.85;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.9);
}
#lb-prev { left: 0; }
#lb-next { right: 0; }
.lb-arrow:disabled { opacity: 0.12; }

/* ---------- Вуаль: затемнение, пока карты тасуются ---------- */
#veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 2, 10, 0.82);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s;
}
#veil.active { opacity: 1; pointer-events: auto; }
#veil .veil-glyph {
  font-size: 56px;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(216, 169, 72, 0.7);
  animation: veilSpin 2.6s ease-in-out infinite;
}
@keyframes veilSpin {
  0%, 100% { transform: rotate(-8deg) scale(1);   opacity: 0.75; }
  50%      { transform: rotate(8deg)  scale(1.15); opacity: 1; }
}
