/* ---------- reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: #0a0a0c;
  color: #e8e6df;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}
body { min-height: 100dvh; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- app root ---------- */
#app {
  position: relative;
  min-height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
}

/* ---------- grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 5px;
  padding-top: max(env(safe-area-inset-top, 5px), 5px);
  padding-bottom: max(env(safe-area-inset-bottom, 5px), 120px);
  align-content: start;
}
@media (min-width: 600px) {
  .grid { grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 6px; }
}

/* ---- 桌面 (≥900px): 填满视口 + 四周无黑边 + 边缘 bleed ----
   单一 breakpoint, 避开特定缩放比例的布局 bug.
   - #app 取消 max-width, 填满浏览器
   - #app overflow-x hidden 裁掉 bleed
   - grid auto-fill + minmax(200px, 1fr), 列数随视口自动变 (浏览器缩放也生效)
   - grid 宽度 = 100% + 120px, 左右各溢出 60px 被裁, 形成边缘 bleed
*/
@media (min-width: 900px) {
  #app {
    max-width: none;
    margin: 0;
    overflow-x: hidden;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 3px;
    padding: 0;
    padding-bottom: 140px;
    /* bleed: grid 比 #app 宽 120px, 左右各溢出 60px */
    width: calc(100% + 120px);
    margin-left: -60px;
  }
}

.card {
  position: relative;
  top: 0;
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  background: #14141a;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.3s cubic-bezier(.2,.7,.2,1), box-shadow 0.3s, top 0.3s;
  content-visibility: auto;
  contain-intrinsic-size: auto 1fr auto 200px;
  /* 3D flip: 父级透视, 给 flipper 提供 3D 深度 */
  perspective: 1000px;
  -webkit-perspective: 1000px;
}

/* flipper 承载两个 face 元素, 绕 Y 轴旋转 */
.flipper {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 800ms cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
}
/* 桌面 intro tilt: 渲染时 JS 给每张卡加 .entering, 下一帧 staggered 移除,
   靠 .flipper 自带的 transition 滑回 0deg. 不要用 animation —— 否则
   .flipped 的 transform 覆盖会和 animation 冲突, 翻牌瞬间无动画. */
@media (min-width: 900px) {
  .card.entering .flipper {
    transform: rotateY(-90deg);
  }
}

/* 必须放在 .entering 之后, 让 specificity 平手时源序里 .flipped 胜出. */
.card.flipped .flipper {
  transform: rotateY(180deg);
}

.card:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) {
  .card:hover {
    transform: translateY(-3px) scale(1.015);
    box-shadow: 0 14px 32px rgba(0,0,0,0.45), 0 0 0 1px rgba(232,230,223,0.12);
    z-index: 2;
  }
  .card:hover .face { filter: brightness(1.05); }
}

.card.blind .back {
  animation: breathe 7s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: 0.78; }
  50%      { opacity: 1; }
}

/* blind-mode shuffle wobble: per-card cascade nudge */
.card.shuffling {
  animation: blindShuffle 0.6s cubic-bezier(.4, 0, .2, 1);
  z-index: 4;
}
@keyframes blindShuffle {
  0%   { transform: translateY(0) rotate(0deg) scale(1); }
  28%  { transform: translateY(-5px) rotate(-4.5deg) scale(0.96); }
  62%  { transform: translateY(3px) rotate(3.5deg) scale(1.04); }
  100% { transform: translateY(0) rotate(0deg) scale(1); }
}
/* two-sided faces: face-a (front) + face-b (back, pre-rotated 180°)
   backface-visibility 让只有朝向观众的面可见 */
.card .face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  opacity: 0;
  /* 300ms 要比 flip 的 half-duration (400ms) 快, 这样翻到 90° 时 face 已经完全不透明 */
  transition: opacity 300ms ease;
}
.card .face.loaded { opacity: 1; }
.card .face-b {
  transform: rotateY(180deg);
}

.card .back {
  display: none;
  position: absolute;
  inset: 0;
}
.card .back svg {
  display: block;
  width: 100%; height: 100%;
  object-fit: cover;
}

