/* Морана · Telegram Mini App
   Палитра по дизайну: Telegram dark + золото/фиолет/кремовый текст. */

:root {
  --bg: #17212b;
  --bg-elev: #1e2936;
  --bg-card: #232e3c;
  --bg-card-hi: #2b3544;
  --line: rgba(255,255,255,0.06);
  --line-strong: rgba(255,255,255,0.12);
  --text: #f3ecdf;
  --text-dim: rgba(243,236,223,0.62);
  --text-mute: rgba(243,236,223,0.4);
  --tg-blue: #3390ec;
  --tg-blue-dim: rgba(51,144,236,0.15);
  --accent: #6d5bd6;
  --accent-dim: rgba(109,91,214,0.22);
  --gold: #d4b37f;
  --gold-dim: rgba(212,179,127,0.22);
  --ring: rgba(212,179,127,0.35);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 15px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
  height: 100%; overflow: hidden;
}
button { font-family: inherit; }
a { color: inherit; }

#app {
  width: 100%; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--bg);
}

/* ---------- Header (Telegram Mini App style) ---------- */
.header {
  height: 56px; background: var(--bg);
  border-bottom: 0.5px solid var(--line);
  display: flex; align-items: center; padding: 0 12px;
  position: relative; z-index: 5; flex-shrink: 0;
}
.header__title-wrap {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
}
.header__title {
  font-size: 16px; font-weight: 600;
  color: var(--text); letter-spacing: 0.1px; line-height: 1.1;
}
.header__subtitle {
  font-size: 12px; color: var(--text-dim);
  margin-top: 2px; letter-spacing: 0.1px;
}
.header__icon {
  width: 36px; height: 36px;
  background: transparent; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #7d8b9b;
}
.header__spacer { flex: 1; }

/* ---------- MainButton ---------- */
.mainbutton-wrap {
  padding: 8px 8px 14px; background: var(--bg);
  border-top: 0.5px solid var(--line);
  flex-shrink: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
}
.mainbutton {
  width: 100%; height: 50px; border-radius: 12px; border: none;
  background: var(--tg-blue); color: #fff;
  font-size: 16px; font-weight: 600; letter-spacing: 0.1px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.mainbutton:disabled {
  background: var(--bg-card-hi); color: var(--text-mute); cursor: default;
}
.mainbutton.secondary {
  background: transparent; color: var(--tg-blue);
}

/* ---------- Free counter pill ---------- */
.counter-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(212, 179, 127, 0.08);
  border: 0.5px solid var(--ring);
  font-size: 12px; color: var(--gold); letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
}
.counter-pill.compact { padding: 4px 9px; font-size: 11px; }
.counter-pill svg { display: block; }

/* ---------- Nav chips ---------- */
.nav-chips {
  display: flex; gap: 6px; padding: 10px 12px;
  overflow-x: auto; background: var(--bg);
  border-bottom: 0.5px solid var(--line);
  flex-shrink: 0;
}
.nav-chips::-webkit-scrollbar { display: none; }
.nav-chip {
  padding: 7px 14px; border-radius: 16px;
  background: var(--bg-card); color: var(--text-dim);
  font-size: 13px; font-weight: 400;
  white-space: nowrap; letter-spacing: 0.1px;
  cursor: pointer; border: none;
}
.nav-chip.active {
  background: var(--tg-blue); color: #fff; font-weight: 600;
}

