:root {
  color-scheme: light;
  --navy: #1c2350;
  --indigo: #2b3a87;
  --gold: #d9a92e;
  --cream: #fbf8ef;
  --paper: #fffdf7;
  --ink: #1d2340;
  --muted: #62677d;
  --line: #e7dfcc;
  --green: #206d52;
  --shadow: 0 18px 45px -30px rgba(28, 35, 80, .48);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--cream); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: inherit; }
button, input { font: inherit; }
.skip-link { position: fixed; left: 14px; top: -70px; z-index: 100; padding: 12px 16px; background: #fff; border-radius: 10px; }
.skip-link:focus { top: 14px; }

.library-header { min-height: 74px; padding: 12px clamp(18px, 4vw, 52px); display: flex; align-items: center; justify-content: space-between; gap: 24px; background: var(--navy); color: #fff; }
.school-brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; font-family: Georgia, serif; font-size: 18px; font-weight: 700; white-space: nowrap; }
.school-brand img { object-fit: contain; }
.library-header nav { display: flex; align-items: center; gap: 8px; }
.library-header nav a { min-height: 44px; display: inline-flex; align-items: center; padding: 0 14px; color: #eef0ff; font-size: 14px; font-weight: 700; text-decoration: none; border-radius: 999px; }
.library-header nav a:hover, .library-header nav a:focus-visible { background: rgba(255,255,255,.12); outline: none; }

main { width: min(1220px, 100%); margin: 0 auto; padding: 0 clamp(18px, 4vw, 42px) 72px; }
.library-hero { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 30px; align-items: center; padding: clamp(52px, 8vw, 92px) 0 46px; overflow: hidden; }
.eyebrow { margin: 0 0 12px; color: #7d6222; font-size: 13px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
h1 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(42px, 8vw, 78px); line-height: .98; }
.hero-copy { max-width: 740px; margin: 22px 0 0; color: var(--muted); font-size: clamp(17px, 2vw, 20px); line-height: 1.65; }
.hero-mark { color: rgba(43, 58, 135, .1); font-family: Georgia, serif; font-size: clamp(100px, 18vw, 220px); line-height: 1; }

.library-tools { position: sticky; top: 0; z-index: 12; display: grid; grid-template-columns: minmax(240px, 1fr) minmax(0, 1.7fr); gap: 18px; align-items: end; padding: 16px; margin: 0 0 32px; background: rgba(251, 248, 239, .94); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.search-box { display: grid; gap: 7px; color: var(--navy); font-size: 13px; font-weight: 800; }
.search-box input { width: 100%; min-height: 48px; padding: 0 16px; color: var(--ink); background: #fff; border: 1px solid #cfd2df; border-radius: 13px; outline: none; }
.search-box input:focus { border-color: var(--indigo); box-shadow: 0 0 0 4px rgba(43, 58, 135, .12); }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-button { min-height: 44px; padding: 0 15px; color: var(--indigo); background: #fff; border: 1px solid #d4d7e7; border-radius: 999px; font-size: 13px; font-weight: 800; cursor: pointer; }
.filter-button[aria-pressed="true"] { color: #fff; background: var(--indigo); border-color: var(--indigo); }
.filter-button:focus-visible { outline: 3px solid rgba(217, 169, 46, .55); outline-offset: 2px; }
.library-status { min-height: 24px; margin: 0 0 16px; color: var(--muted); font-size: 14px; font-weight: 700; }

.library-section { margin-top: 42px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.section-heading h2 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: clamp(25px, 3vw, 34px); }
.section-heading span { color: var(--muted); font-size: 13px; font-weight: 700; white-space: nowrap; }
.book-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.book-card { min-width: 0; display: flex; flex-direction: column; overflow: hidden; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.book-cover-wrap { position: relative; display: grid; place-items: center; min-height: 270px; padding: 18px; background: linear-gradient(145deg, #eef0fb, #f8f1df); overflow: hidden; }
.book-cover { width: 100%; height: 250px; object-fit: contain; filter: drop-shadow(0 12px 15px rgba(28,35,80,.18)); }
.book-badge { position: absolute; top: 12px; left: 12px; padding: 7px 10px; color: var(--navy); background: rgba(255, 253, 247, .94); border: 1px solid rgba(28, 35, 80, .12); border-radius: 999px; font-size: 11px; font-weight: 900; letter-spacing: .05em; text-transform: uppercase; }
.book-body { flex: 1; display: flex; flex-direction: column; padding: 18px; }
.book-body h3 { margin: 0; color: var(--navy); font-family: Georgia, "Times New Roman", serif; font-size: 21px; line-height: 1.2; }
.book-subtitle { flex: 1; margin: 8px 0 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.book-meta { display: flex; gap: 8px; align-items: center; min-height: 20px; margin-bottom: 14px; color: #74798d; font-size: 12px; font-weight: 700; }
.open-book { min-height: 46px; display: inline-flex; align-items: center; justify-content: center; padding: 0 15px; color: #fff; background: var(--indigo); border-radius: 999px; font-size: 14px; font-weight: 800; text-decoration: none; }
.open-book:hover { background: var(--navy); }
.open-book:focus-visible { outline: 3px solid rgba(217, 169, 46, .65); outline-offset: 2px; }
.error-card { padding: 20px; color: #702626; background: #fff2f0; border: 1px solid #f0c9c4; border-radius: 16px; }

.library-footer { min-height: 190px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 35px 20px; color: #c7cae1; background: #15193a; text-align: center; }
.library-footer p { margin: 0; color: #fff; font-family: Georgia, serif; font-size: 18px; font-weight: 700; }
.library-footer a { min-height: 44px; display: inline-flex; align-items: center; color: #f4c64a; font-size: 14px; font-weight: 800; }

/* Reader */
.reader-page { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; background: #0f1331; color: #fff; overflow: hidden; }
.reader-header { min-width: 0; display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 16px; align-items: center; min-height: 76px; padding: 10px clamp(12px, 3vw, 28px); background: var(--navy); border-bottom: 1px solid rgba(255,255,255,.12); }
.reader-title { min-width: 0; display: flex; align-items: center; gap: 13px; }
.reader-title a { flex: none; min-height: 44px; display: inline-flex; align-items: center; padding: 0 14px; color: #f4c64a; border: 1px solid rgba(244,198,74,.4); border-radius: 999px; font-size: 13px; font-weight: 800; text-decoration: none; }
.reader-title-text { min-width: 0; }
.reader-title h1 { overflow: hidden; margin: 0; color: #fff; font-family: Georgia, serif; font-size: clamp(17px, 2.2vw, 25px); line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.reader-title p { overflow: hidden; margin: 4px 0 0; color: #c5c8dd; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.reader-actions { display: flex; gap: 8px; }
.reader-actions a { min-height: 44px; display: inline-flex; align-items: center; padding: 0 14px; color: #fff; border: 1px solid rgba(255,255,255,.25); border-radius: 999px; font-size: 13px; font-weight: 800; text-decoration: none; }

.reader-shell { min-height: 0; display: grid; grid-template-rows: auto 1fr; }
.reader-toolbar { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 62px; padding: 8px 12px; background: #171c41; border-bottom: 1px solid rgba(255,255,255,.09); }
.reader-toolbar button { min-width: 44px; min-height: 44px; padding: 0 13px; color: #fff; background: #252b5b; border: 1px solid rgba(255,255,255,.15); border-radius: 12px; font-weight: 800; cursor: pointer; }
.reader-toolbar button:disabled { opacity: .38; cursor: default; }
.reader-toolbar button:hover:not(:disabled) { background: #343b78; }
.reader-toolbar button:focus-visible, .reader-actions a:focus-visible, .reader-title a:focus-visible { outline: 3px solid #f4c64a; outline-offset: 2px; }
.page-control { display: flex; align-items: center; gap: 7px; color: #d7d9e7; font-size: 13px; font-weight: 800; }
.page-control input { width: 62px; min-height: 42px; padding: 0 7px; color: var(--navy); background: #fff; border: 0; border-radius: 10px; text-align: center; font-weight: 900; }
.toolbar-divider { width: 1px; height: 28px; background: rgba(255,255,255,.16); }
.zoom-label { min-width: 52px; color: #d7d9e7; font-size: 12px; font-weight: 800; text-align: center; }

.reader-stage { min-height: 0; overflow: auto; padding: clamp(16px, 3vw, 32px); background: radial-gradient(circle at 50% 0, #303765, #10142f 65%); overscroll-behavior: contain; }
.page-frame { position: relative; width: min(100%, 980px); min-height: 420px; display: grid; place-items: center; margin: 0 auto; }
#pdf-canvas { display: block; max-width: 100%; height: auto; background: #fff; box-shadow: 0 24px 65px rgba(0,0,0,.48); }
.reader-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; color: #eef0ff; text-align: center; pointer-events: none; }
.reader-message[hidden] { display: none; }
.loading-spinner { width: 46px; height: 46px; margin: 0 auto 16px; border: 4px solid rgba(255,255,255,.2); border-top-color: #f4c64a; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-tools { position: static; grid-template-columns: 1fr; }
  .hero-mark { position: absolute; right: -20px; z-index: -1; }
}

@media (max-width: 640px) {
  .library-header { align-items: flex-start; flex-direction: column; gap: 7px; }
  .library-header nav { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .library-header nav a { padding: 0 10px; white-space: nowrap; }
  .library-hero { padding-top: 42px; }
  .book-grid { grid-template-columns: 1fr; }
  .book-card { display: grid; grid-template-columns: 116px minmax(0, 1fr); }
  .book-cover-wrap { min-height: 185px; padding: 10px; }
  .book-cover { height: 165px; }
  .book-body { padding: 15px; }
  .book-body h3 { font-size: 19px; }
  .book-badge { top: 8px; left: 8px; max-width: 100px; padding: 5px 7px; font-size: 9px; }
  .section-heading { align-items: flex-start; flex-direction: column; gap: 5px; }
  .reader-page { overflow: auto; }
  .reader-header { position: sticky; top: 0; z-index: 20; grid-template-columns: 1fr; min-height: 0; padding: 9px 10px; }
  .reader-title { gap: 8px; }
  .reader-title a { min-height: 40px; padding: 0 10px; }
  .reader-title h1 { font-size: 17px; }
  .reader-title p { display: none; }
  .reader-actions { display: none; }
  .reader-toolbar { position: sticky; top: 58px; z-index: 19; display: grid; grid-template-columns: auto minmax(92px, 1fr) auto auto auto; gap: 5px; padding: 7px 8px; }
  .reader-toolbar button { min-width: 42px; padding: 0 10px; }
  .reader-toolbar .wide-label, .toolbar-divider, .zoom-label { display: none; }
  #zoom-out, #zoom-in { display: inline-block; }
  .page-control { gap: 5px; }
  .page-control input { width: 52px; }
  .reader-stage { min-height: calc(100vh - 118px); padding: 12px 8px 28px; }
  .page-frame { min-height: 320px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .loading-spinner { animation-duration: 1.8s; }
}
