/* ============================================================
   毛主席语录卡 — 极简样式
   红色主题，克制简洁
   ============================================================ */
:root {
  --bg: #faf7f2;
  --ink: #2a2a2a;
  --ink-soft: #5e5a52;
  --ink-mute: #9b958a;
  --line: #ece6db;
  --paper: #ffffff;
  --paper-warm: #fdfaf3;

  --red: #b22222;
  --red-light: #c93a3a;
  --red-dark: #8a1a1a;
  --red-pale: #b2222214;
  --red-glow: #b2222255;
  --red-glow-soft: #b2222222;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(40, 30, 20, 0.04), 0 2px 6px rgba(40, 30, 20, 0.04);
  --shadow-md: 0 4px 14px rgba(40, 30, 20, 0.06), 0 12px 32px rgba(40, 30, 20, 0.08);

  --serif: "Noto Serif SC", "Songti SC", "STSong", "Source Han Serif SC", "FangSong", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --t-flip: 1.2s;
  --t-glow: 1s;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ===== 顶部栏 ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px 14px;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color .3s var(--ease);
  gap: 12px;
}
.topbar.is-scrolled { border-bottom-color: var(--line); }
.brand-spacer {
  width: 60px;
  flex: 0 0 auto;
}
.tabs { display: flex; gap: 4px; }
.tab {
  position: relative;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--ink-mute);
  font-size: 14px;
  transition: color .2s var(--ease), background .2s var(--ease);
}
.tab:hover { color: var(--ink-soft); }
.tab.is-active { color: var(--ink); background: var(--paper); box-shadow: var(--shadow-sm); }
.tab-count {
  display: inline-block;
  margin-left: 6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  font-size: 11px; line-height: 18px; text-align: center;
  border-radius: 999px;
  background: var(--line);
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.tab-count:empty { display: none; }

.sound-toggle {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--ink-mute);
  transition: color .2s var(--ease), background .2s var(--ease), transform .15s var(--ease);
  flex: 0 0 auto;
}
.sound-toggle:hover { color: var(--ink); background: var(--paper); }
.sound-toggle:active { transform: scale(0.94); }
.sound-toggle:focus-visible { outline: 2px solid rgba(42,42,42,0.28); outline-offset: 3px; }
.sound-toggle svg { display: block; }
.sound-toggle .icon-sound-on { display: none !important; }
.sound-toggle .icon-sound-off { display: block !important; }
.sound-toggle:not(.is-muted) .icon-sound-on { display: block !important; }
.sound-toggle:not(.is-muted) .icon-sound-off { display: none !important; }

/* ===== 舞台 ===== */
.stage {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 24px 80px;
  min-height: calc(100vh - 60px);
  min-height: calc(100dvh - 60px);
  display: flex;
  flex-direction: column;
}
.view { display: none; flex: 1; }
.view.is-active { display: flex; flex-direction: column; }

/* ===== 抽卡页 ===== */
.view-draw {
  align-items: center;
  padding-top: 12vh;
}
.eyebrow {
  margin: 0 0 28px;
  font-size: 13px;
  color: var(--ink-mute);
  text-align: center;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.draw-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.hero-img {
  width: 200px;
  height: 200px;
  object-fit: contain;
  border-radius: 50%;
  flex-shrink: 0;
}

.hero-title {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--red);
  text-align: center;
}
.draw-btn {
  align-self: center;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 200px;
  padding: 18px 40px;
  border-radius: 999px;
  background: var(--red);
  color: var(--paper);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.14em;
  box-shadow: 0 4px 16px rgba(178, 34, 34, 0.25);
  transition: transform .25s var(--ease), background .25s var(--ease), box-shadow .25s var(--ease);
}
.draw-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(178, 34, 34, 0.32); background: var(--red-light); }
.draw-btn:active { transform: translateY(0); }
.draw-btn:disabled { background: var(--line); color: var(--ink-mute); box-shadow: none; }

.meaning {
  margin: 0;
  min-height: 1.6em;
  text-align: center;
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
}

.hint {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-mute);
}

