.library-page-hero {
  background:
    radial-gradient(circle at 84% 0%, rgba(214, 167, 86, 0.13), transparent 31rem),
    linear-gradient(145deg, rgba(10, 22, 32, 0.98), rgba(14, 31, 44, 0.94));
}

.library-page-hero h1 {
  max-width: 20ch;
}

.library-landing-hero h1 {
  max-width: 17ch;
}

.library-section {
  padding-top: clamp(2.5rem, 6vw, 5rem);
}

.library-search-panel {
  padding: clamp(1.2rem, 3vw, 2rem);
  border: 1px solid rgba(214, 167, 86, 0.42);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, #101b25, #111820);
  box-shadow: var(--shadow);
}

.library-search-panel > div:first-child {
  max-width: 720px;
}

.library-search-panel h2,
.library-heading h2 {
  margin: 0;
}

.library-search-panel > div:first-child > p:last-child,
.library-heading > p {
  margin: 0.7rem 0 0;
  color: var(--muted);
}

.library-heading-action p {
  margin: 0 0 0.85rem;
  color: var(--muted);
}

.library-search-controls,
.library-filter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 230px;
  gap: 0.8rem;
  margin-top: 1.4rem;
}

.library-filter-row {
  grid-template-columns: minmax(0, 1fr) 190px 190px;
  margin-top: 0;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--line);
}

.library-search-controls label,
.library-filter-row label,
.library-glossary-search {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.library-search-controls input,
.library-search-controls select,
.library-filter-row input,
.library-filter-row select,
.library-glossary-search input {
  display: block;
  width: 100%;
  min-height: 3.35rem;
  margin-top: 0.35rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-deep);
  color: var(--text);
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
}

.library-search-controls input:focus,
.library-search-controls select:focus,
.library-filter-row input:focus,
.library-filter-row select:focus,
.library-glossary-search input:focus {
  border-color: var(--gold);
  outline: 2px solid rgba(214, 167, 86, 0.22);
}

.library-search-status,
.library-filter-count {
  min-height: 1.8rem;
  margin: 0.75rem 0 0;
  color: var(--quiet);
  font-size: 0.82rem;
}

.library-search-results {
  display: grid;
  max-height: 42rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  overflow-y: auto;
}

.library-search-result,
.library-search-empty {
  padding: 1rem;
  border: 1px solid var(--line-soft);
  background: rgba(8, 11, 14, 0.56);
}

.library-search-result h3,
.library-search-empty h3 {
  margin: 0.45rem 0 0.3rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.08rem;
}

.library-search-result h3 a:hover {
  color: var(--gold-bright);
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.library-search-result p,
.library-search-empty p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.55;
}

.library-search-meta,
.library-register-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  color: var(--quiet);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.library-search-meta span + span,
.library-register-meta span + span {
  padding-left: 0.45rem;
  border-left: 1px solid var(--line);
}

.library-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.75fr);
  align-items: end;
  gap: 2rem;
  margin: clamp(4.5rem, 9vw, 8rem) 0 2rem;
}

.library-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.library-card {
  display: flex;
  min-height: 290px;
  flex-direction: column;
  padding: 1.35rem;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(18, 24, 32, 0.58);
}

.library-card h3,
.library-tool-card h3 {
  margin-bottom: 0.7rem;
  font: 600 1.32rem/1.25 Georgia, "Times New Roman", serif;
}

.library-card p,
.library-tool-card p {
  color: var(--muted);
  font-size: 0.92rem;
}

.library-card small {
  margin-top: auto;
  color: var(--quiet);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.library-card .text-link {
  margin-top: 0.35rem;
}

.library-tool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
}

.library-tool-card {
  display: flex;
  min-height: 260px;
  flex-direction: column;
  padding: 1.35rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.library-tool-card .button {
  width: fit-content;
  margin-top: auto;
}

.library-book-list {
  border-top: 1px solid var(--line);
}

.library-book-row {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 1.1rem;
  padding: 1.15rem 0;
  border-bottom: 1px solid var(--line);
}

.library-book-number {
  color: var(--gold);
  font: 700 0.74rem ui-monospace, SFMono-Regular, Menlo, monospace;
}

.library-book-row h3 {
  margin: 0;
  font: 600 1.14rem/1.35 Georgia, "Times New Roman", serif;
}

.library-book-row h3 a:hover {
  color: var(--gold-bright);
}

.library-book-row p {
  margin: 0.25rem 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.library-book-row small {
  color: var(--quiet);
}

.library-open {
  color: var(--gold-bright);
  font-size: 0.82rem;
  font-weight: 800;
}

.library-reader-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 290px;
  align-items: start;
  gap: clamp(2rem, 6vw, 6rem);
}

.library-prose {
  font: 17px/1.78 Georgia, "Times New Roman", serif;
}

.library-prose > h1:first-of-type {
  display: none;
}

.library-prose h2 {
  scroll-margin-top: 7rem;
  margin: 4rem 0 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--text);
}

.library-prose h3,
.library-prose h4 {
  scroll-margin-top: 7rem;
}

.library-prose h3 {
  margin: 2.5rem 0 0.7rem;
  color: #d8e3ea;
  font: 600 1.32rem/1.3 Georgia, "Times New Roman", serif;
}

.library-prose p,
.library-prose li {
  color: #c7cdd1;
}

.library-prose blockquote {
  margin: 1.5rem 0;
  padding: 1rem 1.15rem;
  border: 1px solid var(--line);
  border-left: 4px solid var(--gold);
  background: var(--surface);
}

