:root {
  --bg: #050505;
  --bg-soft: rgba(12, 12, 12, 0.88);
  --panel: rgba(18, 18, 18, 0.9);
  --panel-strong: rgba(24, 24, 24, 0.97);
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.28);
  --text: #f5f5f5;
  --muted: #a6a6a6;
  --accent: #f0f0f0;
  --accent-soft: rgba(255, 255, 255, 0.08);
  --thumb-width: 218px;
  --thumb-gap: 24px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body.library-body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.09), transparent 32%),
    radial-gradient(circle at bottom right, rgba(255, 255, 255, 0.06), transparent 26%),
    var(--bg);
  color: var(--text);
  font-family: "Courier New", Courier, monospace;
  overflow-x: hidden;
}

body.library-body::before,
body.library-body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body.library-body::before {
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.65;
}

body.library-body::after {
  background: radial-gradient(circle at center, transparent 32%, rgba(0, 0, 0, 0.54) 100%);
}

body.library-body.modal-open {
  overflow: hidden;
}

.library-page {
  position: relative;
  z-index: 1;
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.library-header {
  text-align: center;
  margin-bottom: 18px;
}

.library-header h1 {
  margin: 0;
  font-size: clamp(42px, 6vw, 84px);
  font-weight: normal;
  letter-spacing: 0.3em;
  text-transform: lowercase;
}

.library-shell {
  padding: 26px;
  background: linear-gradient(180deg, rgba(12, 12, 12, 0.94), rgba(8, 8, 8, 0.96));
  box-shadow: var(--shadow);
}

.library-content {
  display: grid;
  gap: 22px;
}

.library-section {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(20, 20, 20, 0.9), rgba(12, 12, 12, 0.94));
  padding: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  display: block;
}

.section-icon path,
.section-icon rect,
.section-icon line,
.section-icon polyline {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.section-icon .icon-fill {
  fill: var(--accent);
  stroke: none;
}

.section-icon.current .book-page {
  transform-box: fill-box;
  transform-origin: left center;
  animation: pageTurn 2.5s ease-in-out infinite;
}

.section-icon.current .book-lines {
  opacity: 0.72;
}

.section-icon.read .shelf-book {
  animation: shelfPulse 3.6s ease-in-out infinite;
}

.section-icon.read .shelf-book.book-two {
  animation-delay: 0.24s;
}

.section-icon.read .shelf-book.book-three {
  animation-delay: 0.48s;
}

.section-icon.want .awning {
  transform-box: fill-box;
  transform-origin: center top;
  animation: awningSwing 3.2s ease-in-out infinite;
}

.section-icon.favorite .spark {
  animation: sparkBlink 2.1s ease-in-out infinite;
}

.shelf-stack {
  display: grid;
  gap: 28px;
}

.shelf-track {
  display: flex;
  gap: var(--thumb-gap);
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  padding: 8px 4px 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.34) rgba(255, 255, 255, 0.06);
  cursor: grab;
}

.shelf-track.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.shelf-track.is-dragging .book-thumb {
  pointer-events: none;
}

.shelf-track::-webkit-scrollbar {
  height: 10px;
}

.shelf-track::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

.shelf-track::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.32);
}

.book-thumb {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  flex: 0 0 auto;
  color: inherit;
  cursor: pointer;
  text-align: left;
  transition: transform 0.18s ease;
}

.book-thumb:hover,
.book-thumb:focus-visible {
  transform: translateY(-5px);
}

.book-thumb:focus-visible .book-skin {
  outline: 2px solid rgba(255, 255, 255, 0.82);
  outline-offset: 3px;
}

.book-skin {
  position: relative;
  width: var(--thumb-width);
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 22px 38px rgba(0, 0, 0, 0.38);
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.12), transparent 28%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.06), rgba(0, 0, 0, 0.24));
}

.book-skin::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 46%, rgba(0, 0, 0, 0.18) 100%);
  pointer-events: none;
}

.book-skin.has-image .book-fallback {
  opacity: 0;
  pointer-events: none;
}

.book-skin.is-missing-image .book-image,
.book-skin:not(.has-image) .book-image {
  display: none;
}

.book-skin.is-missing-image .book-fallback,
.book-skin:not(.has-image) .book-fallback {
  opacity: 1;
}

