:root {
  color-scheme: light;

  --paper:  #fbfaf7;
  --sunk:   #f3f1ea;
  --card:   #ffffff;
  --ink:    #1b1a18;
  --ink-2:  #4b4640;

  --muted:  #635e58;
  --faint:  #746d64;
  --line:   #e5e0d6;
  --hair:   #eeeae1;
  --accent: #8a1c1c;
  --accent-2: #6d1414;
  --accent-soft: #f7eeec;

  --cover:     #fffdf9;
  --cover-ink: #23211e;
  --cover-sub: #6b645c;

  --display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --reading: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bar-h: 58px;
  --r: 7px;
  --reader-size: 1.06rem;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-2); }

h1, h2, h3 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.015em;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 28px;
}

.wrap.narrow { max-width: 760px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar .wrap {
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  margin-right: 4px;
  font-family: var(--display);
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover { color: var(--accent); }

.topbar nav {
  display: flex;
  gap: 4px;
  font-size: 0.82rem;
}

.topbar nav a {
  padding: 6px 11px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease,
              transform 0.2s cubic-bezier(0.2, 0.8, 0.3, 1), box-shadow 0.2s ease;
}

.topbar nav a:active {
  transform: scale(0.955);
  background: var(--sunk);
  box-shadow: inset 0 1px 2px rgba(27, 26, 24, 0.14);
  transition-duration: 0.1s, 0.1s, 0.07s, 0.07s;
}

.topbar nav a:hover {
  color: var(--ink);
  background: var(--hair);
}

.topbar nav a[aria-current="page"] {
  color: var(--ink);
  background: var(--hair);
}

.topbar .grow { flex: 1; }

.searchform { display: flex; min-width: 0; }

.search {
  width: min(280px, 42vw);
  padding: 7px 12px 7px 31px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background-color: var(--sunk);

  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23746d64' stroke-width='1.5'%3E%3Ccircle cx='6.8' cy='6.8' r='4.3'/%3E%3Cpath d='M10.1 10.1 13.6 13.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 11px 50%;
  background-size: 13px 13px;
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.search::placeholder { color: var(--faint); }

.search:hover { border-color: var(--muted); }

.search:focus {
  outline: none;
  border-color: var(--muted);
  background-color: var(--card);
}

.skip {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 60;
  padding: 9px 15px;
  border-radius: var(--r);
  background: var(--ink);
  color: var(--paper);
  font-size: 0.84rem;
  text-decoration: none;
  transform: translateY(-250%);
  transition: transform 0.15s ease;
}

.skip:focus { transform: none; color: var(--paper); }

main { scroll-margin-top: calc(var(--bar-h) + 10px); }

.page { padding-block: 56px 96px; }

.page > h1 {
  margin: 0 0 10px;
  font-size: 2.1rem;
  line-height: 1.15;
}

.lede {
  margin: 0 0 52px;
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 54ch;
}

.shelf { margin: 0 0 52px; }

.shelf-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin: 0 0 22px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.shelf-head h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--ink);
}

.shelf-head .note {
  margin-left: auto;
  color: var(--faint);
  font-size: 0.7rem;
  font-family: var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.row {
  display: flex;
  gap: 24px;
  overflow-x: auto;
  padding: 6px 0 10px;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;

  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 56px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 56px), transparent);
}

.row > * { scroll-snap-align: start; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 34px 24px;
  padding: 4px 0;
}

.book { width: 152px; flex: 0 0 152px; }
.grid .book { width: auto; flex: none; }

.book > a {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 2px 4px 4px 2px;
}

.cover {
  position: relative;
  aspect-ratio: 2 / 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  padding: 18px 14px 34px 20px;
  border-radius: 2px 4px 4px 2px;
  background: var(--cover);
  color: var(--cover-ink);
  overflow: hidden;
  box-shadow:
    inset 0 0 0 1px var(--line),
    inset -10px 0 12px -12px rgba(0, 0, 0, 0.3),
    0 1px 2px rgba(0, 0, 0, 0.05),
    0 12px 20px -16px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.cover::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 6px;
  background: var(--spine, var(--accent));
  box-shadow: inset -1px 0 0 rgba(0, 0, 0, 0.22);
}

.book > a:hover .cover,
.book > a:focus-visible .cover {
  transform: translateY(-4px);
  box-shadow:
    inset 0 0 0 1px var(--line),
    inset -10px 0 12px -12px rgba(0, 0, 0, 0.3),
    0 2px 4px rgba(0, 0, 0, 0.06),
    0 20px 28px -18px rgba(0, 0, 0, 0.5);
}

