:root {
  --abyss-0: #050514;
  --abyss-1: #0a0a22;
  --abyss-2: #141033;
  --silver: #dfe4f5;
  --mist: #9a93b8;
  --mist-dim: #625d80;
  --gold: #d9b662;
  --gold-hi: #ffe0ac;
  --lav: #b8a8e8;
  --serif: "Songti SC", "Noto Serif SC", "STSong", "SimSun", serif;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--abyss-0);
  overflow: hidden;
  font-family: var(--serif);
  color: var(--silver);
  -webkit-font-smoothing: antialiased;
}

.stage {
  position: fixed; inset: 0; overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% -8%, rgba(114, 90, 200, .20), transparent 55%),
    radial-gradient(90% 50% at 50% 112%, rgba(64, 46, 120, .22), transparent 60%),
    linear-gradient(180deg, var(--abyss-1) 0%, var(--abyss-0) 70%);
}
canvas#sky { position: absolute; inset: 0; width: 100%; height: 100%; }
.veil {
  position: absolute; inset: 0; pointer-events: none; z-index: 6;
  background: radial-gradient(135% 100% at 50% 42%, transparent 44%, rgba(2, 2, 10, .62) 100%);
}
.brand {
  position: absolute; top: 18px; left: 0; right: 0; text-align: center; z-index: 7; pointer-events: none;
  font-size: 12px; letter-spacing: .55em; text-indent: .55em; color: rgba(217, 182, 98, .75);
}
#resetBtn {
  position: absolute; top: 12px; right: 12px; z-index: 12;
  font-family: var(--serif); font-size: 11px; letter-spacing: .15em; color: var(--mist);
  background: rgba(20, 16, 51, .5); border: 1px solid rgba(184, 168, 232, .28);
  border-radius: 18px; padding: 6px 13px; cursor: pointer;
  opacity: 0; pointer-events: none; transition: opacity .5s ease;
}
#resetBtn.on { opacity: 1; pointer-events: auto; }
#soundBtn {
  position: absolute; top: 12px; left: 12px; z-index: 12;
  width: 32px; height: 32px; border-radius: 50%;
  font-size: 14px; color: var(--gold); line-height: 1;
  background: rgba(20, 16, 51, .5); border: 1px solid rgba(184, 168, 232, .28);
  cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .5s ease, color .3s ease;
}
#soundBtn.on { opacity: 1; pointer-events: auto; }
#soundBtn.muted { color: var(--mist-dim); text-decoration: line-through; }

/* 抽出的牌飞向槽位 */
.flycard {
  position: fixed; z-index: 30; border-radius: 6px; pointer-events: none;
  background: url("back.svg") center / cover;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .6);
  transition: all .68s cubic-bezier(.3, .72, .3, 1);
}
@keyframes minipop { 0% { transform: scale(.5); } 60% { transform: scale(1.14); } 100% { transform: scale(1); } }
.mini.filled .mc { animation: minipop .5s ease; }

