:root {
  color-scheme: light;
  --paper: #f3f0e8;
  --paper-elevated: #f8f5ee;
  --ink: #191814;
  --muted: #747269;
  --line: #d7d2c6;
  --accent: #a5382f;
  --success: #397452;
  --danger: #a33129;
  --focus: #b04a3d;
  --max-width: 1480px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0d0e0e;
  --paper-elevated: #151616;
  --ink: #eceae4;
  --muted: #9c9b94;
  --line: #303232;
  --accent: #d67468;
  --success: #69ad82;
  --danger: #e17b70;
  --focus: #ef9a8e;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--paper);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

button,
input {
  color: inherit;
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 78%, transparent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  left: 16px;
  top: 12px;
  z-index: 100;
  transform: translateY(-180%);
  background: var(--ink);
  color: var(--paper);
  padding: 10px 14px;
}

.skip-link:focus {
  transform: none;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.app-view {
  min-height: 100vh;
  padding: 0 clamp(24px, 5vw, 82px) 90px;
}

.app-header,
.hero,
.library-section,
.catalog-section {
  width: min(100%, var(--max-width));
  margin-inline: auto;
}

.app-header {
  min-height: 106px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand img {
  width: 43px;
  height: 54px;
  object-fit: contain;
  mix-blend-mode: multiply;
}

:root[data-theme="dark"] .brand img {
  filter: invert(1);
  mix-blend-mode: screen;
}

.brand strong {
  display: block;
  font: 400 20px/1.15 Georgia, "Times New Roman", serif;
  text-transform: lowercase;
}

.brand small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .2em;
  text-transform: uppercase;
}

.header-actions,
.reader-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button,
.quiet-button,
.primary-button,
.text-button {
  min-height: 42px;
  border: 1px solid var(--line);
  background: transparent;
}

.icon-button {
  min-width: 42px;
  padding: 0 11px;
  display: inline-grid;
  place-items: center;
  font-size: 18px;
}

.text-size-button {
  min-width: 48px;
  font: 600 13px Georgia, "Times New Roman", serif;
}

.quiet-button {
  padding: 0 14px;
  font-size: 12px;
}

.primary-button {
  padding: 0 18px;
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-size: 12px;
}

.text-button {
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.hero {
  min-height: 350px;
  display: grid;
  grid-template-columns: 1.12fr .88fr;
  align-items: end;
  gap: clamp(48px, 8vw, 130px);
  padding: 65px 0 59px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .23em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font: 400 clamp(56px, 6.3vw, 90px)/.96 Georgia, "Times New Roman", serif;
  letter-spacing: -.045em;
}

.hero-copy {
  padding-bottom: 6px;
}

.hero-copy p {
  margin: 0 0 12px;
  font: 400 17px/1.6 Georgia, "Times New Roman", serif;
}

.hero-copy .privacy-copy {
  color: var(--muted);
  font: 12px/1.65 Arial, Helvetica, sans-serif;
}

.hero-copy a {
  display: inline-block;
  margin-top: 6px;
  padding-left: 12px;
  border-left: 2px solid var(--accent);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
  text-decoration: none;
}

.hero-copy a:hover {
  color: var(--ink);
}

.library-section,
.catalog-section {
  padding-top: 51px;
}

.catalog-section {
  margin-top: 16px;
  padding-top: 54px;
  border-top: 1px solid var(--line);
}

.section-heading {
  min-height: 88px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  align-items: end;
  gap: 36px;
  margin-bottom: 27px;
}

.section-heading h2 {
  margin: 0;
  font: 400 clamp(26px, 2.4vw, 36px)/1.15 Georgia, "Times New Roman", serif;
}

.result-count {
  min-height: 18px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.catalog-note {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--muted);
}

.search-field svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}

.search-field input {
  width: 100%;
  height: 46px;
  padding: 0 8px 0 10px;
  border: 0;
  outline: 0;
  background: transparent;
}

.continue-section {
  margin: 4px 0 34px;
  padding: 22px 0;
  border-block: 1px solid var(--line);
}

.continue-section h3 {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.continue-book {
  width: min(100%, 760px);
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.continue-book img {
  width: 52px;
  height: 75px;
  object-fit: cover;
  background: var(--paper-elevated);
}

.continue-cover-fallback {
  width: 52px;
  height: 75px;
  display: grid;
  place-items: center;
  background: #49465a;
  color: #fff;
  font: 400 25px Georgia, "Times New Roman", serif;
}

.continue-book strong,
.continue-book small {
  display: block;
}

.continue-book strong {
  font: 400 18px Georgia, "Times New Roman", serif;
}

.continue-book small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: start;
  gap: clamp(18px, 2.1vw, 32px);
}

.book-card,
.add-book-card {
  min-width: 0;
}

.book-cover,
.add-book-card {
  width: 100%;
  aspect-ratio: 2 / 3;
}

.book-cover {
  position: relative;
  overflow: hidden;
  background: var(--paper-elevated);
  box-shadow: 0 12px 27px color-mix(in srgb, #000 15%, transparent);
}

.book-cover img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.placeholder-cover {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(18px, 2.2vw, 30px);
  background: #49465a;
  color: #fff;
}

.placeholder-cover span {
  font-size: 8px;
  letter-spacing: .18em;
  text-transform: uppercase;
}

.placeholder-cover strong {
  margin: auto 0 16px;
  font: 400 clamp(21px, 2vw, 34px)/1.14 Georgia, "Times New Roman", serif;
}

.placeholder-cover small {
  opacity: .75;
  font-size: 10px;
}

.book-meta {
  min-height: 101px;
  padding-top: 13px;
}

.book-meta h3 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.35;
}

.book-meta p {
  min-height: 17px;
  margin: 6px 0 7px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.book-actions {
  min-height: 28px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 13px;
}

.book-actions button,
.book-actions a {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 10px;
  text-decoration: none;
}

.book-actions button:first-child {
  color: var(--accent);
  font-weight: 700;
}

.book-actions .remove-action {
  color: var(--muted);
}

.book-actions a::after {
  content: "↗";
  margin-left: 5px;
}

.add-book-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border: 1px dashed var(--muted);
  background: var(--paper-elevated);
  text-align: center;
}

.add-book-card span {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-size: 22px;
}

.add-book-card strong {
  margin-top: 18px;
  font-size: 14px;
}

.add-book-card small {
  margin-top: 7px;
  color: var(--muted);
  font-size: 10px;
}

.empty-state {
  padding: 46px 0;
  border-block: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
}

.reader-view {
  height: 100vh;
  overflow: hidden;
  background: var(--paper);
}

.reader-toolbar {
  height: 70px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 clamp(16px, 3vw, 48px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  backdrop-filter: blur(12px);
}

.back-button {
  justify-self: start;
}

.reader-book-name {
  min-width: 0;
  max-width: 420px;
  text-align: center;
}

.reader-book-name strong,
.reader-book-name small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-book-name strong {
  font: 400 14px Georgia, "Times New Roman", serif;
}

.reader-book-name small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 9px;
}

.reader-controls {
  justify-self: end;
}

.reader-stage {
  position: relative;
  display: flex;
  justify-content: center;
  height: calc(100vh - 112px);
  overflow: hidden;
}

#viewer {
  width: min(100%, 960px);
  max-width: 960px;
  height: 100%;
  margin-inline: auto;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-y pinch-zoom;
}

#viewer > div,
#viewer iframe {
  width: 100% !important;
  height: 100% !important;
}

.reader-message {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--paper);
  color: var(--muted);
  font-size: 12px;
}

