@import url("https://fonts.googleapis.com/css2?family=EB+Garamond:wght@400;500;600;700&family=Literata:opsz,wght@7..72,400;7..72,600;7..72,700&family=Merriweather:opsz,wght@18..144,400;18..144,600;18..144,700&display=swap");

:root {
  /* Reader app — Light */
  --bg: #fffdfa;
  --paper: #fffdfa;
  --text: #25231f;
  --muted: #817b72;
  --line: #e4dfd7;
  --link: #556f90;
  --reader-size: 19px;
  --reader-font: Georgia, "Times New Roman", serif;
  color-scheme: light;
}

:root[data-theme="sepia"] {
  /* Reader app — Sepia */
  --bg: #f4eddf;
  --paper: #f8f2e7;
  --text: #3e372f;
  --muted: #817466;
  --line: #ddd0bc;
  --link: #556f90;
  color-scheme: light;
}

:root[data-theme="grey"] {
  /* Reader app — Grey. Keep this exact blue-grey. */
  --bg: #e6ecf2;
  --paper: #eef3f7;
  --text: #27313a;
  --muted: #687785;
  --line: #ccd6df;
  --link: #526f91;
  color-scheme: light;
}

:root[data-theme="dark"] {
  /* Reader app — Dark */
  --bg: #181817;
  --paper: #211f1c;
  --text: #f2efe8;
  --muted: #aaa49a;
  --line: #39352f;
  --link: #aabbd0;
  color-scheme: dark;
}

:root[data-theme="eink"] {
  /* Reader app — E-Ink */
  --bg: #ffffff;
  --paper: #ffffff;
  --text: #000000;
  --muted: #555555;
  --line: #d1d1d1;
  --link: #000000;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { color: inherit; cursor: pointer; background: none; border: 0; }

.topbar {
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0;
  font-weight: 700;
}

.brandIcon {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.topActions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topButton,
.primary {
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 8px;
}

.topButton:hover,
.quietButton:hover,
.backButton:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

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

.aaButton {
  min-width: 42px;
  font-family: Georgia, serif;
  font-weight: 600;
}

#welcome {
  max-width: 760px;
  margin: auto;
  padding: 14vh 24px;
}

#welcome h1,
.libraryHead h1 {
  font: 500 clamp(40px, 6vw, 66px) / 1.04 Georgia, serif;
  margin: 0;
}

#welcome > p:not(.kicker) {
  font-size: 19px;
  line-height: 1.6;
  color: var(--muted);
  max-width: 620px;
}

.kicker {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
  color: var(--muted);
}

#status {
  margin-top: 18px;
  color: var(--muted);
}

#library {
  max-width: 1160px;
  margin: auto;
  padding: 50px 24px 100px;
}

.libraryHead {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin-bottom: 34px;
}

.libraryHead h1 { font-size: 42px; }

.quietButton {
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 30px 24px;
}

.book { text-align: left; }

.cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: 0 10px 25px #0002;
  display: grid;
  place-items: center;
  padding: 18px;
  font: 22px/1.15 Georgia, serif;
  text-align: center;
}

.book strong {
  display: block;
  font: 600 18px Georgia, serif;
  margin-top: 12px;
}

.book span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-top: 4px;
}

#reader article {
  width: min(760px, calc(100% - 48px));
  margin: auto;
  padding: 44px 0 120px;
}

.backButton {
  color: var(--muted);
  padding: 6px 8px;
  margin: -6px 0 42px -8px;
  border-radius: 7px;
}

#bookHead {
  padding-bottom: 40px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 46px;
}

#bookHead h1 {
  font: 500 clamp(44px, 8vw, 68px) / 1.03 var(--reader-font);
  margin: 0;
}

#bookHead .sub {
  font: 24px/1.35 var(--reader-font);
  color: var(--muted);
  margin: 12px 0;
}

#bookHead .by { color: var(--muted); }

#content {
  font-family: var(--reader-font);
  font-size: var(--reader-size);
  line-height: 1.72;
}

#content p { margin: 0 0 1.35em; }

#content h1,
#content h2,
#content h3 {
  scroll-margin-top: 80px;
  line-height: 1.16;
}

