:root {
  color-scheme: light;
  --ink: #1c1915;
  --muted: #6d645b;
  --line: #e4dcd2;
  --paper: #f6f1ea;
  --accent: #b5452d;
  --accent-ink: #fff8f4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Songti SC", serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, #fff, transparent 42%),
    var(--paper);
}

main {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 64px;
}

#working {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin: 0;
  padding: 24px 16px 40px;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 214, 196, 0.72), transparent 42%),
    var(--paper);
}

#working[hidden] { display: none; }

.working-card {
  flex: 0 0 auto;
}

.working-card h2:empty,
.working-card .status:empty {
  display: none;
}

.working-card .eyebrow {
  margin: 8px 0 0;
  letter-spacing: 0.08em;
  text-transform: none;
  font-size: 13px;
  color: #e08a72;
}

#working #preview {
  width: min(360px, calc(100vw - 32px), calc((100dvh - 180px) * 9 / 16));
  margin-top: 0;
}

.eyebrow {
  margin: 0 0 8px;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

h1, h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.03em;
}

h1 { font-size: 40px; }

.lead, .status {
  font-family: "Avenir Next", "PingFang SC", sans-serif;
}

.lead {
  max-width: 62ch;
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 8px;
}

.field-head label,
.story-count {
  margin: 0;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 13px;
}

.story-count {
  color: var(--muted);
}

.story-count.is-full {
  color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 220px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font: 16px/1.6 "Avenir Next", "PingFang SC", sans-serif;
  resize: vertical;
}

button {
  height: 46px;
  margin-top: 16px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 15px/1 "Avenir Next", "PingFang SC", sans-serif;
  cursor: pointer;
}

button:disabled { opacity: 0.45; cursor: default; }

.status {
  min-height: 1.4em;
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.status.error { color: var(--accent); }

#player {
  width: min(420px, calc(100% - 24px), calc((100dvh - 120px) * 9 / 16));
  margin: 16px auto 32px;
}

.frame {
  position: relative;
  aspect-ratio: 9 / 16;
  width: 100%;
  overflow: hidden;
  border-radius: 18px;
  background: #1c1915;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  container: stage / size;
}

.leave,
#continue {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: rgba(255, 246, 238, 0.95);
  color: #9a3b28;
  box-shadow: 0 8px 18px rgba(28, 18, 12, 0.28);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.leave {
  position: absolute;
  z-index: 6;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
}

.leave .icon,
#continue .icon {
  width: 22px;
  height: 22px;
  display: block;
}

.ending {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 214, 196, 0.42), transparent 46%),
    rgba(48, 24, 28, 0.42);
}

.ending[hidden] { display: none; }

.ending-card {
  position: relative;
  width: min(340px, 100%);
  padding: 26px 22px 18px;
  border: 4px solid #fff;
  border-radius: 36px;
  background:
    radial-gradient(circle at 18% 0, rgba(255, 255, 255, 0.95), transparent 34%),
    linear-gradient(180deg, #fff7f2 0%, #ffe4d6 100%);
  color: #c2543f;
  text-align: center;
  box-shadow:
    0 0 0 3px #f4a28f,
    0 18px 0 rgba(196, 84, 63, 0.12),
    0 22px 36px rgba(72, 28, 24, 0.28);
  animation: ending-pop 0.42s cubic-bezier(0.2, 1.35, 0.36, 1);
}

.ending-card::before,
.ending-card::after {
  position: absolute;
  color: #f0b43a;
  font-size: 18px;
  line-height: 1;
  text-shadow: 0 2px 0 #fff;
}

.ending-card::before {
  content: "✦";
  top: 14px;
  left: 18px;
  transform: rotate(-12deg);
}

.ending-card::after {
  content: "✦";
  top: 18px;
  right: 20px;
  font-size: 13px;
  transform: rotate(16deg);
}

.ending-face {
  position: relative;
  display: inline-block;
  width: 74px;
  height: 74px;
  margin-bottom: 6px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #ffd0b8;
  box-shadow: 0 8px 0 rgba(244, 162, 143, 0.45);
  animation: leave-bob 2.6s ease-in-out infinite;
}

.ending-face::before {
  content: "";
  position: absolute;
  top: -16px;
  left: 8px;
  width: 22px;
  height: 26px;
  border: 3px solid #fff;
  border-radius: 50% 50% 42% 42%;
  background: #ffd0b8;
  box-shadow: 36px 2px 0 -3px #fff, 36px 2px 0 #ffd0b8;
}

.ending-face::after {
  content: "";
  position: absolute;
  left: 24px;
  bottom: 16px;
  width: 22px;
  height: 12px;
  border-bottom: 4px solid #e36b62;
  border-radius: 0 0 18px 18px;
}

.ending-face i {
  position: absolute;
  top: 26px;
  width: 8px;
  height: 10px;
  border-radius: 50%;
  background: #5c3a32;
  box-shadow: 0 -3px 0 1px #fff;
}

.ending-face i:first-child { left: 18px; }
.ending-face i:last-child { right: 18px; }

.ending-face b {
  position: absolute;
  left: 8px;
  top: 38px;
  width: 12px;
  height: 7px;
  border-radius: 50%;
  background: #ffb0a4;
  box-shadow: 46px 0 0 #ffb0a4;
}

.ending-card h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.02em;
  color: #c2543f;
}

