:root {
    --primary-color: #8b0000;
    --bg-color: #fcf8f2;
    --text-color: #333;
    --highlight: #d4af37;
    --secondary-btn: #555;
    --link-color: #d2691e;
    --coin-border: #5c4300;
}
body {
    font-family: "KaiTi", "楷体", "STKaiti", serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    text-align: center;
    padding: 15px;
    margin: 0;
    -webkit-text-size-adjust: 100%;
}
button, a { -webkit-tap-highlight-color: transparent; user-select: none; }
h1 { color: var(--primary-color); letter-spacing: 2px; margin-bottom: 5px; font-size: 1.6em; }

/* 欢迎页 */
#welcome-screen {
    max-width: 600px; margin: 20px auto; background: #fff;
    padding: 30px 20px; border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
    border-top: 5px solid var(--primary-color);
    line-height: 1.6; font-size: 1.05em; text-align: left;
}
#welcome-screen h2 { text-align: center; color: var(--primary-color); margin-top: 0; font-size: 1.4em; }
.instruction-list { background: #fffaf0; padding: 15px 15px 15px 20px; border-radius: 8px; margin: 15px 0; border: 1px solid #f5deb3; }

/* 模式选择 */
.mode-select { display: flex; flex-direction: column; gap: 14px; margin-top: 20px; }
.mode-btn {
    position: relative; background: #fff; border: 2px solid #d0b090;
    color: var(--text-color); padding: 18px 16px 14px; border-radius: 14px;
    cursor: pointer; font-family: inherit; text-align: center; transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.mode-btn:active { transform: scale(0.98); box-shadow: 0 1px 4px rgba(0,0,0,0.1); }
.mode-btn-primary {
    background: linear-gradient(135deg, #fff8ee, #fff3e0);
    border: 2.5px solid var(--primary-color);
    box-shadow: 0 4px 14px rgba(139,0,0,0.15);
}
.mode-tag {
    position: absolute; top: -1px; right: 14px;
    background: var(--primary-color); color: #fff;
    font-size: 0.72em; padding: 2px 8px; border-radius: 0 0 6px 6px;
    letter-spacing: 1px; font-weight: bold;
}
.mode-icon { font-size: 1.6em; display: block; margin-bottom: 6px; }
.mode-btn .mode-title {
    font-weight: bold; font-size: 1.1em; display: block;
    margin-bottom: 6px; color: var(--primary-color);
}
.mode-btn .mode-desc { font-size: 0.85em; color: #777; display: block; line-height: 1.6; }
.mode-cta {
    display: inline-block; margin-top: 10px;
    font-size: 0.88em; font-weight: bold;
    color: var(--primary-color); letter-spacing: 1px;
}

/* 主舞台 */
#game-board { display: flex; flex-direction: column; align-items: center; animation: fadeIn 0.5s ease-out; }
.intro { font-size: 1rem; color: #666; margin-bottom: 15px; padding: 0 10px; }

/* 线下输入区 */
#input-area {
    background-color: white; padding: 20px 15px; border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); margin-bottom: 20px;
    width: 100%; max-width: 580px; box-sizing: border-box;
}
.toss-counter { font-size: 1.1em; margin-bottom: 15px; color: #555; }
.toss-counter span { color: var(--primary-color); font-size: 1.4em; font-weight: bold; }
.input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.record-btn {
    background-color: #f9f9f9; color: var(--text-color); border: 2px solid #e0e0e0;
    padding: 12px 10px; border-radius: 10px; cursor: pointer; transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05); display: flex; flex-direction: column; align-items: center;
}
.record-btn:active { background-color: #fffaf0; border-color: var(--highlight); transform: scale(0.98); }
.record-btn b { color: var(--primary-color); font-size: 1.05em; margin-bottom: 5px; }
.record-btn .yao-desc { font-size: 0.85em; color: #666; font-family: monospace; }

.mini-coins-wrap { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; pointer-events: none; }
.mini-coin {
    width: 42px; height: 42px; border-radius: 50%;
    overflow: hidden; box-shadow: 0 2px 5px rgba(0,0,0,0.35); flex-shrink: 0;
}
.mini-coin img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mini-coin img.yang-face { object-position: 100% center; }
.mini-coin img.yin-face  { object-position: 0% center; }

/* 线上虚拟区 */
#online-input {
    display: none; background-color: white; padding: 20px 15px; border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05); margin-bottom: 20px;
    width: 100%; max-width: 580px; box-sizing: border-box;
}
.coins-3d-container { display: flex; gap: 20px; justify-content: center; margin: 22px 0 16px; }
.coin-item { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 82px; }
.coin-wrap { width: 82px; height: 82px; flex-shrink: 0; }
.coin-display {
    width: 82px; height: 82px;
    border-radius: 50%; overflow: hidden;
    box-shadow: 0 3px 8px rgba(0,0,0,0.4);
}
.coin-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.coin-img.yang-face { object-position: 100% center; }
.coin-img.yin-face  { object-position: 0% center; }
.coin-face-label {
    font-size: 0.9em; color: #aaa; min-height: 22px;
    padding: 2px 0; text-align: center; width: 100%; display: block;
}
.coin-face-label.yang { color: var(--primary-color); font-weight: bold; }
.coin-face-label.yin  { color: #555; font-weight: bold; }

@keyframes coinFlip {
    0%   { transform: scaleX(1); }
    12%  { transform: scaleX(0); }
    25%  { transform: scaleX(1); }
    37%  { transform: scaleX(0); }
    50%  { transform: scaleX(1); }
    62%  { transform: scaleX(0); }
    75%  { transform: scaleX(1); }
    87%  { transform: scaleX(0); }
    100% { transform: scaleX(1); }
}
.coin-flipping { animation: coinFlip 1.1s ease-in-out forwards; }

#online-result-display {
    display: none; padding: 10px 15px; background: #fffaf0;
    border-radius: 8px; border: 1px solid #f5deb3; margin: 10px 0 5px; font-size: 0.95em; color: #555;
}
#record-online-btn { display: none; background-color: #2e6b30; margin-top: 8px; }
#record-online-btn:active { background-color: #1b4d1c; }

/* 公共按钮 */
.btn-group { display: flex; gap: 15px; justify-content: center; margin-bottom: 20px; margin-top: 10px; }
.main-action-btn {
    background-color: var(--primary-color); color: white; border: none;
    padding: 12px 25px; font-size: 1.1em; font-family: inherit;
    border-radius: 25px; cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    transition: all 0.2s; font-weight: bold;
}
.main-action-btn:active { background-color: #a00000; transform: scale(0.96); box-shadow: 0 2px 3px rgba(0,0,0,0.2); }
#generate-btn { display: none; }
#reset-btn { background-color: var(--secondary-btn); display: none; }
#reset-btn:active { background-color: #333; }

/* 卦象展示 */
.gua-display-area { display: flex; gap: 50px; justify-content: center; margin: 10px 0; min-height: 140px; }
.gua-col { display: flex; flex-direction: column; align-items: center; }
.gua-title { font-size: 1.3em; font-weight: bold; color: var(--primary-color); margin-bottom: 5px; }
.bagua-desc { font-size: 0.85em; color: #666; margin-bottom: 12px; }
.hexagram { display: flex; flex-direction: column-reverse; gap: 6px; width: 80px; }
.yao { height: 12px; display: flex; align-items: center; justify-content: center; position: relative; animation: fadeIn 0.4s forwards; }
.yao .yang { width: 100%; background-color: var(--text-color); height: 100%; border-radius: 2px; }
.yao .yin { width: 100%; display: flex; justify-content: space-between; height: 100%; }
.yao .yin div { width: 44%; background-color: var(--text-color); height: 100%; border-radius: 2px; }
.changing-mark { position: absolute; right: -22px; font-size: 12px; color: var(--primary-color); font-weight: bold; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* 解卦结果 */
#result-board {
    display: none; background-color: white; padding: 25px 15px; border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.1); max-width: 600px; margin: 20px auto;
    text-align: center; border-top: 5px solid var(--primary-color);
    animation: fadeIn 0.6s ease-out; box-sizing: border-box;
}
.result-main { font-size: 1.25em; font-weight: bold; color: #333; margin: 20px 0; line-height: 1.6; }
.result-highlight { color: var(--primary-color); font-size: 1.2em; display: inline-block; margin-top: 15px; padding: 10px 20px; background: #fff5e6; border-radius: 8px; border: 1px solid #f5deb3; }
.sub-info { font-size: 0.9em; color: #888; margin-top: 15px; margin-bottom: 20px; }
.reading-guide {
    text-align: left; background: #f9f9f9; padding: 15px; border-radius: 8px;
    border-left: 4px solid var(--highlight); font-size: 0.9em; line-height: 1.6;
    color: #444; border-top: 1px dashed #ddd;
}
.reading-guide h4 { color: var(--primary-color); margin-top: 0; font-size: 1.05em; margin-bottom: 8px; }
.reading-guide ul { padding-left: 18px; margin: 0 0 10px 0; }
.reading-guide li { margin-bottom: 6px; }
.baike-link {
    color: var(--link-color); text-decoration: underline; text-decoration-style: dashed;
    font-weight: bold; transition: color 0.2s; cursor: pointer; padding: 2px 5px;
}
.baike-link:active { color: var(--primary-color); background-color: rgba(210,105,30,0.1); border-radius: 4px; }

/* AI 解卦区域 */
.ai-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px dashed #f0dfc0;
    text-align: center;
}
.ai-btn {
    background: linear-gradient(135deg, #1a6b3c, #2e8b57);
    color: white; border: none;
    padding: 11px 28px; font-size: 1.05em; font-family: inherit;
    border-radius: 25px; cursor: pointer;
    box-shadow: 0 3px 8px rgba(46,139,87,0.35);
    transition: all 0.2s; font-weight: bold; letter-spacing: 1px;
}
.ai-btn:active { background: linear-gradient(135deg, #145530, #236b43); transform: scale(0.96); }
.ai-btn:disabled { opacity: 0.65; cursor: not-allowed; transform: none; }
.ai-result {
    margin-top: 14px;
    padding: 15px 18px;
    background: #f4fbf7;
    border-radius: 10px;
    border-left: 4px solid #2e8b57;
    text-align: left;
    font-size: 0.95em;
    line-height: 1.9;
    color: #333;
    white-space: pre-wrap;
    word-break: break-all;
    min-height: 40px;
}

/* 保存按钮 */
.save-section {
    margin-top: 12px;
    text-align: center;
}
.save-btn {
    background: #fff; color: var(--primary-color);
    border: 2px solid var(--primary-color);
    padding: 10px 26px; font-size: 1em; font-family: inherit;
    border-radius: 25px; cursor: pointer;
    transition: all 0.2s; font-weight: bold;
}
.save-btn:active { background: var(--primary-color); color: #fff; transform: scale(0.96); }
.save-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* 长图卡片（隐藏，供 html2canvas 渲染） */
#save-card {
    display: none;
    position: fixed; left: -9999px; top: 0;
    width: 390px;
    background: #fcf8f2;
    font-family: "KaiTi", "楷体", "STKaiti", serif;
    color: #333;
    border-top: 6px solid var(--primary-color);
    padding: 0 0 20px;
    box-sizing: border-box;
}
.sc-header {
    text-align: center;
    padding: 20px 20px 14px;
    border-bottom: 1px solid #f0dfc0;
    background: linear-gradient(180deg, #fff8ee 0%, #fcf8f2 100%);
}
.sc-logo { font-size: 1.5em; font-weight: bold; color: var(--primary-color); letter-spacing: 3px; }
.sc-subtitle { font-size: 1em; color: #888; letter-spacing: 2px; margin: 2px 0; }
.sc-date { font-size: 0.8em; color: #aaa; margin-top: 4px; }
.sc-gua-area {
    display: flex; align-items: center; justify-content: center;
    gap: 16px; padding: 20px 20px 10px;
}
.sc-gua-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.sc-gua-name { font-size: 1.05em; font-weight: bold; color: var(--primary-color); text-align: center; }
.sc-gua-sym { font-size: 1.5em; font-weight: normal; margin-left: 4px; }
.sc-gua-sub { font-size: 0.78em; color: #999; }
.sc-arrow { font-size: 1.4em; color: #c8a96e; padding-bottom: 20px; }
.sc-hexagram {
    display: flex; flex-direction: column-reverse;
    gap: 5px; width: 72px;
}
.sc-yao {
    height: 11px; display: flex; align-items: center;
    position: relative;
}
.sc-yang { width: 100%; height: 100%; background: #333; border-radius: 2px; }
.sc-yin { width: 100%; height: 100%; display: flex; justify-content: space-between; }
.sc-yin div { width: 44%; height: 100%; background: #333; border-radius: 2px; }
.sc-mark { position: absolute; right: -18px; font-size: 11px; color: var(--primary-color); font-weight: bold; }
.sc-focus {
    margin: 4px 20px 0;
    padding: 8px 14px;
    background: #fffaf0;
    border: 1px solid #f5deb3;
    border-radius: 8px;
    font-size: 0.88em; color: #666; text-align: center;
}
.sc-divider {
    margin: 16px 20px;
    border: none; border-top: 1px dashed #e0cfa0;
}
.sc-ai-label {
    text-align: center; font-size: 1em; font-weight: bold;
    color: #2e8b57; margin: 0 20px 10px; letter-spacing: 1px;
}
.sc-ai-text {
    margin: 0 20px;
    font-size: 0.9em; line-height: 1.9; color: #333;
    white-space: pre-wrap; word-break: break-all;
    background: #f4fbf7;
    border-left: 3px solid #2e8b57;
    border-radius: 6px;
    padding: 12px 14px;
}
.sc-footer {
    margin-top: 18px;
    text-align: center;
    font-size: 0.75em; color: #bbb; letter-spacing: 1px;
}

/* 响应式 */
@media (max-width: 500px) {
    .input-grid { grid-template-columns: 1fr; }
    .gua-display-area { gap: 30px; }
    .main-action-btn { width: 100%; box-sizing: border-box; }
    .btn-group { flex-direction: column; width: 100%; gap: 10px; padding: 0 15px; box-sizing: border-box; }
    .mode-select { flex-direction: column; }
    .coins-3d-container { gap: 12px; }
}
