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

/* Hide native scrollbars */
html { scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }

body {
  font-family: Georgia, "Times New Roman", Times, serif;
  color: #111;
  background: #fff;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  max-width: 65ch;
  margin: 0 auto;
  padding: 6rem 1.5rem 3rem;
}

header h1 {
  font-size: 1rem;
  font-weight: normal;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

header h1 a {
  color: inherit;
  text-decoration: none;
}

main {
  padding: 0;
}

.home-screen {
  max-width: 65ch;
  margin: 0 auto;
  padding: 0 1.5rem 6rem;
}

.post-list {
  list-style: none;
}

.post-list li {
  padding: 2.5rem 0;
  border-bottom: 1px solid #e5e5e5;
}

.post-list li:first-child {
  padding-top: 0;
}

.post-list a {
  color: inherit;
  text-decoration: none;
}

.post-list a.has-cover {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}

.post-cover {
  width: 80px;
  flex-shrink: 0;
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.post-info { flex: 1; min-width: 0; }

.post-list h2 {
  font-size: 1.5rem;
  font-weight: normal;
  line-height: 1.3;
  margin-bottom: 0.5rem;
}

.post-list time {
  font-size: 0.85rem;
  color: #888;
  display: block;
  margin-bottom: 0.75rem;
}

.post-list p {
  font-size: 1rem;
  line-height: 1.7;
  color: #444;
}

/* Grid footer */
#book-footer {
  position: relative;
  overflow: hidden;
  margin-top: auto;
  height: 70vh;
  min-height: 70vh;
}

.grid-viewport {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.grid-viewport::-webkit-scrollbar { display: none; }

.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 0 24px 24px;
}

/* Book cell */
.book-cell {
  aspect-ratio: 2 / 3;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: box-shadow 0.2s ease;
}
.book-cell:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.book-cell[data-href]:not([data-href=""]) { cursor: pointer; }

.cover-blur, .cover-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}
.cover-blur {
  opacity: 1;
  transition: opacity 0.15s ease;
}
.cover-image {
  opacity: 0;
  transition: opacity 0.15s ease;
}

/* Hover overlay */
.cover-info {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 12px;
  background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.book-cell:hover .cover-info { opacity: 1; }
.cover-title {
  color: #fff;
  font-size: 0.85rem;
  font-weight: bold;
  line-height: 1.3;
}
.cover-author {
  color: rgba(255,255,255,0.8);
  font-size: 0.75rem;
  margin-top: 2px;
}

/* Review badge */
.review-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 4px rgba(74,222,128,0.5);
}

/* Shimmer for loading */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.cover-blur.is-loading {
  background: linear-gradient(90deg, #e0e0e0 25%, #f0f0f0 50%, #e0e0e0 75%) !important;
  background-size: 200% 100% !important;
  animation: shimmer 1.5s infinite;
}

/* Custom scrollbar */
.scroll-track {
  position: fixed;
  top: 0;
  right: 0;
  width: 40px;
  height: 100vh;
  z-index: 99;
  cursor: pointer;
}
.scroll-track-bar {
  position: absolute;
  top: 8px;
  bottom: 8px;
  right: 9px;
  width: 2px;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.3s;
}
.scroll-track.near .scroll-track-bar { opacity: 1; }
[data-theme="light"] .scroll-track-bar { background: rgba(0,0,0,0.08); }
[data-theme="dark"]  .scroll-track-bar { background: rgba(255,255,255,0.08); }
.scroll-thumb {
  width: 9px;
  border-radius: 999px;
  position: absolute;
  right: 6px;
  opacity: 0;
  transition: opacity 0.3s, box-shadow 0.2s;
}
.scroll-thumb::before,
.scroll-thumb::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 5px;
  height: 1px;
  border-radius: 999px;
  transform: translateX(-50%);
}
.scroll-thumb::before {
  top: 5px;
}
.scroll-thumb::after {
  bottom: 5px;
}
.scroll-track.near .scroll-thumb { opacity: 1; }
[data-theme="light"] .scroll-thumb {
  background: rgba(0,0,0,0.62);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.7);
}
[data-theme="light"] .scroll-thumb::before,
[data-theme="light"] .scroll-thumb::after {
  background: rgba(255,255,255,0.75);
}
[data-theme="dark"]  .scroll-thumb {
  background: rgba(255,255,255,0.7);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5);
}
[data-theme="dark"] .scroll-thumb::before,
[data-theme="dark"] .scroll-thumb::after {
  background: rgba(0,0,0,0.65);
}

/* Reader view */
.reader {
  margin: 0 auto;
  padding: 0 1.5rem 6rem;
}

.reader-shell {
  max-width: 76rem;
  margin: 0 auto;
}

