/* ===== 13 Tarot — Custom Mystical Theme ===== */
:root {
  --bg-deep: #120a24;
  --bg-card: #1e1238;
  --bg-soft: #2a1b4e;
  --accent-gold: #d4a843;
  --accent-purple: #9b59b6;
  --accent-purple-soft: #7e3ca3;
  --text-light: #f0e6d2;
  --text-muted: #a89bb8;
  --border: #4a3561;
  --danger: #e74c3c;
  --success: #2ecc71;
  --chat-user: #3d2566;
  --chat-ai: #231543;
}

body {
  background:
    radial-gradient(ellipse at 20% 0%, rgba(155, 89, 182, 0.14) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(212, 168, 67, 0.08) 0%, transparent 45%),
    var(--bg-deep);
  color: var(--text-light);
  font-family: 'EB Garamond', 'Georgia', serif;
  min-height: 100vh;
  font-size: 17px;
}

html, body {
  scroll-behavior: smooth;
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
  min-height: 100%;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Card slots ---------- */
.card-slot {
  background: var(--bg-card);
  border: 2px dashed var(--border);
  border-radius: 14px;
  padding: 16px;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
}
.card-slot:hover {
  border-color: var(--accent-purple);
  transform: translateY(-2px);
}
.card-slot.filled {
  border-style: solid;
  border-color: var(--accent-gold);
  background: linear-gradient(135deg, var(--bg-card) 0%, #3d2566 100%);
}
.card-slot.selected-for-scan {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 2px rgba(155,89,182,0.5), 0 0 24px rgba(155,89,182,0.25);
}

.slot-position-badge {
  position: absolute;
  top: 8px;
  left: 10px;
  background: rgba(212,168,67,0.16);
  color: var(--accent-gold);
  border: 1px solid rgba(212,168,67,0.4);
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  text-transform: uppercase;
}

.mini-card-img {
  height: 72px;
  width: auto;
  max-width: 52px;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  border: 1px solid rgba(212,168,67,0.35);
}
.mini-card-img.reversed,
img.reversed {
  transform: rotate(180deg);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

/* ---------- Keywords ---------- */
.keyword-pill {
  background: rgba(212,168,67,0.14);
  color: var(--accent-gold);
  border: 1px solid rgba(212,168,67,0.22);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: 0.3px;
}

/* ---------- Spread buttons ---------- */
.spread-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.spread-btn:hover {
  border-color: var(--accent-purple);
  color: var(--text-light);
}
.spread-btn.active {
  background: linear-gradient(135deg, var(--accent-gold), #b8892f);
  color: var(--bg-deep);
  border-color: var(--accent-gold);
  font-weight: 700;
}

/* ---------- Buttons ---------- */
.btn-gold {
  background: linear-gradient(135deg, var(--accent-gold), #b8892f);
  color: var(--bg-deep);
}
.btn-gold:hover {
  filter: brightness(1.1);
}
.btn-purple {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-purple-soft));
  color: #fff;
}
.btn-purple:hover { filter: brightness(1.12); }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--accent-purple); color: var(--text-light); }
.btn-danger-ghost {
  background: transparent;
  border: 1px solid rgba(231,76,60,0.4);
  color: #f1948a;
}
.btn-danger-ghost:hover { background: rgba(231,76,60,0.12); }

/* ---------- Picker ---------- */
.picker-card {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  color: var(--text-light);
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 11px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.3;
}
.picker-card:hover {
  border-color: var(--accent-gold);
  background: #3d2566;
  transform: scale(1.03);
}
.picker-card.used { opacity: 0.28; pointer-events: none; }
.picker-card .num {
  color: var(--accent-gold);
  font-weight: 700;
  font-size: 12px;
  display: block;
  margin-bottom: 2px;
}
.picker-card img {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 4px;
  border: 1px solid rgba(212,168,67,0.25);
}

/* ---------- Camera modal ---------- */
.camera-frame {
  border: 3px solid var(--accent-gold);
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  position: relative;
  aspect-ratio: 2 / 3.5;
  max-height: 48vh;
  margin-left: auto;
  margin-right: auto;
}
.camera-frame.compact {
  max-height: 14vh;
}
#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.scan-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(212,168,67,0.85),
              inset 0 0 40px rgba(212,168,67,0.15);
}
.scan-guide::after {
  content: "◈";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 40px;
  color: rgba(212,168,67,0.5);
  text-shadow: 0 0 18px rgba(212,168,67,0.7);
}

/* ---------- Recognition results ---------- */
.match-option {
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  transition: all 0.2s;
  cursor: pointer;
  min-height: 150px;
  padding: 8px !important;
}
.match-option:hover {
  border-color: var(--accent-gold);
  background: #2a1b4e;
  transform: translateY(-2px);
}
.match-option img {
  height: 68px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border-radius: 6px;
  border: 1px solid rgba(212,168,67,0.3);
}
.match-confidence {
  font-size: 13px;
  color: var(--accent-gold);
  font-weight: 700;
  letter-spacing: 0.6px;
}

/* ---------- Reading summary ---------- */
.reading-summary {
  background: linear-gradient(135deg, #3d2566 0%, var(--bg-card) 100%);
  border: 1px solid var(--accent-gold);
  border-radius: 14px;
}

/* ---------- Chat ---------- */
.chat-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0,0,0,0.6);
  transform: translateX(100%);
  transition: transform 0.35s ease, visibility 0.35s;
  z-index: 60;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  visibility: hidden;
}
.chat-drawer.open {
  transform: translateX(0);
  pointer-events: auto;
  visibility: visible;
}
@media (max-width: 480px) {
  .chat-drawer { max-width: 100%; }
}

.chat-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-message.user {
  background: var(--chat-user);
  color: var(--text-light);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}
.chat-message.ai {
  background: var(--chat-ai);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.chat-message.error {
  background: rgba(231,76,60,0.12);
  border: 1px solid rgba(231,76,60,0.4);
  color: #f5b7b1;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-deep); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-purple); }

/* ---------- Misc ---------- */
.modal-backdrop {
  background: rgba(10, 5, 22, 0.82);
  backdrop-filter: blur(6px);
}
.text-shadow-gold { text-shadow: 0 0 24px rgba(212,168,67,0.35); }
.divider-glow {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
}

.hidden { display: none !important; }

@media (max-width: 480px) {
  body { font-size: 18px; }

  .camera-panel {
    min-height: calc(100dvh - 24px);
  }

  .camera-frame {
    max-height: 42vh;
  }

  .camera-frame.compact {
    max-height: 11vh;
  }

  #capturePreview {
    max-height: 58px;
  }

  .match-option {
    min-height: 142px;
  }

  .match-option img {
    height: 60px;
  }
}

@media (max-height: 720px) {
  .camera-panel {
    margin-top: 8px !important;
    margin-bottom: 8px !important;
    padding: 12px !important;
  }

  .camera-frame.compact {
    max-height: 9vh;
  }

  #cameraStatus {
    margin-bottom: 8px !important;
  }

  #capturePreview {
    max-height: 50px;
  }

  .match-option {
    min-height: 128px;
    padding: 6px !important;
  }

  .match-option img {
    height: 52px;
  }
}

@keyframes spiritPulse {
  0%, 100% { opacity: 0.55; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.04); }
}
.spirit-pulse { animation: spiritPulse 1.8s ease-in-out infinite; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in-up { animation: fadeInUp 0.35s ease both; }

/* Spinner */
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(212,168,67,0.25);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
