/* ============================================================================
   ATech Thiên Cơ - Tu Vi Chart v3.1 — Mystical Design (Mobile Compatible)
   All effects use standard CSS (no @property) for iOS/Safari support
   ============================================================================ */

/* ===== CHART WRAPPER — Animated Border Glow ===== */
.tuvi-chart-wrapper {
    position: relative;
    border-radius: 16px;
    padding: 2px;
    margin: 16px 0;
    overflow: hidden;

    /* Outer aura */
    box-shadow:
        0 0 30px rgba(245, 158, 11, 0.12),
        0 0 60px rgba(139, 92, 246, 0.08);

    animation: wrapperReveal 0.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
}

@keyframes wrapperReveal {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(10px);
        filter: blur(3px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
        filter: blur(0);
    }
}

/* Rotating gradient border — uses transform:rotate (works on ALL browsers) */
.tuvi-chart-wrapper::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(from 0deg,
            rgba(245, 158, 11, 0.6),
            rgba(139, 92, 246, 0.4),
            rgba(245, 158, 11, 0.1),
            rgba(139, 92, 246, 0.6),
            rgba(245, 158, 11, 0.6));
    animation: borderRotate 6s linear infinite;
    z-index: 0;
}

@keyframes borderRotate {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Shimmer light sweep */
.tuvi-chart-wrapper::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg,
            transparent 35%,
            rgba(245, 158, 11, 0.05) 42%,
            rgba(255, 255, 255, 0.07) 48%,
            rgba(139, 92, 246, 0.05) 55%,
            transparent 65%);
    background-size: 250% 100%;
    animation: shimmerSweep 4s ease-in-out infinite;
    pointer-events: none;
    z-index: 10;
    border-radius: 16px;
}

@keyframes shimmerSweep {
    0% {
        background-position: 250% 0;
    }

    100% {
        background-position: -250% 0;
    }
}

/* ===== CHART GRID ===== */
.tuvi-chart {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, auto);
    gap: 1px;
    border-radius: 14px;
    overflow: hidden;
    font-family: 'Spectral', 'Be Vietnam Pro', serif;
    width: 100%;
    position: relative;
    z-index: 1;
    background: rgba(15, 23, 42, 0.95);
}

/* ===== PALACE CELL ===== */
.palace-cell {
    background: rgba(2, 6, 23, 0.95);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    padding: 6px 4px;
    min-height: 140px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);

    /* Staggered entrance */
    opacity: 0;
    transform: translateY(6px);
    animation: cellSlideIn 0.45s ease-out forwards;
}

.palace-cell:nth-child(1) {
    animation-delay: 0.08s;
}

.palace-cell:nth-child(2) {
    animation-delay: 0.12s;
}

.palace-cell:nth-child(3) {
    animation-delay: 0.16s;
}

.palace-cell:nth-child(4) {
    animation-delay: 0.2s;
}

.palace-cell:nth-child(5) {
    animation-delay: 0.24s;
}

.palace-cell:nth-child(6) {
    animation-delay: 0.28s;
}

.palace-cell:nth-child(7) {
    animation-delay: 0.32s;
}

.palace-cell:nth-child(8) {
    animation-delay: 0.36s;
}

.palace-cell:nth-child(9) {
    animation-delay: 0.4s;
}

.palace-cell:nth-child(10) {
    animation-delay: 0.44s;
}

.palace-cell:nth-child(11) {
    animation-delay: 0.48s;
}

.palace-cell:nth-child(12) {
    animation-delay: 0.52s;
}

@keyframes cellSlideIn {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Subtle purple ambient per cell */
.palace-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 25% 15%, rgba(139, 92, 246, 0.06) 0%, transparent 55%);
    pointer-events: none;
}

/* ===== MỆNH — Golden Aura ===== */
.palace-cell.is-menh {
    background: linear-gradient(170deg, rgba(245, 158, 11, 0.1) 0%, rgba(2, 6, 23, 0.92) 35%);
}

.palace-cell.is-menh::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #f59e0b, rgba(245, 158, 11, 0.3), transparent);
    animation: menhBar 2.5s ease-in-out infinite;
}

@keyframes menhBar {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

.palace-cell.is-menh .palace-name {
    color: #fcd34d;
    text-shadow: 0 0 14px rgba(252, 211, 77, 0.6);
}

/* ===== THÂN — Violet Aura ===== */
.palace-cell.is-than {
    background: linear-gradient(170deg, rgba(139, 92, 246, 0.1) 0%, rgba(2, 6, 23, 0.92) 35%);
}

.palace-cell.is-than::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #8b5cf6, rgba(139, 92, 246, 0.3), transparent);
}

/* ===== PALACE HEADER ===== */
.palace-header {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}

.palace-name {
    font-size: 11.5px;
    font-weight: 800;
    color: #fbbf24;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
}

.palace-chi {
    font-size: 10px;
    color: rgba(148, 163, 184, 0.8);
    font-weight: 600;
    margin-left: 2px;
}