.back-link {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6f6a63;
  text-decoration: none;
  display: inline-block;
  margin-bottom: 2.5rem;
}
.back-link:hover { color: #111; }

.reader-head {
  display: grid;
  grid-template-columns: minmax(11rem, 13rem) minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
  margin-bottom: 3.5rem;
}

.reader-head.no-book {
  grid-template-columns: minmax(0, 44rem);
  justify-content: center;
}

.reader-book-card {
  margin: 0;
}

.reader-cover {
  display: block;
  width: 100%;
  border-radius: 4px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.14);
}

.reader-book-meta {
  margin-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.reader-book-title {
  font-size: 0.92rem;
  line-height: 1.4;
}

.reader-book-author {
  font-size: 0.82rem;
  color: #6f6a63;
}

.reader-intro {
  max-width: 44rem;
}

.reader-eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 0.9rem;
}

.reader h1 {
  font-size: clamp(2.4rem, 5vw, 4.5rem);
  font-weight: normal;
  line-height: 1.02;
  letter-spacing: -0.03em;
  max-width: 12ch;
  margin-bottom: 1.1rem;
}

.reader-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.88rem;
  color: #888;
  margin-bottom: 1.4rem;
}

.reader-meta time {
  display: inline;
}

.reader-meta-sep {
  opacity: 0.5;
}

.reader-deck {
  max-width: 34rem;
  font-size: 1.15rem;
  line-height: 1.7;
  color: #444;
}

.reader-body {
  max-width: 43rem;
  margin: 0 auto;
  font-size: 1.1rem;
  line-height: 1.8;
}

.reader-body h1, .reader-body h2, .reader-body h3,
.reader-body h4, .reader-body h5, .reader-body h6 {
  font-weight: normal;
  margin: 2.5rem 0 1rem;
  line-height: 1.3;
}

.reader-body h2 { font-size: 1.5rem; }
.reader-body h3 { font-size: 1.25rem; }

.reader-body > *:first-child {
  margin-top: 0;
}

.reader-body p {
  margin-bottom: 1.5rem;
}

.reader-body ul, .reader-body ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}

.reader-body li {
  margin-bottom: 0.5rem;
  line-height: 1.7;
}

.reader-body blockquote {
  border-left: 2px solid #d7d1c9;
  padding-left: 1.5rem;
  margin: 2.2rem 0;
  color: #555;
  font-style: italic;
}

.reader-body code {
  font-family: "Courier New", Courier, monospace;
  font-size: 0.9em;
  background: #f5f5f5;
  padding: 0.15em 0.35em;
}

.reader-body pre {
  background: #f5f5f5;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  overflow-x: auto;
}

.reader-body pre code {
  background: none;
  padding: 0;
}

.reader-body img {
  max-width: 100%;
  margin: 2rem 0;
}

.reader-body a {
  color: #111;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reader-body hr {
  border: none;
  border-top: 1px solid #e5e5e5;
  margin: 3rem 0;
}

.empty {
  padding: 6rem 0;
  text-align: center;
  color: #888;
}