.reader-message.error-message {
  padding: 30px;
  color: var(--danger);
  text-align: center;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(1turn); }
}

.reader-status {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 clamp(18px, 3vw, 48px);
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}

.reader-status strong {
  color: var(--ink);
  font-weight: 400;
}

.reader-status strong + span::before {
  content: " · ";
}

.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: color-mix(in srgb, #000 32%, transparent);
  backdrop-filter: blur(3px);
}

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  width: min(440px, 94vw);
  overflow-y: auto;
  padding: 34px 28px 50px;
  border-left: 1px solid var(--line);
  background: var(--paper);
  box-shadow: -18px 0 54px color-mix(in srgb, #000 18%, transparent);
}

.side-panel > header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
}

.side-panel h2,
.app-dialog h2 {
  margin: 0;
  font: 400 33px/1.1 Georgia, "Times New Roman", serif;
}

.toc-list {
  display: grid;
}

.panel-empty {
  margin: 0;
  padding: 24px 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

.toc-item {
  width: 100%;
  min-height: 50px;
  padding: 12px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  line-height: 1.45;
}

.toc-item[aria-current="location"] {
  color: var(--accent);
}

.panel-search {
  margin-bottom: 14px;
}

.search-summary {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 10px;
}

.search-summary button {
  width: 30px;
  height: 28px;
  border: 1px solid var(--line);
  background: transparent;
}

.index-progress {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 10px;
}

.search-results {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.search-result {
  width: 100%;
  padding: 14px 2px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.search-result[aria-current="true"] {
  color: var(--accent);
}

.search-result strong,
.search-result span {
  display: block;
}

.search-result strong {
  margin-bottom: 5px;
  font: 400 14px Georgia, "Times New Roman", serif;
}

.search-result span {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 32px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px);
}

.drop-overlay > div {
  width: min(620px, 100%);
  min-height: 300px;
  display: grid;
  place-content: center;
  gap: 8px;
  border: 1px dashed var(--accent);
  text-align: center;
}

.drop-overlay strong {
  font: 400 30px Georgia, "Times New Roman", serif;
}

.drop-overlay span {
  color: var(--muted);
  font-size: 11px;
}

.app-dialog {
  width: min(460px, calc(100% - 36px));
  padding: 0;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 24px 80px color-mix(in srgb, #000 35%, transparent);
}

.app-dialog::backdrop {
  background: color-mix(in srgb, #000 52%, transparent);
  backdrop-filter: blur(4px);
}

.app-dialog form {
  padding: 38px;
}

.app-dialog p:not(.eyebrow) {
  margin: 18px 0 28px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-line;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
}

.danger-button {
  min-height: 42px;
  padding: 0 18px;
  border: 1px solid #8e2f28;
  background: #8e2f28;
  color: #fff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 80;
  max-width: min(560px, calc(100% - 36px));
  transform: translateX(-50%);
  padding: 13px 18px;
  background: var(--ink);
  color: var(--paper);
  font-size: 11px;
  box-shadow: 0 12px 40px color-mix(in srgb, #000 28%, transparent);
}

@media (max-width: 1180px) {
  .book-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .reader-toolbar {
    grid-template-columns: auto 1fr;
  }

  .reader-book-name {
    display: none;
  }

  .reader-controls {
    flex-wrap: nowrap;
  }
}

@media (max-width: 840px) {
  .hero {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 38px;
  }

  .section-heading {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 18px;
  }

  .book-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .reader-controls .quiet-button {
    padding-inline: 9px;
  }
}

@media (max-width: 650px) {
  .app-view {
    padding-inline: 20px;
  }

  .app-header {
    min-height: 90px;
  }

  .header-actions .primary-button {
    width: 43px;
    overflow: hidden;
    padding: 0;
    gap: 20px;
    white-space: nowrap;
  }

  .header-actions .primary-button span {
    width: 43px;
    flex: 0 0 43px;
    text-align: center;
  }

  .hero h1 {
    font-size: clamp(48px, 15vw, 66px);
  }

  .book-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px;
  }

  .reader-toolbar {
    height: auto;
    min-height: 64px;
    padding-block: 9px;
  }

  .reader-controls {
    gap: 4px;
    overflow-x: auto;
    justify-self: stretch;
    justify-content: flex-end;
  }

  .reader-controls .icon-button,
  .reader-controls .quiet-button {
    min-height: 38px;
  }

  .reader-stage {
    height: calc(100vh - 106px);
  }

  .reader-status {
    padding-inline: 13px;
  }

  .reader-status > span {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
