:root {
  --paper: #f3ecdd;
  --paper-2: #faf6ec;
  --ink: #221d17;
  --ink-2: #5d5346;
  --ink-3: #8d8271;
  --line: #d9cdb6;
  --red: #a8281e;
  --red-soft: #f1d9d2;
  --green: #2f6b52;
  --green-soft: #d9e8dd;
  --gold: #9a7b3f;
  --wx-mu: #3a7d5c;
  --wx-huo: #c0432f;
  --wx-tu: #a88147;
  --wx-jin: #8b8f98;
  --wx-shui: #2c5282;
  --shadow: 0 1px 0 rgba(255, 255, 255, .6) inset, 0 8px 24px -14px rgba(60, 40, 10, .35);
  --serif: 'Noto Serif TC', 'Songti TC', 'PMingLiU', 'MingLiU', 'Source Han Serif TC', serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #17140f;
    --paper-2: #201c15;
    --ink: #ece3d0;
    --ink-2: #b9ad96;
    --ink-3: #857a66;
    --line: #3a3326;
    --red: #d9584a;
    --red-soft: #3b1f1a;
    --green: #6bb590;
    --green-soft: #1c2f26;
    --gold: #c9a45c;
    --wx-mu: #5fb089;
    --wx-huo: #e0604a;
    --wx-tu: #c9a060;
    --wx-jin: #b4b8c2;
    --wx-shui: #6b9bd8;
    --shadow: 0 8px 24px -14px rgba(0, 0, 0, .8);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  background-image: radial-gradient(circle at 20% 0%, rgba(154, 123, 63, .10), transparent 45%), radial-gradient(circle at 90% 100%, rgba(168, 40, 30, .06), transparent 40%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.85;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }

/* ── 頁首 ── */
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; max-width: 980px; margin: 0 auto; padding: 18px 20px 6px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; }
.seal { display: grid; place-items: center; width: 44px; height: 44px; background: var(--red); color: #fff6ea; font-weight: 900; font-size: 26px; border-radius: 6px; box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--red); transform: rotate(-3deg); }
.brand-text b { display: block; font-size: 22px; letter-spacing: .2em; line-height: 1.2; }
.brand-text small { color: var(--ink-3); letter-spacing: .3em; font-size: 12px; }
nav { display: flex; gap: 4px; }
nav a { text-decoration: none; padding: 6px 14px; border-radius: 999px; color: var(--ink-2); letter-spacing: .15em; }
nav a:hover { color: var(--ink); }
nav a.on { background: var(--ink); color: var(--paper); }

main { max-width: 980px; margin: 0 auto; padding: 8px 20px 60px; }
.view { display: none; }
.view.on { display: block; animation: rise .4s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.hero { text-align: center; padding: 22px 0 8px; }
.epigraph { margin: 0; font-size: 20px; letter-spacing: .12em; color: var(--ink-2); }
.epigraph cite { display: block; font-style: normal; font-size: 13px; color: var(--ink-3); margin-top: 4px; }

.card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 14px; padding: 26px 28px; margin: 18px 0; box-shadow: var(--shadow); }
h1 { font-size: 28px; letter-spacing: .2em; margin: 0 0 10px; }
h2 { font-size: 19px; letter-spacing: .12em; margin: 0 0 4px; }
.hint { color: var(--ink-3); font-size: 14px; margin: 0 0 12px; }
.hint.small { font-size: 12.5px; margin: 6px 0 0; line-height: 1.6; }

/* ── 問字表單 ── */
.step { padding: 6px 0 20px; border-bottom: 1px dashed var(--line); margin-bottom: 20px; }
.step h2 i { font-style: normal; display: inline-grid; place-items: center; width: 28px; height: 28px; margin-right: 10px; border: 1.5px solid var(--red); color: var(--red); border-radius: 50%; font-size: 14px; letter-spacing: 0; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 12px; padding: 8px 12px; cursor: pointer; transition: .15s; text-align: left; display: flex; flex-direction: column; gap: 2px; min-height: 56px; color: inherit; font: inherit; }
.chip b { font-weight: 600; letter-spacing: .12em; font-size: 16px; }
.chip small { font-size: 12.5px; line-height: 1.35; color: var(--ink-2); letter-spacing: 0; }
.chip[aria-checked="true"] small { color: inherit; opacity: .8; }
.chip:hover { border-color: var(--ink-2); }
.chip[aria-checked="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.write-row { display: flex; gap: 28px; align-items: flex-start; flex-wrap: wrap; }
.tian { position: relative; width: 190px; height: 190px; flex: none; border: 2px solid var(--red); border-radius: 6px; background:
  linear-gradient(var(--red-soft), var(--red-soft)) center/1px 100% no-repeat,
  linear-gradient(var(--red-soft), var(--red-soft)) center/100% 1px no-repeat, var(--paper); }
.tian input { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: transparent; text-align: center; font-size: 120px; font-weight: 600; line-height: 1; padding: 0 0 8px; outline: none; caret-color: var(--red); }
.tian input::placeholder { color: var(--line); font-weight: 400; }
.tian:focus-within { box-shadow: 0 0 0 4px var(--red-soft); }
.seg { display: inline-flex; border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden; margin: 2px 0 18px; }
.seg button { border: 0; background: transparent; padding: 8px 24px; letter-spacing: .15em; cursor: pointer; font-size: 16px; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.mode { display: none; }
.mode.on { display: block; }
.mode-tip { flex: 1; min-width: 220px; margin: 0; align-self: center; color: var(--ink-2); font-size: 15px; }
.pad-wrap { flex: none; max-width: 100%; }
.recog { flex: 1; min-width: 200px; }
.tian.small { width: 110px; height: 110px; display: grid; place-items: center; font-size: 72px; font-weight: 600; line-height: 1; }
.tian.small:empty::before { content: '？'; color: var(--line); font-weight: 400; }
.cands { display: flex; flex-wrap: wrap; gap: 6px; min-height: 44px; }
.cands button { width: 42px; height: 42px; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; font-size: 24px; line-height: 1; cursor: pointer; padding: 0; }
.cands button:hover { border-color: var(--ink-2); }
.row.who { margin-top: 10px; align-items: center; }
.row.who input[type=number] { width: 7.5em; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--red); }
.cands .ai-refresh { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; width: 42px; height: 42px; padding: 0; color: var(--red); border-color: var(--red); background: transparent; }
.cands .ai-refresh:hover:not(:disabled) { background: var(--red); color: #fff6ea; }
.cands .ai-refresh:disabled { opacity: .45; cursor: not-allowed; }
.cands .ai-refresh.spin { opacity: 1; cursor: progress; }
.cands .ai-refresh.spin svg { animation: spin 0.9s linear infinite; }
.cands button.from-ai { border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red-soft); }
@keyframes spin { to { transform: rotate(360deg); } }
.manual { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 14px; color: var(--ink-2); }
.manual input { width: 52px; height: 42px; text-align: center; font-size: 24px; line-height: 1; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); padding: 0; }
.manual input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.manual input.used { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.cands button[aria-pressed="true"] { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.pad-head { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); margin-top: 6px; width: 260px; max-width: 100%; }
#pad { width: 260px; height: 260px; max-width: 100%; display: block; border: 1px dashed var(--ink-3); border-radius: 6px; touch-action: none; cursor: crosshair; background:
  linear-gradient(var(--line), var(--line)) center/1px 100% no-repeat,
  linear-gradient(var(--line), var(--line)) center/100% 1px no-repeat, var(--paper); }
.link { border: 0; background: none; color: var(--red); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
select, input[type="datetime-local"], input[type="search"] { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
input[type="search"] { width: 100%; }
.time { color: var(--ink-2); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.submit { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.primary { background: var(--red); color: #fff6ea; border: 0; border-radius: 10px; padding: 12px 34px; font-size: 19px; letter-spacing: .3em; font-weight: 600; cursor: pointer; box-shadow: 0 6px 16px -8px var(--red); transition: transform .12s; }
.primary:hover { transform: translateY(-1px); }
.primary:disabled { opacity: .6; cursor: progress; }
.msg { color: var(--red); font-size: 14px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ── 批斷 ── */
.result-head { display: grid; grid-template-columns: 240px 1fr auto; gap: 26px; align-items: center; }
.glyph { width: 240px; height: 240px; border: 2px solid var(--ink); border-radius: 8px; background:
  linear-gradient(var(--line), var(--line)) center/1px 100% no-repeat,
  linear-gradient(var(--line), var(--line)) center/100% 1px no-repeat, var(--paper); display: grid; place-items: center; }
.glyph svg { width: 100%; height: 100%; }
.glyph .plain { font-size: 170px; font-weight: 600; line-height: 1; }
.glyph path { opacity: 0; animation: ink .5s ease forwards; }
@keyframes ink { to { opacity: 1; } }
.meta h3 { margin: 0 0 6px; font-size: 22px; letter-spacing: .1em; }
.meta p { margin: 2px 0; color: var(--ink-2); font-size: 15px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 14px; }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; background: var(--c); }
.verdict { writing-mode: vertical-rl; text-orientation: upright; font-size: 40px; font-weight: 900; letter-spacing: .15em; padding: 18px 12px; border: 3px double currentColor; border-radius: 8px; transform: rotate(2deg); min-height: 120px; text-align: center; }
.v-great, .v-good { color: var(--red); }
.v-flat { color: var(--gold); }
.v-bad, .v-worst { color: var(--ink-2); }
.wx-木 { --c: var(--wx-mu); } .wx-火 { --c: var(--wx-huo); } .wx-土 { --c: var(--wx-tu); } .wx-金 { --c: var(--wx-jin); } .wx-水 { --c: var(--wx-shui); }
.wxc { color: var(--c); font-weight: 600; }

.card h3.sec { margin: 0 0 14px; font-size: 18px; letter-spacing: .2em; display: flex; align-items: center; gap: 10px; }
.card h3.sec::before { content: ''; width: 5px; height: 18px; background: var(--red); border-radius: 2px; }
.account { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink-2); min-height: 34px; border-radius: 999px; transition: box-shadow .3s; }
.account .who { font-weight: 600; color: var(--ink); max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .quota b { color: var(--red); }
.account.flash { box-shadow: 0 0 0 3px var(--red-soft), 0 0 0 5px var(--red); }
.ghost { border: 1px solid var(--red); color: var(--red); background: transparent; border-radius: 999px; padding: 6px 18px; cursor: pointer; letter-spacing: .1em; transition: .15s; }
.ghost:hover:not(:disabled) { background: var(--red); color: #fff6ea; }
.ghost:disabled { opacity: .55; cursor: not-allowed; }
.ai-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.ai-row .msg { font-size: 13.5px; color: var(--ink-2); }
.tag { font-size: 12px; letter-spacing: .05em; border: 1px solid var(--line); border-radius: 999px; padding: 0 10px; color: var(--ink-3); font-weight: 400; }
.reading p { margin: 0 0 12px; text-align: justify; }
.reading p:last-child { margin-bottom: 0; }
.reading .caret::after { content: '▍'; color: var(--red); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
details { margin-top: 12px; font-size: 14px; color: var(--ink-2); }
summary { cursor: pointer; color: var(--ink-3); }
pre { white-space: pre-wrap; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 12.5px; line-height: 1.6; font-family: ui-monospace, Consolas, monospace; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two .card { margin: 0; }

/* 卦 */
.guas { display: flex; gap: 22px; justify-content: space-between; flex-wrap: wrap; }
.gua { text-align: center; flex: 1; min-width: 96px; }
.gua .yao { display: flex; flex-direction: column-reverse; gap: 6px; width: 84px; margin: 0 auto 8px; }
.yao i { height: 9px; background: var(--ink); border-radius: 1px; position: relative; display: block; }
.yao i.yin { background: linear-gradient(90deg, var(--ink) 42%, transparent 42%, transparent 58%, var(--ink) 58%); }
.yao i.mv { background-color: var(--red); }
.yao i.mv.yin { background: linear-gradient(90deg, var(--red) 42%, transparent 42%, transparent 58%, var(--red) 58%); }
.yao i[data-s]::after { content: attr(data-s); position: absolute; left: calc(100% + 8px); top: -9px; font-style: normal; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.gua.ben { padding-right: 34px; }
.gua b { display: block; letter-spacing: .1em; }
.gua small { color: var(--ink-3); font-size: 12.5px; display: block; line-height: 1.5; }
.tiyong { margin-top: 14px; font-size: 15px; color: var(--ink-2); border-top: 1px dashed var(--line); padding-top: 12px; }
.tiyong p { margin: 3px 0; }

/* 拆字 */
.parts { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.part { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: flex; gap: 10px; align-items: center; max-width: 100%; }
.part b { font-size: 30px; line-height: 1; }
.part span { font-size: 13px; color: var(--ink-2); line-height: 1.5; }
.sub { font-size: 14px; color: var(--ink-3); letter-spacing: .1em; margin: 14px 0 6px; }
.derive { display: flex; flex-wrap: wrap; gap: 8px; }
.dv { border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.dv b { font-size: 24px; color: var(--ink); line-height: 1.2; }
.dv.good { background: var(--red-soft); border-color: transparent; }
.dv.good b { color: var(--red); }
.dv.bad { background: color-mix(in srgb, var(--ink) 9%, transparent); border-color: transparent; }
.dv.pick { box-shadow: 0 0 0 2px var(--gold); }
.phrases { display: flex; flex-wrap: wrap; gap: 8px; }
.phrases span { border-left: 3px solid var(--gold); padding: 0 10px; font-size: 16px; letter-spacing: .1em; }

/* 論據 */
.ev { list-style: none; margin: 0; padding: 0; }
.tier { margin: 16px 0 4px; font-size: 15px; letter-spacing: .2em; color: var(--red); display: flex; align-items: baseline; gap: 12px; }
.tier small { letter-spacing: .05em; color: var(--ink-2); font-weight: 400; font-size: 13px; }
.ev li { display: grid; grid-template-columns: 52px 54px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 15px; align-items: baseline; }
.ev li:last-child { border: 0; }
.ev .g { color: var(--ink-3); font-size: 13px; letter-spacing: .1em; }
.ev .p { font-family: ui-monospace, Consolas, monospace; font-size: 13px; text-align: right; }
.ev .p.pos { color: var(--red); } .ev .p.neg { color: var(--ink-3); }
.ev cite { font-style: normal; color: var(--ink-3); font-size: 12px; margin-left: 6px; }
.meter { height: 8px; background: linear-gradient(90deg, var(--ink-3), var(--line) 50%, var(--red)); border-radius: 99px; position: relative; margin: 16px 0 6px; }
.meter i { position: absolute; top: -5px; width: 4px; height: 18px; background: var(--ink); border-radius: 2px; transform: translateX(-2px); }
.meter-l { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); }

.case { border-left: 3px solid var(--line); padding: 2px 0 2px 14px; margin: 10px 0; font-size: 15px; }
.case cite { display: block; font-style: normal; font-size: 12.5px; color: var(--ink-3); }
.again { text-align: center; margin: 26px 0 0; }
.ghost { background: none; border: 1px solid var(--ink-2); border-radius: 10px; padding: 9px 26px; letter-spacing: .2em; cursor: pointer; }
.note { font-size: 13px; color: var(--ink-3); text-align: center; margin-top: 14px; }

/* ── 學理／古案 ── */
.prose h2 { margin: 28px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.prose .lead { color: var(--ink-2); }
.prose code { font-size: 13px; background: var(--paper); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line); }
.flow { counter-reset: f; list-style: none; padding: 0; }
.flow li { counter-increment: f; padding: 6px 0 6px 44px; position: relative; }
.flow li::before { content: counter(f, cjk-ideographic); position: absolute; left: 0; top: 7px; width: 28px; height: 28px; border-radius: 50%; background: var(--ink); color: var(--paper); display: grid; place-items: center; font-size: 13px; }
.defs { display: grid; grid-template-columns: minmax(7.8em, max-content) 1fr; gap: 0; }
.defs dt { font-weight: 600; color: var(--red); letter-spacing: .1em; white-space: nowrap; padding: 7px 18px 7px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.defs dd { margin: 0; padding: 7px 0; border-bottom: 1px solid color-mix(in srgb, var(--line) 55%, transparent); }
.grid { border-collapse: collapse; width: 100%; max-width: 460px; text-align: center; margin: 10px 0; }
.grid th, .grid td { border: 1px solid var(--line); padding: 4px 8px; }
.grid th { background: var(--paper); font-weight: 600; }
.classic { font-size: 15px; color: var(--ink-2); text-align: justify; }
.case-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.case-card { background: var(--paper-2); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-size: 14.5px; line-height: 1.75; }
.case-card header { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.case-card button { width: 46px; height: 46px; flex: none; border: 1.5px solid var(--red); color: var(--red); background: none; border-radius: 6px; font-size: 26px; font-weight: 600; cursor: pointer; line-height: 1; }
.case-card button:hover { background: var(--red); color: #fff6ea; }
.case-card header small { color: var(--ink-3); font-size: 12px; line-height: 1.4; }
.case-card p { margin: 0; max-height: 11.5em; overflow: auto; }
footer { text-align: center; color: var(--ink-3); font-size: 13px; padding: 0 0 34px; letter-spacing: .15em; }

@media (max-width: 760px) {
  body { font-size: 16px; }
  .card { padding: 20px 18px; }
  .result-head { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .verdict { writing-mode: horizontal-tb; min-height: 0; padding: 6px 22px; font-size: 30px; }
  .legend { justify-content: center; }
  .two { grid-template-columns: 1fr; }
  .ev li { grid-template-columns: 44px 44px 1fr; }
  .tian { width: 150px; height: 150px; }
  .tian input { font-size: 92px; }
  .defs { grid-template-columns: 1fr; }
  .defs dt { border-bottom: 0; padding-bottom: 0; }
  .defs dd { padding-top: 2px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .glyph path { opacity: 1; }
}