#content h1 {
  font-size: 2.1em;
  margin: 2.2em 0 .7em;
}

#content h2 {
  font-size: 1.55em;
  margin: 2em 0 .6em;
}

#content h3 {
  font-size: 1.2em;
  margin: 1.8em 0 .5em;
}


#content a {
  color: var(--link);
}

#content blockquote {
  margin: 1.8em 0;
  padding: .1em 0 .1em 1.2em;
  border-left: 2px solid var(--line);
  color: var(--muted);
}

#content ul,
#content ol {
  margin: 1.15em 0 1.55em 1.35em;
  padding: 0;
}

#content li {
  margin: .45em 0;
  padding-left: .22em;
}

#content li::marker { color: var(--muted); }

#content blockquote.callout {
  margin: 2em 0;
  padding: 18px 22px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--text);
  border-radius: 8px;
  background: var(--paper);
  color: var(--text);
}

#content .callout-label {
  margin: 0 0 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--muted);
}

#content blockquote.callout p:last-child { margin-bottom: 0; }

#content .footnote-ref {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: .62em;
  line-height: 0;
  vertical-align: super;
  margin-left: 0;
}

#content .footnote-ref a {
  text-decoration: none;
  color: var(--muted);
}

#content .footnotes {
  margin-top: 5em;
  padding-top: 2em;
  border-top: 1px solid var(--line);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: var(--muted);
}

#content .footnotes h2 {
  margin: 0 0 1.2em;
  font-family: var(--reader-font);
  font-size: 1.65em;
  color: var(--text);
}

#content .footnotes ol { margin-left: 1.4em; }

#content .footnotes li {
  margin: 0 0 .9em;
  padding-left: .35em;
}

#content .footnote-back {
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
}

/* Contents drawer */
#toc {
  position: fixed;
  left: 0;
  top: 58px;
  bottom: 0;
  z-index: 60;
  width: min(390px, 88vw);
  padding: 24px 22px 34px;
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--line);
  box-shadow: 10px 0 30px #0002;
  transform: translateX(-102%);
  transition: transform .18s ease;
}

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

.tocHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.tocHeader strong {
  font-family: Georgia, serif;
  font-size: 22px;
  font-weight: 600;
}

.closeButton {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 25px;
  line-height: 1;
  color: var(--muted);
}

.closeButton:hover {
  background: var(--bg);
  color: var(--text);
}

#tocLinks {
  display: grid;
  gap: 1px;
}

#tocLinks a {
  color: inherit;
  text-decoration: none;
  border-radius: 7px;
  padding: 8px 9px;
  line-height: 1.28;
}

#tocLinks a:hover {
  background: var(--bg);
}

#tocLinks .h1 {
  font-size: 17px;
  font-weight: 650;
}

#tocLinks .h2 {
  padding-left: 22px;
  font-size: 16px;
}

#tocLinks .h3 {
  padding-left: 36px;
  color: var(--muted);
  font-size: 15px;
}

.tocBackdrop {
  position: fixed;
  inset: 58px 0 0 0;
  z-index: 50;
  width: 100%;
  height: calc(100vh - 58px);
  padding: 0;
  background: rgba(0, 0, 0, .28);
}

/* Reading settings */
.settingsDialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--text);
  box-shadow: 0 18px 60px #0004;
}

.settingsDialog::backdrop {
  background: rgba(0, 0, 0, .3);
}

.settingsDialog form {
  display: grid;
  gap: 22px;
  padding: 20px;
}

.dialogHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialogHeader strong {
  font-size: 18px;
}

