:root {
  color-scheme: dark;
  --ink: #221f1a;
  --paper: #fcfaf4;
  --paper-deep: #f1ecdf;
  --gold: #c99a4a;
  --gold-light: #ecd096;
  --night: #181612;
  --night-soft: #242019;
  --muted: rgba(255, 249, 235, 0.62);
  --book-width: min(82vw, calc((100dvh - 190px) * 1.333), 1120px);
  --turn-duration: 920ms;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--night);
}

body {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: #fff9ed;
  background:
    radial-gradient(circle at 50% -20%, rgba(207, 163, 88, 0.14), transparent 38%),
    radial-gradient(circle at 50% 115%, rgba(96, 73, 39, 0.24), transparent 42%),
    linear-gradient(145deg, #1a1814 0%, #12110e 55%, #1d1913 100%);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  pointer-events: none;
  opacity: 0.22;
  background-image:
    repeating-linear-gradient(98deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(12deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 11px);
  mix-blend-mode: soft-light;
}

button,
input {
  font: inherit;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ambient-light {
  position: fixed;
  z-index: -1;
  width: 34vw;
  height: 34vw;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.09;
  pointer-events: none;
}

.ambient-light--one {
  top: -12vw;
  left: -8vw;
  background: #f1a84a;
}

.ambient-light--two {
  right: -12vw;
  bottom: -18vw;
  background: #4b71a8;
}

.welcome {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 50% 25%, rgba(219, 173, 94, 0.13), transparent 32%),
    rgba(16, 14, 11, 0.94);
  transition: opacity 700ms ease, visibility 700ms ease;
}

.welcome.is-closing {
  visibility: hidden;
  opacity: 0;
}

.welcome__book {
  position: relative;
  width: min(520px, 88vw);
  aspect-ratio: 0.78;
  border: 1px solid rgba(235, 205, 145, 0.35);
  border-radius: 5px 14px 14px 5px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(95, 67, 31, 0.14), transparent 3%, transparent 95%, rgba(95, 67, 31, 0.08)),
    radial-gradient(circle at 35% 20%, rgba(255, 255, 255, 0.8), transparent 28%),
    repeating-linear-gradient(8deg, rgba(72, 50, 28, 0.018) 0 1px, transparent 1px 8px),
    #f4eddc;
  box-shadow:
    0 42px 90px rgba(0, 0, 0, 0.58),
    18px 12px 0 -9px #d7c8ac,
    23px 16px 0 -11px #aa987a;
  overflow: hidden;
  isolation: isolate;
}

.welcome__book::before,
.welcome__book::after {
  position: absolute;
  content: "";
  pointer-events: none;
}

.welcome__book::before {
  inset: 18px;
  border: 1px solid rgba(110, 78, 39, 0.28);
  border-radius: 2px 8px 8px 2px;
}

.welcome__book::after {
  inset: 28px;
  border: 1px solid rgba(201, 154, 74, 0.52);
  border-radius: 1px 6px 6px 1px;
}

.welcome__threads {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 12px;
  z-index: 2;
  display: flex;
  width: 14px;
  flex-direction: column;
  justify-content: space-evenly;
}

.welcome__threads i {
  width: 8px;
  height: 8px;
  border: 1px solid rgba(82, 57, 29, 0.44);
  border-radius: 50%;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.22);
}

.welcome__content {
  position: relative;
  z-index: 3;
  display: flex;
  height: 100%;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding: 58px 54px;
  text-align: center;
}

.welcome__seal,
.identity__seal {
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-family: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
}

.welcome__seal {
  width: 64px;
  height: 64px;
  margin-bottom: 30px;
  color: #9a4034;
  font-size: 1.8rem;
  box-shadow: inset 0 0 0 5px rgba(154, 64, 52, 0.08);
}

.eyebrow {
  margin: 0 0 18px;
  color: #8c724d;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.68rem;
  letter-spacing: 0.24em;
}

.welcome h1 {
  margin: 0;
  font-family: "Noto Serif TC", "Songti TC", "PMingLiU", serif;
  font-size: clamp(2.1rem, 7vw, 3.65rem);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0.14em;
}

.welcome h1 span {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.52em;
  font-weight: 400;
  letter-spacing: 0.25em;
}

.welcome__rule {
  width: 1px;
  height: 44px;
  margin: 25px 0 20px;
  background: linear-gradient(transparent, var(--gold), transparent);
}

.welcome__count {
  margin: 0 0 34px;
  color: #756248;
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 0.94rem;
  letter-spacing: 0.1em;
}