.book-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.book-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 16px;
  color: var(--cover-ink, #171210);
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.18), transparent 30%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(0, 0, 0, 0.12)),
    var(--cover-color, #e3cda8);
  opacity: 1;
  transition: opacity 0.18s ease;
  filter: grayscale(1);
}

.book-fallback::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.16), transparent 10%, transparent 88%, rgba(0, 0, 0, 0.12)),
    linear-gradient(180deg, rgba(0, 0, 0, 0.08), transparent 28%);
  mix-blend-mode: multiply;
  pointer-events: none;
}

.book-badge {
  position: relative;
  z-index: 1;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.9;
}

.book-title-stack {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 6px;
}

.book-title-stack strong {
  display: block;
  font-size: 26px;
  line-height: 1.02;
  text-transform: uppercase;
}

.book-title-stack span {
  display: block;
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.85;
}

.book-favorite {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 8, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: #f2f2f2;
  font-size: 15px;
}

.record-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
}

.record-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

.record-card {
  position: relative;
  z-index: 1;
  width: min(980px, calc(100vw - 24px));
  margin: min(8vh, 56px) auto;
  padding: 18px;
  background: linear-gradient(180deg, rgba(24, 24, 24, 0.97), rgba(12, 12, 12, 0.98));
  border: 1px solid var(--line-strong);
  box-shadow: 0 28px 64px rgba(0, 0, 0, 0.48);
}

.record-close {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font: inherit;
  padding: 8px 10px;
  margin-left: auto;
  display: block;
  cursor: pointer;
}

.record-close:hover,
.record-close:focus-visible {
  border-color: rgba(255, 255, 255, 0.55);
  color: var(--text);
}

.record-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.record-cover .book-skin {
  width: 100%;
  max-width: 300px;
}

.record-copy h2 {
  margin: 0 0 14px;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: normal;
  line-height: 1;
}

.record-label {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}

.record-grid {
  margin: 0;
  display: grid;
  gap: 10px;
}

.record-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.record-row dt,
.record-row dd {
  margin: 0;
  line-height: 1.55;
}

.record-row dt {
  color: var(--muted);
}

.record-row dt::after {
  content: ":";
  margin-left: 4px;
}

.record-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.record-block h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.record-block p,
.record-block li {
  line-height: 1.6;
}

.record-block p,
.record-block ul {
  margin: 0;
}

.record-block ul {
  padding-left: 18px;
}

.record-error {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(18, 18, 18, 0.9);
  padding: 18px;
}

.record-error p {
  margin: 0;
  line-height: 1.6;
  color: var(--muted);
}

@keyframes pageTurn {
  0%,
  100% {
    transform: scaleX(1);
    opacity: 0.84;
  }

  45% {
    transform: scaleX(0.16) skewY(-5deg);
    opacity: 0.52;
  }
}

@keyframes shelfPulse {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-1px);
  }
}

@keyframes awningSwing {
  0%,
  100% {
    transform: rotate(0deg);
  }

  40% {
    transform: rotate(-2.5deg);
  }

  60% {
    transform: rotate(2deg);
  }
}

@keyframes sparkBlink {
  0%,
  100% {
    opacity: 0.4;
  }

  50% {
    opacity: 1;
  }
}

@media (max-width: 820px) {
  .library-page {
    width: min(94vw, 760px);
    padding: 18px 0 28px;
  }

  .library-shell {
    padding: 16px;
  }

  .library-section {
    padding: 14px;
  }

  .record-layout {
    grid-template-columns: 1fr;
  }

  .record-cover .book-skin {
    max-width: 220px;
  }
}

@media (max-width: 560px) {
  .library-header h1 {
    letter-spacing: 0.2em;
  }

  .library-shell {
    padding: 12px;
  }

  .library-section {
    padding: 12px;
  }

  .shelf-track {
    --thumb-width: 136px;
    --thumb-gap: 16px;
  }

  .book-skin {
    width: var(--thumb-width);
  }

  .book-title-stack strong {
    font-size: 18px;
  }

  .book-title-stack span,
  .book-badge {
    font-size: 10px;
  }

  .record-card {
    padding: 14px;
    margin-top: 16px;
  }

  .record-row {
    grid-template-columns: 70px minmax(0, 1fr);
  }
}
