:root {
    /* Classical Cool Palette */
    --bg-color: #0d1b2a;
    --text-color: #e0e1dd;
    --primary-color: #ffd700;
    /* Gold */
    --secondary-color: #1b263b;
    /* Deep Blue */
    --accent-color: #778da9;
    /* Muted Blue-Grey */
    --border-color: #ffd700;
    --glass-bg: rgba(13, 27, 42, 0.7);
    --glass-border: 1px solid rgba(255, 215, 0, 0.3);
    --shadow-glow: 0 0 15px rgba(255, 215, 0, 0.2);
    --paper-texture: url('../assets/mystic_mountain_bg.png');
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Serif SC', 'Songti SC', serif;
    background-color: var(--bg-color);
    background-image: var(--paper-texture);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    min-height: 100vh;
    padding: 20px;
    color: var(--text-color);
    overflow-x: hidden;
}

.container {
    max-width: 1400px;
    margin: 40px auto;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    position: relative;
    padding: 20px;
    overflow: hidden;
}

/* Decorative Corners - Updated to use new Gold Frame */
.corner-decoration {
    position: absolute;
    width: 150px;
    height: 150px;
    background-image: url('../assets/gold_frame_border.png');
    background-size: contain;
    background-repeat: no-repeat;
    pointer-events: none;
    z-index: 0;
    opacity: 1;
    filter: drop-shadow(0 0 2px gold);
}

.corner-tl {
    top: 0;
    left: 0;
    transform: rotate(0deg);
}

.corner-tr {
    top: 0;
    right: 0;
    transform: rotate(90deg);
}

.corner-bl {
    bottom: 0;
    left: 0;
    transform: rotate(-90deg);
}

.corner-br {
    bottom: 0;
    right: 0;
    transform: rotate(180deg);
}

.container::before {
    content: '';
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    pointer-events: none;
    border-radius: 8px;
}

.header {
    text-align: center;
    padding: 60px 0 40px;
    border-bottom: none;
    margin-bottom: 30px;
    background: transparent;
    position: relative;
    z-index: 1;
}

.header::after {
    content: '';
    display: block;
    width: 60%;
    height: 40px;
    margin: 20px auto 0;
    background-image: url('../assets/gold_cloud_divider.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.8;
}

.header h1 {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 4.5em;
    background: linear-gradient(to bottom, #ffd700, #b8860b);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 15px;
    text-shadow: 0 0 20px rgba(184, 134, 11, 0.3);
    letter-spacing: 5px;
}

.header p {
    font-size: 1.4em;
    color: var(--text-color);
    letter-spacing: 4px;
    opacity: 0.8;
    font-weight: 300;
}

.main-content {
    padding: 20px 40px;
    position: relative;
    z-index: 1;
}

.input-section {
    background: rgba(255, 255, 255, 0.05);
    padding: 50px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    max-width: 900px;
    margin: 0 auto 50px;
    position: relative;
    border-radius: 8px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}

.input-section h2 {
    font-family: 'Ma Shan Zheng', cursive;
    color: var(--primary-color);
    margin-bottom: 40px;
    font-size: 2.2em;
    text-align: center;
    border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    padding-bottom: 15px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.2);
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: normal;
    color: var(--primary-color);
    font-size: 1.1em;
    font-family: 'Noto Serif SC', serif;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 15px;
    border: none;
    border-bottom: 2px solid rgba(255, 215, 0, 0.3);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px 4px 0 0;
    font-family: 'Noto Serif SC', serif;
    font-size: 16px;
    color: #fff;
    transition: all 0.3s;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-bottom-color: var(--primary-color);
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 4px 6px -6px var(--primary-color);
}

/* Custom Select Arrow */
.form-group select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='gold'%3e%3cpath d='M7 10l5 5 5-5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
}

/* Date Input Dark Mode Fix */
.form-group input[type="datetime-local"] {
    color-scheme: dark;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 30px;
}

