/* The Library of Alexandria */
.lib-main { padding: 0 0 2.4rem; }
.lib-app { width: 100%; }
.lib-wrap { width: min(100% - 1.6rem, var(--wide)); margin-inline: auto; }

.lib-hero {
  background:
    radial-gradient(circle at 50% -20%, rgba(212, 175, 55, 0.22), transparent 60%),
    linear-gradient(180deg, var(--red-deep), #2e0b0b);
  color: var(--parchment);
  border-bottom: 1px solid var(--gold);
  padding: 2.2rem 0 2rem;
  text-align: center;
}
.lib-hero-inner { width: min(100% - 1.6rem, 46rem); margin-inline: auto; }
.lib-kicker { margin: 0; font-family: var(--display); font-size: 0.7rem; letter-spacing: 0.3em; text-transform: uppercase; color: var(--gold-bright); }
.lib-hero h1 { margin: 0.35rem 0 0.4rem; font-family: var(--display); font-weight: 700; font-size: clamp(1.6rem, 5vw, 2.5rem); letter-spacing: 0.06em; color: #f8e9c4; }
.lib-tag { margin: 0 auto; max-width: 38rem; color: #f0d9a8; font-size: 1.1rem; }
.lib-member { margin-top: 1rem; display: flex; gap: 0.6rem; justify-content: center; align-items: center; flex-wrap: wrap; font-size: 1rem; }
.lib-member .btn { padding: 0.45rem 1rem; }
.btn-ghost { background: transparent; border: 1px solid var(--gold-bright); color: var(--gold-bright); }
.lib-linkbtn { background: none; border: 0; padding: 0; color: var(--gold-bright); font: inherit; text-decoration: underline; cursor: pointer; }

.lib-search { margin: 1.2rem auto 0; max-width: 34rem; position: relative; }
.lib-search input {
  width: 100%; padding: 0.7rem 0.95rem; font: inherit; font-size: 1.05rem;
  border: 1px solid var(--gold); background: #fff8e8; color: var(--ink); border-radius: 2px;
}

.lib-section { margin-top: 1.8rem; }
.lib-section h2 {
  font-family: var(--display); font-size: 0.95rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--red); margin: 0 0 0.75rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--rule);
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap;
}
.lib-section h2 small { font-family: var(--serif); text-transform: none; letter-spacing: 0; color: var(--muted); font-size: 0.95rem; }

.lib-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1.4rem; }
.lib-chip {
  font: inherit; font-size: 0.95rem; padding: 0.3rem 0.75rem; border: 1px solid var(--card-edge);
  background: var(--card); color: var(--ink-soft); cursor: pointer; border-radius: 999px;
}
.lib-chip[aria-pressed="true"] { background: var(--red); color: #f8e9c4; border-color: var(--red); }
.lib-toolbar .lib-sep { flex: 1; }

.lib-shelf { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(14rem, 18rem); gap: 0.9rem; overflow-x: auto; padding-bottom: 0.5rem; }
.lib-book {
  display: grid; gap: 0.25rem; align-content: start; padding: 0.95rem 1rem 1rem; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--card-edge); border-left: 4px solid var(--red); box-shadow: 0 4px 14px var(--shadow);
}
.lib-book:hover { border-color: var(--gold); color: var(--ink); }
.lib-book .t { font-weight: 600; font-size: 1.05rem; line-height: 1.25; }
.lib-book .a { color: var(--muted); font-size: 0.95rem; }
.lib-book .m { color: var(--gold); font-size: 0.85rem; font-family: var(--display); letter-spacing: 0.08em; text-transform: uppercase; }
.lib-bar { height: 3px; background: var(--card-edge); margin-top: 0.4rem; }
.lib-bar i { display: block; height: 100%; background: var(--gold); }

