:root {
    --primary-color: #5e35b1;
    --secondary-color: #3949ab;
    --accent-color: #f57c00;
    --light-bg: #f5f5f5;
    --dark-text: #333;
    --border-color: #e0e0e0;
    --base-font-size: 16px;
    --qimen-palace-font-base: 1em;
}

html {
    font-size: var(--base-font-size);
}

input[type="date"], input[type="time"] {
    -webkit-appearance: none; 
    font-family: inherit;
}

input[type="date"]::-webkit-inner-spin-button,
input[type="time"]::-webkit-inner-spin-button,
input[type="date"]::-webkit-clear-button,
input[type="time"]::-webkit-clear-button {
    -webkit-appearance: none; 
    display: none;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-picker-indicator {
    opacity: 1;
    -webkit-appearance: none; 
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
    background: linear-gradient(135deg, #1a237e, #4a148c);
    color: var(--dark-text);
    min-height: 100vh;
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    max-width: 1000px;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.98);
    border-radius: 15px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

header {
    background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.header-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
    flex-shrink: 0;
}

.header-content {
    flex-grow: 1;
    text-align: center;
}

h1 { font-size: 1.8rem; font-weight: 600; margin-bottom: 4px; line-height: 1.2; }
.subtitle { font-size: 0.95rem; opacity: 0.9; }

.copyright-footer {
    text-align: center;
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    font-size: 0.85rem;
    color: #666;
    font-weight: 500;
}

.copyright-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: bold;
    transition: color 0.2s;
}

.copyright-footer a:hover {
    color: var(--accent-color);
    text-decoration: underline;
}

.content { padding: 15px; }

.card {
    background: white;
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-color);
}

.card-title {
    color: var(--primary-color);
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
    font-size: 1.2rem;
    font-weight: 600;
}

#chart-time-display {
    display: inline-block;
    margin-left: 15px;
    font-size: 0.85em;
    font-weight: normal;
    color: #555;
    background-color: #f5f5f5;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid #f0f0f0;
}

.card-header-flex .card-title { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.form-buttons {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 15px;
}

.chart-nav-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    margin-top: 15px; 
    width: 100%;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.chart-nav-buttons button {
    padding: 8px 5px;
    font-size: 0.9rem;
    border-radius: 4px;
}

label { display: block; margin-bottom: 5px; font-weight: 500; color: #555; font-size: 0.85rem; }

input, select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s;
}

input:focus, select:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(94, 53, 177, 0.2);
}

