/* ==========================================================
   星塵斗悟｜青玄子微命理科技諮詢棧
   深炭灰科技風＋金黃邊框 (Style CSS v2.2)
   ========================================================== */
:root {
    --bg: #0e1013;
    --frame-bg: #15181d;
    --panel-bg: #1b1f25;
    --card-bg: #20252c;
    --card-hover: #262c34;
    --gold: #d4a94a;
    --gold-bright: #f0c868;
    --gold-soft: rgba(212, 169, 74, 0.14);
    --gold-line: rgba(212, 169, 74, 0.38);
    --text: #ece8df;
    --text-muted: #a2a8b0;
    --text-dim: #6f757d;
    --accent: #f0c868;
    --input-bg: #12151a;
    --radius: 12px;
    --radius-sm: 8px;
    --font-sans: "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", sans-serif;
    --font-serif: "Noto Serif TC", "PMingLiU", serif;

    /* 提示條與狀態顏色 */
    --color-success: #43a047;
    --color-info: #1e88e5;
    --color-warn: #fb8c00;
    --color-error: #e53935;
}

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

html, body {
    background: var(--bg);
}

body {
    color: var(--text);
    font-family: var(--font-sans);
    line-height: 1.6;
    background:
        radial-gradient(1200px 600px at 15% -10%, rgba(212, 169, 74, 0.08), transparent 60%),
        radial-gradient(900px 500px at 110% 110%, rgba(90, 110, 140, 0.10), transparent 60%),
        var(--bg);
    min-height: 100vh;
    overflow-x: hidden;
}

/* 隱藏元素輔助類別 */
.is-hidden {
    display: none !important;
}

/* ===================== 外框與排版 ===================== */
.app-frame {
    display: flex;
    flex-direction: column;
    background: var(--frame-bg);
    border: 1.5px solid var(--gold);
    border-radius: 18px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 0 32px rgba(212, 169, 74, 0.18), 0 20px 60px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

body.view-window {
    padding: 28px 24px;
}
body.view-window .app-frame {
    max-width: 1200px;
    margin: 0 auto;
}

body.view-full {
    padding: 10px;
}
body.view-full .app-frame {
    width: 100%;
    min-height: calc(100vh - 20px);
}

/* ===================== 頁首 ===================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 18px 28px;
    border-bottom: 1px solid var(--gold-line);
    background: linear-gradient(180deg, rgba(212, 169, 74, 0.06), transparent);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    width: 64px;
    height: 64px;
    border-radius: 12px;
    object-fit: cover;
    border: 1px solid var(--gold);
    flex-shrink: 0;
}

.brand-main {
    font-family: var(--font-serif);
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 6px;
    color: var(--gold-bright);
    text-shadow: 0 0 18px rgba(240, 200, 104, 0.25);
    line-height: 1.2;
}

.brand-sub {
    margin-top: 4px;
    font-size: 0.95rem;
    letter-spacing: 4px;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.view-switch {
    display: flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--gold-line);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.view-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s;
}

.view-btn:hover {
    color: var(--gold-bright);
}

.view-btn.active {
    background: var(--gold-soft);
    color: var(--gold-bright);
    box-shadow: inset 0 0 0 1px var(--gold-line);
}

/* ===================== 步驟導航列 (Stepper) ===================== */
.stepper-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid var(--gold-line);
    padding: 12px 28px;
    position: relative;
}

.stepper-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-dim);
    font-weight: 500;
    font-size: 0.92rem;
    position: relative;
    z-index: 1;
}

.stepper-item .step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 1px solid var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.stepper-item.active {
    color: var(--gold-bright);
    font-weight: 700;
}

.stepper-item.active .step-num {
    background: var(--gold);
    color: #1a1408;
    border-color: var(--gold-bright);
    box-shadow: 0 0 10px rgba(212, 169, 74, 0.4);
}

.stepper-item.completed {
    color: var(--text-muted);
}

