/* ===== Reset & Base ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f8f6f4;
  --bg-end: #f2f0ee;
  --card-bg: rgba(255, 255, 255, 0.7);
  --card-border: rgba(0, 0, 0, 0.06);
  --text-primary: #1a1a1a;
  --text-secondary: #8c8c8c;
  --accent: #d98c5a;
  --accent-end: #cf7a4d;
  --accent-shadow: rgba(217, 140, 90, 0.3);
  --nav-bg: rgba(255, 255, 255, 0.85);
  --nav-shadow: rgba(0, 0, 0, 0.04);
  --divider: rgba(0, 0, 0, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141415;
    --bg-end: #1e1d20;
    --card-bg: rgba(40, 40, 42, 0.75);
    --card-border: rgba(255, 255, 255, 0.06);
    --text-primary: #f2f2f2;
    --text-secondary: #8c8c8c;
    --accent-shadow: rgba(217, 140, 90, 0.35);
    --nav-bg: rgba(26, 26, 28, 0.9);
    --nav-shadow: rgba(0, 0, 0, 0.15);
    --divider: rgba(255, 255, 255, 0.06);
  }
}

html {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-end) 100%);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  width: 100%;
}

body.preview-open {
  overflow: hidden;
  touch-action: none;
}

/* ===== App Shell ===== */
#app {
  --card-scale: 1;
  width: min(100%, max(430px, 90vw), 760px);
  max-width: 760px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* ===== Pages ===== */
.page {
  position: absolute;
  inset: 0 0 calc(52px + env(safe-area-inset-bottom, 0px)) 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform: translateY(8px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#page-home {
  inset: 0;
}

.page.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Hide scrollbar */
.page::-webkit-scrollbar { display: none; }
.page { scrollbar-width: none; }

/* ===== Home ===== */
.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 0;
  position: relative;
}

.btn-draw {
  background: linear-gradient(135deg, var(--accent), var(--accent-end));
  color: #fff;
  border: none;
  padding: 14px 40px;
  border-radius: 25px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--accent-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  margin-top: 40px;
  flex-shrink: 0;
}

.btn-draw:active {
  transform: scale(0.96);
  box-shadow: 0 2px 12px var(--accent-shadow);
}

/* ===== Result ===== */
.result-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 24px;
  padding-top: env(safe-area-inset-top, 16px);
  height: 100%;
}

.back-btn {
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 8px;
  margin: 4px 0 8px -8px;
  cursor: pointer;
  border-radius: 12px;
  transition: background 0.2s;
}

.back-btn:active {
  background: var(--card-bg);
}

.card-container {
  position: relative;
  width: 100%;
  max-width: 300px;
  aspect-ratio: 5 / 7;
  margin: 0 auto 24px;
  flex-shrink: 0;
}

.card-container::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 24px;
  background: rgba(248, 246, 244, 0);
  backdrop-filter: blur(0);
  -webkit-backdrop-filter: blur(0);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, backdrop-filter 0.2s ease;
  z-index: 3;
}

