/* ============================================================
 *  RESET & BASE
 *  ============================================================ */
.tarot-oracle-wrapper *,
.tarot-oracle-wrapper *::before,
.tarot-oracle-wrapper *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.tarot-oracle-wrapper {
  --bg-primary: transparent;
  --bg-secondary: rgba(0, 0, 0, 0.03);
  --bg-card: rgba(0, 0, 0, 0.05);
  --bg-card-hover: rgba(0, 0, 0, 0.08);
  --border-glow: #aaa;
  --gold: #b8860b;
  --gold-dim: #8b6914;
  --purple: #6a4b8a;
  --purple-dim: #4a2d63;
  --text-primary: inherit;
  --text-secondary: inherit;
  --text-muted: #888;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  --radius: 14px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-serif: "Georgia", "Times New Roman", serif;
  --font-sans: "Segoe UI", "Helvetica Neue", Arial, sans-serif;

  display: block;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 60px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  min-height: 100vh;
}

/* ============================================================
 *  PASOS
 *  ============================================================ */
.tarot-step {
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.tarot-step[style*="display:none"] {
  display: none !important;
}
.tarot-step.visible {
  display: block !important;
  animation: fadeUp 0.5s ease;
}
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================================
 *  PREGUNTA
 *  ============================================================ */
.tarot-question {
  margin: 28px 0 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.tarot-question label {
  font-size: 0.95rem;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  font-weight: 300;
}
.tarot-question input {
  width: 100%;
  max-width: 620px;
  padding: 14px 22px;
  border-radius: 50px;
  border: 1px solid var(--purple-dim);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: var(--font-sans);
  transition: var(--transition);
  outline: none;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.1);
}
.tarot-question input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 20px rgba(184, 134, 11, 0.15), inset 0 2px 8px rgba(0, 0, 0, 0.1);
}
.tarot-question input::placeholder {
  color: var(--text-muted);
  font-style: italic;
  opacity: 0.7;
}
.btn-secondary {
  padding: 14px 28px;
  border-radius: 50px;
  border: 1px solid var(--purple-dim);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.04em;
  display: inline-block;
}
.btn-secondary:hover {
  border-color: var(--gold-dim);
  color: var(--text-primary);
  background: rgba(184, 134, 11, 0.06);
}

/* ============================================================
 *  SELECTOR DE CARTAS (paso 2)
 *  ============================================================ */
#tarotSpreadHelp {
  text-align: center;
  color: var(--gold);
  font-size: 1.1rem;
  margin-bottom: 16px;
  font-weight: 500;
  letter-spacing: 0.05em;
}

.tarot-spread-selector {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px 30px;
  margin: 18px 0 10px;
}
.spread-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.tarot-spread-selector button {
  padding: 12px 28px;
  border-radius: 50px;
  border: 1px solid var(--purple-dim);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.04em;
  font-weight: 400;
  backdrop-filter: blur(4px);
  width: 100%;
  min-width: 120px;
}
.tarot-spread-selector button:hover {
  border-color: var(--gold-dim);
  color: var(--text-primary);
  background: rgba(184, 134, 11, 0.06);
}
.tarot-spread-selector button.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(184, 134, 11, 0.1);
  box-shadow: 0 0 24px rgba(184, 134, 11, 0.07);
}
.spread-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  letter-spacing: 0.02em;
}

/* ============================================================
 *  SPREAD AREA (cartas seleccionadas)
 *  ============================================================ */
.tarot-spread-area {
  min-height: 150px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid rgba(0, 0, 0, 0.1);
  padding: 18px 14px 14px;
  margin: 6px 0 12px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}
.tarot-spread-area .spread-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px 22px;
  align-items: flex-start;
}
.tarot-spread-area .spread-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 0 1 120px;
  min-width: 75px;
  transition: var(--transition);
}
.tarot-spread-area .spread-slot .card-wrapper {
  position: relative;
  width: 100%;
  max-width: 120px;
  aspect-ratio: 5 / 8;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  border: 2px solid transparent;
  transition: var(--transition);
  background: var(--bg-card);
}
.tarot-spread-area .spread-slot .card-wrapper.filled {
  border-color: var(--gold-dim);
}
.tarot-spread-area .spread-slot .card-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
}
.tarot-spread-area .spread-slot .card-wrapper img.reversed {
  transform: rotate(180deg);
}

