:root {
  --paper: #f7f8fa;
  --panel: #ffffff;
  --ink: #25292d;
  --muted: #6c737b;
  --line: #dfe3e8;
  --accent: #bf5f4e;
  --accent-soft: #f9e9e5;
  --jade: #2f7c73;
  --jade-soft: #e1f0ed;
  --nav: #eef1f3;
  --shadow: 0 14px 32px rgba(29, 38, 46, 0.08);
}

:root[data-theme="dark"] {
  --paper: #171b1e;
  --panel: #20262a;
  --ink: #ecf0f1;
  --muted: #a9b2b9;
  --line: #3a444b;
  --accent: #ef907c;
  --accent-soft: #3d2b29;
  --jade: #6eb7ac;
  --jade-soft: #233b39;
  --nav: #1b2125;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.2);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
  font-family: "Noto Serif SC", "Songti SC", Georgia, serif;
}
button, input, select, textarea { font: inherit; }
button { color: inherit; }

.layout { min-height: 100vh; display: grid; grid-template-columns: 320px minmax(0, 1fr); }
.sidebar { padding: 34px 26px; background: var(--nav); border-right: 1px solid var(--line); }
.brand { display: flex; gap: 14px; align-items: center; padding: 18px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.brand-mark, .bagua-mark { display: grid; place-items: center; flex: 0 0 auto; }
.brand-mark { width: 58px; height: 58px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-size: 30px; font-weight: 700; }
.brand-title { font-size: 24px; line-height: 1.1; }
.brand-copy { margin-top: 6px; color: var(--muted); font-size: 14px; }
.eyebrow { margin: 40px 0 16px; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 12px; }
.eyebrow::after { content: ""; height: 1px; flex: 1; background: var(--line); }
.nav-list { display: grid; gap: 8px; }
.nav-item { width: 100%; display: grid; grid-template-columns: 46px 1fr; gap: 13px; align-items: center; padding: 12px; border: 1px solid transparent; border-radius: 7px; background: transparent; text-align: left; cursor: pointer; }
.nav-item:hover, .nav-item.active { border-color: var(--line); background: var(--panel); }
.nav-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-family: Arial, sans-serif; font-size: 21px; }
.nav-item:nth-child(2) .nav-icon { background: var(--jade-soft); color: var(--jade); }
.nav-item:nth-child(3) .nav-icon { background: #e9eef8; color: #4b6f9c; }
.nav-name { font-size: 18px; }
.nav-copy { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.sidebar-foot { margin-top: 34px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.icon-button { width: 38px; height: 38px; display: inline-grid; place-items: center; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); cursor: pointer; }

.main { min-width: 0; background: var(--paper); }
.topbar { height: 106px; padding: 0 48px; display: flex; align-items: center; gap: 18px; background: color-mix(in srgb, var(--paper) 92%, transparent); border-bottom: 1px solid var(--line); }
.menu-button { display: none; }
.topbar-title { padding-left: 18px; border-left: 1px solid var(--line); font-size: 23px; }
.topbar-copy { color: var(--muted); font-size: 17px; }
.content { width: min(1020px, calc(100% - 64px)); margin: 0 auto; padding: 78px 0 54px; }
.hero { text-align: center; padding: 42px 18px 68px; }
.bagua-mark { width: 160px; height: 160px; margin: 0 auto 30px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); box-shadow: var(--shadow); color: var(--ink); font-family: Arial, sans-serif; font-size: 88px; }
.hero h1 { margin: 0; font-size: 68px; font-weight: 500; line-height: 1.1; }
.hero p { margin: 20px 0 0; color: var(--accent); font-size: 26px; }
.section-intro { max-width: 630px; margin: 0 auto 24px; text-align: center; }
.section-intro h2 { margin: 0; font-size: 28px; font-weight: 500; }
.section-intro p { margin: 8px 0 0; color: var(--muted); }
.entry-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.entry-card { display: block; min-height: 202px; padding: 24px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit; text-decoration: none; box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02); transition: transform .18s ease, box-shadow .18s ease; }
.entry-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.card-kicker { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-family: Arial, sans-serif; font-size: 22px; }
.entry-card:nth-child(2) .card-kicker { background: var(--jade-soft); color: var(--jade); }
.entry-card:nth-child(3) .card-kicker { background: #e9eef8; color: #4b6f9c; }
.entry-card h3 { margin: 22px 0 7px; font-size: 22px; font-weight: 500; }
.entry-card p { margin: 0; color: var(--muted); line-height: 1.65; }
.steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 70px; }
.step { padding: 24px; border-top: 2px solid var(--ink); background: var(--panel); }
.step-no { color: var(--accent); font-family: Arial, sans-serif; font-size: 14px; }
.step h3 { margin: 16px 0 8px; font-size: 20px; font-weight: 500; }
.step p { margin: 0; color: var(--muted); line-height: 1.65; }

