/* --- KHUNG BAO CHUNG --- */
.selected-container {
  display: flex;
  justify-content: center;
  align-items: center;
}

.tarot-card-area.-hidden {
  height: 0;
}

/* Container chính cho khu vực trải bài */
.card-spread-container {
  perspective: 2000px;
  overflow: visible !important; /* Hiển thị chữ tràn ra ngoài */
  min-height: 500px;
  width: 100%;
  transition: transform 0.8s ease-in-out;
}

/* Vùng chứa các lá bài (Cỗ bài) */
.card-deck {
  position: relative;
  width: 100%;
  height: 100%;
  transform: translateX(0px); /* Sẽ thay đổi khi kéo */
}

/* Hiệu ứng ẩn bộ đếm mượt mà */
.counter-wrap.slide-up-hide {
  max-height: 0 !important;
  opacity: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  transform: translateY(-20px);
}

/* --- CẤU HÌNH LÁ BÀI --- */
.tarot-card {
  --spread: 35px; /* Độ xòe ngang desktop */
  --arc-rotate: 2.5deg; /* Góc xoay */
  --arc-translate-y: 1.5px; /* Độ cong */

  width: 130px;
  height: 213px;
  position: absolute;
  left: 50%;
  top: 50%;
  cursor: pointer;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  transform-style: preserve-3d;

  /* Trạng thái ban đầu */
  opacity: 0;
  -webkit-user-drag: none;
  user-select: none;
}

.tarot-card .card-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* --- TRẠNG THÁI CARD DECK --- */
/* 1. Đã xòe bài */
.card-deck.is-shuffled .tarot-card {
  opacity: 1;
  transition: transform calc(3s * (1 + 0.05 * (var(--n) / 2 - var(--n)))) cubic-bezier(0.32, 0, 0.133, 1.02);
  transform: translate(-50%, -50%) translateX(calc((var(--n) - 11.5) * var(--spread)))
    translateY(calc(abs(var(--n) - 11.5) * var(--arc-translate-y))) rotate(calc((var(--n) - 11.5) * var(--arc-rotate)));
}

.card-deck.is-shuffled {
  cursor: grab;
}
.card-deck.is-shuffled.is-dragging {
  cursor: grabbing;
}

/* 2. Hover vào lá bài */
.card-deck.is-shuffled .tarot-card:hover {
  transform: translate(-50%, -50%) translateX(calc((var(--n) - 11.5) * var(--spread)))
    translateY(calc(abs(var(--n) - 11.5) * var(--arc-translate-y) - 20px))
    rotate(calc((var(--n) - 11.5) * var(--arc-rotate))) scale(1.03);
  transition: all 0.1s ease-out;
  transition-delay: 0s;
}

/* 3. Lá bài đã chọn (trong bộ bài) */
.card-deck.is-shuffled .tarot-card.selected {
  transform: translate(-50%, -50%) translateX(calc((var(--n) - 11.5) * var(--spread)))
    translateY(calc(abs(var(--n) - 11.5) * var(--arc-translate-y) - 25px))
    rotate(calc((var(--n) - 11.5) * var(--arc-rotate))) scale(1.05);
  filter: brightness(1.15);
  transition: all 0.3s ease-out;
  transition-delay: 0s;
}

/* 4. Lá bài không chọn bay đi */
.tarot-card.fly-out {
  opacity: 0;
  z-index: 0;
  transform: translate(-50%, -50%) translateX(60vw) !important;
  transition-delay: calc(var(--n) * 0.04s);
}

/* --- CHI TIẾT LÁ BÀI & LẬT --- */
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.tarot-card .card {
  width: 100%;
  cursor: pointer;
  position: relative;
  transform-style: preserve-3d;
  transform: translateZ(0);
  transition: transform 0.6s cubic-bezier(0.23, 1, 0.32, 1);
  background-color: transparent;
}

/* Tên lá bài */
.card-name {
  white-space: nowrap;
  position: absolute;
  top: 96%;
  opacity: 0;
  transform: translate(0, 4rem) rotate(-180deg);
  pointer-events: none;
  text-shadow: 0px 0px 1rem #e6f3e8;
}

/* Mặt sau */
.card-back {
  position: relative;
  width: 100%;
  border-radius: 0.35rem;
  overflow: hidden;
  transform: translateZ(1px);
}
.card-back img,
.card-front img {
  display: block;
  width: 100%;
}
.card-back .glare {
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}
.card-back:hover .glare,
.selected .card-back .glare {
  opacity: 1;
}

