.library-page {
  overflow-x: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgb(87 49 23 / 18%), transparent 28rem),
    linear-gradient(180deg, #080706, #020303 78%);
}

.library-page [hidden] {
  display: none !important;
}

.library-shell {
  position: relative;
  isolation: isolate;
  display: grid;
  width: min(100%, 860px);
  min-height: 100svh;
  min-height: 100dvh;
  grid-template-rows: auto minmax(0, 1fr);
  margin: 0 auto;
  padding:
    calc(16px + env(safe-area-inset-top))
    calc(10px + env(safe-area-inset-right))
    calc(16px + env(safe-area-inset-bottom))
    calc(10px + env(safe-area-inset-left));
  overflow: hidden;
  border-inline: 1px solid rgb(216 187 128 / 14%);
  background:
    linear-gradient(180deg, rgb(0 0 0 / 10%), rgb(0 0 0 / 70%)),
    repeating-linear-gradient(90deg, rgb(53 31 16 / 10%) 0 1px, transparent 1px 32px),
    linear-gradient(90deg, #070504, #120b07 50%, #070504);
  box-shadow: 0 0 52px #000;
}

.library-shell::before {
  content: "";
  position: absolute;
  inset: 7px;
  z-index: -1;
  border: 1px solid rgb(216 187 128 / 24%);
  pointer-events: none;
}

.library-header {
  position: relative;
  display: grid;
  justify-items: center;
  min-height: clamp(118px, 19svh, 190px);
  align-content: start;
  text-align: center;
}

.back-link {
  position: absolute;
  top: 7px;
  left: 8px;
  color: var(--gold-bright);
  font-size: 12px;
  letter-spacing: .1em;
  text-decoration: none;
  display: inline-flex;
  min-width: 52px;
  min-height: 44px;
  align-items: center;
}

.back-link span {
  font: 27px/0 Georgia, serif;
  vertical-align: -2px;
}

.asset-slot--library-crest {
  width: clamp(36px, 9vw, 56px);
  aspect-ratio: 1;
  border: 0;
  background: transparent;
  filter: drop-shadow(0 4px 9px rgb(0 0 0 / 58%));
}

.library-kicker {
  margin: 6px 0 0;
  color: var(--muted);
  font: 10px/1 Georgia, serif;
  letter-spacing: .18em;
}

.library-header h1 {
  margin: 5px 0 0;
  color: var(--paper);
  font: 500 clamp(29px, 8vw, 54px)/1 Georgia, "Times New Roman", serif;
  letter-spacing: .06em;
  text-shadow: 0 3px 14px #000;
}

.library-header h1::after {
  content: "";
  display: block;
  width: min(48vw, 220px);
  height: 1px;
  margin: 9px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

.library-description {
  margin: 9px 0 0;
  color: var(--gold);
  font-size: clamp(9px, 2.5vw, 13px);
  letter-spacing: .07em;
}

.book-selector {
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(260px, 1fr) auto auto auto;
  align-content: stretch;
}

.book-stage {
  --book-width: clamp(158px, 49vw, 245px);
  --book-shift: clamp(155px, 52vw, 330px);
  position: relative;
  min-height: clamp(300px, 52svh, 500px);
  overflow: visible;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.book-stage::after {
  content: "";
  position: absolute;
  right: 3%;
  bottom: 3%;
  left: 3%;
  height: 12px;
  border-block: 1px solid rgb(216 187 128 / 26%);
  background: #160e09 url("../assets/official/ui/shelf-board.webp") center / 100% 100% no-repeat;
  box-shadow: 0 9px 20px #000, inset 0 1px rgb(216 187 128 / 8%);
}

.book-track {
  position: absolute;
  inset: 0;
}

.book-slide {
  --cover-accent: #671322;
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  display: grid;
  width: var(--book-width);
  aspect-ratio: 4 / 7;
  max-height: calc(100% - 18px);
  place-items: center;
  overflow: hidden;
  padding: 30px 22px;
  border: 1px solid rgb(216 187 128 / 62%);
  border-radius: 3px 9px 9px 3px;
  background-image:
    linear-gradient(rgb(4 4 5 / 12%), rgb(4 4 5 / 12%)),
    var(--cover-image, linear-gradient(transparent, transparent)),
    linear-gradient(90deg, #18070b 0 7%, var(--cover-accent) 7% 9%, transparent 9%),
    repeating-linear-gradient(135deg, transparent 0 8px, rgb(216 187 128 / 2%) 8px 9px),
    radial-gradient(circle at 50% 38%, rgb(142 83 38 / 18%), transparent 42%),
    linear-gradient(145deg, #2a0a11, #090708 78%);
  background-position: center, center, center, center, center, center;
  background-size: cover, 100% 100%, auto, auto, auto, auto;
  background-repeat: no-repeat;
  color: var(--paper);
  box-shadow:
    inset -9px 0 0 rgb(255 238 208 / 6%),
    inset -11px 0 12px rgb(0 0 0 / 24%),
    inset 0 0 0 7px rgb(0 0 0 / 25%),
    0 24px 32px rgb(0 0 0 / 68%);
  opacity: 0;
  transform: translate(-50%, -50%) scale(.5);
  transition: transform .36s ease, opacity .28s ease, filter .28s ease;
  pointer-events: none;
}

.book-slide::before {
  content: "";
  position: absolute;
  inset: 13px 12px 13px 25px;
  border: 1px solid rgb(216 187 128 / 48%);
  box-shadow: inset 0 0 0 4px rgb(0 0 0 / 14%), inset 0 0 20px rgb(216 187 128 / 3%);
  pointer-events: none;
}

.book-slide::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 17px;
  left: 13px;
  color: rgb(216 187 128 / 35%);
  font: 7px/1 Georgia, serif;
  letter-spacing: .2em;
  text-align: center;
}

.book-slide.is-active {
  z-index: 4;
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
  cursor: pointer;
}

.book-slide.is-previous {
  z-index: 2;
  opacity: .56;
  transform: translate(calc(-50% - var(--book-shift)), -50%) scale(.76) perspective(700px) rotateY(7deg);
  filter: brightness(.62);
  pointer-events: auto;
  cursor: pointer;
}

.book-slide.is-next {
  z-index: 2;
  opacity: .56;
  transform: translate(calc(-50% + var(--book-shift)), -50%) scale(.76) perspective(700px) rotateY(-7deg);
  filter: brightness(.62);
  pointer-events: auto;
  cursor: pointer;
}

.book-slide__content {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 12px;
  width: 100%;
  text-align: center;
  text-shadow: 0 2px 8px #000;
}

.book-slide.has-cover-image .book-slide__content {
  align-content: space-between;
  min-height: 78%;
  padding-block: 2px;
}

.book-slide__content::before {
  content: "◆";
  color: rgb(216 187 128 / 58%);
  font: 10px/1 Georgia, serif;
}

.book-slide__label {
  margin: 0;
  color: var(--gold);
  font: clamp(12px, 3.5vw, 18px)/1.25 Georgia, "Yu Mincho", serif;
  letter-spacing: .08em;
}

.book-slide__title {
  max-width: calc(100% + 14px);
  margin: 0;
  overflow-wrap: normal;
  word-break: keep-all;
  white-space: nowrap;
  color: var(--paper);
  font: 500 clamp(20px, 6.2vw, 34px)/1.35 "Yu Mincho", "Hiragino Mincho ProN", serif;
  letter-spacing: .04em;
}

.book-slide__title.is-long {
  font-size: clamp(16px, 4.7vw, 27px);
  letter-spacing: 0;
}

.book-slide.requires-title-fit .book-slide__title {
  justify-self: center;
  overflow: visible;
  text-align: center;
}

.book-slide__title.is-multiline {
  display: grid;
  gap: 4px;
  white-space: normal;
  font: 500 clamp(12px, 3.5vw, 19px)/1.35 Georgia, "Times New Roman", serif;
  letter-spacing: .015em;
}

.book-slide__title.is-multiline span {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}

.book-slide__count {
  margin: 7px 0 0;
  color: var(--muted);
  font: 9px/1.4 "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
  letter-spacing: .1em;
}

.carousel-arrow {
  position: absolute;
  z-index: 6;
  top: 50%;
  width: 42px;
  height: 64px;
  padding: 0;
  background: transparent;
  color: var(--gold-bright);
  font: 50px/1 Georgia, serif;
  text-shadow: 0 0 10px #000, 0 0 8px rgb(216 187 128 / 38%);
  transform: translateY(-50%);
  cursor: pointer;
  transition: color .16s ease, text-shadow .16s ease, transform .16s ease;
}

.carousel-arrow:hover,
.carousel-arrow:focus-visible {
  color: #f8e7bb;
  text-shadow: 0 0 12px #000, 0 0 12px rgb(216 187 128 / 58%);
}

.carousel-arrow--previous {
  left: 0;
}

.carousel-arrow--next {
  right: 0;
}

.book-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  min-height: 16px;
  margin-top: 2px;
}

.book-dot {
  width: 7px;
  height: 7px;
  padding: 0;
  border: 1px solid var(--gold-dim);
  background: transparent;
  transform: rotate(45deg);
  cursor: pointer;
}

.book-dot.is-active {
  background: var(--gold-bright);
  box-shadow: 0 0 7px rgb(216 187 128 / 50%);
}

.gesture-help {
  margin: 3px 0 8px;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .08em;
  text-align: center;
}

.open-area {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding-bottom: 1px;
}

.open-book {
  display: grid;
  width: min(72vw, 330px);
  min-height: 48px;
  place-items: center;
  border: 1px solid rgb(216 187 128 / 62%);
  background: linear-gradient(180deg, #1c120d, #050505);
  color: var(--gold-bright);
  font-size: 17px;
  letter-spacing: .24em;
  text-decoration: none;
  box-shadow: inset 0 0 0 5px rgb(216 187 128 / 6%);
  cursor: pointer;
  transition: border-color .16s ease, color .16s ease, box-shadow .16s ease;
}

.open-book:hover,
.open-book:focus-visible {
  border-color: var(--gold);
  color: #f8e7bb;
  box-shadow: inset 0 0 0 5px rgb(216 187 128 / 9%), 0 9px 18px rgb(0 0 0 / 38%);
}

.open-book:disabled {
  opacity: .68;
}

.open-note {
  min-height: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .06em;
  text-align: center;
}

.empty-library {
  align-self: center;
  display: grid;
  justify-items: center;
  gap: 24px;
  width: min(100% - 24px, 600px);
  margin: auto;
}

.empty-library__frame {
  width: 100%;
  padding: clamp(44px, 10vw, 80px) 24px;
  border: 1px solid rgb(216 187 128 / 42%);
  background: linear-gradient(145deg, rgb(25 17 10 / 74%), rgb(3 4 4 / 92%));
  box-shadow: inset 0 0 0 7px rgb(0 0 0 / 35%), inset 0 0 38px rgb(216 187 128 / 4%), 0 24px 38px #000;
  text-align: center;
}

.empty-library__label {
  margin: 0 0 17px;
  color: var(--gold);
  font: 12px/1 Georgia, serif;
  letter-spacing: .2em;
}

.empty-library h2 {
  margin: 0;
  color: var(--paper);
  font-size: clamp(19px, 5vw, 29px);
  font-weight: 500;
  line-height: 1.55;
}

.empty-library__frame p:last-child {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.8;
}

.empty-library__back {
  color: var(--gold-bright);
  font-size: 12px;
  letter-spacing: .14em;
  text-underline-offset: 5px;
}

.library-error {
  align-self: center;
  margin: 0 auto;
  color: #e6b2aa;
  font-size: 12px;
  text-align: center;
}

@media (max-height: 650px) {
  .library-header {
    min-height: 106px;
  }

  .asset-slot--library-crest {
    width: 30px;
  }

  .library-header h1 {
    font-size: 27px;
  }

  .book-selector {
    grid-template-rows: minmax(250px, 1fr) auto auto auto;
  }

  .book-stage {
    --book-width: clamp(146px, 43vw, 190px);
    min-height: 274px;
  }

  .book-slide {
    padding-block: 22px;
  }

  .open-book {
    min-height: 42px;
  }
}

@media (max-width: 350px) {
  .library-shell {
    padding-inline: 7px;
  }

  .book-stage {
    --book-width: 156px;
    --book-shift: 146px;
  }

  .book-slide__title {
    font-size: 19px;
  }

  .book-slide__title.is-long {
    font-size: 15px;
  }

  .book-slide__title.is-multiline {
    font-size: 11px;
  }

  .carousel-arrow {
    width: 34px;
    font-size: 42px;
  }

  .library-description {
    letter-spacing: .035em;
  }
}

@media (min-width: 700px) {
  .book-stage {
    --book-width: clamp(218px, 28vw, 250px);
    --book-shift: clamp(275px, 37vw, 350px);
  }
}