.settingsDialog fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.settingsDialog legend {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

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

.choiceRow button {
  min-width: 58px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.choiceRow button[aria-pressed="true"] {
  border-color: var(--text);
  background: var(--text);
  color: var(--paper);
}

.settingNote {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.dialogFooter {
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.dangerButton {
  padding: 8px 0 0;
  color: #a94d45;
}

@media (max-width: 640px) {
  .topbar {
    height: 54px;
    padding: 0 14px;
  }

  .brand span {
    display: none;
  }

  .brandIcon {
    width: 25px;
    height: 25px;
  }

  .topButton {
    padding: 7px 9px;
    font-size: 14px;
  }

  #grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 25px 15px;
  }

  #library { padding: 34px 18px 80px; }

  #reader article {
    width: calc(100% - 34px);
    padding-top: 30px;
  }

  #toc {
    top: 54px;
  }

  .tocBackdrop {
    inset: 54px 0 0 0;
    height: calc(100vh - 54px);
  }
}


/* v0.1.4 — bookmarks, highlights, and footnote sheets */

.libraryActions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.iconOnlyButton {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 38px;
  padding: 0;
}

.iconOnlyButton svg {
  width: 19px;
  height: 19px;
}

.bookmarkButton.active svg {
  fill: currentColor;
}

#content mark.user-highlight {
  background: color-mix(in srgb, #f0cf63 58%, transparent);
  color: inherit;
  border-radius: 2px;
  padding: .02em .04em;
  margin: 0 -.04em;
  cursor: pointer;
}

:root[data-theme="dark"] #content mark.user-highlight {
  background: color-mix(in srgb, #d8ad38 48%, transparent);
}

/* Keep the visual superscript tiny, but make the real mobile hit target large. */
.footnote-ref {
  position: relative;
}

@media (pointer: coarse) {
  .footnote-ref a::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 44px;
    height: 44px;
    transform: translate(-50%, -50%);
  }

  #content .footnote-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    margin: -12px -10px;
  }
}

.noteDialog,
.savedDialog {
  width: min(560px, calc(100vw - 32px));
  max-height: min(76vh, 720px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--text);
  box-shadow: 0 18px 60px #0004;
}

.noteDialog::backdrop,
.savedDialog::backdrop {
  background: rgba(0, 0, 0, .30);
}

.noteDialog form,
.savedDialog form {
  padding: 20px;
}

.noteDialogBody {
  font: 17px/1.6 var(--reader-font);
}

.noteDialogBody p {
  margin: 0;
}

.noteDialogFooter {
  display: flex;
  justify-content: flex-end;
}

.savedDialog form {
  display: grid;
  gap: 16px;
}

.savedList {
  display: grid;
  gap: 10px;
  overflow-y: auto;
  max-height: calc(76vh - 90px);
}

.savedEmpty {
  color: var(--muted);
  padding: 8px 0 18px;
}

.savedItem {
  position: relative;
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 13px 48px 13px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
  text-align: left;
}

.savedItem:hover {
  border-color: color-mix(in srgb, var(--text) 35%, var(--line));
}

.savedItemBook {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  color: var(--muted);
}

.savedItemTitle {
  font-size: 15px;
  font-weight: 650;
}

.savedItemQuote {
  font-family: var(--reader-font);
  font-size: 15px;
  line-height: 1.45;
}

.savedItemDelete {
  position: absolute;
  right: 8px;
  top: 8px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--muted);
}

.savedItemDelete:hover {
  background: var(--paper);
  color: #a94d45;
}

.highlightQuote {
  margin: 10px 0 20px;
  padding-left: 15px;
  border-left: 2px solid var(--line);
  font: 18px/1.55 var(--reader-font);
}

.selectionToolbar {
  position: fixed;
  left: 50%;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px));
  z-index: 90;
  transform: translateX(-50%);
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
  box-shadow: 0 10px 35px #0003;
}

.selectionToolbar button {
  min-width: 96px;
  min-height: 42px;
  padding: 8px 15px;
  border-radius: 7px;
  background: var(--text);
  color: var(--paper);
  font-weight: 650;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  z-index: 120;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: 9px;
  background: var(--text);
  color: var(--paper);
  box-shadow: 0 10px 30px #0003;
  text-align: center;
  font-size: 14px;
}

@media (max-width: 640px) {
  .libraryHead {
    align-items: flex-start;
    gap: 18px;
  }

  .libraryActions {
    gap: 0;
  }

  .libraryActions .quietButton {
    padding-left: 7px;
    padding-right: 7px;
    font-size: 13px;
  }

  .noteDialog,
  .savedDialog {
    width: 100vw;
    max-width: none;
    max-height: 72vh;
    margin: auto 0 0 0;
    border-radius: 16px 16px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .noteDialog form,
  .savedDialog form {
    padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  }

  .noteDialogBody {
    font-size: 17px;
  }

  .savedList {
    max-height: calc(72vh - 96px);
  }
}


/* v0.1.5 — cached library + in-book annotation tabs */

.drawerTabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  margin: 0 0 18px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--bg);
}