.btn-generate {
    background: linear-gradient(135deg, #b8860b, #ffd700, #b8860b);
    background-size: 200% 200%;
    color: #0d1b2a;
    padding: 18px 40px;
    border: 1px solid #ffd700;
    border-radius: 50px;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.5s ease;
    width: 100%;
    margin-top: 30px;
    letter-spacing: 8px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(184, 134, 11, 0.4);
    animation: gradientMove 3s ease infinite;
}

@keyframes gradientMove {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

.btn-generate:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 0 40px rgba(255, 215, 0, 0.6);
    border-color: #fff;
}

.btn-generate:active {
    transform: translateY(-1px);
}

.result-section {
    display: none;
    margin-top: 50px;
    animation: fadeInUp 0.8s ease;
}

.result-section.show {
    display: block;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.result-content {
    background: rgba(13, 27, 42, 0.6);
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-radius: 12px;
    padding: 35px;
    max-height: 800px;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    color: #ccc;
}

/* Scrollbar Styling */
.result-content::-webkit-scrollbar {
    width: 8px;
}

.result-content::-webkit-scrollbar-track {
    background: #0d1b2a;
}

.result-content::-webkit-scrollbar-thumb {
    background: #b8860b;
    border-radius: 4px;
}

.basic-info {
    background: linear-gradient(135deg, rgba(27, 38, 59, 0.8), rgba(65, 90, 119, 0.8));
    padding: 25px;
    border-radius: 10px;
    margin-bottom: 25px;
    border-left: 4px solid #ffd700;
    position: relative;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.basic-info h3 {
    color: #ffd700;
    margin-bottom: 20px;
    font-size: 1.6em;
    font-weight: 600;
    font-family: 'Ma Shan Zheng', cursive;
    letter-spacing: 2px;
}

.basic-info p {
    margin: 10px 0;
    line-height: 1.7;
    color: #e0e1dd;
    font-size: 1.05em;
}

.basic-info strong {
    color: #ffd700;
    font-weight: 600;
}

.palace-info {
    margin-bottom: 30px;
    padding: 25px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    border: 1px solid rgba(255, 215, 0, 0.1);
    transition: all 0.3s ease;
}

.palace-info:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.1);
    background: rgba(255, 255, 255, 0.05);
}

.palace-title {
    font-size: 1.4em;
    font-weight: bold;
    color: #ffd700;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    font-family: 'Ma Shan Zheng', cursive;
}

.palace-content {
    line-height: 1.8;
    color: #ccc;
}

.palace-content p {
    margin: 8px 0;
    font-size: 1.05em;
}

.palace-content strong {
    color: #b8860b;
    font-weight: 600;
}

.copy-section {
    position: fixed;
    bottom: 2px;
    left: 2px;
    z-index: 9999;
    opacity: 0.1;
    transition: opacity 0.3s;
    margin: 0;
    padding: 0;
}

.copy-section:hover {
    opacity: 1;
}

.btn-copy {
    background: transparent;
    color: #ccc;
    padding: 0;
    border: none;
    cursor: pointer;
    font-size: 8px;
    font-weight: normal;
    transition: all 0.3s ease;
    margin: 0;
    box-shadow: none;
}

.btn-copy:hover {
    color: #999;
    text-decoration: underline;
}

.btn-ai-diagnosis {
    background: linear-gradient(45deg, var(--primary-color), #ff4d4d);
    color: white;
    padding: 15px 50px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-size: 28px;
    font-weight: bold;
    font-family: 'Ma Shan Zheng', cursive;
    transition: all 0.3s ease;
    box-shadow: 0 0 20px rgba(139, 0, 0, 0.4);
    animation: pulse-glow 2s infinite;
    display: block;
    margin: 30px auto;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    border: 2px solid gold;
}

.btn-ai-diagnosis:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 0 30px rgba(255, 0, 0, 0.6);
    filter: brightness(1.2);
}

@keyframes pulse-glow {
    0% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(139, 0, 0, 0.4);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 30px rgba(255, 69, 0, 0.8), 0 0 10px gold;
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 10px rgba(139, 0, 0, 0.4);
    }
}

.loading {
    text-align: center;
    padding: 50px;
    display: none;
}

.loading.show {
    display: block;
}

.spinner {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #667eea;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 25px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading p {
    font-size: 1.2em;
    color: #6c757d;
    margin-top: 15px;
}

.error-message {
    background: linear-gradient(135deg, #f8d7da, #ffe6e6);
    color: #721c24;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    border: 1px solid #f5c6cb;
    display: none;
    font-size: 1.1em;
    text-align: center;
}

.error-message.show {
    display: block;
}

.success-message {
    background: linear-gradient(135deg, #d4edda, #e8f5e8);
    color: #155724;
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    border: 1px solid #c3e6cb;
    display: none;
    font-size: 1.1em;
    text-align: center;
}

.success-message.show {
    display: block;
}

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* 特殊标记样式 */
.special-mark {
    color: #e74c3c;
    font-weight: bold;
}

.star-brightness {
    color: #8e44ad;
    font-weight: 600;
}

.mutagen {
    color: #d35400;
    font-weight: bold;
}

/* 测试信息显示区域 */
.test-info {
    background: #f8f9fa;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    max-height: 300px;
    overflow-y: auto;
}

.test-info h4 {
    color: #2c3e50;
    margin-bottom: 10px;
}

.test-button {
    background: #6c757d;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin: 5px;
    font-size: 14px;
}

/* Visual Chart Styles */
.ziwei-chart-container {
    margin-top: 50px;
    overflow-x: auto;
    padding: 20px;
}

.ziwei-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, minmax(200px, auto));
    gap: 15px;
    /* Increased gap for card look */
    background-color: transparent;
    border: none;
    margin: 0 auto;
    max-width: 1300px;
    font-family: 'Noto Serif SC', serif;
}

.palace-cell {
    background-color: rgba(13, 27, 42, 0.6);
    background-image: none;
    /* Removed paper texture for glass look */
    backdrop-filter: blur(5px);
    padding: 15px;
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 8px;
    /* Rounded corners */
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    color: #e0e1dd;
}

.palace-cell:hover {
    transform: translateY(-5px) scale(1.02);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5), 0 0 15px rgba(255, 215, 0, 0.1);
    border-color: rgba(255, 215, 0, 0.6);
    z-index: 10;
}

.center-cell {
    grid-column: 2 / 4;
    grid-row: 2 / 4;
    background: radial-gradient(circle, rgba(27, 38, 59, 0.9), rgba(13, 27, 42, 0.95));
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    /* Rounded center */
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.15);
}

.center-cell h2,
.center-cell h3,
.center-cell p {
    color: #ffd700;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.3);
}


/* Earthly Branch positions */
.cell-si {
    grid-area: 1 / 1 / 2 / 2;
}

/* 巳 */
.cell-wu {
    grid-area: 1 / 2 / 2 / 3;
}

/* 午 */
.cell-wei {
    grid-area: 1 / 3 / 2 / 4;
}

/* 未 */
.cell-shen {
    grid-area: 1 / 4 / 2 / 5;
}

/* 申 */

.cell-chen {
    grid-area: 2 / 1 / 3 / 2;
}

