body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #f0f2f5;
    color: #1d1d1d;
    display: flex;
    justify-content: center;
    padding: 1em;
    margin: 0;
    overflow-x: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 1300px;
    gap: 20px;
}

.form-section {
    width: 100%;
    max-width: 450px;
    flex-shrink: 0;
}

.output-section {
    display: flex;
    flex-direction: column; 
    align-items: center; 
    width: 100%;
}

.hidden {
    display: none;
}

#hidden {
    display: none;
}

#result-container {
    width: 100%;
    display: flex;
    justify-content: center;
}

#chart-wrapper {
    position: relative;
    width: 788px;
    height: 1008px; 
    transform: scale(0.47);
    transform-origin: top center;
    flex-shrink: 0;
}

#chart-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 195px); 
    grid-template-rows: repeat(4, 250px);   
    width: 780px; 
    height: 1000px;
    background-image: url("background.jpg"); 
    background-size: cover;
    background-position: center;
    padding: 5px;
} 

#arrow-svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

@media (min-width: 1220px) {
    .container {
        flex-direction: row;
        align-items: flex-start;
    }

    .form-section {
        flex: 0 0 450px;
    }

    .output-section {
        flex: 1 1 auto;
    }

    #chart-wrapper {
        transform: scale(1);
        height: 1000px;
    }

    .luan-giai-container { 
        width: 100%;
        max-width: 780px;
    }

    #chart-legend {
        flex-direction: row; 
        align-items: flex-start;
    }

    .legend-group {
        flex-wrap: wrap; 
        gap: 10px;
    }

}