/* ===== TAGS — Glowing Badges ===== */
.tv-tag {
    display: inline-block;
    font-size: 8px;
    padding: 2px 5px;
    border-radius: 4px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
    margin-left: auto;
}

/* Shimmer sweep on tag */
.tv-tag::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    animation: tagSweep 2.5s ease-in-out infinite;
}

@keyframes tagSweep {

    0%,
    70% {
        left: -100%;
    }

    100% {
        left: 100%;
    }
}

.tv-tag-menh {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.35), rgba(234, 88, 12, 0.2));
    color: #fcd34d;
    border: 1px solid rgba(245, 158, 11, 0.5);
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.25);
    animation: glowPulse 2.5s ease-in-out infinite;
}

@keyframes glowPulse {

    0%,
    100% {
        box-shadow: 0 0 6px rgba(245, 158, 11, 0.2);
    }

    50% {
        box-shadow: 0 0 14px rgba(245, 158, 11, 0.5);
    }
}

.tv-tag-than {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.35), rgba(99, 102, 241, 0.2));
    color: #c4b5fd;
    border: 1px solid rgba(139, 92, 246, 0.5);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.25);
}

/* ===== STARS ===== */
.palace-stars {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.main-stars {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 2px;
    margin-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 4px;
}

.minor-stars-container {
    display: flex;
    justify-content: space-between;
    gap: 4px;
    flex: 1;
}

.minor-stars-left,
.minor-stars-right {
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 48%;
}

.minor-stars-right {
    align-items: flex-end;
    text-align: right;
}

.tv-star {
    font-size: 9.5px;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
    white-space: nowrap;
    line-height: 1.5;
    -webkit-transition: transform 0.2s;
    transition: transform 0.2s;
}

.tv-star:active {
    -webkit-transform: scale(1.15);
    transform: scale(1.15);
}

.tv-star-good {
    color: #34d399;
    background: rgba(52, 211, 153, 0.1);
    text-shadow: 0 0 8px rgba(52, 211, 153, 0.4);
}

.tv-star-bad {
    color: #fb7185;
    background: rgba(251, 113, 133, 0.1);
    text-shadow: 0 0 6px rgba(251, 113, 133, 0.3);
}

.tv-star-neutral {
    color: #93c5fd;
    background: rgba(147, 197, 253, 0.07);
}

/* Ngũ Hành Specific Styling - Crucial for Master Interpretation */
.tv-star.element-kim {
    color: var(--color-kim);
    text-shadow: 0 0 8px rgba(253, 224, 71, 0.3);
}

.tv-star.element-moc {
    color: var(--color-moc);
    text-shadow: 0 0 8px rgba(74, 222, 128, 0.3);
}

.tv-star.element-thuy {
    color: var(--color-thuy);
    text-shadow: 0 0 8px rgba(56, 189, 248, 0.3);
}

.tv-star.element-hoa {
    color: var(--color-hoa);
    text-shadow: 0 0 8px rgba(251, 113, 133, 0.3);
}

.tv-star.element-tho {
    color: var(--color-tho);
    text-shadow: 0 0 8px rgba(251, 146, 60, 0.3);
}

/* Star Brightness Indicators */
.tv-star-brightness {
    font-size: 7.5px;
    font-weight: 700;
    margin-left: 2px;
    opacity: 0.7;
    color: #94a3b8;
    vertical-align: super;
}

.major-stars .tv-star {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    display: block;
    /* One major star per line for clarity */
    margin-bottom: 0px;
    letter-spacing: 0.5px;
    padding: 0;
    background: none;
    border: none;
}

.tv-star-minor {
    font-size: 8px;
    line-height: 1.2;
    opacity: 0.85;
    white-space: normal;
    background: none !important;
    padding: 0 !important;
}

.tv-star-hua {
    font-style: italic;
    font-weight: 700;
    border-bottom: 1px dashed currentColor;
}

/* ===== ĐẠI VẬN ===== */
.palace-daivan {
    font-size: 8px;
    color: rgba(148, 163, 184, 0.6);
    margin-top: auto;
    padding-top: 4px;
    text-align: right;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ===== CENTER INFO — Celestial Core ===== */
.chart-center {
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.98), rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.98));
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    padding: 14px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    overflow: hidden;

    opacity: 0;
    animation: centerFadeIn 0.7s ease-out 0.35s forwards;
}

@keyframes centerFadeIn {
    from {
        opacity: 0;
        -webkit-transform: scale(0.92);
        transform: scale(0.92);
    }

    to {
        opacity: 1;
        -webkit-transform: scale(1);
        transform: scale(1);
    }
}

/* Breathing aura */
.chart-center::before {
    content: '';
    position: absolute;
    width: 200px;
    height: 200px;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(245, 158, 11, 0.1) 0%, rgba(139, 92, 246, 0.05) 40%, transparent 70%);
    pointer-events: none;
    animation: auraBreathe 4s ease-in-out infinite;
}

