@font-face {
  font-family: "Berkeley Mono Local";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src:
    local("Berkeley Mono Regular"),
    local("Berkeley Mono"),
    url("fonts/BerkeleyMono-Regular.woff2") format("woff2");
}

@font-face {
  font-family: "Berkeley Mono Local";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src:
    local("Berkeley Mono Italic"),
    local("Berkeley Mono"),
    url("fonts/BerkeleyMono-Italic.woff2") format("woff2");
}

@font-face {
  font-family: "Berkeley Mono Local";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src:
    local("Berkeley Mono Bold"),
    local("Berkeley Mono"),
    url("fonts/BerkeleyMono-Bold.woff2") format("woff2");
}

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/fraunces-latin-ext-full-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Fraunces";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/fraunces-latin-full-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/fraunces-latin-ext-full-italic.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Fraunces";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("fonts/fraunces-latin-full-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Literata";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/literata-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Literata";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/literata-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Literata";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/literata-latin-ext-wght-italic.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Literata";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("fonts/literata-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  --font-interface: "Berkeley Mono Local", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --font-heading: var(--font-interface);
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-reading: "Literata", "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --background: #ffffff;
  --surface: #f5f5f5;
  --surface-hover: #ececec;
  --text: #000000;
  --secondary: #666666;
  --inactive: #9a9a9a;
  --border: #dedede;
  --cover-border: #cfcfcf;
  --shadow: 0 12px 30px rgb(0 0 0 / 12%);
  --page-gutter: clamp(20px, 3vw, 40px);
  --content-gap: 24px;
  --section-padding: 24px;
  --heading-gap: 10px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #090909;
  --surface: #171717;
  --surface-hover: #242424;
  --text: #ffffff;
  --secondary: #9a9a9a;
  --inactive: #666666;
  --border: #2d2d2d;
  --cover-border: #454545;
  --shadow: 0 12px 30px rgb(0 0 0 / 45%);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--background);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: var(--font-interface);
  letter-spacing: 0;
}

body.reader-open {
  overflow: hidden;
}

button,
input,
select {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.site-shell {
  min-height: 100vh;
  overflow-x: clip;
  background: var(--background);
}

.site-header {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  padding: 16px var(--page-gutter);
}

.header-main {
  display: grid;
  grid-template-columns: 220px minmax(280px, 720px) auto;
  align-items: center;
  gap: 24px;
}

.brand {
  display: grid;
  justify-self: start;
  padding: 0;
  background: transparent;
  text-align: left;
  text-transform: uppercase;
}

.brand-title {
  display: block;
  background: #000000;
  color: #f2f1ef;
  font-family: var(--font-heading);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  padding: 9px 10px 8px;
}

.brand-subtitle {
  margin-top: 5px;
  color: var(--secondary);
  font-size: 12px;
  line-height: 1.2;
  text-transform: none;
}

.search-field {
  position: relative;
  display: block;
  width: 100%;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 14px;
  color: var(--secondary);
  transform: translateY(-50%);
}

.search-icon svg {
  width: 18px;
  height: 18px;
}

.search-field input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--background);
  padding: 0 14px 0 44px;
  font-size: 13px;
}

.search-field input::placeholder {
  color: var(--inactive);
}

.header-tools {
  display: flex;
  justify-self: end;
  align-items: center;
  gap: 8px;
}

.icon-button,
.rail-button,
.back-button {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
}

.icon-button:hover,
.rail-button:hover,
.back-button:hover {
  background: var(--surface-hover);
}

.icon-button:disabled,
.rail-button:disabled {
  cursor: default;
  color: var(--inactive);
}

.library-settings-control,
.reader-menu-control {
  position: relative;
}

.utility-menu,
.reader-menu {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  width: min(300px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--background);
  box-shadow: var(--shadow);
}

.utility-menu[hidden],
.reader-menu[hidden] {
  display: none;
}

.menu-heading {
  display: flex;
  min-height: 42px;
  align-items: center;
  margin: 0;
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  color: var(--secondary);
  font-size: 11px;
  text-transform: uppercase;
}

