/* === CSS Variables === */
:root {
  --bg-primary: #0a0015;
  --bg-secondary: #120025;
  --bg-card: #1a0a3e;
  --gold: #d4a574;
  --gold-light: #e8c9a0;
  --gold-dark: #a67c52;
  --text-primary: #f0e6d3;
  --text-secondary: #b8a9d4;
  --reversed-accent: #8b2222;
  --card-front-bg: linear-gradient(180deg, #f5e6d3 0%, #e8d5c4 50%, #dbc8b0 100%);
  --card-front-text: #1a0a3e;
  --radius-card: 10px;
  --shadow-gold: 0 4px 20px rgba(212, 165, 116, 0.3);
  --shadow-gold-hover: 0 8px 30px rgba(212, 165, 116, 0.5);
  --shadow-glow: 0 0 30px rgba(180, 140, 200, 0.4);
  --font-heading: Georgia, 'Times New Roman', serif;
  --font-body: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font-body);
  background: radial-gradient(ellipse at 50% 0%, #1a1040 0%, #0d0020 50%, var(--bg-primary) 100%);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  padding-bottom: 60px;
}

/* === Stars Background === */
.stars {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
}
.stars::before, .stars::after {
  content: '';
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: transparent;
  box-shadow:
    50px 80px 0 #fff, 120px 200px 0 rgba(255,255,255,0.8), 200px 60px 0 rgba(255,255,255,0.6),
    300px 150px 0 #fff, 400px 40px 0 rgba(255,255,255,0.7), 500px 300px 0 rgba(255,255,255,0.5),
    600px 100px 0 #fff, 700px 250px 0 rgba(255,255,255,0.9), 800px 50px 0 rgba(255,255,255,0.6),
    900px 180px 0 #fff, 1000px 280px 0 rgba(255,255,255,0.7), 150px 350px 0 rgba(255,255,255,0.5),
    350px 400px 0 #fff, 550px 420px 0 rgba(255,255,255,0.8), 750px 380px 0 rgba(255,255,255,0.6),
    80px 500px 0 rgba(255,255,255,0.7), 250px 520px 0 #fff, 450px 500px 0 rgba(255,255,255,0.5),
    650px 480px 0 rgba(255,255,255,0.9), 850px 520px 0 rgba(255,255,255,0.6), 950px 100px 0 #fff,
    1100px 150px 0 rgba(255,255,255,0.5), 1050px 350px 0 rgba(255,255,255,0.7),
    70px 150px 0 rgba(255,255,255,0.4), 180px 90px 0 rgba(255,255,255,0.3), 270px 300px 0 rgba(255,255,255,0.5),
    420px 180px 0 rgba(255,255,255,0.4), 580px 340px 0 rgba(255,255,255,0.3);
  animation: twinkle 4s ease-in-out infinite alternate;
}
.stars::after {
  box-shadow:
    100px 120px 0 rgba(255,255,255,0.5), 250px 80px 0 rgba(255,255,255,0.8), 380px 250px 0 rgba(255,255,255,0.4),
    520px 130px 0 rgba(255,255,255,0.7), 680px 320px 0 rgba(255,255,255,0.5), 820px 70px 0 rgba(255,255,255,0.9),
    960px 220px 0 rgba(255,255,255,0.6), 130px 280px 0 rgba(255,255,255,0.4), 330px 350px 0 rgba(255,255,255,0.3),
    560px 280px 0 rgba(255,255,255,0.5), 780px 400px 0 rgba(255,255,255,0.7), 920px 360px 0 rgba(255,255,255,0.4),
    1080px 80px 0 rgba(255,255,255,0.6);
  animation: twinkle 5s ease-in-out infinite alternate-reverse;
}
@keyframes twinkle {
  0% { opacity: 0.4; }
  100% { opacity: 1; }
}

/* === Header === */
.header {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 40px 20px 20px;
  border-bottom: 1px solid rgba(212, 165, 116, 0.3);
}
.title {
  font-family: var(--font-heading);
  font-size: 2.5rem;
  color: var(--gold);
  text-shadow: 0 0 20px rgba(212, 165, 116, 0.4);
  letter-spacing: 4px;
}
.subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 8px;
}

/* === Mode Selector === */
.mode-selector {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 24px 20px;
  flex-wrap: wrap;
}
.mode-btn {
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 24px;
  border: 1px solid rgba(212, 165, 116, 0.3);
  border-radius: 25px;
  background: rgba(26, 10, 62, 0.5);
  color: var(--text-secondary);
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: all 0.3s ease;
}
.mode-btn:hover {
  border-color: var(--gold);
  color: var(--gold-light);
  transform: translateY(-1px);
}
.mode-btn.active {
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.25), rgba(166, 124, 82, 0.25));
  border-color: var(--gold);
  color: var(--gold);
  box-shadow: 0 0 15px rgba(212, 165, 116, 0.3);
}