.enter-button {
  display: inline-flex;
  min-height: 50px;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px 24px;
  border: 1px solid rgba(79, 59, 33, 0.72);
  border-radius: 999px;
  color: #fff9ec;
  background: #29231b;
  box-shadow: 0 10px 24px rgba(64, 42, 16, 0.2);
  cursor: pointer;
  letter-spacing: 0.13em;
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
}

.enter-button:hover {
  transform: translateY(-2px);
  background: #3a3023;
  box-shadow: 0 14px 30px rgba(64, 42, 16, 0.28);
}

.enter-button:focus-visible,
.icon-button:focus-visible,
.turn-button:focus-visible,
.page-dot:focus-visible,
.volume-control input:focus-visible {
  outline: 3px solid var(--gold-light);
  outline-offset: 4px;
}

.enter-button svg {
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.welcome__music-note {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 16px 0 0;
  color: #8b795f;
  font-size: 0.75rem;
}

.music-note-icon {
  color: #a27535;
  font-family: Georgia, serif;
  font-size: 1rem;
}

.site-shell {
  display: grid;
  min-height: 100dvh;
  grid-template-rows: auto 1fr auto;
  opacity: 0;
  transform: scale(0.988);
  transition: opacity 850ms ease 180ms, transform 850ms ease 180ms;
}

.site-shell.is-visible {
  opacity: 1;
  transform: scale(1);
}

.topbar {
  display: flex;
  min-height: 78px;
  align-items: center;
  justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) max(26px, env(safe-area-inset-right)) 10px
    max(26px, env(safe-area-inset-left));
}

.identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.identity__seal {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  color: var(--gold-light);
  font-size: 1rem;
  box-shadow: inset 0 0 0 3px rgba(236, 208, 150, 0.07);
}

.identity__name {
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 1.05rem;
  letter-spacing: 0.12em;
  white-space: nowrap;
}

.identity__divider {
  width: 1px;
  height: 18px;
  background: rgba(255, 255, 255, 0.24);
}

.identity__collection {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.music-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.now-playing {
  max-width: 190px;
  overflow: hidden;
  color: rgba(255, 249, 235, 0.5);
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 8px 14px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  color: #fff8e9;
  background: rgba(255, 255, 255, 0.045);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease;
}

.icon-button:hover {
  border-color: rgba(236, 208, 150, 0.48);
  background: rgba(255, 255, 255, 0.08);
}

.sound-bars {
  display: inline-flex;
  height: 16px;
  align-items: end;
  gap: 2px;
}

.sound-bars i {
  width: 2px;
  border-radius: 2px;
  background: var(--gold-light);
  transform-origin: bottom;
  animation: sound-wave 900ms ease-in-out infinite alternate;
}

.sound-bars i:nth-child(1) {
  height: 7px;
}

.sound-bars i:nth-child(2) {
  height: 14px;
  animation-delay: -300ms;
}

.sound-bars i:nth-child(3) {
  height: 10px;
  animation-delay: -600ms;
}

.sound-button[aria-pressed="false"] .sound-bars i {
  height: 2px;
  animation-play-state: paused;
}

.sound-label {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}

.volume-control {
  display: flex;
  width: 82px;
  align-items: center;
}

.volume-control input {
  width: 100%;
  height: 3px;
  margin: 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.18);
  accent-color: var(--gold-light);
  cursor: pointer;
}

.gallery {
  display: flex;
  min-height: 0;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding: 2px 22px 0;
}

.book-stage {
  position: relative;
  display: grid;
  align-items: center;
  grid-template-columns: 56px auto 56px;
  gap: clamp(10px, 2vw, 28px);
  perspective: 2200px;
}

.book {
  position: relative;
  width: var(--book-width);
  aspect-ratio: 4 / 3;
  border-radius: 3px 10px 10px 3px;
  box-shadow:
    0 36px 66px rgba(0, 0, 0, 0.48),
    10px 11px 0 -7px #cfc5b2,
    15px 15px 0 -10px #8f8068;
  transform-style: preserve-3d;
  touch-action: pan-y;
}

.book::before {
  position: absolute;
  inset: auto 8% -30px;
  z-index: -1;
  height: 36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.54);
  filter: blur(18px);
  content: "";
}

.book__edge {
  position: absolute;
  inset: 4px auto 4px 0;
  z-index: 20;
  width: 14px;
  border-radius: 4px 0 0 4px;
  background: linear-gradient(90deg, rgba(45, 35, 24, 0.34), rgba(255, 255, 255, 0.09), transparent);
  pointer-events: none;
}

