:root {
  --yellow: #f4d000;
  --yellow-soft: #ffe455;
  --ink: #171717;
  --ink-2: #262626;
  --muted: #737373;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --line: rgba(23, 23, 23, 0.12);
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 16px 38px rgba(0, 0, 0, 0.18);
  --radius: 18px;
  --page-ratio: 1.415254;
  --book-ratio: 2.830508;
}

* { box-sizing: border-box; }

html { color-scheme: light; scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(244, 208, 0, 0.16), transparent 30rem),
    linear-gradient(180deg, #f6f6f4 0%, #ecece9 100%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

svg {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.top-link svg { fill: currentColor; stroke: none; }

.noscript {
  padding: 1rem;
  text-align: center;
  color: #fff;
  background: #111;
}

.app { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 70px;
  padding: 0.7rem clamp(1rem, 4vw, 4rem);
  color: #fff;
  background: rgba(20, 20, 20, 0.94);
  border-bottom: 1px solid rgba(255,255,255,0.09);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  color: #111;
  background: var(--yellow);
  border-radius: 11px 3px 11px 3px;
  font-size: 1.15rem;
  font-weight: 950;
  box-shadow: inset 0 -5px 12px rgba(0,0,0,0.08);
}

.brand-copy { display: grid; line-height: 1.1; }
.brand-copy strong { font-size: 1.05rem; letter-spacing: 0.08em; }
.brand-copy small { margin-top: 0.23rem; color: rgba(255,255,255,0.62); font-size: 0.72rem; }

.top-actions { display: flex; align-items: center; gap: 0.55rem; }

.top-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 42px;
  padding: 0.65rem 0.9rem;
  color: rgba(255,255,255,0.9);
  border: 1px solid rgba(255,255,255,0.17);
  border-radius: 11px;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 750;
  transition: 160ms ease;
}

.top-link:hover { color: #fff; border-color: rgba(255,255,255,0.38); transform: translateY(-1px); }
.top-link-primary { color: #111; background: var(--yellow); border-color: var(--yellow); }
.top-link-primary:hover { color: #111; background: var(--yellow-soft); border-color: var(--yellow-soft); }

.main { padding: clamp(1.4rem, 3vw, 2.8rem) clamp(0.75rem, 3vw, 2.5rem) 1.5rem; }
.catalog { width: min(1560px, 100%); margin: 0 auto; }

.catalog-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin: 0 auto 1.2rem;
  padding-inline: clamp(0.25rem, 2vw, 1rem);
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: #8f7900;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.5rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.catalog-intro {
  max-width: 34rem;
  margin: 0;
  color: #626262;
  font-size: 0.92rem;
  line-height: 1.5;
  text-align: right;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: min(72vh, 820px);
  overflow: auto;
  padding: clamp(1.1rem, 3vw, 2.2rem) clamp(3rem, 5vw, 5rem);
  background:
    radial-gradient(circle at 50% 45%, rgba(255,255,255,0.11), transparent 33%),
    linear-gradient(145deg, #313131 0%, #181818 55%, #0e0e0e 100%);
  border: 1px solid rgba(0,0,0,0.35);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  outline: none;
  isolation: isolate;
  touch-action: pan-y;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.32;
  background-image: linear-gradient(rgba(255,255,255,.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.02) 1px, transparent 1px);
  background-size: 26px 26px;
  border-radius: inherit;
}

.stage:focus-visible { box-shadow: var(--shadow-lg), 0 0 0 4px rgba(244,208,0,0.5); }

.loader {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  color: #fff;
  background: rgba(18,18,18,0.95);
  border-radius: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  transition: opacity 300ms ease, visibility 300ms ease;
}
.loader.is-hidden { opacity: 0; visibility: hidden; }
.loader-ring {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.desktop-viewer {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 760px;
  min-height: 0;
  perspective: 2600px;
}

.desktop-zoom {
  width: min(100%, calc((100vh - 260px) * var(--book-ratio)));
  aspect-ratio: var(--book-ratio) / 1;
  transform: scale(1);
  transform-origin: center;
  transition: transform 180ms ease;
  will-change: transform;
}

.book {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: translateX(-25%);
  transition: transform 850ms cubic-bezier(.22,.75,.18,1);
  filter: drop-shadow(0 22px 32px rgba(0,0,0,0.38));
}

.book.is-open { transform: translateX(0); }
.book.is-back-cover { transform: translateX(25%); }

.book-base {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: #f9f9f7;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.04);
  transition: opacity 250ms ease;
}
.book:not(.is-open):not(.is-back-cover) .book-base-left { opacity: 0; }
.book.is-back-cover .book-base-right { opacity: 0; }
.book-base-left { left: 0; }
.book-base-right { right: 0; }

.sheet {
  position: absolute;
  top: 0;
  left: 50%;
  width: 50%;
  height: 100%;
  transform: rotateY(0deg);
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform 850ms cubic-bezier(.22,.75,.18,1);
  will-change: transform;
}
.sheet.is-flipped { transform: rotateY(-180deg); }

.page {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #fff;
  border-radius: 2px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05), 0 5px 18px rgba(0,0,0,0.13);
}

.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.front::after { background: linear-gradient(90deg, rgba(0,0,0,0.13), transparent 4.5%, transparent 95%, rgba(255,255,255,0.14)); }
.back::after { background: linear-gradient(270deg, rgba(0,0,0,0.13), transparent 4.5%, transparent 95%, rgba(255,255,255,0.14)); }
.back { transform: rotateY(180deg); }
.page img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; }

.mobile-viewer {
  display: none;
  place-items: center;
  width: 100%;
  min-height: 0;
}

.mobile-page-frame {
  width: min(100%, 720px);
  aspect-ratio: var(--page-ratio) / 1;
  overflow: hidden;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.38);
  transform: scale(1);
  transform-origin: center;
  transition: transform 180ms ease;
}
.mobile-page-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 1;
  transition: opacity 150ms ease, transform 220ms ease;
  user-select: none;
}
.mobile-page-frame img.is-changing { opacity: 0.2; transform: scale(0.985); }

.edge-nav {
  position: absolute;
  top: 50%;
  z-index: 60;
  display: grid;
  place-items: center;
  width: 46px;
  height: 66px;
  padding: 0;
  color: #fff;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  cursor: pointer;
  transform: translateY(-50%);
  transition: 160ms ease;
}
.edge-nav:hover { color: #111; background: var(--yellow); border-color: var(--yellow); }
.edge-nav:disabled { opacity: 0.22; cursor: not-allowed; }
.edge-nav-prev { left: 0.75rem; }
.edge-nav-next { right: 0.75rem; }
.edge-nav svg { width: 1.55rem; height: 1.55rem; }

.gesture-note {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  display: none;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  color: rgba(255,255,255,0.72);
  background: rgba(0,0,0,0.3);
  border-radius: 999px;
  font-size: 0.72rem;
  transform: translateX(-50%);
  pointer-events: none;
}
.gesture-note svg { width: 1rem; height: 1rem; }

.controlbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.8rem;
  padding: 0.65rem;
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08);
  backdrop-filter: blur(12px);
}