.lib-era { margin-top: 1.6rem; }
.lib-era h3 { font-family: var(--display); font-size: 0.85rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); margin: 0 0 0.6rem; }
.lib-authors { display: grid; gap: 0.6rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.lib-author {
  display: flex; justify-content: space-between; gap: 0.6rem; align-items: baseline; flex-wrap: wrap; padding: 0.65rem 0.85rem;
  background: var(--card); border: 1px solid var(--card-edge); text-decoration: none; color: var(--ink);
}
.lib-author:hover { border-color: var(--gold); color: var(--ink); }
.lib-author .n { font-weight: 600; }
.lib-author .d { color: var(--muted); font-size: 0.9rem; white-space: nowrap; margin-left: auto; }

.lib-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.lib-list a { display: block; padding: 0.7rem 0.9rem; background: var(--card); border: 1px solid var(--card-edge); text-decoration: none; color: var(--ink); }
.lib-list a:hover { border-color: var(--gold); }
.lib-list .t { font-weight: 600; }
.lib-list .s { color: var(--muted); font-size: 0.92rem; }

.lib-crumbs { margin: 1.2rem 0 0; font-size: 0.95rem; color: var(--muted); }
.lib-crumbs a { color: var(--red); }
.lib-head { margin: 0.4rem 0 0.2rem; font-family: var(--display); font-size: clamp(1.3rem, 4vw, 2rem); letter-spacing: 0.04em; color: var(--red-deep); }
.lib-sub { margin: 0; color: var(--muted); font-size: 1.05rem; }
.lib-prov { margin-top: 1rem; padding: 0.7rem 0.9rem; border: 1px dashed var(--rule); font-size: 0.92rem; color: var(--ink-soft); background: rgba(255, 248, 232, 0.6); }
.lib-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1rem; }
.lib-toc { counter-reset: none; list-style: none; padding: 0; margin: 0; columns: 1; }
.lib-toc li { break-inside: avoid; }
.lib-toc a { display: flex; gap: 0.7rem; padding: 0.42rem 0.2rem; border-bottom: 1px dotted var(--rule); text-decoration: none; color: var(--ink); }
.lib-toc a:hover { color: var(--red); }
.lib-toc .no { color: var(--gold); min-width: 2.2rem; text-align: right; font-variant-numeric: tabular-nums; }
.lib-toc .here { color: var(--red); font-weight: 600; }
@media (min-width: 900px) { .lib-toc.cols { columns: 2; column-gap: 2.2rem; } }
.lib-empty { color: var(--muted); font-style: italic; }

