
    :root {
        --primary-color: #0073aa;
        --primary-dark-color: #005a87;
        --light-gray-color: #f0f0f1;
        --border-color: #ddd;
        --text-color: #333;
        --auspicious-color: #d9534f; /* Màu Cát (Đỏ) */
        --inauspicious-color: #6c757d; /* Màu Hung (Xám) */
        --cach-cuc-color: #0d5aa1; /* Màu mới cho Cách Cục */
        --background-color: #f4f6f8;
        --content-background: #ffffff;
        --status-kv-color: #8884d8; /* Màu cho icon Không Vong */
        --status-dm-color: #a0522d; /* Màu cho icon Dịch Mã */
    }

    /* --- CÀI ĐẶT CHUNG & FONT --- */
    html { font-size: 16px; }
    body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        background-color: var(--background-color);
        margin: 0;
        padding: 0.5rem;
        color: var(--text-color);
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
    .kymon-app-container {
        background: var(--content-background);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 1rem;
        width: 100%;
        max-width: 900px;
        margin: 0 auto;
        box-sizing: border-box;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    }


    /* --- CSS CHO HEADER --- */
.app-header {
    display: flex; /* Bật Flexbox */
    align-items: center; /* Căn giữa theo chiều dọc */
    justify-content: center; /* Căn giữa theo chiều ngang */
    gap: 1rem; /* Khoảng cách giữa logo và chữ */
    /* Xóa text-align: center; nếu có */
}

.header-logo {
    width: 50px; /* Kích thước logo */
    height: 50px;
}

.app-header h1 {
    margin: 0; /* Đảm bảo không có margin thừa */
}

/* --- CSS CHO FOOTER --- */


.app-footer h3 {
    margin: 0; /* Xóa margin cũ của h3 để flexbox kiểm soát */
}

