*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #07060f;
  --bg2: #0d0b1e;
  --surface: rgba(18, 15, 38, 0.85);
  --surface2: rgba(26, 22, 54, 0.7);
  --border: rgba(138, 110, 255, 0.18);
  --border2: rgba(180, 160, 255, 0.1);
  --text: rgba(248, 246, 255, 1);
  --text2: rgba(210, 205, 240, 0.92);
  --text3: rgba(170, 165, 210, 0.78);
  --accent: rgba(138, 110, 255, 1);
  --accent2: rgba(200, 180, 255, 1);
  --gold: rgba(230, 200, 130, 1);
  --glow: rgba(138, 110, 255, 0.35);
}
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Bitter', serif; overflow-x: hidden; }
body { min-height: 100vh; }

/* Headings use Bitter (inherited) */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Bitter', serif;
  font-weight: 700;
  color: var(--text);
}

/* Body / paragraph text uses Space Grotesk for readability */
p, li, .body-text {
  font-family: 'Space Grotesk', sans-serif;
}

/* Starfield canvas */
#starfield { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* Nebula bg */
.nebula {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 20% 30%, rgba(80, 40, 160, 0.18) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 80% 70%, rgba(40, 80, 160, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 60% 20%, rgba(100, 40, 140, 0.1) 0%, transparent 60%);
}

#root { position: relative; z-index: 1; min-height: 100vh; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(138,110,255,0.3); border-radius: 4px; }

/* Animations */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 0.6; } 50% { opacity: 1; }
}
@keyframes cardFlip {
  0% { transform: rotateY(0deg) scale(1); }
  50% { transform: rotateY(90deg) scale(0.95); }
  100% { transform: rotateY(0deg) scale(1); }
}
@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}
@keyframes deckShake {
  0%   { transform: translate(0,0) rotate(0deg); }
  10%  { transform: translate(-9px,2px) rotate(-4deg); }
  20%  { transform: translate(9px,-2px) rotate(4deg); }
  30%  { transform: translate(-11px,1px) rotate(-5deg); }
  40%  { transform: translate(11px,-1px) rotate(5deg); }
  50%  { transform: translate(-9px,2px) rotate(-4deg); }
  60%  { transform: translate(9px,-2px) rotate(4deg); }
  70%  { transform: translate(-5px,1px) rotate(-2deg); }
  80%  { transform: translate(5px,-1px) rotate(2deg); }
  90%  { transform: translate(-2px,0) rotate(-1deg); }
  100% { transform: translate(0,0) rotate(0deg); }
}
@keyframes spin {
  from { transform: rotate(0deg); } to { transform: rotate(360deg); }
}
@keyframes cardShuffle1 {
  0%   { transform: translateX(0) rotate(0deg); }
  25%  { transform: translateX(-70px) rotate(-14deg); }
  50%  { transform: translateX(0) rotate(0deg); }
  75%  { transform: translateX(70px) rotate(14deg); }
  100% { transform: translateX(0) rotate(0deg); }
}
@keyframes cardShuffle2 {
  0%   { transform: translateX(0) rotate(0deg); }
  25%  { transform: translateX(60px) rotate(11deg); }
  50%  { transform: translateX(0) rotate(0deg); }
  75%  { transform: translateX(-60px) rotate(-11deg); }
  100% { transform: translateX(0) rotate(0deg); }
}
@keyframes cardShuffle3 {
  0%   { transform: translateX(0) rotate(0deg) translateY(0); }
  20%  { transform: translateX(-45px) rotate(-9deg) translateY(-12px); }
  40%  { transform: translateX(45px) rotate(9deg) translateY(6px); }
  60%  { transform: translateX(-22px) rotate(-4deg) translateY(-6px); }
  80%  { transform: translateX(22px) rotate(4deg) translateY(6px); }
  100% { transform: translateX(0) rotate(0deg) translateY(0); }
}
@keyframes floatUp {
  0%   { transform: translateY(0) scale(1); opacity: 0.8; }
  100% { transform: translateY(-130px) scale(0.5); opacity: 0; }
}
@keyframes deckPulse {
  0%, 100% { box-shadow: 0 20px 60px rgba(138,110,255,0.3), 0 0 40px rgba(138,110,255,0.2); }
  50%       { box-shadow: 0 20px 80px rgba(138,110,255,0.55), 0 0 70px rgba(138,110,255,0.4); }
}
@keyframes cardStackReveal {
  0%   { opacity: 0; transform: translateY(40px) scale(0.85); }
  60%  { opacity: 1; transform: translateY(-6px) scale(1.03); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cardFlip3d {
  0%   { transform: rotateY(0deg); }
  49%  { transform: rotateY(90deg); }
  50%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg); }
}

