﻿/* ---------------------------------------------------- */
/* SECTION 1: GLOBAL DEFINITIONS AND VARIABLES            */
/* ---------------------------------------------------- */

/* Font face must be defined globally to be available for all components. */
@font-face {
    font-family: 'FZKAI-Z03 REGULAR';
    src: url('/fonts/FZKAI-Z03 REGULAR.TTF') format('truetype');
    font-weight: normal;
    font-style: normal;
}

:root {
    /* Fonts and Sizing */
    --cn-font-family: 'FZKAI-Z03 REGULAR', serif;
    --app-height: 100vh; /* 100% visible screen height */
    --base-font-size: clamp(12px, 1.4vw, 16px);
    --cn-font-size: clamp(18px, 5.5vw, 28px);
    --small-font-size: clamp(14px, 1.2vw, 14px);
    /* UI Styling */
    --border-color: #ccc;
    --panel-gap: 8px;
    --panel-radius: 12px;
    --panel-shadow: 0 2px 8px rgba(0,0,0,.06);
    --bg-muted: #f7f7f8;
    --bs-white: #ffffff;
    /* BaZi Element Colors */
    --bazi-wood: #228B22; /* Forest Green */
    --bazi-metal: #808080; /* Gray */
    --bazi-earth: #D2B48C; /* Sandy Brown */
    --bazi-fire: #B22222; /* Firebrick Red */
    --bazi-water: #1E90FF; /* Dodger Blue */
    --colorLeader1: darkcyan; /* Special Case */
}

/* ---------------------------------------------------- */
/* SECTION 2: GLOBAL COLOR MAPPING (Required for BaZi elements) */
/* ---------------------------------------------------- */
/* These rules use !important globally to ensure BaZi element colors are applied. */

/* Generic Element Colors */
.color-green, .text-wood, .color-warn-0 {
    color: var(--bazi-wood) !important;
}

.color-gray, .text-metal {
    color: var(--bazi-metal) !important;
}

.color-sandybrown, .text-earth {
    color: var(--bazi-earth) !important;
}

.color-red, .text-fire, .color-warn-1 {
    color: var(--bazi-fire) !important;
}

.color-blue, .text-water {
    color: var(--bazi-water) !important;
}

/* Primary BaZi Character Colors (Mapped by class index) */
span.cn_word.color0, span.cn_word.color1, span.cn_word.colorEB2, span.cn_word.colorEB3 {
    color: var(--bazi-wood) !important;
}

span.cn_word.color6, span.cn_word.color7, span.cn_word.colorEB8, span.cn_word.colorEB9 {
    color: var(--bazi-metal) !important;
}

span.cn_word.color4, span.cn_word.color5, span.cn_word.colorEB1, span.cn_word.colorEB4, span.cn_word.colorEB7, span.cn_word.colorEB10 {
    color: var(--bazi-earth) !important;
}

span.cn_word.color2, span.cn_word.color3, span.cn_word.colorEB5, span.cn_word.colorEB6 {
    color: var(--bazi-fire) !important;
}

span.cn_word.color8, span.cn_word.color9, span.cn_word.colorEB0, span.cn_word.colorEB11 {
    color: var(--bazi-water) !important;
}

/* Secondary Info Panel Colors */
.colorLeader1, .text-leader {
    color: darkcyan !important;
}

.colorLeader4, .colorStar3, .colorStar4, .colorGate3, .colorGate4 {
    color: var(--bazi-wood) !important;
}

.colorLeader3, .colorLeader5, .colorLeader8, .colorStar7, .colorStar8, .colorGate7, .colorGate8 {
    color: var(--bazi-metal) !important;
}

.colorLeader7, .colorStar2, .colorStar6, .colorStar9, .colorGate2, .colorGate6 {
    color: var(--bazi-earth) !important;
}

.colorLeader2, .colorStar5, .colorGate5 {
    color: var(--bazi-fire) !important;
}

.colorLeader6, .colorStar1, .colorGate1 {
    color: var(--bazi-water) !important;
}

/* Qimen Grid Highlight Classes */
.border-blue {
    border: 2px solid var(--bazi-water) !important; /* Dodger Blue */
}

/*.highlight-yellow {
    background-color: #ffd700 !important;*/ /* Gold/Yellow for Harms/Special Line */
/*}*/

.highlight-red {
    background-color: #FF0000 !important;
}

