/* ===== ORÁCULO DE LA LOTERÍA MEXICANA — styles.css ===== */
/* Mobile-first. Probado en 360px, 390px, 414px, 768px, 1024px */

*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --gold:  #ffaa32;
  --gold2: #ffcc00;
  --red:   #c0392b;
  --red2:  #922b21;
  --dark:  #1a0a0a;
  --text:  #f0d080;
  --muted: #cc8844;
  --card-bg: #fdf6e3;
  --card-bg2: #f5e6c0;
}

html { height: 100%; }

body {
  font-family: 'Cormorant Garamond', serif;
  background: linear-gradient(150deg, #1a0a0a 0%, #2d1117 35%, #1a0f00 65%, #0d0805 100%);
  min-height: 100vh;
  position: relative;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

#particles-canvas, #stars-canvas {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}

.fog {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center, transparent 0%, rgba(26,10,10,0.4) 100%);
  animation: fogMove 22s ease-in-out infinite alternate;
  z-index: 1; pointer-events: none; will-change: transform;
}
@keyframes fogMove {
  0%   { transform: translate(-4%,-4%); opacity: .28; }
  100% { transform: translate(4%,4%);   opacity: .52; }
}
@media (prefers-reduced-motion: reduce) { .fog { animation: none; opacity: .22; } }

/* ===== LAYOUT ===== */
.container {
  position: relative; z-index: 10;
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 14px 80px;
}

/* ===== HEADER ===== */
.header {
  text-align: center;
  margin-bottom: 24px;
  padding-top: 50px;
}

.title {
  font-family: 'Cinzel Decorative', serif;
  font-size: clamp(1.5rem, 5.5vw, 2.4rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold) 0%, #ff6b35 30%, var(--gold2) 60%, #e8a020 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  line-height: 1.2;
}

.subtitle {
  font-family: 'Cinzel', serif;
  font-size: clamp(0.68rem, 2.2vw, 0.88rem);
  color: var(--gold);
  letter-spacing: 0.15em;
  opacity: 0.82;
  word-break: break-word;
}

/* ===== BACK BUTTON ===== */
.back-button {
  position: fixed;
  top: 12px; left: 12px;
  z-index: 100;
  font-family: 'Cinzel', serif;
  font-size: 0.82rem;
  color: var(--gold);
  text-decoration: none;
  background: rgba(26,10,10,0.8);
  border: 1px solid rgba(255,170,50,0.3);
  padding: 8px 15px;
  border-radius: 20px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  min-height: 40px;
  display: flex; align-items: center;
  transition: background .2s, border-color .2s;
}
.back-button:hover { background: rgba(255,170,50,.15); border-color: rgba(255,170,50,.6); }

/* ===== SECCIÓN PREGUNTA ===== */
.question-section {
  background: rgba(255,170,50,.05);
  border: 1px solid rgba(255,170,50,.2);
  border-radius: 14px;
  padding: clamp(16px, 4vw, 28px);
  margin-bottom: 22px;
}

.question-label {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: clamp(0.85rem, 2.8vw, 1rem);
  color: var(--gold);
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.question-input {
  width: 100%;
  min-height: 96px;
  background: rgba(0,0,0,.45);
  border: 1px solid rgba(255,170,50,.25);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Cormorant Garamond', serif;
  font-size: 16px; /* iOS: no zoom */
  line-height: 1.6;
  padding: 12px 14px;
  resize: vertical; outline: none;
  transition: border-color .25s;
  -webkit-appearance: none;
}
.question-input:focus { border-color: rgba(255,170,50,.65); }
.question-input::placeholder { color: rgba(240,208,128,.35); font-style: italic; }

.submit-button {
  margin-top: 14px;
  width: 100%;
  padding: 15px;
  font-family: 'Cinzel', serif;
  font-size: clamp(0.9rem, 3vw, 1.05rem);
  font-weight: 700;
  letter-spacing: 0.07em;
  color: #1a0a0a;
  background: linear-gradient(135deg, var(--gold), #ff8c42, var(--gold2));
  border: none; border-radius: 50px; cursor: pointer;
  box-shadow: 0 0 18px rgba(255,170,50,.3);
  min-height: 50px;
  touch-action: manipulation;
  transition: transform .25s, box-shadow .25s;
}
.submit-button:hover:not(:disabled),
.submit-button:focus:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 32px rgba(255,170,50,.55);
  outline: none;
}
.submit-button:disabled { opacity: .5; cursor: not-allowed; }

/* ===== LOADING ===== */
.loading { display: none; text-align: center; padding: 32px 16px; }
.loading.active { display: block; }

.loading-spinner {
  width: 42px; height: 42px;
  border: 3px solid rgba(255,170,50,.15);
  border-top-color: var(--gold);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: clamp(1rem, 3vw, 1.12rem);
  color: var(--muted);
}

/* ===== CARTE ===== */
.cards-section { display: none; margin-bottom: 28px; }
.cards-section.active { display: block; }

.cards-container {
  display: flex;
  gap: clamp(6px, 2vw, 16px);
  justify-content: center;
  flex-wrap: wrap;
}

.card-wrapper {
  animation: cardReveal .5s ease-out forwards;
  opacity: 0;
  /* Ancho fluido: fill_remaining / n_cartas pero sin overflow */
  flex: 0 0 clamp(105px, calc((100% - 5 * 6px) / 3), 172px);
  max-width: 172px;
}
.card-wrapper:nth-child(1){animation-delay:.08s}
.card-wrapper:nth-child(2){animation-delay:.28s}
.card-wrapper:nth-child(3){animation-delay:.48s}
.card-wrapper:nth-child(4){animation-delay:.68s}
.card-wrapper:nth-child(5){animation-delay:.88s}

@keyframes cardReveal {
  0%   { opacity:0; transform:translateY(20px) scale(.93); }
  100% { opacity:1; transform:translateY(0)   scale(1);    }
}
@media (prefers-reduced-motion: reduce) {
  .card-wrapper { animation: none; opacity: 1; }
}

.loteria-card {
  width: 100%;
  background: linear-gradient(160deg, var(--card-bg), var(--card-bg2));
  border: 3px solid var(--red);
  border-radius: 9px;
  overflow: hidden;
  box-shadow: 0 5px 20px rgba(0,0,0,.55);
  transition: transform .22s;
}
@media (hover: hover) {
  .loteria-card:hover { transform: translateY(-5px) scale(1.02); }
}
.loteria-card:active { transform: scale(.97); }

/* ---- Etichette carta ---- */
.card-position-label {
  background: var(--red);
  color: var(--card-bg);
  font-family: 'Cinzel', serif;
  /* MINIMO LEGGIBILE: 11px */
  font-size: clamp(0.68rem, 1.8vw, 0.72rem);
  letter-spacing: 0.08em;
  text-align: center;
  padding: 4px 5px;
  text-transform: uppercase;
  line-height: 1.2;
}

.card-header {
  background: var(--red);
  color: var(--card-bg);
  text-align: center;
  padding: 4px 6px 5px;
  border-bottom: 2px solid var(--red2);
}
.card-number-label {
  font-family: 'Cinzel', serif;
  font-size: clamp(0.65rem, 1.6vw, 0.72rem);
  opacity: .82;
  letter-spacing: .06em;
}
.card-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(0.75rem, 2.2vw, 0.9rem);
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.2;
}

.card-image-wrapper {
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--card-bg2);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; position: relative;
}
.card-real-image {
  width: 100%; height: 100%;
  object-fit: contain; display: block;
}
.card-emoji-fallback {
  display: none;
  font-size: 2.8rem;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
}