/* === Question Input === */
.question-section {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 10px 20px 0;
}
.question-input-wrapper {
  display: flex;
  align-items: center;
  max-width: 460px;
  margin: 0 auto;
  background: rgba(26, 10, 62, 0.5);
  border: 1px solid rgba(212, 165, 116, 0.25);
  border-radius: 25px;
  backdrop-filter: blur(6px);
  transition: all 0.3s ease;
}
.question-input-wrapper:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(212, 165, 116, 0.2);
}
.question-icon {
  font-size: 1.2rem;
  padding-left: 16px;
  opacity: 0.7;
}
.question-input {
  flex: 1;
  background: none;
  border: none;
  padding: 12px 16px;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text-primary);
  outline: none;
}
.question-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
}
.question-hint {
  font-size: 0.7rem;
  color: var(--text-secondary);
  opacity: 0.5;
  margin-top: 6px;
  font-style: italic;
}

/* === Deal Button === */
.deal-section {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 10px 0 30px;
}
.deal-btn {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  padding: 14px 48px;
  border: 2px solid var(--gold);
  border-radius: 30px;
  background: linear-gradient(135deg, rgba(26, 10, 62, 0.8), rgba(46, 20, 80, 0.8));
  color: var(--gold);
  cursor: pointer;
  letter-spacing: 2px;
  transition: all 0.3s ease;
  animation: pulse 2.5s ease-in-out infinite;
}
.deal-btn:hover {
  background: linear-gradient(135deg, rgba(212, 165, 116, 0.2), rgba(166, 124, 82, 0.2));
  box-shadow: 0 0 30px rgba(212, 165, 116, 0.4);
  transform: translateY(-2px);
}
.deal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  animation: none;
  transform: none;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 10px rgba(212, 165, 116, 0.2); }
  50% { box-shadow: 0 0 30px rgba(212, 165, 116, 0.5); }
}

