@import url("https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@400;700&family=Cinzel:wght@400;600&family=EB+Garamond:ital,wght@0,400;0,500;1,400&display=swap");

/* ── Variabili ───────────────────────────────────── */
:root {
  --bg-deep: #07050f;
  --bg-mid: #0e0a1e;
  --bg-card: #130d2a;
  --accent: #c9a84c;
  --accent2: #7b2cbf;
  --accent-glow: #e0aaff;
  --text: #e8e0f0;
  --text-muted: #9e8fbb;
  --border: rgba(201, 168, 76, 0.25);
  --radius: 12px;
}

/* ── Base ────────────────────────────────────────── */
body {
  background-color: var(--bg-deep);
  background-image:
    radial-gradient(
      ellipse 80% 60% at 50% -10%,
      rgba(123, 44, 191, 0.35) 0%,
      transparent 70%
    ),
    radial-gradient(
      ellipse 60% 40% at 80% 100%,
      rgba(201, 168, 76, 0.12) 0%,
      transparent 60%
    );
  color: var(--text);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 18px;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────── */
header {
  background: linear-gradient(
    180deg,
    rgba(7, 5, 15, 0.98),
    rgba(14, 10, 30, 0.9)
  );
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

header h1 {
  font-family: "Cinzel Decorative", serif;
  font-size: clamp(1rem, 3vw, 1.5rem);
  color: var(--accent);
  text-shadow: 0 0 20px rgba(201, 168, 76, 0.5);
}

nav a {
  font-family: "Cinzel", serif;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 7px 16px;
  border: 1px solid transparent;
  border-radius: 30px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all 0.3s;
}
nav a:hover,
nav a.active {
  color: var(--accent);
  border-color: var(--border);
  background: rgba(201, 168, 76, 0.06);
}

/* ── Hero ────────────────────────────────────────── */
.hero {
  text-align: center;
  padding: 120px 24px 100px;
  position: relative;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    ellipse 50% 60% at 50% 50%,
    rgba(123, 44, 191, 0.2),
    transparent 70%
  );
  pointer-events: none;
}
.hero h2 {
  font-family: "Cinzel Decorative", serif;
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  color: var(--accent);
  text-shadow: 0 0 40px rgba(201, 168, 76, 0.4);
  margin-bottom: 20px;
  line-height: 1.2;
}
.hero p {
  font-size: 1.2rem;
  color: var(--text-muted);
  max-width: 520px;
  margin: 0 auto 40px;
  font-style: italic;
}

/* ── Bottone principale ──────────────────────────── */
.btn-custom {
  display: inline-block;
  font-family: "Cinzel", serif;
  font-size: 0.9rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--bg-deep);
  background: linear-gradient(
    135deg,
    var(--accent) 0%,
    #e8c96a 50%,
    var(--accent) 100%
  );
  background-size: 200% auto;
  padding: 16px 44px;
  border: none;
  border-radius: 40px;
  cursor: pointer;
  text-decoration: none;
  transition:
    background-position 0.4s,
    transform 0.2s,
    box-shadow 0.3s;
  box-shadow:
    0 0 30px rgba(201, 168, 76, 0.3),
    0 4px 20px rgba(0, 0, 0, 0.5);
}
.btn-custom:hover {
  background-position: right center;
  transform: translateY(-2px);
  box-shadow:
    0 0 50px rgba(201, 168, 76, 0.5),
    0 8px 30px rgba(0, 0, 0, 0.5);
  color: var(--bg-deep);
  text-decoration: none;
}

/* ── Titoli pagina ───────────────────────────────── */
main h2 {
  font-family: "Cinzel Decorative", serif;
  color: var(--accent);
  font-size: clamp(1.2rem, 3vw, 1.8rem);
}
.sottotitolo {
  color: var(--text-muted);
  font-style: italic;
}

