:root {
    --primary-color: #8c2a2a;      /* 朱紅/古紅 */
    --primary-dark: #611b1b;       /* 暗紅 */
    --accent-gold: #c5a059;        /* 鎏金 */
    --accent-gold-light: #f5ece0;  /* 淺金米色 */
    --bg-color: #f2ede4;           /* 宣紙復古背景 */
    --paper-bg: #fdfaf3;          /* 籤文紙張色 */
    --ink-black: #2c2523;          /* 墨黑 */
    --border-color: #dcd1be;       /* 古風邊框 */
    --ai-purple: #4a2e80;          /* AI 靈感紫 */
}

body {
    font-family: "Noto Serif TC", "Songti SC", "STSong", "DFKai-SB", "KaiTi", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, serif;
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(rgba(197, 160, 89, 0.15) 1px, transparent 1px),
        radial-gradient(rgba(140, 42, 42, 0.08) 1px, var(--bg-color) 1px);
    background-size: 24px 24px;
    background-position: 0 0, 12px 12px;
    color: var(--ink-black);
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 15px;
    line-height: 1.7;
}

.container {
    background: #faf6ee;
    padding: 30px 25px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 30px rgba(60, 40, 20, 0.12);
    position: relative;
}

.container::before {
    content: "";
    position: absolute;
    top: 6px; left: 6px; right: 6px; bottom: 6px;
    border: 1px solid rgba(197, 160, 89, 0.5);
    border-radius: 6px;
    pointer-events: none;
}

.header-box {
    text-align: center;
    position: relative;
    margin-bottom: 20px;
}

h1 {
    color: var(--primary-color);
    font-size: 28px;
    letter-spacing: 4px;
    margin: 0 0 6px 0;
    font-weight: bold;
    text-shadow: 1px 1px 0px rgba(255,255,255,0.8);
}

.subtitle {
    text-align: center;
    color: #7a6b5d;
    font-size: 14px;
    letter-spacing: 2px;
}

/* 占問事項卡片 */
.question-card {
    background: #fdfbf7;
    border: 1.5px solid var(--accent-gold);
    border-radius: 8px;
    padding: 16px 18px;
    margin-bottom: 20px;
    box-shadow: inset 0 0 10px rgba(197, 160, 89, 0.08);
}

.question-label {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 15px;
    margin-bottom: 8px;
}

.question-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #ffffff;
    font-family: inherit;
    font-size: 14.5px;
    color: var(--ink-black);
    box-sizing: border-box;
    resize: vertical;
    min-height: 60px;
    outline: none;
    transition: border-color 0.3s;
}

.question-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 5px rgba(140, 42, 42, 0.2);
}

.quick-tags {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.quick-tag-label {
    font-size: 12.5px;
    color: #888;
}

.tag-btn {
    background: #f4ebd9;
    border: 1px solid #e0d1b8;
    color: #615243;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 12.5px;
    cursor: pointer;
    transition: all 0.2s;
}

.tag-btn:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

/* ✨ 語音輸入按鈕樣式 */
.voice-btn {
    background: #f4ebd9;
    border: 1px solid var(--accent-gold);
    color: var(--primary-color);
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.25s ease;
}

.voice-btn:hover {
    background: var(--accent-gold-light);
}

.voice-btn.recording {
    background: #d32f2f;
    color: #ffffff;
    border-color: #b71c1c;
    animation: pulse-red 1.2s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(211, 47, 47, 0.6); }
    70% { box-shadow: 0 0 0 8px rgba(211, 47, 47, 0); }
    100% { box-shadow: 0 0 0 0 rgba(211, 47, 47, 0); }
}

/* 註解按鈕 */
.annotation-btn-wrap {
    text-align: center;
    margin-bottom: 20px;
}

button.annotation-btn {
    background-color: #f4ebd9;
    color: var(--primary-color);
    border: 1px solid var(--accent-gold);
    padding: 6px 18px;
    font-size: 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

button.annotation-btn:hover {
    background-color: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
}

/* 頁籤選單 */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--accent-gold);
    margin-bottom: 25px;
    gap: 10px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: #ede4d4;
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    font-size: 16px;
    font-weight: bold;
    color: #665b50;
    cursor: pointer;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* 金錢卦搖卦區 */