/* CSS CHO RESPONSIVE (ĐIỆN THOẠI) */
@media (max-width: 767px) {
    .header-logo {
        width: 40px;
        height: 40px; 
    }
}

    /* --- APP HEADER --- */
    .app-header {
        text-align: center;
        padding: 0.5rem 0 1.5rem 0;
        border-bottom: 1px solid #eee;
        margin: 0 -1rem 1rem -1rem;
    }
    .app-header h1 {
        margin: 0;
        font-family: 'Times New Roman', Times, serif;
        font-size: clamp(1.8rem, 5vw, 2.5rem);
        font-weight: 600;
        color: var(--primary-dark-color);
        letter-spacing: 1px;
        text-shadow: 1px 1px 3px rgba(0,0,0,0.1);
    }

    /* --- NAVIGATION TABS --- */
    .app-nav {
        display: flex;
        gap: 0.5rem;
        margin-bottom: 1.5rem;
    }
    .nav-btn {
        padding: 0.6rem 1.2rem;
        border: 1px solid var(--border-color);
        background-color: var(--light-gray-color);
        border-radius: 8px;
        cursor: pointer;
        font-weight: bold;
        color: var(--primary-dark-color);
        transition: all 0.2s ease;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.6rem;
    }
    .nav-btn.active {
        background-color: var(--primary-color);
        color: white;
        border-color: var(--primary-dark-color);
        box-shadow: 0 2px 4px rgba(0, 90, 135, 0.2);
    }

    .app-view { display: none; }
    .app-view.active { display: block; }

    /* --- FORM ĐIỀU KHIỂN GỌN --- */
    .kymon-form-compact {
        margin-bottom: 0.5rem;
        display: flex;
        flex-wrap: wrap;
        gap: 0.75rem;
        align-items: flex-end;
    }
    .kymon-form-group {
        display: flex;
        flex-direction: column;
        gap: 0.3rem;
        flex: 1 1 150px;
    }
    .kymon-form-group label {
        font-size: 0.8rem;
        font-weight: bold;
        white-space: nowrap;
    }
    .kymon-form-group input, .kymon-form-group select {
        padding: 0.5rem;
        border: 1px solid #ccc;
        border-radius: 4px;
        font-size: 0.9rem;
        width: 100%;
        box-sizing: border-box;
    }
    .kymon-time-controls { display: flex; }
    .kymon-time-nav-btn {
        padding: 0.5rem 0.75rem;
        border: 1px solid #ccc;
        background-color: var(--light-gray-color);
        cursor: pointer;
    }
    #kymon-hour-select { border-radius: 0; }
    .kymon-time-nav-btn:first-child { border-radius: 4px 0 0 4px; }
    .kymon-time-nav-btn:last-child { border-radius: 0 4px 4px 0; }
    .kymon-action-buttons { display: flex; gap: 0.5rem; flex-shrink: 0; }
    .kymon-secondary-button, .kymon-submit-button {
        padding: 0.5rem 1rem;
        border-radius: 4px;
        cursor: pointer;
        font-weight: bold;
        font-size: 0.9rem;
        transition: background-color 0.2s;
        border: 1px solid transparent;
    }
    .kymon-secondary-button { background-color: var(--light-gray-color); border-color: #ccc; }
    .kymon-submit-button { background-color: var(--primary-color); color: white; }
    .tiet-khi-info {
        font-size: 0.8rem;
        font-weight: bold;
        color: var(--primary-dark-color);
        padding: 0.5rem 0;
        margin-bottom: 1rem;
        border-bottom: 1px solid #eee;
    }

    /* --- THANH THÔNG TIN & BẢNG TỨ TRỤ --- */
    .chart-header h1 {
        font-size: clamp(1.2rem, 4vw, 1.5rem);
        text-align: center;
        margin: 0 0 1rem 0;
    }
    .chart-info-bar {
        padding: 0.75rem;
        border-radius: 6px;
        font-size: 0.8rem;
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem 1rem;
        justify-content: center; /* Căn giữa trên điện thoại */
        text-align: left;
        background: var(--light-gray-color);
        margin-bottom: 1rem;
    }
    .qimen-info {
        width: 100%;
        max-width: 500px;
        margin: 1.5rem auto 0 auto;
        border-collapse: collapse;
    }
    .qimen-info th, .qimen-info td {
        border: 1px solid #e5e5e5;
        text-align: center;
        padding: 0.5rem;
    }
    .qimen-info thead th {
        background-color: var(--primary-color);
        color: white;
        font-weight: bold;
    }
    .qimen-info .can-chi { font-size: 1.1rem; font-weight: bold; }
    .qimen-info .nap-am { font-size: 0.8rem; color: #666; }

    /* --- BỐ CỤC LƯỚI KỲ MÔN (RESPONSIVE) --- */
    .qimen-grid-wrapper {
        display: grid;
        /* Thay đổi để linh hoạt hơn trên mobile */
        grid-template-columns: minmax(20px, 30px) 1fr minmax(20px, 30px);
        grid-template-rows: auto 1fr auto;
        align-items: center;
        justify-items: center;
        gap: 2px; /* Giảm gap */
        margin: 0 auto;
        max-width: 900px;
    }
    .qimen-grid {
        grid-column: 2 / 3;
        grid-row: 2 / 3;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        border: 2px solid #555;
        width: 100%;
        aspect-ratio: 1 / 1;
    }
    .direction {
        font-weight: bold;
        /* Clamp font size nhỏ hơn trên mobile */
        font-size: clamp(0.7rem, 2.5vw, 1rem);
        text-align: center;
        color: var(--primary-dark-color);
    }
    .qimen-grid-wrapper > .direction:nth-child(1) { grid-area: 1/1; }
    .qimen-grid-wrapper > .direction:nth-child(2) { grid-area: 1/2; }
    .qimen-grid-wrapper > .direction:nth-child(3) { grid-area: 1/3; }
    .qimen-grid-wrapper > .direction:nth-child(4) { grid-area: 2/1; align-self: center; }
    .qimen-grid-wrapper > .direction:nth-child(6) { grid-area: 2/3; align-self: center; }
    .qimen-grid-wrapper > .direction:nth-child(7) { grid-area: 3/1; }
    .qimen-grid-wrapper > .direction:nth-child(8) { grid-area: 3/2; }
    .qimen-grid-wrapper > .direction:nth-child(9) { grid-area: 3/3; }

    /* --- ĐỊNH DẠNG CUNG (PALACE) --- */
    .palace {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: 1fr 1fr 1fr;
        border: 1px solid #ccc;
        font-weight: bold;
        cursor: pointer;
        position: relative;
        background-color: var(--content-background);
        transition: transform 0.2s ease-out, box-shadow 0.2s ease-out; /* Thêm hiệu ứng chuyển động */
    }
    /* [GOAL 3] Thêm hiệu ứng khi tương tác với cung */
    .palace:not(.center-palace):hover {
        transform: scale(1.05);
        box-shadow: 0 4px 15px rgba(0,0,0,0.15);
        z-index: 10;
    }
    .palace-item {
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 1px; /* Giảm padding */
        box-sizing: border-box;
        width: 100%;
        font-size: clamp(0.7rem, 2.8vw, 1.2rem);
    }
    .center-palace { 
    background-color: #fdfde7; 
    position: relative; /* Cần thiết cho pseudo-element */
    }
    /* === BACKGROUND BẢN QUYỀN CHO Ô GIỮA === */
    .center-palace::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-image: url('logo.png'); /* <-- THAY ĐỔI ĐƯỜNG DẪN LOGO TẠI ĐÂY */
        background-repeat: no-repeat;
        background-position: center;
        background-size: 75%; /* Kích thước logo so với ô */
        opacity: 0.8; /* Độ mờ của logo */
        z-index: 0; /* Đưa logo xuống lớp nền */
    }

    .auspicious { color: var(--auspicious-color); }
    .inauspicious { color: var(--inauspicious-color); } /* Màu cho yếu tố Hung */
    .center-datetime-overlay {
        position: absolute; top: 50%; left: 50%;
        transform: translate(-50%, -50%);
        background-color: rgba(255, 255, 255, 0.8);
        padding: 0.25rem 0.5rem; border-radius: 4px;
        font-size: clamp(0.6rem, 2vw, 0.75rem);
        font-weight: bold; color: var(--primary-dark-color);
        z-index: 5; white-space: nowrap; pointer-events: none;
    }
    .palace-heaven-stem { grid-area: 1 / 1; }
    .palace-star { grid-area: 1 / 2; }
    .palace-phitinh-number { grid-area: 1 / 3; color: var(--primary-dark-color); }

    /* [GOAL 1] Chỉnh chữ Cách Cục nhỏ và gọn hơn */
    .palace-cach-cuc {
        grid-area: 2 / 1 / 3 / 3;
        font-size: 0.65em; /* Kích thước nhỏ hơn, linh hoạt theo kích thước cung */
        font-weight: normal; /* Chữ thường, không in đậm */
        color: var(--cach-cuc-color); /* Màu mới */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 1px 4px; /* Điều chỉnh padding */
        justify-content: flex-start; /* Căn trái */
        align-items: center;
    }

    /* [GOAL 3] Thêm biểu tượng cho Dịch Mã (DM) và Không Vong (KV) */
    .palace-status-icons-container {
        grid-area: 2 / 3;
        font-size: 0.9em; /* Kích thước icon */
        display: flex;
        gap: 3px;
        align-items: center;
        justify-content: center;
    }
    .kv-icon, .dm-icon {
        font-family: "Font Awesome 6 Free";
        font-weight: 900;
        font-size: 1em; /* Kích thước tương đối */
    }
    .kv-icon::before {
        content: "\f6e2"; /* Biểu tượng "ghost" */
        color: var(--status-kv-color);
    }
    .dm-icon::before {
        content: "\f6f0"; /* Biểu tượng "horse" */
        color: var(--status-dm-color);
    }
    /* Ẩn chữ DM, KV gốc nếu có */
    .kv-icon, .dm-icon {
        text-indent: -9999px;
        display: inline-block;
        line-height: 1;
    }

    .palace-earth-stem { grid-area: 3 / 1; }
    .palace-door { grid-area: 3 / 2; }
    .palace-deity { grid-area: 3 / 3; }

    /* --- FINDER VIEW STYLES --- */
    .finder-form {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 1rem;
    }
    .finder-form .kymon-form-group { flex-basis: auto; }
    .finder-form .full-width { grid-column: 1 / -1; }
    .finder-form .kymon-form-group label { white-space: normal; }
    .finder-form textarea { width: 100%; min-height: 60px; padding: 0.5rem; border-radius: 4px; border: 1px solid #ccc; font-size: 0.9rem; }
    .finder-form .checkbox-group { display: flex; align-items: center; gap: 0.5rem; }
    .finder-results { margin-top: 1.5rem; }
    .finder-progress { text-align: center; padding: 1rem; font-weight: bold; color: var(--primary-color); }
    .result-day { margin-bottom: 1.5rem; border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; }
    .result-day-header { background-color: var(--primary-dark-color); color: white; padding: 0.75rem; font-weight: bold; }

    /* === Styling for the custom multi-select checkbox dropdown === */
    .multi-select-checkbox { position: relative; width: 100%; }
    .multi-select-trigger {
        width: 100%; padding: 0.5rem; border: 1px solid #ccc; border-radius: 4px; background-color: white;
        font-size: 0.9rem; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .multi-select-panel {
        display: none; position: absolute; top: 100%; left: 0; width: 100%; max-height: 250px; overflow-y: auto;
        background: white; border: 1px solid #ccc; border-radius: 4px; margin-top: 2px; z-index: 100;
        box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    }
    .multi-select-panel.open { display: block; }
    .multi-select-actions {
        padding: 5px 10px; border-bottom: 1px solid #eee; display: flex; gap: 10px; position: sticky;
        top: 0; background-color: white;
    }
    .multi-select-actions button {
        background: none; border: none; color: var(--primary-color); cursor: pointer;
        font-size: 0.8rem; font-weight: bold; padding: 4px;
    }
    .multi-select-list { padding: 5px; }
    .multi-select-item { display: block; }
    .multi-select-item label {
        display: flex; align-items: center; gap: 0.5rem; font-weight: normal; font-size: 0.9rem;
        white-space: normal; cursor: pointer; padding: 5px 10px;
    }
    .multi-select-item label:hover { background-color: #f0f0f0; }
    .multi-select-item input { width: auto; }

    /* Other styles */
    .result-hour-list { list-style: none; padding: 0; margin: 0; }
    .result-hour-item {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem 1rem;
        padding: 0.75rem;
        border-bottom: 1px solid #eee;
        align-items: center;
    }
    .result-hour-item:last-child { border-bottom: none; }
    .hour-time { font-weight: bold; flex-shrink: 0; width: 160px; }
    .hour-details { font-size: 0.9rem; display: flex; flex-wrap: wrap; gap: 0.5rem; }
    .hour-details span { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 4px; background-color: var(--light-gray-color); }
    .hour-details .palace-name { background-color: var(--primary-color); color: white; font-weight: bold; }
    .hour-details .cach-cuc { background-color: #e0f2fe; color: #0ea5e9; }
    .kymon-loading, .kymon-error { text-align: center; padding: 40px; font-size: 1rem; }
    .kymon-error { color: #d63638; font-weight: bold; }
    .kymon-modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 1rem; box-sizing: border-box; }
    .kymon-modal-content { background: white; padding: 1.5rem; border-radius: 8px; width: 100%; max-width: 800px; max-height: 90vh; overflow-y: auto; position: relative; }
    .kymon-modal-close { position: absolute; top: 10px; right: 15px; background: none; border: none; font-size: 28px; cursor: pointer; color: #888; }
    .kymon-modal-header h2 { margin-top: 0; color: var(--primary-color); font-size: 1.2rem; }
    .info-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.9rem; }
    .info-table th, .info-table td { border: 1px solid #ddd; padding: 0.5rem; text-align: center; }
    .info-table th { background-color: #f5f5f5; }
    .giai-thich-section h3 { font-size: 1rem; border-bottom: 2px solid #eee; padding-bottom: 5px; margin: 1rem 0 0.5rem 0; }
    .giai-thich-section p { font-size: 0.9rem; line-height: 1.6; white-space: pre-wrap; }

    /* --- APP FOOTER --- */
    .app-footer {
        margin-top: 2rem; padding: 2.5rem 1.5rem 1.5rem 1.5rem; border-top: 1px solid var(--border-color);
        background-color: #fcfcfc; border-radius: 0 0 12px 12px; margin: 2rem -1rem -1rem -1rem;
    }
    .footer-content { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2rem; margin-bottom: 1.5rem; }
    .footer-column { flex: 1; min-width: 220px; }
    .app-footer h3 { font-family: 'Times New Roman', Times, serif; color: var(--primary-dark-color); font-size: 1.5rem; margin-top: 0; margin-bottom: 0.75rem; }
    .app-footer h4 { color: var(--primary-dark-color); font-size: 1rem; margin-top: 0; margin-bottom: 1rem; text-transform: uppercase; letter-spacing: 0.5px; }
    .app-footer p { font-size: 0.9rem; line-height: 1.6; margin: 0; color: #555; }
    .footer-links { list-style: none; padding: 0; margin: 0; }
    .footer-links li { margin-bottom: 0.6rem; }
    .app-footer a { color: var(--primary-color); text-decoration: none; transition: color 0.2s ease-in-out; }
    .app-footer a:hover { color: var(--primary-dark-color); text-decoration: underline; }
    .footer-social-icons { display: flex; gap: 1rem; align-items: center; }
    .footer-social-icons a {
        display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
        border-radius: 50%; background-color: var(--light-gray-color); color: var(--primary-dark-color);
        font-size: 1.1rem; transition: all 0.2s ease-in-out;
    }
    .footer-social-icons a:hover { background-color: var(--primary-color); color: white; transform: translateY(-2px); }
    .footer-bottom { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--border-color); text-align: center; font-size: 0.85rem; color: #777; }
    .footer-bottom p { font-size: inherit; color: inherit; }
    .footer-disclaimer { font-style: italic; margin-bottom: 0.5rem; }

    /* [GOAL 2] Tối ưu hiển thị trên điện thoại */
    @media (max-width: 767px) {
        .kymon-app-container {
            padding: 0.5rem;
            border: none;
            box-shadow: none;
        }
        .app-header, .app-footer {
            margin-left: -0.5rem;
            margin-right: -0.5rem;
        }
        .kymon-form-compact {
             gap: 0.5rem;
        }
        .kymon-action-buttons {
            flex-basis: 100%;
            justify-content: center;
        }
        .kymon-action-buttons button {
            flex-grow: 1;
        }
        .chart-info-bar {
            font-size: 0.75rem;
            padding: 0.5rem;
            gap: 0.25rem 0.75rem;
        }
        .qimen-info .can-chi { font-size: 1rem; }
        .qimen-info .nap-am { font-size: 0.75rem; }
        .qimen-info th, .qimen-info td { padding: 0.3rem; }

        .finder-form {
            grid-template-columns: 1fr 1fr;
        }
        .result-hour-item {
            flex-direction: column;
            align-items: flex-start;
        }
        .hour-time {
            width: 100%;
            margin-bottom: 0.5rem;
        }
    }
    @media (max-width: 480px) {
        .nav-btn {
            padding: 0.5rem 0.8rem;
            font-size: 0.8rem;
        }
        .qimen-info .can-chi { font-size: 0.9rem; }
        .qimen-info .nap-am { font-size: 0.7rem; }
    }