.card-footer {
  background: var(--red);
  border-top: 2px solid var(--red2);
  padding: 4px 6px;
}
.card-verso {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  /* minimo 11px */
  font-size: clamp(0.68rem, 1.6vw, 0.72rem);
  color: var(--card-bg);
  text-align: center;
  line-height: 1.3;
}

.card-meaning-text {
  font-family: 'Cormorant Garamond', serif;
  /* mínimo 12px legible */
  font-size: clamp(0.75rem, 1.9vw, 0.82rem);
  color: #5a2d0c;
  text-align: center;
  padding: 6px 5px 8px;
  line-height: 1.4;
  font-style: italic;
  background: var(--card-bg);
}

/* ===== 5 CARTE (tirada destino) — layout speciale ===== */
/* Móvil estrecho: 2 filas (3 arriba + 2 abajo centradas) */
@media (max-width: 500px) {
  .cards-container.five-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
  }
  .cards-container.five-cards .card-wrapper {
    flex: unset; max-width: unset;
  }
  .cards-container.five-cards .card-wrapper:nth-child(4) {
    grid-column: 1 / 2;
    margin-left: 50%;
    transform: translateX(-50%);
  }
  .cards-container.five-cards .card-wrapper:nth-child(5) {
    grid-column: 3 / 4;
    margin-right: 50%;
    transform: translateX(50%);
  }
  /* Rimuovi il gap tra le carte 4 e 5 su mobile */
  .cards-container.five-cards .card-wrapper:nth-child(4),
  .cards-container.five-cards .card-wrapper:nth-child(5) {
    transform: none;
    margin: 0 auto;
  }
}