.shake-status-box {
    background: #f5ede0;
    border: 1px dashed var(--accent-gold);
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    margin-bottom: 20px;
}

.progress-text {
    font-size: 18px;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.coins-stage {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 25px;
    min-height: 95px;
    margin: 15px 0;
    perspective: 800px;
}

.coin-img-wrapper {
    width: 75px; height: 75px;
    border-radius: 50%;
    box-shadow: 0 4px 10px rgba(0,0,0,0.25);
    transition: transform 0.8s ease-out;
    transform-style: preserve-3d;
    background-color: #d4af37;
}

.coin-img-wrapper img {
    width: 100%; height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

@keyframes coinFlipReal {
    0% { transform: translateY(0) rotateX(0deg) rotateY(0deg) scale(1); }
    30% { transform: translateY(-50px) rotateX(720deg) rotateY(360deg) scale(1.15); }
    60% { transform: translateY(10px) rotateX(1440deg) rotateY(720deg) scale(0.95); }
    80% { transform: translateY(-15px) rotateX(1800deg) rotateY(900deg) scale(1.05); }
    100% { transform: translateY(0) rotateX(2160deg) rotateY(1080deg) scale(1); }
}

.coin-img-wrapper.shaking { animation: coinFlipReal 0.8s ease-in-out; }

.coins-detail {
    font-size: 15px;
    color: #555;
    min-height: 24px;
    margin-top: 10px;
}

.input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    justify-content: center;
}

input[type="number"] {
    width: 85px;
    padding: 10px;
    font-size: 16px;
    border: 1px solid var(--accent-gold);
    background-color: #fcf9f2;
    border-radius: 6px;
    text-align: center;
    color: var(--ink-black);
    font-weight: bold;
}

.btn-div {
    text-align: center;
    margin: 20px 0;
    display: flex;
    justify-content: center;
    gap: 12px;
}

button.action-btn {
    background: linear-gradient(180deg, #9e3232 0%, #7a2222 100%);
    color: #fdfaf3;
    border: 1px solid var(--accent-gold);
    padding: 12px 28px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(122, 34, 34, 0.3);
}

button.reset-btn {
    background-color: #6b635b;
    color: white;
    border: none;
    padding: 12px 20px;
    font-size: 16px;
    border-radius: 6px;
    cursor: pointer;
}

.hexagram-display {
    display: flex;
    flex-direction: column-reverse;
    margin: 20px 0;
    background: var(--accent-gold-light);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--accent-gold);
}

/* 解卦結果籤文框 */
.result-box-fortune {
    margin-top: 30px;
    background-color: var(--paper-bg);
    border: 3px double var(--primary-color);
    border-radius: 8px;
    padding: 30px 22px;
    position: relative;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12), inset 0 0 30px rgba(197, 160, 89, 0.12);
}

.result-box-fortune::before {
    content: "";
    position: absolute;
    top: 6px; left: 6px; right: 6px; bottom: 6px;
    border: 1px solid var(--accent-gold);
    pointer-events: none;
    border-radius: 4px;
}

.stamp-seal {
    position: absolute;
    top: 22px; right: 22px;
    width: 58px; height: 58px;
    border: 2px solid #b82626;
    color: #b82626;
    font-family: "STKaiti", "DFKai-SB", "KaiTi", serif;
    font-weight: bold;
    font-size: 16px;
    display: flex;
    align-items: center; justify-content: center;
    text-align: center;
    line-height: 1.15;
    border-radius: 8px;
    transform: rotate(-8deg);
    opacity: 0.85;
    background: rgba(253, 250, 243, 0.85);
    pointer-events: none;
}

.slip-header {
    text-align: center;
    border-bottom: 2px dashed var(--accent-gold);
    padding-bottom: 16px;
    margin-bottom: 25px;
}