.art-page {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  padding: clamp(16px, 2.4vw, 38px) clamp(16px, 2.7vw, 44px) clamp(12px, 1.65vw, 24px);
  border: 1px solid rgba(80, 63, 41, 0.13);
  border-radius: 3px 10px 10px 3px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(94, 72, 42, 0.08), transparent 4%, transparent 96%, rgba(94, 72, 42, 0.035)),
    repeating-linear-gradient(4deg, rgba(74, 55, 35, 0.012) 0 1px, transparent 1px 9px),
    var(--paper);
  backface-visibility: hidden;
  overflow: hidden;
}

.art-page--current {
  z-index: 5;
}

.art-page--under {
  z-index: 3;
  visibility: hidden;
}

.art-page__mat {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  border: 1px solid rgba(50, 43, 32, 0.12);
  background: #fff;
  box-shadow:
    0 12px 28px rgba(72, 55, 32, 0.12),
    0 2px 5px rgba(72, 55, 32, 0.08);
  overflow: hidden;
}

.art-page__mat::after {
  position: absolute;
  inset: 0;
  border: 7px solid rgba(255, 255, 255, 0.4);
  content: "";
  pointer-events: none;
}

.art-page__image {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.art-page__caption {
  display: flex;
  min-height: 32px;
  align-items: end;
  justify-content: space-between;
  padding-top: clamp(8px, 1vw, 14px);
  color: #786d5d;
  font-family: "Noto Serif TC", "Songti TC", serif;
  font-size: clamp(0.72rem, 1vw, 0.88rem);
  letter-spacing: 0.12em;
}

.art-page__label,
.art-page__meta {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: clamp(6px, 1vw, 12px);
}

.art-page__meta {
  justify-content: flex-end;
}

.art-page__number {
  flex: none;
  color: #a2937c;
}

.art-page__title {
  overflow: hidden;
  color: #5d5346;
  font-size: 1.12em;
  letter-spacing: 0.06em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.art-page__tune {
  flex: none;
  color: #a08a5f;
  font-size: 0.86em;
  letter-spacing: 0.04em;
}

.art-page__artist {
  flex: none;
  color: #9c8c74;
  font-size: 0.82em;
}

.page-shade {
  position: absolute;
  inset: 0;
  z-index: 12;
  border-radius: 3px 10px 10px 3px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.15), transparent 18%, transparent 82%, rgba(0, 0, 0, 0.04));
  opacity: 0;
  pointer-events: none;
}

.turning-sheet {
  position: absolute;
  inset: 0;
  z-index: 10;
  transform-origin: left center;
  transform-style: preserve-3d;
  pointer-events: none;
}

.turning-sheet__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.turning-sheet__face--back {
  transform: rotateY(180deg);
}

.turning-sheet.is-forward {
  animation: turn-forward var(--turn-duration) cubic-bezier(0.62, 0.02, 0.24, 1) forwards;
}

.turning-sheet.is-backward {
  transform: rotateY(-180deg);
  animation: turn-backward var(--turn-duration) cubic-bezier(0.62, 0.02, 0.24, 1) forwards;
}

.turning-sheet::after {
  position: absolute;
  inset: 0;
  border-radius: 3px 10px 10px 3px;
  background: linear-gradient(90deg, transparent 36%, rgba(0, 0, 0, 0.22));
  content: "";
  opacity: 0;
  backface-visibility: hidden;
  animation: page-shadow var(--turn-duration) ease-in-out;
}

.turn-button {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 50%;
  color: #fff8e9;
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, opacity 180ms ease;
}

.turn-button:hover:not(:disabled) {
  transform: scale(1.06);
  border-color: rgba(236, 208, 150, 0.5);
  background: rgba(255, 255, 255, 0.08);
}

.turn-button:disabled {
  opacity: 0.22;
  cursor: default;
}

.turn-button svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.book-footer {
  display: grid;
  width: var(--book-width);
  min-height: 76px;
  align-items: center;
  grid-template-columns: 120px 1fr 270px;
  padding-top: 15px;
}

.page-status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: rgba(255, 249, 235, 0.82);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
}

.page-status__line {
  width: 34px;
  height: 1px;
  background: rgba(255, 255, 255, 0.26);
}