/* ---------- 露娜：月光之身 ---------- */
.luna {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -58%); z-index: 3;
  transition: transform 1.8s cubic-bezier(.2, .7, .2, 1), opacity 1.3s ease, filter 1.3s ease;
  filter: drop-shadow(0 0 44px rgba(184, 168, 232, .16)); opacity: 0;
}
.luna.here { opacity: 1; }
.luna .inner { position: relative; animation: breathe 6.5s ease-in-out infinite; transform-origin: 50% 96%; }
.luna .lart {
  display: block; width: min(68vw, 310px); height: auto;
  -webkit-mask-image: radial-gradient(ellipse 66% 58% at 50% 46%, #000 50%, transparent 77%);
  mask-image: radial-gradient(ellipse 66% 58% at 50% 46%, #000 50%, transparent 77%);
}
/* 魔法球覆盖层：对准画中水晶球（约横向居中、纵向44.5%处），screen 混合提亮 */
.luna .orbfx {
  position: absolute; left: 50%; top: 44.5%; width: 30%; aspect-ratio: 1;
  transform: translate(-50%, -50%); border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 240, 190, .85) 0%, rgba(255, 224, 172, .32) 48%, transparent 70%);
  mix-blend-mode: screen; pointer-events: none;
  animation: orbglow 4.6s ease-in-out infinite;
}
/* 思考粒子环：绕立绘缓转的金色星点 */
.luna .orbits {
  position: absolute; inset: 4% 6%; opacity: 0; pointer-events: none;
  transition: opacity .8s ease; animation: orbitspin 10s linear infinite;
}
.luna .orbits i { position: absolute; border-radius: 50%; background: #ffe0ac; box-shadow: 0 0 10px rgba(255, 224, 172, .9); }
.luna .orbits i:nth-child(1) { left: 50%; top: 0; width: 5px; height: 5px; }
.luna .orbits i:nth-child(2) { right: 0; top: 50%; width: 4px; height: 4px; }
.luna .orbits i:nth-child(3) { left: 50%; bottom: 0; width: 3.5px; height: 3.5px; }
.luna .orbits i:nth-child(4) { left: 0; top: 50%; width: 4px; height: 4px; }
.luna.recede { transform: translate(-50%, -100%) scale(.58); opacity: .75; }
.luna.hide { transform: translate(-50%, -150%) scale(.4); opacity: 0; }
.luna.speaking { filter: drop-shadow(0 0 60px rgba(255, 224, 172, .3)); }
.luna.thinking { filter: drop-shadow(0 0 72px rgba(255, 224, 172, .4)); }
.luna.here.faded { opacity: .16; }
@keyframes breathe { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(1.012) translateY(-1.5px); } }
@keyframes orbglow { 0%, 100% { opacity: .5; } 50% { opacity: 1; } }
.luna.speaking .orbfx { animation-duration: 1.6s; }
@keyframes orbflicker {
  0%, 100% { opacity: .35; } 16% { opacity: 1; } 33% { opacity: .5; }
  52% { opacity: .95; } 70% { opacity: .42; } 86% { opacity: .9; }
}
.luna.thinking .orbfx { animation: orbflicker .9s linear infinite; }
@keyframes orbitspin { to { transform: rotate(360deg); } }
.luna.thinking .orbits { opacity: 1; }
/* 露娜隐身时（逐张解读阶段）的思考特效：大牌呼吸金光 */
@keyframes cardpulse {
  0%, 100% { filter: drop-shadow(0 0 12px rgba(217, 182, 98, .15)); }
  50% { filter: drop-shadow(0 0 42px rgba(255, 224, 172, .55)); }
}
body.thinking #bigwrap.on #bigcard { animation: cardpulse 1.7s ease-in-out infinite; }

/* ---------- 顶部牌列（小缩略图） ---------- */
#strip {
  position: absolute; top: 46px; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: center; gap: 9px;
  opacity: 0; transition: opacity .8s ease; pointer-events: none;
}
#strip.on { opacity: 1; }
.mini { text-align: center; width: 44px; }
.mini .mc {
  width: 38px; height: 64px; margin: 0 auto; border-radius: 4px;
  border: 1px dashed rgba(184, 168, 232, .35);
  background-size: cover; background-position: center;
  transition: all .5s ease; position: relative;
}
.mini.filled .mc { border: 1px solid rgba(184, 168, 232, .3); background-image: url("back.svg"); box-shadow: 0 3px 10px rgba(0, 0, 0, .5); }
.mini.done .mc { border-color: rgba(217, 182, 98, .4); }
.mini.done .mc img { width: 100%; height: 100%; object-fit: cover; border-radius: 3px; display: block; }
.mini.done .mc img.rev { transform: rotate(180deg); }
.mini.current .mc { box-shadow: 0 0 16px rgba(217, 182, 98, .55); border-color: var(--gold); transform: translateY(-3px); }
.mini .mp { font-size: 9px; letter-spacing: .08em; color: var(--mist); margin-top: 5px; white-space: nowrap; transform: scale(.92); }

