/* ═══════ Ziwei Doushu Chart — 紫微斗数命盘 v3 (Konton 和モダン) ═══════ */

.ziwei-scroll-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    touch-action: pan-x pan-y pinch-zoom;
}

.ziwei-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, minmax(0, 1fr));
    gap: 2px;
    max-width: 800px;
    margin: 0 auto;
}

/* ─── Palace Cell ─── */
.ziwei-cell {
    background: var(--bg-glass);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 5px 6px 4px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

.ziwei-cell::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(140, 108, 216, 0.04) 0%, transparent 50%);
    pointer-events: none;
}

.ziwei-cell:hover {
    border-color: var(--color-purple);
    box-shadow: 0 0 15px rgba(140, 108, 216, 0.12);
    transform: scale(1.01);
}

.ziwei-cell:active { transform: scale(0.99); }

/* 命宫高亮 */
.ziwei-cell.ming-gong {
    border-color: var(--color-gold);
    box-shadow: 0 0 20px var(--color-gold-glow);
}
.ziwei-cell.ming-gong::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(230, 193, 112, 0.06) 0%, transparent 60%);
    pointer-events: none;
}
/* 身宫高亮 */
.ziwei-cell.shen-gong {
    border-color: var(--color-purple-dim);
    box-shadow: 0 0 12px rgba(140, 108, 216, 0.1);
}

/* Branch label — top right corner */
.palace-branch-corner {
    position: absolute;
    top: 3px;
    right: 5px;
    font-size: 10px;
    color: var(--text-tertiary);
    z-index: 1;
}

/* ─── Stars Section ─── */
.stars-section {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding-top: 2px;
}

.star-row {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: wrap;
}

.star-name {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    text-shadow: 0 0 8px currentColor;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 主星 */
.star-major { color: var(--color-purple); font-weight: 600; }

.brightness-label {
    font-size: 9px;
    font-weight: normal;
    text-shadow: none;
    opacity: 0.8;
}

/* 庙旺标签 */
.brightness-miao, .brightness-wang { color: var(--color-gold); }
.brightness-de, .brightness-li { color: var(--text-secondary); }
.brightness-ping { color: var(--text-tertiary); }
.brightness-xian { color: var(--text-tertiary); opacity: 0.5; }

/* 辅星 */
.star-aux {
    font-size: 10px;
    color: var(--color-success);
    line-height: 1.3;
    white-space: nowrap;
}

.aux-row {
    gap: 3px;
    margin-top: 1px;
}

/* 煞星 */
.star-sha {
    font-size: 10px;
    color: var(--color-danger);
    line-height: 1.3;
    text-shadow: 0 0 4px rgba(239, 71, 54, 0.3);
    white-space: nowrap;
}

.sha-row { gap: 3px; }

/* 杂曜 */
.star-misc {
    font-size: 9px;
    color: var(--text-tertiary);
    line-height: 1.2;
    white-space: nowrap;
}

.misc-row { gap: 3px; margin-top: 1px; }

/* ─── SiHua Badges ─── */
.sihua-badge {
    display: inline-block;
    font-size: 9px;
    padding: 0 3px;
    border-radius: 3px;
    margin-left: 2px;
    font-weight: bold;
    vertical-align: middle;
    line-height: 1.4;
}

.sihua-lu {
    background: rgba(123, 198, 126, 0.15);
    color: var(--color-success);
}
.sihua-quan {
    background: rgba(239, 71, 54, 0.15);
    color: var(--color-danger);
}
.sihua-ke {
    background: rgba(54, 191, 240, 0.15);
    color: var(--color-info);
}
.sihua-ji {
    background: rgba(255, 140, 0, 0.15);
    color: #FF8C00;
}

/* ─── Palace Footer (name + daxian) ─── */
.palace-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 2px;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
}

/* 宫名 */
.palace-name {
    font-size: 11px;
    color: var(--text-gold);
    font-weight: 600;
    white-space: nowrap;
}

.palace-ming-mark {
    color: var(--color-gold);
    font-size: 10px;
    text-shadow: 0 0 6px rgba(230, 193, 112, 0.5);
    margin-left: 2px;
}

.palace-shen-mark {
    color: var(--color-purple);
    font-size: 10px;
    text-shadow: 0 0 6px rgba(140, 108, 216, 0.5);
    margin-left: 2px;
}

.daxian-label {
    font-size: 9px;
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* ─── Center Panel ─── */
.ziwei-center {
    grid-column: 2 / 4;
    grid-row: 2 / 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    cursor: default;
    position: relative;
    overflow: visible;
    gap: 1px;
}

.ziwei-center::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(230, 193, 112, 0.05) 0%, transparent 70%);
    pointer-events: none;
    border-radius: var(--radius-md);
}

.center-name {
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: 600;
    line-height: 1.3;
}

.center-info {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    line-height: 1.4;
}

.center-wuxing {
    font-size: 0.8rem;
    color: var(--color-gold);
    font-weight: 600;
    margin: 1px 0;
}

.center-row {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.7rem;
    line-height: 1.3;
}

