/* ─── Library detail view (sidebar + PDF preview) ───────────────────────── */

/* When the detail view is open, collapse #site-main's vertical padding so the
   preview pane sits flush below the sticky header (its own height calc already
   reserves bottom slack via var(--preview-sticky-top) + 2rem). library.js's showLibView
   sets body.lib-detail-open together with the view switch. */
body.lib-detail-open #site-main {
  padding-top: 0;
  padding-bottom: 0;
}

#lib-detail-view:not(.hidden) {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  gap: 1rem;
  height: calc(100vh - var(--preview-sticky-top));   /* fixed height; the preview box's WIDTH tracks the
                                                         zoom factor and stays horizontally centred, the
                                                         PDF scrolls vertically inside the box */
  align-items: stretch;
}

@media (max-width: 767px) {
  /* :not(.hidden) so this beats the desktop #lib-detail-view:not(.hidden) rule
     (equal specificity → later source order wins). Plain #lib-detail-view loses
     the cascade and the desktop 2-col 17rem layout crushes the PDF to a sliver. */
  #lib-detail-view:not(.hidden) {
    grid-template-columns: minmax(0, 1fr);     /* single column (minmax(0,) lets it shrink) */
    grid-template-rows: auto minmax(0, 1fr);   /* compact sidebar, PDF fills the rest */
    align-items: stretch;                      /* override desktop align-items:start */
    gap: 0.6rem;
    height: calc(100vh - var(--preview-sticky-top));     /* fallback */
    height: calc(100dvh - var(--preview-sticky-top));    /* dvh: tracks mobile chrome */
    min-height: 0;
  }
}

/* ── Left sidebar ─────────────────────────────────────────────────────────── */

#lib-sidebar {
  position: sticky;            /* stays in view as the page scrolls; also anchors the download btn */
  top: var(--preview-sticky-top);
  align-self: start;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--preview-sticky-top));
  min-height: 0;
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.07);
  background: var(--reading-surface, #01040e);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

@media (max-width: 767px) {
  /* Roomy file selector. A DEFINITE height (not height:auto) is required so the
     flex:1 list fills it — with height:auto the flex-basis:0 list collapses to
     ~0 and only the header shows, which is why the selector looked tiny. */
  #lib-sidebar {
    height: clamp(9rem, 34vh, 18rem);
  }
}

/* Header. Line 1 is Back, Download, 2-up, in that order (the user's layout, 2026-09-15); line 2
   is the subject. Portrait phones put both lines on one bar (see the mobile block below),
   where the two lines' rules meet into one.
   Each rule is declared once, where it is drawn: a `border-bottom: 0` override would lose to the
   generated light-theme rule for the border it removes, which is more specific. */
#lib-sidebar-head { display: flex; flex-direction: column; flex-shrink: 0; }
.lib-sidebar-toprow {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding-right: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.lib-sidebar-subrow {
  display: flex;
  align-items: center;
  min-width: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.lib-sidebar-subrow > .lib-sidebar-subject-hdr { flex: 1 1 auto; min-width: 0; }
#lib-vote-slot { flex: none; margin-left: auto; padding-right: 0.25rem; }

/* Back button */
#lib-back-btn {
  display: flex;
  align-items: center;
  flex: none;
  gap: 0.5rem;
  padding: 0.6rem 0.25rem 0.6rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: rgb(148 163 184);
  border-radius: 1rem 0 0 0;
  transition: color 0.15s, background 0.15s;
  text-align: left;
  cursor: pointer;
}
#lib-back-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.04); }
#lib-back-btn:focus-visible { outline: 2px solid rgba(34, 211, 238, 0.7); outline-offset: -2px; }

/* Subject label: line 2 of the header, stays visible */
.lib-sidebar-subject-hdr {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.875rem;
  flex-shrink: 0;
}
.lib-sidebar-subject-dot {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 9999px;
  flex-shrink: 0;
}
/* One dot class per CATEGORY hue (IGCSE sky / A-Level violet / AP rose /
   Morning Reading amber) — matches the picker's --tab-rgb palette. */
.lib-sidebar-subject-dot--sky     { background: rgb(56 189 248);  box-shadow: 0 0 5px rgba(56, 189, 248, 0.55);  }
.lib-sidebar-subject-dot--violet  { background: rgb(167 139 250); box-shadow: 0 0 5px rgba(167, 139, 250, 0.55); }
.lib-sidebar-subject-dot--rose    { background: rgb(251 113 133); box-shadow: 0 0 5px rgba(251, 113, 133, 0.55); }
.lib-sidebar-subject-dot--amber   { background: rgb(251 191 36);  box-shadow: 0 0 5px rgba(251, 191, 36, 0.55);  }
.lib-sidebar-subject-dot--orange  { background: rgb(251 146 60);  box-shadow: 0 0 5px rgba(251, 146, 60, 0.55);  }
/* The lanes' current hues (library.html --tab-rgb / library.js theme): IGCSE sky, A-Level
   cyan, AP violet, Languages indigo, Morning Reading blue — the landing's own ramp. */
.lib-sidebar-subject-dot--cyan    { background: rgb(34 211 238);  box-shadow: 0 0 5px rgba(34, 211, 238, 0.55);  }
.lib-sidebar-subject-dot--indigo  { background: rgb(129 140 248); box-shadow: 0 0 5px rgba(129, 140, 248, 0.55); }
.lib-sidebar-subject-dot--blue    { background: rgb(96 165 250);  box-shadow: 0 0 5px rgba(96, 165, 250, 0.55);  }
.lib-sidebar-subject-dot--teal    { background: rgb(45 212 191);  box-shadow: 0 0 5px rgba(45, 212, 191, 0.55);  }
.lib-sidebar-subject-name {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgb(148 163 184);
}

/* Scrollable file list */
#lib-sidebar-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 0.375rem 0.375rem 0.75rem;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(56, 189, 248, 0.22) transparent;
}