.stepper-item.completed .step-num {
    background: var(--gold-soft);
    border-color: var(--gold-line);
    color: var(--gold);
}

/* ===================== 主內容與面板 ===================== */
.app-main {
    flex: 1;
    padding: 22px 28px;
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--gold-line);
    border-radius: var(--radius);
    padding: 20px 22px;
    margin-bottom: 18px;
}

.panel.narrow {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
}

.panel-title {
    font-family: var(--font-serif);
    color: var(--gold-bright);
    font-size: 1.25rem;
    letter-spacing: 2px;
    margin-bottom: 10px;
}

.tip-msg {
    background: var(--gold-soft);
    border-left: 3px solid var(--gold);
    color: var(--text);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.88rem;
    margin-bottom: 16px;
}

/* 淺色紙面（報告、PDF、大限卡片）裡的提示與按鈕，改用深色字 */
.pdf-container .tip-msg {
    color: #2b2620;
}

.daxian-year-card .btn-secondary {
    color: #7a5a1a;
    border-color: #b8862a;
}

.field-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 6px;
    line-height: 1.4;
}

/* 服務聲明條款區塊 */
.disclaimer-content {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 18px;
    max-height: 380px;
    overflow-y: auto;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.disclaimer-content h3 {
    color: var(--gold-bright);
    font-size: 0.98rem;
    margin: 12px 0 6px;
}

.disclaimer-content h3:first-child {
    margin-top: 0;
}

.disclaimer-content p {
    margin-bottom: 8px;
    line-height: 1.6;
}

.disclaimer-agree-box {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    padding-top: 10px;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text);
}

.panel-footer-link {
    margin-top: 16px;
    text-align: center;
}

/* ===================== Toast & Inline 提示條 ===================== */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90%;
    max-width: 480px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 0.92rem;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    animation: slideDown 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

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

.toast-success { background: var(--color-success); }
.toast-info    { background: var(--color-info); }
.toast-warn    { background: var(--color-warn); color: #1a1408; }
.toast-error   { background: var(--color-error); }

.toast-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 4px;
    margin-left: 12px;
    line-height: 1;
}

.inline-msg {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.88rem;
    margin-bottom: 14px;
    border-left: 4px solid;
}