.library-prose blockquote p:last-child {
  margin-bottom: 0;
}

.library-prose table {
  display: block;
  width: 100%;
  margin: 1.5rem 0 2rem;
  overflow-x: auto;
  border-collapse: collapse;
  font: 0.85rem/1.45 Inter, ui-sans-serif, system-ui, sans-serif;
}

.library-prose th,
.library-prose td {
  min-width: 8rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.library-prose th {
  background: #172330;
  color: var(--text);
}

.library-prose tr:nth-child(even) td {
  background: rgba(24, 32, 42, 0.46);
}

.library-prose code {
  padding: 0.08em 0.3em;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: #e6d6b7;
  font: 0.86em ui-monospace, SFMono-Regular, Menlo, monospace;
}

.library-prose pre {
  padding: 1rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--bg-deep);
}

.library-prose pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.library-prose .heading-link {
  margin-left: 0.35rem;
  opacity: 0;
  font: 0.7em Inter, ui-sans-serif, system-ui, sans-serif;
  text-decoration: none;
}

.library-prose h2:hover .heading-link,
.library-prose h3:hover .heading-link,
.library-prose .heading-link:focus {
  opacity: 1;
}

.anchor-alias {
  display: block;
  scroll-margin-top: 7rem;
}

.library-toc {
  max-height: calc(100vh - 116px);
  overflow-y: auto;
}

.library-side-links {
  margin-top: 1rem;
}

.library-side-links a {
  color: var(--gold-bright) !important;
}

.library-mobile-toc {
  display: none;
}

.library-pagination {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 4rem;
  padding-top: 1.3rem;
  border-top: 1px solid var(--line);
}

.library-pagination a {
  color: var(--gold-bright);
  font: 600 1rem/1.4 Georgia, "Times New Roman", serif;
}

.library-pagination small {
  display: block;
  color: var(--quiet);
  font: 800 0.68rem Inter, ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-next {
  text-align: right;
}

.library-register-list,
.library-glossary-list {
  margin: 0;
  border-top: 1px solid var(--line);
}

.library-register-item {
  padding: 1.7rem 0 2rem;
  border-bottom: 1px solid var(--line);
}

.library-register-item[hidden],
.library-glossary-entry[hidden] {
  display: none;
}

.library-register-item h2 {
  max-width: 950px;
  margin: 0.65rem 0 1rem;
  font-size: clamp(1.3rem, 3vw, 1.65rem);
}

.library-register-details {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 1.5rem;
  margin-bottom: 0.8rem;
}

.library-register-details h3 {
  margin: 0 0 0.3rem;
  color: var(--gold);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-register-details p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.library-status {
  padding: 0.12rem 0.4rem;
  border: 1px solid currentColor !important;
}

.library-status--completed {
  color: #a6cea9;
}

.library-status--in-progress {
  color: #a9c6de;
}

.library-status--queued {
  color: #e1b880;
}

.library-glossary-search {
  display: block;
  max-width: 720px;
}

.library-alphabet {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 1.2rem 0;
}

.library-alphabet button {
  min-width: 2.1rem;
  padding: 0.32rem 0.45rem;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.library-alphabet button:hover,
.library-alphabet button.is-active {
  border-color: var(--gold);
  background: var(--gold);
  color: #171208;
}

.library-glossary-entry {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 2rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--line);
}

.library-glossary-entry dt {
  font: 600 1.14rem Georgia, "Times New Roman", serif;
}

.library-glossary-entry dd {
  margin: 0;
}

.library-glossary-entry p {
  margin: 0 0 0.45rem;
  color: var(--muted);
}

.library-glossary-entry .library-aliases {
  color: var(--quiet);
  font-size: 0.82rem;
}

@media (max-width: 900px) {
  .library-card-grid,
  .library-tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .library-reader-grid {
    display: block;
  }

  .library-toc {
    display: none;
  }

  .library-mobile-toc {
    display: block;
    margin-bottom: 1.5rem;
    padding: 0.8rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
  }

  .library-mobile-toc summary {
    cursor: pointer;
    font-weight: 800;
  }

  .library-mobile-toc nav {
    display: grid;
    max-height: 24rem;
    margin-top: 0.8rem;
    overflow-y: auto;
  }

  .library-mobile-toc a {
    padding: 0.45rem 0;
    border-top: 1px solid var(--line-soft);
    color: var(--muted);
    font-size: 0.84rem;
  }

  .library-filter-row {
    grid-template-columns: minmax(0, 1fr) 170px 170px;
  }
}

@media (max-width: 680px) {
  .library-search-controls,
  .library-filter-row,
  .library-heading,
  .library-register-details,
  .library-glossary-entry {
    grid-template-columns: 1fr;
  }

  .library-search-results,
  .library-card-grid,
  .library-tool-grid {
    grid-template-columns: 1fr;
  }

  .library-card {
    min-height: 250px;
  }

  .library-book-row {
    grid-template-columns: 2.2rem minmax(0, 1fr);
  }

  .library-open {
    display: none;
  }

  .library-pagination {
    grid-template-columns: 1fr;
  }

  .library-next {
    text-align: left;
  }

  .library-glossary-entry {
    gap: 0.35rem;
  }
}

@media print {
  .library-toc,
  .library-mobile-toc,
  .library-pagination {
    display: none;
  }

  .library-reader-grid {
    display: block;
  }
}