.card-container::before {
  content: "抽卡中…";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 4;
  transform: translate(-50%, -50%) scale(0.96);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  color: rgba(26, 26, 26, 0.72);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.card-container.is-loading::after {
  opacity: 1;
  background: rgba(248, 246, 244, 0.18);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.card-container.is-loading::before {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.card-glow {
  position: absolute;
  inset: -8px;
  border-radius: 32px;
  background: var(--accent);
  opacity: 0.08;
  filter: blur(24px);
  pointer-events: none;
}

.card-text-wrap {
  position: absolute;
  top: 30px;
  left: 16px;
  right: 16px;
  z-index: 2;
  display: flex;
  justify-content: center;
  opacity: 0;
  transform: scaleY(1.22) scaleX(0.96);
  transform-origin: center bottom;
  clip-path: inset(100% 0 0 0);
  filter: blur(6px);
  transition:
    opacity 0.42s ease,
    transform 0.63s cubic-bezier(0.2, 0.8, 0.2, 1),
    clip-path 0.63s cubic-bezier(0.2, 0.8, 0.2, 1),
    filter 0.45s ease;
  pointer-events: none;
}

.card-text-wrap.show {
  opacity: 1;
  transform: scaleY(1) scaleX(1);
  clip-path: inset(0 0 0 0);
  filter: blur(0);
}

.card-text {
  max-width: min(100%, 200px);
  padding: 0;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.84);
  text-align: center;
  font-family: "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", sans-serif;
  font-size: clamp(32px, 9vw, 42px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  word-break: keep-all;
  text-wrap: nowrap;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.14),
    0 6px 22px rgba(0, 0, 0, 0.22);
  opacity: 1;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 24px;
  position: relative;
  z-index: 1;
  cursor: zoom-in;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  border: 0.5px solid var(--card-border);
  transition: opacity 0.2s ease, transform 0.2s ease, filter 0.2s ease;
}

.card-container.is-loading .card-image,
.card-container.is-loading .card-text-wrap {
  opacity: 0.22;
  filter: blur(3px);
  transform: scale(0.985);
}

.image-preview {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  perspective: 1200px;
  perspective-origin: 50% 50%;
}

.image-preview.show {
  opacity: 1;
  pointer-events: auto;
}

.image-preview-stage {
  position: relative;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

.image-preview-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate3d(0, 0, 0) scale(1);
  transform-origin: center center;
  will-change: transform;
}

.image-preview-content.is-entering {
  opacity: 0;
}

.image-preview-text-wrap {
  position: absolute;
  top: calc(var(--preview-card-w, 400px) * 0.097);
  left: calc(var(--preview-card-w, 400px) * 0.022);
  right: calc(var(--preview-card-w, 400px) * 0.022);
  z-index: 2;
  display: flex;
  justify-content: center;
  opacity: 0;
  transform: scaleY(1.22) scaleX(0.96);
  transform-origin: center top;
  clip-path: inset(100% 0 0 0);
  filter: blur(6px);
  transition:
    opacity 0.42s ease,
    transform 0.63s cubic-bezier(0.2, 0.8, 0.2, 1),
    clip-path 0.63s cubic-bezier(0.2, 0.8, 0.2, 1),
    filter 0.45s ease;
  pointer-events: none;
}

.image-preview-text-wrap.show {
  opacity: 1;
  transform: scaleY(1) scaleX(1);
  clip-path: inset(0 0 0 0);
  filter: blur(0);
}

.image-preview-text {
  max-width: 100%;
  padding: 0;
  background: none;
  border: none;
  color: #fff;
  text-align: center;
  font-family: "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", "SF Pro Display", "Helvetica Neue", sans-serif;
  font-size: calc(var(--preview-card-w, 400px) * 0.188);
  font-weight: 500;
  line-height: 1;
  letter-spacing: calc(var(--preview-card-w, 400px) * 0.051);
  white-space: nowrap;
  word-break: keep-all;
  text-wrap: nowrap;
  mix-blend-mode: overlay;
  opacity: 1;
}

.image-preview-text[data-chars="3"] {
  font-size: calc(var(--preview-card-w, 400px) * 0.144);
}

.image-preview-text[data-chars="4"] {
  font-size: calc(var(--preview-card-w, 400px) * 0.111);
}

.image-preview-text-wrap.show .image-preview-text {
  animation: preview-text-breathe 2.8s ease-in-out infinite;
}

.image-preview-text-wrap.is-swapping .image-preview-text {
  animation: none;
  transition: opacity 0.18s ease-out;
  opacity: 0;
}

@keyframes preview-text-breathe {
  0%, 100% { opacity: 0.75; transform: scale(1); }
  50%      { opacity: 0;   transform: scale(0.96); }
}

.image-preview-img {
  width: auto;
  max-width: 100vw;
  max-width: 100dvw;
  max-height: 100vh;
  max-height: 100dvh;
  object-fit: contain;
  border-radius: 0;
  box-shadow: none;
}

.image-preview.is-zoomed .image-preview-content {
  transition: transform 0.02s linear;
}

/* 全屏字层切换按钮 */
.preview-text-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 16px) + 12px);
  right: 16px;
  z-index: 1010;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: background 0.2s, color 0.2s, opacity 0.28s ease;
  -webkit-tap-highlight-color: transparent;
}

.image-preview.is-revealed .preview-text-btn {
  opacity: 1;
  pointer-events: auto;
}