.slip-title {
    color: var(--primary-color);
    font-size: 24px;
    font-weight: bold;
    letter-spacing: 3px;
    margin: 0;
}

.gua-cards-container {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    justify-content: center;
    margin-bottom: 25px;
}

.gua-card-main {
    flex: 1;
    min-width: 280px;
    background: #faf4e8;
    border: 1px solid #ebdcc5;
    border-top: 4px solid var(--primary-color);
    padding: 16px;
    border-radius: 6px;
}

.gua-card-changed {
    flex: 1;
    min-width: 280px;
    background: #f1f6f2;
    border: 1px solid #cce3d2;
    border-top: 4px solid #2e7d32;
    padding: 16px;
    border-radius: 6px;
}

.notice-banner {
    margin-bottom: 25px;
    padding: 16px 20px;
    background: #fcf4dd;
    border-left: 5px solid #d99b00;
    border-right: 1px solid #f0e2be;
    border-top: 1px solid #f0e2be;
    border-bottom: 1px solid #f0e2be;
    border-radius: 4px;
    color: #7a5200;
    font-weight: bold;
    font-size: 15px;
    line-height: 1.6;
}

/* 解卦 Tab 頁籤 */
.gua-tabs-wrapper { margin-bottom: 25px; }

.gua-tabs {
    display: flex;
    gap: 6px;
    border-bottom: 2px solid var(--accent-gold);
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.gua-tab-btn {
    padding: 9px 16px;
    background-color: #f0e6d6;
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    font-size: 14.5px;
    font-weight: bold;
    color: #5c4e43;
    cursor: pointer;
    transition: all 0.25s ease;
}

.gua-tab-btn:hover {
    background-color: #e8dbb8;
    color: var(--primary-color);
}

.gua-tab-btn.active {
    background-color: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
}

.gua-tab-btn.ai-tab-btn.active {
    background: linear-gradient(135deg, #5b33a8 0%, #3a1c71 100%);
    border-color: #5b33a8;
}

.gua-tab-content {
    display: none;
    animation: fadeIn 0.2s ease-out;
}

.gua-tab-content.active { display: block; }

.gua-text-block {
    background: #ffffff;
    border: 1px solid #e8decb;
    padding: 20px 22px;
    border-radius: 6px;
}

.gua-section { margin-bottom: 18px; }
.gua-section:last-child { margin-bottom: 0; }

.gua-section-title {
    font-weight: bold;
    color: var(--primary-color);
    font-size: 16px;
    margin-bottom: 6px;
}

.gua-original-text {
    font-size: 16px;
    line-height: 1.8;
    color: #2b2421;
    background: #faf6ee;
    padding: 10px 14px;
    border-radius: 4px;
    border-left: 3px solid var(--accent-gold);
    margin-bottom: 8px;
    white-space: pre-wrap;
}

.gua-explanation-text {
    font-size: 15px;
    line-height: 1.85;
    color: #443c38;
    white-space: pre-wrap;
}

/* 變爻/動爻區塊 */
.moving-lines-box {
    background: #faf5eb;
    border: 1px solid #e5d8bf;
    border-left: 4px solid var(--primary-color);
    border-radius: 6px;
    padding: 18px 20px;
    margin-top: 20px;
}

.moving-lines-header {
    font-size: 17px;
    font-weight: bold;
    color: var(--primary-color);
    border-bottom: 1px dashed var(--accent-gold);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.moving-lines-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.yao-card {
    background: #ffffff;
    border: 1px solid #ebdcc5;
    border-radius: 6px;
    padding: 14px 16px;
}

.yao-title {
    font-size: 15.5px;
    font-weight: bold;
    color: #8c2a2a;
    margin-bottom: 8px;
}

.yao-field {
    font-size: 14.5px;
    line-height: 1.75;
    color: #332d29;
    margin-bottom: 4px;
}

/* AI 靈卦 Tab 頁籤內容卡片 */
.ai-card {
    background: linear-gradient(135deg, #fbf7f0 0%, #f3ebff 100%);
    border: 1.5px solid #d3c2eb;
    border-radius: 10px;
    padding: 20px;
    position: relative;
    box-shadow: 0 4px 12px rgba(74, 46, 128, 0.08);
}

.ai-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    border-bottom: 1px dashed #c4b0e3;
    padding-bottom: 8px;
    flex-wrap: wrap;
    gap: 8px;
}

.ai-title {
    font-size: 18px;
    font-weight: bold;
    color: var(--ai-purple);
}

.key-status-badge {
    font-size: 12.5px;
    padding: 4px 10px;
    border-radius: 12px;
    background: #e9e0f7;
    color: var(--ai-purple);
    border: 1px solid #bba3e3;
    cursor: pointer;
    font-weight: bold;
}

.ai-question-recap {
    font-size: 14.5px;
    color: #4a4453;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.8);
    padding: 10px 14px;
    border-radius: 6px;
    border-left: 3px solid var(--ai-purple);
}

.ai-btn {
    background: linear-gradient(135deg, #5b33a8 0%, #3a1c71 100%);
    color: #ffffff;
    border: 1px solid #9d7bd8;
    padding: 11px 24px;
    font-size: 15.5px;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(58, 28, 113, 0.25);
    transition: all 0.3s;
}

.ai-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(58, 28, 113, 0.35);
}

.ai-result-content {
    margin-top: 18px;
    background: #ffffff;
    border: 1px solid #dcd1be;
    border-radius: 8px;
    padding: 20px;
    font-size: 15px;
    line-height: 1.85;
    color: #2b2421;
}

.ai-result-content h1, .ai-result-content h2, .ai-result-content h3 {
    color: var(--ai-purple);
    margin-top: 16px;
    margin-bottom: 8px;
}

.ai-result-content ul, .ai-result-content ol {
    padding-left: 22px;
}

/* Modal 彈窗 (API Key) */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.65);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    background: #fdfaf3;
    border: 2px solid var(--accent-gold);
    max-width: 520px;
    width: 100%;
    max-height: 85vh;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 10px 35px rgba(0,0,0,0.4);
    position: relative;
    overflow-y: auto;
    animation: fadeIn 0.25s ease-out;
}

.modal-close {
    position: absolute;
    top: 15px; right: 20px;
    font-size: 26px;
    color: #888;
    cursor: pointer;
}

.modal-close:hover { color: var(--primary-color); }

.modal-title {
    color: var(--primary-color);
    font-size: 20px;
    font-weight: bold;
    margin-top: 0; margin-bottom: 15px;
    border-bottom: 2px solid var(--accent-gold);
    padding-bottom: 8px;
    text-align: center;
}

.input-group-modal { margin-bottom: 18px; }

.input-group-modal label {
    display: block;
    font-weight: bold;
    font-size: 14px;
    margin-bottom: 6px;
    color: #443c38;
}

.key-input-wrapper {
    display: flex;
    gap: 8px;
}

.key-input-wrapper input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--accent-gold);
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
}