/* Base style for the inner Chinese text elements */
.fzkai-text-responsive {
    font-family: var(--cn-font-family);
    font-size: var(--base-font-size); /* Use a standard size, max 16px on desktop */
    font-weight: 600;
}

/* ---------------------------------------------------- */
/* SECTION 3: CORE APPLICATION LAYOUT (Desktop First)     */
/* ---------------------------------------------------- */

/* Outer Layout: Sets background for the entire screen */
.outer-layout {
    background-color: #f6e3da; /* Beach Color */
    min-height: var(--app-height);
    display: flex;
    justify-content: center;
    padding: 0;
    margin: 0;
}

/* Main Content Wrapper: Constrains width and provides white background */
.main-content-wrapper {
    width: 100%;
    max-width: 100%;
    background-color: white;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
}

/* Desktop/Tablet 80% Constraint */
@media (min-width: 768px) {
    .main-content-wrapper {
        max-width: 80%; /* Limits width to 80% on desktop/tablet */
    }

    .text-wood,
    .text-metal,
    .text-earth,
    .text-fire,
    .text-water {
        font-size: 1.8rem;
    }
}

/* Header Image Styling */
.header-picture-container {
    width: 100%;
    max-height: 200px;
    overflow: hidden;
}

    .header-picture-container img {
        object-fit: cover;
        height: 100%;
    }

/* Navbar Fixes */
.navbar-nav {
    width: 100%;
    display: flex;
    justify-content: center;
}

@media (min-width: 992px) {
    .navbar-collapse {
        justify-content: flex-end !important;
    }

    .navbar-nav {
        justify-content: center;
        flex-grow: 1;
    }
}

/* ---------------------------------------------------- */
/* SECTION 4: BAZI QIMEN LAYOUT (Desktop/Tablet 60/40 Split) */
/* ---------------------------------------------------- */

.bazi-container {
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 0;
    background-color: transparent;
}

    .bazi-container .wrapper {
        display: flex;
        gap: var(--panel-gap);
        margin-top: 20px;
        align-items: stretch;
        flex-wrap: nowrap;
        width: 100% !important;
        box-sizing: border-box;
    }

    /* Left Panel: BaZi Table (60%) */
    .bazi-container .bazi {
        flex: 0 0 60% !important;
        width: 60% !important;
        box-sizing: border-box;
        padding: 15px;
        border: 1px solid var(--border-color);
        border-radius: var(--panel-radius);
        box-shadow: var(--panel-shadow);
        background-color: var(--bg-muted);
        min-width: 0;
        overflow: hidden;
    }

    /* Right Panel: Info Table (40%) */
    .bazi-container .info {
        flex: 0 0 40% !important;
        width: 40% !important;
        box-sizing: border-box;
        padding: 15px;
        border: 1px solid var(--border-color);
        border-radius: var(--panel-radius);
        box-shadow: var(--panel-shadow);
        background-color: var(--bg-muted);
        min-width: 0;
        overflow: hidden;
    }

.bg-light-green {
    background-color: #dcffcf !important;
}
/* ---------------------------------------------------- */
/* SECTION 5: UTILITIES, TYPOGRAPHY, AND LOGO OVERLAY     */
/* ---------------------------------------------------- */

/* Base Typography */
.cn_word {
    font-family: var(--cn-font-family);
    font-size: var(--cn-font-size);
    line-height: 1.1;
    display: inline-block;
}

.custom-footer-text {
    font-size: 1.0rem;
}

.bg-warm-brown {
    background-color: #008080 !important;
}

/* App Content Wrapper for Centering and Max-width */
#app-content-wrapper {
    margin-left: auto;
    margin-right: auto;
    max-width: 1400px;
    padding: 0 20px;
}

/* Logo Overlay Container */
#logo-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: none;
}

    #logo-overlay img {
        opacity: 0.1;
        object-fit: contain;
        max-width: 40vw;
        max-height: 40vh;
        min-width: 290px;
        min-height: 290px;
    }

/* ---------------------------------------------------- */
/* SECTION 6: RESPONSIVE OVERRIDES (MOBILE & TABLET)      */
/* ---------------------------------------------------- */

