:root {
  --ink: #172126;
  --muted: #617078;
  --line: #dbe4e5;
  --paper: #ffffff;
  --wash: #f4f8f7;
  --teal: #2f8f9d;
  --teal-dark: #17606b;
  --coral: #c95f4a;
  --shadow: 0 16px 40px rgba(23, 33, 38, .12);
  --app-brand-color: #3d75c5;
  --app-accent-color: #2f6fed;
  --app-library-background: #e1e4ea;
  --app-toolbar-background: #fbfbfc;
  --app-sidebar-background: #fff;
  --app-sidebar-active-background: #cfe4fb;
  --app-sidebar-active-text: #163b65;
  --app-text-color: #0b0f14;
  --app-muted-color: #4d5560;
  --app-reader-background: #e4e7ed;
  --app-reader-toolbar-background: #fbfbfc;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #eef2f5;
  --muted: #a7b0b7;
  --line: #343b43;
  --paper: #1b2027;
  --wash: #11151a;
  --teal: #70c9d4;
  --teal-dark: #8ad7df;
  --coral: #ff9f8c;
  --shadow: 0 16px 40px rgba(0, 0, 0, .32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--wash);
  font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] body:not(.reader-body) {
  background: var(--wash);
}

a {
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.site-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(219, 228, 229, .8);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
}

html[data-theme="dark"] .site-bar {
  border-bottom-color: rgba(52, 59, 67, .9);
  background: rgba(22, 26, 32, .92);
}

.brand {
  font-weight: 750;
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.site-nav a,
.filter-link,
.button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 13px;
  border-radius: 7px;
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 650;
  line-height: 1.2;
}

.site-nav a:hover,
.filter-link:hover {
  background: #e9f2f3;
}

html[data-theme="dark"] .site-nav a:hover,
html[data-theme="dark"] .filter-link:hover {
  background: #232a32;
}

.button {
  border-color: var(--app-accent-color, var(--teal-dark));
  background: var(--app-accent-color, var(--teal-dark));
  color: #fff;
  cursor: pointer;
}

.button.danger {
  border-color: #a33c2a;
  background: #a33c2a;
}

.button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

html[data-theme="dark"] .button.secondary {
  background: #20262e;
}

.site-nav form {
  margin: 0;
}

.site-nav button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 13px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 650;
}

html[data-theme="dark"] .site-nav button {
  border-color: var(--line);
  background: #20262e;
  color: var(--ink);
}

.flash {
  max-width: 1120px;
  margin: 14px auto 0;
  padding: 10px 14px;
  border: 1px solid #b8d8d5;
  border-radius: 7px;
  background: #e9f7f5;
  color: #124d54;
}

html[data-theme="dark"] .flash {
  border-color: #285b61;
  background: #143238;
  color: #d7fbff;
}

.hero {
  min-height: 320px;
  display: flex;
  align-items: flex-end;
  background: linear-gradient(90deg, #17333a, #2f8f9d);
  background-size: cover;
  background-position: center;
}

.hero-inner {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 76px 0 44px;
  color: #fff;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--coral);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.hero .eyebrow {
  color: #ffb49f;
}

.hero h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(36px, 7vw, 74px);
  line-height: .96;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 660px;
  margin: 18px 0 0;
  color: rgba(255, 255, 255, .9);
  font-size: 18px;
}

.library-shell,
.admin-shell,
.book-detail,
.locked-panel {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
}

.library-shell {
  padding: 22px 0 48px;
}

.library-toolbar,
.section-heading,
.form-actions,
.summary-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.filter-link {
  background: #fff;
  border-color: var(--line);
}

html[data-theme="dark"] .filter-link,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .book-card,
html[data-theme="dark"] .book-summary,
html[data-theme="dark"] .reader-panel,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .panel-form {
  background: var(--paper);
}

.filter-link.active {
  background: #dff0f1;
  color: var(--teal-dark);
  border-color: #b9dfe2;
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
  margin-top: 22px;
}

.book-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 2px 14px rgba(23, 33, 38, .05);
}

.cover-link {
  display: block;
  aspect-ratio: 3 / 4;
  background: #e7eeee;
  text-decoration: none;
}

html[data-theme="dark"] .cover-link {
  background: #242b33;
}

.cover-link img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--teal-dark);
  font-size: 72px;
  font-weight: 800;
}

.book-card-body {
  padding: 14px;
}

