:root {
  --bg: #080a09;
  --surface: #111310;
  --surface-2: #171812;
  --surface-3: #202017;
  --gold: #caa260;
  --gold-light: #e7c98c;
  --gold-dark: #806331;
  --text: #f3eee3;
  --muted: #aaa394;
  --danger: #cf8876;
  --line: rgba(202, 162, 96, .3);
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  --radius: 18px;
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--text);
  background:
    linear-gradient(115deg, rgba(255,255,255,.012), transparent 35%, rgba(202,162,96,.018) 70%, transparent),
    repeating-linear-gradient(92deg, #080a09 0, #0a0c0b 4px, #080a09 9px, #090b0a 15px);
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}

button, textarea, input { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 3px;
}

.app-shell {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  overflow-x: clip;
  border-inline: 1px solid rgba(202, 162, 96, .08);
  background:
    radial-gradient(circle at 85% 8%, rgba(128,99,49,.10), transparent 24%),
    linear-gradient(180deg, rgba(15,17,15,.94), rgba(7,9,8,.98));
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(92px + var(--safe-bottom));
}

.screen--table { width: 100%; min-width: 0; padding-inline: 0; }
.screen--center { display: flex; flex-direction: column; }

.topbar {
  min-height: 48px;
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 6px;
  margin: -4px 0 18px;
}
.topbar--table { padding-inline: 16px; }
.topbar__title { margin: 0; text-align: center; font-size: 15px; font-weight: 500; letter-spacing: .12em; color: var(--gold-light); }
.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
}
.icon-button:active { background: rgba(255,255,255,.06); transform: scale(.96); }

.eyebrow {
  margin: 0 0 9px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: .22em;
  text-transform: uppercase;
}
h1, h2, h3, p { overflow-wrap: anywhere; }
.display-title {
  margin: 0;
  font-family: "Songti TC", "Noto Serif TC", "PMingLiU", serif;
  font-size: clamp(30px, 9vw, 42px);
  font-weight: 400;
  letter-spacing: .08em;
}
.section-title { margin: 0 0 8px; font-family: "Songti TC", "Noto Serif TC", serif; font-size: 26px; font-weight: 400; letter-spacing: .06em; }
.lead { margin: 10px 0 0; color: var(--muted); line-height: 1.75; font-size: 14px; }
.gold { color: var(--gold-light); }

.home-hero {
  min-height: 250px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 26px 4px 30px;
  position: relative;
}
.home-hero::after {
  content: "";
  position: absolute;
  right: -56px;
  top: 0;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  opacity: .24;
  background: radial-gradient(circle, rgba(202,162,96,.4), transparent 60%);
  filter: blur(12px);
  pointer-events: none;
}

