:root {
  --bg: #f7f5f0;
  --ink: #111111;
  --muted: #8a8680;
  --rule: #e4e0d8;
  --serif: "Instrument Serif", "Newsreader", "Times New Roman", serif;
  --sans: "Avenir Next", Avenir, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --shelf-h: 280px;
  --cover-ratio: 0.68;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ink); text-decoration: none; border-bottom: 1px solid transparent; }
a:hover { border-bottom-color: var(--ink); }

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--rule);
}

.brand {
  font-family: var(--sans);
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  text-transform: lowercase;
  border: 0;
}

.site-nav {
  display: flex;
  gap: 1.25rem;
  align-items: baseline;
  font-size: 0.85rem;
  text-transform: lowercase;
  color: var(--muted);
}
.site-nav a { color: var(--muted); border: 0; }
.site-nav a:hover { color: var(--ink); }
.demo-tag {
  color: #bbb;
  font-size: 0.75rem;
}

.shelf-page {
  max-width: 100%;
  padding: 2.5rem 0 4rem;
}

.hero {
  padding: 0 2rem 2rem;
  max-width: 52rem;
}
.hero h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2.6rem, 6vw, 4.2rem);
  line-height: 1.05;
  margin: 0 0 0.85rem;
  letter-spacing: -0.01em;
}
.lede {
  margin: 0;
  max-width: 36rem;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

.controls {
  padding: 0 2rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.1rem;
  align-items: center;
}
.chip {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.82rem;
  text-transform: lowercase;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
  border-radius: 999px;
  line-height: 1;
}
.chip:hover { color: var(--ink); }
.chip.is-active {
  color: var(--ink);
  background: #ece8e0;
}
.chip .dot { margin-right: 0.15rem; }

.search-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  max-width: 28rem;
}
.search {
  flex: 1;
  appearance: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  font-family: var(--sans);
  font-size: 0.9rem;
  padding: 0.45rem 0;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.search::placeholder { color: #b0aaa2; }
.search:focus { border-bottom-color: var(--ink); }
.count {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  text-transform: lowercase;
}

/* —— Shelf —— */
.shelf-wrap {
  position: relative;
  padding: 1.5rem 0 0.5rem;
}

.shelf-viewport {
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1.75rem 2rem 1.25rem;
  outline: none;
  cursor: grab;
  scrollbar-width: thin;
  scrollbar-color: #d4cfc5 transparent;
}
.shelf-viewport::-webkit-scrollbar { height: 4px; }
.shelf-viewport::-webkit-scrollbar-thumb { background: #d4cfc5; border-radius: 2px; }
.shelf-viewport.is-dragging { cursor: grabbing; user-select: none; }

.shelf-track {
  display: flex;
  align-items: flex-end;
  gap: 1.5px;
  height: var(--shelf-h);
  width: max-content;
  min-width: 100%;
  justify-content: center;
}

.shelf-shadow {
  height: 28px;
  margin: -4px 3rem 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.18) 0%, rgba(0,0,0,0.06) 45%, transparent 72%);
  filter: blur(6px);
  pointer-events: none;
  opacity: 0.85;
}

/* Book — reset <button> UA chrome so colour fills edge-to-edge */
.book {
  appearance: none;
  -webkit-appearance: none;
  border: 0 !important;
  padding: 0 !important;
  margin: 0;
  background: transparent !important;
  color: inherit;
  font: inherit;
  line-height: normal;
  position: relative;
  flex: 0 0 auto;
  flex-shrink: 0;
  min-width: 0;
  height: var(--shelf-h);
  width: var(--bw, 40px);
  cursor: pointer;
  transform-origin: center bottom;
  /* lift only — never scale (scale softens the cover raster) */
  transform: translateY(var(--lift, 0px));
  z-index: 1;
  perspective: none;
  -webkit-tap-highlight-color: transparent;
  overflow: visible;
  box-shadow: none;
  outline: none;
  border-radius: 0;
}
.book:focus, .book:focus-visible {
  outline: none;
}
.book.is-open { z-index: 8; }
.book.is-focused { z-index: 4; }
.book.is-leaving {
  pointer-events: none;
}
/* 3D only while the flip spring is in motion */
.book.is-flipping {
  perspective: 900px;
}

.book-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: flat;
  transform: none;
  filter: none;
  background: transparent;
  overflow: hidden;
  border-radius: 0;
}
.book.is-flipping .book-inner {
  transform-style: preserve-3d;
  transform: rotateY(var(--rot, 0deg));
  filter: drop-shadow(0 calc(var(--shadow-y, 2px)) calc(var(--shadow-blur, 4px)) rgba(0,0,0, var(--shadow-a, 0.12)));
}
/* Settled open: fully flat + crisp, shadow via box-shadow (not filter) */
.book.is-open.is-crisp {
  perspective: none !important;
}
.book.is-open.is-crisp .book-inner {
  transform: none !important;
  filter: none !important;
  transform-style: flat !important;
}
.book.is-open.is-crisp .cover-face {
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.22),
    0 2px 6px rgba(0, 0, 0, 0.12);
}