.ending-card p {
  margin: 6px 0 0;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 14px;
  color: #a56a58;
}

.ending-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

.ending-actions button {
  height: 42px;
  margin: 0;
  padding: 0 22px;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(194, 84, 63, 0.22);
  font-weight: 700;
}

#ending-replay {
  background: #ff8f78;
  color: #fff;
}

#ending-close {
  background: #fff;
  color: #c2543f;
}

@container stage (max-height: 280px) {
  .ending { padding: 8px; }
  .ending-card {
    width: min(300px, 100%);
    padding: 8px 14px 8px;
    border-width: 3px;
    border-radius: 22px;
    box-shadow:
      0 0 0 2px #f4a28f,
      0 10px 18px rgba(72, 28, 24, 0.24);
  }
  .ending-card::before,
  .ending-card::after { display: none; }
  .ending-face {
    width: 36px;
    height: 36px;
    margin-bottom: 2px;
    border-width: 2px;
    box-shadow: none;
  }
  .ending-face::before {
    top: -7px;
    left: 3px;
    width: 11px;
    height: 13px;
    border-width: 2px;
    box-shadow: 18px 1px 0 -2px #fff, 18px 1px 0 #ffd0b8;
  }
  .ending-face::after {
    left: 11px;
    bottom: 7px;
    width: 12px;
    height: 6px;
    border-bottom-width: 2px;
  }
  .ending-face i {
    top: 12px;
    width: 4px;
    height: 5px;
    box-shadow: none;
  }
  .ending-face i:first-child { left: 8px; }
  .ending-face i:last-child { right: 8px; }
  .ending-face b {
    left: 3px;
    top: 18px;
    width: 6px;
    height: 4px;
    box-shadow: 22px 0 0 #ffb0a4;
  }
  .ending-card h2 { font-size: 18px; }
  .ending-card p {
    margin-top: 2px;
    font-size: 12px;
  }
  .ending-actions {
    gap: 8px;
    margin-top: 6px;
  }
  .ending-actions button {
    height: 32px;
    padding: 0 16px;
    border-width: 2px;
    font-size: 13px;
    box-shadow: none;
  }
}

@keyframes ending-pop {
  from { transform: scale(0.86) rotate(-2deg); }
  to { transform: none; }
}

@media (max-height: 520px) {
  #working { gap: 12px; padding: 12px; }
  .working-card {
    padding: 12px 16px 10px;
    border-radius: 24px;
  }
  .working-card::before,
  .working-card::after { display: none; }
  .working-card .ending-face {
    width: 46px;
    height: 46px;
    margin-bottom: 0;
    border-width: 2px;
    box-shadow: none;
  }
  .working-card .ending-face::before {
    top: -9px;
    left: 4px;
    width: 13px;
    height: 15px;
    border-width: 2px;
    box-shadow: 22px 1px 0 -2px #fff, 22px 1px 0 #ffd0b8;
  }
  .working-card .ending-face::after {
    left: 15px;
    bottom: 9px;
    width: 14px;
    height: 7px;
    border-bottom-width: 3px;
  }
  .working-card .ending-face i {
    top: 15px;
    width: 5px;
    height: 6px;
    box-shadow: none;
  }
  .working-card .ending-face i:first-child { left: 11px; }
  .working-card .ending-face i:last-child { right: 11px; }
  .working-card .ending-face b {
    left: 4px;
    top: 23px;
    width: 8px;
    height: 4px;
    box-shadow: 28px 0 0 #ffb0a4;
  }
  .working-card h2 { font-size: 20px; }
  .working-card .eyebrow { margin-top: 4px; }
}

