/* ============ 基础 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --gold: #d4af37;
  --gold-light: #f6e27a;
  --purple: #2b1c50;
  --purple-dark: #150f30;
  --text: #f2e6c9;
  --text-dim: #b9a883;
}

html, body {
  font-family: 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
  background: radial-gradient(120% 90% at 50% 0%, #2b1c50 0%, #150f30 55%, #0d0920 100%);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }

/* 星空背景点缀 */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 80% 10%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 45% 65%, #f6e27a 50%, transparent 51%),
    radial-gradient(1px 1px at 90% 45%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 25% 85%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 65% 30%, #c9b6ff 50%, transparent 51%),
    radial-gradient(1px 1px at 5% 50%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 80%, #fff 50%, transparent 51%);
  animation: twinkle 4s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.5; } to { opacity: 1; } }

.container {
  position: relative; z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* ============ 屏幕切换 ============ */
.screen { display: none; }
.screen.active { display: block; animation: fadeUp 0.5s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ============ 顶部返回链接 ============ */
.top-bar { padding: 8px 0 0; }
.top-bar .back-link {
  display: inline-block; font-size: 14px; color: var(--text-dim);
  letter-spacing: 1px; padding: 6px 10px; border-radius: 8px;
}
.top-bar .back-link:active { color: var(--gold-light); }

/* ============ 首页 ============ */
.hero { text-align: center; padding: 18px 0 26px; }
.logo {
  font-size: 40px; color: var(--gold-light);
  text-shadow: 0 0 24px rgba(246, 226, 122, 0.35);
  animation: floaty 3s ease-in-out infinite;
}
@keyframes floaty { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.hero h1 {
  font-size: 30px; letter-spacing: 8px; margin-top: 6px;
  background: linear-gradient(180deg, #f6e27a, #d4af37);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero .sub { color: var(--text-dim); font-size: 13px; margin-top: 8px; letter-spacing: 2px; }
.hero .disclaimer {
  display: inline-block; margin-top: 12px; padding: 4px 12px;
  font-size: 12px; color: var(--text-dim);
  border: 1px solid rgba(212, 175, 55, 0.35); border-radius: 20px;
}

.section-title {
  text-align: center; color: var(--text-dim); font-size: 13px;
  letter-spacing: 4px; margin: 20px 0 14px;
}

.spread-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%; margin-bottom: 14px; padding: 16px 18px;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.12), rgba(212, 175, 55, 0.03));
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 14px;
  text-align: left;
  transition: transform 0.2s, border-color 0.2s;
}
.spread-card:active { transform: scale(0.97); border-color: var(--gold); }
.spread-icon {
  font-size: 26px; color: var(--gold-light); width: 40px; text-align: center;
  flex-shrink: 0;
}
.spread-name { font-size: 17px; letter-spacing: 1px; color: var(--text); }
.spread-desc { display: block; font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.spread-count {
  margin-left: auto; font-size: 11px; color: var(--gold-light);
  border: 1px solid rgba(212, 175, 55, 0.4); border-radius: 12px; padding: 3px 8px;
  flex-shrink: 0;
}

/* ============ 抽牌页 ============ */
.pick-back { padding: 4px 0 0; }
.pick-back button {
  font-size: 14px; color: var(--text-dim); letter-spacing: 1px;
  padding: 6px 10px; border-radius: 8px;
}
.pick-back button:active { color: var(--gold-light); }
.pick-head { text-align: center; padding: 8px 0 4px; }
.pick-head h2 { font-size: 22px; letter-spacing: 4px; color: var(--gold-light); }
.pick-head .hint { font-size: 13px; color: var(--text-dim); margin-top: 8px; line-height: 1.7; }
#pick-count {
  text-align: center; font-size: 13px; color: var(--gold-light);
  letter-spacing: 2px; margin: 10px 0 4px;
}

/* 抽牌槽位（吸顶：滚动牌堆时已抽区域始终可见） */
#slots {
  display: flex; justify-content: center; gap: 10px;
  padding: 10px 0 6px; min-height: 158px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(180deg, #150f30 78%, rgba(21, 15, 48, 0));
}
.slot { width: 22.5%; max-width: 96px; text-align: center; }
.slot-card {
  position: relative; width: 100%; aspect-ratio: 300 / 520;
  border: 1px dashed rgba(212, 175, 55, 0.4); border-radius: 8px;
  overflow: hidden;
  background: rgba(212, 175, 55, 0.05);
}
.slot-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* 未抽中前：牌背隐藏，槽位只显示虚线空位占位 */
.slot-card .back { opacity: 0; transition: opacity 0.35s ease; }
.slot.occupied .slot-card .back { opacity: 1; }
/* 空位占位符：提醒这个位置会落下抽到的牌 */
.slot-ph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: rgba(212, 175, 55, 0.4);
  transition: opacity 0.3s ease; user-select: none;
}
.slot.occupied .slot-ph { opacity: 0; }
.slot-card .face {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; transform: rotateY(180deg);
  transition: opacity 0.4s, transform 0.6s;
}
.slot-card.revealed .face { opacity: 1; transform: rotateY(0deg); }
.slot-card.revealed img.back { display: none; }
.slot-card .face.reversed { transform: rotateY(0deg) rotate(180deg); }
.slot-label {
  margin-top: 6px; font-size: 12px; color: var(--text-dim); letter-spacing: 1px;
}
.slot.filled .slot-card { border-color: var(--gold); border-style: solid; }

/* 平铺牌堆：洗牌后牌背向上铺开 */
#fan-area { margin-top: 8px; }
#fan {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  padding: 4px 2px 10px;
}
.fan-card {
  position: relative;
  width: 100%;
  aspect-ratio: 300 / 520;
  transform: translate(var(--pileX, 0), var(--pileY, 0)) rotate(var(--r, 0deg));
  transform-origin: center center;
  cursor: pointer;
  transition: transform 0.6s cubic-bezier(0.25, 0.6, 0.3, 1), filter 0.25s;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45));
}
.fan-card.dealt {
  transform: rotate(var(--r, 0deg));
  transition-delay: 0ms;
}
.fan-card img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 6px; }
.fan-card:hover { filter: drop-shadow(0 4px 12px rgba(246, 226, 122, 0.35)) brightness(1.12); }
.fan-card.flying {
  z-index: 999 !important;
  transform: translate(var(--dx, 0), var(--dy, 0)) rotate(0deg) scale(1.05);
  transition: transform 0.5s cubic-bezier(0.3, 0.1, 0.3, 1), opacity 0.5s;
  transition-delay: 0ms;
  opacity: 0.9;
  pointer-events: none;
}
/* 抽走后：保留网格空位，不补位，牌淡出 */
.fan-card.picked-out {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

/* ============ 结果页 ============ */
.result-hero { text-align: center; padding: 8px 0 16px; }
.result-hero h2 { font-size: 22px; letter-spacing: 4px; color: var(--gold-light); }
.result-hero .sub { font-size: 13px; color: var(--text-dim); margin-top: 6px; }

/* 综合解读：多张牌整合成一段总述 */
.result-summary {
  padding: 18px 16px; margin-bottom: 18px;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.16), rgba(212, 175, 55, 0.04));
  border: 1px solid rgba(212, 175, 55, 0.45);
  border-radius: 14px;
  animation: fadeUp 0.5s ease both;
}
.rs-title {
  text-align: center; font-size: 17px; letter-spacing: 4px;
  color: var(--gold-light); margin-bottom: 10px;
}
.rs-text { font-size: 14.5px; line-height: 2; color: var(--text); }
.rs-cards-title {
  text-align: center; color: var(--text-dim); font-size: 13px;
  letter-spacing: 4px; margin: 4px 0 14px;
}