.preview-text-btn.is-active {
  background: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.preview-text-btn:active {
  transform: scale(0.9);
}

/* 换字按钮（字按钮下方） */
.preview-swap-btn {
  position: absolute;
  top: calc(env(safe-area-inset-top, 16px) + 12px + 36px + 10px);
  right: 16px;
  z-index: 1010;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: background 0.2s, color 0.2s, opacity 0.28s ease;
  -webkit-tap-highlight-color: transparent;
}

.image-preview.is-revealed .preview-swap-btn {
  opacity: 1;
  pointer-events: auto;
}

.preview-swap-btn:active {
  transform: scale(0.9);
}

.preview-swap-btn.is-loading {
  opacity: 0.5;
  pointer-events: none;
}

.preview-back-btn,
.preview-share-btn,
.preview-fav-btn,
.preview-question-btn {
  position: absolute;
  z-index: 1010;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: background 0.2s, color 0.2s, opacity 0.28s ease, transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.preview-back-btn {
  top: calc(env(safe-area-inset-top, 16px) + 12px);
  left: 16px;
}

.preview-share-btn {
  top: calc(env(safe-area-inset-top, 16px) + 12px);
  right: 16px;
}

.preview-fav-btn {
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
}

.preview-question-btn {
  left: 120px;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
  font-size: 14px;
  font-weight: 700;
}

.preview-text-tools {
  position: absolute;
  left: 16px;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 16px);
  z-index: 1010;
  width: 92px;
  height: 40px;
  padding: 2px;
  border-radius: 22px;
  border: 0.5px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease, background 0.2s ease, border-color 0.2s ease;
}

.preview-text-tools .preview-text-btn,
.preview-text-tools .preview-swap-btn {
  position: static;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  color: rgba(255, 255, 255, 0.72);
  opacity: 1;
  pointer-events: auto;
}

.image-preview.is-revealed .preview-back-btn,
.image-preview.is-revealed .preview-share-btn,
.image-preview.is-revealed .preview-fav-btn,
.image-preview.is-revealed .preview-question-btn,
.image-preview.is-revealed .preview-text-tools {
  opacity: 1;
  pointer-events: auto;
}

.preview-fav-btn.is-favorited,
.preview-question-btn.is-active {
  background: rgba(255, 255, 255, 0.35);
  color: #fff;
}

.preview-fav-btn.is-favorited .preview-fav-icon {
  fill: currentColor;
}

.preview-back-btn:active,
.preview-share-btn:active,
.preview-fav-btn:active,
.preview-question-btn:active {
  transform: scale(0.9);
}

.preview-question-board {
  position: fixed;
  z-index: 1008;
  padding: var(--question-pad-y, 8px) var(--question-pad-x, 28px);
  border-radius: 11px;
  border: 0.5px solid rgba(255, 255, 255, 0.49);
  background: rgba(10, 10, 10, 0.11);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  box-shadow:
    0 6px 18px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  touch-action: none;
  transition: opacity 0.22s ease;
}

.preview-question-board.show {
  opacity: 1;
  pointer-events: auto;
}

.preview-question-board.is-panel-entering {
  animation: question-panel-in 180ms ease-out;
}

.preview-question-copy {
  position: relative;
  z-index: 1;
  width: 100%;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--question-line-gap, 8px);
  transform: translate(0, var(--question-text-offset-y, 2px));
  color: rgba(255, 255, 255, 1);
  font-family: "PingFang SC", "Hiragino Sans GB", sans-serif;
  text-align: center;
  text-shadow:
    0 1px 1.5px rgba(0, 0, 0, 0.1),
    0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 8px rgba(255, 255, 255, 0.42),
    0 0 18px rgba(255, 255, 255, 0.36),
    0 0 34px rgba(255, 255, 255, 0.28);
}

.preview-question-line {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  letter-spacing: 0.7px;
  font-size: var(--question-line-size, 14px);
  font-weight: 600;
  line-height: 1.28;
}

.preview-question-arrow {
  position: absolute;
  z-index: 2;
  top: 50%;
  width: var(--question-arrow-size, 25px);
  height: calc(var(--question-arrow-size, 25px) * 1.68);
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  font-size: var(--question-arrow-size, 25px);
  font-weight: 500;
  line-height: 1;
  transform: translateY(-50%);
  transition: opacity 160ms ease, transform 120ms ease;
}

.preview-question-arrow-left { left: var(--question-arrow-inset, 10px); }
.preview-question-arrow-right { right: var(--question-arrow-inset, 10px); }

.preview-question-arrow:active {
  transform: translateY(-50%) scale(0.94);
}

.preview-question-arrow.is-disabled {
  opacity: 0.34;
}

