body {
    font-family: Arial, sans-serif;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.main-content-wrapper {
    display: flex;
    gap: 30px;
    align-items: flex-start;
    margin-top: 30px;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    width: 600px;
    height: 600px;
    position: relative;
    /* margin: 0 auto; Removed auto margin to align left in flex */
}

.analysis-panel {
    flex: 1;
    min-width: 300px;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    background-color: #f9f9f9;
}

.analysis-item {
    margin-bottom: 15px;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.analysis-item h4 {
    margin: 0 0 5px 0;
}

.palace {
    border: 1px solid #ccc;
    padding: 10px;
    position: relative;
    text-align: center;
}

/* 宮位位置定義 - Standard Layout */
.palace.巳 {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
}

.palace.午 {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
}

.palace.未 {
    grid-column: 3 / 4;
    grid-row: 1 / 2;
}

.palace.申 {
    grid-column: 4 / 5;
    grid-row: 1 / 2;
}

.palace.辰 {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
}

.palace.酉 {
    grid-column: 4 / 5;
    grid-row: 2 / 3;
}

.palace.卯 {
    grid-column: 1 / 2;
    grid-row: 3 / 4;
}

.palace.戌 {
    grid-column: 4 / 5;
    grid-row: 3 / 4;
}

.palace.寅 {
    grid-column: 1 / 2;
    grid-row: 4 / 5;
}

.palace.丑 {
    grid-column: 2 / 3;
    grid-row: 4 / 5;
}

.palace.子 {
    grid-column: 3 / 4;
    grid-row: 4 / 5;
}

.palace.亥 {
    grid-column: 4 / 5;
    grid-row: 4 / 5;
}

.celestial {
    color: #c00;
    font-weight: bold;
}


.star {
    font-size: 0.9em;
    margin: 2px 0;
    color: #333;
    font-weight: 500;
    cursor: pointer;
    /* Add pointer to indicate clickable */
    transition: color 0.2s, background-color 0.2s;
    padding: 2px 4px;
    /* Add padding for better hit area */
    border-radius: 4px;
}

.star:hover {
    color: #fff;
    background-color: #7b1fa2;
    /* Highlight color on hover */
}

/* Analysis Panel Styling */
.analysis-panel {
    flex: 1;
    min-width: 300px;
    padding: 15px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    max-height: 800px;
    overflow-y: auto;
}

.analysis-panel h3 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 1.1em;
}

.trans {
    color: #090;
    font-size: 0.8em;
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0;
}

#four-trans {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 15px;
}

.trans-result {
    padding: 8px 12px;
    border-left: 3px solid #ddd;
    background: #fafafa;
    border-radius: 4px;
}

.zihua-highlight {
    background-color: #fcfcfc;
    border-left: 4px solid #607d8b;
    padding-left: 10px;
}


.zihua-tag {
    display: inline-block;
    background-color: #607d8b;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    margin-right: 5px;
}

/* Center Info Panel */
.center-info {
    grid-column: 2 / 4;
    grid-row: 2 / 4;
    background-color: rgba(255, 255, 255, 0.95);
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    overflow-y: auto;
    font-size: 0.9em;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.center-info h3 {
    margin-top: 0;
    margin-bottom: 15px;
    text-align: center;
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    color: #333;
}

.center-info .analysis-item {
    border-bottom: none;
    padding-bottom: 0;
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
        margin: 0;
    }

    /* Hide form and buttons */
    form,
    button,
    #copyStatus,
    #pdfStatus {
        display: none !important;
    }

    /* Remove height restrictions */
    .analysis-panel,
    #four-trans,
    #all-12-trans {
        max-height: none !important;
        overflow: visible !important;
        height: auto !important;
    }

    /* Adjust layout for print */
    .main-content-wrapper {
        display: block;
        page-break-inside: avoid;
    }

    .right-panel {
        width: 100%;
        page-break-before: always;
    }

    /* Avoid breaking inside palace sections */
    .palace-section {
        page-break-inside: avoid;
        margin-bottom: 15px;
    }

    /* Chart styling */
    .chart-grid {
        page-break-inside: avoid;
        page-break-after: always;
    }

    /* Headers */
    h1,
    h2,
    h3 {
        page-break-after: avoid;
    }

    /* Ensure all content is visible */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* Arrow Container for Four Transformations */
.arrow-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.arrow-container svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Arrow colors for each transformation type */
.arrow-lu {
    stroke: #d32f2f;
    fill: none;
    stroke-width: 2;
    marker-end: url(#arrowhead-lu);
}

.arrow-quan {
    stroke: #388e3c;
    fill: none;
    stroke-width: 2;
    marker-end: url(#arrowhead-quan);
}

.arrow-ke {
    stroke: #1976d2;
    fill: none;
    stroke-width: 2;
    marker-end: url(#arrowhead-ke);
}

.arrow-ji {
    stroke: #7b1fa2;
    fill: none;
    stroke-width: 2;
    marker-end: url(#arrowhead-ji);
}

/* Palace Filter Styles */
#palace-filter-section label:hover {
    background-color: #f5f5f5;
}

#palace-filter-section input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #1976d2;
}

#palace-filter-section button {
    background-color: #1976d2;
    color: white;
    border: none;
    border-radius: 4px;
    transition: background-color 0.2s;
}

#palace-filter-section button:hover {
    background-color: #1565c0;
}

#selectAllPalaces {
    background-color: #388e3c;
}

#selectAllPalaces:hover {
    background-color: #2e7d32;
}

#deselectAllPalaces {
    background-color: #d32f2f;
}

#deselectAllPalaces:hover {
    background-color: #c62828;
}

/* --- New UI Elements --- */

#oppositeTransBtn {
    background-color: #546e7a;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

#oppositeTransBtn:hover {
    background-color: #37474f;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.birth-trans {
    display: inline-block;
    padding: 0px 4px;
    border-radius: 4px;
    background: #fff3e0;
    color: #e65100;
    font-weight: bold;
    border: 1px solid #ffe0b2;
    margin-right: 3px;
    font-size: 0.9em;
}

.zihua-label {
    position: relative;
    z-index: 20; /* Ensure it's above arrows for clicking */
}

/* Gold Table Style for Birth Tone */
.birth-tone-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background: linear-gradient(135deg, #fff7e6 0%, #fff 100%);
    border: 2px solid #ffd700;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.15);
    animation: goldGlow 3s infinite alternate;
}

@keyframes goldGlow {
    from {
        box-shadow: 0 4px 15px rgba(212, 175, 55, 0.15), inset 0 0 10px rgba(255, 215, 0, 0.05);
        border-color: #ffd700;
    }
    to {
        box-shadow: 0 4px 20px rgba(212, 175, 55, 0.4), inset 0 0 20px rgba(255, 215, 0, 0.1);
        border-color: #ff9800;
    }
}

.birth-tone-table th {
    background: #ffd700;
    color: #8b4513;
    padding: 8px;
    font-size: 0.9em;
}

.birth-tone-table td {
    padding: 10px;
    border-top: 1px solid #ffe58f;
    font-size: 0.95em;
    color: #333;
}