@font-face {
  font-family: 'KuaiLe';
  src: url('../fonts/kuaile.woff2') format('woff2');
  font-display: swap;
}

:root {
  --paper: oklch(97.5% 0.014 30);
  --paper-2: oklch(94.5% 0.025 25);
  --paper-3: oklch(91% 0.035 20);
  --white: oklch(99.4% 0.004 30);
  --ink: oklch(33% 0.06 340);
  --ink-soft: oklch(52% 0.05 340);
  --line: oklch(89% 0.03 20);

  --straw: oklch(70% 0.17 10);
  --straw-deep: oklch(60% 0.18 10);
  --straw-tint: oklch(93% 0.05 10);
  --peach-tint: oklch(94% 0.05 50);
  --mint: oklch(84% 0.10 165);
  --mint-tint: oklch(94% 0.05 165);
  --sun: oklch(90% 0.14 95);
  --lilac-tint: oklch(93% 0.05 300);
  --sky-tint: oklch(93% 0.05 230);
  --danger: oklch(62% 0.19 25);

  --shadow-sticker: 0 2px 0 var(--line), 0 6px 14px oklch(60% 0.08 20 / 0.12);
  --shadow-page: 0 8px 0 var(--paper-3), 0 18px 40px oklch(55% 0.09 20 / 0.18);
  --shadow-lift: 0 10px 24px oklch(45% 0.1 20 / 0.28);

  --r-sticker: 22px;
  --r-page: 28px;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.7, 0, 0.84, 0);
  --dur-fast: 120ms;
  --dur-mid: 240ms;

  --font-display: 'KuaiLe', 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Microsoft YaHei', sans-serif;
  --font-ui: 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans CJK SC', 'Microsoft YaHei', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--paper);
  background-image: radial-gradient(oklch(90% 0.035 20) 1.3px, transparent 1.4px);
  background-size: 24px 24px;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.3;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
button:focus { outline: none; }
button:focus-visible { outline: 3px solid var(--straw); outline-offset: 3px; }

.global-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- 整体布局 ---------- */

.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  grid-template-rows: 76px minmax(0, 1fr);
  grid-template-areas: "top top" "stage book";
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---------- 顶栏 ---------- */

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl) 0 var(--space-xl);
  gap: var(--space-lg);
}

.title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 30px;
  font-weight: 400;
  color: var(--straw-deep);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.title-mark { width: 38px; height: 38px; animation: title-wiggle 6s ease-in-out infinite; transform-origin: 50% 60%; }
@keyframes title-wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-12deg); } 90% { transform: rotate(10deg); } 95% { transform: rotate(-6deg); } }

.topbar-actions { display: flex; gap: var(--space-md); }

.tb {
  display: grid;
  justify-items: center;
  gap: 2px;
  width: 64px;
  color: var(--ink);
}
.tb-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--shadow-sticker);
  display: grid;
  place-items: center;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
}
.tb-icon svg { width: 28px; height: 28px; }
.tb-label { font-size: 13px; color: var(--ink-soft); }
.tb:active .tb-icon { transform: scale(0.9); box-shadow: 0 1px 0 var(--line); }
.tb:disabled { opacity: 0.35; }
.tb .snd-off { display: none; }
.tb[aria-pressed="false"] .snd-wave { display: none; }
.tb[aria-pressed="false"] .snd-off { display: block; }

/* ---------- 舞台 ---------- */

.stage-wrap {
  grid-area: stage;
  container-type: size;
  display: grid;
  place-items: center;
  padding: var(--space-xl) var(--space-lg) var(--space-xl) var(--space-xl);
  min-width: 0;
  min-height: 0;
}

.frame {
  position: relative;
  width: min(100cqw, calc(100cqh * 4 / 3));
  aspect-ratio: 4 / 3;
}
/* 两条和纸胶带，把"书页"贴在桌面上 */
.frame::before, .frame::after {
  content: "";
  position: absolute;
  top: -14px;
  width: 112px;
  height: 30px;
  z-index: 3;
  opacity: 0.85;
  background: repeating-linear-gradient(135deg, var(--mint) 0 10px, oklch(90% 0.07 165) 10px 20px);
  box-shadow: 0 2px 4px oklch(50% 0.05 20 / 0.15);
  pointer-events: none;
}
.frame::before { left: 46px; transform: rotate(-7deg); }
.frame::after {
  right: 46px;
  transform: rotate(6deg);
  background: repeating-linear-gradient(135deg, oklch(86% 0.08 10) 0 10px, oklch(92% 0.06 10) 10px 20px);
}

