:root,
:root[data-astro-theme="polnoch"] {
  --bg: #12081f;
  --bg2: #1c0f30;
  --gold: #e6c675;
  --text: #f1e9ff;
  --muted: #b7a6d9;
  --card: #201133;
  --card-rgb: 32,17,51;
  --input-bg: rgba(21,10,36,0.75);
  --input-border: rgba(230,198,117,0.25);
  --accent: #7c4dff;
  --plasma-glow-a: #5a3fb0;
  --plasma-glow-b: #2a1560;
  --plasma-core: #e6c675;
  --plasma-core-bright: #fff3d6;
  --plasma-bolt: #c9b6ff;
  color-scheme: dark;
}

:root[data-astro-theme="abyss"] {
  --bg: #05060a;
  --bg2: #0a0d16;
  --gold: #4fe3c1;
  --text: #eaf6f2;
  --muted: #7f95a3;
  --card: #0d1420;
  --card-rgb: 13,20,32;
  --input-bg: rgba(3,5,10,0.75);
  --input-border: rgba(79,227,193,0.3);
  --accent: #1f8f7a;
  --plasma-glow-a: #0f3d38;
  --plasma-glow-b: #0a1a1f;
  --plasma-core: #4fe3c1;
  --plasma-core-bright: #d6fff4;
  --plasma-bolt: #6be3d6;
}

:root[data-astro-theme="eclipse"] {
  --bg: #0a0e1f;
  --bg2: #131a33;
  --gold: #c9d4f2;
  --text: #eef1ff;
  --muted: #8b93b8;
  --card: #151d3a;
  --card-rgb: 21,29,58;
  --input-bg: rgba(6,9,20,0.75);
  --input-border: rgba(159,178,255,0.3);
  --accent: #3f5cff;
  --plasma-glow-a: #26307a;
  --plasma-glow-b: #10152e;
  --plasma-core: #c9d4f2;
  --plasma-core-bright: #ffffff;
  --plasma-bolt: #9fb2ff;
}

:root[data-astro-theme="aurora"] {
  --bg: #f4f1fb;
  --bg2: #ece5fb;
  --gold: #b8862f;
  --text: #241a3d;
  --muted: #6b5d8a;
  --card: #ffffff;
  --card-rgb: 255,255,255;
  --input-bg: #f7f4ff;
  --input-border: rgba(124,77,255,0.35);
  --accent: #7c4dff;
  --plasma-glow-a: #c9b6ff;
  --plasma-glow-b: #ece5fb;
  --plasma-core: #b8862f;
  --plasma-core-bright: #fff3d6;
  --plasma-bolt: #9b7fe0;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { overflow-x: clip; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", Roboto, sans-serif;
  min-height: 100vh;
}
#app { position: relative; z-index: 1; max-width: 480px; margin: 0 auto; padding: 24px 20px calc(env(safe-area-inset-bottom, 0px) + 60px); }

.plasma-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}
.plasma-bg svg { width: min(120vw, 900px); height: min(120vw, 900px); opacity: 0.55; }
.plasma-bg .bolt { animation: bolt-flicker 2.4s infinite ease-in-out; }
.plasma-bg .bolt-a { animation-delay: 0s; }
.plasma-bg .bolt-b { animation-delay: 0.2s; }
.plasma-bg .bolt-c { animation-delay: 0.5s; }
.plasma-bg .bolt-d { animation-delay: 0.1s; }
.plasma-bg .bolt-e { animation-delay: 0.35s; }
.plasma-bg .bolt-f { animation-delay: 0.6s; }
.plasma-bg .bolt-g { animation-delay: 0.45s; }
@keyframes bolt-flicker {
  0%, 100% { opacity: 0.25; }
  20% { opacity: 0.95; }
  35% { opacity: 0.4; }
  55% { opacity: 0.9; }
  70% { opacity: 0.3; }
  85% { opacity: 0.8; }
}

h1, h2, h3 { font-weight: 600; margin: 0 0 8px; }
h1 { font-size: 26px; color: var(--gold); }
p { color: var(--muted); line-height: 1.5; }

.card {
  background: rgba(var(--card-rgb), 0.62);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(230,198,117,0.15);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 16px;
}

label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
input, select, textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  color: var(--text);
  font-family: inherit;
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
}
textarea { resize: vertical; min-height: 70px; }

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #b388ff);
  color: white;
  font-size: 16px;
  font-weight: 600;
  margin-top: 18px;
  cursor: pointer;
}
.btn.secondary { background: transparent; border: 1px solid var(--gold); color: var(--gold); }
.btn:disabled { opacity: 0.5; }

.choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
.choice {
  position: relative;
  padding: 13px 16px;
  border-radius: 14px;
  border: 1px solid var(--input-border);
  background: rgba(var(--card-rgb), 0.4);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  line-height: 1.3;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.choice:hover { border-color: var(--accent); transform: translateY(-1px); }
.choice.active {
  background: linear-gradient(135deg, var(--accent), var(--gold));
  color: #14081f;
  font-weight: 700;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
  transform: translateY(-1px);
}
.choice.active::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 11px;
  font-weight: 700;
}

.tarot-row { display: flex; gap: 10px; justify-content: center; margin: 18px 0; }
.tarot-row > div { flex: 1; max-width: 120px; }
/* Карта: рубашка + лицо, переворот через rotateY. */
.tarot-card { width: 100%; aspect-ratio: 3 / 5; perspective: 900px; }
.tarot-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.7s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.tarot-card.flipped .tarot-inner { transform: rotateY(180deg); }
.tarot-back, .tarot-face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 8px;
}
.tarot-face { transform: rotateY(180deg); gap: 10px; }
.tarot-glyph { font-size: 26px; line-height: 1; font-family: Georgia, "Times New Roman", serif; }
.tarot-glyph.rev { transform: rotate(180deg); }
.tarot-name {
  font-size: 12.5px; line-height: 1.25;
  hyphens: auto; -webkit-hyphens: auto; overflow-wrap: anywhere;
}
.tarot-label { text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px; }
.tarot-rev { text-align: center; font-size: 11px; color: #ff6b8a; margin-top: 2px; }

/* Стиль «Классика» */
.deck-classic .tarot-back {
  border: 1px solid var(--gold);
  background:
    radial-gradient(circle at 50% 50%, rgba(230,198,117,0.25) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(230,198,117,0.12) 0 2px, transparent 2px 10px),
    linear-gradient(160deg, #2a1548, #150a24);
  color: var(--gold); font-size: 22px;
}
.deck-classic .tarot-face {
  border: 1px solid var(--gold);
  background: linear-gradient(160deg, #2a1548, #150a24);
  color: var(--gold);
}

/* Стиль «Мистик» — тёмная карта со свечением */
.deck-mystic .tarot-back, .deck-mystic .tarot-face {
  background: radial-gradient(circle at 50% 35%, #1d1238, #07040d 70%);
  border: 1px solid rgba(179,136,255,0.6);
  box-shadow: 0 0 18px rgba(124,77,255,0.45), inset 0 0 22px rgba(124,77,255,0.25);
  color: #d9c8ff;
}
.deck-mystic .tarot-back { font-size: 26px; text-shadow: 0 0 10px #b388ff; }
.deck-mystic .tarot-glyph { text-shadow: 0 0 12px #b388ff; }

/* Стиль «Минимал» — чёрно-белые линии, как у Co-Star */
.deck-minimal .tarot-back, .deck-minimal .tarot-face {
  background: #0b0b0b;
  border: 1px solid #f2f2f2;
  color: #f2f2f2;
}
.deck-minimal .tarot-back { font-size: 18px; outline: 1px solid #f2f2f2; outline-offset: -7px; }
.deck-minimal .tarot-name { text-transform: uppercase; letter-spacing: 0.06em; font-size: 10.5px; }
:root[data-astro-theme="aurora"] .deck-minimal .tarot-back,
:root[data-astro-theme="aurora"] .deck-minimal .tarot-face { background: #fff; border-color: #111; color: #111; outline-color: #111; }

.loading { text-align: center; color: var(--muted); padding: 30px 0; }

#topbar {
  position: relative;
  z-index: 2;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.pill-bar { display: flex; gap: 6px; }
.pill-bar .pill {
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--muted);
  border: 1px solid rgba(230,198,117,0.25);
  cursor: pointer;
}
.pill-bar .pill.active { background: var(--accent); color: white; border-color: transparent; }
.pill-bar .swatch {
  width: 20px; height: 20px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.pill-bar .swatch[data-theme="polnoch"] { background: linear-gradient(135deg, #7c4dff, #e6c675); }
.pill-bar .swatch[data-theme="abyss"] { background: linear-gradient(135deg, #0d1420, #4fe3c1); }
.pill-bar .swatch[data-theme="eclipse"] { background: linear-gradient(135deg, #151d3a, #9fb2ff); }
.pill-bar .swatch[data-theme="aurora"] { background: linear-gradient(135deg, #f4f1fb, #b8862f); }
.pill-bar .swatch.active { border-color: var(--gold); }
.tabs {
  display: flex;
  width: 100vw;
  margin: 0 calc(50% - 50vw) 20px;
  border-bottom: 1px solid rgba(var(--card-rgb), 0.9);
}
.tab {
  flex: 1 1 auto;
  white-space: nowrap;
  text-align: center;
  padding: 14px 8px;
  font-size: clamp(12px, 3.6vw, 14px);
  background: rgba(var(--card-rgb), 0.5);
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
  border-bottom: 2px solid transparent;
}
.tab.active { background: rgba(var(--card-rgb), 0.9); color: var(--gold); border-bottom-color: var(--accent); }

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
}
.seg {
  flex: 1;
  text-align: center;
  padding: 10px 6px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg.active { background: linear-gradient(135deg, var(--accent), var(--gold)); color: #14081f; }
.card textarea { margin-top: 12px; }

.reading { color: var(--text); margin: 0; }

.do-dont { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dd { padding: 14px 16px; margin-bottom: 16px; border-top: 3px solid transparent; }
.dd h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.dd.do { border-top-color: var(--gold); }
.dd.do h3 { color: var(--gold); }
.dd.dont { border-top-color: #ff6b8a; }
.dd.dont h3 { color: #ff6b8a; }
.dd-list { list-style: none; margin: 0; padding: 0; }
.dd-list li { color: var(--text); font-size: 14px; line-height: 1.35; padding: 6px 0; border-bottom: 1px solid var(--input-border); }
.dd-list li:last-child { border-bottom: none; }

.history-item { margin-bottom: 26px; }
.history-meta { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 4px 8px; }

.btn.small { width: auto; margin: 0; padding: 9px 14px; font-size: 14px; }
.icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: 22px; line-height: 1; padding: 4px 6px;
}
.icon-btn:hover { color: #ff6b8a; }

.person { display: flex; align-items: center; gap: 10px; padding: 14px 16px; margin-bottom: 10px; }
.person-info { flex: 1; min-width: 0; }
.person-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.compat-head { display: flex; align-items: center; gap: 18px; }
.compat-ring {
  --p: 0;
  flex: none;
  width: 84px; height: 84px; border-radius: 50%;
  background: conic-gradient(var(--gold) calc(var(--p) * 1%), var(--input-bg) 0);
  display: grid; place-items: center;
}
.compat-ring span {
  width: 68px; height: 68px; border-radius: 50%;
  background: rgba(var(--card-rgb), 1);
  display: grid; place-items: center;
  font-size: 20px; font-weight: 700; color: var(--gold);
}
.compat-names { font-size: 17px; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.compat-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.compat-param { padding: 8px 0; }
.compat-param + .compat-param { border-top: 1px solid var(--input-border); }
.compat-param-top { display: flex; justify-content: space-between; font-size: 14px; color: var(--text); font-weight: 600; }
.compat-bar { height: 6px; border-radius: 3px; background: var(--input-bg); margin-top: 7px; overflow: hidden; }
.compat-bar > div { height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--accent), var(--gold)); }
.compat-note { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
#compat-result { margin-top: 16px; }

/* Стиль «Гравюра» — тушь на старом пергаменте; картинки в cards/engraving/<номер>.jpg */
.deck-engraving .tarot-back, .deck-engraving .tarot-face {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,248,225,0.55), transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(90,60,25,0.35), transparent 55%),
    linear-gradient(160deg, #e9dcc0, #cdb88f);
  border: 1px solid #3b2a17;
  outline: 1px solid rgba(59,42,23,0.55);
  outline-offset: -6px;
  color: #2a1d10;
  overflow: hidden;
}
.deck-engraving .tarot-back { font-size: 24px; }
.deck-engraving .tarot-glyph { font-family: Georgia, "Times New Roman", serif; }
.deck-engraving .tarot-name { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.tarot-art {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
}
.tarot-art.rev { transform: rotate(180deg); }
.tarot-face.has-art { padding: 0; }
.tarot-face.has-art .tarot-glyph { display: none; }
.tarot-face.has-art .tarot-name {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1;
  padding: 5px 4px;
  background: rgba(233,220,192,0.92);
  border-top: 1px solid #3b2a17;
  font-size: 11px;
}
.deck-engraving .tarot-back {
  background: url("cards/engraving/back.jpg") center / cover no-repeat, linear-gradient(160deg, #e9dcc0, #cdb88f);
  outline: none;
}
.deck-engraving .tarot-back span { display: none; }

.demo-badge {
  font-size: 11.5px; line-height: 1.35;
  color: var(--gold);
  border: 1px dashed var(--input-border);
  border-radius: 8px;
  padding: 6px 9px;
  margin-bottom: 10px;
}
#btn-example { margin: 4px 0 18px; }

/* Выбор колоды: 5 вариантов не помещаются в строку на телефоне — сетка 3 + 2. */
.deck-picker .segmented { display: grid; grid-template-columns: repeat(3, 1fr); }

/* Стиль «Сказка» — цветные иллюстрации в золотой рамке */
.deck-fairytale .tarot-back, .deck-fairytale .tarot-face {
  background:
    radial-gradient(circle at 50% 50%, rgba(230,198,117,0.35) 0 14%, transparent 15%),
    repeating-conic-gradient(from 0deg at 50% 50%, rgba(230,198,117,0.18) 0 6deg, transparent 6deg 30deg),
    linear-gradient(160deg, #1b2447, #0d1330);
  border: 2px solid #c9a24a;
  outline: 1px solid rgba(201,162,74,0.6);
  outline-offset: -6px;
  color: #e6c675;
  overflow: hidden;
}
.deck-fairytale .tarot-back { font-size: 22px; }
.deck-fairytale .tarot-face.has-art { border-color: #c9a24a; outline: none; }
.deck-fairytale .tarot-face.has-art .tarot-name {
  background: rgba(13,19,48,0.9);
  border-top: 1px solid #c9a24a;
  color: #e6c675;
  font-family: Georgia, "Times New Roman", serif;
}

/* Стиль «Сепия» — сепийные версии карт друга; пока берёт рубашку и пергамент «Гравюры» */
.deck-sepia .tarot-back, .deck-sepia .tarot-face {
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,248,225,0.55), transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(90,60,25,0.35), transparent 55%),
    linear-gradient(160deg, #e9dcc0, #cdb88f);
  border: 1px solid #3b2a17;
  outline: 1px solid rgba(59,42,23,0.55);
  outline-offset: -6px;
  color: #2a1d10;
  overflow: hidden;
}
.deck-sepia .tarot-back {
  background: url("cards/engraving/back.jpg") center / cover no-repeat, linear-gradient(160deg, #e9dcc0, #cdb88f);
  outline: none;
}
.deck-sepia .tarot-back span { display: none; }
.deck-sepia .tarot-glyph, .deck-sepia .tarot-name { font-family: Georgia, "Times New Roman", serif; }
.deck-sepia .tarot-name { font-style: italic; }
.deck-sepia .tarot-face.has-art { outline: none; }
.deck-sepia .tarot-face.has-art .tarot-name {
  background: rgba(233,220,192,0.92);
  border-top: 1px solid #3b2a17;
}

/* ---------- Карта во весь экран ---------- */
.tarot-slot { cursor: pointer; border-radius: 12px; }
.tarot-slot:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
body.viewer-open { overflow: hidden; }
.viewer {
  position: fixed; inset: 0; z-index: 50;
  overflow-y: auto; overscroll-behavior: contain;
  background: rgba(var(--card-rgb), 0.97);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 32px);
  animation: viewer-in 0.2s ease-out;
}
@keyframes viewer-in { from { opacity: 0; transform: scale(0.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .viewer { animation: none; } }
.viewer-inner { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.viewer-close {
  position: sticky; top: 0; margin-left: auto; display: block; z-index: 2;
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--input-border); background: rgba(var(--card-rgb), 0.9);
  color: var(--text); font-size: 24px; line-height: 1; cursor: pointer;
}
.viewer-close:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.viewer-card { margin: 0; justify-content: center; }
.viewer-card > .tarot-card { flex: none; width: min(78vw, 380px); max-width: 100%; }
.viewer-card .tarot-name { font-size: 15px; }
.viewer-card .tarot-glyph { font-size: 44px; }
.viewer-title { text-align: center; font-size: 24px; color: var(--gold); margin: 6px 0 0; text-wrap: balance; }
.viewer-sub { text-align: center; color: var(--muted); font-size: 14px; }
.viewer-sub .tarot-rev { display: inline; }
.viewer-hint { text-align: center; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; margin-bottom: 4px; }
.viewer .card { margin-bottom: 0; }
.viewer .card h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); }
.viewer-note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }
