:root {
  --paper: #f3ecdc;
  --paper-2: #ebe1cb;
  --ink: #1f1b16;
  --ink-soft: #5a5146;
  --muted: #8a7f70;
  --red: #b23a2a;
  --red-soft: rgba(178, 58, 42, 0.12);
  --gold: #a8843a;
  --rule: rgba(31, 27, 22, 0.14);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 0%, #f8f3e7 0%, var(--paper) 55%, var(--paper-2) 100%) fixed;
  color: var(--ink);
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 20px;
  line-height: 1.5;
}
body::before { /* paper fibres */
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .4 0 0 0 0 .35 0 0 0 0 .25 0 0 0 .08 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: none; }
.zh, .zhname { font-family: "Ma Shan Zheng", "Noto Serif TC", serif; }

.top { display: flex; justify-content: space-between; align-items: center; max-width: 760px; margin: 0 auto; padding: 16px 16px 0; }
.seal { width: 44px; height: 44px; background: var(--red); color: #fbeee0; font-family: "Ma Shan Zheng", serif; font-size: 28px; border-radius: 6px; line-height: 1;
  box-shadow: inset 0 0 0 2px rgba(255, 240, 220, .35); transform: rotate(-4deg); }
.link { font-size: 19px; color: var(--ink-soft); border-bottom: 1px solid var(--rule); padding: 0 2px; }
main { max-width: 760px; margin: 0 auto; padding: 8px 16px 40px; }
footer { text-align: center; font-size: 15px; color: var(--muted); padding: 0 16px 24px; }
footer a { color: inherit; }

.screen { display: none; }
.screen.active { display: block; animation: fade .6s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

/* ask */
#ask { text-align: center; padding-top: 6vh; }
h1 { margin: 0 0 12px; font-weight: 400; }
h1 .zh { display: block; font-size: clamp(72px, 16vw, 120px); line-height: 1; letter-spacing: .08em; }
h1 .en { display: block; font-size: 24px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); margin-top: 6px; }
.lede { max-width: 520px; margin: 18px auto; color: var(--ink-soft); }
textarea { width: 100%; max-width: 560px; font: inherit; font-size: 22px; background: rgba(255, 252, 244, .7); border: 1px solid var(--rule); border-radius: 4px;
  padding: 12px 16px; color: var(--ink); resize: none; outline: none; }