/* Borde morado cuando la carta está invertida */
.tarot-spread-area .spread-slot .card-wrapper.reversed.filled {
  border-color: var(--purple);
  box-shadow: 0 0 0 2px rgba(106, 75, 138, 0.25),
              0 4px 24px rgba(0, 0, 0, 0.2);
}

/* Badge circular "↻" en la esquina superior derecha */
.tarot-spread-area .spread-slot .card-wrapper .orientation-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--purple);
  color: #fff;
  font-size: 13px;
  line-height: 22px;
  text-align: center;
  font-weight: 700;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.25);
  animation: fadeUp 0.35s ease;
}

.tarot-spread-area .spread-slot .card-name {
  font-size: 0.65rem;
  color: var(--gold);
  letter-spacing: 0.04em;
  text-align: center;
  font-weight: 400;
  font-family: var(--font-sans);
  min-height: 1.2em;
  line-height: 1.3;
  margin-top: 1px;
}
.tarot-spread-area .spread-slot .position-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 400;
  text-align: center;
  min-height: 1.2em;
}

/* Etiqueta explícita "Invertida" o "Al derecho" bajo cada carta */
.tarot-spread-area .spread-slot .orientation-label {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-top: 1px;
  padding: 1px 6px;
  border-radius: 8px;
  line-height: 1.4;
}
.tarot-spread-area .spread-slot .orientation-label.upright {
  color: var(--gold-dim);
  background: rgba(184, 134, 11, 0.08);
}
.tarot-spread-area .spread-slot .orientation-label.reversed {
  color: #fff;
  background: var(--purple);
}

/* ============================================================
 *  CONTADOR
 *  ============================================================ */
.tarot-counter {
  text-align: center;
  font-size: 1.1rem;
  color: var(--text-secondary);
  padding: 8px 0 14px;
  letter-spacing: 0.06em;
  font-weight: 500;
  border-top: 1px solid rgba(0,0,0,0.05);
  border-bottom: 1px solid rgba(0,0,0,0.05);
  margin: 0 0 12px 0;
}
.tarot-counter .highlight {
  color: var(--gold);
  font-weight: 700;
}

/* ============================================================
 *  MAZO — GRID RESPONSIVO (paso 3)
 *  ============================================================ */
.tarot-deck-section {
  margin: 10px 0 20px;
  transition: opacity 0.6s ease, transform 0.6s ease, max-height 0.6s ease, margin 0.6s ease;
  overflow: hidden;
}
.tarot-deck-section.hidden {
  opacity: 0;
  transform: scale(0.95);
  max-height: 0;
  margin: 0;
  pointer-events: none;
}
.tarot-deck-section .deck-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding-left: 4px;
  font-weight: 300;
}

.tarot-deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 10px;
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 520px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.tarot-deck-grid::-webkit-scrollbar {
  width: 6px;
}
.tarot-deck-grid::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

.tarot-deck-grid .deck-card {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 8;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-card);
  border: 2px solid transparent;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s ease, box-shadow 0.2s ease,
              border-color 0.2s ease, opacity 0.3s ease;
  outline: none;
}
.tarot-deck-grid .deck-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  user-select: none;
}
.tarot-deck-grid .deck-card:hover:not(.selected),
.tarot-deck-grid .deck-card:focus-visible:not(.selected) {
  transform: translateY(-4px) scale(1.06);
  border-color: var(--gold);
  box-shadow: 0 10px 22px rgba(184, 134, 11, 0.35);
  z-index: 2;
}
.tarot-deck-grid .deck-card.selected {
  cursor: default;
  border-color: var(--gold);
  opacity: 0.45;
  transform: scale(0.92);
  box-shadow: 0 0 0 2px rgba(184, 134, 11, 0.35);
}
.tarot-deck-grid .deck-card.selected::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--gold);
  color: #fff;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}