.shuffle-card-1 { animation: cardShuffle1 1.4s ease-in-out infinite; }
.shuffle-card-2 { animation: cardShuffle2 1.4s ease-in-out infinite 0.18s; }
.shuffle-card-3 { animation: cardShuffle3 1.4s ease-in-out infinite 0.36s; }
.deck-pulse { animation: deckPulse 1.8s ease-in-out infinite; }

.fade-up { animation: fadeUp 0.5s ease forwards; }
.fade-in { animation: fadeIn 0.4s ease forwards; }

.card-stack-item {
  animation: cardStackReveal 0.6s cubic-bezier(0.34, 1.4, 0.64, 1) forwards;
  animation-fill-mode: forwards;
}
.card-flipping { animation: cardFlip3d 0.55s ease forwards; }
.card-perspective { perspective: 800px; }

.tarot-card-visual:hover {
  transform: translateY(-6px) scale(1.03) !important;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 40px rgba(138,110,255,0.25) !important;
}

/* Nav — floating pill */
.nav-wrap {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 200; width: calc(100% - 48px); max-width: 900px;
}
.nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 10px 20px;
  border-radius: 100px;
  border: 1px solid rgba(180,160,255,0.18);
  backdrop-filter: blur(20px) saturate(160%);
  background: rgba(12,10,28,0.82);
  box-shadow: 0 8px 32px rgba(0,0,0,0.45), 0 0 0 0.5px rgba(180,160,255,0.1) inset;
}
.nav-logo {
  font-family: 'DM Mono', monospace; font-size: 13px; letter-spacing: 0.2em;
  color: rgba(235,232,255,1); text-transform: uppercase; display: flex; align-items: center; gap: 10px;
}
.nav-links { display: flex; gap: 4px; }
.nav-btn {
  font-family: 'DM Mono', monospace; font-size: 10px; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 7px 16px; border-radius: 100px;
  border: 1px solid transparent; background: transparent;
  color: rgba(180,175,215,0.65); cursor: pointer; transition: all 0.2s ease;
}
.nav-btn:hover { border-color: rgba(138,110,255,0.35); color: rgba(228,225,250,0.95); background: rgba(138,110,255,0.1); }
.nav-btn.active { border-color: rgba(138,110,255,0.5); color: rgba(185,160,255,1); background: rgba(138,110,255,0.14); }
.nav-btn.verified { border-color: rgba(60,200,100,0.4); color: rgba(100,230,140,0.9); background: rgba(60,200,100,0.08); }
.nav-btn.verified:hover { border-color: rgba(60,200,100,0.6); color: rgba(100,230,140,1); background: rgba(60,200,100,0.14); }
.nav-btn.verified.active { border-color: rgba(60,200,100,0.6); color: rgba(100,230,140,1); background: rgba(60,200,100,0.14); }

/* offset content below fixed nav */
#root { padding-top: 72px; }

/* Input styles */
.arcana-input {
  width: 100%; background: rgba(18,15,38,0.7); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px 24px; font-family: 'Space Grotesk', sans-serif;
  font-size: 16px; color: var(--text); outline: none; resize: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  backdrop-filter: blur(8px);
}
.arcana-input::placeholder { color: var(--text3); }
.arcana-input:focus {
  border-color: rgba(138,110,255,0.5);
  box-shadow: 0 0 0 3px rgba(138,110,255,0.1), 0 0 20px rgba(138,110,255,0.12);
}

/* Primary button */
.btn-primary {
  background: linear-gradient(135deg, rgba(138,110,255,0.9), rgba(100,80,220,0.9));
  border: 1px solid rgba(180,155,255,0.4); color: white;
  font-family: 'DM Mono', monospace; font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase; padding: 14px 28px; border-radius: 100px;
  cursor: pointer; transition: all 0.25s ease;
  box-shadow: 0 4px 20px rgba(138,110,255,0.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(138,110,255,0.45);
  background: linear-gradient(135deg, rgba(158,130,255,0.95), rgba(120,100,240,0.95));
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Ghost button */
.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--text2); font-family: 'DM Mono', monospace;
  font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase;
  padding: 12px 24px; border-radius: 100px; cursor: pointer; transition: all 0.2s ease;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); background: rgba(138,110,255,0.08); }