.book > a:focus-visible { outline: 2px solid var(--muted); outline-offset: 3px; }

.cover .t {
  font-family: var(--display);
  font-size: 0.9rem;
  line-height: 1.28;
  letter-spacing: -0.01em;
  overflow-wrap: break-word;
  hyphens: auto;
}

.cover .t span {
  display: -webkit-box;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cover .rule {
  width: 18px;
  height: 1px;
  margin: 13px auto;
  background: var(--spine, var(--accent));
  opacity: 0.65;
}

.cover .a {
  color: var(--cover-sub);
  font-size: 0.7rem;
  line-height: 1.35;
  letter-spacing: 0.015em;
  overflow-wrap: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.cover .yr {
  position: absolute;
  left: 20px;
  right: 14px;
  bottom: 14px;
  font-family: var(--mono);
  font-size: 0.63rem;
  letter-spacing: 0.09em;
  color: var(--faint);
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 5px 11px;
  background: transparent;
  color: var(--muted);
  font-family: var(--ui);
  font-size: 0.76rem;
  line-height: 1.5;

  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.chip:hover { color: var(--ink); border-color: var(--muted); }

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.empty { color: var(--muted); padding: 28px 0; font-size: 0.9rem; }

footer.site {
  border-top: 1px solid var(--line);
  padding: 28px 0 64px;
  color: var(--faint);
  font-size: 0.78rem;
}

footer.site p { margin: 0 0 4px; max-width: 62ch; }

.crumb {
  padding: 28px 0 0;
  margin: 0;
  font-size: 0.78rem;
}

.crumb a { color: var(--muted); text-decoration: none; }
.crumb a:hover { color: var(--ink); }

.masthead {
  display: flex;
  gap: 40px;
  align-items: flex-start;
  padding: 36px 0 40px;
  border-bottom: 1px solid var(--line);
}

.masthead .book { flex: 0 0 148px; width: 148px; }
.masthead .info { flex: 1; min-width: 0; }

.masthead h1 {
  margin: 0 0 8px;
  font-size: 2rem;
  line-height: 1.15;
}

.masthead .by {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.95rem;
}

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 22px;
  font-size: 0.72rem;
}

.facts span {
  border: 1px solid var(--hair);
  border-radius: var(--r);
  padding: 3px 9px;
  background: var(--sunk);
  color: var(--muted);
}

.actions { display: flex; flex-wrap: wrap; gap: 9px; }

.btn {
  display: inline-block;
  padding: 8px 15px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  color: var(--ink);
  font-family: var(--ui);
  font-size: 0.82rem;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:hover { border-color: var(--muted); background: var(--sunk); color: var(--ink); }

.btn.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.btn.primary:hover { background: var(--ink-2); border-color: var(--ink-2); color: var(--paper); }

.progress {
  position: fixed;
  left: 0;
  top: var(--bar-h);
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 39;
}

.readerbar {
  position: sticky;
  top: var(--bar-h);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  background: color-mix(in srgb, var(--paper) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  font-size: 0.76rem;
}

.readerbar .grow { flex: 1; }

.readerbar .pct {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--faint);
  min-width: 34px;
  text-align: right;
}

.readerbar button, .readerbar select {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  max-width: 210px;
}

.readerbar button:hover, .readerbar select:hover {
  border-color: var(--muted);
  color: var(--ink);
}

.readerbar .sizer {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--r);
}

.readerbar .sizer button {
  border: 0;
  border-radius: 0;
  padding: 4px 9px;
}

.readerbar .sizer button + button { box-shadow: inset 1px 0 0 var(--line); }
.readerbar .sizer button:first-child { border-radius: 6px 0 0 6px; }
.readerbar .sizer button:last-child { border-radius: 0 6px 6px 0; }

.readerbar .sizer button:hover { background: var(--sunk); color: var(--ink); }

.readerbar .sizer #zoom {
  min-width: 52px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--faint);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.readerbar .sizer #zoom:hover { color: var(--ink); }
.readerbar .sizer button[disabled]:hover { background: transparent; color: var(--muted); }

article.text {
  font-family: var(--reading);
  font-size: var(--reader-size);
  line-height: 1.75;
  color: var(--ink);
  max-width: min(34em, 100%);
  overflow-wrap: break-word;
  margin: 52px auto 0;
  padding-bottom: 48px;
}

article.text .lead {
  font-variant-caps: small-caps;
  letter-spacing: 0.05em;
}

article.text p.open::first-letter {
  float: left;
  margin: 0.04em 0.09em 0 0;
  color: var(--accent);
  font-size: 3.2em;
  line-height: 0.78;
}

article.text p {
  margin: 0 0 1.15em;
  text-align: justify;
  hyphens: auto;
}

article.text p.pre {
  white-space: pre-wrap;
  text-align: left;
  color: var(--ink-2);
}

article.text h2 {
  font-family: var(--display);
  font-size: 1.1em;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  letter-spacing: 0.01em;
  margin: 3em 0 1.4em;
  padding-top: 1.8em;
  border-top: 1px solid var(--line);
  scroll-margin-top: calc(var(--bar-h) + 56px);
}

article.text h2:first-child { border-top: 0; margin-top: 0; padding-top: 0; }

article.text h2 .cont {
  display: block;
  margin-top: 0.5em;
  font-family: var(--ui);
  font-size: 0.6em;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.text-end {
  max-width: min(34em, 100%);
  margin: 0 auto;
  padding: 28px 0 0;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.78rem;
}

.text-end a { color: var(--muted); }
.text-end a:hover { color: var(--accent); }

.readerbar #toc {
  flex: 0 1 auto;
  min-width: 0;
  max-width: min(38ch, 52%);
  text-overflow: ellipsis;
}

.readerbar button[disabled] {
  opacity: 0.35;
  cursor: default;
}

.readerbar button[disabled]:hover {
  border-color: var(--line);
  color: var(--muted);
}

.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(34em, 100%);
  margin: 0 auto 40px;
}