/* 辰 */
.cell-you {
    grid-area: 2 / 4 / 3 / 5;
}

/* 酉 */

.cell-mao {
    grid-area: 3 / 1 / 4 / 2;
}

/* 卯 */
.cell-xu {
    grid-area: 3 / 4 / 4 / 5;
}

/* 戌 */

.cell-yin {
    grid-area: 4 / 1 / 5 / 2;
}

/* 寅 */
.cell-chou {
    grid-area: 4 / 2 / 5 / 3;
}

/* 丑 */
.cell-zi {
    grid-area: 4 / 3 / 5 / 4;
}

/* 子 */
.cell-hai {
    grid-area: 4 / 4 / 5 / 5;
}

/* 亥 */

/* Palace Cell Layout Refactor */
.palace-cell {
    position: relative;
    background: rgba(255, 255, 255, 0.4);
    /* padding: 8px; Removed padding to allow full edge control, will use internal padding */
    padding: 5px;
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    /* Prevent spillover */
}

/* Top Section: Stars */
.stars-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1;
    /* Take up available space */
    overflow-y: auto;
    /* Scroll if absolutely too many stars, though rare */
    padding-right: 30px;
    /* Avoid overlap with top-right Stage badge */
}

.stars-major {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 2px;
    font-weight: bold;
    font-size: 1.1em;
    line-height: 1.2;
}

/* Battle Configuration Styles */
.battle-config {
    background: rgba(253, 251, 247, 0.95);
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 2px dashed var(--primary-color);
    animation: slideDown 0.3s ease;
}

.battle-title {
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 10px;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.1em;
}

.battle-checkboxes {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.immortal-option {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    background: white;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.immortal-option:hover {
    border-color: var(--primary-color);
    background: #fffdf5;
}

.immortal-option input:checked+.immortal-name {
    color: var(--primary-color);
    font-weight: bold;
}

/* 神级强者 special styling */
.immortal-option.god-of-gods {
    background: linear-gradient(135deg, #fff8e1, #ffe082);
    border: 2px solid #ffd700;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
    position: relative;
}

.immortal-option.god-of-gods:hover {
    background: linear-gradient(135deg, #ffe082, #ffd54f);
    border-color: #ffab00;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
}

.immortal-option.god-of-gods .immortal-name {
    font-weight: bold;
    color: #b8860b;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* AI Section Styles (Embedded) */
.ai-section {
    margin-top: 40px;
    background: rgba(13, 27, 42, 0.6);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 8px;
    padding: 20px;
    display: none;
    /* Hidden by default */
    animation: fadeInUp 0.6s ease;
}

.ai-section.show {
    display: block;
}

.ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.ai-title {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.8em;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 600px;
}

.ai-chat-window {
    flex-grow: 1;
    border: 1px solid rgba(255, 215, 0, 0.1);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.ai-controls-area {
    background: rgba(255, 255, 255, 0.05);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid rgba(255, 215, 0, 0.1);
}

.quick-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.action-btn {
    background: rgba(27, 38, 59, 0.8);
    border: 1px solid var(--accent-color);
    color: var(--text-color);
    padding: 8px 15px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9em;
}

.action-btn:hover {
    background: var(--primary-color);
    color: #0d1b2a;
    border-color: var(--primary-color);
}

.ai-input-group {
    display: flex;
    gap: 15px;
    transition: all 0.3s ease;
}

.ai-input-group.debate-mode {
    display: block;
}

.debate-bottom-config {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 215, 0, 0.25);
    border-radius: 10px;
    overflow: hidden;
}
.debate-bottom-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(255, 215, 0, 0.08);
    font-size: 0.95em;
    color: #ffd700;
    font-weight: 500;
}
.debate-cancel-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: #aaa;
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
}
.debate-cancel-btn:hover {
    border-color: #ff5252;
    color: #ff5252;
}
.debate-bottom-body {
    padding: 12px 16px;
}
.debate-config-row {
    display: flex;
    gap: 20px;
    margin-bottom: 8px;
}
.debate-config-section {
    flex: 1;
}
.debate-bottom-input-row {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}
.debate-bottom-input-row .ai-input {
    height: 50px;
}
.debate-go-btn {
    white-space: nowrap;
    padding: 0 20px !important;
    font-size: 1em !important;
    min-width: 90px;
}

.ai-input {
    flex-grow: 1;
    padding: 15px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    border-radius: 8px;
    resize: none;
    height: 60px;
    font-family: inherit;
    font-size: 1em;
    transition: border-color 0.3s;
}

.ai-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.ai-send-btn {
    width: 100px;
    background: var(--primary-color);
    color: #0d1b2a;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.2em;
    transition: background 0.3s;
}

.ai-send-btn:hover {
    background: #e6c200;
}

.ai-send-btn:disabled {
    background: #555;
    cursor: not-allowed;
}

.ai-debate-btn {
    width: 100px;
    background: linear-gradient(135deg, #8b0000, #c41e3a);
    color: #ffd700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.1em;
    transition: background 0.3s, opacity 0.3s;
    position: relative;
    animation: debatePulse 2.5s ease-in-out infinite;
}

@keyframes debatePulse {
    0%, 100% { box-shadow: 0 0 4px rgba(255, 215, 0, 0.2); }
    50% { box-shadow: 0 0 14px rgba(255, 215, 0, 0.5), 0 0 4px rgba(196, 30, 58, 0.6); }
}

.ai-debate-btn::after {
    content: '真理越辩越明 ✨';
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #ffd700;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75em;
    font-family: -apple-system, 'Microsoft YaHei', sans-serif;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
    border: 1px solid rgba(255,215,0,0.3);
}

.ai-debate-btn:hover::after {
    opacity: 1;
}

.ai-debate-btn:hover {
    background: linear-gradient(135deg, #a00000, #d42e4a);
    animation: none;
    box-shadow: 0 0 16px rgba(255, 215, 0, 0.6);
}

.ai-debate-btn:disabled {
    background: #555;
    color: #999;
    cursor: not-allowed;
    animation: none;
    box-shadow: none;
}

.ai-debate-btn:disabled::after {
    display: none;
}

/* Message Styles (Reused/Adapted) */
.message {
    max-width: 80%;
    padding: 15px 20px;
    border-radius: 12px;
    line-height: 1.6;
    position: relative;
}

.message.user {
    align-self: flex-end;
    background: rgba(29, 53, 87, 0.8);
    border-bottom-right-radius: 2px;
    border: 1px solid rgba(119, 141, 169, 0.3);
    color: #e0e1dd;
}

.message.ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    /* Very slight transparency for readability */
    border-bottom-left-radius: 2px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    color: #e0e1dd;
}

.sender-name {
    font-size: 0.8em;
    color: var(--accent-color);
    margin-bottom: 5px;
    display: block;
}

/* Start Button overlay */
.start-ai-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--accent-color);
}

.btn-start-ai {
    margin-top: 20px;
    background: linear-gradient(135deg, #b8860b, #ffd700);
    color: #0d1b2a;
    padding: 15px 40px;
    font-size: 1.2em;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(184, 134, 11, 0.4);
    transition: transform 0.2s;
    font-family: inherit;
    font-weight: bold;
}

.btn-start-ai:hover {
    transform: scale(1.05);
}

.start-buttons {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.start-buttons .btn-start-ai {
    margin-top: 0;
}

.btn-start-debate {
    background: linear-gradient(135deg, #8b0000, #c41e3a);
    color: #ffd700;
    padding: 15px 35px;
    font-size: 1.2em;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 5px 15px rgba(139, 0, 0, 0.4);
    transition: transform 0.2s;
    font-family: inherit;
    font-weight: bold;
}

.btn-start-debate:hover {
    transform: scale(1.05);
}

.chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    font-family: 'Noto Serif SC', serif;
}

.chat-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), #b8860b);
    color: #0d1b2a;
    border: none;
    box-shadow: 0 4px 15px rgba(184, 134, 11, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(184, 134, 11, 0.6);
}

.chat-container {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    height: 600px;
    background: rgba(13, 27, 42, 0.95);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
    backdrop-filter: blur(10px);
}

.chat-container.open {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-header {
    padding: 15px;
    background: rgba(27, 38, 59, 0.9);
    color: #ffd700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--secondary-color);
}

.chat-title {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.2em;
    letter-spacing: 1px;
}

.chat-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.model-select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--accent-color);
    background: rgba(13, 27, 42, 0.8);
    font-size: 12px;
    color: #e0e1dd;
    cursor: pointer;
}

.close-chat {
    background: none;
    border: none;
    color: var(--accent-color);
    cursor: pointer;
    font-size: 20px;
    padding: 0 5px;
}

.close-chat:hover {
    color: #fff;
}

.chat-messages {
    flex-grow: 1;
    padding: 15px;
    overflow-y: auto;
    background-color: transparent;
    /* Changed from paper texture */
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Scrollbar for chat */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 3px;
}

.message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.95em;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background: rgba(27, 38, 59, 0.8);
    border: 1px solid #415a77;
    border-bottom-right-radius: 2px;
    color: #e0e1dd;
}

.message.ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 215, 0, 0.2);
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    color: #e0e1dd;
}