/* Spread card selector */
.spread-card {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 14px; padding: 20px; cursor: pointer;
  transition: all 0.25s ease; text-align: left;
}
.spread-card:hover { border-color: rgba(138,110,255,0.4); background: var(--surface2); transform: translateY(-2px); }
.spread-card.selected {
  border-color: var(--accent); background: rgba(138,110,255,0.1);
  box-shadow: 0 0 20px rgba(138,110,255,0.15);
}

/* Glass panel */
.glass-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; backdrop-filter: blur(16px);
}

/* Gallery card */
.gallery-card {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 14px; padding: 16px; cursor: pointer;
  transition: all 0.25s ease; display: flex; flex-direction: column; gap: 10px;
  align-items: center; text-align: center;
}
.gallery-card:hover {
  border-color: rgba(138,110,255,0.4); background: var(--surface2);
  transform: translateY(-3px); box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}

/* Section label */
.section-label {
  font-family: 'DM Mono', monospace; font-size: 10px;
  letter-spacing: 0.2em; text-transform: uppercase; color: var(--text3);
}

/* Bitter title utility */
.bitter-title {
  font-family: 'Bitter', serif;
  font-weight: 700;
  color: var(--text);
}

/* Loading shimmer */
.shimmer-text {
  background: linear-gradient(90deg, var(--text2) 0%, var(--accent2) 50%, var(--text2) 100%);
  background-size: 200% auto; -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
  animation: shimmer 2s linear infinite;
}

/* Result prose */
.result-prose {
  font-family: 'Bitter', serif;
  font-size: 15px; line-height: 1.9; color: var(--text2);
  text-wrap: pretty;
}
.result-prose strong { color: var(--text); font-weight: 700; }

/* API key input */
.api-input {
  background: rgba(18,15,38,0.7); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 16px; font-family: 'DM Mono', monospace;
  font-size: 12px; color: var(--text); outline: none; width: 100%;
  transition: border-color 0.2s;
}
.api-input:focus { border-color: rgba(138,110,255,0.5); }
.api-input::placeholder { color: var(--text3); }

/* Tabs */
.tab-bar {
  display: flex; gap: 0; border-bottom: 1px solid var(--border2);
  margin-bottom: 32px;
}
.tab-item {
  padding: 12px 24px; font-family: 'DM Mono', monospace; font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase; cursor: pointer;
  color: var(--text3); border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: all 0.2s ease; background: none; border-top: none;
  border-left: none; border-right: none;
}
.tab-item:hover { color: var(--text2); }
.tab-item.active { color: var(--accent2); border-bottom-color: var(--accent); }

/* Modal overlay */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(4,3,10,0.85); backdrop-filter: blur(8px);
  display: flex; align-items: flex-start; justify-content: center; 
  padding: 60px 20px; overflow-y: auto;
  animation: fadeIn 0.25s ease;
}
.modal-inner {
  max-width: 680px; width: 100%; margin: 0 auto;
  animation: fadeUp 0.3s ease;
}

/* Copy button */
.copy-btn {
  background: rgba(138,110,255,0.12); border: 1px solid rgba(138,110,255,0.3);
  color: var(--accent2); font-family: 'DM Mono', monospace;
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 8px 16px; border-radius: 8px; cursor: pointer; transition: all 0.2s ease;
}
.copy-btn:hover { background: rgba(138,110,255,0.2); }

/* Prompt box */
.prompt-box {
  background: rgba(10,8,24,0.9); border: 1px solid var(--border);
  border-radius: 12px; padding: 20px; font-family: 'DM Mono', monospace;
  font-size: 12px; line-height: 1.7; color: var(--text2);
  white-space: pre-wrap; word-break: break-word;
}