@keyframes leave-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-2px) rotate(-6deg); }
}

#preview {
  margin-top: 18px;
  cursor: default;
}

#preview[hidden] { display: none; }

#preview-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

#preview-actor {
  position: absolute;
  left: 50%;
  bottom: 0;
  height: 58%;
  max-width: 78%;
  transform: translateX(-50%);
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.35));
}

#preview-critter {
  position: absolute;
  left: 8%;
  bottom: 8%;
  height: 24%;
  max-width: 22%;
  object-fit: contain;
  object-position: center bottom;
  animation: critter-hop 1.1s ease-in-out infinite;
}

#bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

#bg.is-drift { animation: drift 22s ease-in-out infinite alternate; }
#bg.is-push { animation: cam-push 16s ease-in-out infinite alternate; }
#bg.is-pull { animation: cam-pull 16s ease-in-out infinite alternate; }
#bg.is-pan-left { animation: cam-left 14s ease-in-out infinite alternate; }
#bg.is-pan-right { animation: cam-right 14s ease-in-out infinite alternate; }
#bg.is-sway { animation: cam-sway 7s ease-in-out infinite; }

#actor-wrap.is-bow { animation: actor-bow 0.9s ease; }
#actor-wrap.is-lean { animation: actor-lean 1.1s ease; }
#actor-wrap.is-recoil { animation: actor-recoil 0.45s ease; }
#actor-wrap.is-step { animation: actor-step 0.7s ease; }

#glow,
#fx,
#flash {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#glow {
  z-index: 1;
  background: radial-gradient(ellipse at 50% 78%, rgba(255, 148, 64, 0.34), transparent 58%);
  opacity: 0;
  transition: opacity 0.45s ease;
}

#glow.is-on { opacity: 1; }

#fx { z-index: 2; }

#flash {
  z-index: 4;
  background: #fff8ee;
  opacity: 0;
}

#flash.is-on { animation: flash 0.45s ease; }

#critters {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}

.critter {
  position: absolute;
  bottom: 10%;
  height: 26%;
  max-width: 22%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.28));
}

.critter.is-hop { animation: critter-hop 1.1s ease-in-out infinite; }
.critter.is-fly { animation: critter-fly 7s ease-in-out infinite alternate; }
.critter.is-swim { animation: critter-swim 5.5s ease-in-out infinite; }
.critter.is-walk { animation: critter-walk 8s linear infinite; }
.critter.is-scurry { animation: critter-scurry 3.4s linear infinite; }

@keyframes critter-hop {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(-26px); }
}

@keyframes critter-fly {
  from { transform: translate3d(0, 8px, 0); }
  to { transform: translate3d(180px, -70px, 0); }
}

@keyframes critter-swim {
  0% { transform: translateX(0) translateY(0); }
  50% { transform: translateX(120px) translateY(-12px); }
  100% { transform: translateX(0) translateY(0); }
}

@keyframes critter-walk {
  0% { transform: translateX(0); }
  100% { transform: translateX(160px); }
}

@keyframes critter-scurry {
  0% { transform: translateX(0) translateY(0); }
  25% { transform: translateX(40px) translateY(-10px); }
  50% { transform: translateX(90px) translateY(0); }
  75% { transform: translateX(130px) translateY(-8px); }
  100% { transform: translateX(170px) translateY(0); }
}

#actor-wrap {
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 2;
  width: 78%;
  height: 58%;
  transform: translateX(-50%);
  pointer-events: none;
}

#actor-wrap.is-enter { animation: arrive 0.65s ease; }

#actor-wrap.is-loading #actor,
#actor:not([src]) {
  opacity: 0;
}

#actor {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.35));
  animation: bob 3.6s ease-in-out infinite;
}

.frame.is-booting .dialogue,
.frame.is-booting #actor-wrap,
.frame.is-booting .poem-panel,
.frame.is-booting #leave {
  visibility: hidden;
}