.form-container {text-align: center; width: 100%; box-sizing: border-box; padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }
#tuvi-form { display: grid; grid-template-columns: auto 1fr; gap: 12px 10px; align-items: center; }
#tuvi-form label { text-align: left; font-weight: bold; }
select, input[type="text"], input[type="number"] { width: 100%; box-sizing: border-box; padding: 8px; border: 1px solid #ccc; border-radius: 4px;}
#form-logo { display: block; margin: 0 auto 15px auto; width: 150px; }
.calendar-toggle { display: flex; flex-wrap: nowrap; align-items: center; }
.calendar-toggle label { font-weight: normal; margin: 0 10px 0 2px; }
.date-select-group, .time-select-group { display: flex; gap: 5px; align-items: center; }
#select-ngay, #select-thang, #select-gio, #select-phut { flex: 1 1 50px; }
#select-nam { flex: 1 1 70px; }
#gio_chi_display { font-weight: bold; color: #0056b3; margin-left: 5px; }

#tuvi-form button { grid-column: 1 / -1; padding: 12px; font-size: 1em; color: white; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; transition: background-color 0.2s; }
#submit-btn { background-color: #007bff; margin-top: 10px; }
#submit-btn:hover { background-color: #0056b3; }
#download-btn { background-color: #28a745; margin-top: 8px; }
#download-btn:hover { background-color: #218838; }
#download-btn:disabled { background-color: #6c757d; cursor: not-allowed; opacity: 0.7; }
#luan-giai-btn { background-color: #ff8c00; margin-top: 8px; }
#luan-giai-btn:hover { background-color: #cc7000; }

.palace { background-color: transparent; border: 1px solid #1d1d1d; position:relative; display: flex; flex-direction: column; padding: 2px;  }
.palace-header { display: flex; justify-content: space-between; font-size: 0.9em; font-weight: bold; color: black; transform: translateY(50%); }
.palace-name { display: flex; flex-direction: column; justify-content: start; align-items: center; flex-grow: 1; text-align: center; min-height: 50px; }
.palace-chi-vertical { position: absolute; left: 5px; top: 100%; transform: translateY(-120%); writing-mode: horizontal-tb; text-orientation: upright; font-size: 0.9em; font-weight: normal; color: #000; }
.palace-content { display: flex; flex-direction: row; flex-grow: 1; margin-top: 8px; align-items: flex-start; gap: 3px; }
.palace-footer { display: inline-flex; justify-content: space-between; font-size: 0.8em; color: #333; padding-bottom: 6px;}
.cung-ty  { grid-area: 1 / 1; } .cung-ngo { grid-area: 1 / 2; }
.cung-mui { grid-area: 1 / 3; } .cung-than{ grid-area: 1 / 4; }
.cung-thin{ grid-area: 2 / 1; } .cung-dau { grid-area: 2 / 4; }
.cung-mao { grid-area: 3 / 1; } .cung-tuat{ grid-area: 3 / 4; }
.cung-dan { grid-area: 4 / 1; } .cung-suu { grid-area: 4 / 2; }
.cung-ty-bottom { grid-area: 4 / 3; } .cung-hoi { grid-area: 4 / 4; }
#center-info { font-size: 15px; grid-area: 2 / 2 / 4 / 4; display: flex; flex-direction: column; align-items: left; justify-content: top; padding: 20px; border: 1px solid #777; text-align: center; line-height: 14px; background-color: transparent; }
.center-header { width: 100%; text-align: center; margin-bottom: 20px; }
.center-header a { color: blue; font-weight: normal; text-decoration: none; font-size: 20px; line-height: 22px; }
#center-info h3 { margin: 10px; font-size: 1.0em; font-weight: bold; color: #c00; line-height: 10px; z-index: 1; }
#center-info-table, #center-summary-table { width: 100%; border-collapse: collapse; }
#center-info-table td{ padding: 3px; vertical-align: center; }
#center-summary-table .label { text-align: left; font-weight: bold; width: 35%; }
#center-summary-table td { padding: 3px; vertical-align: center; width: 55%; }
#center-info-table .label { text-align: left; font-weight: bold; width: 23%; }
#center-info-table .value { text-align: left; width: 28%; color: blue; }
#center-info-table .canchi { text-align: left; font-weight: bold; width: 18%; color: blue; }
#center-info-table .tuoi { text-align: left; width: 15%; transform: translateX(-65%); color: red; font-weight: bold; }
#center-summary-table .value-full { text-align: left; font-weight: normal; color: blue; }
.center-divider { width: 80%; border: 0; border-top: 1px solid #ccc; margin: 5px 0; }
.summary-info { margin-top: 5px; }
.summary-info p { margin: 2px 0; font-weight: bold; color: blue; line-height: 17px; }
.sao { display: inline-flex; line-height: 1.2; }
.do-sang { font-size: 0.6em; color: #333; font-weight: bold;}
.sao.sao-tu-vi { color: #DAA520; }
.sao.sao-thien-phu { color: #DAA520; }
.sao.sao-thien-co { color: #2ECC71; }
.sao.sao-thai-duong { color: #b90e0e; }
.sao.sao-vu-khuc { color: #a3a3a3; }
.sao.sao-thien-dong { color: #000000; }
.sao.sao-liem-trinh { color: #b90e0e; }
.sao.sao-thai-am { color: #000000; }
.sao.sao-tham-lang { color: #000000; }
.sao.sao-cu-mon { color: #000000; }
.sao.sao-thien-tuong { color: #000000; }
.sao.sao-thien-luong { color: #008000; }
.sao.sao-that-sat { color: #7F8C8D; }
.sao.sao-pha-quan { color: #030303; }
.sao.sao-loc-ton, .sao.sao-l-loc-ton { color: #DAA520; font-weight: 600;}
.tuan-triet-marker { position: absolute; background-color: black; color: white; font-weight: normal; text-align: center; font-size: 0.8em; padding: 2px 6px; border-radius: 2px; z-index: 15; transform: translate(-50%, -50%); }
.tuan-triet-marker text { text-align: center; }
.ten-cung{ text-align: center; font-size: 0.85em; font-weight: bold; color: rgb(0, 0, 0); text-transform: uppercase; }
.ngu-ho-don-text { font-size: 0.95em; font-weight: bold; left:100%; }
.vong-trang-sinh{ font-size: 1em; font-weight: bold; color: rgb(0, 0, 0); text-align: center; }
.dai-van-text { font-size: 0.8em; font-weight: bold; color: rgb(0, 0, 0); }
.chinh-tinh-container { display: relative; justify-content:top; text-align: top; width: 100%; font-size: 1.1em; font-weight: bold; line-height: 1.2em; }
.sao-columns-wrapper { display: flex; flex-grow: 1; justify-content: space-between; align-items: flex-start; padding: none; }
.sao-column { width: 50%; display: flex; flex-direction: column; }
.sao-column-left { align-items: flex-start; padding-left: 3px; }
.sao-column-right { align-items: flex-start; padding: none; justify-items: right; }
.sao-column-left .sao { display: flex; text-align: left; font-size: 0.8em; line-height: 1.2em; align-items: flex-start; }
.sao-column-right .sao { display: flex; text-align: right; font-size: 0.8em; line-height: 1.2em; align-items: flex-start; }
.luu-tinh-container { display: flex; flex-direction: column; align-items: flex-start; }
.sao-group { display: flex; flex-direction: column; }
.sao-group + .sao-group { margin-top: 3px; }
.hanh-kim { color: #858585; }
.hanh-moc { color: #008000; }
.hanh-thuy { color: #000000; }
.hanh-hoa { color: #FF0000; }
.hanh-tho { color: #c56b05; }
.sao-green { color: #008000; }
.sao-red { color: #D90429; }
.sao-gray { color: #858585; }
.sao-black { color: #000000; }
.sao-yellow { color: #c56b05; }
.sao-bold-1 { font-weight: 700; color: #008000 }
.sao-bold-2 { font-weight: 700; color: #D90429 }
.sao-bold-3 { font-weight: 600; color: #000000}
.luan-giai-container { display: flex; background-color: #fffbe8; border: 1px solid #ddd; border-radius: 8px; }
#luan-giai-content { white-space: pre-wrap; line-height: 1.7; text-align: justify; }
.arrow-line { stroke: #686868; stroke-width: 1; marker-end: url(#arrowhead); z-index: 10; }
.arrow-line.xung-chieu { stroke-dasharray: 3, 3; stroke: #686868; }
.nguyet-han-marker { position: relative; bottom: 2px; right: 2px; background-color: rgba(228, 148, 1, 0.7); color: white; font-size: 10px; padding: 1px 3px; border-radius: 3px; font-weight: normal; font-size: 1.1em; }
.tieu-van-chi{ font-size: 1.2em; }
/* --- CSS cho phần chú giải lá số --- */

#chart-legend.hidden, #result-container.hidden, #luan-giai-container.hidden {
    display: none;
}

/* Quy tắc cũ cho #chart-legend vẫn giữ nguyên để định dạng khi nó hiển thị */
#chart-legend {
    display: flex;
    flex-wrap: wrap; 
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 2px 15px;
    background-color: #f0ebe5;
    border: 1.5px solid #1d1d1d;
    border-top: 0.5px;
    max-width: 780px;
    box-sizing: border-box;
    margin: 0 auto;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.legend-group {
    display: flex;
    gap: 15px; 
    align-items: center;
}

.legend-group span {
    display: inline-flex; 
    align-items: center;
}
.text-red {
    color: #FF0000;
}
.text-black {
    color: #000000;
}

.color-box {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 5px;
    border: 1px solid #777;
}

.kim { background-color: #808080; }
.moc { background-color: #008000; }
.thuy { background-color: #000000; }
.hoa { background-color: #FF0000; }
.tho { background-color: #DAA520; }

/* --- CSS CHO MÀU SẮC CỦA TỪNG SAO LƯU --- */

/* Bạn có thể tùy chỉnh màu sắc bằng cách thay đổi mã màu (ví dụ: #FF0000 là màu đỏ) */

/* Nhóm sao Lưu Thái Tuế */
.sao.luu-tinh {
    font-size: 12px;
}
.sao.luu-tinh.sao-l-thai-tue {
    color: #D90429; /* Đỏ đậm */
    font-weight: bold;
}
.sao.luu-tinh.sao-l-tang-mon,
.sao.luu-tinh.sao-l-bach-ho {
    color: #585858; /* Xám đậm */
}

/* Nhóm sao Lưu Lộc Tồn */
.sao.luu-tinh.sao-l-loc-ton {
    color: #c56b05; /* Vàng cam */
    font-weight: bold;
}
.sao.luu-tinh.sao-l-kinh-duong,
.sao.luu-tinh.sao-l-da-la {
    color: #858585; /* Xám */
    font-weight: bold;
}

/* Nhóm Lưu Thiên Mã, Đào Hoa, Hồng Loan */
.sao.luu-tinh.sao-l-thien-ma {
    color: #D90429; /* Xanh dương */
}
.sao.luu-tinh.sao-l-dao-hoa,
.sao.luu-tinh.sao-l-hong-loan {
    color: #e83e8c; /* Hồng */
}

/* Nhóm Lưu Văn Xương, Văn Khúc */
.sao.luu-tinh.sao-l-van-xuong,
.sao.luu-tinh.sao-l-van-khuc {
    color: #17a2b8; /* Xanh ngọc */
}

/* Nhóm Lưu Tứ Hóa */
.sao.luu-tinh.sao-l-hoa-loc {
    color: #28a745; /* Xanh lá cây */
    font-weight: bold;
}
.sao.luu-tinh.sao-l-hoa-quyen {
    color: #006400; /* Xanh lá đậm */
    font-weight: bold;
}
.sao.luu-tinh.sao-l-hoa-khoa {
    color: #414141; /* Tím */
    font-weight: bold;
}
.sao.luu-tinh.sao-l-hoa-ky {
    color: #131414; /* Đen nhạt */
    font-weight: bold;
}

/* Các sao Lưu khác */
.sao.luu-tinh.sao-l-thien-khoc,
.sao.luu-tinh.sao-l-thien-hu {
    color: #6c757d; /* Xám nhạt */
}