#lib-sidebar-list::-webkit-scrollbar { width: 8px; }
#lib-sidebar-list::-webkit-scrollbar-track { background: transparent; }
#lib-sidebar-list::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.22);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
#lib-sidebar-list::-webkit-scrollbar-thumb:hover {
  background: rgba(56, 189, 248, 0.38);
  background-clip: padding-box;
  border: 2px solid transparent;
}

/* Year row with gradient divider line */
.lib-sidebar-year-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.5rem 0.2rem;
  margin-top: 0.375rem;
}
#lib-sidebar-list > .lib-sidebar-year-row:first-child { margin-top: 0; }

.lib-sidebar-year-label {
  padding: 0;
  flex-shrink: 0;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgb(100 116 139);
}
.lib-sidebar-year-divider {
  height: 1px;
  flex: 1;
  background: linear-gradient(to right, rgba(255, 255, 255, 0.13), transparent);
}

/* Session badge row */
.lib-sidebar-session-row {
  padding: 0.1rem 0.5rem 0.1rem;
}
.lib-sidebar-session-badge {
  display: inline-flex;
  height: 1.15rem;
  min-width: 1.15rem;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.04);
  padding: 0 0.25rem;
  font-size: 0.625rem;
  font-weight: 700;
  color: rgb(100 116 139);
  letter-spacing: 0.05em;
  cursor: default;
}

/* File buttons */
.lib-sidebar-item {
  display: block;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  color: rgb(148 163 184);
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
  box-shadow: inset 2px 0 0 transparent;
}
.lib-sidebar-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #e2e8f0;
  box-shadow: inset 2px 0 0 rgba(255, 255, 255, 0.10);
}
.lib-sidebar-item:focus-visible { outline: 2px solid rgba(34, 211, 238, 0.6); outline-offset: -2px; }

/* Active highlight per CATEGORY hue — background + color + left accent
   (same four-hue palette as the picker; sky doubles as the fallback). */