/* Responsive Layout */
@media (max-width: 768px) {
  .modal-layout {
    flex-direction: column !important;
    align-items: center !important;
    gap: 20px !important;
  }
  .modal-meanings {
    flex-direction: row !important;
  }
  .modal-meanings > div {
    flex: 1;
  }
  .modal-grid-3 {
    grid-template-columns: 1fr !important;
  }
  .glass-panel.modal-panel {
    padding: 20px !important;
  }

  /* Card Pool — stack into two rows on mobile */
  .card-pool-panel {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 16px !important;
  }
  .card-pool-panel > div:first-child {
    width: 100%;
  }
  .card-pool-reversed {
    width: 100%;
    justify-content: space-between !important;
    padding-top: 14px;
    border-top: 1px solid rgba(180,160,255,0.1);
  }
  .card-reveal-row {
    flex-direction: column !important;
    align-items: center !important;
  }
  .card-reveal-meta {
    width: 100% !important;
  }
  .card-reveal-grid3 {
    grid-template-columns: 1fr !important;
  }

  /* Drawn card thumbnails row — scroll horizontally on mobile */
  .drawn-cards-row {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    justify-content: flex-start !important;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
  }
}

.arcana-toast-success {
  position: fixed;
  top: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(26,22,54,0.97);
  border: 1px solid rgba(100,230,140,0.5);
  color: rgba(100,230,140,1);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 12px 24px;
  border-radius: 100px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 12px rgba(100,230,140,0.2) inset;
  backdrop-filter: blur(16px);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
}
.arcana-toast-success.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.arcana-toast-error {
  position: fixed;
  top: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(26,22,54,0.97);
  border: 1px solid rgba(255,120,120,0.5);
  color: rgba(255,150,150,1);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 12px 24px;
  border-radius: 100px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 12px rgba(255,120,120,0.15) inset;
  backdrop-filter: blur(16px);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}
.arcana-toast-error.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Perspective dropdown — visible only on mobile (toggled via media query) */
.perspective-dropdown {
  display: none;
  width: 100%;
  background: rgba(18,15,38,0.8);
  border: 1px solid rgba(138,110,255,0.35);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  font-family: 'DM Mono', monospace;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238a6eff' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.perspective-dropdown:focus {
  outline: none;
  border-color: rgba(138,110,255,0.6);
  box-shadow: 0 0 0 3px rgba(138,110,255,0.12);
}

.modal-col-left {
  flex: 0 0 240px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.modal-col-right {
  flex: 1;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

@media (max-width: 768px) {
  .modal-col-left {
    flex: 1 1 100%;
    align-items: center;
  }
  .modal-col-left > * {
    width: 100% !important;
    max-width: 280px;
  }
  .modal-col-right {
    min-width: 0;
    width: 100%;
  }
  /* Tab bar — scroll horizontally instead of wrapping */
  .modal-tab-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    border-radius: 12px !important;
    padding: 4px !important;
    scrollbar-width: none;
  }
  .modal-tab-bar::-webkit-scrollbar { display: none; }
  .modal-tab-bar button {
    flex: 0 0 auto !important;
    white-space: nowrap;
    min-width: 64px;
  }
  /* Perspective dropdown shown, pill bar hidden */
  .perspective-pill-bar { display: none !important; }
  .perspective-dropdown { display: block !important; }
  /* Gallery card grid — single column on very small screens */
  .gallery-card-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Hide carousel arrow buttons on mobile — swipe is available */
@media (max-width: 600px) {
  .carousel-arrow { display: none !important; }
}

/* About Page */
.about-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 600px) {
  .about-grid {
    grid-template-columns: 1fr;
  }
}

/* Global Thai Font Override */
.lang-th, .lang-th * {
  font-family: 'Anuphan', sans-serif !important;
}

/* Modal Scroll Lock */
body.modal-open {
  overflow: hidden;
}

/* Thai language result prose */
.result-prose.lang-th {
  font-family: "Anuphan", "Space Grotesk", sans-serif;
  line-height: 1.9;
}


/* Mobile Nav */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: rgba(235,232,255,1);
  cursor: pointer;
  padding: 4px;
}
@media (max-width: 768px) {
  .nav-toggle {
    display: block;
  }
  .nav {
    flex-wrap: wrap;
    transition: all 0.3s ease;
  }
  .nav.open {
    border-radius: 24px;
  }
  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    margin-top: 12px;
    gap: 8px;
    padding-bottom: 8px;
    order: 3;
  }
  .nav-links.open {
    display: flex;
  }
  .nav-btn {
    width: 100%;
    text-align: left;
    padding: 10px 16px;
  }
}