.drawerTab {
  min-width: 0;
  padding: 8px 7px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.drawerTab.active {
  background: var(--paper);
  color: var(--text);
  box-shadow: 0 1px 3px #0001;
}

.drawerPane[hidden] {
  display: none !important;
}

.drawerEmpty {
  padding: 12px 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.drawerSavedItem {
  position: relative;
  display: grid;
  gap: 4px;
  width: 100%;
  margin-bottom: 7px;
  padding: 10px 42px 10px 10px;
  border-radius: 8px;
  text-align: left;
  line-height: 1.32;
}

.drawerSavedItem:hover {
  background: var(--bg);
}

.drawerSavedItemTitle {
  font-size: 15px;
  font-weight: 650;
}

.drawerSavedItemQuote {
  font: 14px/1.42 var(--reader-font);
  color: var(--muted);
}

.drawerSavedDelete {
  position: absolute;
  right: 4px;
  top: 4px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  color: var(--muted);
}

.drawerSavedDelete:hover {
  background: var(--paper);
  color: #a94d45;
}

.libraryRefreshing::after {
  content: "Checking Dropbox…";
  display: block;
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 640px) {
  .drawerTab {
    font-size: 13px;
    padding-left: 4px;
    padding-right: 4px;
  }
}


/* v0.1.6 — in-place highlight control + visible bookmark markers */

#content h1,
#content h2,
#content h3 {
  position: relative;
}

.pageBookmarkMarker {
  position: absolute;
  left: -36px;
  top: .08em;
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 7px;
  color: var(--muted);
}

.pageBookmarkMarker:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
  color: var(--text);
}

.pageBookmarkMarker svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.savedBookmarkIcon {
  display: inline-block;
  width: 15px;
  height: 15px;
  margin-right: 6px;
  vertical-align: -2px;
  fill: currentColor;
}

.selectionToolbar {
  bottom: auto;
  transform: none;
  transition: opacity .08s ease;
}

.selectionToolbar.fallbackBottom {
  left: 50% !important;
  top: auto !important;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 12px)) !important;
  transform: translateX(-50%);
}

@media (max-width: 640px) {
  .pageBookmarkMarker {
    position: static;
    display: inline-grid;
    width: 27px;
    height: 27px;
    margin: 0 7px 0 -2px;
    vertical-align: .06em;
  }

  .pageBookmarkMarker svg {
    width: 17px;
    height: 17px;
  }
}


/* v0.1.7 — highlights must never alter text spacing */
#content mark.user-highlight {
  line-height: inherit;
}


/* v0.1.8 — Library alignment, mobile layout, and Dropbox recovery */

[hidden] {
  display: none !important;
}

/* The app name is already in the top bar; the Library page only needs its page title. */
#library {
  max-width: 1040px;
  padding-top: 42px;
}

.libraryHead {
  align-items: center;
  margin-bottom: 30px;
}

.libraryHead h1 {
  margin: 0;
  font: 600 30px/1.1 Georgia, "Times New Roman", serif;
}

.libraryActions {
  gap: 7px;
}

.libraryActionButton {
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.libraryActionButton:hover,
.libraryActionButton:focus-visible {
  border-color: var(--line);
  background: var(--paper);
  color: var(--text);
}

/* Fixed-width desktop cards prevent a two-book library from stretching across
   huge columns. Titles reserve two lines so authors stay aligned. */
#grid {
  grid-template-columns: repeat(auto-fill, 190px);
  gap: 34px 28px;
  align-items: start;
  justify-content: start;
}

.book {
  width: 190px;
  display: flex;
  flex-direction: column;
  align-self: start;
  text-align: left;
}

.coverFrame {
  width: 100%;
  aspect-ratio: 2 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  box-shadow: 0 9px 24px #00000018;
}

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

.coverPlaceholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  padding: 14px;
  text-align: center;
  font: 21px/1.15 Georgia, "Times New Roman", serif;
}

.bookMeta {
  padding-top: 12px;
}

.bookTitle {
  display: block;
  min-height: 2.32em;
  margin: 0;
  font: 600 18px/1.16 Georgia, "Times New Roman", serif;
}

.bookAuthor {
  display: block;
  min-height: 1.25em;
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.25;
}

/* Old .cover rules are retained for backwards safety, but new cards use the
   coverFrame/coverImage structure above. */
.book .cover {
  padding: 0;
}

/* Recoverable Dropbox errors stay compact instead of replacing the Library. */
.libraryNotice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: -8px 0 26px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.libraryNoticeActions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
}

.libraryNoticeActions button,
.secondaryButton {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--bg);
}

.libraryNoticeActions button:hover,
.secondaryButton:hover {
  border-color: color-mix(in srgb, var(--text) 35%, var(--line));
  color: var(--text);
}

.connectionDialog {
  width: min(430px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--text);
  box-shadow: 0 18px 60px #0004;
}

.connectionDialog::backdrop {
  background: rgba(0, 0, 0, .3);
}

.connectionDialog form {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.connectionStatus {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.connectionActions {
  display: grid;
  gap: 8px;
}

.connectionActions button {
  width: 100%;
  min-height: 42px;
  text-align: center;
}

.borderedDangerButton {
  padding: 8px 10px;
  border: 1px solid color-mix(in srgb, #a94d45 38%, var(--line));
  border-radius: 7px;
  background: transparent;
}

.libraryRefreshing::after {
  content: "Checking Dropbox…";
  margin-top: 12px;
}

@media (max-width: 640px) {
  #library {
    padding: 26px 16px 70px;
  }

  .libraryHead {
    display: block;
    margin-bottom: 24px;
  }

  .libraryHead h1 {
    font-size: 27px;
  }

  .libraryActions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin-top: 15px;
  }

  .libraryActionButton {
    width: 100%;
    min-height: 44px;
    padding: 8px 7px;
    border-color: var(--line);
    background: color-mix(in srgb, var(--paper) 72%, transparent);
    text-align: center;
    font-size: 14px;
  }

  #grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 28px 14px;
  }

  .book {
    width: 100%;
    min-width: 0;
  }

  .coverFrame {
    padding: 7px;
    border-radius: 4px;
  }

  .bookMeta {
    padding-top: 9px;
  }

  .bookTitle {
    min-height: 2.45em;
    font-size: 16px;
    line-height: 1.2;
  }

  .bookAuthor {
    margin-top: 4px;
    font-size: 13px;
  }

  .libraryNotice {
    display: block;
    margin: -5px 0 22px;
    padding: 12px;
  }

  .libraryNoticeActions {
    margin-top: 10px;
  }

  .libraryNoticeActions button {
    flex: 1 1 0;
    min-height: 42px;
  }

  .connectionDialog {
    width: 100vw;
    max-width: none;
    margin: auto 0 0 0;
    border-radius: 16px 16px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }

  .connectionDialog form {
    padding: 20px 18px calc(22px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 350px) {
  #library {
    padding-left: 12px;
    padding-right: 12px;
  }

  #grid {
    gap-left: 10px;
    gap-right: 10px;
    column-gap: 10px;
  }

  .bookTitle {
    font-size: 15px;
  }
}


/* v0.1.9 — lock the mobile reader to the viewport */

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  overscroll-behavior-x: none;
}

body {
  touch-action: pan-y pinch-zoom;
}

main,
#reader,
#reader article,
#bookHead,
#content {
  min-width: 0;
  max-width: 100%;
}

#reader {
  overflow-x: hidden;
}

/* Long source URLs and other unbroken strings in notes must never widen the
   document. A single long URL at the bottom of a commentary can otherwise
   make the entire page horizontally pannable on iOS Safari. */
#content a,
#content .footnotes a,
#content code,
#content pre {
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

#content img,
#content video,
#content iframe,
#content table {
  max-width: 100%;
}

