/**
 * Tarot 3D Cards, Animations & Table Spreads Stylesheet
 * -------------------------------------------------------------
 */

/* 3D Card Architecture */
.tarot-card {
  width: var(--card-width, 170px);
  height: var(--card-height, 280px);
  perspective: 1200px;
  cursor: pointer;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.tarot-card:hover:not(.is-flipped) {
  transform: translateY(-8px) scale(1.03);
}

.tarot-card:hover:not(.is-flipped) .card-back {
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.6), 0 0 20px var(--gold-glow);
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.85s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Flip state */
.tarot-card.is-flipped .card-inner {
  transform: rotateY(180deg);
}

.tarot-card.is-flipped .card-front {
  z-index: 2;
}

.tarot-card.is-flipped .card-back {
  z-index: 1;
}

/* Card Faces */
.card-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
}

/* Back Face */
.card-back {
  background-color: #0b071c;
  border: 1px solid var(--gold-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
  transform-style: preserve-3d;
  z-index: 2;
}

.card-back-pattern {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-back-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.card-back-glow {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(212, 175, 55, 0.12) 0%, transparent 70%);
  z-index: 1;
}

/* Front Face (Full-Bleed Canvas) */
.card-front {
  background: linear-gradient(145deg, #181138, #0e0a24);
  border: 1px solid var(--gold-primary);
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
  transform-style: preserve-3d;
  z-index: 1;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.6), 0 0 15px rgba(212, 175, 55, 0.2);
}

/* Reversed Card Orientation */
.tarot-card.is-reversed.is-flipped .card-front {
  transform: rotateY(180deg) rotate(180deg);
}

.tarot-card.is-flipped {
  cursor: zoom-in;
}

/* Full-Bleed Artwork Layer */
.card-artwork {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: hidden;
  border-radius: 11px;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.card-art-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.4s ease;
  pointer-events: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Protective transparent shield overlay */
.card-art-shield {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
  background: transparent;
}

.tarot-card:hover .card-art-img {
  transform: scale(1.04);
}

.card-art-fallback {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 50%, #1e1445 0%, #0d0924 100%);
}

.card-art-svg {
  width: 75%;
  height: 75%;
  filter: drop-shadow(0 0 8px rgba(212, 175, 55, 0.4));
}

/* Corner Ornaments */
.card-border-ornament {
  position: absolute;
  top: 4px;
  left: 4px;
  right: 4px;
  bottom: 4px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 8px;
  pointer-events: none;
  z-index: 2;
}

.card-border-ornament .corner {
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--gold-primary);
  border-style: solid;
}

.corner.tl { top: -1px; left: -1px; border-width: 2px 0 0 2px; }
.corner.tr { top: -1px; right: -1px; border-width: 2px 2px 0 0; }
.corner.bl { bottom: -1px; left: -1px; border-width: 0 0 2px 2px; }
.corner.br { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; }

/* Overlaid Text & Badges Container */
.card-front-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

/* Header Overlaid at Top */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px 16px;
  background: linear-gradient(180deg, rgba(8, 5, 22, 0.9) 0%, rgba(8, 5, 22, 0.6) 55%, transparent 100%);
  position: relative;
  z-index: 4;
}

