@font-face {
  font-family: 'HuiwenMingchao';
  src: url('https://font.xinjianhub.cn/汇文明朝体-subset-v20260214.woff2') format('woff2');
  font-display: swap;
}

@font-face {
  font-family: 'ZhiMangXing';
  src: url('https://font.xinjianhub.cn/ZhiMangXing-subset-v20260207.woff2') format('woff2');
  font-display: swap;
}

:root {
  --paper: #fdfaf2;
  --page: #f0f0f0;
  --ink: #374151;
  --muted: #6b7280;
  --line: #e5e7eb;
  --gold: #d4a574;
  --red: #c13832;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  min-height: 100svh;
}

.center-page {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.home {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  transform: translateY(-4vh);
  transform: translateY(-4svh);
}

.home.classic-home {
  background: var(--page);
}

.home-logo {
  width: 58px;
  height: 58px;
  margin-bottom: 22px;
  border-radius: 50%;
  border: 1px solid rgba(139, 69, 19, 0.14);
}

.home-title {
  margin: 0;
  color: var(--ink);
  font-family: 'HuiwenMingchao', 'STSong', 'SimSun', serif;
  font-size: 48px;
  font-weight: 800;
  letter-spacing: 0;
}

.classic-home .home-title {
  font-family: inherit;
}

.classic-home .home-logo {
  background: #f5ead6;
}

.classic-home .btn-primary {
  background: #f1c9a7;
  border-color: #f1c9a7;
}

.home-subtitle {
  margin: 12px 0 0;
  color: #4b5563;
  font-family: 'ZhiMangXing', STKaiti, KaiTi, cursive;
  font-size: 28px;
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(240px, 78vw);
  margin-top: 30px;
}

.btn {
  min-height: 48px;
  padding: 0 22px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
}

.btn-primary {
  background: var(--gold);
  border-color: var(--gold);
}

.result-page {
  min-height: 100vh;
  min-height: 100svh;
  padding: 24px 0 calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.result-page.classic-page {
  background: var(--page);
}

.classic-page .btn-primary {
  background: #f1c9a7;
  border-color: #f1c9a7;
}

.book-stage {
  width: min(86vw, 420px);
  perspective: 1200px;
  position: relative;
  margin-bottom: 24px;
  margin-bottom: clamp(18px, 3.2vh, 32px);
}

@supports (height: 100svh) {
  .book-stage {
    margin-bottom: clamp(18px, 3.2svh, 32px);
  }
}

.book {
  position: relative;
  width: 100%;
  aspect-ratio: 340 / 520;
  transform-style: preserve-3d;
}

.book-spine,
.hinge-mask,
.cover3d,
.card-reveal {
  position: absolute;
  top: 0;
  bottom: 0;
}

.book-spine {
  left: -14px;
  width: 14px;
  background: #ece6dd;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
  box-shadow: inset -2px 0 6px rgba(0, 0, 0, 0.15);
  z-index: 1;
}

.hinge-mask {
  left: 8px;
  width: 10px;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.06) 60%, transparent);
  z-index: 2;
}

.cover3d {
  left: 0;
  right: 0;
  z-index: 4;
  transform-origin: left center;
  transform-style: preserve-3d;
}

.book.animating .cover3d {
  animation: openBook 2.7s ease-in-out forwards;
}

.book.done .cover3d,
.book.done .book-spine,
.book.done .hinge-mask {
  display: none;
}

.cover-face {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ece6dd;
  border: 1px solid rgba(139, 69, 19, 0.15);
  backface-visibility: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}

.cover-face.back {
  transform: rotateY(180deg);
}

.book-title {
  font-family: 'HuiwenMingchao', 'STSong', 'SimSun', serif;
  font-size: clamp(28px, 8vw, 42px);
  font-weight: 900;
  color: #d22e2e;
}

.classic-page .cover-face,
.classic-page .book-spine {
  background: #f5ead6;
}

.classic-page .book-title {
  color: #5a3a1a;
  font-family: "Noto Serif SC", serif;
}

.card-reveal {
  inset: 0;
  opacity: 0;
  transform: scale(0.99);
  z-index: 1;
}

.book.animating .card-reveal {
  animation: cardIn 0.42s 0.55s ease-out forwards;
}

.book.done .card-reveal {
  opacity: 1;
  transform: scale(1);
}

@keyframes openBook {
  0% { transform: rotateY(0); }
  14% { transform: rotateY(-8deg); }
  58% { transform: rotateY(-90deg); }
  100% { transform: rotateY(-180deg); }
}

