/* ==========================================
   1. 基礎設定與首頁卡片佈局 (主畫面 UI)
   ========================================== */
body {
    background-color: #E2E8F0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.main-container {
    width: 95%;
    max-width: 1200px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: 30px;
}

    .header h1 {
        color: #1A365D;
        font-size: 28px;
        font-weight: 800;
        margin-bottom: 5px;
    }

    .header p {
        color: #718096;
        font-size: 14px;
        margin: 0;
    }

.section-title {
    font-size: 14px;
    font-weight: bold;
    color: #4A5568;
    margin-bottom: 2px !important;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 25px;
}

.system-card {
    background-color: #F7FAFC;
    border: 2px solid #EDF2F7;
    border-radius: 12px;
    padding: 15px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

    .system-card:hover {
        border-color: #CBD5E0;
    }

    .system-card.active {
        border-color: #3182CE;
        background-color: #EBF8FF;
        box-shadow: 0 4px 6px rgba(49, 130, 206, 0.1);
    }

    .system-card .icon {
        display: block;
        font-size: 24px;
        margin-bottom: 5px;
    }

    .system-card .name {
        font-size: 13px;
        font-weight: bold;
        color: #2D3748;
    }

    .system-card.disabled {
        opacity: 0.5;
        cursor: not-allowed;
        pointer-events: none;
    }

.input-section {
    display: flex;
    flex-direction: column;
    gap: 5px !important;
}

.input-row {
    display: flex;
    gap: 10px;
}

.input-field {
    flex: 1;
    padding: 14px;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    font-size: 16px;
    text-align: center;
    background-color: #F7FAFC;
}

    .input-field.full-width {
        flex: none;
        width: 100%;
        box-sizing: border-box;
    }

    .input-field:focus {
        outline: none;
        border-color: #3182CE;
        background-color: #FFF;
    }

.analyze-btn {
    background-color: #2B6CB0;
    color: white;
    padding: 16px;
    border-radius: 10px;
    border: none;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.2s;
}

    .analyze-btn:hover {
        background-color: #2C5282;
    }

    .analyze-btn:disabled {
        background-color: #A0AEC0;
        cursor: not-allowed;
    }

.result-title {
    text-align: center;
    color: #2D3748;
    font-size: 20px;
    margin-bottom: 20px;
}

.basic-board {
    background-color: #F7FAFC;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    text-align: center;
    border: 1px dashed #CBD5E0;
}

.highlight-text {
    color: #DD6B20;
    font-size: 13px;
    font-weight: bold;
    margin-top: 10px;
}

.ai-report-container {
    position: relative;
    min-height: 200px;
}

.ai-title {
    background-color: #EBF8FF;
    color: #2B6CB0;
    margin: 0;
    padding: 15px;
    font-size: 16px;
    text-align: center;
    border-bottom: 1px solid #E2E8F0;
}

.report-content {
    padding: 20px;
    color: #4A5568;
    line-height: 1.6;
}

    .report-content.blurred {
        filter: blur(5px);
        user-select: none;
    }

.unlock-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    z-index: 10;
    padding: 20px;
    text-align: center;
}

    .unlock-overlay p {
        color: #2D3748;
        font-weight: bold;
        margin-bottom: 15px;
    }

.unlock-btn {
    margin-top: 10px;
    padding: 12px 24px;
    cursor: pointer;
}

