:root {
  --bg: #000000;
  --bg-2: #121212;
  --text: #f2efe9;
  --muted: #9a968e;
  --accent: #c9a86a;
  --shadow: rgba(0, 0, 0, .55);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  min-height: 100vh;
}

/* ---------- Bookshelf: single-screen 4×2 layout ---------- */

.shelf-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.site-header {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px 20px;
  /* takes 1 part of the spare space vs 7 parts below the grid — keeps the
     top ribbon at roughly 60% of the all-spare-on-top height */
  flex: 1 0 auto;
}

.brand-logo {
  height: 96px;
  width: auto;
  display: block;
  max-width: 88vw;
}

.shelf-main {
  flex: 7 0 auto;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 30px;
  text-align: center;
}

.shelf {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: auto auto;
  gap: 18px 26px;
}

.book-card {
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 0;
  transition: transform .25s ease;
}

.book-card:hover { transform: translateY(-5px); }

.cover-box {
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.cover-box img {
  max-width: 100%;
  /* cap so both rows + header/title/footer always fit the viewport */
  max-height: calc((100dvh - 390px) / 2);
  width: auto;
  height: auto;
  display: block;
  border-radius: 4px;
  box-shadow: 0 12px 28px var(--shadow), 0 2px 6px rgba(0, 0, 0, .4);
  transition: box-shadow .25s ease;
}

.book-card:hover .cover-box img {
  box-shadow: 0 20px 44px var(--shadow), 0 3px 8px rgba(0, 0, 0, .5);
}

.book-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 8px;
  flex: none;
}

.book-title { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

.book-pages { color: var(--muted); font-size: 11px; }

.shelf-title {
  font-family: 'Argentum Sans', 'Inter', system-ui, sans-serif;
  font-weight: 300;
  font-size: clamp(22px, 2.6vw, 34px);
  letter-spacing: .06em;
  color: var(--text);
  padding: 16px 0 4px;
  flex: none;
  /* auto margins center the title in the leftover space below the grid */
  margin: auto 0;
}

.site-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  flex: none;
  padding: 6px 0 14px;
}

/* small screens: back to a scrollable flow, 2-up then 1-up */
@media (max-width: 899px) {
  .shelf-page { height: auto; overflow: visible; }
  .shelf-main { padding: 8px 20px 0; }
  .shelf {
    flex: none;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: none;
    gap: 26px 20px;
  }
  .cover-box img { max-height: none; }
  .site-footer { padding: 40px 0 20px; }
}

@media (max-width: 479px) {
  .shelf { grid-template-columns: 1fr; }
}

/* ---------- Viewer ---------- */

.viewer-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  gap: 16px;
}

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  white-space: nowrap;
}

.back-link:hover { color: var(--text); }

.viewer-title {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-spacer { width: 60px; }

.viewer-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 0;
  padding: 0 6px;
}

.flipbook-wrap {
  flex: 1;
  height: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#flipbook { box-shadow: 0 24px 60px var(--shadow); }

#flipbook .page {
  background: #fff;
}

#flipbook .page img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.nav-arrow {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 30px;
  cursor: pointer;
  padding: 18px 10px;
  transition: color .2s;
  z-index: 5;
}

.nav-arrow:hover { color: var(--accent); }

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 12px 0 16px;
}

.viewer-toolbar button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 19px;
  cursor: pointer;
  transition: color .2s;
}

.viewer-toolbar button:hover { color: var(--accent); }

.page-indicator {
  color: var(--muted);
  font-size: 13px;
  min-width: 70px;
  text-align: center;
}

/* thumbnails strip */

.thumbs {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 10px 16px;
  background: var(--bg-2);
}

.thumbs img {
  height: 74px;
  border-radius: 2px;
  cursor: pointer;
  opacity: .65;
  transition: opacity .2s, outline .2s;
  outline: 2px solid transparent;
}

.thumbs img:hover { opacity: 1; }

.thumbs img.active { opacity: 1; outline: 2px solid var(--accent); }

/* zoom overlay */

.zoom-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, .96);
  z-index: 50;
}

.zoom-canvas {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}

.zoom-canvas.dragging { cursor: grabbing; }

.zoom-canvas img {
  max-width: none;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
}

.zoom-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 26px;
  cursor: pointer;
  z-index: 51;
}

@media (max-width: 640px) {
  .nav-arrow { display: none; }
  .viewer-title { font-size: 17px; }
  .thumbs img { height: 56px; }
}
