#view-library.view {
  padding: 0;
  overflow: hidden;
}

.library-root {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.library-shelf,
.library-reader {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.library-root [hidden] {
  display: none !important;
}

.library-shelf {
  overflow: auto;
  padding: 0.4rem 1.5rem 2rem;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr));
  gap: 1.15rem 1rem;
  max-width: 1100px;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.55rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.book-card:hover,
.book-card:focus-visible {
  background: var(--gray-50);
}

.book-card.is-open {
  background: var(--gray-50);
}

.book-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  width: 100%;
  border-radius: 4px;
  overflow: hidden;
  background: var(--gray-100);
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}

.book-cover-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--gray-500);
  letter-spacing: 0.04em;
}

.book-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.35);
}

.book-progress > span {
  display: block;
  height: 100%;
  background: var(--note-orange);
  width: 0;
}

.book-card h3 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--gray-800);
}

.book-card p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--gray-500);
}

.library-empty {
  max-width: 28rem;
  margin: 2rem 0;
  color: var(--gray-500);
}

.library-empty i {
  font-size: 2.2rem;
  color: var(--gray-400);
}

.library-empty h3 {
  margin: 0.6rem 0 0.3rem;
  color: var(--gray-800);
  font-size: 1.05rem;
}

.library-empty p {
  margin: 0;
  font-size: 0.88rem;
}

.library-empty code {
  font-family: var(--font-mono);
  font-size: 0.8em;
}

.library-reader-chrome {
  flex: none;
}

.library-toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 52px;
  padding: 0 0.55rem 0 0.35rem;
  flex: none;
}

.library-now {
  flex: 1;
  min-width: 0;
}

.library-now-title {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-now-meta {
  margin: 0;
  font-size: 0.72rem;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-now-page {
  display: none;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--gray-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex: none;
}

.library-progress-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0 0.9rem 0.45rem;
  flex: none;
}

.library-progress-row input[type="range"] {
  flex: 1;
  min-width: 0;
  margin: 0;
  appearance: none;
  height: 3px;
  background: var(--gray-200);
  border-radius: 99px;
  outline: none;
}

.library-progress-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gray-700);
  cursor: pointer;
}

.library-progress-row input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: 0;
  border-radius: 50%;
  background: var(--gray-700);
  cursor: pointer;
}

#library-page-label {
  flex: none;
  min-width: 6.4rem;
  text-align: right;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--gray-500);
}

.library-stage-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--white);
}

.library-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: manipulation;
}

.library-stage.is-zoomed {
  touch-action: pan-x pan-y;
}

.library-chrome-peek {
  display: none;
}

.library-stage.is-leaves {
  align-items: flex-start;
  justify-content: flex-start;
  touch-action: none;
}

.library-stage.is-leaves.is-zoomed {
  touch-action: none;
}

.library-stage.is-leaves .library-spread,
.library-stage.is-leaves .library-leaf[data-leaf="single"] {
  margin: auto;
}

.library-stage.is-leaves.is-zoomed .library-spread,
.library-stage.is-leaves.is-zoomed .library-leaf[data-leaf="single"] {
  margin: 0 auto;
}

.library-stage iframe {
  background: var(--white);
}

.library-spread {
  display: flex;
  align-items: stretch;
  justify-content: center;
  flex: none;
  gap: 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.library-leaf {
  position: relative;
  flex: none;
  overflow: hidden;
  background: #cbb892;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.library-leaf[data-leaf="left"] {
  border-radius: 6px 0 0 6px;
}

.library-leaf[data-leaf="right"] {
  border-radius: 0 6px 6px 0;
}

.library-leaf[data-leaf="left"]::after,
.library-leaf[data-leaf="right"]::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 22px;
  pointer-events: none;
  z-index: 1;
}

.library-leaf[data-leaf="left"]::after {
  right: 0;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.28), rgba(0, 0, 0, 0.08) 42%, transparent);
}

.library-leaf[data-leaf="right"]::after {
  left: 0;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.22), rgba(0, 0, 0, 0.06) 42%, transparent);
}

.library-leaf[data-leaf="single"] {
  border-radius: 6px;
}

.library-leaf.is-blank {
  background-color: #5e4b3d;
  background-image:
    linear-gradient(90deg, rgba(0, 0, 0, 0.22), transparent 24%),
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.05) 0 1px,
      transparent 1px 3px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.08) 0 1px,
      transparent 1px 3px
    ),
    linear-gradient(145deg, #6d5848 0%, #534336 52%, #46382d 100%);
}