@keyframes cardIn {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.quote-card {
  position: relative;
  width: 100%;
  aspect-ratio: 340 / 520;
  --card-scale: 1;
}

.card-3d {
  position: absolute;
  inset: 0;
}

.card-3d.flip-ready {
  transform-style: preserve-3d;
  transition: transform 0.6s ease;
}

.card-3d.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  overflow: hidden;
}

.card-3d.flip-ready .card-face {
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.front-face {
  z-index: 2;
}

.back-face {
  display: none;
  transform: rotateY(180deg);
}

.card-3d.flip-ready .back-face {
  display: block;
}

.bg-image,
.interpret-bg-image,
.interpret-bg-classic {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.interpret-bg-classic {
  background: #f5ead6;
}

.inner {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.new-template .inner {
  padding: 95px 30px 90px;
}

.classic-template .inner {
  padding: 56px 30px;
}

.title-text {
  position: absolute;
  top: 40px;
  left: 20px;
  font-family: 'HuiwenMingchao', 'STSong', 'SimSun', serif;
  font-size: calc(36px * var(--card-scale));
  line-height: 1.3;
  color: #d22e2e;
}

.content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  overflow: hidden;
}

.content-wrapper::before {
  content: '';
  flex: 1;
  max-height: calc(40px * var(--card-scale));
}

.content-wrapper.short-quote::before {
  max-height: none;
}

.content-wrapper::after {
  content: '';
  flex: 1;
}

.classic-template .content-wrapper {
  padding-bottom: calc(70px * var(--card-scale));
}

.classic-template .content-wrapper::before {
  max-height: calc(55px * var(--card-scale));
}

.classic-template .content-wrapper.compact-quote::before {
  max-height: none;
}

.classic-template .content-wrapper.medium-quote::before {
  max-height: calc(105px * var(--card-scale));
}

.classic-template .content-wrapper.long-quote::before {
  max-height: calc(55px * var(--card-scale));
}

.content {
  letter-spacing: 0;
}

.new-template .content,
.new-template .source,
.new-template .interpret-title,
.new-template .interpret-text {
  font-family: 'HuiwenMingchao', 'STSong', 'SimSun', serif;
  color: #333;
}

.classic-template .content {
  font-family: "Ma Shan Zheng", "STKaiti", "KaiTi", cursive;
  color: #8c3a32;
}

.classic-template .source,
.classic-template .interpret-title,
.classic-template .interpret-text {
  font-family: "STKaiti", "KaiTi", serif;
  color: #8c3a32;
}

.content {
  font-weight: 700;
}

.content.normal {
  text-align: left;
}

.content.poetic {
  text-align: center;
}

.text-line {
  display: block;
  white-space: nowrap;
}

.source-wrapper {
  position: absolute;
  width: calc(200px * var(--card-scale));
  right: calc(30px * var(--card-scale));
  bottom: calc(30px * var(--card-scale));
}

.classic-template .source-wrapper {
  bottom: var(--source-bottom, calc(64px * var(--card-scale)));
}

.source {
  width: 100%;
  font-size: calc(20px * var(--card-scale));
  line-height: 1.3;
  text-align: right;
}

.classic-template .source {
  line-height: 1.2;
}

.interpret-inner {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  padding: calc(40px * var(--card-scale)) calc(24px * var(--card-scale)) calc(36px * var(--card-scale));
}

.interpret-title {
  margin-bottom: calc(28px * var(--card-scale));
  font-size: calc(36px * var(--card-scale));
  line-height: 1.3;
  font-weight: 700;
}

.interpret-content-wrapper {
  flex: 1;
  overflow: hidden;
}

.interpret-text {
  display: block;
  text-align: justify;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: calc(18px * var(--card-scale));
  line-height: 1.55;
}

.flip-hint {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  pointer-events: none;
  font-size: 14px;
  letter-spacing: 0;
}

.flip-hint.show {
  display: flex;
  animation: fadeHint 3s ease forwards;
}

.flip-hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  font-size: 30px;
  animation: iconBounce 1.6s ease-in-out infinite;
}

@keyframes iconBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes fadeHint {
  0%, 82% { opacity: 1; }
  100% { opacity: 0; }
}

.actions {
  width: min(86vw, 420px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
}

.modal {
  width: min(360px, 88vw);
  max-height: 88vh;
  max-height: 88svh;
  overflow-y: auto;
  border-radius: 12px;
  background: #fff;
  padding: 24px;
  text-align: center;
}

.poster-modal {
  width: min(460px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.wechat-poster-modal {
  width: auto;
  max-width: 92vw;
  padding: 0;
  overflow: visible;
  background: transparent;
  position: relative;
}

.poster-preview-wrap {
  width: fit-content;
  max-height: min(68vh, 720px);
  max-height: min(68svh, 720px);
  max-width: 100%;
  overflow: auto;
  border-radius: 10px;
  background: transparent;
  border: 1px solid var(--line);
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 165, 116, 0.6) rgba(212, 165, 116, 0.12);
}

.poster-preview-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.poster-preview-wrap::-webkit-scrollbar-track {
  background: rgba(212, 165, 116, 0.08);
  border-radius: 999px;
}

.poster-preview-wrap::-webkit-scrollbar-thumb {
  background: rgba(212, 165, 116, 0.55);
  border-radius: 999px;
}

.poster-preview {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: min(68vh, 720px);
  max-height: min(68svh, 720px);
  height: auto;
  margin: 0 auto;
  background: transparent;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

.wechat-poster-modal .poster-preview-wrap {
  max-height: min(84vh, 760px);
  max-height: min(84svh, 760px);
  border: 0;
}

.wechat-poster-modal .poster-preview {
  max-height: min(84vh, 760px);
  max-height: min(84svh, 760px);
}

.poster-toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.82);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.poster-toast.hide {
  opacity: 0;
  transform: translate(-50%, 8px);
}

.poster-hint {
  margin-top: 14px;
  font-size: 14px;
  color: var(--ink-light, #666);
  text-align: center;
}

.poster-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.modal-title {
  margin: 0 0 12px;
  font-size: 20px;
  color: var(--ink);
}

.modal-desc {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
  text-align: left;
}

.modal-desc p {
  margin: 0 0 10px;
}

.strong {
  color: var(--ink);
  font-weight: 700;
}

.qr-code {
  width: 200px;
  height: 200px;
  margin: 18px auto 0;
  border-radius: 12px;
  display: block;
}

.text-link {
  display: inline-flex;
  margin-top: 12px;
  color: #8b6914;
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 3px;
  background: transparent;
}

.template-options {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.template-option {
  min-height: 52px;
  padding: 0 14px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  text-align: center;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
}

.template-option.active {
  border-color: var(--gold);
  background: #fdfaf2;
}

.more-modal {
  width: min(320px, 88vw);
  padding: 18px;
}

.more-actions {
  display: grid;
  gap: 12px;
}

.community-page {
  min-height: 100vh;
  min-height: 100svh;
  padding: clamp(28px, 5vw, 56px) 16px 40px;
  background: var(--page);
}

.community-wrap {
  max-width: min(86vw, 420px);
  margin: 0 auto;
}

.community-title {
  margin: 0 0 clamp(18px, 3vw, 30px);
  font-size: clamp(24px, 4.8vw, 34px);
  color: var(--ink);
  text-align: center;
}

.infographic-list {
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 4vw, 26px);
}

.infographic-item {
  display: grid;
  gap: 10px;
  padding: 0;
}

.infographic-title {
  font-size: clamp(15px, 2.5vw, 18px);
  font-weight: 650;
  line-height: 1.45;
}

.infographic-image {
  width: 100%;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(90, 58, 26, 0.12);
  background: #f5ead6;
  cursor: zoom-in;
}

.join-section {
  margin-top: 28px;
  padding: 24px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 1px solid rgba(139, 69, 19, 0.14);
  border-radius: 8px;
  background: #fffdf7;
  text-align: center;
}

.image-preview-modal {
  width: min(920px, 94vw);
  padding: 14px;
  background: #fff;
}

.image-preview {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 78vh;
  max-height: 78svh;
  margin: 0 auto;
  border-radius: 8px;
}

.join-hint {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

#posterCanvas {
  position: fixed;
  left: -9999px;
  top: -9999px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 420px) {
  .home-title {
    font-size: 42px;
  }

  .actions-row {
    grid-template-columns: 1fr;
  }

  .book-stage,
  .actions {
    width: 86vw;
  }

  .new-template .inner {
    padding: 28% 8.8% 26%;
  }

  .classic-template .inner {
    padding: 16.5% 8.8%;
  }

  .classic-template .content-wrapper {
    padding-bottom: calc(70px * var(--card-scale));
  }

  .title-text {
    top: 7.6%;
    left: 5.8%;
    font-size: 9.6vw;
  }
}

@media (min-width: 900px) {
  .result-page {
    padding-top: 48px;
    padding-bottom: 48px;
  }

  .book-stage,
  .actions {
    width: min(38vw, 420px);
  }

  .btn {
    min-height: 46px;
  }
}
