:root {
  --cream: #fff8e6;
  --paper: #f7efd9;
  --ink: #17382c;
  --ink-soft: #2f5a47;
  --emerald: #2f6b4f;
  --emerald-deep: #143b2d;
  --gold: #d8a84e;
  --gold-soft: #e7c98a;
  --wood: #8c5a34;
  --wood-light: #c99766;
  --coral: #cf6d4c;
  --font-serif: "Songti SC", "STSong", "Noto Serif CJK SC", "SimSun", Georgia, serif;
  --font-sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --shelf-width: min(92vw, 940px, calc((100vh - 268px) * 1.32));
  --shelf-gap: clamp(22px, 4.4vh, 58px);
  --book-gap: clamp(12px, 2.6vw, 36px);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--cream);
  font-family: var(--font-sans);
  background: #10291f;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  background: #10291f url("img/shelf-backdrop.jpg") center / cover no-repeat;
  transform: scale(1.035);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(255, 232, 173, 0.16), transparent 56%),
    linear-gradient(180deg, rgba(7, 24, 18, 0.58) 0%, rgba(7, 24, 18, 0.22) 34%, rgba(7, 24, 18, 0.68) 100%);
  pointer-events: none;
}

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

.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(100%, 1280px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(16px, 2.4vh, 28px) clamp(16px, 3.6vw, 56px) clamp(12px, 2vh, 22px);
}

/* ---------- header ---------- */

.site-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 clamp(2px, 0.8vw, 10px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: clamp(40px, 4.6vh, 50px);
  height: clamp(40px, 4.6vh, 50px);
  flex: none;
  border: 1px solid rgba(216, 168, 78, 0.62);
  border-radius: 50%;
  background: rgba(255, 248, 230, 0.1);
  box-shadow: inset 0 0 18px rgba(216, 168, 78, 0.16), 0 6px 18px rgba(0, 0, 0, 0.18);
  color: var(--gold);
  backdrop-filter: blur(6px);
}

.brand-mark svg { width: 72%; height: 72%; display: block; }

.brand-words { display: flex; flex-direction: column; min-width: 0; }

.brand-name {
  font-family: var(--font-serif);
  font-size: clamp(20px, 2.5vw, 28px);
  font-weight: 700;
  letter-spacing: 0.2em;
  line-height: 1.1;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.3);
}

.brand-tag {
  margin-top: 4px;
  color: rgba(255, 248, 230, 0.64);
  font-size: clamp(9px, 0.95vw, 11px);
  letter-spacing: 0.28em;
  white-space: nowrap;
}

.header-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }

.edition-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border: 1px solid rgba(255, 248, 230, 0.24);
  border-radius: 999px;
  background: rgba(20, 52, 39, 0.5);
  color: rgba(255, 248, 230, 0.92);
  font-size: clamp(10px, 0.95vw, 12px);
  letter-spacing: 0.08em;
  backdrop-filter: blur(8px);
}

.edition-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 9px rgba(216, 168, 78, 0.9);
}

.header-note {
  color: rgba(255, 248, 230, 0.5);
  font-size: clamp(9px, 0.85vw, 11px);
  letter-spacing: 0.1em;
}

/* ---------- shelf stage ---------- */

.shelf-stage {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: clamp(6px, 1.8vh, 20px) 0;
}

.shelf-glow {
  position: absolute;
  inset: 4% 8% 8%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 46%, rgba(255, 226, 158, 0.2), transparent 64%);
  filter: blur(22px);
  pointer-events: none;
}

.shelf-viewport {
  position: relative;
  width: var(--shelf-width);
  max-width: 100%;
  overflow: hidden;
  touch-action: pan-y;
  cursor: grab;
  outline: none;
}

.shelf-viewport.is-dragging { cursor: grabbing; }

.shelf-track {
  display: flex;
  align-items: stretch;
  will-change: transform;
  transition: transform 620ms cubic-bezier(0.22, 0.78, 0.2, 1);
}

.shelf-viewport.is-dragging .shelf-track { transition: none; }

.shelf-page {
  flex: 0 0 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--shelf-gap);
  padding: 2px clamp(4px, 1vw, 14px);
}

.shelf-row {
  position: relative;
  padding-bottom: clamp(15px, 2.1vh, 24px);
}

.shelf-row::before {
  content: "";
  position: absolute;
  inset: 4% 2% 14px;
  border-radius: 50% 50% 12% 12% / 28% 28% 10% 10%;
  background: radial-gradient(ellipse at 50% 100%, rgba(216, 168, 78, 0.11), transparent 68%);
  pointer-events: none;
}