/* ===== 揭晓页 ===== */
.view-reveal {
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding-top: 24px;
}

.card {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 5 / 6;
  perspective: 1400px;
  position: relative;
  cursor: grab;
  touch-action: none;
  user-select: none;
  outline: none;
}
.card:focus-visible .card-inner { outline: 2px solid rgba(42, 42, 42, 0.28); outline-offset: 6px; }
.card[data-state="front"] { cursor: default; }
.card.is-dragging { cursor: grabbing; }

.card-halo {
  position: absolute;
  inset: -28%;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 50%,
    var(--card-glow, transparent) 0%,
    var(--card-glow-soft, transparent) 38%,
    transparent 70%
  );
  opacity: 0;
  transform: scale(0.88);
  filter: blur(18px);
  transition: opacity 1.2s var(--ease), transform 1.2s var(--ease);
  pointer-events: none;
}
.card[data-state="front"] .card-halo {
  animation: haloBurst 0.8s var(--ease);
  opacity: 0.9;
  transform: scale(1);
}

@keyframes haloBurst {
  0%   { opacity: 0;   transform: scale(0.6); filter: blur(8px); }
  55%  { opacity: 1;   transform: scale(1.18); filter: blur(26px); }
  100% { opacity: 0.9; transform: scale(1);    filter: blur(18px); }
}

.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  z-index: 1;
}
.card.is-dragging .card-face { transition: none; }

.card-face {
  position: absolute; inset: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  -webkit-backface-visibility: hidden;
          backface-visibility: hidden;
  overflow: hidden;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 30px 28px;
  background: var(--paper);
  transition: transform var(--t-flip) var(--ease), opacity .3s var(--ease), box-shadow var(--t-glow) var(--ease);
}

.card-back {
  background:
    radial-gradient(circle at 28% 22%, rgba(255,255,255,0.25), transparent 32%),
    radial-gradient(circle at 70% 78%, rgba(255,255,255,0.12), transparent 34%),
    var(--card-back, var(--red));
  color: var(--card-back-ink, var(--paper));
  gap: 16px;
}
.card-back-ring {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 2px solid rgba(212, 168, 67, 0.35);
  box-shadow:
    0 0 0 8px rgba(212, 168, 67, 0.10),
    0 0 0 16px rgba(212, 168, 67, 0.06),
    inset 0 0 20px rgba(212, 168, 67, 0.08);
}

.card-front {
  background: var(--card-bg, var(--paper));
  color: var(--card-ink, var(--ink));
  text-align: center;
  gap: 24px;
}

.card[data-state="back"] .card-back {
  opacity: 1;
  transform: rotateY(var(--drag-rotation, 0deg));
}
.card[data-state="back"] .card-front {
  opacity: 0;
  transform: rotateY(-180deg);
}
.card[data-state="front"] .card-back {
  opacity: 0;
  transform: rotateY(180deg);
}
.card[data-state="front"] .card-front {
  opacity: 1;
  transform: rotateY(0deg);
}
.card[data-state="front"] .card-front {
  box-shadow:
    0 4px 14px rgba(40, 30, 20, 0.06),
    0 12px 32px rgba(40, 30, 20, 0.08),
    0 0 60px var(--card-glow, transparent),
    0 0 140px var(--card-glow-soft, transparent);
}
.card.is-dragging .card-face {
  box-shadow:
    0 4px 14px rgba(40, 30, 20, 0.06),
    0 12px 32px rgba(40, 30, 20, 0.08),
    0 0 64px var(--card-glow, transparent);
}

.card-text {
  margin: 0;
  font-family: var(--serif);
  font-size: 24px;
  line-height: 1.72;
  letter-spacing: 0.02em;
  white-space: pre-wrap;
  word-break: break-word;
  text-align: center;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-chapter {
  margin: 0;
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-mute);
  letter-spacing: 0.08em;
}