.message .sender {
    font-size: 0.75em;
    color: var(--accent-color);
    margin-bottom: 4px;
    display: block;
}

.thinking-process {
    font-size: 0.9em;
    color: #ccc;
    background: rgba(0, 0, 0, 0.2);
    border-left: 3px solid var(--accent-color);
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 0 4px 4px 0;
    display: none;
    /* Initially hidden or collapsed if desired */
}

.thinking-process.active {
    display: block;
    margin-top: 5px;
}

.thinking-header {
    font-size: 0.8em;
    font-weight: bold;
    color: var(--accent-color);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 5px;
}

.thinking-header::before {
    content: '▶';
    font-size: 0.8em;
    transition: transform 0.2s;
}

.thinking-process.expanded .thinking-header::before {
    transform: rotate(90deg);
}

.thinking-content {
    margin-top: 5px;
    white-space: pre-wrap;
    display: none;
}

.thinking-process.expanded .thinking-content {
    display: block;
}

.chat-input-area {
    padding: 15px;
    background: rgba(13, 27, 42, 0.95);
    border-top: 1px solid rgba(255, 215, 0, 0.1);
    display: flex;
    gap: 10px;
}

.chat-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--accent-color);
    border-radius: 6px;
    resize: none;
    height: 40px;
    font-family: inherit;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    transition: all 0.3s;
}

.chat-input:focus {
    outline: none;
    border-color: var(--primary-color);
    height: 60px;
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #0d1b2a;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
    align-self: flex-end;
}

.send-btn:hover {
    background: #e6c200;
    transform: translateY(-2px);
}

.send-btn:disabled {
    background: #555;
    cursor: not-allowed;
    transform: none;
}

@media (max-width: 480px) {
    .chat-container {
        width: calc(100% - 40px);
        right: 20px;
        bottom: 90px;
        height: 500px;
    }
}