textarea:focus { border-color: var(--gold); }
.method { display: flex; gap: 22px; justify-content: center; margin: 14px 0 22px; color: var(--ink-soft); font-size: 18px; }
.method input { accent-color: var(--red); }
.primary { background: var(--ink); color: var(--paper); padding: 12px 34px; border-radius: 2px; font-size: 21px; letter-spacing: .06em; transition: transform .15s, background .2s; }
.primary:hover { background: #3a3128; }
.primary:active { transform: translateY(2px); }
.primary:disabled { opacity: .35; cursor: default; }

/* cast */
#cast { text-align: center; padding-top: 2vh; }
.asked { font-style: italic; color: var(--ink-soft); min-height: 1.5em; }
.castwrap { display: flex; align-items: center; justify-content: center; gap: 40px; flex-wrap: wrap; margin: 16px 0; }
.coins { display: flex; gap: 16px; perspective: 700px; height: 200px; align-items: flex-end; }
.coin { width: 78px; height: 78px; position: relative; transform-style: preserve-3d; }
.face { position: absolute; inset: 0; border-radius: 50%; backface-visibility: hidden; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #e8c77a, #b38a3c 55%, #7c5a22 100%);
  box-shadow: inset 0 0 0 4px rgba(90, 60, 20, .45), inset 0 0 0 7px rgba(255, 230, 170, .25), 0 3px 6px rgba(40, 25, 10, .25); }
.face::after { content: ""; width: 20px; height: 20px; background: var(--paper); box-shadow: inset 0 0 0 2px rgba(90, 60, 20, .6); }
.face.yin { transform: rotateX(180deg); }
.face.yin span { position: absolute; font-family: "Noto Serif TC", serif; font-weight: 600; font-size: 15px; color: #4a3210; }
.face.yin span:nth-child(1) { top: 9px; } .face.yin span:nth-child(2) { bottom: 9px; }
.face.yin span:nth-child(3) { right: 11px; } .face.yin span:nth-child(4) { left: 11px; }
.yarrow { width: 260px; height: 200px; }
.tally { min-height: 3em; color: var(--ink-soft); }
.tally b { color: var(--ink); font-weight: 600; }
.hint { color: var(--muted); font-size: 16px; margin-top: 8px; }

/* hexagram svg */
.hex { width: 150px; height: auto; overflow: visible; }
.hex.big { width: 200px; }
.hex .bar { stroke: var(--ink); stroke-width: 22; stroke-linecap: butt; filter: url(#ink); fill: none; }
.hex .bar.draw { animation: brush .55s ease-out forwards; }
@keyframes brush { from { stroke-dashoffset: var(--len); } to { stroke-dashoffset: 0; } }
.hex .slot { stroke: var(--rule); stroke-width: 1; stroke-dasharray: 3 5; }
.hex .mark { fill: none; stroke: var(--red); stroke-width: 3; }
.hex .changing { stroke: #3a2a20; }

/* reading */
.rhead { display: grid; grid-template-columns: auto 1fr; gap: 26px; align-items: center; margin: 18px 0 10px; }
.rhead .hex { width: 130px; }
.num { color: var(--red); letter-spacing: .12em; font-size: 17px; text-transform: uppercase; }
.zhname { font-size: 64px; line-height: 1.05; }
.pyname { font-size: 26px; font-style: italic; }
.trig { color: var(--ink-soft); font-size: 18px; margin-top: 4px; }
.trig b { font-family: "Noto Serif TC", serif; font-weight: 400; font-size: 22px; color: var(--ink); }
.question { font-style: italic; font-size: 22px; border-left: 3px solid var(--red); padding: 2px 0 2px 14px; margin: 18px 0; color: var(--ink-soft); }
.focus { background: var(--red-soft); border-radius: 4px; padding: 10px 14px; font-size: 18px; color: #6b2a1f; margin: 14px 0; }
.sect { font-weight: 500; font-size: 15px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); margin: 28px 0 6px; border-bottom: 1px solid var(--rule); padding-bottom: 4px; }
.text { margin: 6px 0 12px; font-size: 21px; }
.text.key { position: relative; }
.text.key::before { content: "●"; position: absolute; left: -22px; color: var(--red); font-size: 12px; top: 8px; }
.line { display: grid; grid-template-columns: 74px 1fr; gap: 12px; margin: 10px 0; }
.line .pos { font-size: 16px; color: var(--muted); padding-top: 4px; letter-spacing: .05em; }
.line .pos i { display: block; font-style: normal; color: var(--red); }
.line.key .text { font-weight: 500; }
.arrow { text-align: center; color: var(--muted); font-size: 18px; margin: 30px 0 0; letter-spacing: .1em; }
.relating { border-top: 1px solid var(--rule); margin-top: 8px; }
.relating .rhead .hex { width: 96px; }
.relating .zhname { font-size: 46px; }
.sage { margin: 34px 0 10px; padding: 20px 22px; background: rgba(255, 252, 244, .65); border: 1px solid var(--rule); border-radius: 4px; }
.sage p { margin: 0 0 12px; }
.sage .who { display: flex; align-items: center; gap: 10px; font-size: 15px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); margin-bottom: 8px; }
.actions { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; margin-top: 28px; }
.ghost { border: 1px solid var(--ink); padding: 11px 26px; border-radius: 2px; font-size: 20px; }
.pulse { animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .45; } }

/* journal */
.entries { list-style: none; padding: 0; margin: 0; }
.entries li { display: grid; grid-template-columns: 54px 1fr auto; gap: 14px; align-items: center; padding: 12px 4px; border-bottom: 1px solid var(--rule); cursor: pointer; }
.entries li:hover { background: rgba(255, 252, 244, .5); }
.entries .hex { width: 46px; }
.entries .q { font-style: italic; color: var(--ink-soft); font-size: 18px; }
.entries .d { color: var(--muted); font-size: 15px; text-align: right; }
.empty { color: var(--muted); font-style: italic; text-align: center; padding: 30px; }

@media (max-width: 560px) {
  body { font-size: 19px; }
  .rhead { grid-template-columns: 1fr; text-align: center; gap: 10px; }
  .rhead .hex { margin: 0 auto; }
  .zhname { font-size: 54px; }
  .coins { gap: 10px; height: 170px; }
  .coin { width: 66px; height: 66px; }
  .line { grid-template-columns: 1fr; gap: 0; }
  .text.key::before { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01s !important; } }

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

/* ================= Tolan theme ================= */
[data-theme="tolan"] body { background: #f4f2e7; color: #2c2c2c; font-family: "Inter Tight", system-ui, sans-serif; font-size: 17px; letter-spacing: -.01em; }
[data-theme="tolan"] body::before { display: none; }
[data-theme="tolan"] :is(.zh, .zhname, h1 .zh) { font-family: "Noto Serif TC", serif; font-weight: 400; }
[data-theme="tolan"] .seal { background: #8f6cf0; border-radius: 12px; transform: none; font-family: "Noto Serif TC", serif; font-size: 22px; box-shadow: none; }
[data-theme="tolan"] .link { font-size: 15px; font-weight: 500; color: #474744; border: 1px solid #e2e0c3; background: #fff; border-radius: 999px; padding: 9px 14px; }
[data-theme="tolan"] h1 .zh { font-size: clamp(60px, 13vw, 96px); letter-spacing: .02em; color: #2c2c2c; }
[data-theme="tolan"] h1 .en { text-transform: none; letter-spacing: -.02em; font-weight: 600; font-size: 26px; color: #2c2c2c; margin-top: 12px; }
[data-theme="tolan"] .lede { color: #7a7869; font-size: 17px; }
[data-theme="tolan"] textarea { background: #fff; border: 1px solid #e2e0c3; border-radius: 18px; font-size: 18px; padding: 16px 18px; box-shadow: 0 1px 2px rgba(44,44,44,.05); }
[data-theme="tolan"] textarea:focus { border-color: #8f6cf0; }
[data-theme="tolan"] .method { font-size: 15px; color: #474744; }
[data-theme="tolan"] .method input { accent-color: #8f6cf0; }
[data-theme="tolan"] .primary { background: #2c2c2c; color: #fff; border-radius: 14px; font-size: 16px; font-weight: 500; letter-spacing: -.01em; padding: 14px 30px; }
[data-theme="tolan"] .primary:hover { background: #474744; }
[data-theme="tolan"] .ghost { background: #faf8f3; border: 1px solid #e2e0c3; color: #474744; border-radius: 14px; font-size: 16px; font-weight: 500; }
[data-theme="tolan"] .asked, [data-theme="tolan"] .tally { color: #7a7869; font-size: 16px; }
[data-theme="tolan"] .hint { font-size: 13px; }

/* soft, flat coins */
[data-theme="tolan"] .face { background: radial-gradient(circle at 35% 30%, #fbf8ec, #e2e0c3 70%); box-shadow: inset 0 0 0 1px #c9c5a8, inset 0 0 0 7px rgba(255,255,255,.5), 0 6px 16px rgba(44,44,44,.1); }
[data-theme="tolan"] .face::after { background: #f4f2e7; box-shadow: inset 0 0 0 1px #c9c5a8; border-radius: 3px; }
[data-theme="tolan"] .face.yin span { color: #8f6cf0; font-weight: 400; }

/* clean rounded bars instead of brush ink */
[data-theme="tolan"] .hex .bar { stroke: #2c2c2c; stroke-width: 18; stroke-linecap: round; filter: none; }
[data-theme="tolan"] .hex .bar.changing { stroke: #8f6cf0; }
[data-theme="tolan"] .hex .mark { stroke: #8f6cf0; }
[data-theme="tolan"] .hex .slot { stroke: #dcd9c3; }

/* the reading becomes a white card */
[data-theme="tolan"] #readingBody { background: #fff; border: 1px solid #e2e0c3; border-radius: 28px; padding: 8px 28px 28px; box-shadow: 0 2px 12px rgba(44,44,44,.05); }
[data-theme="tolan"] .num { color: #8f6cf0; letter-spacing: 0; text-transform: none; font-weight: 600; font-size: 14px; }
[data-theme="tolan"] .zhname { font-size: 52px; }
[data-theme="tolan"] .pyname { font-style: normal; font-weight: 600; font-size: 22px; letter-spacing: -.02em; }
[data-theme="tolan"] .trig { font-size: 14px; color: #7a7869; }
[data-theme="tolan"] .question { border-left-color: #8f6cf0; font-style: normal; font-size: 17px; color: #474744; }
[data-theme="tolan"] .focus { background: #f1ecff; color: #4b3a91; border-radius: 14px; font-size: 15px; }
[data-theme="tolan"] .sect { text-transform: none; letter-spacing: -.01em; font-weight: 600; font-size: 14px; color: #7a7869; border-bottom-color: #edece2; }
[data-theme="tolan"] .text { font-size: 17px; line-height: 1.6; color: #474744; }
[data-theme="tolan"] .text.key { color: #2c2c2c; }
[data-theme="tolan"] .text.key::before { color: #8f6cf0; }
[data-theme="tolan"] .line .pos { font-size: 13px; }
[data-theme="tolan"] .line .pos i { color: #8f6cf0; }
[data-theme="tolan"] .arrow { font-size: 14px; }
[data-theme="tolan"] .relating { border-top-color: #edece2; }
[data-theme="tolan"] .sage { background: #f4f2e7; border: none; border-radius: 20px; }
[data-theme="tolan"] .sage .who { color: #8f6cf0; letter-spacing: 0; text-transform: none; font-weight: 600; font-size: 14px; }
[data-theme="tolan"] .sage p { font-size: 16px; color: #474744; }
[data-theme="tolan"] .sect + .entries, [data-theme="tolan"] .entries { background: #fff; border: 1px solid #e2e0c3; border-radius: 22px; overflow: hidden; }
[data-theme="tolan"] .entries li { border-bottom-color: #edece2; padding: 14px 16px; }
[data-theme="tolan"] .entries .q { font-style: normal; font-size: 15px; color: #7a7869; }
[data-theme="tolan"] footer { font-size: 13px; color: #9a978a; }

/* Marc: a cartoon glam-rock companion who offers the reflection */
.marc { width: 92px; height: auto; flex: none; filter: drop-shadow(0 4px 10px rgba(60, 40, 30, .15)); }
.marc.mini { width: 54px; }
.marc.note { width: 46px; }
.marcask { display: flex; align-items: center; gap: 16px; }
.marcask .marcsays { margin: 0 0 10px; font-style: italic; color: var(--ink-soft); }
.marcnote { display: inline-flex; align-items: center; gap: 10px; margin: 0 auto 18px; color: var(--ink-soft); font-size: 17px; }
[data-theme="tolan"] .marcask .marcsays { font-style: normal; color: #474744; font-size: 16px; }
[data-theme="tolan"] .marcnote { color: #8a8a80; font-size: 15px; }
@media (max-width: 520px) { .marcask { flex-direction: column; text-align: center; } }
