:root {
  --bg: #120c24;
  --bg2: #1d1438;
  --card-back: #2a1d55;
  --gold: #e8c46a;
  --gold-soft: rgba(232, 196, 106, 0.25);
  --text: #f2ecff;
  --muted: #a99cc9;
  --danger: #ff8a8a;
  --radius: 14px;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%) fixed;
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
}

body { padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }

.stars {
  position: fixed; inset: 0; pointer-events: none; z-index: -1;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #fff8, transparent),
    radial-gradient(1px 1px at 70% 10%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 85% 60%, #fff7, transparent),
    radial-gradient(1px 1px at 40% 80%, #fff5, transparent),
    radial-gradient(1px 1px at 10% 70%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 55% 45%, #fff4, transparent);
}

h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: normal; letter-spacing: 0.5px; }
h1 { font-size: 40px; margin: 4px 0; color: var(--gold); }
h2 { font-size: 26px; margin: 8px 0 4px; color: var(--gold); text-align: center; }
.muted { color: var(--muted); text-align: center; margin: 4px 0 16px; }
.hidden { display: none !important; }

.screen { display: none; max-width: 560px; margin: 0 auto; animation: fade .35s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hero { text-align: center; padding: 16px 0 8px; }
.hero-moon { font-size: 44px; color: var(--gold); text-shadow: 0 0 24px var(--gold-soft); }

/* Кнопки раскладов */
.spreads { display: grid; gap: 12px; }
.spread-btn {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 16px; border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--gold-soft);
  color: var(--text); text-align: left; font: inherit; cursor: pointer;
  transition: transform .15s, background .15s;
}
.spread-btn:active { transform: scale(0.98); background: rgba(255, 255, 255, 0.09); }
.spread-icon { font-size: 30px; width: 40px; text-align: center; }
.spread-name { font-weight: 600; }
.spread-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.spread-btn.daily { border-color: var(--gold); background: linear-gradient(135deg, rgba(232,196,106,.15), rgba(255,255,255,.03)); }

button.primary, button.secondary {
  width: 100%; padding: 14px; border-radius: var(--radius);
  font: inherit; font-weight: 600; cursor: pointer; border: none;
}
button.primary { background: linear-gradient(135deg, #f0d184, #c99a3a); color: #2a1a00; }
button.secondary { background: transparent; color: var(--gold); border: 1px solid var(--gold-soft); }
button.primary:active, button.secondary:active { opacity: .85; }
.link-btn {
  display: block; margin: 20px auto 0; background: none; border: none;
  color: var(--gold); font: inherit; text-decoration: underline; cursor: pointer;
}
.disclaimer { color: var(--muted); font-size: 12px; text-align: center; opacity: .7; margin-top: 18px; }

/* Вопрос */
.ask { display: grid; gap: 10px; margin-bottom: 16px; }
textarea {
  width: 100%; resize: none; padding: 12px; border-radius: var(--radius);
  background: rgba(255,255,255,.06); color: var(--text);
  border: 1px solid var(--gold-soft); font: inherit;
}
textarea::placeholder { color: var(--muted); }
.question-shown { width: 100%; text-align: center; font-style: italic; color: var(--text); margin: 0 0 12px; }
.hint { margin-top: 0; }

/* Стол с картами */
.table { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin: 8px 0 20px; }
.slot { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 30%; max-width: 140px; min-width: 92px; }
.slot-label { font-size: 13px; color: var(--muted); text-align: center; min-height: 2.4em; }

.card { width: 100%; aspect-ratio: 0.58; perspective: 900px; cursor: pointer; }
.card-inner {
  position: relative; width: 100%; height: 100%;
  transition: transform .7s cubic-bezier(.2,.8,.2,1); transform-style: preserve-3d;
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; border-radius: 10px; backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 8px 6px; border: 2px solid var(--gold);
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.card-back {
  background:
    repeating-linear-gradient(45deg, transparent 0 8px, rgba(232,196,106,.08) 8px 9px),
    radial-gradient(circle at center, #3b2a78, var(--card-back));
  justify-content: center; color: var(--gold); font-size: 34px;
}
.card.dealt { animation: deal .5s ease backwards; }
@keyframes deal { from { opacity: 0; transform: translateY(-40px) rotate(-8deg); } }
.card:not(.flipped):hover .card-back { filter: brightness(1.15); }

.card-front {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #fbf3dc, #ecdcb0);
  color: #3a2560;
}
.card-front .num { font-family: Georgia, serif; font-size: 14px; font-weight: bold; }
.card-front .icon { font-size: 38px; line-height: 1; }
.card-front .name { font-size: 11px; text-align: center; font-weight: 600; line-height: 1.2; }
.card.reversed .card-front .icon { transform: rotate(180deg); }
.card.reversed .card-front { background: linear-gradient(180deg, #e9dcc0, #d6c08e); }

/* Толкование */
.result { display: grid; gap: 12px; margin-bottom: 16px; }
.meaning {
  padding: 14px; border-radius: var(--radius);
  background: rgba(255,255,255,.05); border-left: 3px solid var(--gold);
  animation: fade .4s ease backwards;
}
.meaning-pos { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.meaning-name { font-weight: 600; margin: 4px 0 6px; color: var(--gold); }
.meaning-name small { color: var(--muted); font-weight: normal; }
.meaning p { margin: 0; line-height: 1.45; }
.actions { display: grid; gap: 10px; }

/* История */
.history-item {
  padding: 12px 14px; border-radius: var(--radius); margin-bottom: 10px;
  background: rgba(255,255,255,.05); border: 1px solid var(--gold-soft);
}
.history-date { font-size: 12px; color: var(--muted); }
.history-title { font-weight: 600; margin: 2px 0; }
.history-q { font-style: italic; color: var(--muted); font-size: 14px; }
.history-cards { font-size: 14px; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); margin: 30px 0; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 20px;
  font-size: 14px; transition: .25s; pointer-events: none; max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Пустое место под карту ---------- */
.card.placeholder {
  border: 2px dashed var(--gold-soft); border-radius: 10px; cursor: default;
}

/* ---------- Веер для выбора карт ---------- */
.fan {
  position: relative; height: 170px; margin: 4px auto 20px; max-width: 420px;
}
.fan-card {
  position: absolute; left: 50%; bottom: 0; width: 64px; height: 110px; margin-left: -32px;
  border-radius: 8px; border: 2px solid var(--gold); color: var(--gold); font-size: 22px;
  background:
    repeating-linear-gradient(45deg, transparent 0 6px, rgba(232,196,106,.08) 6px 7px),
    radial-gradient(circle at center, #3b2a78, var(--card-back));
  box-shadow: 0 4px 12px rgba(0,0,0,.5);
  transform-origin: 50% 140%;
  transform: rotate(calc(var(--i) * 7deg));
  transition: transform .25s ease, opacity .3s ease;
  animation: fanIn .45s ease backwards;
  cursor: pointer; padding: 0;
}
.fan-card:hover, .fan-card:focus-visible { transform: rotate(calc(var(--i) * 7deg)) translateY(-14px); outline: none; }
.fan-card.taken { opacity: 0; transform: rotate(calc(var(--i) * 7deg)) translateY(-60px) scale(.8); pointer-events: none; }
@keyframes fanIn { from { opacity: 0; transform: rotate(0deg) translateY(30px); } }

/* ---------- ИИ-толкование ---------- */
.ai-block {
  padding: 16px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(232,196,106,.14), rgba(59,42,120,.35));
  border: 1px solid var(--gold); box-shadow: 0 0 24px rgba(232,196,106,.12);
  animation: fade .4s ease backwards;
}
.ai-title { font-family: Georgia, serif; color: var(--gold); font-size: 19px; margin-bottom: 8px; }
.ai-body p { margin: 0 0 10px; line-height: 1.55; animation: fade .5s ease backwards; }
.ai-body p:last-child { margin-bottom: 0; }
.ai-loading { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.ai-loading span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--gold);
  animation: pulse 1.2s infinite ease-in-out;
}
.ai-loading span:nth-child(2) { animation-delay: .2s; }
.ai-loading span:nth-child(3) { animation-delay: .4s; margin-right: 6px; }
@keyframes pulse { 0%, 80%, 100% { opacity: .2; transform: scale(.7); } 40% { opacity: 1; transform: scale(1); } }
.ai-block.ai-off { border-color: var(--gold-soft); box-shadow: none; background: rgba(255,255,255,.04); }
.ai-note { color: var(--muted); font-size: 14px; }
.meanings-title { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .5px; margin-top: 6px; }

.history-ai summary { cursor: pointer; color: var(--gold); font-size: 14px; margin-top: 6px; }
.history-ai div { white-space: pre-line; font-size: 14px; line-height: 1.45; margin-top: 6px; }