.menu-field {
  display: grid;
  gap: 8px;
  padding: 14px;
  color: var(--secondary);
  font-size: 11px;
  text-transform: uppercase;
}

.menu-field select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  padding: 0 10px;
  color: var(--text);
  font-size: 12px;
  text-transform: none;
}

.main-content {
  padding: 24px var(--page-gutter) 72px;
}

.main-content.is-category-index {
  padding-top: 0;
}

.main-content:focus {
  outline: 0;
}

.library-home {
  display: grid;
  gap: var(--content-gap);
}

.shelf-section,
.continue-section {
  min-width: 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: var(--section-padding);
}

.shelf-heading {
  display: flex;
  min-height: 28px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: var(--heading-gap);
}

.category-link,
.see-all {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text);
  text-transform: uppercase;
}

.category-link {
  min-width: 0;
  min-height: 40px;
  padding: 0;
  text-align: left;
}

.shelf-title {
  margin: 0;
  overflow: hidden;
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.category-chevron {
  display: none;
}

.see-all {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0;
  font-size: 11px;
}

.see-all svg,
.category-chevron svg,
.inline-icon svg {
  width: 16px;
  height: 16px;
}

.shelf-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.rail-controls {
  display: flex;
  gap: 6px;
}

.rail-button {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
}

.rail-button svg {
  width: 17px;
  height: 17px;
}

.book-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(128px, calc((100% - 98px) / 8));
  gap: 14px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.book-rail::-webkit-scrollbar {
  display: none;
}

.book-tile {
  display: grid;
  min-width: 0;
  align-content: start;
  scroll-snap-align: start;
  background: transparent;
  padding: 0;
  color: var(--text);
  text-align: left;
}

.cover-frame {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid var(--cover-border);
  background: var(--surface);
}

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

.book-title {
  margin-top: 7px;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 550;
  font-optical-sizing: auto;
  line-height: 1.3;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.book-copy {
  display: grid;
  min-width: 0;
}

.book-author,
.book-progress {
  margin-top: 3px;
  overflow: hidden;
  color: var(--secondary);
  font-size: 11px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-progress:empty {
  display: none;
}

.book-tile .book-chevron {
  display: none;
}

.book-tile:hover .book-title {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.continue-row {
  position: relative;
}

.continue-book {
  display: grid;
  width: 100%;
  grid-template-columns: 82px minmax(0, 1fr) 72px;
  gap: 18px;
  align-items: center;
  background: transparent;
  padding: 0;
  color: var(--text);
  text-align: left;
}

.continue-book > .inline-icon {
  justify-self: end;
}

.continue-remove {
  position: absolute;
  z-index: 2;
  top: 50%;
  right: 28px;
  transform: translateY(-50%);
}

.continue-cover {
  display: block;
  width: 82px;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid var(--cover-border);
  background: var(--surface);
}

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

.continue-copy {
  display: grid;
  min-width: 0;
}

.continue-title {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  font-optical-sizing: auto;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.continue-author,
.continue-progress-label {
  margin-top: 5px;
  color: var(--secondary);
  font-size: 11px;
}

.continue-progress {
  display: block;
  width: 100%;
  height: 2px;
  margin-top: 18px;
  overflow: hidden;
  background: var(--border);
}

.continue-progress span {
  display: block;
  height: 100%;
  background: var(--text);
}

.remove-reading-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 4px;
  background: transparent;
  color: var(--secondary);
}

.remove-reading-button:hover {
  background: var(--surface);
  color: var(--text);
}

.remove-reading-button svg {
  width: 17px;
  height: 17px;
}

.reading-book-entry {
  position: relative;
  min-width: 0;
}

.reading-book-entry .book-tile {
  width: 100%;
}

.reading-book-entry > .remove-reading-button {
  position: absolute;
  z-index: 2;
  top: 6px;
  right: 6px;
  border: 1px solid var(--border);
  background: var(--background);
}

.reading-book-entry > .remove-reading-button:hover {
  background: var(--surface);
}

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

.view-header {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
}

.view-header.without-back {
  grid-template-columns: minmax(0, 1fr);
}

.view-header-copy h1 {
  margin: 0;
  overflow: hidden;
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 600;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.view-header-copy p {
  margin: 4px 0 0;
  color: var(--secondary);
  font-size: 11px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 28px 14px;
  padding-top: 24px;
}

.results-grid.is-list {
  display: block;
  padding-top: 0;
}

.results-grid.is-list .book-tile {
  width: 100%;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
}

.results-grid.is-list .cover-frame {
  grid-row: 1;
  width: 46px;
}

.results-grid.is-list .book-copy {
  grid-column: 2;
  grid-row: 1;
  align-self: center;
}

.results-grid.is-list .book-title {
  min-height: 0;
  margin: 0;
  font-size: 15px;
}

.results-grid.is-list .book-author,
.results-grid.is-list .book-progress {
  margin-top: 2px;
}

.results-grid.is-list .book-chevron {
  display: grid;
  grid-column: 3;
  grid-row: 1;
  align-self: center;
}

.results-grid.is-list .book-chevron svg {
  width: 16px;
  height: 16px;
}

.results-grid.is-list .reading-book-entry {
  display: block;
  border-bottom: 1px solid var(--border);
}

.results-grid.is-list .reading-book-entry .book-tile {
  grid-template-columns: 46px minmax(0, 1fr) 72px;
  border-bottom: 0;
}

.results-grid.is-list .reading-book-entry .book-chevron {
  justify-self: end;
}

.results-grid.is-list .reading-book-entry > .remove-reading-button {
  top: 50%;
  right: 28px;
  border: 0;
  transform: translateY(-50%);
}

.category-index {
  margin-top: 0;
}

.category-row {
  display: grid;
  width: 100%;
  min-height: 72px;
  grid-template-columns: minmax(0, 1fr) 20px;
  gap: 16px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: transparent;
  padding: 0;
  color: var(--text);
  text-align: left;
}

.category-row-copy {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.category-row-title {
  display: block;
  overflow: hidden;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 600;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.category-row-count {
  display: block;
  color: var(--secondary);
  font-size: 11px;
}

.category-row svg {
  width: 16px;
  height: 16px;
}

.empty-state {
  display: grid;
  min-height: 45vh;
  place-content: center;
  gap: 8px;
  text-align: center;
}

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

.empty-state h2 {
  font-family: var(--font-heading);
  font-size: 19px;
  font-weight: 600;
  text-transform: uppercase;
}

.empty-state p {
  color: var(--secondary);
  font-size: 12px;
}

.secondary-button {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  padding: 0 16px;
  font-size: 11px;
  text-transform: uppercase;
}

.reader-view {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  min-width: 320px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--background);
  color: var(--text);
}

.reader-view[hidden] {
  display: none;
}

.reader-header {
  position: relative;
  z-index: 4;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  padding: 14px var(--page-gutter);
}

.reader-header-row {
  display: grid;
  min-height: 44px;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  grid-template-areas:
    "back spacer actions"
    "meta meta meta";
  column-gap: 18px;
  row-gap: 12px;
  align-items: center;
}

.reader-back {
  grid-area: back;
}

.reader-book-meta {
  grid-area: meta;
  min-width: 0;
}

.reader-header h1 {
  margin: 0;
  overflow: hidden;
  font-family: var(--font-heading);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.reader-header p {
  margin: 5px 0 0;
  overflow: hidden;
  color: var(--secondary);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-header-actions {
  grid-area: actions;
  display: flex;
  gap: 8px;
}

.reader-header-actions .icon-button {
  background: var(--background);
  border-color: var(--border);
}

.reader-header-actions .icon-button:hover,
.reader-header-actions .icon-button[aria-expanded="true"],
.reader-header-actions .icon-button.is-active {
  background: var(--surface);
}

.reader-header-actions .icon-button.is-loading {
  position: relative;
}

.reader-header-actions .icon-button.is-loading::after {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #bf8700;
  content: "";
}

.reader-font-button svg {
  width: 20px;
  height: 20px;
}

.reader-menu {
  width: 300px;
}

.chapters-menu {
  width: 380px;
}

.chapters-menu .menu-heading {
  min-height: 48px;
  padding-inline: 16px;
  font-size: 13px;
}

.language-option {
  display: block;
  width: 100%;
  min-height: 44px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  padding: 0 14px;
  color: var(--secondary);
  font-size: 12px;
  text-align: left;
}

.language-option:hover,
.language-option.is-selected {
  background: var(--surface);
  color: var(--text);
}

.language-option.is-selected::after {
  float: right;
  content: "✓";
}

.translation-engine-status,
.voice-engine-status {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 9px;
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  color: var(--secondary);
  font-size: 11px;
  line-height: 1.35;
  text-transform: uppercase;
}

.translation-status-dot,
.voice-status-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 7px;
  border-radius: 50%;
  background: var(--inactive);
}

.reader-menu[data-status="ready"] .translation-status-dot,
.reader-menu[data-status="ready"] .voice-status-dot,
.reader-menu[data-status="playing"] .voice-status-dot {
  background: #238636;
}

.reader-menu[data-status="loading"] .translation-status-dot,
.reader-menu[data-status="translating"] .translation-status-dot,
.reader-menu[data-status="loading"] .voice-status-dot,
.reader-menu[data-status="generating"] .voice-status-dot {
  background: #bf8700;
}

.reader-menu[data-status="error"] .translation-status-dot,
.reader-menu[data-status="error"] .voice-status-dot {
  background: #cf222e;
}

.translation-progress,
.voice-progress {
  display: block;
  width: calc(100% - 28px);
  height: 3px;
  margin: -1px 14px 12px;
  accent-color: var(--text);
}

.translation-progress[hidden],
.voice-progress[hidden] {
  display: none;
}

.chapters-list {
  max-height: min(520px, calc(100vh - 150px));
  overflow-y: auto;
}

.chapter-button {
  display: grid;
  width: 100%;
  min-height: 66px;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  padding: 12px 16px;
  color: var(--text);
  text-align: left;
}

.chapter-button:last-child {
  border-bottom: 0;
}

.chapter-button:hover,
.chapter-button.is-current {
  background: var(--surface);
}

.chapter-number {
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
  text-transform: uppercase;
}

.chapter-pages,
.chapter-duration {
  color: var(--secondary);
  font-size: 11px;
  line-height: 1.3;
  text-transform: uppercase;
}

.chapter-metrics {
  display: grid;
  min-width: 76px;
  gap: 3px;
  justify-items: end;
}

.chapter-title {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  color: var(--secondary);
  font-family: var(--font-display);
  font-size: 13px;
  font-style: italic;
  font-optical-sizing: auto;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-title:empty {
  display: none;
}

.reader-scroll {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  outline: 0;
  overscroll-behavior-y: contain;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}

.reader-scroll:focus-visible {
  box-shadow: inset 3px 0 0 var(--text);
}

.reader-message {
  display: grid;
  min-height: 50vh;
  place-items: center;
  color: var(--secondary);
  font-size: 12px;
  text-align: center;
}

.reader-message[hidden] {
  display: none;
}

.reader-article {
  width: min(700px, calc(100% - 48px));
  margin: 0 auto;
  padding: 52px 0 150px;
  font-family: var(--font-reading);
  font-size: var(--reader-font-size, 17px);
  font-weight: 400;
  font-optical-sizing: auto;
  line-height: 1.68;
}

.reader-article:empty {
  display: none;
}

.reader-chapter {
  scroll-margin-top: 32px;
}

.reader-chapter + .reader-chapter {
  margin-top: 64px;
  border-top: 1px solid var(--border);
  padding-top: 64px;
}

.reader-text {
  overflow-wrap: break-word;
}

.reader-paragraph {
  margin: 0;
  white-space: pre-wrap;
}

.reader-paragraph + .reader-paragraph {
  margin-top: 1.4em;
}

.reader-chapter-heading {
  font-family: var(--font-display);
  font-size: 1.45em;
  font-weight: 600;
  font-optical-sizing: auto;
  line-height: 1.25;
}

.reader-chapter-heading + .reader-paragraph {
  margin-top: 1.8em;
}

.reader-footer {
  position: relative;
  z-index: 3;
  background: var(--background);
  padding: 0 var(--page-gutter) env(safe-area-inset-bottom);
}

.reader-progress-track {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 1px;
  overflow: hidden;
  background: var(--border);
}

.reader-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--text);
  transition: width 120ms linear;
}

.reader-speech-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.reader-speech-status:empty {
  visibility: hidden;
}

.reader-audio-row {
  display: grid;
  width: min(480px, 100%);
  height: 68px;
  margin: 0 auto;
  grid-template-columns: repeat(5, minmax(44px, 1fr));
  align-items: center;
}

.reader-audio-button {
  position: relative;
  display: grid;
  width: 44px;
  height: 44px;
  justify-self: center;
  place-items: center;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
}

.reader-audio-button:hover {
  background: var(--surface);
}

.reader-audio-button:disabled {
  cursor: default;
  color: var(--inactive);
  opacity: 1;
}

.reader-audio-button svg {
  width: 28px;
  height: 28px;
}

.reader-play-button {
  width: 50px;
  height: 50px;
}

.reader-play-button svg {
  position: relative;
  z-index: 1;
  width: 38px;
  height: 38px;
  fill: currentColor;
  stroke: none;
}

#readerPrevious svg,
#readerNext svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
  stroke: none;
}

.reader-seek-button svg {
  width: 30px;
  height: 30px;
}

.reader-play-button.is-loading svg {
  visibility: hidden;
}

.reader-play-button.is-loading::before {
  position: absolute;
  width: 17px;
  height: 17px;
  border: 2px solid var(--inactive);
  border-top-color: var(--text);
  border-radius: 50%;
  content: "";
  animation: reader-loading 800ms linear infinite;
  z-index: 1;
}

.reader-seek-button::after {
  position: absolute;
  top: 16px;
  left: 0;
  width: 100%;
  content: "15";
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.reader-progress-label {
  display: none;
}

@keyframes reader-loading {
  to {
    transform: rotate(360deg);
  }
}

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

@media (max-width: 1040px) {
  .header-main {
    grid-template-columns: 180px minmax(240px, 1fr) auto;
    gap: 16px;
  }

  .book-rail {
    grid-auto-columns: calc((100% - 70px) / 6);
  }

  .reader-progress-label {
    display: none;
  }
}

@media (max-width: 700px) {
  :root {
    --page-gutter: 20px;
    --content-gap: 16px;
    --section-padding: 16px;
    --heading-gap: 8px;
  }

  .site-header {
    position: relative;
    padding: 16px var(--page-gutter);
  }

  .header-main {
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 12px;
    row-gap: 16px;
  }

  .brand-title {
    font-size: 20px;
  }

  .search-field {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .search-field input {
    height: 50px;
    font-size: 16px;
  }

  .header-tools {
    grid-column: 2;
    grid-row: 1;
  }

  .library-settings-menu {
    position: fixed;
    top: 64px;
    right: 16px;
    left: auto;
    width: min(300px, calc(100vw - 32px));
  }

  .main-content {
    padding-top: var(--content-gap);
    padding-bottom: 48px;
  }

  .main-content.is-category-index {
    padding-top: 0;
  }

  .rail-controls {
    display: none;
  }

  .view-header-copy h1 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-height: 1.2;
    white-space: normal;
  }

  .book-rail {
    margin-right: calc(var(--page-gutter) * -1);
    grid-auto-columns: 112px;
    gap: 10px;
    padding-right: var(--page-gutter);
  }

  .book-rail .book-progress {
    display: none;
  }

  .book-rail .book-title {
    margin-top: 6px;
    font-size: 14px;
    line-height: 1.25;
  }

  .book-rail .book-author {
    margin-top: 2px;
    font-size: 11px;
  }

  .shelf-title {
    display: -webkit-box;
    font-size: 14px;
    line-height: 1.25;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .see-all {
    min-height: 44px;
    font-size: 11px;
  }

  .continue-book {
    grid-template-columns: 76px minmax(0, 1fr) 68px;
    gap: 14px;
  }

  .continue-cover {
    width: 76px;
  }

  .continue-title {
    font-size: 18px;
    line-height: 1.25;
  }

  .continue-author,
  .continue-progress-label {
    font-size: 11px;
  }

  .continue-progress {
    margin-top: 13px;
  }

  .results-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px 10px;
    padding-top: 16px;
  }

  .results-grid:not(.is-category-grid):not(.is-list) .book-title {
    font-size: 14px;
  }

  .results-grid:not(.is-category-grid):not(.is-list) .book-author,
  .results-grid:not(.is-category-grid):not(.is-list) .book-progress,
  .results-grid.is-list .book-author,
  .results-grid.is-list .book-progress {
    font-size: 11px;
  }

  .results-grid.is-list .book-tile {
    grid-template-columns: 52px minmax(0, 1fr) auto;
    gap: 14px;
    min-height: 82px;
    padding: 8px 0 12px;
  }

  .results-grid.is-list .cover-frame {
    width: 52px;
  }

  .view-header {
    min-height: 72px;
    padding-bottom: 16px;
  }

  .view-header-copy p {
    font-size: 12px;
  }

  .view-header .back-button {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .reader-header {
    padding: 12px 16px;
  }

  .reader-header-row {
    grid-template-columns: 40px minmax(0, 1fr) auto;
    column-gap: 10px;
    row-gap: 12px;
  }

  .reader-header-actions {
    justify-content: flex-end;
  }

  .reader-header h1 {
    font-size: 22px;
  }

  .reader-header p {
    font-size: 14px;
  }

  .reader-menu {
    position: fixed;
    top: 132px;
    right: 16px;
    left: 16px;
    width: auto;
  }

  .chapters-menu {
    width: auto;
  }

  .chapters-list {
    max-height: calc(100dvh - 266px);
  }

  .chapter-button {
    min-height: 72px;
    padding: 14px 16px;
  }

  .chapter-number {
    font-size: 13px;
  }

  .chapter-pages,
  .chapter-duration {
    font-size: 12px;
  }

  .reader-article {
    width: calc(100% - 40px);
    padding: 38px 0 110px;
    line-height: 1.64;
  }

  .reader-chapter + .reader-chapter {
    margin-top: 48px;
    padding-top: 48px;
  }

  .reader-footer {
    padding-inline: 16px;
  }

  .reader-speech-status {
    right: 16px;
    left: 16px;
  }
}

@media (max-width: 430px) {
  .header-tools {
    gap: 6px;
  }

  .header-tools .icon-button {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .results-grid:not(.is-list) {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px 8px;
  }

  .results-grid:not(.is-category-grid):not(.is-list) .book-title,
  .results-grid.is-category-grid:not(.is-list) .book-title {
    font-size: 12px;
  }

  .results-grid:not(.is-list) .book-author,
  .results-grid:not(.is-list) .book-progress {
    font-size: 11px;
  }

  .category-row {
    min-height: 0;
    padding: 12px 0 16px;
  }

  .category-row-title {
    display: -webkit-box;
    line-height: 1.2;
    white-space: normal;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .reader-header-actions {
    gap: 6px;
  }

  .reader-header-actions .icon-button {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .reader-back {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }
}

@media (max-width: 360px) {
  :root {
    --page-gutter: 16px;
  }

  .results-grid:not(.is-list) {
    column-gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html,
  .reader-scroll {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
