* { box-sizing: border-box; margin: 0; }

:root {
  --paper: #f0efec;
  --ink: #1c1c1c;
  --bg: #d8d6d1;
  --accent: #c8372d;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Helvetica, Arial, sans-serif;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #fff;
  border-bottom: 1px solid #bbb;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 17px; font-weight: 700; }
.topbar .sub { color: #777; font-size: 13px; }
.topbar .back { color: var(--accent); text-decoration: none; font-size: 14px; }
.controls { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.controls input[type=search] { width: 240px; }
input[type=search], input[type=number] {
  font: inherit;
  padding: 6px 9px;
  border: 1px solid #aaa;
  border-radius: 4px;
}
input[type=number] { width: 64px; }
.pagejump { font-size: 13px; color: #555; }
button {
  font: inherit;
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid #aaa;
  border-radius: 4px;
  background: #f5f5f5;
  cursor: pointer;
}
button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* home */
.home { max-width: 1100px; margin: 0 auto; padding: 28px 18px; }
.searchbox input { width: 100%; font-size: 16px; padding: 12px 14px; }
.bookgrid {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.bookcard {
  display: block;
  text-decoration: none;
  color: inherit;
  background: #fff;
  border: 1px solid #bbb;
  border-radius: 6px;
  overflow: hidden;
  transition: box-shadow .15s;
}
.bookcard > a { color: inherit; text-decoration: none; }
.seclinks { border-top: 1px solid #eee; padding: 6px 0 10px; }
.seclink {
  display: block;
  padding: 4px 12px;
  font-size: 12.5px;
  color: #444;
  text-decoration: none;
}
.seclink:hover { color: var(--accent); }
.bookcard:hover { box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.bookcard img { width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block; background: var(--paper); }
.bookcard .label { padding: 10px 12px; font-size: 14px; font-weight: 700; }
.bookcard .label span { display: block; font-weight: 400; color: #777; font-size: 12px; margin-top: 2px; }

/* search results */
.results { margin-top: 18px; }
.results:empty { display: none; }
.floatpanel {
  position: fixed;
  top: 62px;
  right: 18px;
  width: 340px;
  max-height: 70vh;
  overflow: auto;
  background: #fff;
  border: 1px solid #999;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
  z-index: 20;
  margin: 0;
}
.result {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid #e2e2e2;
  text-decoration: none;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
}
.result:hover { background: #f6f3ee; }
.result .where { color: var(--accent); font-weight: 700; margin-bottom: 3px; }
.result mark { background: #ffe27a; }
.rcount { padding: 8px 14px; font-size: 12px; color: #777; }

/* layout with sidebar */
.layout { display: flex; align-items: flex-start; }
#sidebar {
  position: sticky;
  top: 53px;
  width: 300px;
  flex: 0 0 300px;
  height: calc(100vh - 53px);
  background: #fff;
  border-right: 1px solid #bbb;
  display: flex;
  flex-direction: column;
}
body.nosb #sidebar { display: none; }
#sbtoggle { padding: 4px 10px; }
.tabs { display: flex; border-bottom: 1px solid #ccc; }
.tabs button {
  flex: 1;
  border: none;
  border-radius: 0;
  background: #eee;
  padding: 9px 0;
  border-right: 1px solid #ccc;
}
.tabs button:last-child { border-right: none; }
.tabs button.active { background: #fff; color: var(--ink); font-weight: 700; }
.tabpane { display: none; overflow-y: auto; flex: 1; padding: 10px 0; }
.tabpane.active { display: block; }

/* volume switcher */
.volswitch { display: flex; gap: 4px; align-items: center; font-size: 13px; color: #666; }
.volswitch button { padding: 4px 10px; }

/* clickable printed-contents lines: transparent hotspots over the scan */
.page a.tl.lnk {
  color: transparent;
  border-bottom: 2px solid rgba(200, 55, 45, .45);
  cursor: pointer;
}
.page a.tl.lnk:hover { background: rgba(200, 55, 45, .14); border-radius: 2px; }

/* contents tab */
.toc-item.l0 {
  font-weight: 700;
  font-size: 13.5px;
  margin-top: 8px;
  border-top: 1px solid #eee;
  padding-top: 9px;
}
.thumbvol {
  font-weight: 700;
  font-size: 12.5px;
  color: #999;
  padding: 12px 4px 6px;
}
.toc-item {
  display: block;
  padding: 6px 16px;
  font-size: 13px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.toc-item.l2 { padding-left: 32px; font-size: 12.5px; color: #444; }
.toc-item:hover { background: #f3efe8; }
.toc-item.cur { border-left-color: var(--accent); background: #f8f4ec; }
.toc-item .pg { float: right; color: #999; font-size: 11px; }
.toc-empty { padding: 16px; font-size: 13px; color: #888; }

/* thumbnails tab */
#tab-thumbs { padding: 10px; }
.thumbgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.thumb { cursor: pointer; text-align: center; }
.thumb img {
  width: 100%;
  border: 2px solid #ccc;
  border-radius: 3px;
  display: block;
  background: var(--paper);
  aspect-ratio: 3 / 4;
  object-fit: cover;
}
.thumb.cur img { border-color: var(--accent); }
.thumb .tn { font-size: 11px; color: #666; margin-top: 3px; }

/* index tab */
.letternav {
  padding: 4px 12px 10px;
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 7px;
  border-bottom: 1px solid #eee;
}
.letternav a { color: var(--accent); text-decoration: none; font-weight: 700; }
.idx-letter { font-weight: 700; font-size: 13px; padding: 10px 16px 2px; color: #999; }
.idx-term { padding: 3px 16px; font-size: 12.5px; }
.idx-term .pgs a { color: var(--accent); text-decoration: none; margin-right: 5px; }
.idx-term .pgs a:hover { text-decoration: underline; }

/* recreated pages: live type over artwork windowed from the scan */
.rpage { container-type: inline-size; }
/* --scan is set per page by the viewport observer, so a page's artwork is only
   fetched when the reader is near it */
.rpage .art { position: absolute; background-repeat: no-repeat; background-image: var(--scan, none); }
.rpage .rt {
  position: absolute;
  color: var(--ink);
  line-height: 1.33;
  letter-spacing: -.004em;
  white-space: pre-wrap;
}
/* the book sets its body copy in a heavy Helvetica */
.rpage .rt-body { font-weight: 700; }
.rpage .rt-caption { font-style: italic; font-weight: 400; }
.rpage .rt-heading, .rpage .rt-label { font-weight: 700; }
.rpage .rt-title { font-weight: 700; line-height: 1.06; letter-spacing: -.015em; }
.rpage .rt-folio { color: #444; font-weight: 400; }
/* a printed column runs continuously; new paragraphs are marked by an indent */
.rpage .rt .para { display: block; }
.rpage .rt .para.ind { text-indent: 1.7em; }
.rpage .rt.hl { background: #ffe27a; border-radius: 2px; }
.rpage a.rlnk { color: var(--accent); text-decoration: none; cursor: pointer; }
.rpage a.rlnk:hover { text-decoration: underline; }

/* cover */
.cover {
  position: relative;
  background: #fdfdfb;
  box-shadow: 0 3px 14px rgba(0,0,0,.25);
  margin: 0 auto 30px;
  aspect-ratio: 3 / 4;
  display: flex;
  padding: 7% 6% 7% 0;
  gap: 4%;
  font-family: Helvetica, Arial, sans-serif;
}
.cvleft { width: 30%; display: flex; flex-direction: column; gap: 2.5%; }
.cvrow { flex: 1; display: flex; }
.cvred { width: 46%; background: #e23b28; }
.cvc { width: 54%; }
.cvright { flex: 1; display: flex; flex-direction: column; }
.cvhead {
  border-top: 3px solid var(--ink);
  padding-top: .5em;
  font-weight: 700;
  font-size: clamp(9px, 1.5vw, 15px);
  line-height: 1.35;
}
.cvtitle {
  font-size: clamp(20px, 5.2vw, 46px);
  line-height: 1.04;
  letter-spacing: -.015em;
  margin: .25em 0 .35em;
  border-bottom: 3px solid var(--ink);
  padding-bottom: .28em;
}
.cvauthor {
  font-weight: 700;
  font-size: clamp(13px, 2.6vw, 24px);
  border-bottom: 3px solid var(--ink);
  padding-bottom: .35em;
}
.cvlist { margin-top: auto; width: 82%; }
.cvbook { display: flex; gap: 6%; }
.cvbklabel { flex: 0 0 15%; text-align: right; cursor: pointer; line-height: 1; padding-top: 2px; }
.cvbklabel span { display: block; font-size: clamp(7px, 1vw, 10px); }
.cvbklabel b { font-size: clamp(13px, 2.2vw, 22px); }
.cvbklabel:hover b { color: var(--accent); }
.cvsubjects { flex: 1; display: flex; flex-direction: column; }
.cvsubjects a {
  border-top: 1px solid var(--ink);
  font-size: clamp(8px, 1.25vw, 12px);
  padding: 2px 0 3px;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.cvbook:last-child .cvsubjects a:last-child { border-bottom: 1px solid var(--ink); }
.cvsubjects a:hover { color: var(--accent); }

/* pages */
.pages { flex: 1; min-width: 0; max-width: 1000px; margin: 0 auto; padding: 24px 12px 80px; }

/* view modes */
.viewmode { display: flex; }
.viewmode button { border-radius: 0; margin-left: -1px; }
.viewmode button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.viewmode button:last-child { border-radius: 0 4px 4px 0; }

.pagespacer { display: none; }

body.view-page .pages,
body.view-spread .pages {
  max-width: none;
  padding: 14px 14px 40px;
  display: grid;
  justify-items: center;
  align-items: start;
  gap: 16px;
}
body.view-page .pages { grid-template-columns: minmax(0, 1fr); }
body.view-spread .pages { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 6px; }
body.view-spread .pagespacer { display: block; }

/* fit whole pages to the window instead of the column width */
body.view-page .page, body.view-spread .page {
  height: calc(100vh - 96px);
  width: auto;
  max-width: 100%;
  margin: 0;
  scroll-margin-top: 70px;
}
body.view-page .cover, body.view-spread .cover {
  height: calc(100vh - 96px);
  width: auto;
  margin: 0;
}
body.view-spread .cover { grid-column: 1 / -1; }
body.view-page .pageno, body.view-spread .pageno { display: none; }
/* facing pages meet at the gutter */
body.view-spread .page:nth-child(odd) { justify-self: end; }
body.view-spread .page:nth-child(even) { justify-self: start; }
.page {
  position: relative;
  background: var(--paper);
  box-shadow: 0 3px 14px rgba(0,0,0,.25);
  margin: 0 auto 30px;
  overflow: hidden;
  content-visibility: auto;
  contain-intrinsic-size: auto 1300px;
}
.page .tl {
  position: absolute;
  white-space: nowrap;
  line-height: 1;
  color: transparent;
  z-index: 2;
}
.page .tl::selection { background: rgba(60, 120, 255, .35); }
.page .tl.hl { background: rgba(255, 226, 122, .55); border-radius: 2px; }
.page img.scanimg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }
.pageno {
  text-align: center;
  color: #666;
  font-size: 12px;
  margin: -22px 0 26px;
}

/* ---------------------------------------------------------------
   Mobile: one long scrolling page, with a drawer for contents and
   thumbnails. No search, no index, no view modes.
   --------------------------------------------------------------- */
.sbbackdrop { display: none; }

@media (max-width: 820px) {
  .topbar { padding: 8px 12px; gap: 10px; }
  .topbar h1 { font-size: 15px; }
  .topbar .sub { display: none; }
  .back { font-size: 13px; }
  #sbtoggle { font-size: 17px; padding: 3px 10px; }

  /* desktop-only controls */
  .controls input[type=search],
  .pagejump,
  .viewmode,
  #results,
  .tabs button[data-tab="idx"] { display: none; }
  #tab-idx { display: none !important; }

  .controls { margin-left: auto; gap: 6px; }
  .volswitch { font-size: 12px; }
  .volswitch button { padding: 3px 8px; }

  /* sidebar slides in over the page */
  .layout { display: block; }
  #sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 84vw;
    max-width: 330px;
    height: 100%;
    flex: none;
    z-index: 60;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: 0 0 28px rgba(0, 0, 0, .32);
  }
  body.sb-open #sidebar { transform: none; }
  /* the desktop collapse class must not hide the drawer */
  body.nosb #sidebar { display: flex; }
  body.sb-open .sbbackdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .38);
    z-index: 50;
  }

  /* always one continuous column, whatever the saved view mode was */
  .pages,
  body.view-page .pages,
  body.view-spread .pages {
    display: block;
    max-width: none;
    padding: 10px 8px 56px;
  }
  .page, .cover,
  body.view-page .page, body.view-spread .page,
  body.view-page .cover, body.view-spread .cover {
    width: 100%;
    height: auto;
    margin: 0 auto 16px;
  }
  body.view-spread .pagespacer { display: none; }
  .pageno { margin: -8px 0 16px; font-size: 11px; }
  .thumbgrid { grid-template-columns: 1fr 1fr; }
}
