:root {
  --bg: #171221;
  --bg2: #211a30;
  --card: #262038;
  --card-edge: #3a3152;
  --text: #f0ebff;
  --muted: #9d93b8;
  --accent: #e8b84b;
  --accent2: #c0392b;
  --jade: #4fd1a5;
  --radius: 14px;
  --font: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --bg-image: radial-gradient(1200px 800px at 50% -100px, #2c2244, var(--bg));
  --btn-text: #241a05;
  --coin-a: #f4d47c; --coin-b: #c9992f; --coin-ring: #b98a2f; --coin-glyph: #5b3d05;
  --coin-a2: #d8b563; --coin-b2: #9a7422; --coin-ring2: #a37c26; --coin-glyph2: #3d2a04;
  --seg: linear-gradient(90deg, #f0e6c8, #d8c48e);
  --seg-off: #6b5f8d;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg-image);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
}

body, .card, .btn-primary, .btn-secondary, .chip, textarea, .modal-box, .coin-inner .face {
  transition: background .35s ease, color .35s ease, border-color .35s ease;
}

body { font-size: 16px; line-height: 1.65; }

/* ---------- 屏幕切换 ---------- */
.screen { display: none; max-width: 560px; margin: 0 auto; padding: 16px 14px 40px; }
.screen.active { display: block; }

.app-header { text-align: center; padding: 18px 0 8px; position: relative; }
.app-header h1 { font-size: 34px; letter-spacing: 10px; margin-left: 10px; color: var(--accent); font-weight: 600; }
.subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.btn-login {
  position: absolute; top: 18px; right: 0;
  background: none; border: 1px solid var(--card-edge); color: var(--muted);
  border-radius: 20px; padding: 5px 12px; font-size: 12px;
}
.btn-login.logged-in { color: var(--jade); border-color: var(--jade); }

/* ---------- 卡片与表单 ---------- */
.card {
  background: var(--card); border: 1px solid var(--card-edge);
  border-radius: var(--radius); padding: 18px 16px; margin-top: 16px;
}
.field-label { font-size: 15px; display: block; margin-bottom: 10px; }
.required { color: var(--accent2); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  background: var(--bg2); border: 1px solid var(--card-edge); color: var(--text);
  border-radius: 18px; padding: 7px 16px; font-size: 14px; min-height: 36px;
}
.chip.selected { border-color: var(--accent); color: var(--accent); }

.input-wrap { position: relative; }
textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--card-edge);
  border-radius: 10px; color: var(--text); font-size: 15px; padding: 12px 12px 26px;
  resize: none; font-family: inherit;
}
textarea:focus { outline: none; border-color: var(--accent); }
#char-count { position: absolute; right: 10px; bottom: 8px; font-size: 12px; color: var(--muted); }

.btn-primary {
  display: block; width: 100%; margin-top: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent));
  color: var(--btn-text); border: none; border-radius: 12px;
  font-size: 17px; font-weight: 600; padding: 14px; letter-spacing: 2px;
  font-family: inherit;
}
.btn-primary .btn-sub {
  display: block; margin-top: 3px;
  font-size: 12px; font-weight: 400; letter-spacing: 1px; opacity: .82;
}
#btn-go-result, #btn-toss {
  width: 90%; margin: 16px auto 0;
}
#btn-go-result {
  letter-spacing: 4px; font-size: 18px;
}
.btn-primary:disabled { opacity: .4; }
.btn-secondary {
  display: block; width: 100%; margin-top: 12px;
  background: var(--accent2);
  color: var(--btn-text); border: none; border-radius: 12px; font-size: 16px; padding: 13px;
  font-family: inherit;
}
.btn-text { background: none; border: none; color: var(--muted); font-size: 14px; padding: 8px; }

/* ---------- 摇卦屏 ---------- */
.toss-top { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; }
#toss-progress { color: var(--accent); font-size: 14px; letter-spacing: 1px; }

