@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;1,400&family=Inter:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #08080f;
  --surface:   #0f0e1a;
  --surface2:  #16152a;
  --border:    #1e1d35;
  --primary:   #7c3aed;
  --primary-h: #6d28d9;
  --glow:      rgba(124, 58, 237, 0.35);
  --gold:      #c9a84c;
  --text:      #dbd9f4;
  --muted:     #6b6a8a;
  --error:     #e05c5c;
  --radius:    12px;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Utilities ── */
.hidden { display: none !important; }
.text-muted  { color: var(--muted); }
.text-gold   { color: var(--gold); }
.text-error  { color: var(--error); font-size: 13px; }

/* ── Loading ── */
#view-loading {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); z-index: 100;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Auth / Onboarding ── */
.card-wrapper {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.card {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
}
.card-logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 32px; font-weight: 600;
  color: var(--gold); text-align: center;
  letter-spacing: 0.06em; margin-bottom: 6px;
}
.card-subtitle { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 32px; }
.card h2 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px; font-weight: 600;
  margin-bottom: 20px; text-align: center;
}

/* ── Forms ── */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="email"], input[type="text"], input[type="date"], select {
  width: 100%;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px;
  color: var(--text); font-size: 15px; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
input:focus, select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--glow);
}
input::placeholder { color: var(--muted); }
select option { background: var(--surface2); }
.form-group { margin-bottom: 18px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 8px;
  font-size: 15px; font-weight: 500; font-family: inherit;
  cursor: pointer; border: none;
  transition: background 0.2s, transform 0.1s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); width: 100%;
  margin-top: 10px;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text); }
.btn-ghost-crypto {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); width: 100%;
  margin-top: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 11px 20px; border-radius: 8px;
  font-size: 15px; font-family: inherit; cursor: pointer;
  transition: border-color 0.2s;
}
.btn-ghost-crypto:hover { border-color: var(--primary); color: var(--primary); }
.btn-inline-link {
  background: none; border: none; color: var(--primary);
  cursor: pointer; font-size: 13px; font-family: inherit;
  text-decoration: underline;
}
.btn-text-back {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font-size: 13px; font-family: inherit;
  margin-top: 12px; display: block;
}
.btn-text-back:hover { color: var(--text); }

.info-box {
  background: rgba(124,58,237,0.1);
  border: 1px solid rgba(124,58,237,0.3);
  border-radius: 8px; padding: 14px;
  font-size: 13px; color: var(--text);
  text-align: center; line-height: 1.5;
}

