:root {
  color-scheme: light;
  --paper: #fff8fb;
  --paper-soft: #f9eef3;
  --ink: #3f3540;
  --ink-soft: #746773;
  --accent: #96566d;
  --accent-dark: #743e52;
  --accent-pale: #ebcfd9;
  --line: rgba(116, 62, 82, 0.16);
  --glass: rgba(255, 250, 252, 0.78);
  --shadow: 0 24px 70px rgba(94, 55, 72, 0.16);
  --radius: 22px;
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-bottom: max(16px, env(safe-area-inset-bottom));
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
}

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

button:focus-visible,
label:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(150, 86, 109, 0.42);
  outline-offset: 4px;
}

button:active,
.secondary-button:active {
  transform: translateY(1px) scale(0.99);
}

.memory-site {
  position: relative;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
}

.memory-page {
  position: absolute;
  inset: 0;
  min-height: 100dvh;
  overflow: auto;
  overscroll-behavior: contain;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 520ms cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0s linear 520ms;
}

.memory-page.is-active {
  z-index: 1;
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}

.reveal {
  opacity: 0;
  transform: translateY(18px);
}

.memory-page.is-active .reveal {
  animation: reveal-in 760ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.memory-page.is-active .reveal-delay {
  animation-delay: 160ms;
}

@keyframes reveal-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cover-page {
  display: grid;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 8vh) 24px calc(var(--safe-bottom) + 26px);
  grid-template-rows: auto 1fr auto;
  background: var(--paper);
}