.page-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.page-dot {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.page-dot::before {
  display: block;
  width: 5px;
  height: 5px;
  margin: auto;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  content: "";
  transition: width 180ms ease, border-radius 180ms ease, background 180ms ease;
}

.page-dot[aria-current="true"]::before {
  width: 18px;
  border-radius: 99px;
  background: var(--gold-light);
}

.navigation-hint {
  margin: 0;
  color: rgba(255, 249, 235, 0.42);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-align: right;
}

.footer-note {
  min-height: 30px;
  padding: 0 max(26px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom))
    max(26px, env(safe-area-inset-left));
  color: rgba(255, 249, 235, 0.28);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-align: center;
}

.noscript-message {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 200;
  width: min(360px, 85vw);
  margin: 0;
  padding: 18px;
  border-radius: 12px;
  color: var(--ink);
  background: var(--paper);
  transform: translate(-50%, -50%);
  text-align: center;
}

@keyframes sound-wave {
  from { transform: scaleY(0.45); }
  to { transform: scaleY(1); }
}

@keyframes turn-forward {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(-180deg); }
}

@keyframes turn-backward {
  from { transform: rotateY(-180deg); }
  to { transform: rotateY(0deg); }
}

@keyframes page-shadow {
  0%, 100% { opacity: 0; }
  45%, 60% { opacity: 0.95; }
}

@media (max-width: 900px) {
  :root {
    --book-width: min(84vw, calc((100dvh - 205px) * 1.333));
  }

  .book-stage {
    grid-template-columns: 46px auto 46px;
    gap: 9px;
  }

  .turn-button {
    width: 42px;
    height: 42px;
  }

  .book-footer {
    grid-template-columns: 88px 1fr;
  }

  .navigation-hint {
    display: none;
  }
}

@media (max-width: 660px) {
  :root {
    --book-width: min(94vw, calc((100dvh - 205px) * 1.333));
    --turn-duration: 720ms;
  }

  .topbar {
    min-height: 68px;
    padding-right: 14px;
    padding-left: 14px;
  }

  .identity {
    gap: 8px;
  }

  .identity__seal {
    width: 30px;
    height: 30px;
    font-size: 0.9rem;
  }

  .identity__name {
    font-size: 0.9rem;
  }

  .identity__collection,
  .identity__divider,
  .sound-label,
  .volume-control,
  .now-playing {
    display: none;
  }

  .art-page__number,
  .art-page__artist {
    display: none;
  }

  .art-page__caption {
    gap: 10px;
  }

  .icon-button {
    width: 42px;
    padding: 8px;
  }

  .gallery {
    padding-right: 10px;
    padding-left: 10px;
  }

  .book-stage {
    display: block;
  }

  .turn-button {
    position: absolute;
    z-index: 30;
    top: calc(50% - 22px);
    width: 44px;
    height: 44px;
    border-color: rgba(34, 31, 26, 0.12);
    color: #40382d;
    background: rgba(252, 250, 244, 0.78);
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.17);
  }

  .turn-button--previous {
    left: 9px;
  }

  .turn-button--next {
    right: 9px;
  }

  .book-footer {
    width: var(--book-width);
    min-height: 66px;
    grid-template-columns: 62px 1fr;
    padding-top: 10px;
  }

  .page-status {
    gap: 6px;
    font-size: 0.68rem;
  }

  .page-status__line {
    width: 15px;
  }

  .page-dots {
    gap: 5px;
    justify-content: flex-end;
  }

  .page-dot {
    width: 16px;
  }

  .page-dot[aria-current="true"]::before {
    width: 14px;
  }

  .footer-note {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    font-size: 0.58rem;
  }

  .welcome__content {
    padding: 45px 38px;
  }

  .welcome__seal {
    width: 54px;
    height: 54px;
    margin-bottom: 24px;
  }
}

@media (max-width: 660px) and (orientation: portrait) {
  :root {
    --book-width: min(94vw, calc((100dvh - 215px) * 0.9));
  }

  .book {
    aspect-ratio: 0.9;
  }

  .art-page__mat {
    align-content: center;
  }
}

@media (max-width: 420px) {
  .welcome__book {
    width: min(420px, 92vw);
    max-height: 82dvh;
  }

  .welcome__count {
    max-width: 250px;
    font-size: 0.82rem;
    line-height: 1.7;
  }

  .art-page {
    padding: 11px 12px 9px;
  }

  .art-page__caption {
    min-height: 27px;
    padding-top: 7px;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  :root {
    --book-width: min(74vw, calc((100dvh - 118px) * 1.333));
  }

  .topbar {
    min-height: 54px;
    padding-top: 8px;
    padding-bottom: 4px;
  }

  .book-footer {
    min-height: 50px;
    padding-top: 7px;
  }

  .footer-note {
    display: none;
  }
}

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