/* ── Pulsanti selezione stesa ────────────────────── */
.stesa-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: linear-gradient(160deg, var(--bg-card), #1a0e35);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 16px;
  cursor: pointer;
  color: var(--text);
  text-align: center;
  transition: all 0.3s;
  width: 100%;
  font-family: "EB Garamond", serif;
}
.stesa-btn:hover,
.stesa-btn.attivo {
  border-color: var(--accent);
  background: linear-gradient(160deg, #1f1040, #2a1060);
  box-shadow: 0 0 30px rgba(201, 168, 76, 0.2);
  transform: translateY(-2px);
}
.stesa-icona {
  font-size: 2rem;
}
.stesa-nome {
  font-family: "Cinzel", serif;
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  color: var(--accent);
}
.stesa-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.4;
}

/* ── Loading ─────────────────────────────────────── */
.loading {
  font-family: "Cinzel", serif;
  color: var(--accent);
  letter-spacing: 0.1em;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

/* ── Carta ───────────────────────────────────────── */
@keyframes cardReveal {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.carta {
  background: linear-gradient(160deg, var(--bg-card) 0%, #1a0e35 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: cardReveal 0.6s ease both;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  height: 100%;
  overflow: visible !important;
  /* max-width: 280px;
  margin: 0; */
  /* margin-left: auto;
  margin-right: auto; */
}
.carta::before {
  content: "";
  position: absolute;
  top: -40%;
  left: -40%;
  width: 180%;
  height: 180%;
  background: radial-gradient(
    ellipse at 50% 0%,
    rgba(201, 168, 76, 0.07),
    transparent 60%
  );
  pointer-events: none;
}

.ruolo {
  display: inline-block;
  font-family: "Cinzel", serif;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(201, 168, 76, 0.1);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 12px;
  margin-bottom: 14px;
}

.carta-img-wrap {
  width: 100%;
  flex-grow: 1;
  /* aspect-ratio: 3/4; */
  overflow: hidden;
  border-radius: 8px;
  margin-bottom: 12px;
  border: 1px solid rgba(201, 168, 76, 0.15);
  background: var(--bg-mid);
}
.carta img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s;
}
.carta:hover img {
  transform: scale(1.04);
}
.carta-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  background: radial-gradient(circle, #1d1040, var(--bg-mid));
}

.carta h2 {
  font-family: "Cinzel", serif;
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 10px;
  line-height: 1.3;
}
.seme {
  display: inline-block;
  font-family: "Cinzel", serif;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--accent2);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.carta-dettaglio {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  border-top: 1px solid rgba(201, 168, 76, 0.12);
  padding-top: 7px;
  text-align: left;
}
.det-titolo {
  font-family: "Cinzel", serif;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  text-transform: uppercase;
}
.det-testo {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.4;
}

/* ── Contatto ────────────────────────────────────── */
.contatto-wrap {
  max-width: 600px;
  margin: 80px auto;
  padding: 0 24px 80px;
}
.contatto-wrap h1 {
  font-family: "Cinzel Decorative", serif;
  color: var(--accent);
  font-size: clamp(1.4rem, 4vw, 2rem);
  text-align: center;
  margin-bottom: 10px;
  text-shadow: 0 0 20px rgba(201, 168, 76, 0.3);
}
.contatto-wrap .sottotitolo {
  text-align: center;
  margin-bottom: 40px;
}

.form-group {
  margin-bottom: 22px;
}
.form-group label {
  display: block;
  font-family: "Cinzel", serif;
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 7px;
}
.form-group input,
.form-group textarea {
  width: 100%;
  background: rgba(19, 13, 42, 0.8);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: "EB Garamond", serif;
  font-size: 1rem;
  padding: 12px 16px;
  transition:
    border-color 0.3s,
    box-shadow 0.3s;
  outline: none;
  resize: vertical;
}
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.1);
}
.form-group textarea {
  min-height: 130px;
}
.form-group input.error,
.form-group textarea.error {
  border-color: #e05252;
}
.field-error {
  color: #e07070;
  font-size: 0.8rem;
  margin-top: 5px;
  display: none;
  font-style: italic;
}
.msg-success {
  background: rgba(201, 168, 76, 0.08);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  font-family: "Cinzel", serif;
  color: var(--accent);
}