.card.blind .flipper { display: none; }
.card.blind .back {
  display: block;
  position: absolute;
  inset: 0;
}
.card.blind {
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);
}
/* 金边 via pseudo-element so it sits ABOVE the back image/svg */
.card.blind::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 3;
  box-shadow:
    inset 0 0 0 1px rgba(201, 169, 97, 0.6),
    inset 0 0 0 2px rgba(10, 10, 12, 0.7),
    inset 0 0 0 3px rgba(201, 169, 97, 0.35),
    inset 0 0 0 4px rgba(10, 10, 12, 0.5);
}
.card.selected { transform: scale(0.95); }
.card.selected::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid #e8e6df;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(10,10,12,0.8), 0 0 24px rgba(232,230,223,0.4);
  pointer-events: none;
  animation: selectGlow 2.4s ease-in-out infinite;
}
@keyframes selectGlow {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(10,10,12,0.8), 0 0 18px rgba(232,230,223,0.28); }
  50%      { box-shadow: inset 0 0 0 1px rgba(10,10,12,0.8), 0 0 30px rgba(232,230,223,0.5); }
}

/* ---------- chrome (fading controls) ---------- */
.chrome {
  position: fixed;
  left: 0; right: 0;
  z-index: 5;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.5s ease;
}
.chrome > * { pointer-events: auto; }
#app.idle .chrome { opacity: 0.12; }
#app.idle .chrome:hover { opacity: 1; }

.topbar {
  top: 0;
  display: flex;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top, 10px), 10px) 12px 8px 12px;
  background: linear-gradient(to bottom, rgba(10,10,12,0.5), transparent);
}
.topbar-left, .topbar-right {
  display: flex;
  gap: 4px;
  align-items: center;
}
.bottombar {
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 10px 16px;
  padding-bottom: max(env(safe-area-inset-bottom, 14px), 14px);
  background: linear-gradient(to top, rgba(10,10,12,0.6), transparent);
}

/* ---------- icon buttons ---------- */
.iconbtn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #e8e6df;
  border-radius: 17px;
  transition: background 0.15s;
}
.iconbtn:hover { background: rgba(255,255,255,0.08); }
.iconbtn:active { background: rgba(255,255,255,0.15); }
.iconbtn .icon-blind { display: none; }
.iconbtn[aria-pressed="true"] .icon-open { display: none; }
.iconbtn[aria-pressed="true"] .icon-blind { display: inline-block; }

.textbtn {
  font-size: 14px;
  letter-spacing: 0.08em;
  color: #e8e6df;
  padding: 10px 16px;
  border-radius: 8px;
  transition: background 0.15s;
}
.textbtn:hover { background: rgba(255,255,255,0.06); }

/* ---------- save button in topbar ---------- */
.save-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: #e8e6df;
  color: #0a0a0c;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.1em;
  animation: popin 0.2s cubic-bezier(.2,.8,.2,1);
}
.save-btn:active { transform: scale(0.96); }
.save-count {
  display: inline-flex;
  align-items: center; justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  background: #0a0a0c;
  color: #e8e6df;
  border-radius: 9px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

/* ---------- deck picker ---------- */
.deck-picker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  color: #e8e6df;
  border: 1px solid rgba(200,197,185,0.25);
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: 0.15em;
  transition: all 0.15s;
}
.deck-picker:hover { border-color: rgba(232,230,223,0.6); }
.deck-picker .chevron { opacity: 0.7; }