.pager .btn[disabled] { opacity: 0.35; cursor: default; }
.pager .btn[disabled]:hover { border-color: var(--line); background: transparent; }

.pager .where {
  flex: 1;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--faint);
}

.status {
  color: var(--muted);
  font-family: var(--ui);
  font-size: 0.88rem;
  text-align: center;
}

article.text[aria-busy="true"] { opacity: 0.35; }

[data-tip] { position: relative; }

[data-tip]::after {

  content: attr(data-tip) / "";
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 50;
  padding: 4px 9px;
  border-radius: 5px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--ui);
  font-size: 0.7rem;
  line-height: 1.4;
  letter-spacing: 0.005em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -3px);
  transition: opacity 0.13s ease, transform 0.13s ease;
}

[data-tip]:hover::after,
[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
  transition-delay: 0.3s;
}

[data-tip-at="start"]::after { left: 0; transform: translate(0, -3px); }
[data-tip-at="end"]::after { left: auto; right: 0; transform: translate(0, -3px); }

[data-tip-at="start"]:hover::after,
[data-tip-at="start"]:focus-visible::after,
[data-tip-at="end"]:hover::after,
[data-tip-at="end"]:focus-visible::after { transform: translate(0, 0); }

@media (hover: none) {
  [data-tip]::after { content: none; }
}

@media (max-width: 720px) {
  .wrap { padding: 0 18px; }
  .topbar .wrap { gap: 10px; }

  .topbar nav { gap: 2px; }
  .topbar nav a { padding: 6px 8px; }
  .topbar .grow { display: none; }
  .searchform { flex: 1; }

  .search {
    width: 100%;
    padding-left: 27px;
    background-position: 9px 50%;
  }
  .page { padding-block: 36px 72px; }
  .page > h1 { font-size: 1.55rem; }
  .lede { margin-bottom: 36px; }
  .masthead { gap: 20px; padding: 26px 0 30px; }
  .masthead .book { flex-basis: 100px; width: 100px; }
  .masthead h1 { font-size: 1.35rem; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 26px 18px; }
  article.text { margin-top: 36px; }
  .readerbar { flex-wrap: wrap; row-gap: 8px; }
  .readerbar #toc { flex: 1 1 auto; max-width: none; }

  .readerbar .grow { flex-basis: 100%; height: 0; }
  .readerbar .pct { margin-left: auto; }
  .pager .btn { padding: 8px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

@media print {
  .topbar, .readerbar, .progress, .crumb, .actions, .pager, footer.site { display: none; }
  article.text { max-width: none; }
}

::selection { background: color-mix(in srgb, var(--accent) 20%, transparent); }

a:focus-visible,
.btn:focus-visible,
.chip:focus-visible,
.search:focus-visible,
.readerbar button:focus-visible,
.readerbar select:focus-visible {
  outline: 2px solid var(--muted);
  outline-offset: 2px;
}

.row::-webkit-scrollbar { height: 6px; }
.row::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }
.row::-webkit-scrollbar-track { background: transparent; }