.preview-question-board.is-switch-next {
  animation: question-switch-next 160ms ease-out;
}

.preview-question-board.is-switch-prev {
  animation: question-switch-prev 160ms ease-out;
}

.preview-question-board.is-wall-left {
  animation: question-wall-left 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.preview-question-board.is-wall-right {
  animation: question-wall-right 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.preview-question-board.is-swipe-faded {
  opacity: 0;
  transition: opacity 90ms linear;
}

@keyframes question-panel-in {
  from { opacity: 0; transform: translateY(4px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes question-switch-next {
  from { opacity: 0.84; transform: translateX(4px) scale(0.995); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes question-switch-prev {
  from { opacity: 0.84; transform: translateX(-4px) scale(0.995); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes question-wall-left {
  0% { transform: translateX(0); }
  38% { transform: translateX(-6px); }
  68% { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

@keyframes question-wall-right {
  0% { transform: translateX(0); }
  38% { transform: translateX(6px); }
  68% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

.oka-toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 16px) + 82px);
  z-index: 1300;
  transform: translate(-50%, 12px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: rgba(255, 255, 255, 0.94);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.oka-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 全局"字"开关关闭时：小卡片不显示字，"换"按钮隐藏 */
body.text-pref-off .carousel-card.is-face-up .carousel-card-text-wrap {
  opacity: 0;
}
body.text-pref-off .preview-swap-btn {
  display: none;
}

/* Action buttons */
.action-row {
  display: grid;
  grid-template-columns: repeat(3, 48px) minmax(114px, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 320px;
  margin-bottom: 16px;
}

.action-btn {
  height: 48px;
  border-radius: 24px;
  border: 0.5px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.action-btn:disabled {
  opacity: 0.42;
  pointer-events: none;
}

.action-btn:active {
  transform: scale(0.96);
}

.action-btn-icon {
  width: 48px;
  padding: 0;
}

.action-btn-again {
  min-width: 0;
}

.action-btn.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-end));
  color: #fff;
  border: none;
  font-weight: 600;
  box-shadow: 0 4px 12px var(--accent-shadow);
}

.action-btn.favorited {
  background: rgba(217, 140, 90, 0.14);
  border-color: rgba(217, 140, 90, 0.2);
}

.action-btn.favorited svg {
  fill: var(--accent);
  stroke: var(--accent);
}

.action-btn.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-end));
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px var(--accent-shadow);
}

.action-icon {
  width: 20px;
  height: 20px;
}

.text-toggle-label {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.14em;
  transform: translateX(0.07em);
}

.link-home {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  padding: 8px 16px;
  letter-spacing: 0.5px;
}

.link-home:active {
  opacity: 0.6;
}

/* ===== List pages (History / Favorites) ===== */
.list-content {
  padding: 24px 20px;
  padding-top: calc(env(safe-area-inset-top, 16px) + 24px);
  padding-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 1px;
  margin-bottom: 20px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 13px;
}

.grid-card {
  background: var(--card-bg);
  border-radius: 18px;
  border: 0.5px solid var(--card-border);
  overflow: hidden;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow:
    0 2px 16px rgba(0, 0, 0, 0.04),
    0 8px 32px rgba(0, 0, 0, 0.02);
  transition: transform 0.15s ease;
  cursor: pointer;
}

.grid-card:active {
  transform: scale(0.97);
}

.grid-card-media {
  position: relative;
}

.grid-card-img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  display: block;
}

.grid-card-text {
  position: absolute;
  top: 16px;
  left: 10px;
  right: 10px;
  z-index: 1;
  color: rgba(255, 255, 255, 0.82);
  text-align: center;
  font-family: "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Helvetica Neue", sans-serif;
  font-size: 22px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
  word-break: keep-all;
  text-wrap: nowrap;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.12),
    0 5px 16px rgba(0, 0, 0, 0.2);
  pointer-events: none;
}

.grid-card-footer {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.grid-card-time {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.grid-card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.grid-card-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.grid-card-actions button:active {
  color: var(--accent);
}

.grid-card-actions .favorited {
  color: var(--accent);
}

.empty-hint {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 80px;
  letter-spacing: 0.5px;
  display: none;
}

.empty-hint.show {
  display: block;
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: none;
}

.tab-bar-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 52px;
  max-width: 760px;
  margin: 0 auto;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 20px;
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  color: var(--accent);
}

.tab-icon {
  width: 22px;
  height: 22px;
}

.tab-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* ===== Animations ===== */
@keyframes cardIn {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.card-container.animate {
  animation: cardIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.action-row.animate {
  animation: fadeUp 0.3s ease 0.15s both;
}

/* ===== Carousel (embedded in home) ===== */
.carousel-stage {
  position: relative;
  width: 100%;
  height: calc(360px * var(--card-scale));
  overflow: hidden;
  touch-action: pan-x;
  -webkit-user-select: none;
  user-select: none;
  flex-shrink: 0;
}

.carousel-card {
  position: absolute;
  top: 50%;
  width: calc(160px * var(--card-scale));
  height: calc(224px * var(--card-scale));
  transform-style: preserve-3d;
  transition: none;
  will-change: transform;
  pointer-events: auto;
  cursor: pointer;
}

.carousel-card-face {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.12),
    0 1px 3px rgba(0, 0, 0, 0.08);
}

/* 卡背 */
.carousel-card-back {
  background-image: url("/static/assets/card-back.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border: none;
  box-shadow:
    0 4px 20px rgba(80, 40, 20, 0.2),
    0 0.5px 0 rgba(255, 255, 255, 0.1) inset;
  overflow: hidden;
}

/* 卡正面 */
/* 默认藏起来，face-up 时显示。不使用 rotateY + backface-visibility 切面，
   原因：iOS Safari 在触摸时会短暂扁平化 3D 上下文，让 backface-visibility
   失效，导致翻开的牌在滑动时露出背面。这里用 display 直接切换。 */
.carousel-card-front {
  display: none;
}

.carousel-card.is-face-up .carousel-card-back {
  display: none;
}

.carousel-card.is-face-up .carousel-card-front {
  display: block;
}

.carousel-card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* face-up 时覆盖在卡面上的文字——比例与全屏预览一致。 */
.carousel-card-text-wrap {
  position: absolute;
  top: calc(160px * var(--card-scale) * 0.097);
  left: calc(160px * var(--card-scale) * 0.022);
  right: calc(160px * var(--card-scale) * 0.022);
  z-index: 2;
  display: flex;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
}

.carousel-card.is-face-up .carousel-card-text-wrap {
  opacity: 1;
}

.carousel-card-text {
  margin: 0;
  padding: 0;
  color: #fff;
  text-align: center;
  font-family: "PingFang SC", "Hiragino Sans GB", "Source Han Sans SC", "Noto Sans SC", "SF Pro Display", "Helvetica Neue", sans-serif;
  font-size: calc(160px * var(--card-scale) * 0.188);
  font-weight: 500;
  line-height: 1;
  letter-spacing: calc(160px * var(--card-scale) * 0.051);
  white-space: nowrap;
  word-break: keep-all;
  text-wrap: nowrap;
  mix-blend-mode: overlay;
  opacity: 1;
}

.carousel-card-text[data-chars="3"] {
  font-size: calc(160px * var(--card-scale) * 0.144);
}

.carousel-card-text[data-chars="4"] {
  font-size: calc(160px * var(--card-scale) * 0.111);
}

.carousel-card.is-face-up .carousel-card-text {
  animation: preview-text-breathe 2.8s ease-in-out infinite;
}

/* 浮动翻牌层 - 挂在 image-preview 首位，通过 DOM 顺序保证 text-wrap 在其之上 */
.flip-clone {
  position: fixed;
  transform-style: preserve-3d;
  pointer-events: none;
  will-change: transform;
  transform-origin: center center;
}

.flip-clone .carousel-card-face {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.flip-clone .flip-clone-front {
  transform: rotateY(180deg);
  background: #0e0e12;
}

.flip-clone .flip-clone-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 18px;
}

.flip-clone.is-flipping {
  transition: transform 1.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.flip-clone.is-flipping-back {
  transition: transform 1.05s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  .carousel-card-back {
    box-shadow:
      0 4px 20px rgba(0, 0, 0, 0.35),
      0 0.5px 0 rgba(255, 255, 255, 0.06) inset;
  }
}

/* ===== Desktop centering ===== */
@media (min-width: 431px) {
  body {
    display: flex;
    justify-content: center;
    min-width: 100vw;
    background: var(--bg);
  }
  #app {
    border-left: 0.5px solid var(--divider);
    border-right: 0.5px solid var(--divider);
  }
}