.center-label {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.center-value {
    color: var(--text-secondary);
}

.center-warning {
    font-size: 0.65rem;
    color: #FF8C00;
    background: rgba(255, 140, 0, 0.08);
    padding: 1px 6px;
    border-radius: 3px;
    line-height: 1.4;
}

.center-ming-stars {
    font-size: 0.7rem;
    color: var(--color-purple);
    margin-top: 2px;
    text-shadow: 0 0 8px rgba(140, 108, 216, 0.4);
}

/* Si Zhu (Four Pillars) */
.center-sizhu {
    display: flex;
    gap: 4px;
    margin: 2px 0;
}

.sizhu-pillar {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2px 5px;
    border-radius: 4px;
    background: var(--color-purple-bg);
    border: 1px solid var(--border-light);
}

.sizhu-label {
    font-size: 0.55rem;
    opacity: 0.6;
    line-height: 1.2;
}

.sizhu-value {
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.3;
}

/* ─── Palace Detail Panel ─── */
#palace-detail {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

#palace-detail .detail-section { margin-bottom: 12px; }

#palace-detail .detail-section-title {
    font-size: 12px;
    color: var(--color-gold);
    font-weight: 600;
    margin-bottom: 6px;
    padding-bottom: 3px;
    border-bottom: 1px solid var(--border-gold);
}

#palace-detail .detail-star-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
}

#palace-detail .detail-star-name {
    font-weight: 600;
    text-shadow: 0 0 6px currentColor;
    min-width: 40px;
}

#palace-detail .detail-star-desc {
    color: var(--text-tertiary);
    font-size: 12px;
}

#palace-detail .detail-daxian {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 6px 10px;
    background: var(--color-purple-bg);
    border-radius: 6px;
    border: 1px solid var(--border-light);
}

/* ─── Mobile Responsive ─── */
@media (max-width: 640px) {
    .ziwei-scroll-wrapper {
        position: relative;
        overflow: auto;
    }

    .ziwei-grid {
        min-width: 520px;
        min-height: 520px;
    }

    .star-name { font-size: 11px; }
    .ziwei-cell { padding: 4px; }
    .palace-name { font-size: 10px; }
    .center-name { font-size: 0.9rem; }
    .center-info { font-size: 0.6rem; }
    .center-wuxing { font-size: 0.7rem; }
    .center-row { font-size: 0.6rem; }
    .sizhu-value { font-size: 0.65rem; }
    .sizhu-pillar { padding: 1px 3px; }
    .center-sizhu { gap: 3px; }
    .center-ming-stars { font-size: 0.6rem; }
    .ziwei-center { padding: 6px 8px; gap: 1px; }
}

@media (max-width: 400px) {
    .ziwei-grid {
        min-width: 460px;
        min-height: 460px;
    }
}

/* ─── Pattern Header + Key Palace Cards ─── */
.pattern-header {
    text-align: center;
    padding: 16px 20px;
    margin-bottom: 12px;
    background: var(--bg-glass);
    backdrop-filter: blur(15px);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
}

.pattern-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at center, rgba(230, 193, 112, 0.05) 0%, transparent 70%);
    pointer-events: none;
}

.pattern-name {
    font-family: var(--font-serif);
    font-size: 20px;
    font-weight: 700;
    color: var(--color-gold);
    text-shadow: 0 0 12px rgba(230, 193, 112, 0.2);
    margin-bottom: 4px;
}

.pattern-desc {
    font-size: 13px;
    color: var(--color-gold-light);
    margin-bottom: 6px;
}

.pattern-trait {
    font-size: 12px;
    color: var(--text-tertiary);
    line-height: 1.6;
}

.key-palaces {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.palace-card {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.palace-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(140, 108, 216, 0.03) 0%, transparent 60%);
    pointer-events: none;
}

.palace-card:hover {
    border-color: var(--color-purple);
    box-shadow: 0 0 12px rgba(140, 108, 216, 0.1);
}

.palace-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.palace-card-icon {
    font-size: 14px;
    line-height: 1;
}

.palace-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-gold);
}

.palace-card-label {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-left: auto;
}

.palace-card-stars {
    font-size: 14px;
    font-weight: 600;
    color: var(--color-purple);
    text-shadow: 0 0 8px rgba(140, 108, 216, 0.3);
    margin-bottom: 6px;
}

.palace-card-reading {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
}

@media (max-width: 480px) {
    .key-palaces {
        grid-template-columns: 1fr;
    }

    .pattern-name { font-size: 18px; }
    .palace-card { padding: 10px 12px; }
}

/* ─── AI Reading Text ─── */
.ai-reading-text {
    line-height: 1.8;
    white-space: pre-wrap;
}

.reading-tab {
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 13px;
    color: var(--text-tertiary);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.reading-tab.active {
    color: var(--color-gold);
    border-color: var(--border-gold);
    background: var(--gold-glow);
}

/* ─── Sanfang Lines ─── */
.sanfang-line {
    stroke: var(--color-purple-light);
    stroke-dasharray: 4 4;
    opacity: 0.4;
}