/* ---------- deck menu sheet ---------- */
.deck-menu {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadein 0.2s ease;
}
.deck-menu-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,10,12,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.deck-menu-sheet {
  position: relative;
  width: min(100%, 420px);
  display: flex;
  flex-direction: column;
  padding: 12px;
  padding-bottom: max(env(safe-area-inset-bottom, 24px), 24px);
  animation: slideup 0.25s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideup {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.deck-option {
  padding: 18px;
  font-size: 16px;
  letter-spacing: 0.2em;
  color: #e8e6df;
  border-radius: 8px;
  margin-bottom: 2px;
  transition: background 0.15s;
}
.deck-option:hover { background: rgba(255,255,255,0.06); }
.deck-option.active { color: #0a0a0c; background: #e8e6df; }

/* ---------- preview (tap-to-zoom + inline note + nav) ---------- */
.preview {
  position: fixed;
  inset: 0;
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadein 0.2s ease;
}
.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,10,12,0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.preview-stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 20px 12px;
  padding-top: max(env(safe-area-inset-top, 24px), 24px);
  padding-bottom: max(env(safe-area-inset-bottom, 24px), 24px);
}
.preview-card-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.preview-card {
  position: relative;
  width: min(72vw, 360px);
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,0.7);
  animation: popin 0.25s cubic-bezier(.2,.8,.2,1);
}
@keyframes popin {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}
.preview-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.preview-x, .preview-heart {
  position: absolute;
  width: 34px; height: 34px;
  display: inline-flex;
  align-items: center; justify-content: center;
  color: #e8e6df;
  background: rgba(10,10,12,0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 17px;
  transition: all 0.15s;
}
.preview-x { top: 10px; right: 10px; }
.preview-heart { top: 10px; left: 10px; }
.preview-x:hover, .preview-heart:hover { background: rgba(10,10,12,0.8); }
.preview-heart[aria-pressed="true"] svg { fill: #e8e6df; }
.preview-heart[aria-pressed="true"] { background: rgba(232,230,223,0.2); }

.preview-seq {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.95);
  -webkit-text-stroke: 0.5px rgba(0, 0, 0, 0.6);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7), 0 0 6px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 2;
}
.preview-seq:empty { display: none; }

.preview-note {
  width: min(72vw, 360px);
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(200,197,185,0.2);
  padding: 10px 4px;
  resize: none;
  font-size: 15px;
  line-height: 1.6;
  color: #e8e6df;
  outline: none;
  text-align: center;
  transition: border-color 0.2s;
}
.preview-note:focus { border-bottom-color: rgba(232,230,223,0.5); }
.preview-note::placeholder { color: rgba(200,197,185,0.35); }

.preview-nav {
  position: relative;
  flex-shrink: 0;
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center; justify-content: center;
  color: rgba(232,230,223,0.6);
  border-radius: 20px;
  transition: all 0.15s;
}
.preview-nav:hover { color: #e8e6df; background: rgba(255,255,255,0.06); }
.preview-nav:disabled { opacity: 0.2; cursor: default; }
.preview-nav:disabled:hover { background: transparent; color: rgba(232,230,223,0.6); }

@media (max-width: 480px) {
  .preview-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px; height: 44px;
    background: rgba(10,10,12,0.5);
    backdrop-filter: blur(8px);
  }
  .preview-nav-prev { left: 4px; }
  .preview-nav-next { right: 4px; }
}

/* ---------- overlay screen (history) ---------- */
.overlay-screen {
  position: fixed;
  inset: 0;
  background: #0a0a0c;
  z-index: 15;
  display: flex;
  flex-direction: column;
  animation: fadein 0.25s ease;
}
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.overlay-top {
  display: flex;
  padding: max(env(safe-area-inset-top, 10px), 10px) 12px 8px 12px;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 8px 16px 32px 16px;
  overflow-y: auto;
  flex: 1;
}
.history-item {
  padding: 18px 4px;
  border-bottom: 1px solid rgba(200,197,185,0.08);
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.history-item:hover { background: rgba(255,255,255,0.02); }
.history-note {
  font-size: 15px;
  line-height: 1.5;
  color: #e8e6df;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.history-note.empty { color: #5a584f; font-style: italic; }
.history-thumbs {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}
.history-thumbs::-webkit-scrollbar { display: none; }
.history-thumb {
  flex-shrink: 0;
  width: 44px; height: 66px;
  border-radius: 3px;
  overflow: hidden;
  background: #14141a;
}
.history-thumb img, .history-thumb svg {
  width: 100%; height: 100%; object-fit: cover;
}
.history-empty {
  text-align: center;
  color: #5a584f;
  font-size: 13px;
  padding: 60px 20px;
}

/* ---------- more sheet (seed) ---------- */
.more-sheet {
  position: fixed;
  inset: 0;
  background: rgba(10,10,12,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadein 0.2s ease;
}
.more-card {
  width: min(90vw, 340px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 24px 24px;
}
.more-about {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-bottom: 4px;
}
.more-about-title {
  font-size: 14px;
  letter-spacing: 0.35em;
  color: #c7c5bd;
  font-weight: 300;
}
.more-about-body {
  font-size: 14px;
  line-height: 1.95;
  color: #a8a69d;
  text-align: center;
  margin: 0;
  max-width: 260px;
  font-family: "Songti SC", "Noto Serif CJK SC", Georgia, serif;
}
.more-about-link {
  font-size: 12px;
  color: #76746b;
  text-decoration: none;
  letter-spacing: 0.12em;
  padding: 6px 12px;
  animation: linkBreathe 3.2s ease-in-out infinite;
  transform-origin: center;
}
.more-about-link:hover,
.more-about-link:active {
  animation: none;
  color: #e8e5dc;
  transform: scale(1.04);
}
@keyframes linkBreathe {
  0%, 100% {
    color: #76746b;
    transform: scale(1);
    opacity: 0.75;
  }
  50% {
    color: #d8d5cc;
    transform: scale(1.05);
    opacity: 1;
  }
}
.more-divider {
  width: 40px;
  height: 1px;
  background: #3a3834;
  margin: 8px 0 4px;
}
.more-label {
  font-size: 10px;
  letter-spacing: 0.25em;
  color: #76746b;
  text-transform: uppercase;
}
.more-close { margin-top: 8px; color: #76746b; }

.follow-qr {
  width: min(60vw, 200px);
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 32px rgba(0,0,0,0.5);
  display: block;
  object-fit: contain;
}


/* ---------- desktop preview: two-column layout ---------- */
@media (min-width: 900px) and (orientation: landscape) {
  .preview-stage {
    max-width: 1000px;
    gap: 20px;
    padding: 32px;
  }
  .preview-card-wrap {
    flex-direction: row;
    align-items: center;
    gap: 36px;
    max-width: 900px;
  }
  .preview-card {
    width: min(42vw, 480px);
    aspect-ratio: 2 / 3;
    flex-shrink: 0;
  }
  .preview-note {
    width: 320px;
    min-height: 240px;
    max-height: 60vh;
    text-align: left;
    border-bottom: none;
    border: 1px solid rgba(200,197,185,0.18);
    border-radius: 10px;
    padding: 18px 20px;
    font-size: 16px;
    line-height: 1.8;
  }
  .preview-note:focus { border-color: rgba(232,230,223,0.4); }
  .preview-nav { width: 48px; height: 48px; }
}

/* ---------- desktop keyboard shortcut help overlay ---------- */
.shortcut-help {
  position: fixed;
  inset: 0;
  z-index: 26;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadein 0.2s ease;
}
.shortcut-help-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10,10,12,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.shortcut-help-card {
  position: relative;
  width: min(92vw, 520px);
  padding: 32px 36px;
  animation: popin 0.25s cubic-bezier(.2,.8,.2,1);
}
.shortcut-help-title {
  font-size: 13px;
  letter-spacing: 0.25em;
  color: #76746b;
  text-transform: uppercase;
  margin-bottom: 20px;
  text-align: center;
}
.shortcut-help-list {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 24px;
  row-gap: 12px;
  align-items: center;
}
.shortcut-help-list dt {
  display: inline-flex;
  gap: 4px;
  font-size: 13px;
  color: #c8c5b9;
}
.shortcut-help-list kbd {
  display: inline-block;
  padding: 3px 8px;
  min-width: 26px;
  text-align: center;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(200,197,185,0.25);
  border-bottom-width: 2px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  color: #e8e6df;
  line-height: 1.2;
}
.shortcut-help-list dd {
  margin: 0;
  font-size: 14px;
  color: #e8e6df;
}
.shortcut-help-hint {
  margin-top: 24px;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #5a584f;
}

/* ---------- privacy banner ---------- */
.privacy {
  position: fixed;
  left: 50%;
  bottom: calc(max(env(safe-area-inset-bottom, 12px), 12px) + 76px);
  transform: translateX(-50%);
  background: rgba(232,230,223,0.96);
  color: #0a0a0c;
  padding: 10px 12px 10px 14px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 32px);
  z-index: 28;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  animation: privacyIn 0.5s cubic-bezier(.2,.8,.2,1);
}
@keyframes privacyIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
.privacy-close {
  width: 22px; height: 22px;
  display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: 11px;
  font-size: 16px;
  color: #555;
}
.privacy-close:hover { background: rgba(0,0,0,0.08); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  color: #0a0a0c;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.1em;
  z-index: 30;
  animation: toast 2s ease forwards;
  pointer-events: none;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, 10px); }
  15%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}