.flip-hint {
  margin: 22px 0 -4px;
  text-align: center;
  font-family: var(--serif);
  font-size: 13px;
  color: var(--ink-mute);
  letter-spacing: 0.14em;
  opacity: 0;
  transition: opacity .45s var(--ease);
  pointer-events: none;
  user-select: none;
}
.card[data-state="back"] ~ .flip-hint {
  opacity: 1;
  transition-delay: .55s;
}
.card[data-state="front"] ~ .flip-hint {
  opacity: 0;
  transition-delay: 0s;
}

.reveal-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(8px);
  visibility: hidden;
  pointer-events: none;
  transition: opacity .5s var(--ease) .2s, transform .5s var(--ease) .2s, visibility 0s linear .7s;
}
.card[data-state="front"] ~ .reveal-actions {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
  transition-delay: .2s, .2s, 0s;
}

.primary, .ghost {
  padding: 12px 22px;
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: 0.05em;
  transition: background .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}
.primary { background: var(--red); color: var(--paper); }
.primary:hover { background: var(--red-light); }
.ghost { background: transparent; color: var(--ink-soft); }
.ghost:hover { background: var(--paper); color: var(--ink); }

.icon-btn {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .2s var(--ease), color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
}
.icon-btn:hover {
  color: var(--ink);
  background: var(--paper-warm);
  box-shadow: var(--shadow-md);
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn:focus-visible {
  outline: 2px solid rgba(42, 42, 42, 0.28);
  outline-offset: 3px;
}
.icon-btn[aria-busy="true"] { opacity: 0.55; pointer-events: none; }
.icon-btn svg { display: block; width: 20px; height: 20px; }
.icon-btn .icon-check { display: none; }
.icon-btn.is-success .icon-download { display: none; }
.icon-btn.is-success .icon-check { display: block; }
.icon-btn.is-success { background: var(--red); color: #ffffff; }

/* ===== 历史页 ===== */
.view-history {
  padding-top: 8px;
}
.history-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 20px;
}
.history-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 500;
  color: var(--ink);
}

.history-day {
  margin: 0 0 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.history-day:last-child { border-bottom: 0; }
.history-day-date {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.history-items {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.history-item {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 14px 16px;
  background: var(--paper);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
  border-left: 3px solid var(--red-pale);
}
.history-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.history-item-text {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink-soft);
  letter-spacing: 0.01em;
  white-space: pre-wrap;
  word-break: break-word;
}
.history-item-chapter {
  margin: 0;
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: 0.04em;
}

.history-empty {
  text-align: center;
  color: var(--ink-mute);
  font-family: var(--serif);
  font-size: 15px;
  margin-top: 60px;
  letter-spacing: 0.05em;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  background: rgba(42, 42, 42, 0.92);
  color: #faf7f2;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.05em;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s var(--ease), transform .3s var(--ease);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
}
.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== 响应式 ===== */
@media (max-width: 520px) {
  .stage { padding: 24px 16px 60px; }
  .topbar { padding: 12px 16px 10px; }
  .brand-spacer { width: 50px; }
  .tab { padding: 6px 10px; font-size: 13px; }
  .tab-count { margin-left: 4px; min-width: 16px; height: 16px; font-size: 10px; line-height: 16px; }
  .draw-btn { min-width: 180px; padding: 16px 32px; font-size: 15px; }
  .eyebrow { font-size: 12px; margin-bottom: 22px; }
  .card { max-width: 320px; }
  .card-face { padding: 24px 20px; }
  .card-text { font-size: 20px; line-height: 1.68; }
  .hero-img { width: 170px; height: 170px; }
  .hero-title { font-size: 26px; }
  .card-back-ring { width: 80px; height: 80px; }
  .history-items { grid-template-columns: 1fr; }
  .reveal-actions { width: 100%; max-width: 300px; }
  .reveal-actions .primary, .reveal-actions .ghost { flex: 1; }
  .icon-btn { width: 40px; height: 40px; }
  .icon-btn svg { width: 18px; height: 18px; }
  .toast { top: 12px; font-size: 12px; padding: 9px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
  .card-face { transition: none !important; }
  .flip-hint { opacity: 1 !important; transition: none !important; }
  @keyframes haloBurst { from, to { opacity: 0.9; transform: scale(1); filter: blur(18px); } }
}