.shelf-books {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--book-gap);
  align-items: end;
  padding: 0 clamp(2px, 1vw, 12px);
}

.shelf-plank {
  position: absolute;
  left: clamp(-18px, -1.2vw, -8px);
  right: clamp(-18px, -1.2vw, -8px);
  bottom: 0;
  height: clamp(11px, 1.4vh, 16px);
  border-radius: 3px 3px 7px 7px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.36), transparent 22%),
    linear-gradient(180deg, #d0a170 0%, #a06a3f 42%, #74452a 78%, #5c351f 100%);
  box-shadow:
    0 1px 0 rgba(255, 230, 190, 0.5) inset,
    0 14px 26px rgba(0, 0, 0, 0.5),
    0 4px 0 rgba(74, 42, 24, 0.5);
}

.shelf-plank::before {
  content: "";
  position: absolute;
  inset: 22% 6% auto auto;
  width: 26%;
  height: 1px;
  background: rgba(255, 238, 205, 0.32);
  box-shadow: 0 5px 0 rgba(255, 238, 205, 0.1);
}

.shelf-plank::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  top: 100%;
  height: clamp(10px, 1.8vh, 22px);
  background: linear-gradient(180deg, rgba(52, 29, 16, 0.55), transparent);
  filter: blur(2px);
}

/* ---------- book cards ---------- */

.book-card {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  border-radius: 3px 8px 8px 3px;
  background: #1d3b2e;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  transform: translateY(0) rotate(var(--tilt, 0deg));
  transform-origin: 50% 100%;
  box-shadow:
    0 20px 28px -14px rgba(0, 0, 0, 0.72),
    0 5px 12px rgba(0, 0, 0, 0.32);
  transition: transform 320ms cubic-bezier(0.22, 0.8, 0.22, 1), box-shadow 320ms ease, filter 320ms ease;
  animation: book-rise 620ms cubic-bezier(0.22, 0.8, 0.22, 1) both;
  animation-delay: calc(var(--i, 0) * 55ms + 80ms);
  outline: none;
}

.book-card:nth-child(1) { --tilt: -1.4deg; }
.book-card:nth-child(2) { --tilt: 0.3deg; }
.book-card:nth-child(3) { --tilt: 1.2deg; }

.book-card::before {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 0 auto 0 0;
  width: 7%;
  border-radius: 3px 0 0 3px;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.5), rgba(255, 255, 255, 0.2) 42%, rgba(0, 0, 0, 0.24) 68%, transparent);
  mix-blend-mode: multiply;
  pointer-events: none;
}

.book-card::after {
  content: "";
  position: absolute;
  z-index: 3;
  inset: 0;
  border-radius: inherit;
  border: 1px solid rgba(255, 248, 230, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), inset 0 -18px 24px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.book-card:focus-visible {
  box-shadow:
    0 0 0 3px rgba(255, 248, 230, 0.95),
    0 0 0 7px rgba(216, 168, 78, 0.45),
    0 22px 30px -14px rgba(0, 0, 0, 0.75);
}

.book-cover {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: inherit;
  background: var(--emerald-deep);
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 700ms cubic-bezier(0.22, 0.8, 0.22, 1);
}

.book-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(112deg, rgba(255, 255, 255, 0.18) 0%, transparent 28%, transparent 72%, rgba(0, 0, 0, 0.16) 100%);
  pointer-events: none;
}

.cover-copy {
  position: absolute;
  z-index: 2;
  left: 8%;
  right: 8%;
  text-align: center;
  color: #fff8e6;
  text-shadow: 0 2px 8px rgba(8, 24, 17, 0.7), 0 1px 2px rgba(8, 24, 17, 0.8);
  pointer-events: none;
}

.cover-copy.is-top { top: 7%; }
.cover-copy.is-bottom { bottom: 7.5%; }

.cover-kicker {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(5.5px, 0.72vw, 8.5px);
  letter-spacing: 0.19em;
  line-height: 1.15;
  color: rgba(255, 248, 230, 0.92);
  text-transform: uppercase;
  text-shadow: 0 1px 3px rgba(8, 24, 17, 0.9), 0 0 10px rgba(8, 24, 17, 0.55);
}

.cover-title {
  display: block;
  margin-top: 3px;
  font-family: var(--font-serif);
  font-size: clamp(16px, 2.05vw, 27px);
  font-weight: 700;
  letter-spacing: 0.13em;
  line-height: 1.12;
}