.question-panel, .panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(30,31,25,.86), rgba(14,16,14,.92));
  box-shadow: 0 18px 48px rgba(0,0,0,.25);
}
.question-panel { padding: 18px; }
.field-label { display: block; margin-bottom: 10px; color: var(--gold-light); font-size: 14px; letter-spacing: .06em; }
textarea, .text-input {
  display: block;
  width: 100%;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  color: var(--text);
  background: rgba(5,6,5,.62);
}
textarea { min-height: 120px; padding: 14px; resize: vertical; line-height: 1.65; }
.text-input { min-height: 48px; padding: 11px 13px; }
textarea::placeholder, input::placeholder { color: #777368; }
.field-error { min-height: 20px; margin: 7px 0 0; color: var(--danger); font-size: 12px; }

.button {
  width: 100%;
  min-height: 50px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 12px 17px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: .04em;
  touch-action: manipulation;
  transition: transform .16s ease, background .16s ease, opacity .16s ease;
}
.button:active { transform: scale(.985); }
.button:disabled { opacity: .44; cursor: not-allowed; }
.button--gold { color: #1a1409; background: linear-gradient(135deg, var(--gold-light), #b98b49); box-shadow: 0 8px 24px rgba(185,139,73,.16); }
.button--outline { border-color: var(--line); color: var(--gold-light); background: rgba(202,162,96,.04); }
.button--quiet { color: var(--muted); background: rgba(255,255,255,.045); }
.button--danger { border-color: rgba(207,136,118,.35); color: #e6aa9b; background: rgba(207,136,118,.06); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: grid; gap: 12px; }
.section-gap { margin-top: 28px; }

.recent-header { margin: 28px 2px 10px; display: flex; align-items: center; justify-content: space-between; }
.recent-header h2 { margin: 0; font-size: 15px; font-weight: 500; letter-spacing: .08em; }
.text-button { min-height: 44px; border: 0; padding: 8px; color: var(--gold); background: transparent; cursor: pointer; }
.record-list { display: grid; gap: 10px; }
.record-row {
  width: 100%;
  min-height: 72px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 13px;
  padding: 13px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-align: left;
  background: rgba(255,255,255,.027);
  cursor: pointer;
}
.record-row__meta { display: block; margin-bottom: 4px; color: var(--gold); font-size: 11px; }
.record-row__question { margin: 0; color: var(--text); font-size: 14px; line-height: 1.45; }
.record-row__arrow { color: var(--muted); }

.tool-list { display: grid; gap: 13px; margin-top: 28px; }
.tool-card {
  width: 100%;
  min-height: 116px;
  border: 1px solid rgba(202,162,96,.22);
  border-radius: 16px;
  padding: 18px;
  display: grid;
  grid-template-columns: 54px 1fr 24px;
  align-items: center;
  gap: 14px;
  text-align: left;
  color: inherit;
  background: linear-gradient(120deg, rgba(28,29,23,.8), rgba(11,13,11,.8));
  cursor: pointer;
}
.tool-card:active { border-color: var(--gold); transform: scale(.99); }
.tool-card__icon { width: 54px; height: 54px; border: 1px solid var(--gold-dark); border-radius: 50%; display: grid; place-items: center; color: var(--gold-light); font-family: serif; font-size: 25px; }
.tool-card h3 { margin: 0 0 5px; color: var(--gold-light); font-family: "Songti TC", serif; font-size: 20px; font-weight: 400; }
.tool-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }

.choice-grid { display: grid; gap: 11px; margin-top: 26px; }
.choice-card {
  width: 100%;
  min-height: 76px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 13px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 48px 1fr 26px;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-align: left;
  background: rgba(255,255,255,.025);
  cursor: pointer;
}
.choice-card.is-selected { border-color: var(--gold); background: rgba(202,162,96,.07); }
.choice-card__number { color: var(--gold-light); font-family: serif; font-size: 26px; }
.choice-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.choice-card p { margin: 0; color: var(--muted); font-size: 12px; }
.choice-check { color: var(--gold-light); opacity: 0; }
.is-selected .choice-check { opacity: 1; }

.position-list { display: grid; gap: 11px; margin-top: 22px; counter-reset: positions; }
.position-field { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center; }
.position-field__number { width: 30px; height: 30px; border: 1px solid var(--gold); border-radius: 50%; display: grid; place-items: center; color: var(--gold-light); font-size: 13px; }
.sticky-action { position: sticky; bottom: calc(12px + var(--safe-bottom)); z-index: 5; margin-top: 24px; padding: 8px; border-radius: 16px; background: rgba(8,10,9,.88); backdrop-filter: blur(12px); }

.table-question { padding: 0 22px; text-align: center; }
.table-question__count { margin: 0 0 7px; color: var(--muted); font-size: 12px; letter-spacing: .18em; }
.table-question h1 { margin: 0; color: var(--gold-light); font-family: "Songti TC", serif; font-size: clamp(23px, 7vw, 31px); font-weight: 400; line-height: 1.35; }
.table-stage {
  width: 100%;
  min-width: 0;
  flex: 1;
  min-height: 430px;
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse at center, rgba(202,162,96,.09), transparent 45%),
    repeating-linear-gradient(4deg, transparent 0, transparent 9px, rgba(255,255,255,.008) 10px);
}
.deck-prep { min-height: 390px; padding: 40px 22px 24px; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; }
.deck-stack { width: 118px; aspect-ratio: .59; position: relative; margin-bottom: 30px; }
.deck-stack::before, .deck-stack::after, .deck-stack__card { content: ""; position: absolute; inset: 0; border: 1px solid var(--gold); border-radius: 9px; background: linear-gradient(145deg, #11172a, #06080f); box-shadow: 0 12px 30px rgba(0,0,0,.45); }
.deck-stack::before { transform: translate(-8px, 5px) rotate(-5deg); opacity: .65; }
.deck-stack::after { transform: translate(8px, 5px) rotate(5deg); opacity: .75; }
.deck-stack__card { z-index: 2; display: grid; place-items: center; }
.deck-stack__card::after, .card-back-design::after { content: "✦"; width: 58%; aspect-ratio: 1; border: 1px solid var(--gold); border-radius: 50%; display: grid; place-items: center; color: var(--gold); font-size: 28px; box-shadow: inset 0 0 0 5px #0d1120, inset 0 0 0 6px rgba(202,162,96,.4); }
.deck-prep h2 { margin: 0; font-family: "Songti TC", serif; font-size: 25px; font-weight: 400; }
.deck-prep p { margin: 10px 0 26px; color: var(--muted); font-size: 13px; line-height: 1.65; }
.deck-prep .button { max-width: 310px; }

.fan-hint { margin: auto 0 18px; text-align: center; color: var(--muted); font-size: 13px; }
.fan-hint strong { display: block; margin-bottom: 5px; color: var(--gold-light); font-weight: 500; }
.card-fan {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 260px;
  padding: 28px clamp(150px, 42vw, 210px);
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}
.card-fan::-webkit-scrollbar { display: none; }
.fan-card {
  flex: 0 0 68px;
  width: 104px;
  height: 178px;
  margin-right: -35px;
  border: 1px solid var(--gold-dark);
  border-radius: 7px;
  padding: 0;
  position: relative;
  background: #090d19;
  box-shadow: -8px 6px 16px rgba(0,0,0,.33);
  scroll-snap-align: center;
  cursor: pointer;
  transform-origin: 50% 120%;
  transition: transform .18s ease, border-color .18s ease;
}
.fan-card:nth-child(4n+1) { transform: rotate(-2deg) translateY(4px); }
.fan-card:nth-child(4n+2) { transform: rotate(1deg); }
.fan-card:nth-child(4n+3) { transform: rotate(2deg) translateY(3px); }
.fan-card:active { transform: translateY(-14px) scale(1.04); border-color: var(--gold-light); z-index: 4; }
.card-back-design { position: absolute; inset: 4px; border: 1px solid rgba(202,162,96,.55); border-radius: 4px; display: grid; place-items: center; background: repeating-linear-gradient(45deg, rgba(202,162,96,.04) 0, rgba(202,162,96,.04) 3px, transparent 3px, transparent 8px); }
.card-back-design::after { font-size: 14px; }
.fan-footer { padding: 0 22px 18px; text-align: center; color: var(--muted); font-size: 12px; }

.draw-overlay { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(20px + env(safe-area-inset-top)) 22px calc(20px + var(--safe-bottom)); background: rgba(3,4,3,.92); backdrop-filter: blur(15px); animation: fade-in .25s ease both; }
.draw-overlay__label { margin: 0 0 18px; color: var(--gold-light); text-align: center; font-family: "Songti TC", serif; font-size: 20px; }
.flip-card { width: min(54vw, 220px); aspect-ratio: .575; perspective: 1200px; }
.flip-card__inner { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform .72s cubic-bezier(.2,.7,.2,1); }
.flip-card.is-flipped .flip-card__inner { transform: rotateY(180deg); }
.flip-card__side { position: absolute; inset: 0; overflow: hidden; border: 1px solid var(--gold); border-radius: 12px; backface-visibility: hidden; box-shadow: 0 26px 60px rgba(0,0,0,.55); background: #0b0d0c; }
.flip-card__back { padding: 5px; }
.flip-card__front { transform: rotateY(180deg); display: grid; place-items: center; }
.flip-card__front img { width: 100%; height: 100%; object-fit: cover; }
.flip-card__front img.is-reversed { transform: rotate(180deg); }
.draw-status { min-height: 72px; margin: 18px 0 14px; text-align: center; }
.draw-status h2 { margin: 0 0 5px; font-family: "Songti TC", serif; font-size: 25px; font-weight: 400; }
.draw-status p { margin: 0; color: var(--gold-light); font-size: 14px; }
.draw-actions { width: min(100%, 360px); display: grid; gap: 10px; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.spread-preview { display: grid; gap: 12px; margin-top: 24px; }
.spread-preview--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.spread-preview--5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.spread-preview--5 .result-card:nth-child(4) { grid-column: 1 / 2; }
.spread-preview--5 .result-card:nth-child(5) { grid-column: 3 / 4; }
.spread-preview--9 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.result-card { min-width: 0; text-align: center; }
.result-card__position { min-height: 32px; margin: 0 0 6px; color: var(--gold-light); font-size: 11px; line-height: 1.35; }
.result-card__image { width: 100%; aspect-ratio: .58; overflow: hidden; border: 1px solid var(--gold-dark); border-radius: 6px; background: var(--surface-3); }
.result-card__image img { width: 100%; height: 100%; object-fit: cover; }
.result-card__image img.is-reversed { transform: rotate(180deg); }
.result-card__name { margin: 6px 0 0; font-size: 11px; line-height: 1.35; }
.spread-preview--9 .result-card__position { display: none; }
.spread-preview--9 .result-card__name { font-size: 10px; }

.coins-stage { margin-top: 22px; text-align: center; }
.coin-row { min-height: 100px; display: flex; justify-content: center; align-items: center; gap: 14px; }
.coin { width: 72px; aspect-ratio: 1; border: 2px solid #9d7337; border-radius: 50%; display: grid; place-items: center; position: relative; color: #231708; background: radial-gradient(circle at 35% 28%, #efd498, #b47d35 58%, #704618); box-shadow: inset 0 0 0 5px rgba(82,48,13,.34), 0 10px 22px rgba(0,0,0,.28); font-family: serif; font-size: 19px; font-weight: 700; animation: coin-arrive .55s ease both; }
.coin--tails { color: #d8b978; background: radial-gradient(circle at 35% 28%, #7b5425, #3e2813 68%, #25170b); }
.coin:nth-child(2) { animation-delay: .08s; }
.coin:nth-child(3) { animation-delay: .16s; }
@keyframes coin-arrive { from { opacity: 0; transform: translateY(-22px) rotateY(180deg); } to { opacity: 1; transform: translateY(0) rotateY(0); } }
.throw-result { min-height: 52px; margin: 10px 0 15px; }
.throw-result strong { display: block; color: var(--gold-light); font-family: "Songti TC", serif; font-size: 22px; font-weight: 400; }
.throw-result span { color: var(--muted); font-size: 12px; }
.hexagram-progress { width: min(230px, 70vw); margin: 18px auto 24px; display: flex; flex-direction: column; gap: 10px; }
.line-row { height: 18px; display: grid; grid-template-columns: 28px 1fr 38px; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.yao { height: 12px; display: flex; gap: 12px; }
.yao::before, .yao::after { content: ""; height: 100%; flex: 1; border-radius: 2px; background: #ded7c8; }
.yao--yang { gap: 0; }
.yao--yang::after { display: none; }
.yao--moving::before, .yao--moving::after { background: var(--gold); }
.yao--empty::before, .yao--empty::after { background: rgba(255,255,255,.12); }
.line-row__type { text-align: right; color: var(--gold); }

.result-summary { padding: 17px; margin-top: 16px; }
.result-meta { display: grid; grid-template-columns: 76px 1fr; gap: 10px; margin: 0; font-size: 13px; line-height: 1.55; }
.result-meta dt { color: var(--muted); }
.result-meta dd { margin: 0; }
.result-list { display: grid; gap: 10px; margin-top: 18px; }
.result-line { padding: 13px; display: grid; grid-template-columns: 28px 1fr; gap: 10px; border-radius: 11px; background: rgba(255,255,255,.03); }
.result-line__number { color: var(--gold); font-family: serif; }
.result-line h3 { margin: 0 0 4px; color: var(--gold-light); font-size: 13px; font-weight: 500; }
.result-line p { margin: 0; color: var(--text); font-size: 13px; line-height: 1.5; }
.hexagram-pair { display: grid; grid-template-columns: 1fr 24px 1fr; align-items: center; gap: 8px; margin-top: 22px; }
.hexagram-card { padding: 16px 10px; text-align: center; }
.hexagram-card h3 { margin: 10px 0 3px; color: var(--gold-light); font-family: "Songti TC", serif; font-size: 19px; font-weight: 400; }
.hexagram-card p { margin: 0; color: var(--muted); font-size: 11px; }
.mini-hexagram { width: 74px; margin: 0 auto; display: flex; flex-direction: column; gap: 5px; }
.mini-hexagram .yao { height: 6px; gap: 7px; }
.hexagram-arrow { color: var(--gold); text-align: center; }

.note-panel { margin-top: 18px; }
.note-panel textarea { min-height: 88px; }
.result-actions { display: grid; gap: 10px; margin-top: 18px; }

.empty-state { padding: 70px 20px; text-align: center; color: var(--muted); }
.empty-state__symbol { display: block; margin-bottom: 16px; color: var(--gold-dark); font-family: serif; font-size: 46px; }
.history-toolbar { display: flex; justify-content: flex-end; margin-bottom: 12px; }

.bottom-nav { position: fixed; z-index: 10; left: 50%; bottom: 0; width: min(100%, 520px); transform: translateX(-50%); padding: 8px 20px var(--safe-bottom); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; border-top: 1px solid rgba(202,162,96,.18); background: rgba(8,10,9,.94); backdrop-filter: blur(18px); }
.nav-button { min-height: 48px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; cursor: pointer; }
.nav-button.is-active { color: var(--gold-light); background: rgba(202,162,96,.07); }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: end center; padding: 20px 16px calc(16px + var(--safe-bottom)); background: rgba(0,0,0,.72); }
.modal__panel { width: min(100%, 480px); border: 1px solid var(--line); border-radius: 18px; padding: 22px; background: #121411; box-shadow: 0 24px 80px rgba(0,0,0,.6); }
.modal__panel h2 { margin: 0 0 8px; font-family: "Songti TC", serif; font-size: 23px; font-weight: 400; }
.modal__panel p { margin: 0 0 20px; color: var(--muted); font-size: 14px; line-height: 1.65; }

.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(84px + var(--safe-bottom)); max-width: calc(100% - 40px); transform: translate(-50%, 12px); border: 1px solid var(--line); border-radius: 999px; padding: 10px 16px; color: var(--text); background: rgba(27,29,24,.96); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; box-shadow: 0 10px 34px rgba(0,0,0,.45); font-size: 13px; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  body { padding-block: 22px; }
  .app-shell { min-height: calc(100dvh - 44px); border-radius: 28px; overflow: hidden; box-shadow: 0 30px 90px rgba(0,0,0,.45); }
  .screen { min-height: calc(100dvh - 44px); }
  .bottom-nav { bottom: 22px; border-radius: 0 0 28px 28px; }
}

@media (max-height: 700px) {
  .home-hero { min-height: 185px; }
  .table-stage { min-height: 360px; }
  .card-fan { height: 220px; }
  .fan-card { height: 148px; width: 87px; flex-basis: 58px; }
  .flip-card { width: min(46vw, 190px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