/* ── App shell ── */
#view-app { display: flex; flex-direction: column; height: 100vh; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.app-logo {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px; font-weight: 600;
  color: var(--gold); letter-spacing: 0.04em;
}
.header-right { display: flex; align-items: center; gap: 16px; }
.credits-badge {
  font-size: 13px; color: var(--muted);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 3px 12px;
}
.credits-badge span { color: var(--text); font-weight: 500; }
.btn-logout {
  background: none; border: none;
  color: var(--muted); font-size: 13px;
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.btn-logout:hover { color: var(--error); }

.app-nav {
  display: flex; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.nav-tab {
  flex: 1; padding: 10px 0;
  background: none; border: none;
  color: var(--muted); font-size: 13px; font-family: inherit;
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.nav-tab:hover:not(.active) { color: var(--text); }

.tab-panels { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.tab-panel { display: none; flex: 1; flex-direction: column; overflow: hidden; }
.tab-panel.active { display: flex; }

/* ── Chat ── */
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 20px 16px;
  display: flex; flex-direction: column; gap: 20px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg-user  { align-self: flex-end;  align-items: flex-end; }
.msg-namtar { align-self: flex-start; align-items: flex-start; }
.msg-bubble {
  padding: 12px 16px; border-radius: 12px;
  font-size: 15px; line-height: 1.65; word-break: break-word;
}
.msg-user .msg-bubble {
  background: var(--primary); color: #fff; border-bottom-right-radius: 3px;
}
.msg-namtar .msg-bubble {
  background: var(--surface2); border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}
.msg-namtar .msg-bubble::before {
  content: 'Намтар';
  display: block;
  font-family: 'Cormorant Garamond', serif;
  font-size: 12px; color: var(--gold);
  margin-bottom: 6px; letter-spacing: 0.06em;
}
.msg-time { font-size: 11px; color: var(--muted); margin-top: 4px; padding: 0 4px; }
.msg-thinking .msg-bubble { display: flex; gap: 6px; align-items: center; padding: 14px 18px; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1); }
}
.chat-form {
  padding: 12px 16px; background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; align-items: flex-end; flex-shrink: 0;
}
.chat-input {
  flex: 1; background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px;
  color: var(--text); font-family: inherit; font-size: 15px;
  resize: none; outline: none; min-height: 44px; max-height: 140px;
  line-height: 1.5; overflow-y: auto; transition: border-color 0.2s;
  width: 100%;
}
.chat-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--glow); }
.chat-input::placeholder { color: var(--muted); }
.chat-send {
  width: 44px; height: 44px; flex-shrink: 0;
  background: var(--primary); border: none; border-radius: 10px;
  color: #fff; cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s, transform 0.1s;
}
.chat-send:hover:not(:disabled) { background: var(--primary-h); }
.chat-send:active { transform: scale(0.95); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
.no-credits-bar {
  padding: 10px 16px; background: rgba(224,92,92,0.1);
  border-top: 1px solid rgba(224,92,92,0.3);
  text-align: center; font-size: 13px; color: var(--error);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

/* ── History ── */
.history-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.history-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  cursor: pointer; transition: border-color 0.2s;
}
.history-item:hover { border-color: var(--primary); }
.history-q { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
.history-meta { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.history-answer {
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 14px; white-space: pre-wrap; display: none;
}
.history-item.expanded .history-answer { display: block; }
.history-empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ── Profile ── */
.profile-content { flex: 1; overflow-y: auto; padding: 24px 16px; max-width: 480px; margin: 0 auto; width: 100%; }
.profile-field { margin-bottom: 20px; }
.profile-value {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; font-size: 15px;
}
.profile-credits-card {
  background: linear-gradient(135deg, rgba(124,58,237,0.2), rgba(201,168,76,0.1));
  border: 1px solid rgba(124,58,237,0.4);
  border-radius: var(--radius); padding: 20px;
  text-align: center; margin-bottom: 24px;
}
.profile-credits-num {
  font-family: 'Cormorant Garamond', serif;
  font-size: 48px; font-weight: 600;
  color: var(--gold); line-height: 1; margin-bottom: 4px;
}
.profile-credits-label { font-size: 13px; color: var(--muted); }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.section-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 20px; font-weight: 600; color: var(--text);
  margin-bottom: 16px;
}
.consult-types { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.type-btn {
  padding: 7px 16px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); font-size: 13px; font-family: inherit;
  cursor: pointer; transition: all 0.2s;
}
.type-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.type-btn:hover:not(.active) { border-color: var(--text); color: var(--text); }

/* ── Shop ── */
.shop-content { flex: 1; overflow-y: auto; padding: 16px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.amulet-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  cursor: pointer; transition: border-color 0.2s, transform 0.15s;
}
.amulet-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.amulet-img { width: 100%; height: 200px; object-fit: cover; display: block; }
.amulet-body { padding: 14px; }
.amulet-name {
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px; font-weight: 600; color: var(--gold);
  margin-bottom: 8px;
}
.amulet-desc { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 12px; }
.amulet-price { font-size: 13px; color: var(--text); }
.amulet-btn {
  margin-top: 12px; width: 100%; padding: 9px;
  background: var(--primary); color: #fff; border: none;
  border-radius: 8px; font-size: 14px; font-family: inherit;
  cursor: pointer; transition: background 0.2s;
}
.amulet-btn:hover { background: var(--primary-h); }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px;
  width: 100%; max-width: 440px;
  max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px;
}
.modal-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 22px; font-weight: 600;
}
.modal-close {
  background: none; border: none; color: var(--muted);
  font-size: 18px; cursor: pointer; line-height: 1;
  padding: 4px 8px; border-radius: 4px;
}
.modal-close:hover { color: var(--text); }

/* Topup packages */
.topup-packages { display: flex; flex-direction: column; gap: 10px; }
.topup-pkg {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  cursor: pointer; transition: border-color 0.2s;
  display: flex; justify-content: space-between; align-items: center;
}
.topup-pkg:hover { border-color: var(--primary); }
.topup-pkg-credits { font-size: 17px; font-weight: 500; color: var(--text); }
.topup-pkg-price { font-size: 14px; color: var(--muted); }
.topup-selected { display: flex; flex-direction: column; }
.topup-selected-title { font-size: 14px; color: var(--muted); margin-bottom: 16px; }
.topup-selected-title span { color: var(--text); font-weight: 500; }
.topup-methods { display: flex; flex-direction: column; gap: 0; }

/* Shop order */
.order-price-line {
  font-size: 14px; color: var(--gold); margin-bottom: 16px;
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .card { padding: 32px 24px; }
  .form-row { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
  .shop-grid { grid-template-columns: 1fr; }
}