button {
    background: linear-gradient(to right, var(--accent-color), #ff9800);
    color: white;
    border: none;
    padding: 12px 10px;
    border-radius: 9px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 3px 8px rgba(245, 124, 0, 0.3);
    width: 100%;
}

button.secondary { background: #6c757d; font-size: 0.9em;}
button:hover { transform: translateY(-2px); box-shadow: 0 5px 12px rgba(0,0,0,0.2); }
#results { margin-top: 25px; }
.results-grid { display: grid; grid-template-columns: 1fr; gap: 25px; }
.bazi-table { width: 100%; border-collapse: collapse; text-align: center; }
.bazi-table th, .bazi-table td { border: 1px solid #f0f3f5; padding: 8px 4px; vertical-align: middle; }
.bazi-table th { background-color: #ecf0f1; font-weight: bold; font-size: 0.8em; }
.stem-char-large { font-size: 1.4em; font-weight: 700; line-height: 1.1; color: black; }

.analysis-options { margin-top: 0; margin-bottom: 0; text-align: right; font-size: 0.9rem; }
.analysis-options label { display: inline-flex; align-items: center; margin: 0 0 0 10px; cursor: pointer; font-weight: normal; gap: 4px;}

.chart-wrapper { 
    position: relative; 
    padding: 0; 
    margin: 15px auto; 
    max-width: 500px; 
    width: 100%; 
    display: flex;
    justify-content: center;
    align-items: center;
}

.qimen-chart-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: 1px;
    background-color: #999;
    border: 1px solid #999;
    padding: 1px;
    width: 100%;
    aspect-ratio: 1 / 1;
}

.palace {
    background-color: #fff;
    display: flex;
    padding: 0;
    font-weight: bold;
    position: relative;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
}

.palace-content-grid {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    width: 100%;
    height: 100%;
    align-items: center;
    text-align: center;
    font-size: var(--qimen-palace-font-base);
    line-height: 1;
    gap: 0;
}

.palace-content-grid > div { 
    line-height: 1;
    white-space: nowrap;
    font-size: clamp(0.55em, 2.8vw, 0.9em);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.grid-item-deity, .grid-item-star, .grid-item-door, 
.grid-item-heaven, .grid-item-earth, 
.grid-item-center-stem-top, .grid-item-center-stem-bottom {
    padding: 0 !important;
    margin: 0 !important;
}

.grid-item-deity, .grid-item-star, .grid-item-door { 
     font-size: clamp(0.65em, 3.5vw, 1.1em);
     font-weight: bold;
}
.grid-item-heaven, .grid-item-earth, .grid-item-center-stem-top, .grid-item-center-stem-bottom {
    font-size: clamp(0.65em, 3.5vw, 1.1em);
    font-weight: bold;
}

.grid-item-deity { grid-column: 2; grid-row: 1; }
.grid-item-star { grid-column: 2; grid-row: 2; }
.grid-item-door { grid-column: 2; grid-row: 3; }

.grid-item-heaven { grid-column: 3; grid-row: 2; justify-content: flex-end; padding-right: 1px !important;}
.grid-item-earth { grid-column: 3; grid-row: 3; justify-content: flex-end; padding-right: 1px !important;}
.grid-item-center-stem-top { grid-column: 1; grid-row: 2; justify-content: flex-start; padding-left: 1px !important;}
.grid-item-center-stem-bottom { grid-column: 1; grid-row: 3; justify-content: flex-start; padding-left: 1px !important;}

.p-special-left, .p-special-right {
    font-size: clamp(0.45em, 2.2vw, 0.7em);
    color: #c62828;
    letter-spacing: -0.5px;
    line-height: 1;
}
.p-special-left { grid-column: 1; grid-row: 1; justify-content: flex-start; padding-left: 1px !important;}
.p-special-right { grid-column: 3; grid-row: 1; justify-content: flex-end; padding-right: 1px !important;}

.underline { text-decoration: underline; text-decoration-thickness: 1px; }

.palace[data-palace="4"] { grid-area: 1 / 1; } .palace[data-palace="9"] { grid-area: 1 / 2; } .palace[data-palace="2"] { grid-area: 1 / 3; }
.palace[data-palace="3"] { grid-area: 2 / 1; } 
.palace[data-palace="5"] { 
    grid-area: 2 / 2; display: flex; align-items: center; justify-content: center; flex-direction: column; font-size: 1.1em; text-align: center; line-height: 1;
    position: relative;
}
.palace[data-palace="5"] img.logo {
    max-width: 80%;
    max-height: 80%;
    object-fit: contain;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.7;
}

.palace[data-palace="7"] { grid-area: 2 / 3; } .palace[data-palace="8"] { grid-area: 3 / 1; } .palace[data-palace="1"] { grid-area: 3 / 2; }
.palace[data-palace="6"] { grid-area: 3 / 3; }

.info-box { background: #f0f7ff; border-left: 5px solid var(--primary-color); padding: 15px; border-radius: 8px; font-size: 0.95em; line-height: 1.6; }

.fab-container { position: fixed; bottom: 25px; right: 25px; z-index: 1000; }
.fab { width: 56px; height: 56px; background-color: var(--primary-color); color: white; border-radius: 50%; border: none; box-shadow: 0 4px 12px rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: center; font-size: 24px; cursor: pointer; transition: transform 0.3s; }
.fab:hover { transform: scale(1.1); }
.fab-options { position: absolute; bottom: 65px; right: 0; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; visibility: hidden; opacity: 0; transition: visibility 0s 0.2s, opacity 0.2s; }
.fab-container.open .fab-options { visibility: visible; opacity: 1; transition: opacity 0.2s; }
.fab-option { background: var(--secondary-color); color: white; border: none; border-radius: 8px; padding: 8px 12px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.2); font-size: 1rem; min-width: 48px; text-align: center; display: flex; align-items: center; gap: 5px; justify-content: center;}
.fab-option:hover { background: var(--accent-color); }

@media (min-width: 768px) {
    .results-grid { 
        grid-template-columns: 35fr 65fr;
    }
    .chart-wrapper { max-width: none; }
    .palace-content-grid { font-size: var(--qimen-palace-font-base); }
    .palace-content-grid > div { font-size: clamp(0.8em, 1vw, 1em); }
    .p-special-left, .p-special-right { font-size: clamp(0.7em, 1vw, 0.9em); }
    .grid-item-deity, .grid-item-star, .grid-item-door, 
    .grid-item-heaven, .grid-item-earth, .grid-item-center-stem-top, .grid-item-center-stem-bottom {
        font-size: clamp(0.9em, 1.5vw, 1.2em);
    }
}