/* ---------- 大牌特写 ---------- */
#bigwrap {
  position: absolute; top: 132px; left: 50%; transform: translateX(-50%) translateY(24px); z-index: 5;
  opacity: 0; transition: opacity .7s ease, transform .7s cubic-bezier(.16, .9, .24, 1);
  pointer-events: none; text-align: center;
}
#bigwrap.on { opacity: 1; transform: translateX(-50%) translateY(0); }
#bigcard {
  height: min(40vh, 350px); aspect-ratio: 250 / 420; margin: 0 auto;
  position: relative; perspective: 900px;
}
#bigcard .flip {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transition: transform 1.05s cubic-bezier(.3, .85, .3, 1);
}
#bigcard .flip.go { transform: rotateY(180deg); }
#bigcard .face {
  position: absolute; inset: 0; border-radius: 10px; overflow: hidden;
  backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 14px 44px rgba(0, 0, 0, .65), 0 0 32px rgba(217, 182, 98, .12);
}
#bigcard .face.back { background: url("back.svg") center / cover; }
#bigcard .face.front { transform: rotateY(180deg); }
#bigcard .face img { width: 100%; height: 100%; object-fit: cover; display: block; }
#bigcard .face img.rev { transform: rotate(180deg); }
#bigname {
  margin-top: 10px; font-size: 14px; color: var(--gold); letter-spacing: .1em;
  opacity: 0; transition: opacity .6s ease .45s;
}
#bigname small { color: var(--mist); font-size: 10px; letter-spacing: .3em; margin-left: 8px; }
#bigwrap.named #bigname { opacity: 1; }

/* ---------- 她的话（字幕） ---------- */
.subtitle {
  position: absolute; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  width: min(86%, 460px); text-align: center; pointer-events: none;
  transition: bottom .8s ease, top .8s ease;
}
.subtitle .who {
  font-size: 11px; letter-spacing: .6em; text-indent: .6em; color: var(--gold);
  margin-bottom: 10px; opacity: 0; transition: opacity .6s ease;
}
.subtitle.show .who { opacity: 1; }
.subtitle .line {
  font-size: clamp(13px, 3.7vw, 15px); font-weight: 300; line-height: 1.9;
  color: var(--silver); letter-spacing: .04em; text-wrap: balance;
  min-height: 3.6em; max-height: 26vh; overflow-y: auto; scrollbar-width: none;
  text-shadow: 0 2px 26px rgba(0, 0, 0, .7);
  pointer-events: auto; text-align: center;
  -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 14px, #000 calc(100% - 6px), transparent 100%);
  mask-image: linear-gradient(180deg, transparent 0, #000 14px, #000 calc(100% - 6px), transparent 100%);
}
.subtitle .line::-webkit-scrollbar { display: none; }
.subtitle .line b { color: var(--gold-hi); font-weight: 400; }
.subtitle .line h4 {
  color: var(--gold); font-size: 14px; font-weight: 500; letter-spacing: .12em;
  margin: 14px 0 4px;
}
.subtitle .line p { margin: 5px 0; }
.subtitle .caret {
  display: inline-block; width: 1.5px; height: 1em; background: var(--gold);
  vertical-align: -.12em; margin-left: 2px; animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
/* 思考等待期：凝神呼吸文字 + 三颗流转星点 */
.thinking-ind { display: flex; flex-direction: column; align-items: center; gap: 15px; padding: 6px 0; }
.thinking-ind .tw {
  font-size: 14px; letter-spacing: .22em; text-indent: .22em; color: var(--gold);
  opacity: .7; animation: thinkbreath 2.6s ease-in-out infinite;
}
@keyframes thinkbreath { 0%, 100% { opacity: .38; } 50% { opacity: .95; } }
.thinking-ind .td { display: flex; gap: 9px; }
.thinking-ind .td i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--gold-hi);
  box-shadow: 0 0 8px rgba(255, 224, 172, .8); animation: thinkdot 1.4s ease-in-out infinite;
}
.thinking-ind .td i:nth-child(2) { animation-delay: .22s; }
.thinking-ind .td i:nth-child(3) { animation-delay: .44s; }
@keyframes thinkdot {
  0%, 100% { transform: scale(.6) translateY(0); opacity: .3; }
  40% { transform: scale(1.15) translateY(-4px); opacity: 1; }
}
/* 大牌特写在场时，字幕贴近底部并限高；露娜不在场，隐去名牌 */
.subtitle.low { bottom: calc(150px + env(safe-area-inset-bottom)); }
.subtitle.low .who { display: none; }
.subtitle.low .line { max-height: 18vh; }
/* 牌扇升起时，字幕上移让位 */
.subtitle.lift { bottom: 47%; }
.subtitle.lift .line { max-height: 18vh; }