.lib-sidebar-item.is-active,
.lib-sidebar-item--sky.is-active     { background: rgba(56, 189, 248, 0.12);  color: rgb(125 211 252); box-shadow: inset 2px 0 0 rgba(56, 189, 248, 0.65);  }
.lib-sidebar-item--violet.is-active  { background: rgba(167, 139, 250, 0.12); color: rgb(196 181 253); box-shadow: inset 2px 0 0 rgba(167, 139, 250, 0.65); }
.lib-sidebar-item--rose.is-active    { background: rgba(251, 113, 133, 0.12); color: rgb(253 164 175); box-shadow: inset 2px 0 0 rgba(251, 113, 133, 0.65); }
.lib-sidebar-item--amber.is-active   { background: rgba(251, 191, 36, 0.12);  color: rgb(252 211 77);  box-shadow: inset 2px 0 0 rgba(251, 191, 36, 0.65);  }
.lib-sidebar-item--orange.is-active  { background: rgba(251, 146, 60, 0.12);  color: rgb(253 186 116); box-shadow: inset 2px 0 0 rgba(251, 146, 60, 0.65);  }
.lib-sidebar-item--cyan.is-active    { background: rgba(34, 211, 238, 0.12);  color: rgb(103 232 249); box-shadow: inset 2px 0 0 rgba(34, 211, 238, 0.65);  }
.lib-sidebar-item--indigo.is-active  { background: rgba(129, 140, 248, 0.12); color: rgb(165 180 252); box-shadow: inset 2px 0 0 rgba(129, 140, 248, 0.65); }
.lib-sidebar-item--blue.is-active    { background: rgba(96, 165, 250, 0.12);  color: rgb(147 197 253); box-shadow: inset 2px 0 0 rgba(96, 165, 250, 0.65);  }
.lib-sidebar-item--teal.is-active    { background: rgba(45, 212, 191, 0.12);  color: rgb(94 234 212);  box-shadow: inset 2px 0 0 rgba(45, 212, 191, 0.65);  }
html:not([data-theme="light"]) #lib-sidebar .lib-sidebar-item,
html:not([data-theme="light"]) #lib-sidebar .lib-sidebar-item:hover,
html:not([data-theme="light"]) #lib-back-btn:hover {
  background: var(--reading-surface, #01040e);
}

/* ── PDF preview pane ────────────────────────────────────────────────────── */

#lib-detail-preview {
  position: relative;          /* anchors pdf-loading-overlay & pdf-empty-state */
  flex: none;                  /* width is strictly the JS-set width below (no flex grow/shrink) */
  width: 100%;                 /* default = full column until JS (libLayoutBox) sizes it */
  min-width: min(240px, 100%); /* avoid an absurd sliver at very low zoom; = full width on tiny screens */
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--preview-sticky-top));   /* fixed height; width tracks the zoom, the PDF scrolls inside */
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;            /* clip to the rounded border; the inner scroll handles the PDF */
  background: var(--pane-bg);
  z-index: 3;                  /* paint over the sidebar when the box breaks out of its column on zoom */
  /* No transition: the box is re-laid-out by each render, which makes flex-basis/transform transitions
     stick at their start value — so width + position are applied instantly (correct end state). */
}

/* Centre each page within the stack (keeps a page narrower than the box centred). */
#lib-detail-preview .pdf-page-wrap {
  margin-left: auto;
  margin-right: auto;
}

/* When the box breaks out of its column and overlaps the sidebar (zoomed in), fade the file-list
   sidebar out so it doesn't peek behind the box; it returns on zoom-out. (JS toggles .lib-zoomed.)
   visibility is delayed so opacity can animate; the base #lib-sidebar transition fades it back in. */
#lib-sidebar { transition: opacity 0.15s ease; }
#lib-detail-view.lib-zoomed #lib-sidebar {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0s linear 0.15s;
}

@media (max-width: 767px) {
  #lib-detail-preview {       /* width stays JS-driven; don't force a flex-basis that overrides it */
    flex: none;
    min-height: 0;
  }
}

/* Centre the pages stack when JS sets an explicit px width narrower than container */
#lib-detail-preview .pdf-pages-stack {
  margin-left: auto;
  margin-right: auto;
}

/* Match the workspace preview-mode override: display:block allows the pages
   stack to centre via margin:auto (flex align-items:stretch would left-align it).
   Padding is zeroed so the rendered page can fill the full container height. */
#lib-detail-preview .pdf-viewport-scroll {
  display: block;
  flex: 1 1 0;                /* fill the bounded box */
  overflow-x: auto;          /* zoomed pages remain pannable inside the fixed mobile frame */
  overflow-y: auto;          /* the PDF scrolls VERTICALLY inside the box */
  scrollbar-gutter: stable;  /* reserve the vertical-scrollbar gutter so the width can't jump */
  overscroll-behavior: contain;
  padding: 0;
  background: linear-gradient(180deg, rgba(8, 30, 52, 0.52) 0%, rgba(2, 8, 20, 0.5) 100%);
}

