/* 基础：设计变量、翻页骨架、通用组件 */
:root {
  --paper: #f4ecdd;
  --paper-deep: #e6d9c0;
  --ink: #2b2622;
  --tomato: #d9482b;
  --night: #232c44;
  --night-deep: #171d30;
  --sun: #ffd23f;
  --sage: #7c9a7e;
  --blush: #f3b9bd;
  --film: #16110f;

  --font-title: 'Ma Shan Zheng', 'STKaiti', 'KaiTi', serif;
  --font-hand: 'Long Cang', 'STKaiti', 'KaiTi', cursive;
  --font-body: 'LXGW WenKai', 'STKaiti', 'KaiTi', 'Songti SC', serif;
  --font-pixel: 'Consolas', 'Courier New', monospace;

  --pager-h: 64px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-back: cubic-bezier(0.34, 1.56, 0.64, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--night-deep);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }
.defs { position: absolute; }
[hidden] { display: none !important; }

/* ---------- 翻页 ---------- */
#book { position: fixed; inset: 0; }
.page {
  position: absolute; inset: 0;
  padding: clamp(20px, 4vh, 44px) clamp(16px, 4vw, 56px) calc(var(--pager-h) + 20px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(10px, 2.2vh, 24px);
  overflow: hidden;
  opacity: 0; visibility: hidden;
  transform: translateX(6%) rotate(1.2deg);
  transition: opacity .5s ease, transform .7s var(--ease-out), visibility 0s .7s;
}
.page.is-active { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; z-index: 2; }
.page.is-past { transform: translateX(-6%) rotate(-1.2deg); }

.page-head { text-align: center; position: relative; z-index: 3; }
.page-head h2 {
  margin: 0; font-family: var(--font-title); font-weight: 400;
  font-size: clamp(1.7rem, 2.6vw + 1rem, 3.2rem); line-height: 1.15; text-wrap: balance;
}
.sub { margin: .35em 0 0; font-family: var(--font-hand); font-size: clamp(1.15rem, 1vw + .9rem, 1.6rem); opacity: .78; }

/* ---------- 翻页条 ---------- */
.pager {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 999px;
  background: var(--paper); color: var(--ink);
  box-shadow: 0 2px 0 var(--ink), 0 10px 24px rgba(0, 0, 0, .35);
  border: 2px solid var(--ink);
}
.pager-arrow {
  width: 40px; height: 40px; border-radius: 50%;
  font-size: 1.6rem; line-height: 1; display: grid; place-items: center;
  transition: background .15s, transform .15s var(--ease-back);
}
.pager-arrow:hover:not(:disabled) { background: var(--paper-deep); }
.pager-arrow:active:not(:disabled) { transform: scale(.9); }
.pager-arrow:disabled { opacity: .25; cursor: default; }
.pager-next:not(:disabled) { background: var(--tomato); color: #fff; }
.pager-next:hover:not(:disabled) { background: #c23c21; }
.pager-next.is-nudge { animation: nudge 1.2s var(--ease-out) infinite; }
.pager-dots { display: flex; gap: 2px; list-style: none; margin: 0; padding: 0; }
.pager-dots button { width: 24px; height: 40px; display: grid; place-items: center; }
.pager-dots button::before {
  content: ''; width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--ink); transition: transform .25s var(--ease-back), background .2s;
}
.pager-dots button[aria-current='true']::before { background: var(--tomato); transform: scale(1.35); }
.pager-title { font-family: var(--font-hand); font-size: 1.25rem; min-width: 4.5em; text-align: center; white-space: nowrap; }
@keyframes nudge { 0%, 60%, 100% { transform: none; } 30% { transform: translateX(5px); } }

.mute {
  position: fixed; top: 12px; right: 12px; z-index: 20;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--paper); border: 2px solid var(--ink); box-shadow: 0 2px 0 var(--ink);
  font-size: 1.2rem;
}
.mute[aria-pressed='true'] { text-decoration: line-through; opacity: .6; }

/* ---------- 拍立得 ---------- */
.polaroid {
  margin: 0; background: #fffdf6; padding: 8px 8px 0;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .2), 0 14px 30px rgba(0, 0, 0, .38);
}
.polaroid img { display: block; width: 100%; object-fit: cover; background: #ddd; }
.polaroid figcaption {
  font-family: var(--font-hand); color: var(--ink); text-align: center;
  font-size: 1.15rem; line-height: 1; padding: .45em 0 .5em;
}

.flash { position: fixed; inset: 0; z-index: 40; background: #fff; opacity: 0; pointer-events: none; }
.flash.is-on { animation: flash .5s ease-out; }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }

/* ---------- 放大看 ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; gap: clamp(4px, 2vw, 24px);
  background: rgba(15, 10, 8, .86); padding: 16px;
  animation: fade .25s ease;
}
.polaroid-big { padding: 14px 14px 0; transform: rotate(-1.5deg); animation: pop .45s var(--ease-back); max-width: min(78vw, 560px); }
.polaroid-big img { width: auto; max-width: 100%; max-height: 66vh; max-height: 66dvh; margin: 0 auto; }
.polaroid-big figcaption { font-size: clamp(1.5rem, 2vw + 1rem, 2.2rem); padding: .5em 0 .55em; }
.lb-nav, .lb-close {
  flex: none; width: 48px; height: 48px; border-radius: 50%;
  background: var(--paper); border: 2px solid var(--ink); font-size: 1.8rem; line-height: 1;
}
.lb-close { position: absolute; top: 14px; right: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.8) rotate(4deg); } }

.btn-paper {
  font-family: var(--font-hand); font-size: 1.3rem; padding: .25em 1em;
  border: 2px solid var(--ink); border-radius: 999px; background: var(--paper);
  box-shadow: 0 3px 0 var(--ink); transition: transform .12s, box-shadow .12s;
}
.btn-paper:hover { background: #fff; }
.btn-paper:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .pager-title { display: none; }
  .lb-nav { position: absolute; bottom: 18px; }
  .lb-prev { left: 22%; } .lb-next { right: 22%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