.cover-rule {
  display: block;
  width: clamp(18px, 2.4vw, 32px);
  height: 1px;
  margin: clamp(4px, 0.8vh, 8px) auto clamp(3px, 0.6vh, 6px);
  background: linear-gradient(90deg, transparent, var(--gold-soft), transparent);
  box-shadow: 0 0 6px rgba(216, 168, 78, 0.55);
}

.cover-sub {
  display: block;
  font-size: clamp(8px, 0.95vw, 12px);
  font-weight: 600;
  letter-spacing: 0.22em;
  color: rgba(255, 248, 230, 0.98);
  text-shadow: 0 1px 4px rgba(8, 24, 17, 0.95), 0 0 12px rgba(8, 24, 17, 0.7);
}

.cover-copy.is-top .cover-sub {
  display: inline-block;
  padding: 2px 10px;
  border: 1px solid rgba(255, 248, 230, 0.12);
  border-radius: 999px;
  background: rgba(9, 30, 21, 0.24);
  backdrop-filter: blur(3px);
}

.cover-badge {
  position: absolute;
  z-index: 4;
  top: 0;
  right: 0;
  padding: clamp(3px, 0.6vh, 6px) clamp(6px, 0.7vw, 10px);
  border-radius: 0 7px 0 8px;
  background: linear-gradient(180deg, rgba(207, 109, 76, 0.98), rgba(171, 78, 50, 0.98));
  color: #fff8e6;
  font-size: clamp(6.5px, 0.7vw, 9px);
  letter-spacing: 0.14em;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.25);
}

.cover-top-veil,
.cover-bottom-veil {
  position: absolute;
  z-index: 1;
  inset: 0;
  pointer-events: none;
}

.cover-top-veil {
  background: linear-gradient(180deg, rgba(9, 30, 21, 0.58) 0%, rgba(9, 30, 21, 0.2) 30%, transparent 52%);
}

.cover-bottom-veil {
  background: linear-gradient(180deg, transparent 48%, rgba(9, 26, 19, 0.34) 68%, rgba(9, 26, 19, 0.86) 100%);
}

.book-meta {
  position: absolute;
  z-index: 4;
  left: 8%;
  right: 8%;
  bottom: -1.35em;
  display: flex;
  justify-content: center;
  color: rgba(255, 248, 230, 0.68);
  font-size: clamp(7px, 0.75vw, 10px);
  letter-spacing: 0.1em;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 240ms ease, transform 240ms ease;
  pointer-events: none;
}

.book-card:hover .book-meta,
.book-card:focus-visible .book-meta { opacity: 1; transform: translateY(0); }

/* Hover only where a real pointer exists */
@media (hover: hover) and (pointer: fine) {
  .book-card:hover {
    transform: translateY(-12px) rotate(0deg) scale(1.015);
    box-shadow:
      0 34px 38px -18px rgba(0, 0, 0, 0.8),
      0 10px 20px rgba(0, 0, 0, 0.34);
    filter: brightness(1.04);
  }

  .book-card:hover .book-cover img { transform: scale(1.045); }
}

/* ---------- arrows ---------- */

.shelf-arrow {
  position: absolute;
  z-index: 6;
  top: 50%;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-top: -26px;
  padding: 0 0 4px;
  border: 1px solid rgba(255, 248, 230, 0.3);
  border-radius: 50%;
  background: rgba(19, 50, 37, 0.56);
  color: var(--cream);
  font-family: Georgia, serif;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.26);
  transition: background 220ms ease, transform 220ms ease, opacity 220ms ease;
}

.shelf-arrow-prev { left: max(4px, calc(50% - var(--shelf-width) / 2 - 74px)); }
.shelf-arrow-next { right: max(4px, calc(50% - var(--shelf-width) / 2 - 74px)); }

.shelf-arrow:hover:not(:disabled) { background: rgba(38, 88, 63, 0.82); transform: translateY(-1px); }
.shelf-arrow:disabled { opacity: 0.18; cursor: default; }
.shelf-arrow:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 3px; }

/* ---------- footer ---------- */

.shelf-footer {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(7px, 1.2vh, 12px);
  padding-top: clamp(6px, 1.2vh, 12px);
}

.shelf-dots { display: flex; align-items: center; gap: 9px; }

.shelf-dot {
  width: 8px;
  height: 8px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 248, 230, 0.34);
  cursor: pointer;
  transition: width 260ms ease, background 260ms ease;
}

.shelf-dot[aria-selected="true"] {
  width: 26px;
  background: var(--gold);
  box-shadow: 0 0 12px rgba(216, 168, 78, 0.55);
}

.shelf-dot:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 3px; }