/* ── Footer ──────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-family: "Cinzel", serif;
  font-size: 0.76rem;
  letter-spacing: 0.1em;
}

/* ── Bottone outline ─────────────────────────────────────────────────────────── */
.btn-outline-custom {
  display: inline-block;
  font-family: "Cinzel", serif;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  background: transparent;
  padding: 12px 32px;
  border: 1px solid var(--border);
  border-radius: 40px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.3s;
}
.btn-outline-custom:hover {
  background: rgba(201, 168, 76, 0.08);
  border-color: var(--accent);
}

/* ── Contatore selezione ─────────────────────────────────────────────────────── */
.contatore-wrap {
  font-family: "Cinzel", serif;
  font-size: 0.9rem;
  color: var(--text-muted);
  letter-spacing: 0.1em;
  margin-top: 12px;
}
.contatore-wrap #contatore {
  font-size: 1.4rem;
  color: var(--accent);
  font-weight: 700;
}

/* ── Griglia mazzo coperto ───────────────────────────────────────────────────── */
.mazzo-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  padding: 20px 0;
}

.carta-retro {
  width: 60px;
  height: 100px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: linear-gradient(160deg, #1a0e35, #0e0820);
  cursor: pointer;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.carta-retro img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: 5px;
}
.carta-retro:hover {
  transform: translateY(-8px) scale(1.06);
  box-shadow: 0 12px 30px rgba(201, 168, 76, 0.35);
  border-color: var(--accent);
  z-index: 2;
}
.carta-retro.selezionata {
  border-color: var(--accent);
  box-shadow:
    0 0 0 2px var(--accent),
    0 8px 24px rgba(201, 168, 76, 0.5);
  transform: translateY(-12px) scale(1.08);
  z-index: 3;
}
.carta-retro.selezionata::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: bold;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.8);
}
.carta-retro.dimmed {
  opacity: 0.35;
  transform: none;
  pointer-events: none;
}

/* Ornamento retro CSS (fallback senza immagine) */
.retro-ornamento {
  font-size: 1.4rem;
  color: var(--accent);
  opacity: 0.6;
}
.retro-ornamento.grande {
  font-size: 3rem;
}

/* ── Flip 3D ─────────────────────────────────────────────────────────────────── */
.flip-container {
  perspective: 1000px;
  -webkit-perspective: 1000px;
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}
.flipper {
  position: relative;
  width: 100%;
  display: grid;
  grid-template-areas: "overlay";
  aspect-ratio: 5 / 8.5; /* Aspect ratio fisso per mantenere le carte uguali */
  transition: transform 0.75s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  /* L'altezza si adatta al flip-back (la carta piena) */
}
.flip-container.flipped .flipper {
  transform: rotateY(180deg);
}

/* Prima del flip: altezza = retro (aspect-ratio 3/5) */
/* .flip-container:not(.flipped) .flipper {
  aspect-ratio: 3/5;
}
 */
/* Dopo il flip: torna auto per contenere la carta completa */
/* .flip-container.flipped .flipper {
  aspect-ratio: unset;
} */