.card-number {
  font-family: var(--font-mystic);
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95), 0 0 8px var(--gold-glow);
  background: rgba(12, 8, 30, 0.7);
  padding: 1px 7px;
  border-radius: 4px;
  border: 1px solid rgba(212, 175, 55, 0.5);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.card-element-tag {
  font-size: 0.85rem;
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.tag-fire { background: rgba(220, 38, 38, 0.65); color: #fee2e2; border: 1px solid rgba(239, 68, 68, 0.6); }
.tag-water { background: rgba(79, 70, 229, 0.65); color: #e0e7ff; border: 1px solid rgba(99, 102, 241, 0.6); }
.tag-air { background: rgba(14, 165, 233, 0.65); color: #e0f2fe; border: 1px solid rgba(56, 189, 248, 0.6); }
.tag-earth { background: rgba(5, 150, 105, 0.65); color: #d1fae5; border: 1px solid rgba(16, 185, 129, 0.6); }

/* Card Title Overlaid at Bottom */
.card-title-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
  padding: 22px 6px 8px;
  background: linear-gradient(0deg, rgba(7, 4, 18, 0.95) 0%, rgba(7, 4, 18, 0.72) 55%, transparent 100%);
  z-index: 4;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card-title-overlay .card-title-en {
  font-family: var(--font-mystic);
  font-size: 0.92rem;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96%;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 2px 6px rgba(0, 0, 0, 0.9), 0 0 10px rgba(0, 0, 0, 0.8);
}

.card-title-overlay .card-title-th {
  font-size: 0.74rem;
  color: var(--gold-light);
  margin-top: 1px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 96%;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 6px rgba(0, 0, 0, 0.8);
}

.card-orientation-badge {
  font-size: 0.62rem;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.card-orientation-badge.upright {
  background: rgba(16, 185, 129, 0.45);
  color: #6ee7b7;
  border: 1px solid rgba(52, 211, 153, 0.65);
}

.card-orientation-badge.reversed {
  background: rgba(245, 158, 11, 0.5);
  color: #fef08a;
  border: 1px solid rgba(251, 191, 36, 0.65);
}

/* Position Label on table */
.card-position-label {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--gold-light);
  text-align: center;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  white-space: nowrap;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Shuffling Animation Deck */
.shuffling-deck-container {
  display: inline-block;
  position: relative;
  width: 160px;
  height: 256px;
  filter: drop-shadow(0 10px 25px rgba(0, 0, 0, 0.7));
}

.deck-pile {
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  border: 1px solid var(--gold-primary);
  background-color: #0b071c;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.7), 0 0 12px rgba(212, 175, 55, 0.25);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.deck-pile .card-back-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.pile-1 { top: 0; left: 0; z-index: 3; }
.pile-2 { top: -4px; left: -4px; z-index: 2; opacity: 0.92; }
.pile-3 { top: -8px; left: -8px; z-index: 1; opacity: 0.85; }

.is-shuffling .pile-1 {
  animation: shuffleLeft 0.6s infinite alternate ease-in-out;
}
.is-shuffling .pile-2 {
  animation: shuffleRight 0.6s infinite alternate ease-in-out;
}

@keyframes shuffleLeft {
  0% { transform: translateX(0) rotate(0deg); }
  50% { transform: translateX(-40px) rotate(-8deg); }
  100% { transform: translateX(0) rotate(0deg); }
}

@keyframes shuffleRight {
  0% { transform: translateX(0) rotate(0deg); }
  50% { transform: translateX(40px) rotate(8deg); }
  100% { transform: translateX(0) rotate(0deg); }
}

/* Table Layouts for different spreads */
.cards-table-grid {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1.8rem;
  padding: 1.5rem 0;
  min-height: 380px;
  width: 100%;
}

/* 1. Single Card Spread */
.cards-table-grid.spread-single {
  justify-content: center;
}

/* 2. Three Cards Spread */
.cards-table-grid.spread-three {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 620px;
  gap: 1.5rem;
  margin: 0 auto;
  justify-items: center;
}

/* 3. Love 4 Cards Spread */
.cards-table-grid.spread-love {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-width: 380px;
  gap: 1.5rem;
  margin: 0 auto;
  justify-items: center;
}

@media (min-width: 850px) {
  .cards-table-grid.spread-love {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: 850px;
    gap: 1.5rem;
  }
}

/* 4. Celtic Cross Traditional Spread (10 cards) */
.cards-table-celtic-container {
  width: 100%;
  padding: 1.5rem 0.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.cards-table-celtic-container .tarot-card {
  --card-width: 110px;
  --card-height: 178px;
}

.celtic-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1.8rem, 4vw, 3.8rem);
  margin: 0 auto;
  min-width: fit-content;
}

/* ฝั่งซ้าย: ไม้กางเขน (The Cross / Circle - ไพ่ใบที่ 1-6) */
.celtic-cross-circle {
  display: grid;
  grid-template-columns: auto auto auto;
  grid-template-rows: auto auto auto;
  align-items: center;
  justify-items: center;
  gap: clamp(1rem, 2.2vw, 2.2rem);
  position: relative;
}

.celtic-cross-circle .slot-top {
  grid-column: 2;
  grid-row: 1;
}

.celtic-cross-circle .slot-left {
  grid-column: 1;
  grid-row: 2;
  justify-self: end;
}

.celtic-cross-circle .slot-center {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.celtic-cross-circle .slot-right {
  grid-column: 3;
  grid-row: 2;
  justify-self: start;
}

.celtic-cross-circle .slot-bottom {
  grid-column: 2;
  grid-row: 3;
}

/* จุดศูนย์กลางไม้กางเขน: ไพ่ใบที่ 1 (ตัวตน) & ไพ่ใบที่ 2 (อุปสรรคขวาง) */
.celtic-center-card-holder {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--card-width);
  height: var(--card-height);
}

.celtic-card-1 {
  position: relative;
  z-index: 2;
  transition: transform 0.3s ease, z-index 0.2s ease, filter 0.3s ease;
}

.celtic-card-1.hover-highlight,
.celtic-card-1:hover {
  z-index: 12 !important;
  transform: scale(1.05);
  filter: drop-shadow(0 0 16px var(--gold-primary));
}

.celtic-card-2 {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) rotate(90deg) !important;
  z-index: 4;
  transition: transform 0.3s ease, z-index 0.2s ease, filter 0.3s ease;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.85));
}

.celtic-card-2.hover-highlight,
.celtic-card-2:hover {
  z-index: 14 !important;
  transform: translate(-50%, -50%) rotate(90deg) scale(1.06) !important;
  filter: drop-shadow(0 0 16px var(--gold-primary));
}

/* ซ่อน Label เดิมของไพ่ 1 และ 2 เพื่อไม่ให้ตัวหนังสือหมุนเอียง 90 องศา หรือซ้อนทับกัน */
.celtic-card-1 .card-position-label,
.celtic-card-2 .card-position-label {
  display: none !important;
}

.celtic-center-labels {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.6rem;
  z-index: 6;
}

.celtic-badge-label {
  font-size: 0.88rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.celtic-badge-label.badge-present {
  background: rgba(212, 175, 55, 0.2);
  border: 1px solid rgba(212, 175, 55, 0.55);
  color: var(--gold-primary);
}

.celtic-badge-label.badge-present:hover {
  background: rgba(212, 175, 55, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 0 12px rgba(212, 175, 55, 0.4);
}

.celtic-badge-label.badge-challenge {
  background: rgba(255, 115, 115, 0.2);
  border: 1px solid rgba(255, 115, 115, 0.55);
  color: #ffaaaa;
}

.celtic-badge-label.badge-challenge:hover {
  background: rgba(255, 115, 115, 0.4);
  transform: translateY(-2px);
  box-shadow: 0 0 12px rgba(255, 115, 115, 0.4);
}

/* ฝั่งขวา: เสาไม้เท้า (The Staff / Pillar - ไพ่ใบที่ 7-10 จากล่างขึ้นบน) */
.celtic-cross-staff {
  display: flex;
  flex-direction: column-reverse;
  gap: clamp(0.7rem, 1.4vw, 1.1rem);
  align-items: center;
  justify-content: space-between;
}

/* Tablet adjustments (601px - 850px) */
@media (max-width: 850px) {
  .tarot-card {
    --card-width: 140px;
    --card-height: 230px;
  }
  .cards-table-celtic-container .tarot-card {
    --card-width: 90px;
    --card-height: 146px;
  }
  .celtic-layout {
    gap: 1.6rem;
  }
  .celtic-cross-circle {
    gap: 0.8rem 1.2rem;
  }
  .cards-table-grid {
    gap: 1.2rem;
  }
  .cards-table-grid.spread-three {
    max-width: 520px;
    gap: 1rem;
  }
}

/* Mobile adjustments (<= 600px) */
@media (max-width: 600px) {
  .tarot-card {
    --card-width: clamp(94px, 28vw, 120px);
    --card-height: clamp(152px, 45vw, 195px);
  }
  .cards-table-celtic-container {
    padding: 0.8rem 0.2rem;
  }
  .cards-table-celtic-container .tarot-card {
    --card-width: clamp(58px, 15.5vw, 76px);
    --card-height: clamp(94px, 25vw, 123px);
  }
  .celtic-layout {
    gap: 0.8rem;
  }
  .celtic-cross-circle {
    gap: 0.5rem 0.6rem;
  }
  .celtic-cross-staff {
    gap: 0.5rem;
  }
  .celtic-badge-label {
    font-size: 0.78rem;
    padding: 3px 8px;
  }
  .card-position-label {
    max-width: 100%;
    font-size: 0.68rem;
    padding: 2px 4px;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
  }
  .card-title-overlay {
    padding: 16px 4px 5px;
  }
  .card-title-overlay .card-title-en {
    font-size: 0.74rem;
  }
  .card-title-overlay .card-title-th {
    font-size: 0.62rem;
  }
  .card-orientation-badge {
    font-size: 0.55rem;
    padding: 1px 4px;
  }
  .card-number {
    font-size: 0.8rem;
  }
  .card-element-tag {
    font-size: 0.76rem;
    padding: 2px 7px;
  }
  .fan-card {
    width: 72px;
    height: 118px;
  }
  .fan-deck-container {
    min-height: 260px;
  }
  .shuffling-deck-container {
    width: 120px;
    height: 190px;
  }
  .cards-table-grid {
    padding: 1rem 0;
    gap: 0.8rem;
  }
  .cards-table-grid.spread-three {
    max-width: 100%;
    gap: 0.4rem;
  }
  .cards-table-grid.spread-love {
    max-width: 280px;
    gap: 0.7rem;
  }
}

/* Extra small mobile adjustments (<= 380px) */
@media (max-width: 380px) {
  .tarot-card {
    --card-width: clamp(86px, 29vw, 98px);
    --card-height: clamp(140px, 47vw, 160px);
  }
  .cards-table-celtic-container .tarot-card {
    --card-width: clamp(50px, 14vw, 60px);
    --card-height: clamp(80px, 22.5vw, 98px);
  }
  .celtic-layout {
    gap: 0.4rem;
  }
  .celtic-cross-circle {
    gap: 0.35rem 0.4rem;
  }
  .fan-card {
    width: 64px;
    height: 104px;
  }
  .card-front {
    padding: 0;
  }
  .card-header {
    padding: 3px 5px 10px;
  }
  .card-footer {
    padding: 14px 4px 6px;
  }
}