.reset-btn {
    width: 100%;
    margin-top: 20px;
    padding: 15px;
    background: transparent;
    border: 1px solid #A0AEC0;
    color: #4A5568;
    border-radius: 10px;
    cursor: pointer;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

/* ==========================================
   2. 強制覆蓋左側選單的文字與 Icon 顏色 
   ========================================== */
.sidebar .nav-link,
.sidebar .nav-link span {
    color: #E2E8F0 !important;
}

    .sidebar .nav-link:hover,
    .sidebar .nav-link:hover span {
        color: #FFFFFF !important;
        background-color: rgba(255, 255, 255, 0.1) !important;
    }

    .sidebar .nav-link.active,
    .sidebar .nav-link.active span {
        color: #FFFFFF !important;
    }

/* ==========================================
   3. 手機版 App 級別底部導覽列 (Bottom Nav)
   ========================================== */
.bottom-nav {
    display: none;
}

/* ==========================================
   4. 數理五格專屬排版 
   ========================================== */
.wuge-board {
    background-color: #F8FAFC;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid #E2E8F0;
}

.wuge-title {
    text-align: center;
    color: #2B6CB0;
    font-weight: bold;
    margin-bottom: 15px;
    font-size: 18px;
}

.wuge-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.wuge-card {
    background-color: #FFFFFF;
    border: 1px solid #CBD5E0;
    border-radius: 8px;
    padding: 12px;
    font-size: 13px;
    color: #4A5568;
    line-height: 1.5;
    text-align: justify;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.wuge-total-card {
    background-color: #2D3748;
    color: #FFFFFF;
    border-radius: 8px;
    padding: 16px;
    font-size: 14px;
    font-weight: bold;
    line-height: 1.6;
    text-align: justify;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* ==========================================
   5. 網格與紫微命盤基礎佈局
   ========================================== */
.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 1000px;
    margin: 0 auto;
}

/* 🌟 新增：五行與氣場圖表容器 (大螢幕預設左右並排) */
.fortune-charts-container {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 20px;
    margin: 30px 0;
}

.result-section {
    width: 100%;
    padding: 20px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* --- 核心命盤 --- */
.ziwei-board {
    display: grid;
    grid-template-areas:
        "p4 p3 p2 p1"
        "p5 center center p12"
        "p6 center center p11"
        "p7 p8 p9 p10";
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    width: 100%;
    max-width: 700px;
    aspect-ratio: 1 / 1;
    margin: 40px auto;
    border: 3px solid #2d3748;
    background: #fff;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.2);
}

/*.palace {
    border: 1px solid #e2e8f0;
    padding: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: #ffffff;
    transition: background 0.3s;
    box-sizing: border-box;
}*/

.palace {
    border: 1px solid #e2e8f0;
    padding: 2px; /* 手機版建議減小 padding */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: #ffffff;
    min-width: 0; /* 重要：防止格子被內容撐爆 */
    overflow: hidden; /* 重要：防止內容溢出破壞格線 */
}

.palace-title {
    font-size: 13px;
    color: #4a5568;
    margin-bottom: 5px;
    font-weight: 600;
}

.star-tag {
    font-size: 11px;
    color: #2d3748;
    background: #f7fafc;
    padding: 2px 4px;
    border-radius: 3px;
    margin: 1px;
    display: inline-block;
}

.four-modern {
    color: #e53e3e;
    font-weight: bold;
    font-size: 12px;
    margin-top: 2px;
}

/* ==========================================
   6. 中間命主資訊框 (大螢幕預設)
   ========================================== */
.center-info {
    grid-column: 2 / 4;
    grid-row: 2 / 4;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: #fdfaf6;
    border: 1px solid #999;
    width: 100%;
    height: 100%;
    overflow: hidden;
    padding: 5px;
    box-sizing: border-box;
}

    .center-info img,
    .center-info .wuge-container,
    .center-info > div:not(.ai-title) {
        max-width: 100%;
        height: auto;
        object-fit: contain;
    }


/* ==========================================
   7. 響應式：平板與導覽列微調 (小於 768px)
   ========================================== */
@media (max-width: 768px) {
    .grid-container {
        grid-template-columns: repeat(2, 1fr);
    }

    .sidebar, .top-row {
        display: none !important;
    }

    .bottom-nav {
        display: flex;
        justify-content: space-around;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        border-top: 1px solid #E2E8F0;
        padding-top: 10px;
        padding-bottom: env(safe-area-inset-bottom, 15px);
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: #A0AEC0;
        font-size: 12px;
        font-weight: bold;
        flex: 1;
        transition: all 0.2s;
    }

        .bottom-nav-item .icon {
            font-size: 22px;
            margin-bottom: 4px;
            filter: grayscale(100%);
        }

        .bottom-nav-item.active {
            color: #2B6CB0;
        }

            .bottom-nav-item.active .icon {
                filter: grayscale(0%);
                transform: scale(1.1);
            }

    main {
        padding-bottom: 80px;
    }
}

/* ==========================================
   8. 響應式：手機版命盤強迫縮緊 (小於 600px) 終極修復版
   ========================================== */
@media (max-width: 600px) {

    /* --- 【關鍵修復】鎖死 4x4 佈局 --- */
    .ziwei-board {
        grid-template-columns: repeat(4, 1fr) !important;
        grid-template-rows: repeat(4, 1fr) !important;
        margin: 10px auto;
    }

    /* 縮小周圍 12 宮位的字體與間距，讓出空間 */
    .palace {
        padding: 2px;
    }

    /* 🌟 【最新修復】將五行與氣場圖表在手機上強制改為上下排列 */
    .fortune-charts-container {
        grid-template-columns: 1fr !important;
    }

    .palace-title {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .star-tag {
        font-size: 10px;
        padding: 1px 2px;
    }

    .four-modern {
        font-size: 10px;
    }

    /* 中間命主與五格資訊框：整體文字縮小 */
    .center-info {
        padding: 2px;
        font-size: 0.85em;
    }

        /* 針對五格圖或內部卡片強制縮放 75% */
        .center-info img,
        .center-info .wuge-container,
        .center-info > div:not(.ai-title) {
            transform: scale(0.75);
            transform-origin: top center;
            max-width: 100%;
            margin-top: -5px;
        }

    /* --- 其他小螢幕排版修正 --- */
    .main-container {
        padding: 10px !important;
        margin: 5px auto !important;
    }

    .header h1 {
        font-size: 24px;
        margin-bottom: 5px !important;
    }

    .header p {
        font-size: 14px;
        margin-bottom: 10px;
    }

    .grid-3 {
        gap: 8px !important;
    }

    .system-card {
        padding: 10px 5px !important;
        font-size: 12px;
    }

    .input-section {
        padding: 10px !important;
    }

    /* --- 輸入框區塊自動換行防擠壓 --- */
    .input-row {
        flex-wrap: wrap !important;
        align-items: center;
        gap: 8px !important;
        margin-bottom: 12px !important;
    }

        /* 防止前面的文字標籤斷行 */
        .input-row label,
        .input-row span,
        .input-row div {
            white-space: nowrap;
            font-size: 14px;
        }

    .input-field {
        flex: 1 1 auto !important;
        min-width: 80px !important;
        padding: 10px !important;
        font-size: 14px !important;
    }

    .summary-card {
        padding: 8px !important;
        margin: 8px 0 !important;
        font-size: 12px !important;
    }

    .analyze-btn {
        padding: 12px !important;
        font-size: 15px !important;
    }
}