.frame.is-shake { animation: shake 0.42s linear; }

.poem-panel {
  position: absolute;
  z-index: 2;
  top: 56px;
  left: 16px;
  width: max-content;
  max-width: min(42%, 280px);
  height: auto;
  max-height: calc(100% - 56px - 120px);
  padding: 12px 14px 14px;
  border-radius: 12px;
  background: rgba(255, 248, 239, 0.82);
  color: #3a2a22;
  box-shadow: 0 10px 24px rgba(28, 18, 12, 0.14);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  scrollbar-width: thin;
  box-sizing: border-box;
}

.poem-panel[hidden] {
  display: none;
}

#poem-title {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.35;
}

.poem-author {
  margin: 4px 0 10px;
  color: #6b5348;
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: 13px;
  line-height: 1.35;
}

.poem-author:empty {
  display: none;
}

.poem-text {
  margin: 0;
  font-family: "Songti SC", "STSong", "Noto Serif SC", serif;
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-line;
}

.poem-text .verse {
  display: block;
}

.poem-text .verse.is-current {
  color: #9a3b28;
  font-weight: 700;
}

@media (max-width: 720px) {
  .poem-panel {
    top: 52px;
    left: 10px;
    right: auto;
    width: max-content;
    max-width: min(58%, 220px);
    height: auto;
    max-height: calc(100% - 52px - 128px);
    padding: 10px 12px;
  }

  #poem-title {
    font-size: 17px;
  }

  .poem-text {
    font-size: 14px;
    line-height: 1.65;
  }
}

.dialogue {
  position: absolute;
  z-index: 5;
  left: 16px;
  right: 16px;
  bottom: 16px;
  padding: 14px 16px 12px;
  border-radius: 14px;
  background: rgba(255, 246, 238, 0.62);
  color: #3a2a22;
  box-shadow: 0 10px 24px rgba(28, 18, 12, 0.16);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#speaker {
  margin: 0 0 6px;
  color: #9a3b28;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 13px;
  font-weight: 650;
}

#line {
  margin: 0;
  height: 1.6em;
  padding-right: 58px;
  overflow: hidden;
  white-space: nowrap;
  font-size: 18px;
  line-height: 1.6;
  scrollbar-width: none;
}

#line-zh {
  margin: 4px 0 0;
  padding-right: 58px;
  color: #6b5348;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 13px;
  line-height: 1.35;
}

#line-zh[hidden] {
  display: none;
}

#line.has-pinyin {
  height: 2.65em;
  line-height: 1;
}

#line.has-pinyin .char {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  vertical-align: bottom;
  line-height: 1;
  margin: 0 0.5px;
}

#line.has-pinyin .py {
  display: block;
  height: 13px;
  font-style: normal;
  font-weight: 600;
  font-size: 10px;
  line-height: 13px;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  letter-spacing: 0;
  color: inherit;
  white-space: nowrap;
}

#line.has-pinyin b {
  font-weight: inherit;
  font-size: 18px;
  line-height: 1.15;
}

#line::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

#continue {
  position: absolute;
  right: 10px;
  bottom: 10px;
}

#continue.is-nudge {
  animation: continue-nudge 0.42s ease-in-out infinite;
}

.continue-hint {
  position: absolute;
  z-index: 4;
  right: 18px;
  bottom: 52px;
  width: 42px;
  height: 42px;
  pointer-events: none;
  transform-origin: 72% 88%;
  filter: drop-shadow(0 4px 0 rgba(154, 59, 40, 0.16));
  animation: continue-point 0.9s ease-in-out infinite;
}

.continue-hint svg {
  display: block;
  width: 100%;
  height: 100%;
}

.continue-hint[hidden],
#continue[hidden] { display: none; }

@keyframes continue-nudge {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  30% { transform: translateX(-3px) rotate(-8deg); }
  70% { transform: translateX(3px) rotate(8deg); }
}

@keyframes continue-point {
  0%, 100% { transform: rotate(148deg) translate(0, 0); }
  50% { transform: rotate(158deg) translate(2px, 5px); }
}

.char {
  color: rgba(58, 42, 34, 0.38);
}

.char.is-read {
  color: #3a2a22;
}

.char.is-current {
  color: #c45a32;
}