/* Face-out books: full cover on the shelf, flat + crisp */
.book.is-face-out {
  perspective: none !important;
  z-index: 2;
}
.book.is-face-out .book-inner {
  transform: none !important;
  filter: none !important;
  transform-style: flat !important;
}
.book.is-face-out .spine {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none;
}
.book.is-face-out .cover-face {
  opacity: 1 !important;
  visibility: visible !important;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.16),
    0 1px 3px rgba(0, 0, 0, 0.08);
}
.book.is-face-out.is-open .cover-face {
  box-shadow:
    0 12px 28px rgba(0, 0, 0, 0.22),
    0 2px 6px rgba(0, 0, 0, 0.12);
}
.book.is-face-out .cover-face img {
  transform: none;
  filter: none;
}


/* Faces fill the full book box — no frame, no padding */
.spine, .cover-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  box-sizing: border-box;
}

.spine {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 12px 0 8px;
  margin: 0;
  background-color: var(--spine);
  color: var(--ink-spine);
  /* cylindrical shading lives only in the gradient overlay below — no inset "frame" ring */
  box-shadow: none;
}

/* Subtle cylinder: darker left/right edges, faint centre highlight.
   Works on light spines too (very faint edge shade, not a white border). */
.spine::before {
  content: "";
  position: absolute;
  inset: 0;
  /* edge shade only — reads on light AND dark spines without a white frame */
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.18) 0%,
    rgba(0, 0, 0, 0.05) 14%,
    rgba(0, 0, 0, 0) 30%,
    rgba(0, 0, 0, 0) 70%,
    rgba(0, 0, 0, 0.05) 86%,
    rgba(0, 0, 0, 0.16) 100%
  );
  pointer-events: none;
  z-index: 0;
}
.spine::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    transparent 36%,
    rgba(255, 255, 255, 0.10) 50%,
    transparent 64%,
    transparent 100%
  );
  pointer-events: none;
  mix-blend-mode: soft-light;
  opacity: 0.7;
  z-index: 0;
}

.spine-text {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding: 0 2px;
  margin: 0 0 auto;
  overflow: hidden;
}

.spine-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--sans);
  font-weight: 700;
  font-size: 14.5px;
  line-height: 1.12;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  max-height: calc(var(--shelf-h) - 72px);
  /* allow two vertical columns on wide spines; single column truncated in JS on narrow */
  max-width: calc(var(--bw, 40px) - 6px);
  overflow: hidden;
  text-overflow: clip;
  white-space: normal;
  word-break: break-word;
  position: relative;
  z-index: 1;
  padding: 0;
  margin: 0 auto;
  color: var(--ink-spine);
  /* keep glyphs crisp over the soft cylinder wash */
  text-shadow:
    0 0 1px rgba(0, 0, 0, 0.12),
    0 1px 0 rgba(0, 0, 0, 0.06);
}

.spine-author {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 9.5px;
  line-height: 1.1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  max-height: 72px;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0.72;
  margin: 8px auto 0;
  position: relative;
  z-index: 1;
  color: var(--ink-spine);
}

.spine-mark {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  margin-top: 8px;
}

@media (max-width: 720px) {
  .spine-title { font-size: 13px; letter-spacing: 0.05em; }
  .spine-author { font-size: 8.5px; max-height: 56px; }
}


.cover-face {
  background: var(--spine, #ddd8ce);
  transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
  padding: 0;
  margin: 0;
}
.cover-face img {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain; /* never stretch or crop covers */
  object-position: center center;
  display: block;
  flex-shrink: 0;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
  image-rendering: auto;
  -webkit-user-drag: none;
}
.book.is-open.is-crisp .cover-face img,
.book.is-face-out .cover-face img {
  transform: none;
  filter: none;
  object-fit: contain;
}

.typo-cover {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1rem 0.85rem;
  background: #ebe6dc;
  color: var(--ink);
  font-family: var(--serif);
}
.typo-cover strong {
  font-weight: 400;
  font-size: 1.05rem;
  line-height: 1.2;
}
.typo-cover span {
  font-family: var(--sans);
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: lowercase;
}

/* When open, we show cover by rotating -90deg; spine gets hidden via backface */


/* Caption */
.caption {
  padding: 1.75rem 2rem 0;
  min-height: 6.5rem;
  text-align: center;
}
.caption-inner {
  max-width: 36rem;
  margin: 0 auto;
}
.caption-inner.is-empty .caption-hint {
  color: #c4bfb6;
  font-size: 0.85rem;
  text-transform: lowercase;
}
.caption-index {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin: 0 0 0.35rem;
  font-variant-numeric: tabular-nums;
}
.caption-title {
  font-family: var(--serif);
  font-size: clamp(1.35rem, 3vw, 1.85rem);
  font-weight: 400;
  margin: 0 0 0.3rem;
  line-height: 1.2;
}
.caption-title .dot {
  margin-right: 0.3rem;
  font-size: 0.85em;
}
.caption-detail {
  margin: 0;
  font-size: 0.82rem;
  color: #a39e96;
  text-transform: lowercase;
}
.caption-actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 1.25rem;
  justify-content: center;
  font-size: 0.85rem;
  text-transform: lowercase;
}
.caption-actions button,
.caption-actions a {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 0;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
  text-transform: lowercase;
}
.caption-actions button:hover,
.caption-actions a:hover {
  border-bottom-color: var(--ink);
}