.cover-art,
.cover-wash {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.cover-art {
  object-fit: cover;
  object-position: center;
}

.cover-wash {
  background:
    linear-gradient(180deg, rgba(255, 250, 252, 0.28), rgba(255, 250, 252, 0.02) 44%),
    linear-gradient(0deg, rgba(255, 248, 251, 0.76), transparent 32%);
}

.cover-copy,
.unlock-wrap {
  position: relative;
  z-index: 1;
  width: min(100%, 640px);
  margin-inline: auto;
  text-align: center;
}

.cover-kicker,
.letter-heading > p,
.song-heading > p,
.gallery-heading > p {
  margin: 0 0 16px;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.14em;
}

.cover-copy h1,
.letter-heading h2,
.song-heading h2,
.gallery-heading h2 {
  margin: 0;
  font-family: "Songti SC", STSong, "Noto Serif CJK SC", serif;
  font-weight: 600;
  letter-spacing: 0.035em;
}

.cover-copy h1 {
  font-size: clamp(2.25rem, 9.4vw, 4.7rem);
  line-height: 1.28;
}

.cover-note {
  max-width: 30rem;
  margin: 22px auto 0;
  color: var(--ink-soft);
  font-family: "Songti SC", STSong, serif;
  font-size: 0.95rem;
  line-height: 1.9;
}

.unlock-wrap {
  align-self: end;
}

.unlock-wrap p {
  margin: 12px 0 0;
  color: rgba(63, 53, 64, 0.7);
  font-size: 0.75rem;
}

.primary-button,
.secondary-button {
  min-height: 50px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

.primary-button {
  width: min(100%, 320px);
  padding: 14px 24px;
  background: var(--accent-dark);
  color: #fff9fb;
  box-shadow: 0 12px 30px rgba(116, 62, 82, 0.24);
  font-weight: 600;
}

.primary-button:hover {
  background: #663348;
  box-shadow: 0 16px 34px rgba(116, 62, 82, 0.28);
}

.letter-page {
  background: var(--paper);
  padding-bottom: calc(92px + var(--safe-bottom));
}

.letter-layout {
  min-height: 100%;
}

.letter-visual {
  height: 42dvh;
  min-height: 300px;
  margin: 0;
  overflow: hidden;
  background: var(--paper-soft);
}

.letter-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 48%;
}

.letter-sheet {
  position: relative;
  z-index: 1;
  margin: -32px 14px 0;
  padding: 38px 24px 68px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  background: rgba(255, 250, 252, 0.94);
  box-shadow: var(--shadow);
}

.letter-heading {
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.letter-heading h2,
.song-heading h2,
.gallery-heading h2 {
  font-size: clamp(2rem, 9vw, 4.6rem);
  line-height: 1.28;
}

.letter-body {
  max-width: 42rem;
  margin: 30px auto 0;
  font-family: "Songti SC", STSong, "Noto Serif CJK SC", serif;
  font-size: 1.02rem;
  line-height: 2.05;
  letter-spacing: 0.03em;
}

.letter-body p {
  margin: 0 0 1.5em;
}

.letter-body blockquote {
  margin: 2.2em 0;
  padding: 8px 0 8px 22px;
  border-left: 2px solid var(--accent);
  color: var(--accent-dark);
  font-size: 1.12em;
  font-weight: 600;
}

.letter-ending {
  color: var(--accent-dark);
  font-weight: 600;
}

.song-page {
  display: grid;
  align-items: end;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 44px) 20px calc(98px + var(--safe-bottom));
  background: var(--paper);
}

.song-art,
.song-wash {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.song-art {
  object-fit: cover;
  object-position: 50% 38%;
}

.song-wash {
  background:
    linear-gradient(180deg, rgba(255, 248, 251, 0.24), rgba(255, 248, 251, 0.02) 36%),
    linear-gradient(0deg, rgba(255, 248, 251, 0.94) 7%, rgba(255, 248, 251, 0.48) 54%, transparent 82%);
}

.song-content {
  position: relative;
  z-index: 1;
  width: min(100%, 680px);
  margin-inline: auto;
}

.song-heading {
  margin-bottom: 28px;
}

.player-panel {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  background: var(--glass);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px) saturate(125%);
  -webkit-backdrop-filter: blur(22px) saturate(125%);
}

.record-orbit {
  display: grid;
  width: 54px;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid rgba(116, 62, 82, 0.24);
  border-radius: 50%;
  background: repeating-radial-gradient(
    circle,
    rgba(150, 86, 109, 0.18) 0 1px,
    transparent 1px 5px
  );
}

.record-orbit span {
  width: 10px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
}

.player-panel.is-playing .record-orbit {
  animation: record-turn 5s linear infinite;
}

@keyframes record-turn {
  to {
    transform: rotate(360deg);
  }
}

.track-copy p {
  margin: 0;
}

.track-title {
  font-family: "Songti SC", STSong, serif;
  font-size: 1.05rem;
  font-weight: 600;
}

.track-status {
  margin-top: 5px !important;
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.play-button {
  min-width: 88px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--accent-dark);
  color: #fff9fb;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 600;
}

.play-button:disabled {
  background: rgba(116, 103, 115, 0.15);
  color: rgba(63, 53, 64, 0.6);
  cursor: not-allowed;
}

.timeline {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.timeline input {
  width: 100%;
  accent-color: var(--accent-dark);
}

.edit-audio,
.gallery-actions {
  grid-column: 1 / -1;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.edit-audio input,
.gallery-manager > input,
.manager-heading > input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.edit-audio p,
.gallery-actions p {
  margin: 9px 0 0;
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 11px 18px;
  border: 1px solid var(--line);
  background: rgba(255, 250, 252, 0.9);
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 600;
}

.gallery-page {
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 76px) 16px calc(104px + var(--safe-bottom));
  background:
    radial-gradient(circle at 88% 7%, rgba(235, 207, 217, 0.58), transparent 32%),
    var(--paper);
}

.gallery-shell {
  width: min(100%, 1100px);
  margin-inline: auto;
}

.gallery-heading {
  max-width: 720px;
  margin-bottom: 42px;
}

.gallery-intro {
  max-width: 31rem;
  margin: 20px 0 0;
  color: var(--ink-soft);
  font-family: "Songti SC", STSong, serif;
  line-height: 1.9;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.gallery-item {
  position: relative;
  min-height: 230px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background: var(--paper-soft);
  box-shadow: 0 14px 40px rgba(94, 55, 72, 0.11);
  cursor: zoom-in;
}

.gallery-item:first-child {
  grid-column: 1 / -1;
  aspect-ratio: 1.32;
}

.gallery-item:not(:first-child) {
  aspect-ratio: 0.78;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.gallery-item:hover img {
  transform: scale(1.025);
}

.gallery-actions {
  margin-top: 28px;
  padding: 22px;
  border: 1px dashed rgba(116, 62, 82, 0.24);
  border-radius: var(--radius);
  background: rgba(255, 250, 252, 0.72);
}

.gallery-manager {
  margin-top: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 250, 252, 0.88);
}

.manager-heading {
  display: grid;
  gap: 16px;
  align-items: center;
}

.manager-heading h3 {
  margin: 0;
  font-family: "Songti SC", STSong, "Noto Serif CJK SC", serif;
  font-size: 1.3rem;
  font-weight: 600;
}

.manager-heading p {
  margin: 7px 0 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
  line-height: 1.65;
}

.gallery-status {
  min-height: 1.4em;
  margin: 16px 0 0;
  color: var(--accent-dark);
  font-size: 0.8rem;
}

.manager-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.manager-empty {
  margin: 0;
  padding: 24px;
  border-radius: 16px;
  background: var(--paper-soft);
  color: var(--ink-soft);
  text-align: center;
  font-size: 0.86rem;
  line-height: 1.7;
}

.manager-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  background: var(--paper-soft);
}

.manager-item img {
  width: 76px;
  height: 88px;
  border-radius: 12px;
  object-fit: cover;
}

.manager-fields {
  min-width: 0;
}

.manager-fields label {
  display: block;
  color: var(--ink-soft);
  font-size: 0.74rem;
  font-weight: 600;
}

.manager-caption {
  width: 100%;
  min-height: 44px;
  margin-top: 7px;
  padding: 10px 12px;
  border: 1px solid rgba(116, 62, 82, 0.22);
  border-radius: 12px;
  background: rgba(255, 250, 252, 0.92);
  color: var(--ink);
  font-size: 1rem;
}

.manager-caption::placeholder {
  color: rgba(63, 53, 64, 0.62);
}

.manager-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.manager-controls button,
.undo-row button {
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid rgba(116, 62, 82, 0.2);
  border-radius: 999px;
  background: rgba(255, 250, 252, 0.96);
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 600;
}

.manager-controls button:disabled {
  color: rgba(63, 53, 64, 0.32);
  cursor: not-allowed;
}

.manager-controls .remove-photo {
  margin-inline-start: auto;
  color: #7d374c;
}

.undo-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 14px;
  background: #f4e3e9;
  color: var(--accent-dark);
  font-size: 0.8rem;
}

.undo-row[hidden] {
  display: none;
}

.page-label {
  position: fixed;
  z-index: 4;
  top: var(--safe-top);
  left: 50%;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: 999px;
  background: rgba(255, 250, 252, 0.74);
  box-shadow: 0 8px 24px rgba(94, 55, 72, 0.08);
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(-8px);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: opacity 320ms ease, transform 320ms ease;
}

body:not([data-page="0"]) .page-label {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.site-nav {
  position: fixed;
  z-index: 5;
  right: 14px;
  bottom: calc(var(--safe-bottom) + 4px);
  left: 14px;
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  gap: 12px;
  align-items: center;
  min-height: 62px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
  background: rgba(255, 250, 252, 0.88);
  box-shadow: 0 14px 38px rgba(94, 55, 72, 0.17);
  opacity: 1;
  backdrop-filter: blur(22px) saturate(120%);
  -webkit-backdrop-filter: blur(22px) saturate(120%);
  transition: opacity 320ms ease, transform 320ms ease;
}

body[data-page="0"] .site-nav {
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
}

.nav-button {
  min-height: 42px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}

.nav-button:disabled {
  color: rgba(63, 53, 64, 0.28);
  cursor: not-allowed;
}

.page-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.page-tabs button {
  height: 4px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(150, 86, 109, 0.18);
  cursor: pointer;
}

.page-tabs button[aria-current="page"] {
  background: var(--accent-dark);
}

.lightbox {
  width: min(calc(100% - 28px), 920px);
  max-width: none;
  max-height: calc(100dvh - 32px);
  padding: 12px;
  overflow: auto;
  border: 0;
  border-radius: var(--radius);
  background: rgba(255, 250, 252, 0.96);
  box-shadow: var(--shadow);
}

.lightbox::backdrop {
  background: rgba(52, 42, 48, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.lightbox img {
  display: block;
  width: 100%;
  max-height: calc(100dvh - 130px);
  border-radius: 16px;
  object-fit: contain;
}

.lightbox p {
  margin: 12px 56px 4px 8px;
  color: var(--ink-soft);
  font-size: 0.84rem;
}

.lightbox-close {
  position: sticky;
  z-index: 1;
  top: 0;
  float: right;
  min-width: 56px;
  min-height: 40px;
  margin: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 252, 0.94);
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
}

.mode-note {
  position: fixed;
  z-index: 8;
  top: var(--safe-top);
  right: 14px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-dark);
  color: #fff9fb;
  font-size: 0.7rem;
  font-weight: 600;
}

@media (min-width: 780px) {
  .cover-page {
    padding-top: calc(var(--safe-top) + 10vh);
  }

  .cover-copy h1 {
    font-size: clamp(3.5rem, 6vw, 5.5rem);
  }

  .letter-layout {
    display: grid;
    grid-template-columns: minmax(360px, 0.86fr) minmax(420px, 1.14fr);
  }

  .letter-visual {
    position: sticky;
    top: 0;
    height: 100dvh;
  }

  .letter-sheet {
    margin: 52px 44px 130px;
    padding: 62px clamp(38px, 6vw, 80px) 82px;
    align-self: start;
  }

  .song-page {
    align-items: center;
    justify-items: end;
    padding-inline: 7vw;
  }

  .song-content {
    width: min(50vw, 620px);
    margin: 0;
  }

  .song-wash {
    background: linear-gradient(
      90deg,
      rgba(255, 248, 251, 0.04) 34%,
      rgba(255, 248, 251, 0.86) 72%,
      rgba(255, 248, 251, 0.96)
    );
  }

  .gallery-grid {
    grid-template-columns: 1.28fr 0.72fr 0.72fr;
    gap: 18px;
  }

  .gallery-item:first-child {
    grid-column: auto;
    grid-row: span 2;
    aspect-ratio: auto;
    min-height: 660px;
  }

  .gallery-item:not(:first-child) {
    grid-column: span 1;
    aspect-ratio: 1;
    min-height: 320px;
  }

  .gallery-item:nth-child(4n) {
    grid-column: span 2;
    aspect-ratio: 1.8;
  }

  .gallery-actions {
    display: flex;
    gap: 18px;
    align-items: center;
    justify-content: space-between;
    text-align: left;
  }

  .gallery-actions p {
    margin: 0;
  }

  .manager-heading {
    grid-template-columns: 1fr auto;
  }

  .manager-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .site-nav {
    right: 50%;
    left: auto;
    width: min(520px, calc(100% - 28px));
    transform: translateX(50%);
  }

  body[data-page="0"] .site-nav {
    transform: translateX(50%) translateY(16px);
  }
}

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

@media (prefers-reduced-transparency: reduce) {
  .player-panel,
  .site-nav,
  .page-label {
    background: #fff8fb;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