.player-bar,
.share,
.music-credit {
  display: none;
}

.player-bar button { margin-top: 0; }

#back, #speech, #music {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.music-credit {
  margin: 10px 0 0;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 13px;
  color: var(--muted);
}

.music-credit a {
  color: inherit;
}

#voice,
#bgm { display: none; }

.share {
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 12px 0 0;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 13px;
  color: var(--muted);
}

.share a {
  color: var(--accent);
  word-break: break-all;
}

#copy { margin-top: 0; }

#editor.is-home {
  width: min(1080px, calc(100% - 28px));
}

#editor.is-home #library { margin-top: 8px; }
#editor.is-home #library h2 { display: none; }

#library { margin-top: 36px; }

#library h2 {
  font-size: 22px;
}

#templates {
  display: grid;
  grid-template-columns: repeat(auto-fit, 134px);
  align-items: end;
  justify-content: center;
  gap: 36px 0;
  margin: 22px 0 0;
  padding: 28px 18px 26px;
  list-style: none;
  background:
    linear-gradient(#4a2f20, #4a2f20) 0 0 / 16px 100% no-repeat,
    linear-gradient(#4a2f20, #4a2f20) 100% 0 / 16px 100% no-repeat,
    linear-gradient(#7a5136, #5c3b26);
  overflow: hidden;
  border-radius: 6px;
  box-shadow:
    inset 0 16px 0 #3d2618,
    inset 0 -18px 0 #3d2618,
    0 18px 36px rgba(48, 26, 12, 0.16);
}

#templates:empty { display: none; }

#templates li.book {
  --cloth: #8d3228;
  position: relative;
  justify-self: center;
  width: 118px;
  margin: 0;
  padding: 0 0 10px;
  overflow: visible;
  background: transparent;
}

#templates li.book:nth-child(7n+2) { --cloth: #1e3a4c; }
#templates li.book:nth-child(7n+3) { --cloth: #2c4a38; }
#templates li.book:nth-child(7n+4) { --cloth: #a15c32; }
#templates li.book:nth-child(7n+5) { --cloth: #6b3f55; }
#templates li.book:nth-child(7n+6) { --cloth: #8a6a32; }
#templates li.book:nth-child(7n) { --cloth: #3d342c; }

#templates li.book:nth-child(5n+1) .book-link { height: 168px; }
#templates li.book:nth-child(5n+2) .book-link { height: 186px; }
#templates li.book:nth-child(5n+3) .book-link { height: 176px; }
#templates li.book:nth-child(5n+4) .book-link { height: 194px; }
#templates li.book:nth-child(5n) .book-link { height: 160px; }

#templates li.book::after {
  content: "";
  position: absolute;
  z-index: 0;
  left: -12px;
  right: -12px;
  bottom: 0;
  height: 16px;
  background: linear-gradient(#f4e0b8, #e2c088 28%, #b07d45 62%, #6d4528);
  box-shadow:
    0 8px 0 #3e2718,
    0 14px 12px rgba(28, 14, 6, 0.32);
}

.book-link {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: stretch;
  height: 176px;
  color: var(--ink);
  text-decoration: none;
  filter: drop-shadow(5px 8px 4px rgba(22, 10, 4, 0.38));
  transition: transform 0.18s ease;
}

.book-link:hover { transform: translateY(-10px); }

.book-spine {
  width: 16px;
  flex: none;
  border-radius: 3px 0 0 2px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.4), transparent 42%, rgba(255, 255, 255, 0.2) 68%, rgba(0, 0, 0, 0.28)),
    var(--cloth);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.18);
}

.book-spine::before,
.book-spine::after {
  content: "";
  display: block;
  height: 2px;
  margin: 14px 3px 0;
  background: rgba(255, 236, 210, 0.55);
}

.book-spine::after { margin-top: 5px; }

.book-cover {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  border-radius: 0 3px 3px 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent 28%),
    var(--cloth);
}

.book-cover::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: 2px;
  right: 0;
  bottom: 2px;
  width: 5px;
  background: repeating-linear-gradient(90deg, #f7f1e6 0 1px, #ddd4c6 1px 2px);
}

.book-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-cover.is-blank {
  display: flex;
  align-items: center;
  justify-content: center;
}