/* Detail view */
.detail {
  padding: 2.5rem 2rem 0;
  max-width: 56rem;
  margin: 0 auto;
  border-top: 1px solid var(--rule);
  margin-top: 2rem;
}
.detail[hidden] { display: none !important; }
.detail-back {
  appearance: none;
  border: 0;
  background: none;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  margin-bottom: 1.75rem;
  text-transform: lowercase;
}
.detail-back:hover { color: var(--ink); }

.detail-grid {
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr;
  gap: 2.5rem;
  align-items: start;
}
.detail-cover-wrap {
  width: 100%;
  aspect-ratio: 2 / 3; /* overridden from JS to true natural aspect */
  background: #ebe6dc;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center center;
  display: block;
  flex-shrink: 0;
}
.detail-cover-wrap .typo-cover {
  aspect-ratio: 2 / 3;
}

.detail-index {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin: 0 0 0.4rem;
  font-variant-numeric: tabular-nums;
}
.detail-body h2 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  margin: 0 0 0.4rem;
  line-height: 1.15;
}
.detail-meta {
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: lowercase;
  margin: 0 0 1.25rem;
}
.detail-blurb {
  margin: 0 0 1.5rem;
  max-width: 36rem;
  line-height: 1.6;
}

.shane-note {
  border: 1px solid #111;
  padding: 1rem 1.1rem;
  margin: 0 0 1.75rem;
  max-width: 36rem;
}
.shane-note h3 {
  margin: 0 0 0.5rem;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.shane-note p {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.45;
}

.detail-section {
  margin: 0 0 1.5rem;
  max-width: 36rem;
}
.detail-section h3 {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  text-transform: lowercase;
  margin: 0 0 0.65rem;
  color: var(--muted);
}
.detail-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--rule);
}
.detail-section li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--rule);
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.4;
}
.detail-buy {
  margin: 1.5rem 0 0;
  font-size: 0.85rem;
  text-transform: lowercase;
}
.detail-buy a { border-bottom: 1px solid var(--rule); }
.detail-buy a:hover { border-bottom-color: var(--ink); }

/* List pages */
.list-page {
  padding: 2.5rem 2rem 4rem;
  max-width: 42rem;
  margin: 0 auto;
}
.list-page h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(2rem, 5vw, 3rem);
  margin: 0 0 0.5rem;
}
.list-page .sub {
  color: var(--muted);
  margin: 0 0 2rem;
  font-size: 0.9rem;
}
.plain-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.plain-list li {
  padding: 1rem 0;
  border-bottom: 1px solid var(--rule);
}
.plain-list .q {
  font-family: var(--serif);
  font-size: 1.15rem;
  line-height: 1.4;
  margin: 0 0 0.35rem;
}
.plain-list .meta {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: lowercase;
  margin: 0;
}
.plain-list a { border: 0; }
.plain-list a:hover .q { text-decoration: underline; }

body.is-detail .shelf-wrap,
body.is-detail .caption,
body.is-detail .controls,
body.is-detail .hero {
  /* keep visible but dim? or hide - brief says detail view */
}
body.is-detail .shelf-wrap,
body.is-detail .caption {
  opacity: 0.35;
  pointer-events: none;
}

@media (max-width: 720px) {
  :root { --shelf-h: 210px; }
  .site-header { padding: 1rem 1.1rem; }
  .shelf-page { padding-top: 1.5rem; }
  .hero, .controls, .caption, .detail { padding-left: 1.1rem; padding-right: 1.1rem; }
  .shelf-viewport { padding-left: 1.1rem; padding-right: 1.1rem; }
  .shelf-shadow { margin-left: 1.5rem; margin-right: 1.5rem; }
  .detail-grid { grid-template-columns: 120px 1fr; gap: 1.25rem; }
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0.25rem;
    margin: 0 -1.1rem;
    padding-left: 1.1rem;
    padding-right: 1.1rem;
  }
  .filters::-webkit-scrollbar { display: none; }
  .chip { white-space: nowrap; }
  .hero h1 { font-size: 2.2rem; }
}

@media (max-width: 480px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-cover-wrap { max-width: 160px; }
}

@media (max-width: 720px) {
  .demo-tag { display: none; }
  .site-nav { gap: 0.85rem; }
}