/* Reader */
body.lib-reading { background: var(--rd-bg, #fbf3e0); }
body.lib-reading .support-cta { display: none; }
.rd { --rd-size: 20px; color: var(--rd-ink); background: var(--rd-bg); min-height: 70vh; }
.rd.light { --rd-bg: #fffdf7; --rd-ink: #1c1410; --rd-muted: #6b5346; --rd-rule: #e6d6b0; --rd-bar: #fffaf0; }
.rd.sepia { --rd-bg: #f4e7c9; --rd-ink: #2b1d14; --rd-muted: #6b5346; --rd-rule: #d8c08c; --rd-bar: #efe0bd; }
.rd.dark { --rd-bg: #17120f; --rd-ink: #e9dcc2; --rd-muted: #b09c84; --rd-rule: #3a2e25; --rd-bar: #201914; }
body.lib-reading.t-light { --rd-bg: #fffdf7; }
body.lib-reading.t-sepia { --rd-bg: #f4e7c9; }
body.lib-reading.t-dark { --rd-bg: #17120f; }
body.lib-reading.t-dark .site-footer { opacity: 0.85; }
.rd-bar {
  position: sticky; top: 0; z-index: 5; background: var(--rd-bar); border-bottom: 1px solid var(--rd-rule);
  display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.8rem; color: var(--rd-ink);
}
.rd-bar .rd-title { flex: 1; min-width: 0; font-size: 0.95rem; line-height: 1.2; overflow: hidden; }
.rd-bar .rd-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rd-bar .rd-title span { display: block; color: var(--rd-muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rd-btn { font: inherit; font-size: 0.95rem; background: transparent; color: var(--rd-ink); border: 1px solid var(--rd-rule); padding: 0.32rem 0.65rem; cursor: pointer; border-radius: 3px; text-decoration: none; white-space: nowrap; }
.rd-btn:hover { border-color: var(--gold); color: var(--rd-ink); }
.rd-progress { position: absolute; left: 0; bottom: -1px; height: 2px; background: var(--gold); width: 0; }
.rd-panel { position: absolute; right: 0.6rem; top: calc(100% + 6px); background: var(--rd-bar); border: 1px solid var(--rd-rule); padding: 0.8rem; width: 17rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: grid; gap: 0.7rem; }
.rd-panel[hidden] { display: none; }
.rd-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.rd-row .lbl { color: var(--rd-muted); font-size: 0.9rem; }
.rd-swatch { width: 2.3rem; height: 2.3rem; border-radius: 50%; border: 2px solid var(--rd-rule); cursor: pointer; font: inherit; font-size: 0.8rem; }
.rd-swatch[aria-pressed="true"] { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); }
.rd-swatch.light { background: #fffdf7; color: #1c1410; }
.rd-swatch.sepia { background: #f4e7c9; color: #2b1d14; }
.rd-swatch.dark { background: #17120f; color: #e9dcc2; }
.rd-text {
  width: min(100% - 2.2rem, 40rem); margin: 0 auto; padding: 1.6rem 0 1rem;
  font-family: var(--serif); font-size: var(--rd-size); line-height: 1.62; color: var(--rd-ink);
  -webkit-touch-callout: none;
}
.rd-text .rd-ch { font-family: var(--display); font-size: 0.75em; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); text-align: center; margin: 0.6rem 0 0.4rem; }
.rd-text h1.rd-h { font-family: var(--serif); font-weight: 600; font-size: 1.35em; text-align: center; margin: 0 0 1.4rem; line-height: 1.25; }
.rd-text p { margin: 0 0 0.9em; text-align: justify; hyphens: auto; -webkit-hyphens: auto; }
.rd-text p.c { text-align: center; }
.rd-text p.q { margin-left: 1.6em; }
.rd-text p.it { font-style: italic; }
.rd-text h3 { font-size: 1.05em; text-align: center; font-weight: 600; margin: 1.6em 0 0.8em; }
.rd-text .sc { font-variant: small-caps; }
.rd-text sup.fn a { font-size: 0.7em; text-decoration: none; color: var(--gold); padding: 0 0.1em; }
.rd-text .notes { margin-top: 2.4rem; padding-top: 0.8rem; border-top: 1px solid var(--rd-rule); font-size: 0.82em; color: var(--rd-muted); }
.rd-text .notes h4 { font-family: var(--display); letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.8em; margin: 0 0 0.5rem; }
.rd-text .notes li { margin-bottom: 0.4rem; }
.rd-text .notes a.back { text-decoration: none; color: var(--gold); }
.rd-text a { color: inherit; }
.rd-text table { border-collapse: collapse; font-size: 0.85em; margin: 1em 0; }
.rd-text td, .rd-text th { border: 1px solid var(--rd-rule); padding: 0.2em 0.4em; vertical-align: top; }
.rd-nav { width: min(100% - 2.2rem, 40rem); margin: 0 auto; padding: 1.2rem 0 2.4rem; display: flex; justify-content: space-between; gap: 0.6rem; border-top: 1px solid var(--rd-rule); }
.rd-nav .rd-btn { padding: 0.6rem 1rem; }
.rd-loading { text-align: center; color: var(--rd-muted); padding: 3rem 0; }
.rd-gate { text-align: center; padding: 3rem 1rem; color: var(--rd-ink); }

/* Modal */
.lib-modal { position: fixed; inset: 0; background: rgba(20, 8, 8, 0.62); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.lib-modal[hidden] { display: none; }
.lib-modal-card { position: relative; width: min(100%, 26rem); background: var(--card); border: 1px solid var(--gold); padding: 1.4rem 1.3rem 1.3rem; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.lib-modal-card h2 { margin: 0 0 0.3rem; font-family: var(--display); font-size: 1.15rem; letter-spacing: 0.06em; color: var(--red-deep); }
.lib-modal-x { position: absolute; right: 0.5rem; top: 0.3rem; background: none; border: 0; font-size: 1.6rem; cursor: pointer; color: var(--muted); }
.lib-auth-note { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.98rem; }
.lib-tabs { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 0.9rem; border: 1px solid var(--card-edge); }
.lib-tabs button { font: inherit; padding: 0.45rem; background: transparent; border: 0; cursor: pointer; color: var(--ink-soft); }
.lib-tabs button[aria-selected="true"] { background: var(--red); color: #f8e9c4; }
#lib-auth-form { display: grid; gap: 0.7rem; }
#lib-auth-form label { display: grid; gap: 0.2rem; font-size: 0.98rem; }
#lib-auth-form input { font: inherit; padding: 0.55rem 0.65rem; border: 1px solid var(--card-edge); background: #fff; }
.lib-opt { color: var(--muted); font-size: 0.88rem; }
.lib-auth-err { margin: 0; color: var(--red); min-height: 1.2em; font-size: 0.95rem; }

@media (max-width: 600px) {
  .lib-hero { padding: 1.6rem 0 1.5rem; }
  .rd-bar { padding: 0.4rem 0.5rem; gap: 0.35rem; }
  .rd-btn { padding: 0.3rem 0.5rem; font-size: 0.88rem; }
  .rd-text { width: calc(100% - 1.6rem); padding-top: 1.1rem; }
  .rd-text p { text-align: left; }
  .lib-shelf { grid-auto-columns: minmax(13rem, 78%); }
}
@media print { .rd-text, .rd { display: none !important; } }
.rd-hide-sm{} @media (max-width:600px){.rd-hide-sm{display:none}}
.rd-text sup.fn { margin: 0 0.18em 0 0.05em; }
.rd-text sup.v { font-size: 0.62em; color: var(--gold); margin: 0 0.18em 0 0.3em; font-family: var(--display); }
.rd-text h3 + p sup.v:first-child { margin-left: 0; }

.rd-text sup.fn { font-size: 0.66em; color: var(--gold); }
.rd-text aside.fnote { margin: -0.2em 0 1.1em; padding: 0.5em 0.8em; border-left: 2px solid var(--rd-rule); font-size: 0.8em; line-height: 1.5; color: var(--rd-muted); }
.rd-text aside.fnote b { color: var(--gold); font-weight: 600; margin-right: 0.15em; }
.rd-text p.c.it, .rd-text p.it.c { text-align: center; font-style: italic; }
.rd-text blockquote { margin: 0 0 0.9em 1.2em; }
.lib-note { margin: -0.2rem 0 0.9rem; color: #6b5a3e; font-size: 0.95rem; max-width: 60ch; }
.rd-text p.v { margin: 0 0 1em 1.4em; text-indent: 0; text-align: left; line-height: 1.55; }
.rd-text figure.fx { margin: 0 0 1.4em; text-align: center; }
.rd-text figure.fx a { display: block; }
.rd-text figure.fx img { display: block; margin: 0 auto; max-width: 100%; height: auto; background: #fff; border: 1px solid var(--rd-rule); box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12); }
.rd.dark .rd-text figure.fx img { filter: invert(0.9) hue-rotate(180deg); }
.rd-text figure.fx figcaption { margin-top: 0.4em; font-size: 0.75em; letter-spacing: 0.06em; color: var(--rd-muted); }
.rd-text p.fx-note { font-style: italic; color: var(--rd-muted); font-size: 0.92em; margin-bottom: 1.4em; }
