/* ═══════════════ 答案之书 · 深紫夜空主题 ═══════════════ */
:root {
  --bg1: #150d2e;
  --bg2: #241547;
  --bg3: #0d0820;
  --gold: #fbbf24;
  --gold-soft: #fde68a;
  --purple: #a78bfa;
  --text: #ede9fe;
  --muted: #9d94b8;
  --card: rgba(255, 255, 255, .06);
  --card-border: rgba(167, 139, 250, .25);
  --danger: #f87171;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: radial-gradient(120% 90% at 50% 0%, var(--bg2), var(--bg1) 58%, var(--bg3) 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 96px; /* 给 tabbar 留位 */
  overflow-x: hidden;
}

/* ═══════════════ 星空 ═══════════════ */
#stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.star {
  position: absolute;
  background: #fff;
  border-radius: 50%;
  opacity: .2;
  animation: twinkle 3s ease-in-out infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: .15; transform: scale(1); }
  50% { opacity: .9; transform: scale(1.35); }
}

#sparkle {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

/* ═══════════════ 顶栏 ═══════════════ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  padding: 14px 18px;
  background: rgba(21, 13, 46, .82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(167, 139, 250, .15);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--gold-soft);
  background: radial-gradient(circle at 35% 30%, #4c2f8f, #2a1752 75%);
  border-radius: 14px;
  box-shadow: 0 0 20px rgba(167, 139, 250, .35);
}
.brand-title { font-size: 18px; font-weight: 800; letter-spacing: 1px; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 2px; text-transform: uppercase; }

/* ═══════════════ 主区域 ═══════════════ */
main { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 22px 18px 30px; }

.screen { display: none; animation: screenIn .3s ease; }
.screen.active { display: block; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

h2 { font-size: 20px; margin-bottom: 4px; }
.page-hint { margin-bottom: 16px; }
.muted { color: var(--muted); font-size: 13px; }

/* ═══════════════ 翻书页 ═══════════════ */
.hint {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 1px;
  margin-bottom: 14px;
}

#questionInput {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 12px 16px;
  resize: none;
  outline: none;
  transition: border-color .2s;
}
#questionInput:focus { border-color: var(--purple); }
#questionInput::placeholder { color: #6d6489; }

/* 书本 */
.book {
  position: relative;
  width: 168px; height: 168px;
  margin: 26px auto 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 28%, #4c2f8f, #251349 72%);
  border-radius: 50%;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform .18s ease, box-shadow .3s;
  box-shadow:
    0 0 46px rgba(167, 139, 250, .38),
    0 0 100px rgba(96, 58, 190, .22),
    inset 0 0 34px rgba(0, 0, 0, .45);
  animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: 0 0 46px rgba(167,139,250,.38), 0 0 100px rgba(96,58,190,.22), inset 0 0 34px rgba(0,0,0,.45); }
  50% { box-shadow: 0 0 60px rgba(167,139,250,.5), 0 0 130px rgba(96,58,190,.3), inset 0 0 34px rgba(0,0,0,.45); }
}
.book:active { transform: scale(.94); }
.book-inner { line-height: 1; filter: drop-shadow(0 6px 14px rgba(0, 0, 0, .55)); }
.book-caption {
  margin-top: 8px;
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--gold-soft);
  opacity: .8;
}
.book-glow {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  border: 1px solid rgba(251, 191, 36, .18);
  animation: haloPulse 3.4s ease-in-out infinite;
  pointer-events: none;
}
@keyframes haloPulse {
  0%, 100% { transform: scale(1); opacity: .35; }
  50% { transform: scale(1.08); opacity: .8; }
}

/* 大按钮 */
.big-btn {
  display: block;
  width: 100%;
  margin: 16px auto 8px;
  padding: 15px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 2px;
  color: #3b2506;
  background: linear-gradient(135deg, var(--gold-soft), var(--gold));
  border: none;
  border-radius: 18px;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(251, 191, 36, .3);
  transition: transform .15s, box-shadow .2s, opacity .2s;
}
.big-btn:active { transform: scale(.97); }
.big-btn:disabled { opacity: .55; }
.big-btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--card-border);
  box-shadow: none;
}
.big-btn.danger { color: var(--danger); border-color: rgba(248, 113, 113, .35); }