.page {
  position: absolute;
  inset: 0;
  border-radius: var(--r-page);
  background: var(--white);
  padding: 10px;
  box-shadow: var(--shadow-page);
  overflow: hidden;
}
#stage {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: calc(var(--r-page) - 10px);
  touch-action: none;
  overflow: hidden;
  background: var(--sky-tint);
}

#stage .item { cursor: grab; }
#stage .item .hit { fill: transparent; }
#stage .item.dragging { cursor: grabbing; }
#stage .item.selected .art { filter: url(#diecut); }
#stage .item.selected .art > * { animation: peel var(--dur-mid) var(--ease-out); transform-box: fill-box; transform-origin: bottom center; }
@keyframes peel { from { transform: scale(0.96); } to { transform: scale(1); } }

#stage .scene-enter { animation: scene-in 420ms var(--ease-out); transform-origin: center; }
@keyframes scene-in { from { opacity: 0; transform: scale(1.03); } to { opacity: 1; transform: scale(1); } }
#stage .item-enter > .art { animation: item-in 320ms var(--ease-out); transform-origin: bottom center; transform-box: fill-box; }
@keyframes item-in { from { opacity: 0; transform: translateY(-40px) scale(0.85); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* 场景里的微动 */
.drift { animation: drift 16s ease-in-out infinite alternate; }
.drift-slow { animation: drift 30s ease-in-out infinite alternate; }
@keyframes drift { from { transform: translateX(-30px); } to { transform: translateX(30px); } }
.spin-slow { animation: spin 70s linear infinite; transform-box: fill-box; transform-origin: center; }
.spin { animation: spin 48s linear infinite; transform-box: fill-box; transform-origin: center; }
.unspin { animation: spin 48s linear infinite reverse; transform-box: fill-box; transform-origin: center; }
@keyframes spin { to { transform: rotate(360deg); } }
.sway { animation: sway 5s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: bottom center; }
@keyframes sway { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
.flag { animation: flag 2.6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: top center; }
@keyframes flag { from { transform: rotate(-9deg); } to { transform: rotate(9deg); } }
.waves { animation: waves 9s linear infinite; }
.waves-slow { animation: waves 16s linear infinite; }
.waves-rev { animation: waves 11s linear infinite reverse; }
@keyframes waves { to { transform: translateX(calc(-1 * var(--len, 200px))); } }
.shimmer { animation: shimmer 3.2s ease-in-out infinite alternate; }
@keyframes shimmer { from { opacity: 0.35; transform: translateX(-16px); } to { opacity: 1; transform: translateX(16px); } }
.bob { animation: bob 3s ease-in-out infinite alternate; }
.bob-rev { animation: bob 3s ease-in-out infinite alternate-reverse; }
@keyframes bob { from { transform: translateY(-7px); } to { transform: translateY(7px); } }
.flutter { animation: flutter 0.55s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes flutter { from { transform: scaleX(1); } to { transform: scaleX(0.55); } }
.twinkle { animation: twinkle 2.2s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes twinkle { from { opacity: 0.35; transform: scale(0.85); } to { opacity: 1; transform: scale(1.08); } }
.pulse { animation: pulse 2.8s ease-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 0% { opacity: 0; transform: scale(0.4); } 30% { opacity: 1; } 100% { opacity: 0; transform: scale(1.15); } }
.swing { animation: swingA 3.2s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: top center; }
@keyframes swingA { from { transform: rotate(-7deg); } to { transform: rotate(7deg); } }
.seesaw { animation: seesaw 4s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes seesaw { from { transform: rotate(-4deg); } to { transform: rotate(5deg); } }

/* 选中物品的小工具条 */
.item-tools {
  position: absolute;
  display: flex;
  gap: var(--space-xs);
  padding: 6px;
  border-radius: 999px;
  background: var(--white);
  box-shadow: var(--shadow-lift);
  z-index: 5;
  transform: translate(-50%, -100%);
  animation: tools-in 200ms var(--ease-out);
}
@keyframes tools-in { from { opacity: 0; transform: translate(-50%, -90%); } to { opacity: 1; transform: translate(-50%, -100%); } }
.it {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--paper);
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast);
}
.it svg { width: 26px; height: 26px; }
.it:active { transform: scale(0.88); background: var(--paper-2); }
.it-danger { color: var(--danger); background: oklch(95% 0.04 25); }

.toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: 10px 12px 10px 20px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font-size: 17px;
  box-shadow: var(--shadow-lift);
  z-index: 6;
  animation: toast-in 240ms var(--ease-out);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast button {
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--sun);
  color: var(--ink);
  font-size: 17px;
}
.toast button:active { transform: scale(0.94); }

/* ---------- 贴纸书 ---------- */

.book {
  grid-area: book;
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  min-height: 0;
  padding: var(--space-xl) var(--space-xl) var(--space-xl) 0;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding-top: 28px;
  z-index: 2;
}
.tab {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  width: 92px;
  height: 96px;
  margin-right: -6px;
  padding-right: 6px;
  border-radius: 22px 0 0 22px;
  font-size: 17px;
  color: var(--ink-soft);
  transform: translateX(8px);
  transition: transform var(--dur-mid) var(--ease-out), background var(--dur-mid), color var(--dur-mid);
}
.tab svg { width: 44px; height: 44px; }
.tab-scene { background: var(--sky-tint); }
.tab-people { background: var(--peach-tint); }
.tab-clothes { background: var(--straw-tint); }
.tab-props { background: var(--lilac-tint); }
.tab.active {
  background: var(--white);
  color: var(--ink);
  transform: translateX(0);
  box-shadow: -4px 3px 10px oklch(60% 0.08 20 / 0.12);
}
.tab:not(.active):active { transform: translateX(4px) scale(0.97); }

.sheet {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--white);
  border-radius: var(--r-page) 0 var(--r-page) var(--r-page);
  border-top-left-radius: 0;
  box-shadow: var(--shadow-page);
  padding: var(--space-xl) var(--space-lg) var(--space-2xl) var(--space-xl);
  scrollbar-width: none;
}
.sheet::-webkit-scrollbar { display: none; }

.sec { margin-bottom: var(--space-xl); }
.sec-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: 0 0 var(--space-md) 0;
  font-size: 20px;
  font-weight: 400;
  color: var(--ink);
}
.sec-title::before {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--straw);
  flex: none;
}
.sec-title .sec-sub { font-size: 14px; color: var(--ink-soft); margin-left: auto; font-family: var(--font-ui); }