.result-card {
  display: flex; gap: 14px; margin-bottom: 16px; padding: 16px;
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.1), rgba(212, 175, 55, 0.02));
  border: 1px solid rgba(212, 175, 55, 0.3); border-radius: 14px;
  animation: fadeUp 0.5s ease both;
}
.result-card:nth-child(2) { animation-delay: 0.15s; }
.result-card:nth-child(3) { animation-delay: 0.3s; }
.result-card:nth-child(4) { animation-delay: 0.45s; }
.result-card:nth-child(5) { animation-delay: 0.6s; }

.rc-img { flex-shrink: 0; width: 96px; }
.rc-img img { width: 100%; border-radius: 8px; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4); display: block; }
.rc-img img.reversed-img { transform: rotate(180deg); }

.rc-body { flex: 1; min-width: 0; }
.rc-pos { font-size: 12px; color: var(--gold-light); letter-spacing: 2px; }
.rc-note { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.rc-name { font-size: 19px; margin-top: 6px; letter-spacing: 1px; }
.rc-en { font-size: 12px; color: var(--text-dim); font-weight: normal; margin-left: 6px; letter-spacing: 1px; }
.rc-badge {
  display: inline-block; margin-top: 8px; padding: 2px 10px; border-radius: 12px;
  font-size: 11px; letter-spacing: 2px;
}
.rc-badge.upright { color: #241a10; background: linear-gradient(135deg, var(--gold-light), var(--gold)); }
.rc-badge.reversed { color: #f2e6c9; background: rgba(120, 90, 200, 0.35); border: 1px solid rgba(180, 150, 255, 0.4); }
.rc-kw { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.kw {
  font-size: 11px; color: var(--text); padding: 2px 8px;
  border: 1px solid rgba(212, 175, 55, 0.35); border-radius: 10px; background: rgba(212, 175, 55, 0.08);
}
.rc-text { font-size: 14px; line-height: 1.8; color: var(--text); margin-top: 10px; }

.result-actions { display: flex; gap: 12px; justify-content: center; margin-top: 22px; }
.btn {
  padding: 12px 30px; border-radius: 30px; font-size: 15px; letter-spacing: 2px;
  transition: transform 0.2s;
}
.btn:active { transform: scale(0.95); }
.btn-gold { color: #241a10; background: linear-gradient(135deg, var(--gold-light), var(--gold)); }
.btn-ghost { color: var(--text); border: 1px solid rgba(212, 175, 55, 0.5); }

.footer {
  text-align: center; font-size: 11px; color: var(--text-dim);
  line-height: 1.8; margin-top: 30px; padding-top: 16px;
  border-top: 1px solid rgba(212, 175, 55, 0.2);
}

/* ============ 小幅屏幕适配 ============ */
@media (max-width: 380px) {
  #fan { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .rc-img { width: 84px; }
}