/* ---------- 你的话，飘向她 ---------- */
.heard {
  position: absolute; z-index: 9; color: var(--lav); font-size: 15px; letter-spacing: .08em;
  pointer-events: none; text-shadow: 0 0 16px rgba(184, 168, 232, .8); opacity: 0; white-space: nowrap;
  animation: drift 2s ease forwards;
}
@keyframes drift {
  0% { opacity: 0; transform: translate(0, 12px) scale(1); }
  16% { opacity: .95; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(.5); }
}

/* ---------- 牌扇 ---------- */
.fan {
  position: absolute; left: 50%; bottom: 66px; transform: translateX(-50%) translateY(160%); z-index: 8;
  width: min(96vw, 520px); height: 148px;
  transition: transform 1.1s cubic-bezier(.16, .9, .24, 1); pointer-events: none;
}
.fan.up { transform: translateX(-50%) translateY(12%); pointer-events: auto; }
.fan .fc {
  position: absolute; left: 50%; bottom: 0; margin-left: -30px;
  width: 60px; height: 101px; border-radius: 6px;
  background: url("back.svg") center / cover; box-shadow: -4px 2px 12px rgba(0, 0, 0, .55);
  transform-origin: 50% 135%; cursor: pointer;
  transform: rotate(var(--a, 0deg));
  transition: transform .22s ease, opacity .45s ease, box-shadow .22s ease, filter .22s ease;
}
/* 悬停/按住：这张牌被"预选"顶起，泛金光 */
.fan .fc.lift, .fan .fc:active {
  transform: rotate(var(--a, 0deg)) translateY(-16px);
  filter: brightness(1.35);
  box-shadow: 0 0 20px rgba(217, 182, 98, .5), -4px 2px 12px rgba(0, 0, 0, .55);
  z-index: 3;
}
.fan .fc.gone { transform: translateY(-70px) scale(.5) !important; opacity: 0; pointer-events: none; }
.fanhint {
  position: absolute; left: 50%; bottom: 224px; transform: translateX(-50%); z-index: 8;
  font-size: 10px; letter-spacing: .24em; text-indent: .24em; color: var(--mist); white-space: nowrap;
  opacity: 0; transition: opacity .8s ease; pointer-events: none;
}
.fanhint.on { opacity: 1; }