@media (max-width: 768px) {
    /* --- General Mobile Layout --- */
    .outer-layout {
        padding: 0;
        margin: 0;
        overflow-x: hidden;
    }

    /* CRUCIAL: Set padding here, and ensure it's inside the width */
    .main-content-wrapper {
        width: 100vw;
        box-shadow: none !important;
        padding-left: 8px;
        padding-right: 8px;
        box-sizing: border-box;
    }

    .header-picture-container {
        max-height: 120px;
    }

    /* --- Navbar & Login/Logout --- */
    .navbar-collapse {
        flex-direction: column;
        align-items: flex-start;
        padding: 0 1rem 1rem;
    }

    .navbar-nav {
        flex-grow: unset;
        width: 100%;
        justify-content: flex-start;
    }

        .navbar-nav .nav-item {
            margin: 0.5rem 0;
        }

    /* --- BaZi QiMen Layout (Stack Panels) --- */
    .bazi-container .wrapper {
        flex-direction: column;
        gap: var(--panel-gap);
        margin-top: 10px;
    }

    .bazi-container .bazi,
    .bazi-container .info {
        flex: 1 1 100% !important;
        width: 100% !important;
        padding: 10px;
    }

        /* ------------------------------------------------ */
        /* *** INFO PANEL MOBILE FIXES (Final Vertical Fit) *** */
        /* ------------------------------------------------ */

        .bazi-container .info td {
            font-size: 0.8rem !important;
            /* CRITICAL: Reduce overall vertical padding to minimum to fit all rows */
            padding: 2px 5px !important;
        }

        .bazi-container .info table {
            margin: 0 !important;
            padding: 0 !important;
        }

        .bazi-container .info .key {
            white-space: normal;
            width: 35%;
            line-height: 1; /* Tighten line height */
        }

        .bazi-container .info .cn_word {
            font-size: 1rem !important;
            line-height: 1; /* Tighten line height */
        }

        .bazi-container .info .val,
        .bazi-container .info .en-text-responsive {
            font-size: 0.8rem !important;
            line-height: 1; /* Tighten line height */
        }

    /* --- Logo Overlay Adjustment (Mobile) --- */
    #app-content-wrapper {
        max-width: 100%;
        padding: 0;
    }

    #logo-overlay img {
        max-width: 80vw;
        max-height: 35vh;
        min-width: 100px;
        min-height: 100px;
        opacity: 0.1;
    }

    /* ------------------------------------------------ */
    /* *** Qimen Grid Mobile Overrides (3x3 Fit) *** */
    /* ------------------------------------------------ */

    .table-container {
        padding: 0;
        margin: 10px auto;
        background-color: var(--bg-muted);
    }

    .grid {
        max-width: 100%;
        width: 100%;
        align-items: stretch;
        border-width: 1px;
    }

    /* CRITICAL MOBILE FIXES FOR INNER GRID STRUCTURE */
    .inner-grid {
        min-height: 70px; /* Reduced minimum height */
        height: auto !important; /* IMPORTANT: Remove the fixed height */
        padding: 0px;
        align-content: space-around;
        align-items: stretch;
    }

    .inner-cell {
        padding: 0px 1px;
        /*line-height: 1.0;*/
        min-width: 0;
        justify-content: center;
        align-items: center;
        /* CRITICAL: Allow text wrapping on mobile to fit the narrow column */
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
    }

    .inner-cell-row-item {
        /* CRITICAL: Ensure nested content can wrap */
        flex-wrap: wrap !important;
        gap: 2px !important; /* Minimal gap for extreme fit */
    }

    /* CRUCIAL FONT ADJUSTMENTS: Increased font size by 2px on mobile */
    .fzkai-text-responsive,
    .en-text-responsive {
        font-size: 0.65rem !important;
        word-break: break-all;
        overflow-wrap: break-word;
        min-width: 0;
    }

    /* Adjust Chinese character size in the QMDJ grid (NOT the Info Panel) */
    .cn_word:not(.info .cn_word) {
        font-size: 1rem !important; /* approx 16px */
    }

    .bazi-container .bazi,
    .bazi-container .info {
        font-size: var(--small-font-size);
    }
}

/* ---------------------------------------------------- */
/* SECTION 6.5: DESKTOP FONT ENHANCEMENT (New Addition)   */
/* ---------------------------------------------------- */

@media (min-width: 769px) {
    /* Rule to increase the font size of the responsive FZKAI text specifically within the Qimen Grid */
    .table-container .fzkai-text-responsive {
        font-size: 1.8rem !important; /* Set larger desktop font size (e.g., 28.8px) */
        line-height: 1.2;
    }
}