.star-major {
    color: #ff4d4d;
    /* Red for major stars to pop */
    font-weight: bold;
    text-shadow: 0 0 2px rgba(255, 77, 77, 0.5);
}

.stars-minor {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.85em;
    color: #ccc;
    line-height: 1.2;
}

.brightness {
    font-size: 0.7em;
    color: var(--primary-color);
    margin-left: 1px;
    vertical-align: super;
}

.mutagen-label {
    background-color: var(--primary-color);
    color: #0d1b2a;
    border-radius: 2px;
    padding: 0 2px;
    font-size: 0.7em;
    margin-left: 1px;
    vertical-align: middle;
    font-weight: bold;
}

/* Bottom Section: Info Grid */
.palace-bottom-info {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
        "gods gods gods"
        "stem spacer name";
    align-items: end;
    margin-top: 5px;
    min-height: 40px;
    /* Ensure space for bottom elements */
}

/* 12 Gods Row */
.gods-row {
    grid-area: gods;
    display: flex;
    justify-content: space-between;
    font-size: 0.75em;
    color: rgba(255, 255, 255, 0.9);
    /* Brightened for dark background */
    border-top: 1px dashed rgba(255, 215, 0, 0.3);
    padding-top: 2px;
    margin-bottom: 2px;
}

.gods-item {
    margin-right: 4px;
}

/* Stem/Branch (Bottom Left) */
.palace-stem-branch {
    grid-area: stem;
    font-size: 1.2em;
    font-weight: bold;
    color: #e0e1dd;
    font-family: 'Ma Shan Zheng', cursive;
    line-height: 1;
}

/* Palace Name (Bottom Right) */
.palace-name {
    grid-area: name;
    background-color: var(--primary-color);
    color: #0d1b2a;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.1em;
    writing-mode: vertical-rl;
    text-orientation: upright;
    margin-left: auto;
    /* Push to right */
    box-shadow: 0 0 5px var(--primary-color);
}

/* Top Right Badge: Stage/Limit */
.palace-stage {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 0.8em;
    color: #fff;
    background: var(--secondary-color);
    padding: 1px 4px;
    border-radius: 3px;
    z-index: 10;
    box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Center Cell Styles */
.chart-logo {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 2.2em;
    color: var(--primary-color);
    margin-bottom: 15px;
    border-bottom: 2px solid var(--accent-color);
    display: inline-block;
    padding-bottom: 5px;
}

.user-info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 12px;
    text-align: left;
    font-size: 0.95em;
}

.user-info-label {
    color: var(--primary-color);
    font-weight: bold;
    text-align: right;
    white-space: nowrap;
}

/* Minimal Footer Attribution */
.footer-attribution {
    position: fixed;
    bottom: 5px;
    right: 10px;
    font-size: 0.7em;
    color: rgba(255, 255, 255, 0.2);
    pointer-events: none;
    /* Let clicks pass through */
}

.header h1 {
    margin-bottom: 5px;
}

.header p {
    font-size: 0.8em;
    opacity: 0.6;
    margin: 0;
    display: none;
    /* Hide original header attribution */
}

.copy-btn-container {
    margin-top: 15px;
}

/* Responsive adjustments */
/* Battle Mode Layout */
.battle-row {
    display: grid;
    gap: 15px;
    width: 100%;
    margin-bottom: 20px;
    align-items: start;
}

.battle-col {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 215, 0, 0.1);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    min-width: 0;
    height: fit-content;
}

.battle-col-header {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.2em;
    color: var(--primary-color);
    border-bottom: 2px solid rgba(255, 215, 0, 0.2);
    padding-bottom: 8px;
    margin-bottom: 10px;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px 4px 0 0;
}

.battle-col .content-text {
    font-size: 0.95em;
    line-height: 1.6;
    color: #ccc;
}

.battle-col .thinking-process {
    margin-bottom: 10px;
}

/* ===== 众仙争论 (Debate Mode) Styles ===== */

/* 轮次标题 */
.debate-round-header {
    text-align: center;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.4em;
    color: var(--primary-color);
    padding: 12px 0;
    margin: 20px 0 10px 0;
    border-top: 1px solid rgba(255, 215, 0, 0.3);
    border-bottom: 1px solid rgba(255, 215, 0, 0.3);
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
    letter-spacing: 4px;
}

.debate-round-header .round-subtitle {
    font-size: 0.6em;
    color: #999;
    letter-spacing: 1px;
    display: block;
    margin-top: 4px;
    font-family: 'Noto Serif SC', serif;
}

/* 裁决区域 */
.debate-verdict {
    margin-top: 20px;
    padding: 20px;
    border: 2px solid #ffd700;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(139, 0, 0, 0.15), rgba(0, 0, 0, 0.4));
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.15);
}

.debate-verdict-header {
    text-align: center;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.6em;
    color: #ffd700;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(255, 215, 0, 0.4);
    letter-spacing: 6px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

.debate-verdict .content-text {
    font-size: 1em;
    line-height: 1.8;
    color: #ddd;
}

.debate-verdict .thinking-process {
    margin-bottom: 10px;
}

/* 争论进度指示 */
.debate-progress {
    text-align: center;
    padding: 8px;
    color: #ffd700;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.1em;
    animation: debatePulse 1.5s ease-in-out infinite;
}

@keyframes debatePulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}
.settings-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5em;
    color: var(--primary-color);
    padding: 5px;
    display: flex;
    align-items: center;
    transition: transform 0.3s;
}

.settings-btn:hover {
    transform: rotate(45deg);
}