/* ===== INTERPRETACIÓN ===== */
.interpretation-section {
  display: none;
  background: rgba(255,170,50,.05);
  border: 1px solid rgba(255,170,50,.2);
  border-radius: 14px;
  padding: clamp(16px, 4vw, 30px);
  animation: fadeUp .7s ease-out both;
}
.interpretation-section.active { display: block; }

@keyframes fadeUp {
  from { opacity:0; transform:translateY(14px); }
  to   { opacity:1; transform:translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .interpretation-section { animation: none; }
}

.interpretation-title {
  font-family: 'Cinzel Decorative', serif;
  font-size: clamp(1.05rem, 4vw, 1.35rem);
  color: var(--gold);
  text-align: center;
  margin-bottom: 18px;
}

.interpretation-text {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(1rem, 3vw, 1.12rem);
  line-height: 1.88;
  color: #e8d090;
  margin-bottom: 22px;
}

.final-response {
  background: rgba(255,170,50,.08);
  border: 1px solid rgba(255,170,50,.28);
  border-radius: 10px;
  padding: clamp(14px, 4vw, 22px);
  margin-top: 14px;
}
.final-response-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(0.88rem, 2.8vw, 1.05rem);
  color: var(--gold2);
  margin-bottom: 10px;
  letter-spacing: .07em;
  text-align: center;
}
.final-response-text {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(1rem, 3vw, 1.12rem);
  font-style: italic;
  line-height: 1.88;
  color: var(--text);
}

/* ===== BOTONES DE ACCIÓN (nueva consulta + PDF) ===== */
.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
  justify-content: center;
}

.new-reading-btn, .pdf-btn {
  padding: 13px 28px;
  font-family: 'Cinzel', serif;
  font-size: clamp(0.85rem, 2.5vw, 0.98rem);
  font-weight: 700;
  letter-spacing: .07em;
  border: none; border-radius: 50px; cursor: pointer;
  min-height: 48px;
  touch-action: manipulation;
  transition: transform .22s, box-shadow .22s;
  text-align: center;
}
.new-reading-btn {
  color: #1a0a0a;
  background: linear-gradient(135deg, var(--gold), #ff8c42, var(--gold2));
  box-shadow: 0 0 16px rgba(255,170,50,.3);
}
.pdf-btn {
  color: var(--card-bg);
  background: linear-gradient(135deg, #2c0a3a, #6b2fa0, #2c0a3a);
  box-shadow: 0 0 16px rgba(107,47,160,.35);
  border: 1px solid rgba(180,100,255,.25);
}
.new-reading-btn:hover, .new-reading-btn:focus { transform:translateY(-2px); box-shadow:0 0 28px rgba(255,170,50,.5); outline:none; }
.pdf-btn:hover, .pdf-btn:focus       { transform:translateY(-2px); box-shadow:0 0 28px rgba(107,47,160,.55); outline:none; }
.new-reading-btn:active, .pdf-btn:active { transform: scale(.97); }

/* ===== EXPLORAR ===== */
.explorar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(95px, 21vw, 148px), 1fr));
  gap: clamp(7px, 1.8vw, 13px);
  margin-top: 8px;
}
.explorar-card { cursor: pointer; }
@media (hover: hover) { .explorar-card:hover .loteria-card { transform: translateY(-4px); } }
.explorar-card:active .loteria-card { transform: scale(.97); }

/* Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.9); z-index: 200;
  align-items: center; justify-content: center;
  padding: 16px;
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }

.modal-content {
  background: linear-gradient(160deg, var(--card-bg), var(--card-bg2));
  border: 3px solid var(--red);
  border-radius: 14px; overflow: hidden;
  max-width: min(340px, 92vw); width: 100%;
  max-height: 88vh; overflow-y: auto;
  box-shadow: 0 18px 50px rgba(0,0,0,.8);
  animation: modalIn .22s ease-out;
  -webkit-overflow-scrolling: touch;
}
@keyframes modalIn { from { opacity:0; transform:scale(.88); } to { opacity:1; transform:scale(1); } }
@media (prefers-reduced-motion: reduce) { .modal-content { animation: none; } }

.modal-header {
  background: var(--red); color: var(--card-bg);
  padding: 10px 14px; text-align: center;
  position: sticky; top: 0; z-index: 1;
}
.modal-header .card-number-label { font-size: .7rem; opacity: .8; }
.modal-header .card-title { font-size: clamp(1rem, 4vw, 1.22rem); }

.modal-image { width:100%; aspect-ratio:2/3; object-fit:contain; display:block; background:var(--card-bg2); }
.modal-body { padding: 14px 18px 16px; background: var(--card-bg); }
.modal-meaning {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(0.9rem, 3vw, 1rem);
  color: #5a2d0c; margin-bottom: 10px; line-height: 1.6;
}
.modal-verso {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: clamp(0.85rem, 2.5vw, 0.9rem);
  color: var(--red2); border-top: 1px solid rgba(192,57,43,.2); padding-top: 10px;
}
.modal-close {
  display: block; margin: 12px auto 0; padding: 9px 28px;
  background: var(--red); color: var(--card-bg);
  border: none; border-radius: 20px; font-family: 'Cinzel', serif;
  font-size: .82rem; cursor: pointer; min-height: 42px; touch-action: manipulation;
  transition: background .2s;
}
.modal-close:hover { background: var(--red2); }

/* ===== VALIDACIÓN ===== */
.question-error {
  display: none; margin-top: 10px;
  padding: 11px 14px;
  background: rgba(192,57,43,.12);
  border: 1px solid rgba(192,57,43,.4);
  border-radius: 10px;
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(0.9rem, 2.8vw, 1rem);
  color: #ffb09a; line-height: 1.5;
  animation: shakeErr .4s ease-out;
}
.question-error.active { display: block; }
.question-error::before { content: '⚠️ '; }
@keyframes shakeErr {
  0%,100%{transform:translateX(0)}20%{transform:translateX(-6px)}
  40%{transform:translateX(6px)}60%{transform:translateX(-4px)}80%{transform:translateX(4px)}
}
.question-input.invalid { border-color: rgba(192,57,43,.6); }

.char-counter {
  font-family: 'Cinzel', serif; font-size: .68rem;
  color: rgba(204,136,68,.48); text-align: right;
  margin-top: 4px; letter-spacing: .04em; transition: color .22s;
}
.char-counter.ok   { color: rgba(46,204,64,.65); }
.char-counter.warn { color: rgba(255,170,50,.7); }

/* ===== BREAKPOINTS ===== */

@media (max-width: 768px) {
  .container { padding: 16px 12px 70px; }
  .header { margin-bottom: 20px; padding-top: 46px; }
  .interpretation-section { padding: 16px 14px; }
}

@media (max-width: 600px) {
  .explorar-grid { grid-template-columns: repeat(auto-fill, minmax(90px,1fr)); gap: 7px; }
}

@media (max-width: 480px) {
  .container { padding: 14px 11px 64px; }
  .header { padding-top: 44px; }
  .back-button { font-size: .78rem; padding: 7px 12px; top:10px; left:10px; }
  .question-section { padding: 14px 12px; }
  .final-response { padding: 12px 11px; }
  .action-buttons { flex-direction: column; align-items: stretch; }
  .new-reading-btn, .pdf-btn { width: 100%; text-align: center; }
}

@media (max-width: 380px) {
  .title { font-size: 1.4rem; letter-spacing: .02em; }
  .subtitle { font-size: .65rem; letter-spacing: .08em; }
  .explorar-grid { grid-template-columns: repeat(3,1fr); gap: 6px; }
  .card-title { font-size: .72rem; }
  .interpretation-text,
  .final-response-text { font-size: .96rem; }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  .container { padding-top: 10px; padding-bottom: 40px; }
  .header { padding-top: 36px; margin-bottom: 12px; }
  .question-input { min-height: 70px; }
  .back-button { top: 8px; }
}

@media print { body { background: white; color: black; } }
