/* Library, new look. Loaded after the page's older styles; html.nl scopes it. */
/* The older parts of this page read --theme-* (set inline from the classic
   theme). In the new look they follow Daylight / Night instead. */
html.nl {
  --theme-background: var(--page) !important; --theme-text: var(--ink) !important;
  --theme-muted: var(--muted) !important; --theme-panel: var(--surface) !important;
  --theme-border: var(--line) !important; --theme-accent: var(--brand) !important;
  --theme-selected: var(--brand) !important; --theme-shelf: var(--surface-2) !important;
  --theme-book: var(--brand-soft) !important; --theme-book-hover: var(--brand-soft) !important;
}
html.nl, html.nl body { background: var(--page); color: var(--text); font: 400 16px/1.6 var(--ui); }
html.nl #Matrix { display: none !important; }
/* The older styles lock html and body to one screen (height 100%, overflow hidden).
   The new look is a normal page, so let it scroll with a finger, a wheel or the keys. */
html.nl, html.nl body { height: auto; min-height: 100%; overflow: visible; }
html.nl body:has(#reader-view.visible), html.nl body:has(#book-preview.visible) { overflow: hidden; }

/* the page scrolls as a normal page; the old layout was a fixed box */
html.nl #library { position: static; inset: auto; display: flex; flex-direction: column; align-items: stretch; overflow: visible; padding: 0 0 40px; min-height: 100vh; font-family: var(--ui); } /* the old page set a system font on the whole box */
html.nl #library-content { overflow: visible; display: block; min-height: 0; }
html.nl #library-content, html.nl #recent-articles { width: min(1180px, calc(100% - 48px)); margin-inline: auto; flex: none; }
@media (max-width: 900px) { html.nl #library-content, html.nl #recent-articles { width: calc(100% - 32px); } }
/* The page's older inline styles still style bare buttons; the new parts opt out. */
html.nl #library .book-card, html.nl #library .item-card, html.nl #library .lib-tab, html.nl #library .chip, html.nl #library .icon-btn, html.nl #library .btn { font-family: var(--ui); letter-spacing: 0; text-transform: none; }
html.nl #library .book-card:hover, html.nl #library .lib-tab:hover { border-color: transparent; }
html.nl .topbar.library-nav { position: sticky; top: 0; width: 100%; margin: 0; padding: 0; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; box-shadow: none; background: rgba(var(--page-rgb), .88); background: color-mix(in srgb, var(--page) 88%, transparent); display: block; }

.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 34px 0 18px; }
.lib-head h1 { margin: 0; color: var(--ink); font: 700 34px/1.1 var(--ui); letter-spacing: -.02em; }
.lib-search { position: relative; flex: 0 1 430px; }
.lib-search svg { position: absolute; left: 14px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.lib-search input { width: 100%; height: 46px; padding: 0 16px 0 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); font: 400 15.5px var(--ui); }
.lib-search input::placeholder { color: var(--muted); }
.lib-search input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }

/* continue reading */
.continue { display: flex; align-items: center; gap: 22px; padding: 18px 22px; margin: 4px 0 26px; }
.continue .cover { width: 62px; flex: none; padding: 7px 6px 6px 10px; border-radius: 5px; }
.continue .cover-title { font-size: 9.5px; -webkit-line-clamp: 4; }
.continue .cover-author { font-size: 7px; }
.continue-body { flex: 1; min-width: 0; }
.continue-label { margin: 0 0 2px; color: var(--muted); font-size: 12.5px; letter-spacing: .12em; text-transform: uppercase; }
.continue-title { margin: 0; color: var(--ink); font: 600 19px/1.3 var(--ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-meta { margin: 2px 0 9px; color: var(--muted); font-size: 14px; }
.meter { display: block; width: min(260px, 100%); height: 5px; border-radius: 5px; background: var(--line); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--brand); border-radius: 5px; }

/* controls: type tabs, language chips, sort */
html.nl .catalog-controls.lib-controls { display: block; width: min(1180px, calc(100% - 48px)); max-width: none; margin: 0 auto; padding: 0; border: 0; background: none; box-shadow: none; }
@media (max-width: 900px) { html.nl .catalog-controls.lib-controls { width: calc(100% - 32px); } }
.lib-types { display: flex; gap: 4px; padding: 4px; margin: 0 0 14px; width: max-content; max-width: 100%; overflow-x: auto; border-radius: 12px; background: var(--surface-2); scrollbar-width: none; }
.lib-types::-webkit-scrollbar { display: none; }
.lib-tab { flex: none; min-height: 36px; padding: 0 15px; border: 0; border-radius: 9px; background: transparent; color: var(--text); font: 500 14.5px var(--ui); cursor: pointer; white-space: nowrap; }
.lib-tab:hover { color: var(--brand); }
.lib-tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(36, 27, 61, .12); font-weight: 600; }
.lib-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.lib-langs { display: flex; gap: 8px; flex: 1 1 auto; min-width: 0; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.lib-langs::-webkit-scrollbar { display: none; }
.lib-langs .chip { flex: none; }
.lib-langs .chip[lang="ar"] { font-family: var(--arabic); }
.lib-sort { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
html.nl .lib-sort select { height: 36px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: 400 14.5px var(--ui); }

/* the full language list, behind "More" */
html.nl #language-menu { position: relative; flex: none; }
html.nl #language-menu > summary { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font: 400 14.5px var(--ui); cursor: pointer; list-style: none; }
html.nl #language-menu > summary::-webkit-details-marker { display: none; }
html.nl #language-menu > summary::after { content: "▾"; font-size: 11px; color: var(--muted); }
html.nl #language-menu #language-summary { display: none; }
html.nl #language-menu .filter-options { position: absolute; z-index: 30; right: 0; top: calc(100% + 6px); width: 240px; max-height: 340px; overflow: auto; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
html.nl #language-menu .filter-option { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; color: var(--text); font: 400 14.5px var(--ui); text-transform: none; letter-spacing: 0; cursor: pointer; }
html.nl #language-menu .filter-option:hover { background: var(--surface-2); }
html.nl #language-menu input { accent-color: var(--brand); }
.lib-hidden-controls { display: none !important; }

.lib-actions { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 14px auto 0; font-size: 14.5px; }
.lib-actions a { color: var(--brand); text-decoration: none; font-weight: 500; }
.lib-actions a:hover { text-decoration: underline; }
html.nl #private-library-notice { margin: 12px auto; padding: 16px 18px; border: 1px solid var(--line) !important; border-radius: var(--radius) !important; background: var(--surface); }
html.nl #private-library-notice h2 { margin: 0 0 4px; color: var(--ink); font-size: 18px; }

/* sections and grids */
.lib-section { margin: 30px 0 0; }
.lib-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.lib-section-head h2 { margin: 0; color: var(--ink); font: 600 19px/1.3 var(--ui); }
.lib-section-head span { color: var(--muted); font-size: 14px; }
.shelf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 26px 20px; }
.book-card { display: flex; flex-direction: column; gap: 8px; padding: 0; border: 0; background: none; color: inherit; text-align: left; cursor: pointer; font: inherit; }
.book-card:hover .cover { transform: translateY(-3px); box-shadow: 0 10px 26px rgba(36, 27, 61, .22); }
.cover { position: relative; display: flex; flex-direction: column; justify-content: space-between; aspect-ratio: .72; width: 100%; padding: 14px 12px; border-radius: 7px; color: #FFF; overflow: hidden; box-shadow: 0 2px 6px rgba(36, 27, 61, .16); transition: transform .15s, box-shadow .15s; }
.cover::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px; background: rgba(0, 0, 0, .16); }
.cover-title { position: relative; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; font: 600 15px/1.25 var(--read); overflow-wrap: anywhere; }
.cover-author { position: relative; font: 500 11px/1.3 var(--ui); opacity: .82; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-name { color: var(--ink); font: 600 14.5px/1.3 var(--ui); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-sub { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 13px; line-height: 1.3; }
.badge { display: inline-flex; align-items: center; min-height: 20px; padding: 0 7px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); font-size: 11.5px; font-weight: 600; }
.book-card .meter { width: 100%; height: 4px; }
.book-progress { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; line-height: 1.2; }
.book-progress .meter { flex: 1; min-width: 0; }
.continue-arrow { display: none; flex: none; color: var(--brand); }
.continue-arrow svg { width: 22px; height: 22px; }

/* Fresh today: news and Wikipedia beside the classics (and the extra search row) */
html.nl { --fresh-tag-bg: #E4F3E8; --fresh-tag-ink: #2E6B42; }
html.nl[data-style="night"] { --fresh-tag-bg: rgba(126, 211, 151, .14); --fresh-tag-ink: #A6E3B8; }
.lib-section-head .fresh-tag { display: inline-flex; align-items: center; min-height: 22px; margin-left: 6px; padding: 0 8px; border-radius: 6px; background: var(--fresh-tag-bg); color: var(--fresh-tag-ink); font: 600 12px/1 var(--ui); vertical-align: 2px; }
.fresh-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.fresh-card { display: flex; flex-direction: column; gap: 8px; min-height: 112px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; text-decoration: none; transition: border-color .15s; }
a.fresh-card:hover { border-color: var(--brand); }
.fresh-kind { color: var(--muted); font-size: 12.5px; line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fresh-title { color: var(--ink); font: 500 16.5px/1.42 var(--read); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.fresh-title:lang(ar) { font-family: var(--arabic); }
.fresh-note { margin-top: -2px; color: var(--muted); font-size: 14px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fresh-note:lang(ar) { font-family: var(--arabic); }
.fresh-search .fresh-title { color: var(--brand); font: 600 15.5px/1.4 var(--ui); }
.fresh-card.is-loading .fresh-kind, .fresh-card.is-loading .fresh-title { display: block; border-radius: 6px; background: var(--surface-2); }
.fresh-card.is-loading .fresh-kind { width: 45%; height: 12px; }
.fresh-card.is-loading .fresh-title { width: 88%; height: 44px; }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 14px; }
/* a title with one very long word (a web address) must wrap, not push the page sideways */
.item-card { min-width: 0; word-break: break-word; overflow-wrap: anywhere; display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: inherit; text-align: left; cursor: pointer; font: inherit; transition: border-color .15s; }
.item-card:hover { border-color: var(--brand); }
.item-kind { color: var(--muted); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.item-title { color: var(--ink); font: 600 16px/1.35 var(--ui); }
.item-detail { color: var(--muted); font-size: 14px; line-height: 1.4; }
.item-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; color: var(--muted); font-size: 13px; }
.item-foot .meter { flex: 1; width: auto; height: 4px; }
.item-go { color: var(--brand); font-weight: 600; font-size: 14px; white-space: nowrap; }

.lib-empty { padding: 26px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; }
.lib-empty a { color: var(--brand); }
.lib-more { display: flex; justify-content: center; margin: 26px 0 0; }
.lib-status { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.lib-note { max-width: 640px; margin: 22px 0 0; color: var(--muted); font-size: 15px; line-height: 1.55; }
.lib-note a { color: var(--brand); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* recently read articles (older component, new skin) */
html.nl #recent-articles { margin: 26px auto 0; padding: 0; border: 0; background: none; }
html.nl .recent-articles-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; color: var(--ink); font: 600 17px var(--ui); text-transform: none; letter-spacing: 0; }
html.nl .recent-article-navigation button { min-height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--text); font: 500 13.5px var(--ui); cursor: pointer; }
html.nl .recent-article { padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font-family: var(--ui); }
html.nl .recent-article strong { color: var(--ink); font: 600 15px/1.35 var(--read); }
html.nl .recent-article small { color: var(--muted); font-size: 12.5px; font-family: var(--ui); line-height: 1.4; }
html.nl .recent-article-actions button, html.nl .recent-article-actions a { border-color: var(--line); color: var(--brand); background: none; font: 500 13px var(--ui); }

/* the reader opens on top of the library */
html.nl .reader-toolbar { background: var(--page); border-bottom: 1px solid var(--line); }
/* the new reader has its own "Library" back link, so this bar steps aside while it shows */
html.nl.reader-own-bar .reader-toolbar { display: none; }
html.nl #back-to-library { min-width: 0; height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: 600 14px var(--ui); letter-spacing: 0; text-transform: none; }

/* book details window */
html.nl #book-preview { background: rgba(var(--page-rgb), .7); background: color-mix(in srgb, var(--page) 70%, transparent); }
html.nl .book-preview-shell { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); font-family: var(--ui); }
html.nl .book-preview-left { background: var(--surface-2); border-color: var(--line); }
html.nl .book-preview-cover { border: 0; border-radius: 8px; background: var(--preview-cover, #2B1F4F); color: #FFF; font: 600 17px/1.3 var(--read); box-shadow: 0 8px 22px rgba(36, 27, 61, .25); }
html.nl #preview-author { color: var(--ink); font: 600 15px var(--ui); text-align: center; }
html.nl .preview-progress { color: var(--muted); font: 400 14px var(--ui); text-align: center; }
html.nl .preview-buttons button { min-height: 42px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); font: 600 14.5px var(--ui); text-transform: none; letter-spacing: 0; cursor: pointer; }
html.nl #preview-open { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
html.nl .preview-heading { color: var(--ink); font: 600 20px var(--ui); text-transform: none; letter-spacing: 0; }
html.nl .preview-subheading, html.nl .preview-empty { color: var(--muted); font: 400 14.5px/1.5 var(--ui); }
html.nl .preview-note { border-color: var(--line); border-radius: 10px; background: var(--page); color: var(--text); font-family: var(--ui); }
html.nl .preview-note-quote { font-family: var(--read); }

html.nl #language-experimental-dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); font-family: var(--ui); box-shadow: var(--shadow); }
html.nl #language-experimental-dialog h2 { color: var(--ink); font-size: 19px; }
html.nl #language-experimental-dialog button { border-radius: 10px; background: var(--surface); color: var(--ink); border-color: var(--line); font-weight: 600; }
html.nl #language-experimental-dialog button[value="continue"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

@media (max-width: 900px) {
  .lib-head { flex-direction: column; align-items: stretch; gap: 14px; padding: 22px 0 12px; }
  .lib-head h1 { font-size: 28px; }
  .lib-search { flex: none; }
  .continue { gap: 14px; padding: 14px 16px; }
  .continue .btn { display: none; }
  .continue-arrow { display: flex; }
  .fresh-grid { display: flex; gap: 12px; margin: 0 -16px; padding: 2px 16px 6px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding-inline: 16px; scrollbar-width: none; }
  .fresh-grid::-webkit-scrollbar { display: none; }
  .fresh-card { flex: 0 0 80%; min-height: 104px; padding: 14px 16px; scroll-snap-align: start; }
  .fresh > .lib-section-head > span, .search-more > .lib-section-head > span { display: none; }
  .lib-row { flex-wrap: wrap; row-gap: 10px; }
  .lib-langs { flex: 1 1 100%; margin: 0 -16px; padding: 2px 16px 4px; }
  .lib-sort { margin-left: auto; }
  .lib-sort span { display: none; }
  .shelf-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 12px; }
  .cover { padding: 10px 8px 9px 12px; border-radius: 5px; }
  .cover::before { width: 5px; }
  .cover-title { font-size: 12px; line-height: 1.22; }
  .cover-author { font-size: 9px; }
  .book-name { font-size: 13px; }
  .book-sub { font-size: 12px; }
  .item-grid { grid-template-columns: minmax(0, 1fr); }
}