.settings-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.settings-content {
    background: rgba(13, 27, 42, 0.95);
    padding: 25px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    border: 1px solid var(--primary-color);
    box-shadow: 0 0 30px rgba(255, 215, 0, 0.2);
    position: relative;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid rgba(255, 215, 0, 0.2);
    padding-bottom: 10px;
}

.settings-title {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.5em;
    color: var(--primary-color);
}

.close-settings {
    background: none;
    border: none;
    font-size: 1.5em;
    cursor: pointer;
    color: var(--accent-color);
}

.close-settings:hover {
    color: #fff;
}

.settings-group {
    margin-bottom: 15px;
}

.settings-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 0.9em;
    color: var(--primary-color);
}

.settings-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--accent-color);
    border-radius: 6px;
    font-family: monospace;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
}

.settings-footer {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-save-settings {
    background: var(--primary-color);
    color: #0d1b2a;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

/* ===== Inline Debate Styles ===== */

.debate-inline-config {
    background: rgba(13, 27, 42, 0.9);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    animation: slideDown 0.3s ease;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.15);
}

.debate-inline-config.collapsed {
    padding: 12px 20px;
}

.debate-inline-config-header {
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.4em;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 15px;
    letter-spacing: 4px;
}

.debate-inline-config.collapsed .debate-inline-config-header {
    margin-bottom: 5px;
    font-size: 1.1em;
}

.debate-inline-config-summary {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85em;
    color: var(--accent-color);
    text-align: center;
}

.debate-config-title {
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 10px;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.1em;
}

.debate-config-title.judge-title {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 215, 0, 0.15);
}

.debate-config-title .judge-hint {
    font-family: inherit;
    font-size: 0.75em;
    color: rgba(255, 215, 0, 0.6);
    font-weight: normal;
}

.judge-checkboxes .immortal-option {
    border-color: rgba(138, 43, 226, 0.3);
}

.judge-checkboxes .immortal-option input:checked + .immortal-name {
    color: #dda0ff;
}

.debate-config-checkboxes {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.debate-cost-estimate {
    margin: 10px 0;
    padding: 10px 14px;
    border-radius: 8px;
    background: rgba(255, 215, 0, 0.08);
    border: 1px solid rgba(255, 215, 0, 0.2);
    font-size: 0.85em;
    line-height: 1.6;
    color: #ccc;
}
.debate-cost-estimate .cost-summary strong {
    color: #ffd700;
}
.debate-cost-estimate .cost-balance {
    color: #8bc34a;
    font-size: 0.9em;
}
.debate-cost-estimate .cost-insufficient {
    border-color: rgba(255, 80, 80, 0.4);
    background: rgba(255, 80, 80, 0.08);
}
.debate-cost-estimate .cost-insufficient .cost-balance {
    color: #ff5252;
    font-weight: bold;
}

.debate-question-area {
    display: flex;
    gap: 15px;
    align-items: stretch;
}

.debate-question-input {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid rgba(255, 215, 0, 0.2);
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    border-radius: 8px;
    resize: none;
    height: 50px;
    font-family: inherit;
    font-size: 1em;
}

.debate-question-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.debate-start-btn {
    background: linear-gradient(135deg, #8b0000, #cc3300);
    color: #ffd700;
    border: 1px solid #ffd700;
    padding: 12px 30px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Ma Shan Zheng', cursive;
    font-size: 1.2em;
    white-space: nowrap;
    transition: all 0.3s;
}

.debate-start-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #a00000, #e63900);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.4);
}

.debate-start-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.debate-inline-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 15px;
    border-left: 3px solid var(--primary-color);
    padding-left: 12px;
    margin: 10px 0;
}

.debate-inline-progress {
    padding: 8px 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 6px;
}

.debate-inline-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 215, 0, 0.3);
    border-radius: 8px;
    margin-top: 10px;
}

.debate-inline-footer-text {
    color: var(--accent-color);
    font-size: 0.9em;
}

.debate-export-btn {
    background: rgba(255, 215, 0, 0.15);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s;
}

.debate-export-btn:hover {
    background: var(--primary-color);
    color: #0d1b2a;
}

.debate-progress-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 5px;
}

.debate-progress-fill {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.5s ease;
}

.debate-progress-text {
    text-align: center;
    font-size: 0.9em;
    color: var(--accent-color);
}

/* ===== Tablet Responsive (≤1024px) ===== */
@media (max-width: 1024px) {
    .container {
        margin: 20px auto;
        padding: 15px;
    }

    .ziwei-grid {
        gap: 6px;
        max-width: 100%;
    }

    .palace-cell {
        padding: 6px;
    }

    .stars-major {
        font-size: 1em;
    }

    .center-cell {
        padding: 12px;
    }

    .chart-logo {
        font-size: 1.6em;
    }

    .user-info-grid {
        font-size: 0.85em;
        gap: 4px 8px;
    }

    .battle-row {
        gap: 10px;
    }
}