/* Mặt trước */
.card-front {
  position: absolute;
  top: 0.5%;
  left: 0.5%;
  width: 99%;
  height: 99%;
  background-color: #f5f5f5;
  border-radius: 0.35rem;
  overflow: hidden;
  padding: 4.68% 4.68%;
  box-sizing: border-box;
  transform: rotateY(180deg) translateZ(0px);
}

/* --- TRẠNG THÁI KẾT QUẢ (FINAL STATE) --- */
.tarot-card.final-state {
  transition: all 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 1000 !important;
  opacity: 1 !important;
  top: 50% !important; /* Đưa về giữa vùng hiển thị */
}

/* Vị trí 3 lá bài khi bay vào */
.tarot-card.final-pos-1 {
  /* Trái */
  transform: translate(-50%, -50%) translateX(-140px) rotate(-10deg) scale(1.1) !important;
}
.tarot-card.final-pos-2 {
  /* Giữa */
  transform: translate(-50%, -50%) translateX(0px) translateY(-30px) scale(1.1) !important;
  z-index: 1001 !important;
}
.tarot-card.final-pos-3 {
  /* Phải */
  transform: translate(-50%, -50%) translateX(140px) rotate(10deg) scale(1.1) !important;
}

/* --- TRẠNG THÁI LẬT BÀI (REVEALED) --- */
.tarot-card.final-state.revealed {
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  width: 130px !important;
  height: 213px !important;
}

/* Vị trí và phóng to sau khi lật */
.tarot-card.final-pos-1.revealed {
  transform: translate(-50%, -50%) translateX(-170px) rotate(-10deg) scale(1.35) !important;
}
.tarot-card.final-pos-2.revealed {
  transform: translate(-50%, -50%) translateX(0px) translateY(-30px) scale(1.35) !important;
  z-index: 2000 !important;
}
.tarot-card.final-pos-3.revealed {
  transform: translate(-50%, -50%) translateX(170px) rotate(10deg) scale(1.35) !important;
}

/* Xử lý xoay mặt bài */
.tarot-card.revealed .card {
  transform: rotateY(180deg);
  transition: transform 0.8s ease-in-out;
}
.tarot-card.revealed .card-inner {
  transform: rotateY(180deg);
}

/* Xử lý bài ngược */
.tarot-card.revealed .card.-reversed {
  transform: rotateY(180deg) rotateZ(180deg) !important;
}

/* Hiển thị tên bài */
.tarot-card.revealed .card-name {
  opacity: 1 !important;
  top: -50px !important;
  left: 50% !important;
  transform: translate(-50%, 0) !important;
  width: 200px;
  text-align: center;
  font-family: "Oswald-Regular";
  z-index: 2000;
}

/* --- RESPONSIVE MOBILE --- */
@media (max-width: 768px) {
  .tarot-card {
    width: 90px;
    height: 150px;
    --spread: 20px;
    --arc-rotate: 3deg;
  }

  .card-spread-container {
    height: 250px;
    min-height: 400px !important;
  }

  /* Chỉnh lại vị trí bài kết quả mobile */
  .tarot-card.final-state.revealed {
    width: 90px !important;
    height: 150px !important;
  }
  .tarot-card.revealed .card-name {
    top: -45px !important;
    font-size: 13px !important;
    width: 150px;
  }

  /* Vị trí trước khi lật */
  .tarot-card.final-pos-1 {
    transform: translate(-50%, -50%) translateX(-90px) rotate(-8deg) scale(1) !important;
  }
  .tarot-card.final-pos-2 {
    transform: translate(-50%, -50%) translateX(0px) translateY(-20px) scale(1) !important;
  }
  .tarot-card.final-pos-3 {
    transform: translate(-50%, -50%) translateX(90px) rotate(8deg) scale(1) !important;
  }

  /* Vị trí sau khi lật (phóng to ít hơn) */
  .tarot-card.final-pos-1.revealed {
    transform: translate(-50%, -50%) translateX(-100px) rotate(-8deg) scale(1.15) !important;
  }
  .tarot-card.final-pos-2.revealed {
    transform: translate(-50%, -50%) translateX(0px) translateY(-20px) scale(1.15) !important;
  }
  .tarot-card.final-pos-3.revealed {
    transform: translate(-50%, -50%) translateX(100px) rotate(8deg) scale(1.15) !important;
  }
}

@media (max-width: 420px) {
  .tarot-card {
    --arc-rotate: 3.5deg;
  }
}