.inline-msg-success { background: rgba(67, 160, 71, 0.15); border-color: var(--color-success); color: #81c784; }
.inline-msg-info    { background: rgba(30, 136, 229, 0.15); border-color: var(--color-info); color: #64b5f6; }
.inline-msg-warn    { background: rgba(251, 140, 0, 0.15); border-color: var(--color-warn); color: #ffb74d; }
.inline-msg-error   { background: rgba(229, 57, 53, 0.15); border-color: var(--color-error); color: #e57373; }

/* 三-2 修正：補上 .inline-msg a 與 .text-dim 規則 */
.inline-msg a { color: var(--gold-bright); }
.text-dim { color: var(--text-dim); }

/* ===================== 自製 Confirm Modal 彈窗 ===================== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 9900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-box {
    background: var(--panel-bg);
    border: 1.5px solid var(--gold);
    border-radius: 14px;
    width: 100%;
    max-width: 500px;
    padding: 22px 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.modal-box.modal-lg {
    max-width: 720px;
}

.modal-title {
    font-family: var(--font-serif);
    color: var(--gold-bright);
    font-size: 1.2rem;
    margin-bottom: 12px;
}

.modal-body {
    font-size: 0.92rem;
    color: var(--text);
    margin-bottom: 20px;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* ===================== 方案選擇區 ===================== */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

body.view-full .plans-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.plan-card:hover {
    border-color: var(--gold-line);
    background: var(--card-hover);
    transform: translateY(-2px);
}

.plan-card.selected {
    border-color: var(--gold);
    background: linear-gradient(180deg, rgba(212, 169, 74, 0.16), rgba(212, 169, 74, 0.05));
    box-shadow: 0 0 14px rgba(212, 169, 74, 0.18);
}

.plan-card.is-disabled-included {
    cursor: not-allowed;
    opacity: 0.45;
    background: var(--card-bg);
    border-color: rgba(255, 255, 255, 0.05);
}

.plan-card.is-disabled-included:hover {
    transform: none;
    background: var(--card-bg);
    border-color: rgba(255, 255, 255, 0.05);
}

.badge-included {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 0.7rem;
    color: var(--gold-bright);
    background: var(--gold-soft);
    border: 1px solid var(--gold-line);
    border-radius: 4px;
    padding: 1px 6px;
}

.plan-header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 6px;
}

.plan-header input[type="checkbox"] {
    margin-top: 4px;
    accent-color: var(--gold);
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    cursor: pointer;
}

.plan-header label {
    cursor: pointer;
    font-size: 0.98rem;
    color: var(--text);
    margin-bottom: 0;
    line-height: 1.4;
}

.plan-desc {
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.5;
    flex: 1;
    margin-bottom: 8px;
}

.plan-price {
    color: var(--accent);
    font-weight: 700;
    font-size: 1.05rem;
    text-align: right;
}

.plan-card.coming-soon {
    cursor: not-allowed;
    opacity: 0.5;
    filter: grayscale(0.6);
    border-style: dashed;
}

.plan-card.coming-soon:hover {
    transform: none;
    background: var(--card-bg);
    border-color: rgba(255, 255, 255, 0.07);
}

.badge-soon {
    align-self: flex-start;
    margin-bottom: 6px;
    font-size: 0.7rem;
    color: var(--gold-bright);
    border: 1px solid var(--gold-line);
    border-radius: 999px;
    padding: 1px 8px;
    letter-spacing: 1px;
}

/* ===================== 結帳與報價明細 ===================== */
.checkout-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: start;
    border-top: 1px solid var(--gold-line);
    padding-top: 18px;
}

.repurchase-section h3 {
    font-size: 0.92rem;
    color: var(--gold-bright);
    font-weight: 500;
    margin-bottom: 8px;
}

.checkout-summary-box {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 14px 16px;
}

.quote-items-detail {
    margin-bottom: 12px;
    font-size: 0.88rem;
    border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
    padding-bottom: 10px;
}

.quote-item-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.quote-item-row.discount-row {
    color: #81c784;
}

.price-summary {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.price-summary p {
    color: var(--text-muted);
    white-space: nowrap;
}

.price-summary .price {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--gold-bright);
}

.price-summary .original-price-strike {
    text-decoration: line-through;
    color: var(--text-dim);
    font-size: 1.1rem;
    margin-right: 8px;
}

/* ===================== 表單元件 ===================== */
.form-group {
    margin-bottom: 14px;
}

.form-group.inline {
    display: flex;
    gap: 12px;
}

.form-group.inline > div,
.form-group.inline > input,
.form-group.inline > select {
    flex: 1;
    min-width: 0;
}

.form-group-3col {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.92rem;
    color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    padding: 9px 12px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    outline: none;
}

input::placeholder {
    color: var(--text-dim);
}

input:focus,
select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(212, 169, 74, 0.2);
}

select option {
    background: var(--panel-bg);
    color: var(--text);
}

.radio-group {
    display: flex;
    gap: 20px;
}

.radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

input[type="radio"],
input[type="checkbox"] {
    accent-color: var(--gold);
}

/* ===================== 按鈕 ===================== */
.btn-primary {
    background: linear-gradient(135deg, #e0b452, #b8862a);
    color: #1a1408;
    border: none;
    padding: 11px 24px;
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font-sans);
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: filter 0.2s, box-shadow 0.2s;
}

.btn-primary:hover {
    filter: brightness(1.08);
    box-shadow: 0 0 16px rgba(212, 169, 74, 0.35);
}

.btn-primary:disabled {
    background: #4a4f57;
    color: #9aa0a6;
    box-shadow: none;
    cursor: not-allowed;
    filter: none;
}

.btn-block {
    width: 100%;
}

.btn-secondary {
    background: transparent;
    color: var(--gold-bright);
    border: 1px solid var(--gold);
    padding: 8px 16px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-secondary:hover {
    background: var(--gold-soft);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.82rem;
}

.btn-link {
    background: transparent;
    border: none;
    color: var(--gold);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.88rem;
}

.btn-link:hover {
    color: var(--gold-bright);
}

/* ===================== Loading 轉圈 ===================== */
.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-bottom-color: var(--gold);
    border-radius: 50%;
    animation: rotation 1s linear infinite;
    margin-bottom: 16px;
}

@keyframes rotation {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.polling-status-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 10px;
}

.timer-display {
    font-size: 1.1rem;
    color: var(--gold-bright);
    margin: 10px 0;
}

.warning-text {
    color: #e57373;
    font-weight: 500;
    font-size: 0.9rem;
}

/* ===================== 預覽與摘要顯示 ===================== */
.summary-display-box {
    background: var(--gold-soft);
    border: 1px solid var(--gold-line);
    border-radius: 8px;
    padding: 14px 18px;
    text-align: center;
    margin-bottom: 18px;
}

.summary-str {
    font-family: var(--font-serif);
    color: var(--gold-bright);
    font-size: 1.25rem;
}

.confirm-actions-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 20px;
}