.bowl-wrap { perspective: 700px; text-align: center; margin: 8px 0 0; }
.bowl {
  display: flex; justify-content: center; align-items: flex-end; gap: 6%;
  height: 150px; position: relative; z-index: 2;
}
.bowl-shadow {
  width: 80%; height: 14px; margin: -8px auto 0;
  background: radial-gradient(closest-side, rgba(0,0,0,.55), transparent);
}
.coin { width: 74px; height: 74px; }
.coin-inner {
  width: 100%; height: 100%; position: relative; transform-style: preserve-3d;
}
.coin.settled .coin-inner { transform: rotateX(64deg); transition: transform .28s cubic-bezier(.2,.9,.3,1.2); }
.face {
  position: absolute; inset: 0;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
}
.face svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 2px 6px rgba(0,0,0,.45)); }
.coin-char {
  fill: var(--coin-glyph);
  font-family: "STKaiti", "KaiTi", "Noto Serif SC", serif;
  font-size: 15px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central;
}
.face-yin .tg rect { fill: var(--coin-glyph2); }
.face-yin { transform: rotateY(180deg); }

.toss-btns { margin-top: 10px; }
.meditate {
  text-align: center; color: var(--accent); font-size: 15px;
  letter-spacing: 6px; text-indent: 6px; margin: 14px 0 0;
  display: flex; align-items: center; justify-content: center; gap: 12px;
}
.meditate::before, .meditate::after {
  content: ""; width: 34px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent));
  opacity: .5; flex: none;
}
.meditate::after { background: linear-gradient(270deg, transparent, var(--accent)); }
#btn-skip {
  display: block; margin: 12px auto 0; text-decoration: underline;
  text-underline-offset: 5px; font-size: 16px; color: var(--text);
  padding: 12px 24px; min-height: 44px; min-width: 220px;
}

.hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; min-height: 20px; }

/* 六爻自下而上 */
.yao-board { margin-top: 22px; min-height: 300px; }
.yao-list {
  list-style: none; display: flex; flex-direction: column-reverse;
  justify-content: flex-start; gap: 14px; padding: 10px 0;
}
.yao-row { display: flex; align-items: center; gap: 12px; animation: yaoIn .55s cubic-bezier(.2,.8,.3,1.1) both; }
@keyframes yaoIn { from { opacity: 0; transform: translateY(26px) scale(.85); } to { opacity: 1; transform: none; } }
.yao-label { width: 52px; font-size: 13px; color: var(--muted); text-align: right; flex: none; }
.yao-bar { flex: 1; height: 18px; display: flex; gap: 0; }
.yao-bar .seg { background: var(--seg); border-radius: 4px; height: 100%; }
.yao-bar.yin .seg { width: calc(50% - 7px); }
.yao-bar.yin { gap: 14px; }
.yao-bar.yang .seg { width: 100%; }
.yao-mark { width: 30px; flex: none; text-align: center; font-size: 20px; font-weight: 700; }
.mark-o { color: var(--accent); }
.mark-x { color: var(--accent2); }

/* ---------- 结果屏 ---------- */
.result-top { padding-top: 6px; }
.hex-row { display: flex; align-items: center; justify-content: space-around; text-align: center; }
.hex-row > .hex-block { flex: 1; }
.hex-arrow {
  font-size: 26px; color: var(--muted);
  align-self: flex-start; height: 73px;   /* 与卦象符号列等高 */
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0; line-height: 1; padding-top: 6px;  /* 光学补偿：→字形偏上，下移对准三四爻之间 */
}
.hex-block h2 { font-size: 22px; margin-top: 6px; }
.hex-block .accent { color: var(--accent); }
.hex-symbol { display: inline-flex; flex-direction: column; gap: 5px; width: 76px; }
.hex-symbol .seg { height: 8px; background: var(--accent); border-radius: 3px; position: relative; }
.hex-symbol .seg.hl { box-shadow: 0 0 12px var(--accent); }
.hex-symbol .seg.off.hl::before, .hex-symbol .seg.off.hl::after { box-shadow: 0 0 10px var(--accent); }
.duan-badge {
  position: absolute; right: -32px; top: 50%; transform: translateY(-50%);
  background: var(--accent); color: var(--btn-text);
  font-size: 11px; line-height: 1; padding: 3px 6px; border-radius: 9px; font-weight: 600;
}
.hex-symbol.small .duan-badge { display: none; }
.hex-symbol .seg.off { background: transparent; box-shadow: none; position: relative; }
.hex-symbol .seg.off::before, .hex-symbol .seg.off::after {
  content: ""; position: absolute; top: 0; height: 8px; width: 38%;
  background: var(--accent); border-radius: 3px;
}
.hex-symbol .seg.off::before { left: 0; }
.hex-symbol .seg.off::after { right: 0; }
.muted { color: var(--muted); font-size: 13px; }
.yao-lines { margin-top: 14px; display: flex; flex-direction: column-reverse; gap: 8px; }
.yao-lines .yao-row { animation: none; }
.moving-note { margin-top: 12px; color: var(--accent); font-size: 14px; }