/* Download and 2-up, beside the back button on line 1 of the header. They appear once a PDF has
   loaded (JS toggles [hidden] on the group); while hidden they keep their room, so nothing on the
   line moves when the PDF arrives. The explicit [hidden] rules are required: this sheet's
   `display` rules would otherwise outrank a plain `[hidden]` / Tailwind `.hidden` (the
   documented trap). */
.lib-detail-controls {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}
.lib-detail-controls[hidden] { visibility: hidden; }
#lib-edition-control {
  display: grid;
  gap: .25rem;
  padding: .4rem .6rem;
  font-size: .75rem;
  color: #e2e8f0;
}
#lib-edition-control[hidden] { display: none; }
#lib-edition-select {
  width: 100%;
  min-width: 0;
  padding: .35rem;
  border: 1px solid currentColor;
  border-radius: .5rem;
  background: var(--reading-surface, #01040e);
  color: inherit;
}
html[data-theme="light"] #lib-edition-control { color: rgb(44 63 88); }
.lib-ctrl-btn[hidden] { display: none; }
.lib-detail-controls .lib-download-btn { padding: 0.45rem 0.8rem 0.45rem 0.65rem; }
@media (orientation: landscape) and (max-height: 500px) {
  /* An 11rem sidebar: the pill keeps its colour and drops its word. */
  .lib-detail-controls .lib-download-btn { padding: 0.45rem; }
  .lib-detail-controls .lib-download-label { display: none; }
  #lib-back-btn { padding-left: 0.6rem; }
}

.lib-ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem;
  border-radius: 0.55rem;
  color: rgb(165 243 252);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.lib-ctrl-btn:hover {
  background: rgba(56, 189, 248, 0.14);
  color: #fff;
  border-color: rgba(56, 189, 248, 0.40);
}
.lib-ctrl-btn:focus-visible {
  outline: 2px solid rgba(34, 211, 238, 0.7);
  outline-offset: 2px;
}
.lib-ctrl-btn svg { width: 1.05rem; height: 1.05rem; display: block; }
/* The 1-up ⇄ 2-up toggle carries a word, and shows when the 2-up layout is on. */
.lib-ctrl-btn--text { gap: 0.3rem; padding: 0.3rem 0.5rem; font-size: 0.75rem; font-weight: 600; line-height: 1; }
#lib-layout-toggle[aria-pressed="true"] {
  color: #fff;
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.55);
}
html[data-theme="light"] #lib-layout-toggle[aria-pressed="true"] {
  color: rgb(8 51 68);
  background-color: rgb(8 145 178 / 0.16);
  border-color: rgb(8 145 178 / 0.5);
}

/* Download: the previewer's one primary action, so it is the one filled control, with a word
   on it. As a ghost icon among the toggles several visitors could not find it (2026-09-15).
   The gradient is the same in both themes: scripts/build_light_theme.py skips this selector
   (PLATE_HINTS), and the light rule below only softens the halo. */