@keyframes auraBreathe {

    0%,
    100% {
        opacity: 0.4;
        -webkit-transform: translate(-50%, -50%) scale(0.8);
        transform: translate(-50%, -50%) scale(0.8);
    }

    50% {
        opacity: 1;
        -webkit-transform: translate(-50%, -50%) scale(1.3);
        transform: translate(-50%, -50%) scale(1.3);
    }
}

/* Orbiting ring */
.chart-center::after {
    content: '';
    position: absolute;
    width: 90px;
    height: 90px;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    border: 1px dashed rgba(245, 158, 11, 0.15);
    border-radius: 50%;
    animation: orbitSpin 18s linear infinite;
    pointer-events: none;
}

@keyframes orbitSpin {
    from {
        -webkit-transform: translate(-50%, -50%) rotate(0deg);
        transform: translate(-50%, -50%) rotate(0deg);
    }

    to {
        -webkit-transform: translate(-50%, -50%) rotate(360deg);
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ===== BAGUA ===== */
.center-bagua {
    font-size: 32px;
    opacity: 0.06;
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    pointer-events: none;
    animation: baguaRotate 22s linear infinite;
}

@keyframes baguaRotate {
    from {
        -webkit-transform: translate(-50%, -50%) rotate(0deg);
        transform: translate(-50%, -50%) rotate(0deg);
    }

    to {
        -webkit-transform: translate(-50%, -50%) rotate(360deg);
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ===== CENTER TITLE ===== */
.center-title {
    font-family: 'Playfair Display', serif;
    font-size: 15px;
    font-weight: 800;
    color: #fbbf24;
    margin-bottom: 8px;
    letter-spacing: 2.5px;
    position: relative;
    z-index: 1;
    text-shadow: 0 0 16px rgba(251, 191, 36, 0.5), 0 0 40px rgba(251, 191, 36, 0.15);
    animation: titlePulse 3s ease-in-out infinite;
}

@keyframes titlePulse {

    0%,
    100% {
        text-shadow: 0 0 12px rgba(251, 191, 36, 0.4);
    }

    50% {
        text-shadow: 0 0 22px rgba(251, 191, 36, 0.8), 0 0 50px rgba(251, 191, 36, 0.2);
    }
}

.center-title::after {
    content: '';
    display: block;
    width: 40px;
    height: 1px;
    background: linear-gradient(90deg, transparent, #f59e0b, transparent);
    margin: 6px auto 0;
    animation: lineExpand 3s ease-in-out infinite;
}

@keyframes lineExpand {

    0%,
    100% {
        width: 25px;
        opacity: 0.5;
    }

    50% {
        width: 55px;
        opacity: 1;
    }
}

/* ===== CENTER INFO ===== */
.center-info {
    width: 100%;
    position: relative;
    z-index: 1;
}

.ci-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 11px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ci-row:last-child {
    border-bottom: none;
}

.ci-label {
    color: rgba(148, 163, 184, 0.7);
    font-size: 10px;
}

.ci-val {
    color: #f1f5f9;
    font-weight: 600;
    font-size: 11px;
}

/* ===== BRAND ===== */
.center-brand {
    margin-top: 8px;
    font-size: 7.5px;
    color: rgba(245, 158, 11, 0.4);
    font-weight: 700;
    letter-spacing: 1.8px;
    position: relative;
    z-index: 1;
    animation: brandHover 5s ease-in-out infinite;
}

@keyframes brandHover {

    0%,
    100% {
        opacity: 0.4;
        -webkit-transform: translateY(0);
        transform: translateY(0);
    }

    50% {
        opacity: 0.6;
        -webkit-transform: translateY(-1px);
        transform: translateY(-1px);
    }
}

/* ===== MOBILE ===== */
@media (max-width: 480px) {
    .tuvi-chart-wrapper {
        border-radius: 14px;
        margin: 12px 0;
    }

    .tuvi-chart {
        border-radius: 12px;
    }

    .palace-cell {
        padding: 6px 4px;
        min-height: 90px;
    }

    .palace-name {
        font-size: 10px;
        letter-spacing: 0.5px;
    }

    .palace-chi {
        font-size: 9px;
    }

    .tv-star {
        font-size: 8.5px;
        padding: 1px 2px;
    }

    .tv-star-minor {
        font-size: 7.5px;
    }

    .tv-tag {
        font-size: 7px;
        padding: 1px 3px;
    }

    .center-title {
        font-size: 12.5px;
        letter-spacing: 2px;
    }

    .ci-row {
        font-size: 10px;
        padding: 3px 0;
    }

    .ci-label {
        font-size: 9px;
    }

    .ci-val {
        font-size: 10px;
    }

    .palace-daivan {
        font-size: 7.5px;
    }

    .center-brand {
        font-size: 6.5px;
    }

    .center-bagua {
        font-size: 26px;
    }
}

@media (max-width: 360px) {
    .palace-cell {
        min-height: 78px;
        padding: 4px 3px;
    }

    .palace-name {
        font-size: 9px;
    }

    .tv-star {
        font-size: 7.5px;
    }

    .center-title {
        font-size: 10.5px;
    }

    .ci-row {
        font-size: 8.5px;
    }
}