.stickers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: var(--space-md);
}
.stickers.wide { grid-template-columns: repeat(2, 1fr); }
.stickers.faces { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }

.sticker {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  gap: 2px;
  padding: 8px 6px 6px;
  border-radius: var(--r-sticker);
  background: var(--white);
  box-shadow: var(--shadow-sticker);
  aspect-ratio: 1;
  color: var(--ink);
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast);
  overflow: hidden;
}
.sticker svg { width: 100%; height: 100%; min-height: 0; }
/* 贴纸缩略图里不跑循环动画：几十张同时动很吵，也省电 */
.sticker svg * { animation: none !important; }
.sticker .name { font-size: 15px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.sticker:active { transform: scale(0.93); box-shadow: 0 1px 0 var(--line); }
.sticker.selected { box-shadow: 0 0 0 4px var(--straw), var(--shadow-sticker); }
.sticker.selected::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--straw) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 10.5 L8.5 14 L15 6.5' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 16px no-repeat;
}
.sticker.scene { aspect-ratio: 4 / 3.3; padding: 6px; }
.sticker.scene svg { border-radius: 14px; }
.sticker.none svg { opacity: 0.35; }
.sticker.add { background: var(--straw-tint); color: var(--straw-deep); }
.sticker.add svg { width: 60%; }
.sticker.toggle { aspect-ratio: 1.6; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid var(--white);
  box-shadow: 0 0 0 2px var(--line), 0 3px 6px oklch(60% 0.08 20 / 0.15);
  transition: transform var(--dur-fast) var(--ease-out);
}
.swatch:active { transform: scale(0.9); }
.swatch.selected { box-shadow: 0 0 0 4px var(--straw), 0 3px 6px oklch(60% 0.08 20 / 0.15); transform: scale(1.1); }
.swatch.face { display: grid; place-items: center; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin: 0 0 var(--space-lg);
}
.chip {
  flex: none;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink-soft);
  font-size: 17px;
  transition: transform var(--dur-fast) var(--ease-out), background var(--dur-fast), color var(--dur-fast);
}
.chip.active { background: var(--straw); color: var(--white); }
.chip:active { transform: scale(0.94); }
.chips.patterns .chip { display: flex; align-items: center; gap: 6px; }
.chip .pat { width: 22px; height: 22px; border-radius: 6px; background: var(--straw); }
.chip.active .pat { background: var(--white); opacity: .9; }