.section-title { font-size: 17px; margin-bottom: 10px; color: var(--accent); }
.tag {
  display: inline-flex; align-items: center;
  font-size: 13px; color: var(--muted); font-weight: normal;
  border: 1px solid var(--card-edge); border-radius: 10px;
  padding: 3px 10px; vertical-align: middle; margin-left: 6px;
}
.interpretation { font-size: 15px; white-space: pre-wrap; }
.interpretation h4 { color: var(--jade); font-size: 14px; margin: 12px 0 4px; }
.extra-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--card-edge); }
.extra-chip { font-size: 13px; padding: 8px 14px; min-height: 36px; }
.detail-content {
  max-height: 62vh; overflow-y: auto; margin-top: 12px;
  white-space: pre-wrap; font-size: 14px; line-height: 1.7; color: var(--text);
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.modal-box { overscroll-behavior: contain; }
body.modal-open { overflow: hidden; }
.quota-hint { color: var(--muted); font-size: 12px; margin-top: 8px; text-align: center; }
.ai-btns { display: flex; gap: 10px; }
.ai-btns .btn-secondary { flex: 1; padding-left: 0; padding-right: 0; }
.master-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.master-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: var(--bg2); border: 1px solid var(--card-edge); border-radius: 10px;
  padding: 12px 14px; color: var(--text); text-align: left; font-size: 14px;
}
.master-item b { color: var(--accent); font-size: 15px; }
.master-item span { font-size: 12px; color: var(--muted); }
.ai-card .btn-secondary:disabled { opacity: .5; }
#ai-result.loading::after {
  content: "…"; display: inline-block; animation: dots 1.2s steps(4) infinite;
}
@keyframes dots { 0% { content: "·"; } 25% { content: "··"; } 50% { content: "···"; } }

.history ul { list-style: none; }
.history li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--card-edge); font-size: 14px; cursor: pointer; }
.history li:last-child { border-bottom: none; }
.history .muted { flex: none; }
.hist-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.hist-main span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-date { font-size: 12px; }

/* ---------- 弹层 / 提示 ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-box { background: var(--card); border: 1px solid var(--card-edge); border-radius: var(--radius); padding: 24px 20px; width: 100%; max-width: 360px; position: relative; }
.modal-box h2 { font-size: 20px; margin-bottom: 6px; }
.modal-close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted); font-size: 24px; }
.modal-box input {
  width: 100%; background: var(--bg2); border: 1px solid var(--card-edge); border-radius: 10px;
  color: var(--text); padding: 12px; font-size: 15px; margin-top: 12px;
}
.modal-box .btn-primary { margin-top: 14px; padding: 12px; font-size: 15px; letter-spacing: 0; }
.modal-box .btn-text { display: block; margin: 12px auto 0; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.auth-tab {
  flex: 1; background: none; border: none; color: var(--muted);
  font-size: 16px; padding: 10px 0; cursor: pointer;
  border-bottom: 2px solid var(--card-edge);
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.auth-switch { text-align: center; font-size: 13px; color: var(--muted); margin-top: 12px; }
.auth-switch a { color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.row-2col { display: flex; gap: 10px; margin-top: 12px; }
.row-2col .btn-text { flex: 1; border: 1px solid var(--card-edge); border-radius: 8px; padding: 8px 0; }
.hidden { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: 48px; transform: translateX(-50%);
  background: rgba(20,15,35,.95); border: 1px solid var(--card-edge);
  color: var(--text); padding: 10px 20px; border-radius: 22px; font-size: 14px; z-index: 60;
  max-width: 86vw; text-align: center;
}

.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 26px 8px 0; }
.footer-link {
  background: none; border: none; color: var(--muted); font-size: 12px;
  text-decoration: underline; text-underline-offset: 4px; padding: 8px 12px; min-height: 36px;
}

@media (max-width: 380px) {
  .coin { width: 62px; height: 62px; }
  .app-header h1 { font-size: 28px; }
}