/* ---------- Viewport (between header and mainbutton) ---------- */
.viewport {
  flex: 1; overflow: hidden; position: relative;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.scroll {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.scroll::-webkit-scrollbar { width: 0; }

/* ---------- Onboarding ---------- */
.onb {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 28px; text-align: center;
}
.onb__glyph { margin-bottom: 28px; opacity: 0.95; }
.onb__name {
  font-family: var(--serif); font-weight: 400;
  font-size: 56px; line-height: 1;
  color: var(--gold); letter-spacing: 1px; margin-bottom: 14px;
}
.onb__sub {
  font-family: var(--serif); font-style: italic;
  font-size: 18px; color: var(--text-dim); margin-bottom: 36px;
  max-width: 280px; line-height: 1.4;
}
.onb__features {
  display: flex; flex-direction: column; gap: 14px;
  width: 100%; max-width: 320px; margin-bottom: 24px;
}
.onb__feature {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 12px;
  background: var(--bg-card); border: 0.5px solid var(--line-strong);
  text-align: left;
}
.onb__feature-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--gold-dim); color: var(--gold);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.onb__feature-text { font-size: 14px; color: var(--text); line-height: 1.35; }
.onb__feature-text small { display: block; color: var(--text-dim); font-size: 12px; margin-top: 2px; }

/* ---------- Chat ---------- */
.chat-top {
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--line);
  display: flex; justify-content: center; flex-shrink: 0;
}
.chat-list {
  flex: 1; overflow-y: auto; padding: 14px 12px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.chat-list::-webkit-scrollbar { width: 0; }
.bubble {
  max-width: 80%; padding: 9px 12px; border-radius: 16px;
  font-size: 15px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap;
}
.bubble--mor {
  background: var(--bg-card); align-self: flex-start;
  border-bottom-left-radius: 4px; color: var(--text);
}
.bubble--me {
  background: var(--tg-blue); align-self: flex-end;
  border-bottom-right-radius: 4px; color: #fff;
}
.bubble--sys {
  align-self: center; background: var(--gold-dim); color: var(--gold);
  font-size: 12px; padding: 6px 12px; border-radius: 12px;
  font-style: italic;
}
.bubble__time {
  display: block; font-size: 10px; color: var(--text-mute);
  margin-top: 4px; text-align: right; font-variant-numeric: tabular-nums;
}
.bubble--me .bubble__time { color: rgba(255,255,255,0.6); }

.chat-typing {
  align-self: flex-start; background: var(--bg-card);
  padding: 12px 14px; border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex; gap: 4px;
}
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-dim); animation: typing 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-quick {
  display: flex; gap: 8px; padding: 6px 12px 0;
  overflow-x: auto; flex-shrink: 0;
}
.chat-quick::-webkit-scrollbar { display: none; }
.chat-quick__chip {
  padding: 8px 14px; border-radius: 16px;
  background: var(--bg-card); border: 0.5px solid var(--line-strong);
  font-size: 13px; color: var(--text-dim); white-space: nowrap;
  cursor: pointer;
}

