*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; margin: 0; padding: 0; }
:root {
  --bg:    #0a0520;
  --gold:  #d4af37;
  --goldb: #f0d070;
  --pur:   #7c3aed;
  --purL:  #a78bfa;
  --txt:   #e8e4f0;
  --dim:   #8b84a8;
  --sh:    env(safe-area-inset-top, 0px);
  --sb:    env(safe-area-inset-bottom, 0px);
}

html { height: 100%; }
body {
  min-height: 100%; background: var(--bg);
  background-image:
    radial-gradient(ellipse at top,    rgba(124,58,237,.22) 0%, transparent 55%),
    radial-gradient(ellipse at bottom, rgba(212,175,55,.07) 0%, transparent 55%);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", sans-serif;
  overscroll-behavior: none;
}

/* ── 星空 ── */
.stars {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, #fff, transparent),
    radial-gradient(1px 1px at 78% 32%, #fff, transparent),
    radial-gradient(1px 1px at 43% 67%, #fff, transparent),
    radial-gradient(1px 1px at 88% 78%, #fff, transparent),
    radial-gradient(1px 1px at 22% 88%, #fff, transparent),
    radial-gradient(1px 1px at 58% 12%, #fff, transparent),
    radial-gradient(1px 1px at 33% 44%, var(--gold), transparent),
    radial-gradient(2px 2px at 52% 24%, #fff, transparent),
    radial-gradient(1px 1px at 68% 58%, var(--purL), transparent);
  opacity: .55;
  animation: twinkle 7s ease-in-out infinite alternate;
}
@keyframes twinkle { to { opacity: .85; } }

/* ── JS 提示 ── */
.js-tip { font-size: 11px; color: var(--dim); text-align: center; margin-top: 10px; letter-spacing: 1px; }

/* ── 主页 ── */
.home {
  position: relative; z-index: 1;
  width: 100%; max-width: 480px; margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  padding: calc(var(--sh) + 28px) 24px calc(var(--sb) + 32px);
  display: flex; flex-direction: column; align-items: center;
}
.logo { text-align: center; margin-bottom: 8px; }
.logo-cn {
  font-family: "STZhongsong","Noto Serif SC",serif;
  font-size: 44px; letter-spacing: 12px;
  background: linear-gradient(170deg, var(--goldb) 0%, var(--gold) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.logo-en { font-size: 10px; letter-spacing: 7px; color: var(--dim); margin-top: 6px; }
.sigil {
  font-size: 72px; color: var(--gold); margin: 18px 0;
  text-shadow: 0 0 40px rgba(212,175,55,.5);
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe { 0%,100%{transform:scale(1);opacity:.85} 50%{transform:scale(1.07);opacity:1} }
.tagline { font-size: 13px; color: var(--dim); margin-bottom: 24px; letter-spacing: 1px; text-align: center; }

.qbox {
  width: 100%;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(212,175,55,.25);
  border-radius: 16px; padding: 14px 16px; margin-bottom: 20px;
  backdrop-filter: blur(10px);
}
.qbox label { display: block; font-size: 11px; color: var(--gold); letter-spacing: 2px; margin-bottom: 10px; }
.qbox textarea {
  width: 100%; background: transparent; border: none; outline: none;
  color: var(--txt); font-size: 16px; line-height: 1.6;
  resize: none; min-height: 60px; font-family: inherit;
}
.qbox textarea::placeholder { color: var(--dim); }

/* ── 按钮 ── */
.btn-main {
  width: 100%; padding: 16px;
  background: linear-gradient(135deg, var(--pur) 0%, #5b21b6 100%);
  border: 1px solid rgba(212,175,55,.55); border-radius: 14px;
  color: var(--goldb); font-size: 17px; letter-spacing: 8px;
  cursor: pointer;
  box-shadow: 0 0 28px rgba(124,58,237,.4), inset 0 1px 0 rgba(255,255,255,.1);
  transition: transform .15s, box-shadow .15s;
}
.btn-main:active { transform: scale(.98); }
.btn-main:disabled { opacity: .38; cursor: not-allowed; }
.btn-main.ready { box-shadow: 0 0 36px rgba(212,175,55,.55), inset 0 1px 0 rgba(255,255,255,.1); }
.btn-ghost {
  background: transparent; border: none;
  color: var(--dim); font-size: 13px; letter-spacing: 1px;
  cursor: pointer; padding: 4px 8px;
}
.btn-close {
  display: block; width: 100%; margin-top: 10px;
  background: transparent; border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px; color: var(--dim);
  font-size: 14px; padding: 12px; cursor: pointer; letter-spacing: 2px;
}

/* ── Dialog 通用 ── */
dialog {
  border: none; padding: 0; background: transparent;
  max-width: none; width: 100%;
}
dialog::backdrop { background: rgba(8,3,22,.82); backdrop-filter: blur(8px); }

.dlg {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; margin: 0;
  background: linear-gradient(175deg, #1d0b44 0%, #0d0528 100%);
  border: 1px solid rgba(212,175,55,.28); border-bottom: none;
  border-radius: 22px 22px 0 0;
  padding: 6px 20px calc(var(--sb) + 26px);
  max-height: 90vh; overflow-y: auto;
  animation: slideUp .35s cubic-bezier(.25,.46,.45,.94) both;
}
.dlg-full {
  height: 92vh; height: 92dvh;
  display: flex; flex-direction: column;
  overflow: hidden; max-height: none;
}
@keyframes slideUp { from { transform: translateX(-50%) translateY(100%); } to { transform: translateX(-50%) translateY(0); } }

.dlg-pill { width: 38px; height: 4px; background: rgba(212,175,55,.28); border-radius: 2px; margin: 10px auto 16px; }
.dlg-title { text-align: center; font-size: 18px; letter-spacing: 5px; color: var(--gold); margin-bottom: 4px; }
.dlg-sub { text-align: center; font-size: 12px; color: var(--dim); margin-bottom: 18px; }

/* ── 牌阵选项 ── */
.spread-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.spread-item {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.04);
  border: 1.5px solid rgba(212,175,55,.2);
  border-radius: 14px; padding: 13px 14px;
  cursor: pointer; transition: all .18s; text-align: left;
  color: var(--txt);
}
.spread-item:active, .spread-item.si-default { background: rgba(212,175,55,.08); }
.spread-item.si-active {
  border-color: var(--gold); border-width: 2px;
  background: rgba(212,175,55,.12);
  box-shadow: 0 0 22px rgba(212,175,55,.3);
}
.si-icon {
  flex-shrink: 0; width: 36px; height: 36px;
  border: 1px solid var(--gold); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: var(--goldb);
}
.spread-item.si-active .si-icon { background: var(--gold); color: #0a0520; }
.si-body { flex: 1; }
.si-name { display: block; font-size: 15px; color: var(--gold); letter-spacing: 3px; }
.si-desc { display: block; font-size: 11px; color: var(--dim); margin-top: 2px; }
.si-cnt { flex-shrink: 0; font-size: 11px; color: var(--dim); }

/* ── 选牌弹窗 ── */
.pick-bar {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 6px;
}
.pick-hint { flex-shrink: 0; text-align: center; font-size: 13px; color: var(--dim); margin-bottom: 10px; }

.slots { flex-shrink: 0; display: grid; gap: 6px; margin-bottom: 10px; }
.slots.n1  { grid-template-columns: 1fr; max-width: 100px; margin-left: auto; margin-right: auto; }
.slots.n3  { grid-template-columns: repeat(3,1fr); }
.slots.n10 { grid-template-columns: repeat(5,1fr); gap: 4px; }
.slot {
  aspect-ratio: 2/3.3; position: relative;
  border: 1.5px dashed rgba(212,175,55,.3); border-radius: 7px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 9px; color: var(--dim); text-align: center; padding: 2px;
  transition: all .25s;
}
.slot.filled { border-style: solid; border-color: var(--gold); box-shadow: 0 0 10px rgba(212,175,55,.25); }
.slot-num { position: absolute; top: 2px; left: 3px; font-size: 8px; color: var(--gold); }
.slot-lbl { font-size: 9px; letter-spacing: 1px; }
.slot.filled .slot-check {
  position: absolute; inset: 3px; border-radius: 5px;
  background: linear-gradient(160deg,#1e0f4a,#0a0520);
  border: 1px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  color: var(--goldb); font-size: 11px;
}

/* ── 牌堆 ── */
.deck-wrap {
  flex: 1; min-height: 0;
  display: flex; align-items: center;
  margin: 8px -20px 12px; overflow: hidden;
}
.deck {
  display: flex; overflow-x: auto; overflow-y: hidden;
  padding: 48px 40vw 28px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  width: 100%; align-items: center;
}
.deck::-webkit-scrollbar { display: none; }
.card {
  flex: 0 0 auto; width: 108px; aspect-ratio: 2/3.3;
  border-radius: 10px; margin: 0 -33px;
  scroll-snap-align: center;
  cursor: pointer; user-select: none; -webkit-user-drag: none;
  transform-origin: bottom center;
  transition: transform .3s cubic-bezier(.2,.9,.3,1), filter .25s;
  position: relative;
}
.card.picked {
  transform: translateY(-26px) scale(1.04) !important;
  filter: drop-shadow(0 0 14px rgba(212,175,55,.65));
  pointer-events: none;
}
.card-back {
  position: absolute; inset: 0; border-radius: 10px;
  background: radial-gradient(circle at 50% 50%, rgba(212,175,55,.14) 0%, transparent 58%),
              linear-gradient(148deg, #291456 0%, #0a0520 100%);
  border: 1.5px solid var(--gold);
  box-shadow: inset 0 0 0 3px rgba(10,5,32,.8), inset 0 0 0 4.5px rgba(212,175,55,.55), 0 6px 18px rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.card-back::before {
  content: ''; position: absolute; inset: 9px;
  border: 1px solid rgba(212,175,55,.35); border-radius: 5px;
  background-image:
    linear-gradient(45deg,rgba(212,175,55,.07) 25%,transparent 25%),
    linear-gradient(-45deg,rgba(212,175,55,.07) 25%,transparent 25%),
    linear-gradient(45deg,transparent 75%,rgba(212,175,55,.07) 75%),
    linear-gradient(-45deg,transparent 75%,rgba(212,175,55,.07) 75%);
  background-size: 11px 11px; background-position: 0 0,0 5.5px,5.5px -5.5px,-5.5px 0;
}
.card-sigil {
  position: relative; width: 48%; aspect-ratio: 1;
  border: 1px solid var(--gold); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--goldb); font-size: 22px;
  text-shadow: 0 0 10px var(--gold);
  background: radial-gradient(circle, rgba(10,5,32,.8) 55%, transparent);
}

/* ── 解读页 ── */
.reading-page {
  position: fixed; inset: 0; z-index: 400;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at top, rgba(124,58,237,.18) 0%, transparent 50%);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  flex-direction: column;   /* activated when display:flex */
}
.rp-inner {
  max-width: 480px; margin: 0 auto;
  padding: calc(var(--sh) + 20px) 20px calc(var(--sb) + 36px);
}
.rp-title {
  text-align: center; font-size: 18px; letter-spacing: 5px;
  color: var(--gold); margin: 4px 0 20px;
}
.cards-mini { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 8px; margin-bottom: 20px; }
.mini-card {
  flex: 0 0 auto; width: 44px; aspect-ratio: 2/3.3;
  border: 1px solid var(--gold); border-radius: 5px;
  background: linear-gradient(160deg,#1e0f4a,#0a0520);
  position: relative; overflow: visible;
}
.mini-card img { position: absolute; inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); object-fit: cover; border-radius: 3px; }
.mini-card.rev img { transform: rotate(180deg); }
.mini-fb { position: absolute; inset: 0; align-items: center; justify-content: center; font-size: 9px; color: var(--gold); }
.mini-tag { position: absolute; top: -15px; left: 50%; transform: translateX(-50%); font-size: 8px; color: var(--dim); white-space: nowrap; }

.thinking {
  background: rgba(167,139,250,.05);
  border: 1px solid rgba(167,139,250,.18); border-left: 3px solid var(--purL);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 16px;
  font-size: 12px; color: var(--dim); line-height: 1.7;
  max-height: 200px; overflow-y: auto;
  transition: max-height .3s;
}
.thinking.collapsed { max-height: 36px; overflow: hidden; }
.thinking-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; color: var(--purL); font-size: 11px; letter-spacing: 1px; cursor: pointer;
}
.t-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--purL); margin-right: 7px; animation: pulse 1.2s infinite; }
.thinking.done .t-dot { animation: none; background: var(--gold); }
@keyframes pulse { 50%{opacity:.25} }

.rp-text {
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(212,175,55,.18); border-radius: 12px;
  padding: 16px 18px; font-size: 15px; line-height: 1.9;
  color: var(--txt); white-space: pre-wrap; word-break: break-word; min-height: 160px;
}
.rp-text strong { color: var(--goldb); }
.rp-text.streaming::after { content: '▊'; color: var(--gold); animation: blink 1s infinite; }
@keyframes blink { 50%{opacity:0} }
.rp-err {
  color: #f87171; background: rgba(248,113,113,.1);
  border: 1px solid rgba(248,113,113,.25); border-radius: 10px;
  padding: 12px; margin-top: 12px; font-size: 14px;
}

/* ── 响应式 ── */
@media (max-height: 670px) {
  .sigil { font-size: 52px; margin: 10px 0; }
  .logo-cn { font-size: 36px; }
  .tagline { margin-bottom: 16px; }
}