.tarot-deck-grid .deck-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  font-style: italic;
  padding: 40px 0;
  font-size: 1rem;
  opacity: 0.7;
}

/* ============================================================
 *  RESULTADO (paso 4)
 *  ============================================================ */
#tarotResultQuestion {
  margin-bottom: 20px;
}
#tarotResultQuestion h3 {
  color: var(--gold);
  margin-bottom: 8px;
}
#tarotResultQuestion blockquote {
  font-style: italic;
  color: var(--text-secondary);
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin: 0 0 20px 0;
}
.tarot-interpretation {
  display: none;
  margin-top: 20px;
  padding: 28px 24px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: var(--shadow);
  animation: fadeUp 0.5s ease;
}
.tarot-interpretation.active {
  display: block;
}
.tarot-interpretation .interp-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  padding-bottom: 16px;
  margin-bottom: 20px;
}
.tarot-interpretation .interp-header h2 {
  font-family: var(--font-serif);
  font-size: 1.6rem;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--gold);
}
.tarot-interpretation .interp-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tarot-interpretation .interp-actions button {
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: var(--text-secondary);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-sans);
}
.tarot-interpretation .interp-actions button:hover {
  background: rgba(184, 134, 11, 0.1);
  border-color: var(--gold-dim);
  color: var(--text-primary);
}
.tarot-interpretation .interp-body {
  font-family: var(--font-serif);
  line-height: 1.8;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 1rem;
}
.tarot-interpretation .interp-body h2,
.tarot-interpretation .interp-body h3,
.tarot-interpretation .interp-body h4 {
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--gold);
  margin: 0.8em 0 0.2em 0;
}
.tarot-interpretation .interp-body h2 {
  font-size: 1.3rem;
}
.tarot-interpretation .interp-body h3 {
  font-size: 1.1rem;
}
.tarot-interpretation .interp-body h4 {
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tarot-interpretation .interp-body p {
  margin: 0.3em 0;
  line-height: 1.6;
}
.tarot-interpretation .interp-body hr {
  margin: 0.6em 0;
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}
.tarot-interpretation .interp-body strong {
  color: var(--gold);
  font-weight: 600;
}
.tarot-interpretation .interp-time {
  margin-top: 18px;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  padding-top: 14px;
  letter-spacing: 0.04em;
}

/* ============================================================
 *  ERROR & LOADING
 *  ============================================================ */
.tarot-error-box {
  display: none;
  margin: 16px 0;
  padding: 18px 24px;
  background: rgba(180, 50, 50, 0.08);
  border: 1px solid rgba(180, 50, 50, 0.2);
  border-radius: var(--radius);
  color: #a04040;
  font-size: 0.95rem;
  text-align: center;
  line-height: 1.6;
  animation: fadeUp 0.3s ease;
}
.tarot-error-box.active {
  display: block;
}
.tarot-error-box .error-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-family: var(--font-sans);
}

.tarot-loading-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 18px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.tarot-loading-overlay.active {
  display: flex;
  opacity: 1;
  animation: fadeUp 0.3s ease;
}
.tarot-loading-overlay .loading-spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid var(--purple-dim);
  border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.tarot-loading-overlay p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}
.tarot-loading-overlay .elapsed {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
 *  BOTÓN NUEVA TIRADA
 *  ============================================================ */
.tarot-new-reading-btn {
  text-align: center;
  margin-top: 20px;
}

/* ============================================================
 *  RESPONSIVE
 *  ============================================================ */
@media (max-width: 768px) {
  .tarot-oracle-wrapper {
    padding: 12px 10px 40px;
  }
  .tarot-spread-area {
    padding: 12px 8px 10px;
    min-height: 110px;
    margin: 4px 0 8px;
  }
  .tarot-spread-area .spread-slot {
    flex: 0 1 90px;
    min-width: 60px;
  }
  .tarot-spread-area .spread-slot .card-wrapper {
    max-width: 90px;
  }
  .tarot-deck-section {
    margin: 6px 0 12px;
  }
  .tarot-deck-section .deck-title {
    margin-bottom: 8px;
    font-size: 0.8rem;
  }
  #tarotDeckHint {
    margin-bottom: 8px !important;
    font-size: 0.9rem !important;
  }
  .tarot-deck-grid {
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 8px;
    padding: 10px;
    max-height: 380px;
  }
  .tarot-counter {
    padding: 6px 0 10px;
    font-size: 0.95rem;
    margin-bottom: 8px;
  }
  .tarot-interpretation {
    padding: 20px 16px;
  }
  .tarot-interpretation .interp-header h2 {
    font-size: 1.3rem;
  }
  .tarot-spread-selector {
    gap: 15px;
  }
  .tarot-spread-selector button {
    padding: 10px 20px;
    font-size: 0.9rem;
    min-width: 100px;
  }
  .tarot-question input {
    padding: 12px 18px;
    font-size: 0.9rem;
  }
}