/* Theme toggle button */
button.theme-toggle {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  background: none;
  border: none;
  cursor: pointer;
  width: 28px;
  height: 28px;
  padding: 0;
  opacity: 0.4;
  transition: opacity 0.2s;
  z-index: 100;
}
button.theme-toggle:hover { opacity: 0.8; }
button.theme-toggle svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
[data-theme="light"] button.theme-toggle { color: #4a4540; }
[data-theme="dark"] button.theme-toggle { color: #d8d5d0; }
.sun-body { transition: r 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.mask-circle { transition: cx 0.5s cubic-bezier(0.4, 0, 0.2, 1), cy 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.sun-rays {
  transform-origin: center;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.4s ease;
}
.sun-rays line {
  stroke-dasharray: 100;
  transition: stroke-dasharray 0.4s ease, opacity 0.4s ease;
}
[data-theme="dark"] .theme-toggle svg { transform: rotate(0deg); }
[data-theme="dark"] .sun-body { r: 5; }
[data-theme="dark"] .mask-circle { cx: 33; cy: 9; }
[data-theme="dark"] .sun-rays { transform: scale(1) rotate(0deg); opacity: 1; }
[data-theme="light"] .theme-toggle svg { transform: rotate(-45deg); }
[data-theme="light"] .sun-body { r: 9; }
[data-theme="light"] .mask-circle { cx: 18; cy: 9; }
[data-theme="light"] .sun-rays { transform: scale(0) rotate(45deg); opacity: 0; }
[data-theme="sepia"] button.theme-toggle { color: #8a7e6b; }
[data-theme="sepia"] .theme-toggle svg { transform: rotate(-15deg); }
[data-theme="sepia"] .sun-body { r: 6; }
[data-theme="sepia"] .mask-circle { cx: 33; cy: 9; }
[data-theme="sepia"] .sun-rays { transform: scale(1) rotate(0deg); opacity: 1; }
[data-theme="sepia"] .sun-rays line { stroke-dasharray: 1; }
[data-theme="sepia"] .sun-rays line:nth-child(2n) { opacity: 0; }

/* Sepia mode */
[data-theme="sepia"] body { background: #f7f2e9; color: #3d3225; }
[data-theme="sepia"] header h1 a { color: #3d3225; }
[data-theme="sepia"] .book-cell { box-shadow: 0 2px 8px rgba(61,50,37,0.15); }
[data-theme="sepia"] .book-cell:hover { box-shadow: 0 4px 16px rgba(61,50,37,0.25); }
[data-theme="sepia"] .cover-blur.is-loading {
  background: linear-gradient(90deg, #e8dfd0 25%, #f0e8da 50%, #e8dfd0 75%) !important;
  background-size: 200% 100% !important;
}
[data-theme="sepia"] .post-list li { border-bottom-color: #e0d5c4; }
[data-theme="sepia"] .post-list time { color: #8a7e6b; }
[data-theme="sepia"] .post-list p { color: #6b5f4e; }
[data-theme="sepia"] .back-link { color: #8a7e6b; }
[data-theme="sepia"] .back-link:hover { color: #3d3225; }
[data-theme="sepia"] .reader-book-author { color: #8a7e6b; }
[data-theme="sepia"] .reader-eyebrow { color: #8a7e6b; }
[data-theme="sepia"] .reader-meta { color: #8a7e6b; }
[data-theme="sepia"] .reader-deck { color: #6b5f4e; }
[data-theme="sepia"] .reader-body a { color: #3d3225; }
[data-theme="sepia"] .reader-body blockquote { border-left-color: #d0c4b0; color: #6b5f4e; }
[data-theme="sepia"] .reader-body code { background: #ede7db; }
[data-theme="sepia"] .reader-body pre { background: #ede7db; }
[data-theme="sepia"] .reader-body hr { border-top-color: #e0d5c4; }
[data-theme="sepia"] .scroll-track-bar { background: rgba(61,50,37,0.08); }
[data-theme="sepia"] .scroll-thumb {
  background: rgba(61,50,37,0.55);
  box-shadow: 0 0 0 1px rgba(247,242,233,0.7);
}
[data-theme="sepia"] .scroll-thumb::before,
[data-theme="sepia"] .scroll-thumb::after {
  background: rgba(247,242,233,0.75);
}

/* Dark mode */
[data-theme="dark"] body { background: #1a1a1a; color: #d8d5d0; }
[data-theme="dark"] header h1 a { color: #d8d5d0; }
[data-theme="dark"] .book-cell { box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
[data-theme="dark"] .book-cell:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.6); }
[data-theme="dark"] .cover-blur.is-loading {
  background: linear-gradient(90deg, #333 25%, #444 50%, #333 75%) !important;
  background-size: 200% 100% !important;
}
[data-theme="dark"] .post-list li { border-bottom-color: #333; }
[data-theme="dark"] .post-list time { color: #777; }
[data-theme="dark"] .post-list p { color: #a7a29b; }
[data-theme="dark"] .back-link { color: #777; }
[data-theme="dark"] .back-link:hover { color: #d8d5d0; }
[data-theme="dark"] .reader-book-author { color: #99948b; }
[data-theme="dark"] .reader-eyebrow { color: #8e887f; }
[data-theme="dark"] .reader-meta { color: #8e887f; }
[data-theme="dark"] .reader-deck { color: #b5b0a8; }
[data-theme="dark"] .reader-body a { color: #d8d5d0; }
[data-theme="dark"] .reader-body blockquote { border-left-color: #555; color: #999; }
[data-theme="dark"] .reader-body code { background: #2a2a2a; }
[data-theme="dark"] .reader-body pre { background: #2a2a2a; }
[data-theme="dark"] .reader-body hr { border-top-color: #333; }

@media (max-width: 600px) {
  header { padding: 3rem 1.5rem 2rem; }
  .home-screen { padding: 0 1.5rem 4rem; }
  .grid-container {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    padding: 0 12px 12px;
  }
  .reader { padding: 0 1.5rem 4rem; }
  .back-link { margin-bottom: 2rem; }
  .reader-head {
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
  }
  .reader-book-card {
    max-width: 8.5rem;
  }
  .reader h1 {
    font-size: 2.2rem;
    max-width: none;
  }
  .reader-deck {
    font-size: 1rem;
  }
}

@media (min-width: 601px) and (max-width: 1024px) {
  .grid-container {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
  .reader-head {
    grid-template-columns: 10rem minmax(0, 1fr);
    gap: 2rem;
  }
}
