:root {
  --cream: #f4ecdd;
  --page: #fdfcf8;
  --desk: #3f392f;
  --ink: #2a211a;
  --rule: #c9b998;
  --accent: #7a2e2e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #e8ddc8;
  color: var(--ink);
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
}

/* ---------- Picker ---------- */

#picker {
  max-width: 1000px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

#picker h1 {
  text-align: center;
  font-weight: normal;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 1.6rem;
  border-bottom: 3px solid var(--accent);
  padding-bottom: 0.75rem;
  margin-bottom: 1.5rem;
}

#search {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto 2rem;
  padding: 0.5rem 0.8rem;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--rule);
  border-radius: 4px;
}

#book-list {
  column-width: 340px;
  column-gap: 2.5rem;
}

.book-group {
  break-inside: avoid-column;
  margin-bottom: 1.5rem;
}

.book-group h2 {
  font-size: 1.1rem;
  font-weight: normal;
  font-style: italic;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.25rem;
  margin: 0 0 0.25rem;
}

.book-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.6rem 0.25rem;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px dotted var(--rule);
}

.book-item:hover { background: rgba(122, 46, 46, 0.08); }

.book-item .title { font-size: 1.05rem; }
.book-item .source { font-size: 0.8rem; color: #70604a; white-space: nowrap; }

#no-results {
  text-align: center;
  color: #70604a;
  font-style: italic;
}

#picker footer {
  text-align: center;
  margin-top: 3rem;
  font-size: 0.8rem;
  color: #70604a;
}

#picker footer a { color: var(--accent); }

#request-toggle {
  margin-top: 1rem;
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

#request-form {
  max-width: 380px;
  margin: 1rem auto 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#request-form[hidden] { display: none; }

#request-form input[type="text"]:not(#request-website), #request-form textarea {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  resize: vertical;
}

#request-form button[type="submit"] {
  align-self: center;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--ink);
  color: var(--cream);
  border: none;
  border-radius: 4px;
  padding: 0.4rem 1rem;
  cursor: pointer;
}

#request-status { font-size: 0.8rem; min-height: 1.2em; text-align: center; margin: 0; }

#request-website {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* ---------- Reader ---------- */

#reader-view { display: none; height: 100vh; flex-direction: column; }
#reader-view.active { display: flex; }

.reader-chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--cream);
  font-size: 0.85rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.reader-chrome .chrome-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.reader-chrome .running-head {
  text-align: center;
  font-style: italic;
  letter-spacing: 0.03em;
  padding: 0 0.5rem;
}

.reader-chrome button, .reader-chrome select {
  background: transparent;
  color: var(--cream);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 0.3rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.reader-chrome button:hover { background: rgba(255,255,255,0.1); }

.reader-chrome a { color: var(--cream); text-decoration: underline; font-size: 0.85rem; }

#viewer-wrap {
  flex: 1;
  position: relative;
  background: var(--desk);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#page {
  position: relative;
  width: min(580px, 92vw);
  height: min(780px, 86vh);
  background: var(--page);
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}

#viewer {
  position: absolute;
  top: 3rem; bottom: 3rem;
  left: 3.2rem; right: 3.2rem;
}

.nav-zone {
  position: absolute;
  top: 0; bottom: 0;
  width: 18%;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: 5;
}

.nav-zone.left { left: 0; }
.nav-zone.right { right: 0; }

#toc-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 280px;
  background: var(--cream);
  border-left: 2px solid var(--rule);
  overflow-y: auto;
  padding: 1rem;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 10;
}

#toc-panel.open { transform: translateX(0); }

#toc-panel h3 { margin-top: 0; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.05em; }
#toc-panel a { display: block; padding: 0.4rem 0; color: var(--ink); text-decoration: none; border-bottom: 1px dotted var(--rule); font-size: 0.9rem; }
#toc-panel a:hover { color: var(--accent); }

@media (max-width: 700px) {
  .reader-chrome .running-head { display: none; }
  .reader-chrome a { display: none; }
  #toc-panel { width: 85%; }
  #page { width: 100vw; height: 100%; box-shadow: none; }
  #viewer { top: 1.5rem; bottom: 1.5rem; left: 1.2rem; right: 1.2rem; }
}
