/* Base Styles */
:root {
  --primary-color: #8a2be2;
  --secondary-color: #ff69b4;
  --tertiary-color: #1e90ff;
  --background-start: #f8f9fa;
  --background-end: #e9ecef;
  --text-color: #2d3748;
  --light-text: #718096;
  --card-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  --card-glow: 0 0 15px rgba(138, 43, 226, 0.3);
  --modal-bg: rgba(255, 255, 255, 0.95);
  --border-radius: 12px;
  --transition-speed: 0.3s;
}

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

body {
  font-family: 'Montserrat', sans-serif;
  background: linear-gradient(135deg, var(--background-start), var(--background-end));
  color: var(--text-color);
  min-height: 100vh;
  line-height: 1.6;
  padding: 0;
  margin: 0;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Typography */
h1, h2 {
  font-family: 'Playfair Display', serif;
  font-weight: 500;
  letter-spacing: 0.5px;
}

h1 {
  font-size: 2.5rem;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-align: center;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  text-align: center;
}

.subtitle {
  text-align: center;
  color: var(--light-text);
  font-size: 1rem;
  margin-bottom: 1.5rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 1rem;
}

/* Selection Counter */
.selection-counter {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 500;
  margin-bottom: 1rem;
  padding: 0.5rem;
  background: rgba(255, 255, 255, 0.7);
  border-radius: var(--border-radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Cards Grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr); /* 6 cards per row */
  gap: 16px;
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
  justify-items: center;
}

.card {
  width: 100px;
  height: 160px;
}

/* Card Styles */
.card {
  position: relative;
  height: 160px;
  perspective: 1000px;
  cursor: pointer;
  margin: 0 auto;
  width: 100%;
  max-width: 100px;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.8s;
  transform-style: preserve-3d;
  box-shadow: var(--card-shadow);
  border-radius: var(--border-radius);
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  border-radius: var(--border-radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-front {
  transform: rotateY(180deg);
  background-color: white;
}

.card-back {
  background-color: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.3rem;
  font-size: 0.7rem;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card.selected .card-inner {
  box-shadow: 0 0 0 2px var(--primary-color), var(--card-glow);
}

.card.disabled {
  opacity: 0.5;
  pointer-events: none;
}

/* Selected Cards */
.selected-cards-container {
  margin-top: 2rem;
}

.selected-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: center;
}

.selected-card {
  width: 100px;
  height: 160px;
  position: relative;
  border-radius: var(--border-radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
}

.selected-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.selected-card-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.3rem;
  font-size: 0.7rem;
  text-align: center;
}

/* Buttons */
.action-buttons {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
}

.btn {
  padding: 0.8rem 1.5rem;
  border: none;
  border-radius: 50px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.get-reading-btn {
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  color: white;
}

.get-reading-btn:disabled {
  background: #cccccc;
  cursor: not-allowed;
  opacity: 0.7;
}

.get-reading-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}

.start-over-btn {
  background: white;
  color: var(--primary-color);
  border: 1px solid var(--primary-color);
}

.start-over-btn:hover {
  background: var(--primary-color);
  color: white;
}

/* Reading Modal */
.reading-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-speed) ease;
}

.reading-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.reading-content {
  background: var(--modal-bg);
  padding: 2rem;
  border-radius: var(--border-radius);
  max-width: 90%;
  width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  position: relative;
  border: 1px solid rgba(138, 43, 226, 0.2);
}

.reading-text {
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-speed) ease;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(138, 43, 226, 0.1);
  border-radius: 50%;
  border-top: 4px solid var(--primary-color);
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Media Queries */
@media (min-width: 768px) {
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
  
  .card, .selected-card {
    max-width: 120px;
    height: 192px;
  }
  
  h1 {
    font-size: 3rem;
  }
  
  .subtitle {
    font-size: 1.2rem;
  }
}

@media (min-width: 1024px) {
  .app-container {
    padding: 2rem;
  }
  
  .cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }
  
  .card, .selected-card {
    max-width: 140px;
    height: 224px;
  }
  
  .card-name, .selected-card-name {
    font-size: 0.8rem;
  }
  .reading-section {
  margin-top: 30px;
  padding: 20px;
  border-top: 2px solid #ccc;
}

#chat-box {
  margin-top: 20px;
}

#chat-log {
  margin-bottom: 10px;
  max-height: 200px;
  overflow-y: auto;
}

.chat-entry {
  margin: 8px 0;
}

.chat-entry.user {
  color: #333;
}

.chat-entry.bot {
  color: #444;
  background: #f5f5f5;
  padding: 10px;
  border-radius: 6px;
}
/* --- Updated Tarot Chat Box --- */
#chat-box {
  display: flex;
  flex-direction: column;
  border: 1px solid #ddd;
  border-radius: 12px;
  margin-top: 30px;
  background: #fff;
  box-shadow: var(--card-shadow);
  max-height: 400px;
  overflow: hidden;
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #f9f9f9;
}

.chat-entry {
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  max-width: 85%;
  word-wrap: break-word;
}

.chat-entry.user {
  align-self: flex-end;
  background-color: var(--tertiary-color);
  color: white;
}

.chat-entry.bot {
  align-self: flex-start;
  background-color: #eee;
  color: #333;
}

#chat-input-container {
  display: flex;
  border-top: 1px solid #ddd;
}

#chat-input {
  flex: 1;
  padding: 12px;
  border: none;
  font-size: 14px;
  outline: none;
  border-radius: 0 0 0 12px;
}

#chat-send-btn {
  padding: 12px 20px;
  border: none;
  background-color: var(--primary-color);
  color: white;
  font-size: 14px;
  cursor: pointer;
  border-radius: 0 0 12px 0;
}

#chat-send-btn:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

#chat-end-message {
  text-align: center;
  padding: 12px;
  font-style: italic;
  color: var(--light-text);
}