.book-card h2 {
  margin: 0 0 8px;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.book-card h2 a {
  text-decoration: none;
}

.book-card p {
  min-height: 72px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.book-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 750;
  text-transform: capitalize;
}

.book-meta span {
  padding: 4px 7px;
  border-radius: 7px;
  background: #eaf4f5;
}

.empty-state {
  margin-top: 24px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  text-align: center;
}

.empty-state h1,
.empty-state h2 {
  margin: 0 0 8px;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--muted);
}

.book-detail {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 24px;
  padding: 28px 0 48px;
}

.book-summary {
  align-self: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-cover {
  width: 100%;
  border-radius: 6px;
  margin-bottom: 16px;
}

.book-summary h1 {
  margin: 0 0 10px;
  font-size: 26px;
  line-height: 1.08;
  letter-spacing: 0;
}

.book-summary p {
  color: var(--muted);
}

.summary-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.reader-panel {
  min-height: 70vh;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.legacy-reader {
  width: 100%;
  height: 78vh;
  border: 0;
}

.native-pages {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.native-pages figure {
  margin: 0;
}

.native-pages img {
  width: min(100%, 900px);
  margin: 0 auto;
  border: 1px solid var(--line);
}

.external-book {
  min-height: 380px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
}

.admin-shell {
  padding: 32px 0 56px;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
}

.admin-heading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
}

td span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.table-actions {
  white-space: nowrap;
}

.table-actions a {
  margin-left: 10px;
  color: var(--teal-dark);
  font-weight: 700;
}

.panel-form {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.panel-form.compact {
  width: min(420px, 100%);
  margin: 80px auto;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.field-label {
  display: block;
  color: var(--ink);
  font-size: 14px;
  font-weight: 750;
}

.form-help {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d4d5;
  border-radius: 7px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  font: inherit;
}

html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  border-color: var(--line);
  background: #12171d;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.wide {
  grid-column: 1 / -1;
}

.asset-upload {
  display: grid;
  gap: 12px;
}

.asset-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(47, 143, 157, .06);
}

.asset-preview img {
  width: 86px;
  height: 116px;
  border-radius: 5px;
  object-fit: cover;
  background: #fff;
}

.asset-preview.compact img {
  width: 44px;
  height: 44px;
}

.asset-preview.wide-preview img {
  width: 160px;
  height: 90px;
}

.dropzone {
  position: relative;
  min-height: 112px;
  place-items: center;
  border: 1px dashed #9fb3b7;
  border-radius: 8px;
  padding: 18px;
  background: rgba(255, 255, 255, .62);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  overflow: hidden;
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.dropzone:focus-within {
  outline: 2px solid var(--app-accent-color, var(--teal-dark));
  outline-offset: 2px;
}

.dropzone-action {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  padding: 7px 13px;
  background: var(--app-accent-color, var(--teal-dark));
  color: #fff;
  font-weight: 800;
}

.dropzone-copy {
  color: var(--ink);
  font-weight: 800;
}

.dropzone small {
  color: var(--muted);
  font-weight: 600;
}

.dropzone-filename {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.settings-note {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(47, 143, 157, .08);
  color: var(--muted);
  font-size: 13px;
}

.category-picker {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(47, 143, 157, .06);
}

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

.category-option {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 11px;
  background: #fff;
  cursor: pointer;
}

.category-option input {
  width: auto;
}

.category-option:has(input:checked) {
  border-color: color-mix(in srgb, var(--app-accent-color, var(--teal-dark)) 55%, var(--line));
  background: color-mix(in srgb, var(--app-accent-color, var(--teal-dark)) 12%, #fff);
}

html[data-theme="dark"] .category-option {
  background: #12171d;
}

html[data-theme="dark"] .category-option:has(input:checked) {
  background: color-mix(in srgb, var(--app-accent-color, var(--teal-dark)) 20%, #12171d);
}

.settings-subsection {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(47, 143, 157, .06);
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 13px;
}

.color-grid input[type="color"] {
  height: 44px;
  padding: 4px;
  cursor: pointer;
}

.settings-password-form {
  margin-top: 20px;
}

.page-manager {
  margin-top: 20px;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.page-tile {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.page-tile img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: contain;
  background: #edf2f5;
}

.page-tile-footer {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.page-tile-footer span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.page-delete-button {
  min-height: 32px;
  border: 1px solid #d4b5ad;
  border-radius: 7px;
  background: #fff4f1;
  color: #8f321f;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(8, 12, 18, .62);
}

.modal-backdrop[hidden] {
  display: none;
}

.confirm-modal {
  width: min(440px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

.confirm-modal h2,
.confirm-modal p {
  margin: 0;
}

.confirm-modal-preview {
  width: 150px;
  max-height: 220px;
  object-fit: contain;
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #edf2f5;
}

html[data-theme="dark"] .page-tile,
html[data-theme="dark"] .confirm-modal {
  background: var(--paper);
}

.compact-heading {
  margin-bottom: 14px;
}

.compact-heading h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: auto;
}

.form-actions {
  justify-content: flex-start;
  margin-top: 18px;
}

.panel-form.is-processing {
  position: relative;
}

.panel-form.is-processing .form-actions .button[type="submit"] {
  opacity: .72;
  cursor: progress;
}

.submit-status {
  position: sticky;
  bottom: 16px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 13px 14px;
  border: 1px solid color-mix(in srgb, var(--app-accent-color, var(--teal-dark)) 45%, var(--line));
  border-radius: 8px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 12px 30px rgba(23, 33, 38, .12);
}

.submit-status[hidden] {
  display: none;
}

.submit-status strong,
.submit-status span {
  display: block;
}

.submit-status strong {
  color: var(--ink);
}

.submit-status [data-submit-message] {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.submit-spinner {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border: 3px solid color-mix(in srgb, var(--app-accent-color, var(--teal-dark)) 22%, transparent);
  border-top-color: var(--app-accent-color, var(--teal-dark));
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

html[data-theme="dark"] .submit-status {
  background: rgba(27, 32, 39, .96);
}

.delete-form {
  margin-top: 16px;
}

.delete-form button {
  border: 0;
  background: transparent;
  color: #a33c2a;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.page-message {
  width: min(620px, calc(100% - 32px));
  margin: 80px auto;
}

@media (max-width: 820px) {
  .site-bar,
  .library-toolbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .book-detail {
    grid-template-columns: 1fr;
  }

  .book-summary {
    display: grid;
    grid-template-columns: 130px minmax(0, 1fr);
    gap: 16px;
  }

  .book-summary h1,
  .book-summary p,
  .summary-actions {
    grid-column: 2;
  }

  .detail-cover {
    grid-row: 1 / span 3;
    margin: 0;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .hero {
    min-height: 280px;
  }

  .hero-inner {
    padding: 54px 0 32px;
  }

  .book-summary {
    display: block;
  }

  .detail-cover {
    margin-bottom: 16px;
  }

  .legacy-reader {
    height: 72vh;
  }
}

/* Kindle-inspired public library and reader surfaces. */
.immersive-main {
  min-height: 100vh;
}

body.library-body {
  overflow: hidden;
  background: var(--app-library-background);
  color: var(--app-text-color);
}

.library-app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  grid-template-rows: 60px minmax(0, 1fr);
}

.library-topbar {
  grid-column: 1 / -1;
  z-index: 20;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  align-items: center;
  border-bottom: 1px solid #c9ced7;
  background: var(--app-toolbar-background);
}

.library-brand {
  padding: 0 14px;
  color: var(--app-brand-color);
  font-size: 28px;
  font-weight: 400;
  line-height: 60px;
  text-decoration: none;
}

.library-controlbar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(220px, 336px) minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  padding: 0 18px 0 0;
}

.library-search input {
  height: 38px;
  border-color: #d4d7dd;
  border-radius: 3px;
  padding-left: 38px;
  background: #fff;
  box-shadow: none;
}

.library-search {
  position: relative;
  display: block;
}

.library-search::before {
  position: absolute;
  top: 50%;
  left: 13px;
  width: 12px;
  height: 12px;
  content: "";
  border: 2px solid var(--app-text-color);
  border-radius: 50%;
  transform: translateY(-58%);
  pointer-events: none;
}

.library-search::after {
  position: absolute;
  top: 25px;
  left: 26px;
  width: 8px;
  height: 2px;
  content: "";
  background: var(--app-text-color);
  transform: rotate(45deg);
  pointer-events: none;
}

.library-toolset {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

.toolbar-select {
  display: inline-flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 7px;
  color: var(--app-text-color);
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
}

.toolbar-select select {
  width: auto;
  min-width: 92px;
  height: 34px;
  border: 0;
  padding: 0 20px 0 4px;
  background-color: transparent;
  color: var(--app-text-color);
  font-size: 14px;
  font-weight: 650;
}

.toolbar-button,
.toolbar-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 5px 10px;
  background: transparent;
  color: var(--app-text-color);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.toolbar-button:hover,
.toolbar-link:hover {
  background: #eef0f4;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--app-text-color);
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}

.theme-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.theme-toggle span {
  position: relative;
  width: 38px;
  height: 20px;
  border: 1px solid #9da6b0;
  border-radius: 999px;
  background: #dbe0e7;
}

.theme-toggle span::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  content: "";
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .15s ease;
}

.theme-toggle input:checked + span {
  border-color: var(--app-accent-color);
  background: var(--app-accent-color);
}

.theme-toggle input:checked + span::after {
  transform: translateX(18px);
}

.theme-toggle input:focus-visible + span {
  outline: 2px solid var(--app-accent-color);
  outline-offset: 2px;
}

.library-sidebar {
  min-width: 0;
  padding: 22px 6px;
  border-right: 1px solid #c9ced7;
  background: var(--app-sidebar-background);
}

.sidebar-heading {
  padding: 0 22px 18px;
  color: var(--app-text-color);
  font-size: 14px;
  font-weight: 800;
}

.sidebar-nav {
  display: grid;
  gap: 4px;
}

.sidebar-nav a,
.sidebar-manage {
  display: flex;
  align-items: center;
  min-height: 50px;
  padding: 0 60px;
  border-radius: 4px;
  color: var(--app-text-color);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.sidebar-nav a.active {
  background: var(--app-sidebar-active-background);
  color: var(--app-sidebar-active-text);
  font-weight: 800;
}

.sidebar-nav a:hover,
.sidebar-manage:hover {
  background: #eef3f8;
}

.sidebar-manage {
  margin-top: 22px;
  color: var(--app-brand-color);
  font-weight: 750;
}

.library-content {
  min-width: 0;
  height: calc(100vh - 60px);
  overflow: auto;
  padding: 28px 36px 56px;
  background: var(--app-library-background);
}

.library-status {
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  color: var(--app-muted-color);
  font-size: 13px;
}

.library-status a {
  color: var(--app-accent-color);
  font-weight: 700;
  text-decoration: none;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 244px));
  align-items: start;
  justify-content: start;
  gap: 42px 38px;
}

.library-title-card {
  min-width: 0;
}

.library-cover-link {
  width: 100%;
  height: 318px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: visible;
  background: #f6f7f9;
  color: var(--app-accent-color);
  text-decoration: none;
}

.library-cover-link img {
  width: auto;
  max-width: 100%;
  height: 100%;
  object-fit: contain;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .32);
}

.library-title-meta {
  padding-top: 11px;
}

.library-title-meta h2 {
  margin: 0 0 3px;
  color: var(--app-text-color);
  font-size: 15px;
  font-weight: 800;
  line-height: 1.18;
  letter-spacing: 0;
}

.library-title-meta h2 a {
  color: inherit;
  text-decoration: none;
}

.library-kind {
  margin: 0;
  overflow: hidden;
  color: var(--app-text-color);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  text-transform: capitalize;
  white-space: nowrap;
}

.library-description {
  display: -webkit-box;
  margin: 7px 0 0;
  overflow: hidden;
  color: var(--app-muted-color);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: 0;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.library-grid[data-view="list"] {
  grid-template-columns: minmax(0, 760px);
  gap: 14px;
}

.library-grid[data-view="list"] .library-title-card {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  padding: 10px;
  background: rgba(255, 255, 255, .55);
}

.library-grid[data-view="list"] .library-cover-link {
  height: 126px;
}

.library-grid[data-view="list"] .library-cover-link img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.library-grid[data-view="list"] .library-title-meta {
  padding: 0;
}

.library-empty {
  width: min(520px, 100%);
  margin: 12vh auto 0;
  text-align: center;
}

.library-empty h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 0;
}

.library-empty p {
  margin: 0;
  color: var(--app-muted-color);
}

html[data-theme="dark"] body.library-body {
  background: #12161c;
  color: #f1f4f7;
}

html[data-theme="dark"] .library-topbar {
  border-bottom-color: #303842;
  background: #171b21;
}

html[data-theme="dark"] .library-brand {
  color: #7fb0ff;
}

html[data-theme="dark"] .library-search input {
  border-color: #3a424c;
  background: #0f1318;
  color: #f1f4f7;
}

html[data-theme="dark"] .library-search input::placeholder {
  color: #9aa4ae;
}

html[data-theme="dark"] .library-search::before {
  border-color: #e5e9ee;
}

html[data-theme="dark"] .library-search::after {
  background: #e5e9ee;
}

html[data-theme="dark"] .toolbar-select,
html[data-theme="dark"] .toolbar-select select,
html[data-theme="dark"] .toolbar-button,
html[data-theme="dark"] .toolbar-link,
html[data-theme="dark"] .theme-toggle {
  color: #f1f4f7;
}

html[data-theme="dark"] .toolbar-button:hover,
html[data-theme="dark"] .toolbar-link:hover {
  background: #232a33;
}

html[data-theme="dark"] .theme-toggle span {
  border-color: #4b5663;
  background: #2a313a;
}

html[data-theme="dark"] .library-sidebar {
  border-right-color: #303842;
  background: #171b21;
}

html[data-theme="dark"] .sidebar-heading,
html[data-theme="dark"] .sidebar-nav a {
  color: #f1f4f7;
}

html[data-theme="dark"] .sidebar-nav a.active {
  background: #1f3f62;
  color: #d7e9ff;
}

html[data-theme="dark"] .sidebar-nav a:hover {
  background: #232a33;
}

html[data-theme="dark"] .library-content {
  background: #11161d;
}

html[data-theme="dark"] .library-status {
  color: #aeb7c0;
}

html[data-theme="dark"] .library-status a {
  color: #8ebeff;
}

html[data-theme="dark"] .library-cover-link {
  background: #202832;
  color: #b9d7ff;
  box-shadow: 0 2px 9px rgba(0, 0, 0, .7);
}

html[data-theme="dark"] .library-title-meta h2,
html[data-theme="dark"] .library-kind {
  color: #f1f4f7;
}

html[data-theme="dark"] .library-description {
  color: #aeb7c0;
}

html[data-theme="dark"] .library-grid[data-view="list"] .library-title-card {
  background: rgba(255, 255, 255, .06);
}

html[data-theme="dark"] .library-empty p {
  color: #aeb7c0;
}

body.reader-body {
  overflow: hidden;
  background: var(--app-reader-background);
  color: var(--app-text-color);
}

.reader-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: 62px minmax(0, 1fr);
  background: var(--app-reader-background);
}

.reader-topbar {
  display: grid;
  grid-template-columns: minmax(126px, 220px) minmax(0, 1fr) minmax(80px, 220px);
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid #c9ced7;
  padding: 0 22px;
  background: var(--app-reader-toolbar-background);
}

.reader-topbar h1 {
  margin: 0;
  display: -webkit-box;
  overflow: hidden;
  color: var(--app-text-color);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.18;
  letter-spacing: 0;
  text-align: center;
  text-transform: uppercase;
  text-wrap: balance;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.reader-topbar h1[data-balanced-title="true"] {
  display: block;
}

.reader-topbar h1[data-balanced-title="true"] span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-library-link,
.reader-actions a,
.reader-open-link {
  justify-self: start;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d9d9d9;
  border-radius: 18px;
  padding: 5px 14px;
  color: var(--app-text-color);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

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

.reader-stage {
  min-height: 0;
  overflow: hidden;
  background: var(--app-reader-background);
}

.native-reader {
  height: 100%;
}

.native-viewport {
  height: 100%;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 28px 18px 86px;
}

.native-spread {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  max-width: 100%;
}

.native-page-wrap {
  position: relative;
  width: min(100%, 1080px);
  flex: 0 0 auto;
  transform-origin: center center;
}

.native-viewport img {
  display: block;
  width: 100%;
  height: auto;
  background: #fff;
  box-shadow: 0 3px 18px rgba(0, 0, 0, .25);
}

.native-link-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.native-page-link {
  position: absolute;
  display: block;
  border-radius: 4px;
  background: rgba(47, 111, 237, 0);
  touch-action: manipulation;
}

.native-page-link:hover,
.native-page-link:focus-visible {
  outline: 2px solid var(--app-accent-color);
  background: color-mix(in srgb, var(--app-accent-color) 12%, transparent);
}

.native-reader.is-turning-next .native-page-wrap {
  animation: nativePageNext 190ms ease-out both;
}

.native-reader.is-turning-prev .native-page-wrap {
  animation: nativePagePrev 190ms ease-out both;
}

@keyframes nativePageNext {
  from {
    opacity: .75;
    transform: translateX(16px) scale(.992);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes nativePagePrev {
  from {
    opacity: .75;
    transform: translateX(-16px) scale(.992);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .native-reader.is-turning-next .native-page-wrap,
  .native-reader.is-turning-prev .native-page-wrap {
    animation: none;
  }
}

.native-controls {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  min-height: 58px;
  min-height: calc(58px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-top: 1px solid #c9ced7;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(247, 248, 250, .96);
  backdrop-filter: blur(10px);
}

.native-controls button {
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  border: 1px solid #b8c0ca;
  border-radius: 50%;
  padding: 0;
  background: #fff;
  color: var(--app-text-color);
  font: inherit;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.native-icon-button {
  display: inline-grid;
  place-items: center;
}

.native-icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.native-controls button:disabled {
  cursor: default;
  opacity: .45;
}

.native-controls span {
  min-width: 68px;
  color: var(--app-text-color);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.native-controls [data-native-zoom-label] {
  min-width: 44px;
}

.reader-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--app-reader-background);
}

.reader-empty {
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  color: var(--app-text-color);
  text-align: center;
}

.reader-empty h2,
.reader-empty p {
  margin: 0;
}

html[data-theme="dark"] body.reader-body {
  background: #000;
  color: #f5f5f5;
}

html[data-theme="dark"] .reader-shell,
html[data-theme="dark"] .reader-stage,
html[data-theme="dark"] .reader-frame {
  background: #000;
}

html[data-theme="dark"] .native-viewport img {
  box-shadow: 0 3px 18px rgba(0, 0, 0, .75);
}

html[data-theme="dark"] .native-controls {
  border-top-color: #282828;
  background: rgba(5, 5, 5, .94);
}

html[data-theme="dark"] .native-controls button {
  border-color: #3a3a3a;
  background: #111;
  color: #fff;
}

html[data-theme="dark"] .native-controls span {
  color: #fff;
}

html[data-theme="dark"] .reader-topbar {
  border-bottom-color: #282828;
  background: #050505;
}

html[data-theme="dark"] .reader-topbar h1,
html[data-theme="dark"] .reader-library-link,
html[data-theme="dark"] .reader-actions a,
html[data-theme="dark"] .reader-open-link,
html[data-theme="dark"] .reader-empty {
  color: #fff;
}

@media (max-width: 920px) {
  body.library-body {
    overflow: auto;
  }

  .library-app {
    display: block;
  }

  .library-topbar {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px 14px;
  }

  .library-brand {
    padding: 0;
    line-height: 1.1;
  }

  .library-controlbar {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .library-toolset {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .library-sidebar {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid #c9ced7;
  }

  .sidebar-heading {
    padding: 0 8px 0 0;
    white-space: nowrap;
  }

  .sidebar-nav {
    display: flex;
    gap: 6px;
  }

  .sidebar-nav a,
  .sidebar-manage {
    min-height: 38px;
    padding: 0 14px;
    white-space: nowrap;
  }

  .sidebar-manage {
    margin: 0;
  }

  .library-content {
    height: auto;
    min-height: 70vh;
    overflow: visible;
    padding: 22px 18px 42px;
  }

  .library-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
    gap: 26px 18px;
  }

  .library-cover-link {
    height: clamp(220px, 58vw, 300px);
  }
}

@media (max-width: 640px) {
  .reader-shell {
    grid-template-rows: 54px minmax(0, 1fr);
  }

  .reader-topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 0 8px;
  }

  .reader-topbar h1 {
    font-size: 13px;
  }

  .reader-library-link,
  .reader-actions a,
  .reader-actions .theme-toggle {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 12px;
  }

  .reader-actions .theme-toggle span {
    width: 32px;
    height: 18px;
  }

  .reader-actions .theme-toggle span::after {
    width: 12px;
    height: 12px;
  }

  .reader-actions .theme-toggle input:checked + span::after {
    transform: translateX(14px);
  }

  .native-viewport {
    padding: 10px 0 calc(76px + env(safe-area-inset-bottom));
  }

  .native-spread {
    gap: 0;
  }

  .native-page-wrap {
    width: 100%;
  }

  .native-viewport img {
    box-shadow: 0 2px 12px rgba(0, 0, 0, .2);
  }

  .native-controls {
    gap: 5px;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  }

  .native-controls button {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
  }
}