.lib-download-btn {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem 0.45rem 0.7rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: linear-gradient(135deg, #22d3ee 0%, #38bdf8 50%, #818cf8 100%);
  color: #04121f;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  box-shadow:
    0 8px 22px -10px rgba(56, 189, 248, 0.9),
    0 0 0 3px rgba(34, 211, 238, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
  transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
/* A sheen that sweeps across once on hover. */
.lib-download-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.5) 50%, transparent 70%);
  transform: translateX(-130%);
  transition: transform 0.65s ease;
}
.lib-download-btn:hover {
  color: #04121f;
  filter: saturate(1.15) brightness(1.04);
  transform: translateY(-1px);
  box-shadow:
    0 12px 26px -10px rgba(56, 189, 248, 1),
    0 0 0 4px rgba(34, 211, 238, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.lib-download-btn:hover::after { transform: translateX(130%); }
.lib-download-btn:active { transform: translateY(0); filter: saturate(1.1) brightness(0.98); }
.lib-download-btn:focus-visible { outline: 2px solid #a5f3fc; outline-offset: 2px; }
.lib-download-btn svg { width: 1rem; height: 1rem; flex: none; display: block; stroke-width: 2.4; }
.lib-download-btn:hover svg { animation: lib-download-nudge 0.7s ease-in-out; }
@keyframes lib-download-nudge {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(2px); }
}
html[data-theme="light"] .lib-download-btn {
  border-color: rgba(8, 47, 73, 0.16);
  box-shadow:
    0 8px 20px -10px rgba(8, 145, 178, 0.75),
    0 0 0 3px rgba(8, 145, 178, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
@media (max-width: 767px) {
  /* The phone header is one short row: the pill keeps its colour and drops its word. */
  .lib-download-btn .lib-download-label { display: none; }
  .lib-download-btn { padding: 0.45rem; }
}
@media (prefers-reduced-motion: reduce) {
  .lib-download-btn, .lib-download-btn::after { transition: none; }
  .lib-download-btn:hover { transform: none; }
  .lib-download-btn:hover::after { transform: translateX(-130%); }
  .lib-download-btn:hover svg { animation: none; }
}

/* Preview column = the centring context for the PDF box. The box (JS-sized, flex:none) is
   horizontally centred; the zoom +/- rail is an absolute overlay positioned by JS. */
#lib-preview-col {
  position: relative;                 /* containing block for the absolute zoom rail */
  display: flex;
  justify-content: center;            /* horizontally centre the (JS-sized) box in the column */
  align-items: stretch;               /* box fills the column height */
  min-width: 0;
  min-height: 0;
}
/* Zoom +/- rail — an absolute overlay pinned to the vertical centre. JS (libLayoutBox) sets `left`
   so it rides the box's right edge, overlapping the box once it fills the column. The `right`
   default places it correctly during the first render, before JS runs (see libLayoutBox). */
.lib-zoom-controls {
  position: absolute;
  top: 0.6rem;                        /* TOP-right, beside the box (JS sets `left` to the box edge) */
  right: 0.4rem;                      /* default before JS sets `left` */
  z-index: 5;                         /* above the box content when it overlaps */
}
.lib-zoom-controls[hidden] { display: none; }
.lib-zoom-inner {
  display: flex;
  flex-direction: column;             /* + over - */
  gap: 0.3rem;
}

/* Full-viewport fallback also works on mobile browsers without the Fullscreen API. */
#lib-fullscreen-toggle { display: none; position: absolute; top: .6rem; left: .6rem; z-index: 6; min-height: 44px; background: var(--reading-surface); }
@media (max-width: 767px) { #lib-fullscreen-toggle { display: inline-flex; } }
body.lib-pdf-fullscreen { overflow: hidden; }
body.lib-pdf-fullscreen .z-content { z-index: 10000; animation: none; transform: none; }
#lib-preview-col.lib-pdf-fullscreen {
  position: fixed; inset: 0; z-index: 10000; width: 100%; height: 100vh; height: 100dvh;
  padding: calc(60px + env(safe-area-inset-top, 0px)) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--reading-surface); box-sizing: border-box;
}
#lib-preview-col.lib-pdf-fullscreen #lib-detail-preview {
  flex: 1; width: 100%; height: 100%; min-width: 0; transform: none; border-radius: 0;
}
#lib-preview-col.lib-pdf-fullscreen #lib-fullscreen-toggle { display: inline-flex; top: calc(.4rem + env(safe-area-inset-top, 0px)); left: calc(.6rem + env(safe-area-inset-left, 0px)); }
#lib-preview-col.lib-pdf-fullscreen .lib-zoom-controls { top: calc(65px + env(safe-area-inset-top, 0px)); }
/* The word-tap card (pinyin + English for a tapped HSK word) and the HSK reveal live on <body> at
   z-index 1000; above the full-screen PDF (10000) they must sit higher, or they open unseen. */
body.lib-pdf-fullscreen .annotation-help { z-index: 10001; }

/* ─── Landscape phones: side-by-side detail layout ─────────────────────── */
/* Tablets in landscape are ≥ 768 px tall, so max-height: 500px excludes them. */
@media (orientation: landscape) and (max-height: 500px) {
  #lib-detail-view:not(.hidden) {
    grid-template-columns: 11rem minmax(0, 1fr);
    grid-template-rows: 1fr;
    height: calc(100vh - var(--preview-sticky-top));
  }
  #lib-sidebar {
    height: calc(100vh - var(--preview-sticky-top));
  }
  #lib-detail-preview {
    height: calc(100vh - var(--preview-sticky-top));
  }
}