/* ===================== 保存工具列 ===================== */
.result-notice-bar {
    background: rgba(251, 140, 0, 0.2);
    border: 1px solid var(--gold);
    color: var(--gold-bright);
    padding: 10px 16px;
    border-radius: 8px;
    text-align: center;
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 16px;
}

.save-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    background: var(--card-bg);
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* ===================== 結果與 PDF（淺色紙面，方便閱讀） ===================== */
.pdf-container {
    background: #fbf8f1;
    color: #2b2620;
    padding: 28px;
    border: 1px solid var(--gold);
    border-radius: 8px;
}

.pdf-header {
    text-align: center;
    border-bottom: 2px solid #b8862a;
    padding-bottom: 12px;
    margin-bottom: 20px;
}

.pdf-header h1 {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    color: #7a5a1a;
}

.pdf-sub {
    color: #7d746a;
    letter-spacing: 3px;
    font-size: 0.9rem;
}

.pdf-date {
    font-size: 0.82rem;
    color: #8a8070;
    margin-top: 4px;
}

.astrolabe-basics {
    background: #f3eddf;
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.astrolabe-basics h3 {
    color: #7a5a1a;
    font-size: 1rem;
}

.basics-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 16px;
    margin-top: 8px;
}

.basic-item {
    font-size: 0.88rem;
    color: #2b2620;
}

.basic-item strong {
    color: #7a5a1a;
}

/* Markdown 樣式與表格 */
.markdown-body {
    line-height: 1.85;
    color: #2b2620;
}

.markdown-body h2 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    color: #7a5a1a;
    margin-top: 20px;
    margin-bottom: 10px;
    border-bottom: 1px solid #e3d6b8;
    padding-bottom: 4px;
}

.markdown-body h3 {
    font-size: 1.08rem;
    color: #8a6420;
    margin-top: 14px;
    margin-bottom: 6px;
}

.markdown-body h4 {
    font-size: 0.98rem;
    color: #8a6420;
    margin-top: 10px;
    margin-bottom: 4px;
}

.markdown-body p {
    margin-bottom: 12px;
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 12px;
    padding-left: 24px;
}

.markdown-body li {
    margin-bottom: 4px;
}

.markdown-body hr {
    border: none;
    border-top: 1px dashed #e3d6b8;
    margin: 18px 0;
}

.md-table-wrap {
    overflow-x: auto;
    margin-bottom: 16px;
}

.md-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.88rem;
}

.md-table th,
.md-table td {
    border: 1px solid #e3d6b8;
    padding: 8px 12px;
    text-align: left;
}