.control-group { display: flex; align-items: center; gap: 0.35rem; }
.page-navigation { flex: 1 1 auto; justify-content: space-between; max-width: 470px; }

.control-button,
.tool-button,
.zoom-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  color: #303030;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: 150ms ease;
}

.control-button { gap: 0.4rem; padding: 0.55rem 0.8rem; font-size: 0.85rem; font-weight: 750; }
.tool-button { width: 42px; padding: 0; text-decoration: none; }
.zoom-level { min-width: 60px; padding: 0.45rem 0.65rem; font-size: 0.77rem; font-weight: 850; }
.control-button:hover:not(:disabled), .tool-button:hover, .zoom-level:hover { color: #111; border-color: #c5aa00; background: #fffbea; transform: translateY(-1px); }
.control-button:disabled { opacity: 0.38; cursor: not-allowed; }
.page-status { min-width: 122px; color: #4f4f4f; font-size: 0.82rem; font-weight: 800; text-align: center; white-space: nowrap; }
.tool-divider { width: 1px; height: 24px; margin: 0 0.2rem; background: var(--line); }
.fullscreen-close { display: none; }
:fullscreen .fullscreen-open { display: none; }
:fullscreen .fullscreen-close { display: block; }
:fullscreen .topbar, :fullscreen .footer, :fullscreen .catalog-heading, :fullscreen .thumbnail-strip { display: none; }
:fullscreen .main { height: 100vh; padding: 0; }
:fullscreen .catalog { width: 100%; height: 100%; }
:fullscreen .stage { min-height: calc(100vh - 64px); border-radius: 0; border: 0; }
:fullscreen .controlbar { position: fixed; z-index: 100; right: 1rem; bottom: 1rem; left: 1rem; margin: 0; }
:fullscreen .desktop-zoom { width: min(94vw, calc((100vh - 105px) * var(--book-ratio))); }

.thumbnail-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(112px, 1fr);
  gap: 0.65rem;
  overflow-x: auto;
  margin-top: 0.8rem;
  padding: 0.25rem 0.1rem 0.65rem;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  scrollbar-color: #b8b8b8 transparent;
}

.thumbnail {
  display: grid;
  gap: 0.42rem;
  min-width: 112px;
  padding: 0.4rem;
  color: #5c5c5c;
  background: rgba(255,255,255,0.6);
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  scroll-snap-align: start;
  transition: 160ms ease;
}
.thumbnail:hover { color: #202020; background: #fff; border-color: var(--line); transform: translateY(-2px); }
.thumbnail.is-active { color: #111; background: #fff; border-color: #d8b900; box-shadow: 0 8px 18px rgba(0,0,0,0.09); }
.thumbnail-image {
  display: block;
  overflow: hidden;
  aspect-ratio: var(--page-ratio) / 1;
  background: #eee;
  border-radius: 6px;
}
.thumbnail-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumbnail > span:last-child { overflow: hidden; font-size: 0.72rem; font-weight: 780; text-align: center; text-overflow: ellipsis; white-space: nowrap; }

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  width: min(1560px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.2rem 0 1.8rem;
  color: #666;
  font-size: 0.78rem;
}
.footer > div:first-child { display: grid; gap: 0.25rem; }
.footer strong { color: #333; }
.footer-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.9rem; }
.footer a { text-decoration: none; }
.footer a:hover { color: #806d00; text-decoration: underline; }

@media (max-width: 900px) {
  .catalog-heading { align-items: start; flex-direction: column; gap: 0.65rem; }
  .catalog-intro { text-align: left; }
  .controlbar { align-items: stretch; flex-direction: column; }
  .page-navigation { width: 100%; max-width: none; }
  .viewer-tools { justify-content: center; }
}

@media (max-width: 760px) {
  .topbar { min-height: 62px; padding: 0.55rem 0.75rem; }
  .brand-mark { width: 36px; height: 36px; flex-basis: 36px; }
  .brand-copy strong { font-size: 0.92rem; }
  .brand-copy small { font-size: 0.66rem; }
  .top-link { min-width: 40px; min-height: 40px; padding: 0.55rem; }
  .top-link span { display: none; }
  .main { padding: 1rem 0.55rem; }
  .catalog-heading { margin-bottom: 0.9rem; padding-inline: 0.35rem; }
  .eyebrow { font-size: 0.68rem; }
  h1 { font-size: 1.55rem; }
  .catalog-intro { font-size: 0.82rem; }
  .stage {
    min-height: min(62vh, 640px);
    padding: 1.1rem 0.65rem 2.6rem;
    border-radius: 14px;
    touch-action: pan-y;
  }
  .desktop-viewer { display: none; }
  .mobile-viewer { display: grid; }
  .edge-nav { width: 34px; height: 54px; border-radius: 10px; background: rgba(20,20,20,0.56); }
  .edge-nav-prev { left: 0.25rem; }
  .edge-nav-next { right: 0.25rem; }
  .gesture-note { display: flex; }
  .controlbar { padding: 0.55rem; }
  .control-button { min-height: 40px; padding: 0.5rem 0.65rem; }
  .control-button span { display: none; }
  .page-status { min-width: 118px; font-size: 0.78rem; }
  .tool-button { width: 40px; min-height: 40px; }
  .thumbnail-strip { grid-auto-columns: 94px; gap: 0.5rem; }
  .thumbnail { min-width: 94px; }
  .footer { align-items: flex-start; flex-direction: column; width: calc(100% - 1.5rem); padding-bottom: 1.2rem; }
  .footer-links { justify-content: flex-start; gap: 0.55rem 0.9rem; }
  :fullscreen .stage { min-height: calc(100vh - 112px); }
  :fullscreen .controlbar { right: 0.5rem; bottom: 0.5rem; left: 0.5rem; }
}

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