@media (max-width: 480px) {
  /* --- Área de selección (paso 3): compacta pero multi-fila --- */
  #tarotSpreadArea {
    padding: 8px 6px 6px;
    min-height: 80px;
    margin: 4px 0 6px;
  }
  #tarotSpreadArea .spread-grid {
    gap: 8px 10px;
  }
  #tarotSpreadArea .spread-slot {
    flex: 0 1 56px;
    min-width: 44px;
  }
  #tarotSpreadArea .spread-slot .card-wrapper {
    max-width: 56px;
  }
  #tarotSpreadArea .spread-slot .card-wrapper .orientation-badge {
    width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 10px;
    top: 2px;
    right: 2px;
  }
  #tarotSpreadArea .spread-slot .card-name {
    font-size: 0.5rem;
    line-height: 1.1;
  }
  #tarotSpreadArea .spread-slot .orientation-label {
    font-size: 0.5rem;
    padding: 0 4px;
    margin-top: 0;
  }
  #tarotSpreadArea .spread-slot .position-label {
    font-size: 0.5rem;
    letter-spacing: 0.06em;
  }

  /* --- Área de resultado (paso 4): una sola fila horizontal con scroll --- */
  #tarotSpreadAreaResult {
    padding: 8px 6px 6px;
    min-height: 0;
    max-height: none;
    margin: 4px 0 6px;
  }
  #tarotSpreadAreaResult .spread-grid {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    gap: 8px;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #tarotSpreadAreaResult .spread-grid::-webkit-scrollbar {
    display: none;
  }
  #tarotSpreadAreaResult .spread-slot {
    flex: 0 0 auto;
    min-width: 54px;
    gap: 1px;
  }
  #tarotSpreadAreaResult .spread-slot .card-wrapper {
    max-width: 54px;
    width: 54px;
  }
  #tarotSpreadAreaResult .spread-slot .card-wrapper .orientation-badge {
    width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 10px;
    top: 2px;
    right: 2px;
  }
  #tarotSpreadAreaResult .spread-slot .card-name {
    font-size: 0.5rem;
    line-height: 1.1;
  }
  #tarotSpreadAreaResult .spread-slot .orientation-label {
    font-size: 0.5rem;
    padding: 0 4px;
    margin-top: 0;
  }
  #tarotSpreadAreaResult .spread-slot .position-label {
    font-size: 0.5rem;
    letter-spacing: 0.06em;
  }

  /* --- Resto de ajustes móvil --- */
  .tarot-deck-grid {
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 6px;
    padding: 8px;
    max-height: 300px;
  }
  .tarot-spread-selector {
    flex-direction: column;
    align-items: center;
  }
  .spread-option {
    width: 100%;
    max-width: 250px;
  }
  .tarot-loading-overlay {
    padding: 28px 16px;
  }
  .tarot-loading-overlay .loading-spinner {
    width: 46px;
    height: 46px;
  }
}

/* ============================================================
 *  UTILITY
 *  ============================================================ */
.tarot-oracle-wrapper .hidden {
  display: none !important;
}
.tarot-oracle-wrapper .text-gold {
  color: var(--gold);
}

#tarot-oracle-app { padding-top: 0px; }
.tarot-question { margin-top: 0px; }
.tarot-question h3 { text-align: center; }
#tarotInterpBody p {max-width:100%;}