/* === Spread Area === */
.spread-area {
  position: relative;
  z-index: 1;
  min-height: 300px;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.placeholder-text {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 1.1rem;
  opacity: 0.7;
}

/* Layout: Single */
.spread-area[data-layout="single"] {
  flex-direction: column;
  gap: 20px;
}
.spread-area[data-layout="single"] .card-wrapper {
  margin: 0 auto;
}

/* Layout: Three */
.spread-area[data-layout="three"] {
  flex-direction: row;
  gap: 50px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  padding-top: 40px;
}

/* Layout: Celtic Cross */
.spread-area[data-layout="celtic"] {
  position: relative;
  width: 100%;
  max-width: 700px;
  min-height: 520px;
  margin: 0 auto;
  padding: 20px 10px;
}
.celtic-container {
  position: relative;
  width: 100%;
  height: 520px;
}

/* === Card Wrapper === */
.card-wrapper {
  perspective: 1200px;
  width: 120px;
  height: 200px;
  cursor: pointer;
  flex-shrink: 0;
}
.card-wrapper.deal-anim {
  animation: dealIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes dealIn {
  0% {
    opacity: 0;
    transform: translateY(-120px) scale(0.5) rotateZ(-3deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotateZ(0deg);
  }
}

/* === Card Inner (flip container) === */
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.7s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}
.card-wrapper.flipped .card-inner {
  transform: rotateY(180deg);
}
.card-wrapper.flipped:hover .card-inner {
  transform: rotateY(180deg) translateY(-4px);
}
.card-wrapper:not(.flipped):hover .card-inner {
  transform: translateY(-4px);
}
.card-wrapper:not(.flipped):hover {
  filter: drop-shadow(0 8px 24px rgba(212, 165, 116, 0.5));
}

/* === Card Front & Back === */
.card-front, .card-back {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-card);
  overflow: hidden;
}

/* Card Back */
.card-back {
  background: linear-gradient(145deg, #1a0a3e 0%, #2d1b69 50%, #1a0a3e 100%);
  border: 2px solid var(--gold-dark);
  box-shadow: var(--shadow-gold);
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-back-inner {
  text-align: center;
  color: var(--gold);
}
.card-back-star {
  font-size: 2rem;
  line-height: 1;
  text-shadow: 0 0 10px rgba(212, 165, 116, 0.5);
  animation: starGlow 3s ease-in-out infinite;
}
@keyframes starGlow {
  0%, 100% { text-shadow: 0 0 8px rgba(212, 165, 116, 0.3); }
  50% { text-shadow: 0 0 20px rgba(212, 165, 116, 0.7); }
}
.card-back-border {
  width: 80px; height: 140px;
  border: 2px solid var(--gold-dark);
  border-radius: 4px;
  margin: 0 auto 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.2);
}
.card-back-label {
  font-family: var(--font-heading);
  font-size: 0.55rem;
  letter-spacing: 2px;
  opacity: 0.7;
}

/* Card Front */
.card-front {
  transform: rotateY(180deg);
  background: var(--card-front-bg);
  border: 2px solid var(--gold-dark);
  box-shadow: var(--shadow-gold);
  color: var(--card-front-text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 8px;
}
.card-front-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.card-front-emoji {
  font-size: 2.2rem;
  line-height: 1;
}
.card-front-name {
  font-family: var(--font-heading);
  font-size: 0.9rem;
  font-weight: bold;
  color: #2d1b69;
}
.card-front-en {
  font-size: 0.55rem;
  color: #6b5a8e;
  font-style: italic;
}
.card-front-suit {
  font-size: 0.7rem;
  color: #8b7a5e;
}
.card-front-position {
  font-family: var(--font-heading);
  font-size: 0.65rem;
  color: var(--gold-dark);
  background: rgba(212, 165, 116, 0.15);
  padding: 2px 10px;
  border-radius: 10px;
}

/* Reversed card */
.card-wrapper.reversed .card-front-content {
  transform: rotate(180deg);
}
.card-wrapper.reversed.flipped .card-inner {
  transform: rotateY(180deg);
}

/* === Card Label (below card) === */
.card-label {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  color: var(--gold);
  margin-top: 10px;
  opacity: 0;
  transition: opacity 0.5s ease;
}
.card-wrapper.flipped + .card-label,
.card-wrapper.flipped ~ .card-label {
  opacity: 1;
}

/* For three-card layout, labels are always visible */
.spread-area[data-layout="three"] .card-label {
  opacity: 0.8;
}
.spread-area[data-layout="three"] .card-wrapper.flipped + .card-label {
  opacity: 1;
  text-shadow: 0 0 10px rgba(212, 165, 116, 0.4);
}

/* === Celtic Cross Card Positions === */
.celtic-card {
  position: absolute;
}
.celtic-card .card-wrapper {
  width: 90px;
  height: 150px;
}
.celtic-card .card-back-star { font-size: 1.5rem; }
.celtic-card .card-back-border { width: 56px; height: 98px; }
.celtic-card .card-front-emoji { font-size: 1.6rem; }
.celtic-card .card-front-name { font-size: 0.7rem; }
.celtic-card .card-front-en { font-size: 0.5rem; }
.celtic-card .card-front-position { font-size: 0.55rem; padding: 1px 8px; }

.celtic-card .celtic-label {
  text-align: center;
  font-family: var(--font-heading);
  font-size: 0.65rem;
  color: var(--gold);
  margin-top: 4px;
  opacity: 0.7;
  width: 90px;
}

/* Celtic layout positions */
.celtic-pos-1 { top: 38%; left: 38%; }       /* Present - center */
.celtic-pos-2 { top: 38%; left: 44%; }        /* Crossing - offset right */
.celtic-pos-3 { top: 68%; left: 38%; }        /* Below */
.celtic-pos-4 { top: 38%; left: 8%; }         /* Past - far left */
.celtic-pos-5 { top: 8%; left: 38%; }          /* Above */
.celtic-pos-6 { top: 38%; left: 68%; }        /* Future - far right */
.celtic-pos-7 { top: 82%; left: 2%; }          /* Bottom row */
.celtic-pos-8 { top: 82%; left: 26%; }
.celtic-pos-9 { top: 82%; left: 50%; }
.celtic-pos-10 { top: 82%; left: 74%; }

/* Crossing card rotation */
.celtic-pos-2 .card-inner {
  transform: rotate(90deg);
}
.celtic-pos-2 .card-wrapper.flipped .card-inner {
  transform: rotateY(180deg) rotate(90deg);
}

/* === Reading Panel === */
.reading-panel {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 30px auto 0;
  padding: 0 20px;
  display: none;
}
.reading-panel.visible {
  display: block;
  animation: fadeInUp 0.6s ease both;
}
@keyframes fadeInUp {
  0% { opacity: 0; transform: translateY(20px); }
  100% { opacity: 1; transform: translateY(0); }
}
.reading-card {
  background: rgba(18, 0, 37, 0.7);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 16px;
  backdrop-filter: blur(10px);
  border-left: 4px solid var(--gold);
  transition: all 0.3s ease;
}
.reading-card.reversed-card {
  border-left-color: var(--reversed-accent);
}
.reading-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.reading-card-emoji {
  font-size: 2rem;
}
.reading-card-info h3 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--gold);
}
.reading-card-info .reading-card-en {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-style: italic;
}
.reading-card-direction {
  display: inline-block;
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 10px;
  margin-left: 8px;
}
.reading-card-direction.upright {
  background: rgba(212, 165, 116, 0.2);
  color: var(--gold);
}
.reading-card-direction.reversed {
  background: rgba(220, 38, 38, 0.2);
  color: #f87171;
}
.reading-card-keywords {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.reading-card-keywords span {
  color: var(--gold-light);
}
.reading-card-desc {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-primary);
}

/* === AI Reading Section === */
.ai-reading-section {
  margin-top: 24px;
}
.ai-reading-section hr {
  border: none;
  border-top: 1px solid rgba(212, 165, 116, 0.3);
  margin-bottom: 20px;
}
.ai-reading-card {
  background: rgba(212, 165, 116, 0.05);
  border: 1px solid rgba(212, 165, 116, 0.25);
  border-radius: 12px;
  padding: 24px;
  backdrop-filter: blur(10px);
}
.ai-reading-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  color: var(--gold);
}
.ai-reading-header .ai-icon {
  font-size: 1.4rem;
}
.ai-reading-question {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  padding: 8px 14px;
  background: rgba(26, 10, 62, 0.4);
  border-radius: 8px;
  border-left: 3px solid var(--gold);
}
.ai-reading-question span {
  color: var(--text-primary);
}
.ai-reading-content {
  font-size: 0.9rem;
  line-height: 1.85;
  color: var(--text-primary);
}
.ai-reading-content p {
  margin-bottom: 10px;
}
.ai-reading-content strong {
  color: var(--gold-light);
}
.ai-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 30px;
  color: var(--text-secondary);
}
.ai-loading-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gold);
  animation: loadingDot 1.2s ease-in-out infinite;
}
.ai-loading-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-loading-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes loadingDot {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.3); }
}
.ai-error {
  color: #f87171;
  text-align: center;
  padding: 16px;
  font-size: 0.85rem;
}
.ai-config-hint {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.ai-config-hint code {
  background: rgba(26, 10, 62, 0.5);
  padding: 2px 8px;
  border-radius: 4px;
  color: var(--gold-light);
  font-size: 0.8rem;
}

/* === Celtic connection lines === */
.celtic-lines {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 0;
}
.celtic-lines svg {
  width: 100%;
  height: 100%;
}
.celtic-lines line {
  stroke: rgba(212, 165, 116, 0.2);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

/* === Responsive === */
@media (max-width: 768px) {
  .title { font-size: 1.8rem; letter-spacing: 2px; }
  .subtitle { font-size: 0.85rem; }

  .mode-selector { gap: 8px; padding: 16px 10px; }
  .mode-btn { padding: 8px 16px; font-size: 0.8rem; }

  .question-section { padding: 8px 16px 0; }
  .question-input { font-size: 16px; padding: 10px 12px; }

  .deal-btn { width: 80%; max-width: 320px; font-size: 1.1rem; padding: 14px 32px; }

  .spread-area[data-layout="three"] {
    flex-direction: column;
    align-items: center;
    gap: 30px;
  }

  .spread-area[data-layout="celtic"] {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .celtic-container {
    min-width: 600px;
    transform: scale(0.7);
    transform-origin: top center;
  }

  .card-wrapper { width: 100px; height: 166px; }
  .card-front-emoji { font-size: 1.8rem; }
  .card-front-name { font-size: 0.8rem; }

  .reading-panel { padding: 0 12px; }
  .reading-card { padding: 14px 16px; }
  .reading-card-header { flex-direction: row; gap: 8px; }
  .reading-card-desc { font-size: 0.85rem; line-height: 1.6; }

  .ai-reading-card { padding: 16px; }
  .ai-reading-content { font-size: 0.85rem; }
  .ai-reading-header { font-size: 1rem; }
}

@media (max-width: 400px) {
  .title { font-size: 1.5rem; }
  .question-input { font-size: 16px; }
  .deal-btn { width: 90%; font-size: 1rem; }
  .celtic-container { transform: scale(0.55); }
  .card-wrapper { width: 85px; height: 140px; }
  .reading-card { padding: 12px; border-radius: 8px; }
  .reading-card-desc { font-size: 0.8rem; }
  .ai-reading-content { font-size: 0.8rem; }
  .ai-reading-question { font-size: 0.78rem; }
}