/* ─── Phones: roomier file selector, the header on one bar ─────────────── */
@media (max-width: 767px) {
  .lib-detail-controls .lib-download-btn { padding: 0.45rem; }
  /* Bigger tap targets for picking a file. */
  .lib-sidebar-item {
    padding: 0.6rem 0.7rem;
    font-size: 0.875rem;
  }
}
/* Both header lines share one bar: Back, Download, 2-up, then the subject label. That frees the
   row the stacked header uses, so the short file list gets more height. Not on a landscape phone,
   which can be under 768px wide too: its 11rem sidebar (the landscape block above) has no room
   for one bar and keeps the stacked header. `align-items: stretch` makes the two rules meet. */
@media (max-width: 767px) and (orientation: portrait), (max-width: 767px) and (min-height: 500.02px) {
  #lib-sidebar-head { flex-direction: row; align-items: stretch; flex-wrap: wrap; }
  /* grows: once the subject line (with the thumbs) wraps below, its rule spans the full width */
  .lib-sidebar-toprow { flex: 1 0 auto; padding-right: 0.25rem; }
  .lib-sidebar-subrow { flex: 1 1 auto; }
  #lib-edition-control { flex: 1 1 100%; min-width: 0; }
}

/* ── Teacher-password lock badge ──────────────────────────────────────────────
   Small padlock beside a gated row's title (unit tests, weekly vocabulary tests —
   web/doc_lock.py). Purely an affordance: the real refusal is the server's 403, and
   whether THIS visitor is unlocked is never rendered here, because /library HTML is
   cached identity-free by the micro-cache and the service worker.
   Amber rather than red — this is "for teachers", not "error". */
.lib-lock {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.5rem;
  color: rgb(251, 191, 36);
  background-color: rgba(251, 191, 36, 0.12);
}

/* ── "Download all": one category as a ZIP ─────────────────────────────────────────────
   Markup: partials/library_zip.html and _zipButton() in library.js; the click: library-zip.js.
   Beside each section title on /library and atop each category panel on /library/<subject>,
   in the category's own --accent-rgb like the title's icon chip. Only the outer <svg> is
   styled (web/svg_sprite.py can turn its shapes into <use> references CSS cannot reach). */
.lib-zip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  flex: none;
  height: 1.875rem;
  min-width: 1.875rem;
  padding: 0 0.4375rem;
  border: 1px solid rgba(var(--accent-rgb), 0.3);
  border-radius: 0.5625rem;
  background: transparent;
  color: rgb(var(--accent-rgb));
  font: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.lib-zip:hover {
  background: rgba(var(--accent-rgb), 0.14);
  border-color: rgba(var(--accent-rgb), 0.55);
  box-shadow: 0 0 18px -8px rgba(var(--accent-rgb), 0.7);
}
.lib-zip:focus-visible { outline: 2px solid rgba(var(--accent-rgb), 0.75); outline-offset: 2px; }
.lib-zip--labelled { padding: 0 0.75rem 0 0.5625rem; }
.lib-zip-label { white-space: nowrap; }
.lib-zip-glyph {
  position: relative;
  display: block;
  flex: none;
  width: 1.0625rem;
  height: 1.0625rem;
  overflow: hidden;
}
.lib-zip-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transition: transform 0.2s ease;
}
.lib-zip-svg + .lib-zip-svg { visibility: hidden; }
.lib-zip:hover .lib-zip-svg:first-child { transform: translateY(1.5px); }
/* While the archive starts: one stack of files drops out of the button and the next drops in. */
.lib-zip.is-busy .lib-zip-svg {
  visibility: visible;
  animation: lib-zip-drop 1.2s ease-in-out infinite both;
}
.lib-zip.is-busy .lib-zip-svg + .lib-zip-svg { animation-delay: -0.6s; }
/* 0-15% in, 15-45% resting, 45-60% out. The second glyph runs half a cycle behind, so each
   stack is still falling out while the next drops in and the button is never empty. */
@keyframes lib-zip-drop {
  0%   { transform: translateY(-105%); opacity: 0; }
  15%  { transform: translateY(0); opacity: 1; }
  45%  { transform: translateY(0); opacity: 1; }
  60%  { transform: translateY(105%); opacity: 0; }
  100% { transform: translateY(105%); opacity: 0; }
}
.lib-zip-note {
  min-width: 0;
  font-size: 0.75rem;
  line-height: 1.35;
  color: rgb(148, 163, 184);
}
.lib-zip-note:empty { display: none; }
.lib-zip-unlock {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: rgb(var(--accent-rgb));
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.libsub-zip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.875rem;
}
@media (prefers-reduced-motion: reduce) {
  .lib-zip-svg { transition: none; }
  .lib-zip.is-busy .lib-zip-svg { animation: none; }
  .lib-zip.is-busy .lib-zip-svg + .lib-zip-svg { visibility: hidden; }
  .lib-zip.is-busy { opacity: 0.6; }
}