.library-leaf.is-blank::before {
  content: "";
  position: absolute;
  z-index: 0;
  pointer-events: none;
  border-radius: 1px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent 28%),
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.03) 0 2px,
      transparent 2px 4px
    ),
    #4a3d32;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    inset 0 0 24px rgba(0, 0, 0, 0.16);
}

.library-leaf[data-leaf="left"].is-blank::before {
  inset: 1.1rem 0.95rem 1.1rem 1.2rem;
}

.library-leaf[data-leaf="right"].is-blank::before {
  inset: 1.1rem 1.2rem 1.1rem 0.95rem;
}

.library-leaf[data-leaf="single"].is-blank::before {
  inset: 1.1rem;
}

.library-pdf-canvas,
.library-page-img {
  display: block;
  flex: none;
  background: #111;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.library-page-img {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: transparent;
  object-fit: contain;
  object-position: center;
}

.library-leaf[data-leaf="single"] .library-pdf-canvas,
.library-leaf[data-leaf="single"] .library-page-img {
  border-radius: 6px;
  box-shadow: var(--shadow-md);
}

.library-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: var(--gray-500);
  font-size: 0.88rem;
  background: var(--white);
}

.library-status[hidden] {
  display: none !important;
}

.library-toc {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(22rem, 88%);
  background: var(--gray-50);
  z-index: 4;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.library-toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.45rem 0.45rem 1rem;
  flex: none;
}

.library-toc-head h2 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gray-800);
}

#library-toc-list {
  flex: 1;
  overflow: auto;
  padding: 0.2rem 0.6rem 1rem;
}

#library-toc-list button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--gray-800);
  font: inherit;
  font-size: 0.86rem;
  padding: 0.45rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
}

#library-toc-list button:hover {
  background: var(--gray-100);
}

#library-toc-list .toc-nested {
  padding-left: 0.8rem;
}

@media (min-width: 801px) {
  .library-reader-chrome {
    display: grid;
    grid-template-columns: auto auto minmax(6.5rem, 1fr) auto;
    grid-template-rows: 40px;
    grid-template-areas: "back now slider actions";
    align-items: center;
    min-height: 40px;
    padding: 0 0.3rem 0 0.2rem;
    column-gap: 0.15rem;
  }

  .library-toolbar {
    display: contents;
  }

  #library-back {
    grid-area: back;
  }

  .library-now {
    grid-area: now;
    flex: none;
    min-width: 0;
  }

  .library-now-title,
  .library-now-meta {
    display: none;
  }

  .library-now-page {
    display: block;
    padding: 0 0.2rem;
    font-size: 0.78rem;
    color: var(--gray-600);
  }

  .library-progress-row {
    grid-area: slider;
    padding: 0 0.55rem 0 0.25rem;
    min-width: 0;
    min-height: 40px;
    height: 40px;
  }

  .library-progress-row #library-page-label {
    display: none;
  }

  .library-toolbar-actions {
    grid-area: actions;
  }
}

@media (max-width: 800px) {
  .library-reader-chrome {
    display: contents;
  }

  .library-shelf {
    padding: 0.2rem 1rem 1.4rem;
  }

  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(8.6rem, 1fr));
    gap: 0.9rem 0.7rem;
  }

  #library-page-label {
    min-width: 5.4rem;
  }

  #library-prev,
  #library-next {
    display: none;
  }

  body.is-reading-immersive .library-reader {
    position: relative;
  }

  body.is-reading-immersive .library-toolbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 6;
    min-height: 44px;
    background: color-mix(in srgb, var(--white) 92%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: opacity 0.18s ease, transform 0.18s ease;
  }

  body.is-reading-immersive .library-now-title,
  body.is-reading-immersive .library-now-meta {
    display: none;
  }

  body.is-reading-immersive .library-now-page {
    display: block;
  }

  body.is-reading-immersive .library-progress-row {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 6;
    padding: 0.55rem 1rem 0.7rem;
    background: color-mix(in srgb, var(--white) 92%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: opacity 0.18s ease, transform 0.18s ease;
  }

  body.is-reading-immersive .library-progress-row #library-page-label {
    display: none;
  }

  body.is-reading-immersive:not(.is-reading-chrome) .library-toolbar {
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
  }

  body.is-reading-immersive:not(.is-reading-chrome) .library-progress-row {
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
  }

  body.is-reading-immersive:not(.is-reading-chrome) .library-chrome-peek {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 22px;
    z-index: 5;
    border: 0;
    padding: 0;
    cursor: pointer;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.08), transparent);
  }
}

@media (max-width: 800px) and (prefers-reduced-motion: reduce) {
  body.is-reading-immersive .library-toolbar,
  body.is-reading-immersive .library-progress-row {
    transition: none;
  }
}