/* ---------- 台前操作 ---------- */
.console {
  position: absolute; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 11;
  width: min(90%, 440px); display: flex; flex-direction: column; gap: 11px; align-items: center;
  transition: opacity .5s ease;
}
.console.off { opacity: 0; pointer-events: none; }
.gbtn {
  font-family: var(--serif); font-size: 14px; letter-spacing: .3em; text-indent: .3em; font-weight: 500;
  color: #201a08; background: linear-gradient(135deg, var(--gold-hi), #a9853f);
  border: none; border-radius: 26px; padding: 12px 30px; cursor: pointer;
  box-shadow: 0 6px 30px rgba(217, 182, 98, .4);
  display: none;
}
.gbtn.on { display: block; }
.gbtn:active { transform: scale(.97); }
/* 四个主题一行放下，不横滑：等宽自适应 */
.chips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; width: 100%; }
.chip {
  font-family: var(--serif); font-size: 12.5px; font-weight: 300; letter-spacing: .04em; color: var(--mist);
  padding: 8px 4px; cursor: pointer; background: rgba(20, 16, 51, .55);
  border: 1px solid rgba(184, 168, 232, .22); border-radius: 20px; backdrop-filter: blur(5px);
  transition: all .3s ease;
  display: flex; align-items: center; justify-content: center; gap: 5px; line-height: 1; min-width: 0;
}
.chip .ci { display: inline-flex; color: var(--gold); flex: none; }
.chip .ci svg { width: 15px; height: 15px; display: block; }
.chip:active { color: var(--silver); border-color: rgba(217, 182, 98, .55); }
.chip:active .ci { color: var(--gold-hi); }
.row { display: flex; gap: 10px; width: 100%; }
.row input {
  flex: 1; background: rgba(20, 16, 51, .6); border: 1px solid rgba(184, 168, 232, .24);
  border-radius: 22px; padding: 12px 17px; color: var(--silver);
  font-family: var(--serif); font-size: 14px; outline: none;
}
.row input::placeholder { color: var(--mist-dim); }
.row input:focus { border-color: rgba(217, 182, 98, .5); }
.row input:disabled { opacity: .45; }
.row button {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(135deg, var(--gold-hi), #a9853f); color: #201a08; font-size: 17px;
  display: grid; place-items: center; line-height: 1; padding: 0;
}
.row button:disabled { opacity: .4; }
/* 语音输入麦克风：无 SpeechRecognition 的环境隐藏，退回打字 */
#micBtn {
  background: rgba(20, 16, 51, .6); border: 1px solid rgba(184, 168, 232, .3);
  color: var(--lav); font-size: 18px;
}
#micBtn.hidden { display: none; }
#micBtn.rec {
  background: linear-gradient(135deg, #d98a8a, #a94f4f); color: #fff; border-color: transparent;
  animation: micpulse 1.1s ease-in-out infinite;
}
@keyframes micpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(217, 138, 138, .5); } 50% { box-shadow: 0 0 0 8px rgba(217, 138, 138, 0); } }
.fine {
  font-size: 9px; letter-spacing: .1em; color: rgba(154, 147, 184, .42);
  text-align: center; margin-top: 2px;
}

/* ---------- 开场 ---------- */
.intro {
  position: absolute; inset: 0; z-index: 20; background: var(--abyss-0); cursor: pointer;
  display: grid; place-items: center; text-align: center; transition: opacity 1.6s ease;
}
.intro.gone { opacity: 0; pointer-events: none; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.intro .cn {
  font-size: 32px; font-weight: 300; letter-spacing: .62em; text-indent: .62em; color: var(--gold);
  text-shadow: 0 0 34px rgba(217, 182, 98, .4); opacity: 0; animation: fadeUp 1.8s ease .2s forwards;
}
.intro .en {
  font-size: 10px; letter-spacing: .5em; color: var(--mist-dim); margin-top: 18px;
  text-transform: uppercase; opacity: 0; animation: fadeUp 1.8s ease .9s forwards;
}
.intro .go {
  font-size: 12px; letter-spacing: .4em; text-indent: .4em; color: var(--mist); margin-top: 52px;
  opacity: 0; animation: fadeUp 1.8s ease 1.7s forwards, blink 2.6s ease 3.4s infinite;
}

@media (prefers-reduced-motion: reduce) {
  .luna .inner, .luna .orbfx, .luna .orbits { animation: none !important; }
}

/* 短屏（横屏手机 / 小设备）：缩小立绘与大牌，避免溢出遮挡 */
@media (max-height: 640px) {
  .luna .lart { width: min(38vh, 180px); }
  .luna { top: 34%; }
  #bigcard { height: min(46vh, 300px); }
  #strip { top: 40px; }
  .subtitle .line { max-height: 22vh; }
}
/* 大屏（平板 / 桌面）：立绘与字幕适度放大，居中不发散 */
@media (min-width: 820px) {
  .luna .lart { width: 300px; }
  .subtitle { width: min(70%, 520px); }
  .subtitle .line { font-size: clamp(15px, 1.6vw, 18px); }
}