/* ---------------------------------------------------- */
/* SECTION 7: Component-Like Table Styles (Global Fallback) */
/* ---------------------------------------------------- */
/* These rules apply general styling for the Bazi and Info tables globally */

/* BaZi Table */
.bazi table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.bazi th, .bazi td {
    border: 1px solid var(--border-color);
    text-align: center;
    vertical-align: middle;
    padding: 6px 4px;
    word-break: break-word;
    font-size: var(--base-font-size);
}

.bazi thead th {
    background: var(--bg-muted);
    font-weight: 600;
}

.bazi table .cn_word {
    font-family: var(--cn-font-family);
    font-size: var(--cn-font-size);
    font-weight: 700;
    line-height: 1.1;
    display: inline-block;
    opacity: 1;
    text-decoration: none;
}

.bazi table td > span:nth-child(2) {
    font-size: 1rem;
    opacity: 0.9;
}

/* Info Panel Table */
.info table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.info td {
    /* Desktop/Tablet Padding (overridden in Section 6 for mobile) */
    border-bottom: 1px dashed var(--border-color);
    padding: 8px 10px;
}

.info tr:last-child td {
    border-bottom: none;
}

.info .key {
    width: 30%;
    white-space: nowrap;
    font-weight: 700;
}

.info .val {
    width: 70%;
    font-size: var(--small-font-size);
}

.info .cn_word {
    font-size: var(--base-font-size);
    font-weight: 600;
}

.en-text-responsive {
    font-size: var(--small-font-size);
}

.mobile-break-placeholder {
    display: none;
}

/* ---------------------------------------------------- */
/* SECTION 8: QIMEN DUN JIA GRID LAYOUT (3x3)             */
/* ---------------------------------------------------- */

/* 1. Centering Wrapper for the entire 3x3 grid */
.table-container {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 20px auto;
    background-color: var(--bg-muted);
}

/* 2. Main 3x3 Grid (The 9 Palaces) */
.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    /*border: 3px solid #333;*/
}

/* 3. Individual Palace Cell (The Inner Grid) */
.inner-grid {
    display: grid;
    /* UPDATED: Custom column widths for 15% | 15% | 40% | 15% | 15% */
    grid-template-columns: 13% 19% 40% 14% 14%;
    /* Uses min-height for flexibility on desktop/tablet */
    min-height: 180px;
    border: 1px solid #999;
    padding: 0;
    box-sizing: border-box;
    text-align: center;
    align-content: space-evenly;
    min-width: 0;
}

/* 4. Individual Content Cell inside the Palace */
.inner-cell {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0;
    font-size: var(--small-font-size);
    white-space: nowrap; /* CRITICAL for desktop 5-column fit */
    overflow: hidden;
    text-overflow: ellipsis;
    /*line-height: 1;*/
}

/* Your custom nested classes for the inner cell structure (unchanged) */
.inner-cell-main-block {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    text-align: center;
}

.inner-cell-row-item {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 100%;
    /*line-height: 1;*/
    flex-wrap: nowrap;
}

/* Image inside the inner-cell (e.g., Trigram image) */
.inner-cell img {
    width: 80%;
    height: auto;
}



/* FaQiMen Intermediate Scroll */
/* Container must allow horizontal scrolling and prevent wrapping */
.scroll-nav-container_faqimenInt {
    display: flex;
    overflow-x: auto; /* Enables the actual horizontal scrollbar */
    padding: 10px 0;
    border-bottom: 1px solid #ccc;
    -ms-overflow-style: none; /* Hide scrollbar for IE and Edge */
    scrollbar-width: none; /* Hide scrollbar for Firefox */
}
    /* Hide scrollbar for Chrome, Safari and Opera */
    .scroll-nav-container_faqimenInt::-webkit-scrollbar {
        display: none;
    }

.nav-button_faqimenInt {
    flex-shrink: 0; /* Important: prevents buttons from shrinking */
    background: none;
    border: none;
    padding: 8px 15px;
    cursor: pointer;
    font-size: 16px;
    transition: color 0.2s, border-bottom 0.2s;
    margin-right: 10px;
    border-bottom: 2px solid transparent; /* Placeholder for active state */
}

    .nav-button_faqimenInt:hover {
        color: #007bff;
    }

    .nav-button_faqimenInt.active {
        font-weight: bold;
        color: #007bff;
        border-bottom: 2px solid #007bff; /* Highlight active item */
    }
