/* tarot.css — công cụ rút bài tarot có hiệu ứng */

.tr-tool {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 26px 22px;
    margin-bottom: 28px;
    box-shadow: var(--shadow-card);
}

.tr-tool h2 {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 18px;
}

.tr-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
}

/* ── Chọn kiểu trải bài ── */
.tr-spreads {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin-bottom: 22px;
}

.tr-spread {
    background: var(--bg-input);
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    padding: 12px 14px;
    cursor: pointer;
    text-align: left;
    font-family: var(--font);
    transition: all var(--transition-fast);
}

.tr-spread:hover { border-color: var(--accent-light); }

.tr-spread.active {
    border-color: var(--accent);
    background: var(--accent-bg);
}

.tr-spread-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.tr-spread-desc {
    display: block;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

/* ── Câu hỏi ── */
.tr-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.tr-chip {
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    padding: 7px 14px;
    font-size: 0.82rem;
    font-family: var(--font);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.tr-chip:hover { border-color: var(--accent-light); color: var(--text-primary); }

.tr-chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.tr-custom {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    font-family: var(--font);
    font-size: 0.9rem;
    color: var(--text-primary);
    resize: vertical;
    margin-bottom: 16px;
}

.tr-custom:focus { outline: none; border-color: var(--accent); }

/* ── Nút rút bài ── */
.tr-draw-btn {
    width: 100%;
    padding: 15px 20px;
    background: linear-gradient(135deg, #5b4dc7, #8b5fd6);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-base);
    box-shadow: 0 4px 14px rgba(91, 77, 199, 0.3);
}

.tr-draw-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(91, 77, 199, 0.4);
}

.tr-draw-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

/* ══════════════════════════════════════════════════
   SÂN KHẤU RÚT BÀI
   ══════════════════════════════════════════════════ */

.tr-stage {
    display: none;
    position: relative;
    min-height: 260px;
    margin: 30px 0;
    perspective: 1400px;
}

.tr-stage.show { display: block; }

/* ── Bộ bài úp đang xào ── */
.tr-deck {
    position: relative;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tr-deck-card {
    position: absolute;
    width: 96px;
    height: 164px;
    border-radius: 10px;
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .07) 0 6px, transparent 6px 12px),
        linear-gradient(150deg, #3a2f7a, #6b4fa8 55%, #2c2358);
    border: 2px solid rgba(255, 215, 140, .5);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
    animation: tr-shuffle 1.15s ease-in-out infinite;
}

.tr-deck-card::after {
    content: "🌙";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
    opacity: .75;
}

@keyframes tr-shuffle {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    25%      { transform: translateX(-24px) rotate(-7deg); }
    75%      { transform: translateX(24px) rotate(7deg); }
}

.tr-deck-card:nth-child(1) { animation-delay: 0s; }
.tr-deck-card:nth-child(2) { animation-delay: .12s; }
.tr-deck-card:nth-child(3) { animation-delay: .24s; }
.tr-deck-card:nth-child(4) { animation-delay: .36s; }
.tr-deck-card:nth-child(5) { animation-delay: .48s; }

.tr-shuffle-text {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.92rem;
    margin-top: 14px;
    animation: tr-pulse 1.6s ease-in-out infinite;
}

@keyframes tr-pulse { 0%, 100% { opacity: .5 } 50% { opacity: 1 } }

/* ── Bài đã trải ── */
.tr-spread-area {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    justify-content: center;
    padding: 10px 0;
}

.tr-card {
    width: 132px;
    opacity: 0;
    transform: translateY(28px);
    animation: tr-deal .5s cubic-bezier(.2, .9, .3, 1.2) forwards;
}

@keyframes tr-deal {
    to { opacity: 1; transform: translateY(0); }
}

.tr-card-pos {
    text-align: center;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: 7px;
    min-height: 2.1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Khối lật 3D */
.tr-flip {
    position: relative;
    width: 132px;
    height: 226px;
    transform-style: preserve-3d;
    transition: transform .75s cubic-bezier(.4, .2, .2, 1);
    cursor: pointer;
}

.tr-card.revealed .tr-flip { transform: rotateY(180deg); }

.tr-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 5px 16px rgba(0, 0, 0, .22);
}

.tr-back {
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, .07) 0 6px, transparent 6px 12px),
        linear-gradient(150deg, #3a2f7a, #6b4fa8 55%, #2c2358);
    border: 2px solid rgba(255, 215, 140, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}

.tr-front {
    transform: rotateY(180deg);
    background: var(--bg-input);
    border: 2px solid var(--accent-light);
}

.tr-front img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Lá ngược — xoay ảnh 180° đúng như luật tarot */
.tr-front.reversed img { transform: rotate(180deg); }

.tr-card-name {
    text-align: center;
    margin-top: 9px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
    opacity: 0;
    transition: opacity .4s ease .3s;
}

.tr-card.revealed .tr-card-name { opacity: 1; }

.tr-card-dir {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    margin-top: 2px;
}

.tr-card-dir.up { color: #1c7a4d; }
.tr-card-dir.rev { color: #b8683a; }

/* ── Kết quả luận giải ── */
.tr-result {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 26px 24px;
    box-shadow: var(--shadow-card);
}

.tr-result.show { display: block; }

.tr-result h3 {
    font-size: 1.08rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 22px 0 10px;
}

.tr-result h3:first-child { margin-top: 0; }

.tr-result h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
    margin: 16px 0 6px;
}

.tr-result p { color: var(--text-secondary); line-height: 1.72; margin-bottom: 12px; }
.tr-result strong { color: var(--text-primary); }
.tr-result ul { margin: 0 0 14px 20px; }
.tr-result li { color: var(--text-secondary); line-height: 1.7; margin-bottom: 6px; }

/* ── Loading / lỗi ── */
.tr-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 30px 0;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.tr-dots { display: flex; gap: 6px; }

.tr-dots span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    animation: tr-bounce 1.3s ease-in-out infinite;
}

.tr-dots span:nth-child(2) { animation-delay: .18s; }
.tr-dots span:nth-child(3) { animation-delay: .36s; }

@keyframes tr-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .4 }
    30%           { transform: translateY(-9px); opacity: 1 }
}

.tr-msg {
    text-align: center;
    padding: 16px 18px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    margin-top: 16px;
}

.tr-msg-err  { background: rgba(200, 60, 60, .1); color: #b13a3a; }
.tr-msg-info { background: var(--accent-bg); color: var(--text-secondary); }

.tr-msg a { color: var(--accent); font-weight: 700; }

.tr-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 22px;
}

.tr-action-btn {
    padding: 11px 20px;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    border-radius: var(--radius-md);
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition-fast);
}

.tr-action-btn:hover { background: var(--accent-bg); }

@media (max-width: 560px) {
    .tr-card, .tr-flip { width: 104px; }
    .tr-flip { height: 178px; }
    .tr-spread-area { gap: 12px; }
}

/* Tôn trọng người dùng tắt hiệu ứng chuyển động */
@media (prefers-reduced-motion: reduce) {
    .tr-deck-card, .tr-shuffle-text, .tr-dots span { animation: none; }
    .tr-card { animation-duration: .01ms; }
    .tr-flip { transition-duration: .01ms; }
}
