:root {
  color-scheme: light;
  --paper: #fcfbf8;
  --card: #fff;
  --ink: #082958;
  --muted: #46566a;
  --line: #d9e1e8;
  --panel: #f3f1ec;
  --accent: #eca879;
  --navy: #082958;
}
:root[data-library-theme="dark"] {
  color-scheme: dark;
  --paper: #101722;
  --card: #172232;
  --ink: #f1f4fa;
  --muted: #becbdd;
  --line: #344a66;
  --panel: #172232;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  min-height: 100vh; display: flex; flex-direction: column; margin: 0;
  color: var(--ink); background: var(--paper); font: 1rem/1.8 Dubai, "Segoe UI", Tahoma, sans-serif;
}
a { color: inherit; text-underline-offset: .25em; }
:is(a,button,input,select):focus-visible { outline: 2px solid #bb7928; outline-offset: 3px; }
.library-header, footer {
  display: flex; align-items: center; justify-content: space-between; gap: .85rem;
  padding: .85rem max(1rem, calc((100% - 74rem) / 2)); background: var(--card);
  border-block-end: 1px solid var(--line);
}
.library-header { min-height: 78px; background: var(--paper); padding-block: .5rem; }
.library-header :is(a,button) { display: inline-flex; align-items: center; gap: .55rem; text-decoration: none; font-weight: bold; }
.library-header svg, .library-kicker svg, .library-action svg { width: 1.1rem; height: 1.1rem; flex: none; }
.library-brand { min-width: 0; line-height: 1.45; }
.library-brand img { object-fit: contain; flex: none; }
.library-header-actions { display: flex; align-items: center; gap: .5rem; }
.library-nav, .library-theme {
  min-height: 46px; justify-content: center; padding: 0 .75rem; border: 1px solid var(--line);
  border-radius: .55rem; color: var(--ink); background: transparent; white-space: nowrap;
}
.library-theme { min-width: 46px; cursor: pointer; }
.library-header-actions :is(a,button):hover, .library-nav[aria-current="page"] { background: var(--panel); }
.library-theme > span { display: grid; place-items: center; }
.library-theme [data-light-icon], [data-library-theme="dark"] .library-theme [data-dark-icon] { display: none; }
[data-library-theme="dark"] .library-theme [data-light-icon] { display: grid; }
main { width: min(100%, 76rem); flex: 1; margin-inline: auto; padding: clamp(1rem, 3vw, 2.5rem) 1rem; }
h1, h2, h3, p { margin: 0; }
h1 { margin-block: .2rem .65rem; font-size: clamp(2.2rem, 6vw, 4.25rem); line-height: 1.24; overflow-wrap: anywhere; }
.library-kicker { display: inline-flex; align-items: center; gap: .55rem; color: var(--muted); font-size: .87rem; font-weight: bold; }
.library-description { max-width: 64ch; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.library-hero {
  display: flex; gap: 1rem; align-items: center; justify-content: space-between;
  padding: clamp(.8rem, 3vw, 1.6rem); border: 1px solid var(--line); border-radius: .75rem;
  background: var(--panel);
}
.library-hero h1 { font-size: clamp(1.65rem, 4vw, 2.85rem); margin-block: .05rem .18rem; }
.library-hero .library-description { font-size: clamp(.78rem, 2.8vw, .95rem); }
.library-action, .library-secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .48rem .8rem; border-radius: .7rem; font-weight: bold; text-decoration: none;
}
.library-action { border: 1px solid transparent; background: var(--navy); color: #fffefa; font: inherit; font-weight: bold; }
[data-library-theme="dark"] .library-action { background: var(--accent); color: #172232; }
button.library-action, .library-filter-panel summary { cursor: pointer; }
.library-secondary { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
button.library-secondary { cursor: pointer; font: inherit; font-weight: bold; }
.library-secondary svg { width: 1rem; height: 1rem; flex: none; }
.library-results { padding-block: 1.25rem .75rem; }
.library-tools { position: relative; display: flex; align-items: center; gap: .5rem; margin-block: 1rem .25rem; }
.library-search-bar { flex: 1; display: flex; gap: .5rem; min-width: 0; }
.library-search-bar input {
  flex: 1; min-width: 0; width: 100%; min-height: 44px; padding: .4rem .65rem;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: .65rem; font: inherit;
}
.library-filter-panel summary { list-style: none; }
.library-filter-panel summary::-webkit-details-marker { display: none; }
.library-filter-panel[open] summary { border-color: var(--accent); background: var(--panel); }
.library-filters {
  position: absolute; z-index: 2; inset: calc(100% + .4rem) 0 auto;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .7rem;
  padding: .85rem; border: 1px solid var(--line); border-radius: .75rem; background: var(--card);
  box-shadow: 0 12px 32px #08162c24;
}
.library-filter-panel:not([open]) .library-filters { display: none; }
.library-filters label { display: grid; gap: .3rem; color: var(--muted); font-size: .8rem; font-weight: bold; }
.library-filters :is(select,input) {
  width: 100%; min-width: 0; min-height: 44px; padding: .4rem .55rem; border: 1px solid var(--line);
  border-radius: .55rem; color: var(--ink); background: var(--panel); font: inherit; font-weight: normal;
}
.library-filter-actions { grid-column: 1 / -1; }
.library-filter-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .4rem; font-size: .83rem; }
.library-applied, .library-pagination { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-block-start: .9rem; }
.library-applied span { border-radius: 2rem; background: var(--panel); padding: .14rem .65rem; font-size: .82rem; }
.library-applied a { font-size: .82rem; }
.library-pagination { justify-content: center; }
.library-visually-hidden, .library-skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.library-skip:focus { position: absolute; inset: .3rem .3rem auto auto; z-index: 3; background: var(--card); padding: .45rem .7rem; }
.library-section-title { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block-end: .8rem; }
.library-section-title h2 { font-size: clamp(1.3rem, 3vw, 1.9rem); }
.library-section-title span { padding: .12rem .55rem; border-radius: 2rem; border: 1px solid var(--line); color: var(--muted); background: var(--card); font-size: .84rem; }
.library-index { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 12rem), 1fr)); gap: 1rem; }
.library-card {
  display: block; height: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: .95rem;
  background: var(--card); text-decoration: none;
}
.library-card:hover { border-color: #bc8a47; }
.library-cover-frame {
  position: relative; display: grid; place-items: center; overflow: hidden;
  aspect-ratio: 210 / 297; background: var(--panel); color: var(--ink);
}
.library-cover { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; }
.library-cover-placeholder { display: grid; justify-items: center; gap: .25rem; font-size: .8rem; font-weight: bold; }
.library-cover-placeholder svg { width: 3rem; height: 3rem; }
.library-counts { position: absolute; inset: 8px 8px auto; display: flex; flex-wrap: wrap; gap: .35rem; }
.library-counts > span {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 6px;
  background: #0a162ce8; color: #fff; font-size: .75rem; line-height: 1.4; white-space: nowrap;
}
.library-counts svg { width: 14px; height: 14px; }
.library-card-copy { padding: .85rem; overflow-wrap: anywhere; }
.library-card-subject { color: var(--muted); font-size: .73rem; font-weight: bold; }
.library-card-copy h3 { margin-block: .22rem .5rem; font-size: clamp(.75rem, 2.8vw, .95rem); line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.library-card-description {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  padding-block-start: .5rem; border-block-start: 1px solid var(--line); color: var(--muted); font-size: .81rem; line-height: 1.55;
}
.library-empty { display: grid; justify-items: center; gap: .32rem; padding: 2rem 1rem; border: 1px dashed var(--line); border-radius: 1rem; text-align: center; background: var(--card); }
.library-empty svg { width: 2rem; color: #b77e35; }
.library-empty p { color: var(--muted); }
.library-crumbs { display: flex; flex-wrap: wrap; gap: .4rem .85rem; color: var(--muted); margin-block-end: 1rem; }
.library-crumbs span::before { content: '‹'; margin-inline-end: .5rem; }
.library-book {
  display: grid; grid-template-columns: minmax(8rem, 15rem) minmax(0, 1fr); align-items: start;
  gap: clamp(1rem, 4vw, 2.5rem); padding: clamp(1rem, 4vw, 2.5rem);
  border: 1px solid var(--line); border-radius: 1.25rem; background: var(--card);
}
.library-book .library-cover-frame { border-radius: .8rem; }
.library-book h1 { font-size: clamp(1.45rem, 4vw, 2.65rem); }
.library-book-actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-block: .8rem; }
.library-book-description { border-block-start: 1px solid var(--line); margin-block-start: 1rem; padding-block-start: .85rem; }
.library-book-description h2 { font-size: 1.05rem; margin-block-end: .35rem; }
footer { border-block: 1px solid var(--line); border-block-end: 0; color: var(--muted); }
@media (max-width: 35rem) {
  .library-header { min-height: 62px; padding: .5rem .75rem; gap: .45rem; }
  .library-header-actions { gap: .3rem; }
  .library-header .library-brand { gap: .35rem; font-size: .8rem; }
  .library-brand img { width: 39px; height: 39px; }
  .library-nav, .library-theme { min-height: 44px; padding-inline: .45rem; font-size: .8rem; }
  .library-nav-current, .library-theme { min-width: 44px; }
  .library-nav-current span { display: none; }
  main { padding: .75rem; }
  .library-filters, .library-index { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-index { gap: .65rem; }
  .library-card-copy { padding: .65rem; }
  .library-card-copy h3 { font-size: .87rem; }
  .library-card-description { font-size: .76rem; }
  .library-counts { inset: 6px 6px auto; gap: .25rem; }
  .library-counts > span { font-size: .65rem; }
  .library-book { grid-template-columns: 1fr; }
  .library-book .library-cover-frame { width: min(54%, 10rem); justify-self: center; }
}
@media (max-width: 360px) {
  .library-card-copy { padding-inline: .4rem; }
  .library-card-copy h3 { font-size: .71rem; }
}