/* 答案卡片 */
.answer-card {
  margin-top: 22px;
  padding: 26px 20px 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .03));
  border: 1px solid rgba(251, 191, 36, .28);
  border-radius: 22px;
  text-align: center;
  animation: answerIn .55s cubic-bezier(.2, .8, .3, 1.2);
}
@keyframes answerIn {
  from { opacity: 0; transform: translateY(22px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.answer-label {
  font-size: 11px;
  letter-spacing: 5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.answer-text {
  font-family: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  font-size: clamp(26px, 8vw, 40px);
  font-weight: 700;
  line-height: 1.55;
  min-height: 1.55em;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, #fff7e0 8%, var(--gold-soft) 45%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  text-shadow: 0 0 30px rgba(251, 191, 36, .18);
  padding: 6px 0 10px;
}
.answer-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}
.mini-btn {
  padding: 9px 18px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  cursor: pointer;
  transition: transform .15s, border-color .2s;
}
.mini-btn:active { transform: scale(.95); }
.mini-btn.gold { color: var(--gold-soft); border-color: rgba(251, 191, 36, .4); }

/* 沉思动画 */
.thinking {
  margin-top: 22px;
  padding: 34px 20px;
  text-align: center;
  background: var(--card);
  border: 1px dashed var(--card-border);
  border-radius: 22px;
}
.book-spin {
  animation: bookFlip 1.1s ease-in-out infinite;
  display: inline-block;
  filter: drop-shadow(0 0 14px rgba(251, 191, 36, .35));
}
@keyframes bookFlip {
  0%, 100% { transform: rotateY(0deg) scale(1); }
  50% { transform: rotateY(180deg) scale(1.06); }
}
.thinking-text {
  margin-top: 14px;
  color: var(--gold-soft);
  font-size: 15px;
  letter-spacing: 2px;
  animation: textPulse 1.4s ease-in-out infinite;
}
@keyframes textPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

/* ═══════════════ 历史页 ═══════════════ */
.history-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.history-item {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 12px 16px;
  animation: screenIn .25s ease;
}
.history-q {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
  word-break: break-all;
}
.history-a {
  font-size: 16px;
  font-weight: 700;
  color: var(--gold-soft);
}
.history-t {
  font-size: 11px;
  color: #6d6489;
  margin-top: 5px;
  text-align: right;
}
.empty {
  text-align: center;
  color: var(--muted);
  padding: 46px 10px;
  font-size: 14px;
  line-height: 2;
}

/* ═══════════════ 统计页 ═══════════════ */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 18px 0 14px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 18px 10px;
  text-align: center;
}
.stat-num {
  font-size: 34px;
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stats-note {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
  margin-bottom: 20px;
}

/* ═══════════════ 底部导航 ═══════════════ */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  background: rgba(21, 13, 46, .92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid rgba(167, 139, 250, .15);
  padding: 6px 10px calc(6px + env(safe-area-inset-bottom));
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  border-radius: 14px;
  transition: color .2s, background .2s;
}
.tab-icon { width: 22px; height: 22px; margin-bottom: 1px; }
.tab-btn.active { color: var(--gold); background: rgba(251, 191, 36, .08); }

/* ═══════════════ Toast ═══════════════ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%) translateY(16px);
  background: rgba(50, 33, 100, .95);
  border: 1px solid var(--card-border);
  color: var(--text);
  font-size: 14px;
  padding: 10px 22px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: all .3s;
  z-index: 99;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ═══════════════ 小屏适配 ═══════════════ */
@media (max-width: 360px) {
  .book { width: 140px; height: 140px; }
  .book-inner { font-size: 56px; }
  .stat-num { font-size: 28px; }
}