.md-table th {
    background: #f3eddf;
    color: #7a5a1a;
    font-weight: 700;
}

.repurchase-box {
    margin-top: 28px;
    padding: 16px;
    background: #fdf1d4;
    border: 1px solid #e8c97a;
    border-radius: 8px;
    page-break-inside: avoid;
}

.repurchase-box h3 {
    color: #7a5a1a;
    margin-bottom: 6px;
}

.repurchase-desc {
    font-size: 0.85rem;
    color: #6e5a1a;
    margin-bottom: 8px;
}

.repurchase-box .code-display {
    font-size: 1.05rem;
    font-weight: 700;
    color: #7a4a10;
    margin-top: 4px;
}

.pdf-footer {
    margin-top: 28px;
    text-align: center;
    font-size: 0.8rem;
    color: #7d746a;
    border-top: 1px solid #e3d6b8;
    padding-top: 12px;
}

.pdf-footer .credit {
    margin: 2px 0;
}

/* ===================== 命盤圖 CSS（合併後標準定義） ===================== */
.chart-wrap {
    margin-bottom: 22px;
    page-break-inside: avoid;
}

.pdf-render .chart-wrap {
    margin-bottom: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
}

.pdf-render .chart-wrap + * {
    page-break-before: always !important;
    break-before: page !important;
}

.chart-title {
    color: #7a5a1a;
    margin-bottom: 8px;
    font-size: 1.05rem;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 3px;
    background: #b8862a;
    border: 2px solid #b8862a;
    border-radius: 6px;
    overflow: hidden;
}

.cg-palace {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 172px;
    padding: 6px 7px;
    background: #fbf8f1;
}

.cg-palace.is-soul {
    background: #f6e7c4;
}

.cg-palace.is-body {
    box-shadow: inset 0 0 0 2px #4f8a7a;
}

.cg-stars {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 5px;
}

.cg-stars .star {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.12;
}

.cg-stars .st-major + .star:not(.st-major) {
    margin-left: 6px;
}