.hint {
  display: grid;
  justify-items: center;
  gap: var(--space-md);
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
  color: var(--ink-soft);
  font-size: 18px;
}
.hint svg { width: 120px; height: 120px; }

/* ---------- 拍照 ---------- */

.photo {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--space-xl);
  background: oklch(40% 0.06 340 / 0.55);
  backdrop-filter: blur(6px);
  animation: fade-in var(--dur-mid) var(--ease-out);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.photo-card {
  display: grid;
  gap: var(--space-lg);
  padding: 18px 18px 22px;
  border-radius: 18px;
  background: var(--white);
  box-shadow: var(--shadow-lift);
  transform: rotate(-1.5deg);
  animation: photo-in 360ms var(--ease-out);
  max-width: min(92vw, 880px);
}
@keyframes photo-in { from { opacity: 0; transform: rotate(-1.5deg) translateY(30px) scale(0.92); } to { opacity: 1; transform: rotate(-1.5deg) translateY(0) scale(1); } }
.photo-card img {
  display: block;
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: 8px;
  background: var(--paper-2);
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}
.photo-actions { display: flex; gap: var(--space-md); justify-content: center; }
.photo-hint { margin: 0; text-align: center; font-family: var(--font-ui); font-size: 14px; color: var(--ink-soft); }

.btn {
  padding: 12px 24px;
  border-radius: 999px;
  background: var(--paper-2);
  font-size: 19px;
  transition: transform var(--dur-fast) var(--ease-out);
}
.btn:active { transform: scale(0.95); }
.btn-primary { background: var(--straw); color: var(--white); }

/* ---------- 竖屏 / 小屏 ---------- */

@media (orientation: portrait) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 76px auto minmax(0, 1fr);
    grid-template-areas: "top" "stage" "book";
  }
  .stage-wrap { container-type: normal; padding: var(--space-xl) var(--space-xl) var(--space-lg); }
  .frame { width: min(100%, calc(52dvh * 4 / 3)); }
  .book {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    padding: 0 var(--space-xl) var(--space-lg);
  }
  .tabs { flex-direction: row; padding: 0 0 0 var(--space-xl); gap: var(--space-sm); }
  .tab {
    width: 96px;
    height: 72px;
    margin: 0 0 -6px 0;
    padding: 0 0 6px 0;
    border-radius: 22px 22px 0 0;
    grid-auto-flow: column;
    gap: 6px;
    transform: translateY(8px);
  }
  .tab svg { width: 34px; height: 34px; }
  .tab.active { transform: translateY(0); box-shadow: 0 -4px 10px oklch(60% 0.08 20 / 0.12); }
  .sheet { border-radius: var(--r-page); border-top-left-radius: 0; }
}

@media (max-width: 720px) {
  .app { grid-template-rows: 64px auto minmax(0, 1fr); }
  .title span { display: none; }
  .topbar { padding: var(--space-sm) var(--space-lg) 0; }
  .tb { width: 54px; }
  .tb-icon { width: 46px; height: 46px; }
  .stage-wrap { padding: var(--space-lg); }
  .frame { width: 100%; }
  .book { padding: 0 var(--space-lg) var(--space-lg); }
  .tabs { padding-left: var(--space-md); }
  .tab { width: 78px; height: 64px; font-size: 15px; }
  .sheet { padding: var(--space-lg) var(--space-md) var(--space-xl); }
  .stickers { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); }
}

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