/* ===== Mobile Responsive (≤768px) ===== */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    .container {
        margin: 10px auto;
        padding: 10px;
        border-radius: 8px;
    }

    .corner-decoration {
        width: 60px;
        height: 60px;
    }

    .container::before {
        top: 5px;
        left: 5px;
        right: 5px;
        bottom: 5px;
    }

    /* Header */
    .header {
        padding: 30px 10px 20px;
        margin-bottom: 15px;
    }

    .header h1 {
        font-size: 1.6em;
        letter-spacing: 2px;
    }

    .header h1 img {
        height: 0.9em !important;
        margin-right: 8px !important;
    }

    .header p {
        font-size: 0.9em;
        letter-spacing: 1px;
    }

    .header::after {
        width: 80%;
        height: 25px;
        margin-top: 10px;
    }

    /* Form */
    .main-content {
        padding: 10px;
    }

    .input-section {
        padding: 15px;
    }

    .input-section h2 {
        font-size: 1.2em;
    }

    .form-group label {
        font-size: 0.9em;
    }

    .form-group input,
    .form-group select {
        font-size: 16px; /* Prevent iOS zoom on focus */
        padding: 8px;
    }

    .btn-generate {
        font-size: 1.1em;
        padding: 12px;
    }

    /* Ziwei Chart Grid — horizontal scroll on mobile */
    .ziwei-chart-container {
        padding: 5px;
        margin-top: 20px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ziwei-grid {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: repeat(4, minmax(110px, auto));
        gap: 3px;
        font-size: 0.6em;
        min-width: 480px; /* Ensure grid doesn't collapse too small */
    }

    .palace-cell {
        padding: 3px;
        min-width: 0;
        overflow: hidden;
    }

    .stars-major {
        font-size: 0.95em;
        gap: 2px;
    }

    .stars-minor {
        font-size: 0.75em;
        gap: 1px;
    }

    .stars-container {
        padding-right: 18px;
    }

    .center-cell {
        padding: 8px;
    }

    .chart-logo {
        font-size: 1.4em;
        margin-bottom: 8px;
    }

    .user-info-grid {
        font-size: 0.8em;
        gap: 2px 6px;
    }

    .user-info-label {
        font-size: 0.8em;
    }

    .copy-btn-container {
        margin-top: 8px;
        display: flex;
        flex-direction: column;
        gap: 6px;
        align-items: center;
    }

    .btn-copy,
    .btn-ai-diagnosis {
        font-size: 0.85em;
        padding: 6px 12px;
    }

    .palace-name {
        font-size: 0.95em;
        padding: 1px 4px;
    }

    .palace-stem-branch {
        font-size: 1em;
    }

    .palace-stage {
        font-size: 0.7em;
    }

    .gods-row {
        font-size: 0.7em;
    }

    /* AI Section */
    .ai-section {
        padding: 10px;
        margin-top: 20px;
    }

    .ai-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
        padding-bottom: 10px;
        margin-bottom: 10px;
    }

    .ai-title {
        font-size: 1.3em;
    }

    .model-controls {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .model-select {
        width: 100%;
        font-size: 0.9em;
    }

    .battle-switch {
        font-size: 0.85em;
    }

    .battle-switch .label-text {
        font-size: 0.85em;
    }

    /* Battle Config */
    .battle-config {
        padding: 10px;
    }

    .battle-checkboxes {
        gap: 6px;
    }

    .immortal-option {
        padding: 6px 10px;
        font-size: 0.85em;
    }

    /* AI Chat Container */
    .ai-container {
        height: auto;
        min-height: 400px;
    }

    .ai-chat-window {
        padding: 10px;
        min-height: 300px;
        max-height: 60vh;
    }

    .ai-controls-area {
        padding: 10px;
    }

    .quick-actions {
        gap: 6px;
        margin-bottom: 10px;
    }

    .action-btn {
        padding: 6px 10px;
        font-size: 0.8em;
    }

    /* Input Group */
    .ai-input-group {
        gap: 8px;
    }

    .ai-input {
        padding: 10px;
        height: 50px;
        font-size: 16px; /* Prevent iOS zoom */
    }

    .ai-send-btn {
        width: 60px;
        font-size: 1em;
    }

    .ai-debate-btn {
        width: 60px;
        font-size: 0.9em;
    }

    /* Debate Bottom Config - Mobile */
    .debate-config-row {
        flex-direction: column;
        gap: 10px;
    }

    .debate-bottom-header {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    .debate-bottom-body {
        padding: 10px 12px;
    }

    .debate-config-title {
        font-size: 0.85em;
    }

    .judge-hint {
        display: block;
        font-size: 0.85em;
        margin-top: 2px;
    }

    .debate-config-checkboxes {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .debate-cost-estimate {
        font-size: 0.8em;
        padding: 8px 10px;
    }

    .debate-bottom-input-row {
        flex-direction: column;
        gap: 8px;
    }

    .debate-bottom-input-row .ai-input {
        height: 45px;
        font-size: 16px;
    }

    .debate-go-btn {
        width: 100% !important;
        min-width: unset;
        padding: 10px !important;
    }

    .ai-debate-btn::after {
        display: none;
    }

    /* Start Overlay */
    .start-ai-overlay p {
        font-size: 0.9em;
        padding: 0 10px;
    }

    .start-buttons {
        flex-direction: column;
        gap: 12px;
    }

    .btn-start-ai,
    .btn-start-debate {
        padding: 12px 30px;
        font-size: 1em;
    }

    /* Messages */
    .message {
        max-width: 95%;
        padding: 10px 12px;
        font-size: 0.9em;
    }

    .message .content-text {
        overflow-wrap: break-word;
        word-break: break-word;
    }

    .message .content-text pre {
        overflow-x: auto;
        max-width: 100%;
        font-size: 0.85em;
    }

    .message .content-text table {
        display: block;
        overflow-x: auto;
        max-width: 100%;
    }

    /* Battle Row */
    .battle-row {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .battle-col {
        padding: 10px;
    }

    .battle-col-header {
        font-size: 1em;
    }

    .battle-col .content-text {
        font-size: 0.85em;
        overflow-wrap: break-word;
        word-break: break-word;
    }

    /* Debate Inline Config */
    .debate-inline-config {
        padding: 12px;
    }

    .debate-inline-config-header {
        font-size: 1.1em;
    }

    .debate-config-checkboxes {
        gap: 6px;
    }

    .debate-question-area {
        flex-direction: column;
        gap: 10px;
    }

    .debate-question-input {
        height: 60px;
    }

    .debate-start-btn {
        width: 100%;
    }

    .debate-inline-config-summary {
        font-size: 0.85em;
    }

    .debate-inline-footer {
        flex-direction: column;
        gap: 10px;
        align-items: center;
    }

    .debate-round-header {
        font-size: 1.1em;
        letter-spacing: 2px;
    }

    /* Settings Modal */
    .settings-content {
        width: 95%;
        padding: 15px;
    }

    .settings-title {
        font-size: 1.2em;
    }

    /* Thinking Process */
    .thinking-process {
        font-size: 0.85em;
    }

    .thinking-content {
        max-height: 200px;
        overflow-y: auto;
    }
}

/* ===== Small Phone (≤480px) ===== */
@media (max-width: 480px) {
    body {
        padding: 4px;
    }

    .container {
        margin: 5px auto;
        padding: 6px;
    }

    .corner-decoration {
        width: 40px;
        height: 40px;
    }

    .header h1 {
        font-size: 1.3em;
        letter-spacing: 1px;
    }

    .header h1 img {
        height: 0.8em !important;
        margin-right: 5px !important;
    }

    .input-section {
        padding: 10px;
    }

    .input-section h2 {
        font-size: 1em;
    }

    .form-row {
        grid-template-columns: 1fr !important;
    }

    /* ===== Chart: 手机端重排为可滚动但更大的格子 ===== */
    .ziwei-chart-container {
        padding: 2px;
        margin-top: 15px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .ziwei-grid {
        font-size: 0.7em;
        gap: 2px;
        min-width: 560px;
        grid-template-rows: repeat(4, minmax(120px, auto));
    }

    .palace-cell {
        padding: 4px;
    }

    .stars-major {
        font-size: 1em;
        gap: 2px;
    }

    .stars-minor {
        font-size: 0.8em;
        gap: 1px;
    }

    .stars-container {
        padding-right: 22px;
    }

    .center-cell {
        padding: 8px;
    }

    .chart-logo {
        font-size: 1.3em;
        margin-bottom: 5px;
    }

    .user-info-grid {
        font-size: 0.75em;
        gap: 1px 4px;
    }

    .copy-btn-container {
        margin-top: 5px;
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        justify-content: center;
    }

    .btn-copy,
    .btn-ai-diagnosis {
        font-size: 0.8em;
        padding: 5px 10px;
    }

    .palace-name {
        font-size: 0.9em;
        padding: 1px 3px;
    }

    .palace-stem-branch {
        font-size: 1em;
    }

    .palace-stage {
        font-size: 0.7em;
    }

    .gods-row {
        font-size: 0.7em;
    }

    /* AI */
    .ai-title {
        font-size: 1.1em;
    }

    .ai-container {
        min-height: 350px;
    }

    .ai-chat-window {
        min-height: 250px;
        max-height: 50vh;
        padding: 8px;
    }

    .ai-send-btn,
    .ai-debate-btn {
        width: 50px;
        font-size: 0.85em;
    }

    .ai-debate-btn::after {
        display: none;
    }

    .debate-bottom-header span {
        font-size: 0.85em;
    }

    .debate-bottom-body {
        padding: 8px 10px;
    }

    .debate-config-title {
        font-size: 0.8em;
        margin-bottom: 4px;
    }

    .debate-cost-estimate {
        font-size: 0.75em;
        padding: 6px 8px;
        line-height: 1.5;
    }

    .debate-cancel-btn {
        font-size: 0.8em;
        padding: 3px 10px;
    }

    .action-btn {
        padding: 5px 8px;
        font-size: 0.75em;
    }

    /* 仙人选择项：手机上两列排列 */
    .battle-checkboxes,
    .debate-config-checkboxes {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .immortal-option {
        padding: 5px 8px;
        font-size: 0.8em;
        justify-content: flex-start;
    }

    .battle-col {
        padding: 8px;
    }

    .debate-inline-config {
        padding: 8px;
    }

    .debate-inline-config-header {
        font-size: 1em;
        letter-spacing: 2px;
    }

    .message {
        max-width: 98%;
        padding: 8px 10px;
        font-size: 0.85em;
    }

    .chat-container {
        width: calc(100% - 20px);
        right: 10px;
        bottom: 80px;
        height: 450px;
    }

    /* 提示滚动 */
    .ziwei-chart-container::after {
        content: '← 左右滑动查看完整命盘 →';
        display: block;
        text-align: center;
        font-size: 0.75em;
        color: rgba(255, 215, 0, 0.5);
        padding: 6px 0 2px;
        font-family: 'Noto Serif SC', serif;
    }
}

/* ===== Very Small Phone (≤380px) ===== */
@media (max-width: 380px) {
    .header h1 {
        font-size: 1.1em;
    }

    .ziwei-grid {
        font-size: 0.5em;
        min-width: 380px;
    }

    .ai-send-btn,
    .ai-debate-btn {
        width: 45px;
        font-size: 0.8em;
    }

    .debate-config-checkboxes {
        grid-template-columns: 1fr !important;
    }

    .debate-bottom-config {
        font-size: 0.9em;
    }

    .btn-generate {
        font-size: 1em;
        padding: 10px;
    }
}