#content pre {
  white-space: pre-wrap;
}

@media (max-width: 640px) {
  /* Keep the app identity visible on normal phones. It was deliberately
     hidden in earlier builds, not disappearing because of dark mode. */
  .brand span {
    display: inline;
    font-size: 15px;
  }

  .topbar {
    padding-left: 12px;
    padding-right: 12px;
  }

  .brand {
    gap: 7px;
    min-width: 0;
  }

  .brandIcon {
    width: 23px;
    height: 23px;
  }

  .topActions {
    gap: 6px;
    flex: 0 0 auto;
  }

  .topButton {
    padding: 7px 8px;
    font-size: 13px;
  }

  .iconOnlyButton {
    width: 40px;
  }

  .aaButton {
    min-width: 40px;
  }

  #reader article {
    width: calc(100% - 32px);
    max-width: calc(100% - 32px);
    margin-left: auto;
    margin-right: auto;
  }

  #content {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  #content p,
  #content li,
  #content blockquote,
  #content h1,
  #content h2,
  #content h3 {
    max-width: 100%;
  }
}

/* On genuinely narrow phones, protect the reading controls first. */
@media (max-width: 365px) {
  .brand span {
    display: none;
  }

  .topbar {
    padding-left: 10px;
    padding-right: 10px;
  }

  .topActions {
    gap: 4px;
  }

  .topButton {
    padding-left: 7px;
    padding-right: 7px;
  }
}


/* v0.1.10 — restore native page scrolling and keep reader controls reachable */

/*
  v0.1.9 used overflow-x:hidden on html/body. On iOS that can turn the root
  into a separate scrolling container, which breaks both sticky positioning
  and window.scrollY-based reading-location persistence. `clip` blocks
  horizontal overflow without creating a new scroll container.
*/
html,
body {
  overflow-x: clip;
  overscroll-behavior-x: none;
}

body {
  touch-action: auto;
}

/* Keep all normal scrolling on the document itself. */
html {
  overflow-y: visible;
}

body {
  overflow-y: visible;
}

@media (max-width: 640px) {
  :root {
    --mobile-topbar-height: calc(54px + env(safe-area-inset-top));
  }

  /* On iOS Safari, fixed is more dependable here than sticky once the browser
     chrome expands/collapses. The controls stay available at every scroll
     position. */
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--mobile-topbar-height);
    padding-top: env(safe-area-inset-top);
    z-index: 100;
  }

  main {
    padding-top: var(--mobile-topbar-height);
  }

  #toc {
    top: var(--mobile-topbar-height);
    max-height: calc(100dvh - var(--mobile-topbar-height));
  }

  .tocBackdrop {
    top: var(--mobile-topbar-height);
    bottom: 0;
    height: auto;
  }

  /* Ensure the action cluster never disappears behind the reader or drawer. */
  .topActions {
    position: relative;
    z-index: 2;
  }
}


/* v0.1.13 — Reader colour themes */
:root[data-theme="eink"] #content {
  font-weight: 500;
}

/* The Reader E-Ink theme is deliberately monochrome. */
:root[data-theme="eink"] #content mark.user-highlight {
  background: #d9d9d9;
}

/* Keep dark-theme highlighting tuned for the Reader dark palette. */
:root[data-theme="dark"] #content mark.user-highlight {
  background: color-mix(in srgb, #d8ad38 48%, transparent);
}


/* v0.1.14 — compact Library toolbar */
@media (min-width: 641px) {
  .libraryHead {
    justify-content: flex-start;
    align-items: center;
    gap: 22px;
  }

  .libraryActions {
    justify-content: flex-start;
    gap: 2px;
  }

  .libraryActionButton {
    padding-left: 8px;
    padding-right: 8px;
  }
}


/* v0.1.15 — cover alignment + full-theme canvas */
html {
  background-color: var(--bg);
}

/* Align the visible title/author block with the inset cover artwork rather
   than the outside edge of the cover frame. */
.bookMeta {
  padding-left: 11px;
  padding-right: 11px;
}

@media (max-width: 640px) {
  .bookMeta {
    padding-left: 7px;
    padding-right: 7px;
  }
}