.cg-stars .st-major { font-size: 1.22rem; font-weight: 700; color: #a3261c; }
.cg-stars .st-lucky { font-size: 0.98rem; font-weight: 500; color: #1d5f8a; }
.cg-stars .st-sha   { font-size: 0.98rem; font-weight: 500; color: #5a5a5a; }
.cg-stars .st-peach { font-size: 0.84rem; color: #b0477a; }
.cg-stars .st-aux   { font-size: 0.8rem;  color: #6e5a8a; }
.cg-stars .st-empty { font-size: 0.95rem; color: #8a8070; }

.cg-stars .st-hua {
    margin: 3px 0 0;
    padding: 1px 3px;
    font-size: 0.68rem;
    line-height: 1.3;
    color: #fff;
    background: #b8862a;
    border-radius: 3px;
}

.cg-stars-low {
    margin-top: auto;
    padding-top: 6px;
}

.cg-stars-low:empty {
    display: none;
}

.cg-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 4px;
    margin-top: 6px;
    padding-top: 4px;
    border-top: 1px dashed #e3d6b8;
    font-size: 0.75rem;
    color: #7d746a;
}

.cg-name {
    font-weight: 700;
    color: #2b2620;
    font-size: 0.85rem;
    white-space: nowrap;
}

.cg-stembranch {
    font-weight: 700;
    color: #7a5a1a;
}

.cg-tag {
    display: inline-block;
    margin-left: 3px;
    padding: 0 4px;
    font-size: 0.68rem;
    color: #fff;
    border-radius: 3px;
    vertical-align: 1px;
}

.tag-soul { background: #a3261c; }
.tag-body { background: #4f8a7a; }

.cg-center {
    grid-column: 2 / 4;
    grid-row: 2 / 4;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: #f3eddf;
    text-align: center;
}

/* 標題：跟十四主星一樣大 */
.cg-center-title {
    font-family: var(--font-serif);
    font-size: 1.22rem;
    font-weight: 700;
    color: #7a5a1a;
    letter-spacing: 4px;
}

/* 中間資訊：直式，由右至左，放不下時自動換到下一排 */
.cg-center-meta {
    display: flex;
    flex-direction: row-reverse;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 10px 7px;
    color: #2b2620;
}

.cg-vitem {
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    gap: 3px;
}

.cg-vcol {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 每個字一格：大小跟六吉星一樣 */
.cg-vcol .vc {
    display: block;
    font-size: 0.98rem;
    line-height: 1.15;
    text-align: center;
    white-space: nowrap;
}

.cg-vcol .vc-label { color: #7a5a1a; font-weight: 700; }
.cg-vcol .vc-value { color: #2b2620; font-weight: 500; }
.cg-vcol .vc-gap   { display: block; height: 0.35em; }

.cg-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 10px;
    font-size: 0.75rem;
}

/* ===================== HTML2PDF 導出隱藏容器 ===================== */

/* 外層 host：只負責隱藏在視窗外 */
.pdf-render-host {
    position: fixed !important;
    left: -10000px !important;
    top: 0 !important;
    z-index: -1 !important;
}

/* 內層 pdf-render：只負責 718px 寬度與導出標準樣式 */
.pdf-render {
    width: 718px !important;
    background: #fbf8f1 !important;
    color: #2b2620 !important;
    padding: 24px !important;
    box-sizing: border-box !important;
}

/* pdf-render 內部的電腦版排版與數值覆寫 (三-1 修正) */
.pdf-render .chart-grid { gap: 3px !important; }
.pdf-render .cg-palace { min-height: 148px !important; padding: 6px 7px !important; }
.pdf-render .markdown-body p,
.pdf-render .markdown-body li,
.pdf-render .md-table tr,
.pdf-render .markdown-body h2,
.pdf-render .markdown-body h3,
.pdf-render .markdown-body h4,
.pdf-render .repurchase-box,
.pdf-render .pdf-footer,
.pdf-render .daxian-year-card { page-break-inside: avoid !important; break-inside: avoid !important; }
.pdf-render .cg-stars { gap: 8px 5px !important; }
.pdf-render .cg-stars .st-major { font-size: 1.22rem !important; }
.pdf-render .cg-stars .st-lucky { font-size: 0.98rem !important; }
.pdf-render .cg-stars .st-sha   { font-size: 0.98rem !important; }
.pdf-render .cg-stars .st-peach { font-size: 0.84rem !important; }
.pdf-render .cg-stars .st-aux   { font-size: 0.8rem !important; }
.pdf-render .cg-stars .st-empty { font-size: 0.95rem !important; }

/* 三-1：.st-hua 補上 padding 與 margin */
.pdf-render .cg-stars .st-hua   { font-size: 0.68rem !important; padding: 1px 3px !important; margin: 3px 0 0 !important; }

.pdf-render .cg-stars .st-major + .star:not(.st-major) { margin-left: 6px !important; }
.pdf-render .cg-bottom { font-size: 0.75rem !important; flex-wrap: nowrap !important; }
.pdf-render .cg-name { font-size: 0.85rem !important; }

/* 三-1：.cg-tag 補上 padding */
.pdf-render .cg-tag { font-size: 0.68rem !important; padding: 0 4px !important; }

.pdf-render .cg-center { padding: 8px !important; gap: 5px !important; }

/* 三-1：.cg-center-title 補上 letter-spacing */
.pdf-render .cg-center-title { font-size: 1.22rem !important; letter-spacing: 4px !important; }

/* 中間直式資訊區：PDF 一律用電腦版數值 */
.pdf-render .cg-center-meta { gap: 6px 5px !important; }
.pdf-render .cg-vitem { gap: 2px !important; }
.pdf-render .cg-vcol .vc { font-size: 0.78rem !important; line-height: 1.05 !important; }
.pdf-render .cg-legend { font-size: 0.75rem !important; }
.pdf-render .basics-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }

/* ===================== 大限 ===================== */
.daxian-progress {
    color: var(--text-muted);
    margin-bottom: 14px;
}

.daxian-year-card {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid #e3d6b8;
    border-radius: 8px;
    page-break-inside: avoid;
}

.daxian-year-card h3 {
    color: #7a5a1a;
    font-size: 1.15rem;
    margin-bottom: 10px;
}

.daxian-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 18px;
}

.daxian-controls .tip-msg {
    margin-bottom: 0;
}

/* ===================== 店主頁面 (Admin) ===================== */
.admin-actions-row {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 16px;
}

.reissue-confirm-box {
    margin-top: 16px;
    padding: 14px;
    background: rgba(229, 57, 53, 0.1);
    border: 1px solid var(--color-error);
    border-radius: 8px;
}

.reissue-confirm-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

.admin-table th,
.admin-table td {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.1);
}

.admin-table th {
    background: var(--card-bg);
    color: var(--gold-bright);
}

.badge-success { background: var(--color-success); color: #fff; padding: 2px 6px; border-radius: 4px; font-size: 0.78rem; }
.badge-warn    { background: var(--color-warn); color: #1a1408; padding: 2px 6px; border-radius: 4px; font-size: 0.78rem; }

/* ===================== 頁尾 ===================== */
.app-footer {
    border-top: 1px solid var(--gold-line);
    padding: 14px 20px;
    text-align: center;
    font-family: var(--font-serif);
    color: var(--text);
    letter-spacing: 1px;
    font-size: 0.95rem;
    background: rgba(0, 0, 0, 0.25);
}

/* ===================== 手機版（≤768px 自動排版，無溢出） ===================== */
@media (max-width: 768px) {
    body.view-window,
    body.view-full {
        padding: 0;
    }

    body.view-window .app-frame,
    body.view-full .app-frame {
        max-width: none;
        width: 100%;
        min-height: 100vh;
        margin: 0;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    .view-switch {
        display: none;
    }

    .app-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 14px;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
    }

    .brand-main {
        font-size: 1.5rem;
        letter-spacing: 4px;
    }

    .brand-sub {
        font-size: 0.8rem;
        letter-spacing: 2px;
    }

    .stepper-bar {
        padding: 10px 12px;
    }

    .stepper-item .step-label {
        display: none;
    }

    .stepper-item.active .step-label {
        display: inline;
        font-size: 0.85rem;
    }

    .app-main {
        padding: 12px 10px;
    }

    .panel {
        padding: 14px 12px;
    }

    .plans-grid,
    body.view-full .plans-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .checkout-row {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .price-summary {
        align-items: stretch;
    }

    .form-group.inline {
        flex-direction: column;
        gap: 10px;
    }

    .form-group-3col {
        grid-template-columns: 1fr;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
    }

    .save-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .basics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .modal-box {
        width: 92vw;
        padding: 18px;
    }

    .toast-container {
        width: 96vw;
    }

    /* 手機版命盤圖細節 */
    .chart-grid { gap: 2px; }
    .cg-palace { min-height: 132px; padding: 4px; }
    .cg-stars { gap: 4px 2px; }
    .cg-stars .st-major + .star:not(.st-major) { margin-left: 3px; }
    .cg-stars .st-major { font-size: 0.82rem; }
    .cg-stars .st-lucky,
    .cg-stars .st-sha   { font-size: 0.68rem; }
    .cg-stars .st-peach,
    .cg-stars .st-aux   { font-size: 0.58rem; }
    .cg-stars .st-empty { font-size: 0.66rem; }
    .cg-stars .st-hua   { font-size: 0.5rem; padding: 0 1px; margin-top: 2px; }
    .cg-bottom { flex-wrap: wrap; font-size: 0.58rem; }
    .cg-name { font-size: 0.64rem; }
    .cg-tag { font-size: 0.55rem; padding: 0 2px; }
    .cg-center { padding: 6px; gap: 4px; }
    .cg-center-title { font-size: 0.82rem; letter-spacing: 2px; }
    .cg-center-meta { gap: 6px 3px; }
    .cg-vitem { gap: 1px; }
    .cg-vcol .vc { font-size: 0.68rem; line-height: 1.12; }
    .cg-legend { font-size: 0.58rem; }
}

@media (max-width: 360px) {
    .plans-grid {
        grid-template-columns: 1fr;
    }
    .basics-grid {
        grid-template-columns: 1fr;
    }
}

/* ===================== 手機版優化 v2（追加段：只作用於畫面，不影響 PDF 與電腦版） ===================== */

/* 命盤中央區自己指定深色字（預覽頁在深色面板上，圖例原本會繼承到淺色字而看不清） */
.cg-center { color: #2b2620; }

@media (max-width: 768px) {
    .app-main { padding: 10px 6px; }
    .app-main .panel { padding: 12px 8px; }
    .app-main .panel-title { font-size: 1.1rem; letter-spacing: 1px; }
    .app-main .tip-msg { font-size: 0.8rem; padding: 6px 8px; }
    .app-main .result-notice-bar { font-size: 0.8rem; padding: 8px 10px; }
    .app-footer p { font-size: 0.75rem; letter-spacing: 0; }

    /* 方案卡 */
    .app-main .plan-card { padding: 10px 8px; }
    .app-main .plan-header { gap: 6px; }
    .app-main .plan-header label { font-size: 0.85rem; line-height: 1.35; }
    .app-main .plan-desc { font-size: 0.72rem; line-height: 1.45; }
    .app-main .plan-price { font-size: 0.95rem; }

    /* 報告紙面 */
    .app-main .pdf-container { padding: 14px 10px; }
    .app-main .pdf-header h1 { font-size: 1.15rem; letter-spacing: 0; }
    .app-main .pdf-sub { font-size: 0.78rem; letter-spacing: 2px; }
    .app-main .pdf-date { font-size: 0.74rem; }
    .app-main .astrolabe-basics { padding: 10px; }
    .app-main .astrolabe-basics h3 { font-size: 0.92rem; }
    .app-main .basic-item { font-size: 0.8rem; }
    .app-main .basics-grid .basic-item:last-child { grid-column: 1 / -1; }
    .app-main .chart-title { font-size: 0.95rem; }

    /* 解析內文 */
    .app-main .markdown-body { font-size: 0.9rem; line-height: 1.7; }
    .app-main .markdown-body h2 { font-size: 1.1rem; margin-top: 16px; }
    .app-main .markdown-body h3 { font-size: 0.98rem; }
    .app-main .markdown-body h4 { font-size: 0.92rem; }
    .app-main .markdown-body ul,
    .app-main .markdown-body ol { padding-left: 20px; }
    .app-main .markdown-body p,
    .app-main .markdown-body li,
    .app-main .markdown-body h2,
    .app-main .markdown-body h3,
    .app-main .markdown-body h4 { overflow-wrap: anywhere; }

    /* 表格 */
    .app-main .md-table { font-size: 0.78rem; }
    .app-main .md-table th,
    .app-main .md-table td { padding: 5px 6px; }
    .app-main .md-table th,
    .app-main .md-table td:first-child { white-space: nowrap; }

    /* 大限 */
    .app-main .daxian-progress { font-size: 0.85rem; }
    .app-main .daxian-year-card { padding: 10px 8px; margin-top: 14px; }
    .app-main .daxian-year-card h3 { font-size: 1rem; }

    /* 回購區與頁尾 */
    .app-main .repurchase-box { padding: 12px 10px; }
    .app-main .repurchase-desc { font-size: 0.78rem; }
    .app-main .code-display { font-size: 0.88rem; overflow-wrap: anywhere; }
    .app-main .pdf-footer { font-size: 0.72rem; }
}