.flip-front,
.flip-back {
  /* position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%; */
  grid-area: overlay;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  /* overflow: hidden; */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
.flip-front {
  transform: rotateY(0deg);
  z-index: 2;
  background: linear-gradient(145deg, #1f0d40 0%, #0b0618 50%, #1a0835 100%);
  border: 1px solid var(--border);
  min-height: 400px; /* Altezza minima per evitare che il flip-back spinga fuori la carta */
  display: flex;
  align-items: center;
  justify-content: center;
  /* Motivo geometrico come retro carta */
  background-image:
    linear-gradient(145deg, #1f0d40 0%, #0b0618 50%, #1a0835 100%),
    repeating-linear-gradient(
      45deg,
      rgba(201, 168, 76, 0.04) 0px,
      rgba(201, 168, 76, 0.04) 1px,
      transparent 1px,
      transparent 10px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(201, 168, 76, 0.04) 0px,
      rgba(201, 168, 76, 0.04) 1px,
      transparent 1px,
      transparent 10px
    );
}
.flip-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* .flip-back {
  position: absolute;
  top: 0;
  left: 0;
  transform: rotateY(180deg);
} */

.flip-back {
  transform: rotateY(180deg);
  z-index: 1;
}

/* ── Responsive mazzo ────────────────────────────────────────────────────────── */
@media (max-width: 576px) {
  .carta-retro {
    width: 46px;
    height: 76px;
  }
}
@media (min-width: 992px) {
  .carta-retro {
    width: 70px;
    height: 116px;
  }
}

/* ── Lettura AI ──────────────────────────────────────────────────────────────── */
.lettura-ai-box {
  max-width: 780px;
  margin: 0 auto 60px;
  background: linear-gradient(160deg, #130d2a, #1a0e35);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 40px;
  box-shadow:
    0 0 60px rgba(201, 168, 76, 0.08),
    0 20px 60px rgba(0, 0, 0, 0.5);
  position: relative;
  overflow: hidden;
}
.lettura-ai-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.lettura-ai-titolo {
  font-family: "Cinzel Decorative", serif;
  color: var(--accent);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  margin-bottom: 24px;
  text-align: center;
  text-shadow: 0 0 20px rgba(201, 168, 76, 0.3);
}
.lettura-ai-testo {
  font-family: "EB Garamond", serif;
  font-size: 1.1rem;
  line-height: 1.85;
  color: var(--text);
  white-space: pre-wrap;
}
.lettura-ai-loading {
  text-align: center;
  padding: 20px 0;
}
.lettura-ai-errore {
  border-color: rgba(220, 80, 80, 0.3);
  color: #e07070;
  text-align: center;
  font-style: italic;
}

/* ── Audio player ────────────────────────────────────────────────────────────── */
.audio-player {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.audio-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Cinzel", serif;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--bg-deep);
  background: linear-gradient(135deg, var(--accent), #e8c96a, var(--accent));
  background-size: 200% auto;
  padding: 10px 24px;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.3s;
  box-shadow: 0 0 20px rgba(201, 168, 76, 0.25);
}
.audio-btn:hover {
  background-position: right center;
  box-shadow: 0 0 35px rgba(201, 168, 76, 0.45);
  transform: translateY(-1px);
}

/* Barre animazione audio */
.audio-barre {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 28px;
}
.audio-barre span {
  display: block;
  width: 3px;
  height: 6px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.3;
  transition: height 0.2s;
}
.audio-barre.playing span {
  opacity: 1;
  animation: equalizer 0.8s ease-in-out infinite alternate;
}
.audio-barre.playing span:nth-child(1) {
  animation-delay: 0s;
}
.audio-barre.playing span:nth-child(2) {
  animation-delay: 0.1s;
}
.audio-barre.playing span:nth-child(3) {
  animation-delay: 0.2s;
}
.audio-barre.playing span:nth-child(4) {
  animation-delay: 0.05s;
}
.audio-barre.playing span:nth-child(5) {
  animation-delay: 0.15s;
}
.audio-barre.playing span:nth-child(6) {
  animation-delay: 0.25s;
}
.audio-barre.playing span:nth-child(7) {
  animation-delay: 0s;
}
.audio-barre.playing span:nth-child(8) {
  animation-delay: 0.1s;
}
.audio-barre.playing span:nth-child(9) {
  animation-delay: 0.2s;
}
.audio-barre.playing span:nth-child(10) {
  animation-delay: 0.05s;
}
.audio-barre.playing span:nth-child(11) {
  animation-delay: 0.15s;
}
.audio-barre.playing span:nth-child(12) {
  animation-delay: 0.25s;
}

@keyframes equalizer {
  from {
    height: 4px;
  }
  to {
    height: 24px;
  }
}