.chat-input {
  display: flex; gap: 8px; padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  border-top: 0.5px solid var(--line); flex-shrink: 0; align-items: flex-end;
}
.chat-input__field {
  flex: 1; min-height: 38px; max-height: 120px;
  padding: 9px 14px; border-radius: 18px;
  background: var(--bg-card); border: 0.5px solid var(--line-strong);
  color: var(--text); font-size: 15px; font-family: inherit;
  resize: none; outline: none; line-height: 1.3;
}
.chat-input__send {
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--tg-blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.chat-input__send:disabled { background: var(--bg-card-hi); color: var(--text-mute); }

/* ---------- Tarot card ---------- */
.tcard {
  width: 84px; height: 132px; border-radius: 8px;
  background: var(--bg-card); border: 0.5px solid var(--line-strong);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; padding: 8px;
  flex-shrink: 0;
}
.tcard.facedown {
  background: linear-gradient(145deg, var(--bg-card-hi), var(--bg-card));
  border-color: var(--ring);
}
.tcard.facedown .tcard__inner {
  position: absolute; inset: 6px; border-radius: 4px;
  border: 0.5px solid var(--ring);
}
.tcard.facedown .tcard__glyph {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.tcard__num { font-family: var(--serif); font-size: 10px; color: var(--gold); letter-spacing: 1.5px; text-align: center; }
.tcard__img { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px 0; }
.tcard__img img { max-width: 100%; max-height: 100%; border-radius: 4px; display: block; }
.tcard__name {
  font-family: var(--serif); font-size: 9px;
  color: var(--text); text-align: center; letter-spacing: 0.5px;
  text-transform: uppercase; line-height: 1.1;
}
.tcard.highlighted {
  background: #1f1a2e; border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-dim), 0 8px 24px rgba(0,0,0,0.5);
}
.tcard.reversed { transform: rotate(180deg); }

/* ---------- Spread pick ---------- */
.spread-pick {
  flex: 1; display: flex; flex-direction: column;
  padding: 16px 12px;
}
.spread-slots {
  display: flex; gap: 10px; justify-content: center;
  margin-bottom: 18px;
}
.spread-slot {
  width: 72px; height: 113px; border-radius: 8px;
  border: 1px dashed var(--ring); background: rgba(212,179,127,0.05);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 4px;
  font-family: var(--serif); font-size: 11px; color: var(--text-dim);
  letter-spacing: 0.5px; text-transform: uppercase;
}
.spread-slot.filled { border-style: solid; padding: 0; background: transparent; }
.spread-slot__pos { font-size: 9px; color: var(--text-mute); }
.spread-help {
  text-align: center; font-size: 13px; color: var(--text-dim);
  margin-bottom: 16px; font-style: italic; font-family: var(--serif);
}
.spread-fan {
  flex: 1; position: relative;
  display: flex; align-items: center; justify-content: center;
  margin-top: -10px;
}
.spread-fan__inner {
  position: relative; width: 100%; height: 220px;
  display: flex; align-items: center; justify-content: center;
}
.spread-fan .tcard {
  position: absolute; transition: transform 0.25s ease;
  cursor: pointer;
}

/* ---------- Spread result ---------- */
.spread-result {
  flex: 1; padding: 16px 16px 24px; overflow-y: auto;
}
.spread-result__title {
  font-family: var(--serif); font-size: 22px; font-weight: 500;
  color: var(--text); text-align: center; margin: 0 0 4px;
}
.spread-result__time {
  text-align: center; font-size: 12px; color: var(--text-dim);
  margin-bottom: 18px; font-variant-numeric: tabular-nums;
}
.spread-result__cards {
  display: flex; gap: 10px; justify-content: center; margin-bottom: 22px;
}
.spread-result__cards .tcard { width: 92px; height: 145px; }
.spread-result__pos {
  display: flex; gap: 10px; justify-content: center; margin-bottom: 18px;
  font-family: var(--serif); font-size: 11px; color: var(--gold);
  letter-spacing: 1.5px; text-transform: uppercase;
}
.spread-result__pos > span { width: 92px; text-align: center; }
.spread-result__interp {
  background: var(--bg-card); border-radius: 12px;
  padding: 16px; font-size: 14px; line-height: 1.55; color: var(--text);
  border: 0.5px solid var(--line-strong);
  white-space: pre-wrap;
}

/* ---------- History ---------- */
.history {
  flex: 1; padding: 12px 12px 24px; overflow-y: auto;
}
.history__item {
  background: var(--bg-card); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 10px;
  border: 0.5px solid var(--line-strong);
}
.history__head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
}
.history__title {
  font-family: var(--serif); font-size: 16px; color: var(--text);
}
.history__date {
  font-size: 11px; color: var(--text-mute);
  font-variant-numeric: tabular-nums;
}
.history__preview {
  font-size: 13px; color: var(--text-dim); line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.history__cards {
  display: flex; gap: 4px; margin-top: 8px;
}
.history__cards .tcard {
  width: 28px; height: 44px; padding: 2px;
  box-shadow: none;
}
.history__cards .tcard__name { display: none; }
.history__cards .tcard__num { display: none; }

.empty {
  padding: 60px 24px; text-align: center;
  color: var(--text-dim); font-family: var(--serif);
  font-style: italic; font-size: 16px;
}

/* ---------- Profile ---------- */
.profile {
  flex: 1; padding: 18px 16px 24px; overflow-y: auto;
}
.profile__card {
  background: linear-gradient(135deg, #2c5b97, #1d3f6f);
  border-radius: 14px; padding: 18px 18px 20px;
  display: flex; gap: 14px; align-items: center;
  margin-bottom: 16px;
}
.profile__avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,255,255,0.18); display: flex;
  align-items: center; justify-content: center;
  font-size: 22px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}
.profile__name { font-size: 17px; font-weight: 600; color: #fff; }
.profile__handle { font-size: 13px; color: rgba(255,255,255,0.7); margin-top: 2px; }

.profile__stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 16px;
}
.profile__stat {
  background: var(--bg-card); border-radius: 10px;
  padding: 12px; text-align: center;
  border: 0.5px solid var(--line-strong);
}
.profile__stat-num {
  font-family: var(--serif); font-size: 22px; color: var(--gold);
  font-variant-numeric: tabular-nums; line-height: 1;
}
.profile__stat-lbl {
  font-size: 11px; color: var(--text-dim); margin-top: 4px;
  letter-spacing: 0.2px;
}
.profile__section-title {
  font-size: 12px; color: var(--text-mute);
  text-transform: uppercase; letter-spacing: 1.5px;
  margin: 12px 4px 8px;
}
.profile__row {
  background: var(--bg-card); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 8px;
  border: 0.5px solid var(--line-strong);
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer;
}
.profile__row-label { font-size: 14px; color: var(--text); }
.profile__row-value { font-size: 13px; color: var(--text-dim); }
.profile__banner {
  background: linear-gradient(135deg, var(--accent-dim), var(--gold-dim));
  border: 0.5px solid var(--ring); border-radius: 12px;
  padding: 16px; margin-top: 12px; text-align: center;
}
.profile__banner-title {
  font-family: var(--serif); font-size: 18px; color: var(--gold); margin-bottom: 4px;
}
.profile__banner-text { font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }

/* ---------- Paywall ---------- */
.paywall { flex: 1; padding: 20px 16px 24px; overflow-y: auto; }
.paywall__title {
  font-family: var(--serif); font-size: 28px; font-weight: 500;
  color: var(--gold); text-align: center; margin: 8px 0 6px; letter-spacing: 0.5px;
}
.paywall__sub {
  text-align: center; font-size: 14px; color: var(--text-dim);
  margin-bottom: 22px; font-family: var(--serif); font-style: italic;
}
.paywall__plans { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.paywall__plan {
  background: var(--bg-card); border-radius: 14px;
  padding: 14px 16px; border: 1px solid var(--line-strong);
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; position: relative; transition: all 0.15s;
}
.paywall__plan.selected {
  background: #1f1a2e; border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold);
}
.paywall__plan.popular { border-color: var(--accent); }
.paywall__plan-tokens {
  font-family: var(--serif); font-size: 22px; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.paywall__plan-tokens small {
  display: block; font-size: 11px; font-family: var(--sans);
  color: var(--text-dim); letter-spacing: 0.5px; text-transform: uppercase;
  margin-top: 2px;
}
.paywall__plan-price {
  font-family: var(--serif); font-size: 22px; color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.paywall__plan-discount {
  font-size: 11px; color: var(--accent); font-weight: 600;
  margin-top: 2px; text-align: right;
}
.paywall__badge {
  position: absolute; top: -8px; right: 14px;
  background: var(--accent); color: #fff;
  font-size: 10px; padding: 3px 8px; border-radius: 6px;
  letter-spacing: 0.5px; text-transform: uppercase; font-weight: 600;
}
.paywall__perks {
  background: var(--bg-card); border-radius: 12px;
  padding: 14px 16px; border: 0.5px solid var(--line-strong);
  margin-bottom: 16px;
}
.paywall__perks-title {
  font-size: 12px; color: var(--text-mute);
  text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 10px;
}
.paywall__perk {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 13px; color: var(--text-dim); margin-bottom: 8px;
}
.paywall__perk:last-child { margin-bottom: 0; }
.paywall__perk svg { flex-shrink: 0; margin-top: 2px; }
.paywall__email-label {
  font-size: 12px; color: var(--text-mute); letter-spacing: 0.5px;
  margin: 6px 4px 6px;
}
.paywall__email {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  background: var(--bg-card); border: 0.5px solid var(--line-strong);
  color: var(--text); font-size: 14px; font-family: inherit;
  outline: none;
}
.paywall__email:focus { border-color: var(--gold); }

/* ---------- Loading / errors ---------- */
.loader-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
.loader {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--bg-card-hi); border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card-hi); color: var(--text);
  padding: 10px 16px; border-radius: 8px; font-size: 13px;
  z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  border: 0.5px solid var(--ring); max-width: 90%; text-align: center;
}

/* ---------- Light theme override (если у юзера светлая тема в TG) ---------- */
@media (prefers-color-scheme: light) {
  /* мы оставляем тёмную палитру — Морана ночная. */
}
