:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #241b13;
  background: #f7f3ec;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
}

a {
  color: inherit;
}

.library,
.reader {
  width: min(100% - 2rem, 1440px);
  margin-inline: auto;
}

.library-header {
  padding-block: 1.5rem;
}

.library-header h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  padding-bottom: 2rem;
}

.book-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 0.55rem;
  color: inherit;
  text-decoration: none;
}

.book-card:hover .book-title,
.book-card:focus-visible .book-title {
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.cover-frame {
  display: grid;
  min-height: 200px;
  aspect-ratio: 2 / 3;
  place-items: center;
  overflow: hidden;
  background: #e9e1d5;
  border-radius: 0.3rem;
}

.cover-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.book-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
}

.reader {
  width: min(100% - 1rem, 1440px);
  padding-bottom: 2rem;
}

.reader-nav {
  padding-block: 1rem;
}

.reader-nav a {
  display: inline-block;
  padding: 0.5rem 0;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.reader-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
}

.reader-header h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.2;
}

.width-control {
  display: grid;
  flex: 0 0 min(300px, 48%);
  gap: 0.4rem;
  font-size: 0.9rem;
}

.width-control input {
  width: 100%;
}

.page-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.page-image {
  display: block;
  width: min(var(--reader-width, 900px), calc(100vw - 1rem));
  height: auto;
  background: #fff;
}

.reader-nav-bottom {
  padding-top: 1.5rem;
}

@media (max-width: 600px) {
  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
  }

  .cover-frame {
    min-height: 0;
  }

  .reader-header {
    align-items: stretch;
    flex-direction: column;
  }

  .width-control {
    flex-basis: auto;
    width: 100%;
  }
}