.eye-btn {
    padding: 0 12px;
    background: #ede4d4;
    border: 1px solid var(--accent-gold);
    border-radius: 6px;
    cursor: pointer;
}

.security-note {
    background: #f4ede2;
    border-left: 3px solid #c5a059;
    padding: 10px 12px;
    font-size: 12.5px;
    color: #615347;
    border-radius: 4px;
    margin-bottom: 20px;
    line-height: 1.6;
}

.modal-btn-group {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-confirm {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 9px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
}

.btn-cancel {
    background: #888;
    color: white;
    border: none;
    padding: 9px 16px;
    border-radius: 6px;
    cursor: pointer;
}

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

.loading-spin {
    display: inline-block;
    animation: spin 1.5s infinite linear;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.download-jpg-btn {
    background: linear-gradient(135deg, #2e7d32 0%, #1b5e20 100%);
    color: #ffffff;
    border: 1px solid #81c784;
    padding: 11px 22px;
    font-size: 15.5px;
    font-weight: bold;
    border-radius: 25px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.25);
    transition: all 0.3s ease;
}

.download-jpg-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(46, 125, 50, 0.35);
}

.download-jpg-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ✨ 語音選單下拉框樣式 */
.voice-lang-select {
    background: #f4ebd9;
    border: 1px solid var(--accent-gold);
    color: var(--primary-color);
    padding: 3px 8px;
    border-radius: 14px;
    font-size: 12.5px;
    font-weight: bold;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.25s ease;
}

.voice-lang-select:hover {
    background: var(--accent-gold-light);
}

/* ==========================================
   ✨ 爻象全右對齊樣式（無紅點標籤，手機電腦雙端完美對齊）
   ========================================== */

.gua-visual-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
}