#templates .card-title {
  position: absolute;
  z-index: 2;
  right: 7px;
  bottom: 0;
  left: 0;
  padding: 28px 8px 8px;
  background: linear-gradient(transparent, rgba(20, 12, 8, 0.9));
  color: #fff8f2;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.book-cover.is-blank .card-title {
  position: static;
  display: block;
  padding: 10px 12px 10px 8px;
  background: none;
  text-align: center;
  color: #fff6ee;
}

.card-actions {
  position: absolute;
  z-index: 3;
  top: 6px;
  right: 6px;
  left: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

#templates li.book:hover .card-actions,
#templates li.book:focus-within .card-actions {
  opacity: 1;
}

.card-actions button,
.card-title-input {
  height: 32px;
  margin: 0;
  border-radius: 999px;
  font: 600 13px/1 "Avenir Next", "PingFang SC", sans-serif;
}

.card-actions button {
  height: 24px;
  padding: 0 7px;
  border: 1px solid rgba(255, 248, 242, 0.7);
  background: rgba(255, 248, 242, 0.94);
  color: var(--ink);
  font-size: 11px;
}

.card-delete { color: var(--accent); }

.card-title:has(input) {
  display: block;
  -webkit-line-clamp: unset;
}

.card-title-input {
  width: 100%;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

#progress {
  margin-left: auto;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  font-size: 13px;
  color: var(--muted);
}

@keyframes drift {
  from { transform: scale(1.05); }
  to { transform: scale(1.12) translate3d(-1.6%, -1%, 0); }
}

@keyframes cam-push {
  from { transform: scale(1.04); }
  to { transform: scale(1.18); }
}

@keyframes cam-pull {
  from { transform: scale(1.16); }
  to { transform: scale(1.04); }
}

@keyframes cam-left {
  from { transform: scale(1.1) translateX(2%); }
  to { transform: scale(1.1) translateX(-3%); }
}

@keyframes cam-right {
  from { transform: scale(1.1) translateX(-2%); }
  to { transform: scale(1.1) translateX(3%); }
}

@keyframes cam-sway {
  0%, 100% { transform: scale(1.06) rotate(-0.6deg); }
  50% { transform: scale(1.06) rotate(0.6deg); }
}

@keyframes actor-bow {
  0%, 100% { transform: translateX(-50%) translateY(0) rotate(0deg); }
  40% { transform: translateX(-50%) translateY(16px) rotate(7deg); }
}

@keyframes actor-lean {
  0%, 100% { transform: translateX(-50%) rotate(0deg); }
  50% { transform: translateX(-46%) rotate(-4deg); }
}

@keyframes actor-recoil {
  0%, 100% { transform: translateX(-50%); }
  35% { transform: translateX(-62%) translateY(6px); }
}

@keyframes actor-step {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  45% { transform: translateX(-42%) translateY(8px); }
}

@keyframes arrive {
  from { opacity: 0; transform: translateX(-50%) translateY(28px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

@keyframes flash {
  0% { opacity: 0; }
  18% { opacity: 0.5; }
  100% { opacity: 0; }
}

@media (hover: none) {
  .card-actions { opacity: 1; }
}

@media (max-width: 760px) {
  h1 { font-size: 32px; }
  #player {
    width: min(100%, calc(100dvh * 9 / 16));
    margin: 0 auto;
  }
  .frame {
    aspect-ratio: 9 / 16;
    border-radius: 0;
  }
  #working #preview {
    width: min(320px, calc(100vw - 24px), calc((100dvh - 160px) * 9 / 16));
  }
  #actor-wrap { width: 88%; height: 62%; }
  #preview-actor { max-width: 72%; height: 62%; }
  #line { font-size: 16px; }
  #templates {
    grid-template-columns: repeat(auto-fit, 108px);
    gap: 28px 0;
    padding: 22px 14px 20px;
  }
  #templates li.book { width: 92px; margin: 0; }
  #templates li.book:nth-child(5n+1) .book-link { height: 140px; }
  #templates li.book:nth-child(5n+2) .book-link { height: 156px; }
  #templates li.book:nth-child(5n+3) .book-link { height: 148px; }
  #templates li.book:nth-child(5n+4) .book-link { height: 164px; }
  #templates li.book:nth-child(5n) .book-link { height: 136px; }
  #templates .card-title { font-size: 12px; }
}