/* ▼▼ LIGHT THEME — GENERATED by scripts/build_light_theme.py from the rules above. Do not edit by hand: run the builder. Hand tuning goes in 36-theme-light.css. ▼▼ */
html[data-theme="light"] #lib-sidebar{border-color:rgb(15 23 42/0.098);background:var(--reading-surface, rgb(252 252 253))}
html[data-theme="light"] .lib-sidebar-toprow{border-bottom-color:rgb(15 23 42/0.084)}
html[data-theme="light"] .lib-sidebar-subrow{border-bottom-color:rgb(15 23 42/0.084)}
html[data-theme="light"] #lib-back-btn{color:rgb(61 75 94)}
html[data-theme="light"] #lib-back-btn:hover{color:rgb(51 63 82);background-color:rgb(15 23 42/0.04)}
html[data-theme="light"] .lib-sidebar-subject-dot--sky{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--violet{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--rose{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--amber{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--orange{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--cyan{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--indigo{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--blue{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-dot--teal{box-shadow:none}
html[data-theme="light"] .lib-sidebar-subject-name{color:rgb(61 75 94)}
html[data-theme="light"] .lib-sidebar-year-label{color:rgb(87 101 122)}
html[data-theme="light"] .lib-sidebar-year-divider{background-image:linear-gradient(to right, rgb(15 23 42/0.13), transparent)}
html[data-theme="light"] .lib-sidebar-session-badge{border-color:rgb(15 23 42/0.14);background-color:rgb(15 23 42/0.04);color:rgb(87 101 122)}
html[data-theme="light"] .lib-sidebar-item{color:rgb(61 75 94)}
html[data-theme="light"] .lib-sidebar-item:hover{background-color:rgb(15 23 42/0.06);color:rgb(44 63 88);box-shadow:none}
html[data-theme="light"] .lib-sidebar-item.is-active,html[data-theme="light"] .lib-sidebar-item--sky.is-active{color:rgb(0 90 133);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--violet.is-active{color:rgb(28 0 132);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--rose.is-active{color:rgb(133 0 16);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--amber.is-active{color:rgb(126 96 0);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--orange.is-active{color:rgb(133 68 0);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--cyan.is-active{color:rgb(2 111 126);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--indigo.is-active{color:rgb(1 24 131);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--blue.is-active{color:rgb(0 63 133);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] .lib-sidebar-item--teal.is-active{color:rgb(12 114 98);box-shadow:inset 2px 0px rgb(15 23 42/0.2)}
html[data-theme="light"] #lib-detail-preview{border-color:rgb(15 23 42/0.112)}
html[data-theme="light"] #lib-detail-preview .pdf-viewport-scroll{background-image:linear-gradient(180deg, rgb(243 246 249/0.52) 0%, rgb(251 251 253/0.5) 100%)}
html[data-theme="light"] #lib-edition-control{color:rgb(44 63 88)}
html[data-theme="light"] #lib-edition-select{background:var(--reading-surface, rgb(252 252 253))}
html[data-theme="light"] .lib-ctrl-btn{color:rgb(1 111 124);background-color:rgb(15 23 42/0.05);border-color:rgb(15 23 42/0.14)}
html[data-theme="light"] .lib-ctrl-btn:hover{color:rgb(51 63 82)}
html[data-theme="light"] #lib-layout-toggle[aria-pressed="true"]{color:rgb(51 63 82)}
html[data-theme="light"] .lib-lock{color:rgb(127 92 0)}
html[data-theme="light"] .lib-zip{color:color-mix(in srgb,rgb(var(--accent-rgb)) 44%,#0f172a)}
html[data-theme="light"] .lib-zip:hover{box-shadow:0px 5px 18px -8px rgb(15 23 42/0.12)}
html[data-theme="light"] .lib-zip-note{color:rgb(61 75 94)}
html[data-theme="light"] .lib-zip-unlock{color:color-mix(in srgb,rgb(var(--accent-rgb)) 44%,#0f172a)}
/* ▲▲ LIGHT THEME END ▲▲ */
