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

body {
  font-family: Georgia, "Times New Roman", Times, serif;
  color: #111;
  background: #fff;
  -webkit-font-smoothing: antialiased;
}

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;
}

/* Grid viewport — fills available space, scrolls */
.grid-viewport {
  width: 100%;
  height: calc(100vh - 120px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.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: transform 0.2s ease, box-shadow 0.2s ease;
}
.book-cell:hover {
  transform: scale(1.03);
  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.35s ease;
}
.cover-image {
  opacity: 0;
  transition: opacity 0.25s 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:empty {
  background: linear-gradient(90deg, #e0e0e0 25%, #f0f0f0 50%, #e0e0e0 75%) !important;
  background-size: 200% 100% !important;
  animation: shimmer 1.5s infinite;
}

/* Reader view */
.reader {
  max-width: 65ch;
  margin: 0 auto;
  padding: 0 1.5rem 6rem;
}

.back-link {
  font-size: 0.85rem;
  color: #888;
  text-decoration: none;
  display: inline-block;
  margin-bottom: 2rem;
}
.back-link:hover { color: #111; }

.reader h1 {
  font-size: 2rem;
  font-weight: normal;
  line-height: 1.3;
  margin-bottom: 1rem;
}

.reader time {
  font-size: 0.85rem;
  color: #888;
  display: block;
  margin-bottom: 3rem;
}

.reader .body {
  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 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 #ccc;
  padding-left: 1.5rem;
  margin: 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;
}
[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; }

/* 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:empty {
  background: linear-gradient(90deg, #333 25%, #444 50%, #333 75%) !important;
  background-size: 200% 100% !important;
}
[data-theme="dark"] .back-link { color: #777; }
[data-theme="dark"] .back-link:hover { color: #d8d5d0; }
[data-theme="dark"] .reader time { color: #777; }
[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; }
  .grid-viewport { height: calc(100vh - 90px); }
  .grid-container {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    padding: 0 12px 12px;
  }
  .reader { padding: 0 1.5rem 4rem; }
  .reader h1 { font-size: 1.5rem; }
}

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