/* 單行設定：全部靠右邊（justify-content: flex-end） */
.gua-line-row {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    width: 100%;
}

/* 左側文字：靠右對齊不換行 */
.line-label {
    font-size: 0.73rem;
    color: #444;
    font-weight: bold;
    white-space: nowrap;
    text-align: right;
}

/* 右側爻條：固定 80px 寬度，齊右排開 */
.line-bar-box {
    width: 80px;
    flex-shrink: 0;
    height: 9px;
}

.yang-line, .yin-line {
    width: 100%;
    height: 100%;
}

.yang-line {
    border-radius: 2px;
}

.yin-line {
    display: flex;
    justify-content: space-between;
}

.yin-line div {
    width: 44%;
    height: 100%;
    border-radius: 2px;
}

/* 爻條顏色（動爻保持紅色高亮） */
.line-normal { background-color: #8c2a2a; }
.line-changed { background-color: #2e7d32; }
.line-moving { background-color: #d32f2f; }

/* 極小螢幕手機（寬度小於 360px）字級與寬度微調 */
@media (max-width: 360px) {
    .gua-line-row {
        gap: 5px;
    }
    .line-label {
        font-size: 0.66rem;
    }
    .line-bar-box {
        width: 70px;
    }
}

/* ==========================================
   ✨ Step 1: AI 雙模式頁籤與排隊 UI 樣式
   ========================================== */

/* 二級模式切換頁籤 (駐場大師 / 私人 AI) */
.ai-mode-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid #d3c2eb;
    padding-bottom: 10px;
}

.ai-mode-btn {
    flex: 1;
    padding: 8px 12px;
    background: #f0e6f7;
    border: 1px solid #c4b0e3;
    border-radius: 6px;
    font-size: 13.5px;
    font-weight: bold;
    color: var(--ai-purple);
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: center;
}

.ai-mode-btn:hover {
    background: #e4d5f5;
}

.ai-mode-btn.active {
    background: var(--ai-purple);
    color: #ffffff;
    border-color: var(--ai-purple);
    box-shadow: 0 2px 6px rgba(74, 46, 128, 0.2);
}

.ai-mode-content {
    display: none;
}

.ai-mode-content.active {
    display: block;
    animation: fadeIn 0.25s ease-out;
}

/* 駐場 AI 排隊卡片樣式 */
.queue-box {
    background: #fffdf9;
    border: 1.5px dashed var(--accent-gold);
    border-radius: 8px;
    padding: 20px 15px;
    text-align: center;
    margin-top: 12px;
    box-shadow: inset 0 0 10px rgba(197, 160, 89, 0.05);
}

.queue-status-title {
    font-size: 16px;
    font-weight: bold;
    color: var(--ai-purple);
    margin-bottom: 6px;
}

.queue-number-display {
    font-size: 26px;
    font-weight: bold;
    color: var(--primary-color);
    margin: 12px 0;
    letter-spacing: 1px;
}

.queue-hint {
    font-size: 12.5px;
    color: #7a6b5d;
    margin-bottom: 14px;
}

.btn-cancel-queue {
    background: #888888;
    color: #ffffff;
    border: none;
    padding: 7px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: bold;
    transition: all 0.2s ease;
}

.btn-cancel-queue:hover {
    background: #666666;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}