.tool-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.tool-header h1 { margin: 0; font-size: 38px; font-weight: 500; }
.tool-header p { margin: 7px 0 0; color: var(--muted); }
.text-button { border: 0; padding: 9px 0; color: var(--jade); background: transparent; cursor: pointer; font-size: 15px; }
.panel { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); box-shadow: var(--shadow); }
.form-panel { padding: 30px; }
.field-label { display: block; margin-bottom: 10px; color: var(--ink); font-size: 17px; }
textarea, input, select { width: 100%; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--paper); outline: none; }
textarea { min-height: 150px; resize: vertical; padding: 16px; line-height: 1.65; }
input, select { height: 46px; padding: 0 12px; }
textarea:focus, input:focus, select:focus { border-color: var(--jade); box-shadow: 0 0 0 3px color-mix(in srgb, var(--jade) 20%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 26px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; color: var(--muted); background: var(--panel); cursor: pointer; }
.chip:hover { color: var(--accent); border-color: var(--accent); }
.primary { min-height: 48px; border: 0; border-radius: 6px; padding: 0 22px; background: var(--accent); color: #fff; cursor: pointer; font-size: 17px; }
.primary:hover { background: #a94f40; }
.form-note { margin: 15px 0 0; color: var(--muted); font-size: 14px; }
.result { margin-top: 24px; padding: 30px; border-left: 4px solid var(--jade); }
.result h2 { margin: 0 0 14px; font-size: 27px; font-weight: 500; }
.result-meta { color: var(--jade); font-size: 15px; }
.result p { line-height: 1.85; }
.hexagram { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; margin: 18px 0; padding: 18px; background: var(--paper); border-radius: 6px; }
.line-stack { display: grid; gap: 5px; width: 86px; }
.yao { height: 8px; background: var(--ink); }
.yao.yin { display: flex; justify-content: space-between; background: transparent; }
.yao.yin::before, .yao.yin::after { width: 42%; height: 8px; content: ""; background: var(--ink); }
.result-disclaimer { margin-top: 20px; color: var(--muted); font-size: 14px; }
.principles { display: grid; gap: 0; margin-top: 26px; }
.principle { padding: 18px 0; border-bottom: 1px solid var(--line); }
.principle strong { font-size: 18px; font-weight: 500; }
.principle p { margin: 7px 0 0; color: var(--muted); line-height: 1.6; }
.field-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 16px; }
.radio-row { display: flex; gap: 22px; margin: 0 0 22px; }
.radio-row label { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); }
.history { margin-top: 32px; padding: 24px; }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.history-head h2 { margin: 0; font-size: 20px; font-weight: 500; }
.history-list { margin: 16px 0 0; display: grid; gap: 10px; }
.history-item { padding: 14px 0; border-top: 1px solid var(--line); }
.history-item:first-child { border-top: 0; }
.history-item strong { display: block; font-weight: 500; }
.history-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.empty { color: var(--muted); margin: 16px 0 0; }
.footer { padding: 40px 0 0; text-align: center; color: var(--muted); font-size: 13px; }
.error { margin: 12px 0 0; color: #a5352b; font-size: 14px; }
.is-casting { display: none; }
.casting-panel { margin-top: 4px; padding: 28px; overflow: hidden; }
.asked { display: grid; gap: 8px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.asked span, .cast-head p, .cast-rule, .cast-row small, .result-grid small { color: var(--muted); font-size: 14px; }
.asked strong { font-size: 20px; font-weight: 500; overflow-wrap: anywhere; }
.cast-head { display: flex; justify-content: space-between; gap: 18px; align-items: start; padding: 20px 0 6px; }
.cast-head strong { font-size: 22px; font-weight: 500; }
.cast-head p { margin: 6px 0 0; }
.cast-state { padding: 6px 10px; border: 1px solid var(--jade); color: var(--jade); font-size: 14px; }
.coin-row { display: flex; justify-content: center; gap: 18px; padding: 22px 0 18px; }
.coin { width: 72px; height: 72px; display: grid; place-items: center; border: 6px double var(--accent); border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; box-shadow: 0 4px 10px rgba(29, 38, 46, .12); }
.coin.flip { animation: coin-turn .88s cubic-bezier(.4, .05, .2, 1); }
.coin.late { animation-delay: .11s; }
.coin.later { animation-delay: .22s; }
@keyframes coin-turn { 0% { transform: rotateY(0) translateY(0); } 38% { transform: rotateY(270deg) translateY(-24px); } 76% { transform: rotateY(550deg) translateY(2px); } 100% { transform: rotateY(720deg) translateY(0); } }
.cast-rule { max-width: 680px; margin: 0 auto; text-align: center; line-height: 1.7; }
.cast-table { margin-top: 18px; padding: 8px 20px; }
.cast-table-head, .cast-row { display: grid; grid-template-columns: 90px minmax(120px, 1fr) minmax(110px, 1fr) minmax(120px, 1fr); gap: 14px; align-items: center; }
.cast-table-head { padding: 12px 0; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }
.cast-row { min-height: 62px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.cast-row:last-child { border-bottom: 0; }
.cast-row b, .cast-row small { display: block; }
.mini-coins { display: flex; gap: 6px; }
.mini-coin { width: 26px; height: 26px; display: grid; place-items: center; border: 1px solid var(--jade); border-radius: 50%; background: var(--jade-soft); color: var(--jade); font-size: 12px; font-style: normal; }
.mini-coin.word { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.cast-yao { height: 7px; background: var(--ink); }
.cast-yao.yin { display: flex; justify-content: space-between; background: transparent; }
.cast-yao.yin::before, .cast-yao.yin::after { content: ''; width: 42%; background: var(--ink); }
.cast-yao.moving { box-shadow: 0 0 0 3px var(--accent-soft); }
.appear { animation: line-in .38s ease-out both; }
@keyframes line-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.cast-empty { padding: 20px 0; text-align: center; }
.result-reveal { animation: result-in .45s ease-out both; }
@keyframes result-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }
.result-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 18px; align-items: stretch; margin: 20px 0; }
.result-grid article { display: grid; gap: 8px; padding: 18px; border: 1px solid var(--line); background: var(--paper); }
.result-grid article > span { color: var(--jade); font-size: 14px; }
.result-grid strong { font-size: 20px; font-weight: 500; }
.result-grid .line-stack { width: 100%; margin-top: 8px; }
.change-arrow { display: grid; place-items: center; color: var(--accent); font-size: 14px; writing-mode: vertical-rl; }

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: block; position: fixed; z-index: 10; inset: 0 auto 0 0; width: min(86vw, 320px); overflow: auto; box-shadow: var(--shadow); }
  .topbar { height: 72px; padding: 0 20px; }
  .menu-button { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
  .topbar-title { font-size: 19px; }
  .topbar-copy { display: none; }
  .content { width: min(100% - 32px, 740px); padding-top: 42px; }
  .hero h1 { font-size: 50px; }
  .hero p { font-size: 21px; }
}

@media (max-width: 650px) {
  .entry-grid, .steps, .field-grid, .field-grid.two { grid-template-columns: 1fr; }
  .hero { padding: 14px 0 42px; }
  .bagua-mark { width: 124px; height: 124px; font-size: 68px; }
  .hero h1 { font-size: 42px; }
  .tool-header { align-items: flex-start; flex-direction: column; }
  .tool-header h1 { font-size: 31px; }
  .form-panel, .result, .history { padding: 20px; }
  .radio-row { flex-wrap: wrap; gap: 12px; }
  .casting-panel { padding: 20px; }
  .coin { width: 58px; height: 58px; font-size: 15px; }
  .coin-row { gap: 12px; }
  .cast-table { padding: 8px 14px; }
  .cast-table-head { display: none; }
  .cast-row { grid-template-columns: 62px 86px minmax(70px, 1fr); gap: 10px; }
  .cast-row > span:last-child { grid-column: 1 / -1; color: var(--muted); }
  .result-grid { grid-template-columns: 1fr; }
  .change-arrow { height: 20px; writing-mode: horizontal-tb; }
}