.shelf-hint {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  color: rgba(255, 248, 230, 0.58);
  font-size: clamp(9px, 0.88vw, 11px);
  letter-spacing: 0.1em;
  text-align: center;
}

.hint-swipe { display: inline-flex; align-items: center; gap: 5px; }
.hint-icon { color: var(--gold-soft); font-size: 13px; }
.hint-sep { width: 1px; height: 11px; background: rgba(255, 248, 230, 0.24); }

/* ---------- loading ---------- */

.book-loading {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(8, 24, 18, 0.72);
  backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 240ms ease, visibility 240ms ease;
}

.book-loading.is-visible { opacity: 1; visibility: visible; }

.loading-book {
  width: 54px;
  height: 68px;
  border-radius: 3px 7px 7px 3px;
  background: linear-gradient(145deg, #f2e2bb, #d8a84e);
  box-shadow: 0 18px 28px rgba(0, 0, 0, 0.4);
  transform-origin: left center;
  animation: book-open 1.15s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.loading-text { color: rgba(255, 248, 230, 0.86); font-size: 13px; letter-spacing: 0.18em; }

/* ---------- ambient fireflies ---------- */

.ambient { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }

.firefly {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffe6a3;
  box-shadow: 0 0 10px 3px rgba(255, 216, 122, 0.55);
  opacity: 0.35;
  animation: drift 9s ease-in-out infinite;
}

.firefly.f1 { left: 9%; top: 24%; animation-delay: -1s; }
.firefly.f2 { left: 18%; top: 68%; animation-delay: -4.2s; animation-duration: 11s; }
.firefly.f3 { left: 83%; top: 31%; animation-delay: -2.4s; animation-duration: 10s; }
.firefly.f4 { left: 91%; top: 73%; animation-delay: -6.1s; animation-duration: 12s; }
.firefly.f5 { left: 72%; top: 12%; animation-delay: -3.3s; animation-duration: 8.5s; }
.firefly.f6 { left: 27%; top: 11%; animation-delay: -5.2s; animation-duration: 9.5s; }

@keyframes drift {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); opacity: 0.22; }
  35% { transform: translate3d(14px, -22px, 0) scale(1.25); opacity: 0.62; }
  70% { transform: translate3d(-9px, -9px, 0) scale(0.9); opacity: 0.34; }
}

@keyframes book-rise {
  from { opacity: 0; transform: translateY(26px) rotate(0deg); }
  to { opacity: 1; transform: translateY(0) rotate(var(--tilt, 0deg)); }
}

@keyframes book-open {
  0%, 100% { transform: perspective(220px) rotateY(0deg); }
  45% { transform: perspective(220px) rotateY(-38deg); }
  65% { transform: perspective(220px) rotateY(-18deg); }
}

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .shelf-arrow { width: 44px; height: 44px; margin-top: -22px; font-size: 26px; }
  .shelf-arrow-prev { left: max(2px, calc(50% - var(--shelf-width) / 2 - 58px)); }
  .shelf-arrow-next { right: max(2px, calc(50% - var(--shelf-width) / 2 - 58px)); }
}

@media (max-width: 900px) {
  :root { --shelf-width: min(94vw, 720px); --shelf-gap: clamp(20px, 4vh, 44px); }
  .shelf-arrow { display: none; }
  .site-header { align-items: flex-start; }
  .header-note { display: none; }
}

@media (max-width: 620px) {
  :root { --shelf-width: 94vw; --book-gap: 11px; }
  .app-shell { padding: 14px 12px 12px; }
  .brand { gap: 9px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand-name { letter-spacing: 0.14em; }
  .brand-tag { letter-spacing: 0.18em; font-size: 8px; }
  .edition-pill { padding: 5px 9px; font-size: 9px; letter-spacing: 0.04em; }
  .shelf-page { padding-inline: 0; gap: clamp(18px, 3.6vh, 32px); }
  .shelf-books { padding-inline: 4px; }
  .cover-copy { left: 7%; right: 7%; }
  .cover-title { letter-spacing: 0.08em; }
  .cover-sub { letter-spacing: 0.14em; }
  .cover-badge { letter-spacing: 0.08em; }
  .shelf-hint { gap: 8px; font-size: 9px; letter-spacing: 0.04em; }
  .hint-sep { display: none; }
  .book-meta { display: none; }
}

@media (max-width: 380px) {
  .brand-tag { display: none; }
  .edition-pill { font-size: 8px; }
}

@media (max-height: 640px) and (min-width: 901px) {
  :root { --shelf-gap: 20px; --book-gap: 20px; }
  .brand-tag { display: none; }
  .shelf-footer { padding-top: 4px; }
}

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