/* ==========================================================================
   E-book Reader — styles
   ========================================================================== */

:root {
  --bg: #f3ede3;
  --bg-elev: #f9f5ee;
  --surface: #fffdf9;
  --surface-2: #f6f0e6;
  --ink: #2a221d;
  --ink-soft: #5b4f45;
  --muted: #8a7c70;
  --line: #e4d9c9;
  --line-strong: #d3c4b0;
  --accent: #9b4a2c;
  --accent-hover: #843c21;
  --accent-soft: #f3e1d5;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --success: #2f7a4b;
  --focus: #c4683f;
  --shadow-sm: 0 1px 2px rgb(58 38 22 / 0.08), 0 1px 1px rgb(58 38 22 / 0.04);
  --shadow-md: 0 8px 20px -8px rgb(58 38 22 / 0.28), 0 2px 6px rgb(58 38 22 / 0.08);
  --shadow-lg: 0 28px 70px -24px rgb(40 24 12 / 0.5), 0 8px 20px -10px rgb(40 24 12 / 0.25);
  --overlay: rgb(28 20 14 / 0.45);

  --reader-bg: radial-gradient(ellipse 90% 80% at 50% 45%, #4b3b30 0%, #2c231d 55%, #19130f 100%);
  --reader-bar: rgb(22 17 13 / 0.78);
  --reader-ink: #f3eadf;
  --reader-muted: #bfae9b;
  --reader-line: rgb(255 255 255 / 0.1);
  --paper: #fdfbf6;

  --radius: 14px;
  --radius-sm: 9px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, "Noto Sans", "Noto Sans Arabic", Tahoma, Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Noto Naskh Arabic", "Traditional Arabic", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17130f;
    --bg-elev: #1d1813;
    --surface: #241e18;
    --surface-2: #2b241d;
    --ink: #f0e6d9;
    --ink-soft: #d0c1af;
    --muted: #9c8c7b;
    --line: #382f27;
    --line-strong: #4a3f35;
    --accent: #e0905f;
    --accent-hover: #eba57b;
    --accent-soft: #3c2a1f;
    --accent-ink: #1d130c;
    --danger: #f08a80;
    --danger-soft: #3d1f1c;
    --success: #7fcf9b;
    --focus: #e9a47c;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-md: 0 10px 24px -10px rgb(0 0 0 / 0.7), 0 2px 6px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 30px 80px -24px rgb(0 0 0 / 0.85);
    --overlay: rgb(0 0 0 / 0.6);
    --reader-bg: radial-gradient(ellipse 90% 80% at 50% 45%, #2f261f 0%, #17120e 60%, #0c0907 100%);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #17130f;
  --bg-elev: #1d1813;
  --surface: #241e18;
  --surface-2: #2b241d;
  --ink: #f0e6d9;
  --ink-soft: #d0c1af;
  --muted: #9c8c7b;
  --line: #382f27;
  --line-strong: #4a3f35;
  --accent: #e0905f;
  --accent-hover: #eba57b;
  --accent-soft: #3c2a1f;
  --accent-ink: #1d130c;
  --danger: #f08a80;
  --danger-soft: #3d1f1c;
  --success: #7fcf9b;
  --focus: #e9a47c;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-md: 0 10px 24px -10px rgb(0 0 0 / 0.7), 0 2px 6px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 30px 80px -24px rgb(0 0 0 / 0.85);
  --overlay: rgb(0 0 0 / 0.6);
  --reader-bg: radial-gradient(ellipse 90% 80% at 50% 45%, #2f261f 0%, #17120e 60%, #0c0907 100%);
  color-scheme: dark;
}

/* ---------------------------------------------------------------- base */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  display: block;
}

[dir="rtl"] .flip-rtl .icon { transform: scaleX(-1); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  transition: background-color .15s, color .15s, border-color .15s, transform .1s, box-shadow .15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--accent) 60%, transparent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(1.08); }

.btn-small { min-height: 32px; padding: 0 12px; font-size: 13px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  transition: background-color .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.icon-btn-small { width: 32px; height: 32px; }
.icon-btn-small .icon { width: 17px; height: 17px; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.segmented button {
  min-width: 38px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.select, .input {
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
}
.select { padding-inline-end: 32px; }
.input { width: 100%; }

/* ---------------------------------------------------------------- library */

.library {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 48px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  flex: none;
}
.brand-text { min-width: 0; }
.brand h1 {
  font: 700 21px/1.15 var(--font-serif);
  letter-spacing: .01em;
}
.tagline {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.library-main {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 48px) 40px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font: 700 19px/1.2 var(--font-serif);
}
.count-pill {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 700 12px/1.6 var(--font);
}

/* Continue reading */
.continue { margin-bottom: 36px; }
.continue .section-title { margin-bottom: 14px; }
.continue-card {
  display: flex;
  gap: 22px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background:
    radial-gradient(120% 140% at 0% 0%, var(--accent-soft) 0%, transparent 55%),
    var(--surface);
  box-shadow: var(--shadow-sm);
}
[dir="rtl"] .continue-card {
  background:
    radial-gradient(120% 140% at 100% 0%, var(--accent-soft) 0%, transparent 55%),
    var(--surface);
}
.continue-cover {
  flex: none;
  width: 104px;
  padding: 0;
  border: 0;
  background: none;
}
.continue-info {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.continue-title {
  font: 700 20px/1.25 var(--font-serif);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  width: 100%;
}
.continue-info .progress { width: min(360px, 100%); }
.continue-info .btn { margin-top: 6px; }

/* Shelf */
.shelf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.shelf-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search > span {
  position: absolute;
  inset-inline-start: 12px;
  color: var(--muted);
  pointer-events: none;
}
.search input {
  width: min(280px, 60vw);
  height: 40px;
  padding: 0 14px;
  padding-inline-start: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
}
.search input::placeholder { color: var(--muted); }

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 34px 26px;
}

.book-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.book-open {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  border-radius: 4px 10px 10px 4px;
}
.book-open:focus-visible { outline-offset: 4px; }

.cover {
  position: relative;
  aspect-ratio: 3 / 4.1;
  overflow: hidden;
  border-radius: 3px 9px 9px 3px;
  background: linear-gradient(160deg, var(--surface-2), var(--line));
  box-shadow: var(--shadow-md);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s;
}
.cover.is-rtl { border-radius: 9px 3px 3px 9px; }
.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* spine highlight on the binding side */
.cover::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(90deg,
    rgb(0 0 0 / .28) 0%, rgb(255 255 255 / .22) 2.2%, rgb(0 0 0 / .1) 4.5%,
    rgb(255 255 255 / .06) 7%, transparent 11%);
}
.cover.is-rtl::before {
  background: linear-gradient(270deg,
    rgb(0 0 0 / .28) 0%, rgb(255 255 255 / .22) 2.2%, rgb(0 0 0 / .1) 4.5%,
    rgb(255 255 255 / .06) 7%, transparent 11%);
}
.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08);
  pointer-events: none;
}
.cover-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.cover-fallback .icon { width: 40%; height: 40%; }
.cover-badge {
  position: absolute;
  z-index: 2;
  bottom: 8px;
  inset-inline-end: 8px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgb(24 18 14 / .72);
  color: #fff;
  font: 700 10.5px/1.6 var(--font);
  letter-spacing: .06em;
  backdrop-filter: blur(4px);
}
.cover-small { width: 100%; }

.book-open:hover .cover,
.continue-cover:hover .cover {
  transform: translateY(-5px) rotate(-.4deg);
  box-shadow: var(--shadow-lg);
}

.book-info { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.book-title {
  font-size: 14.5px;
  font-weight: 650;
  line-height: 1.35;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.book-meta {
  color: var(--muted);
  font-size: 12.5px;
}

/* Titles keep their own text direction (dir="auto") but line up with the interface. */
html[dir="ltr"] :is(.book-title, .continue-title, .file-name) { text-align: left; }
html[dir="rtl"] :is(.book-title, .continue-title, .file-name) { text-align: right; }

.progress {
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width .4s;
}

.card-actions {
  position: absolute;
  top: 8px;
  inset-inline-start: 10px;
  z-index: 3;
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s;
}
.book-card:hover .card-actions,
.card-actions:focus-within {
  opacity: 1;
  transform: none;
}
@media (hover: none) {
  .card-actions { opacity: 1; transform: none; }
}

.no-results {
  padding: 40px 0;
  text-align: center;
  color: var(--muted);
}

/* Empty state */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  max-width: 480px;
  margin: 6vh auto 0;
  padding: 24px;
}
.empty-art { width: 210px; margin-bottom: 8px; }
.empty-shadow { fill: var(--line); }
.empty-page { fill: var(--surface); stroke: var(--line-strong); stroke-width: 1.5; }
.empty-line { fill: none; stroke: var(--line-strong); stroke-width: 2; stroke-linecap: round; }
.empty-spine { stroke: var(--accent); stroke-width: 2; }
.empty h3 { font: 700 22px/1.3 var(--font-serif); }
.empty p { color: var(--ink-soft); }
.empty .btn { margin-top: 12px; }

.library-footer {
  padding: 16px clamp(16px, 4vw, 48px) 22px;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}

/* ---------------------------------------------------------------- dialogs */

.dialog {
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}
.dialog-small { width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(3px);
}
.dialog[open] { animation: dialog-in .22s cubic-bezier(.2,.8,.2,1); }
@keyframes dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0 24px;
}
[dir="rtl"] .dialog-head { padding: 18px 24px 0 20px; }
.dialog-head h2, .dialog-body > h2 { font: 700 19px/1.3 var(--font-serif); }
.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 24px;
}
.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 0 0 18px 18px;
}
.confirm-text { color: var(--ink-soft); }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 16px;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-elev);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background-color .15s;
}
.dropzone:hover, .dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}
.dropzone-text { font-weight: 600; }
.dropzone-sub { color: var(--muted); font-size: 13px; }

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}
.file-list:empty { display: none; }
.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.file-icon { color: var(--accent); }
.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.file-size { color: var(--muted); font-size: 12.5px; flex: none; }
.file-ok { color: var(--success); padding: 0 6px; }
.file-error { color: var(--danger); font-size: 12.5px; max-width: 45%; text-align: end; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.field-label {
  font-size: 13px;
  font-weight: 650;
  color: var(--ink-soft);
  padding: 0;
}
.field-hint { margin-top: -8px; color: var(--muted); font-size: 12.5px; }

.radio-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.radio-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  text-align: center;
  cursor: pointer;
}
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card-art { font: 700 17px/1.4 var(--font-serif); color: var(--muted); direction: ltr; }
.radio-card:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.radio-card:has(input:checked) .radio-card-art { color: var(--accent); }
.radio-card:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

.dialog.is-busy .dialog-foot .btn-ghost,
.dialog.is-busy .dialog-head .icon-btn { visibility: hidden; }

/* ---------------------------------------------------------------- toasts & overlays */

.toasts {
  position: fixed;
  z-index: 100;
  inset-inline: 0;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  pointer-events: none;
}
.reader:not([hidden]) ~ .toasts { bottom: 86px; }
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(460px, 100%);
  padding: 11px 16px;
  border-radius: 14px;
  background: #2a211b;
  color: #f6eee4;
  box-shadow: 0 12px 30px -10px rgb(0 0 0 / .5);
  font-size: 14px;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }
.toast-icon { padding-top: 1px; color: #e9a47c; }
.toast-success .toast-icon { color: #8fd8a8; }
.toast-error .toast-icon { color: #ff9b91; }
.toast-msg { font-weight: 600; }
.toast-detail { color: #cdbca9; font-size: 13px; }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--accent) 22%, var(--overlay));
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.drop-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 40px 56px;
  border: 2px dashed #fff;
  border-radius: 24px;
  color: #fff;
  font-size: 19px;
  font-weight: 650;
  text-align: center;
}
.drop-overlay-inner .icon { width: 44px; height: 44px; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgb(255 255 255 / .2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
.spinner-small {
  width: 18px;
  height: 18px;
  border-width: 2px;
  border-color: var(--line-strong);
  border-top-color: var(--accent);
  margin: 0 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- reader */

.reader {
  position: fixed;
  inset: 0;
  padding-left: env(safe-area-inset-left);    /* phone notch when turned sideways */
  padding-right: env(safe-area-inset-right);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);   /* a crowded bar must not widen the reader */
  background: var(--reader-bg);
  color: var(--reader-ink);
  overflow: hidden;
  --accent-reader: #e4996b;
}

.reader-bar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px clamp(10px, 2vw, 20px);
  background: var(--reader-bar);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.reader-top { border-bottom: 1px solid var(--reader-line); }
.reader-bottom {
  border-top: 1px solid var(--reader-line);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.reader .btn-ghost {
  border-color: var(--reader-line);
  color: var(--reader-ink);
}
.reader .btn-ghost:hover { background: rgb(255 255 255 / .08); }
.reader .icon-btn { color: var(--reader-muted); }
.reader .icon-btn:hover { color: var(--reader-ink); background: rgb(255 255 255 / .08); }
.reader-back { min-height: 36px; padding: 0 14px 0 10px; }
[dir="rtl"] .reader-back { padding: 0 10px 0 14px; }

.reader-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font: 600 15px/1.3 var(--font-serif);
}
.reader-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-actions { display: flex; align-items: center; gap: 4px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 32px;
  padding: 0 8px 0 12px;
  border: 1px solid var(--reader-line);
  border-radius: 999px;
  background: rgb(255 255 255 / .06);
  color: var(--reader-ink);
  font: 700 12px/1 var(--font);
  letter-spacing: .08em;
  direction: ltr;
}
.chip:hover { background: rgb(255 255 255 / .12); }

.zoom-controls {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 2px;
  margin-inline-end: 4px;
  border: 1px solid var(--reader-line);
  border-radius: 999px;
  background: rgb(255 255 255 / .04);
  direction: ltr;
}
.reader .zoom-controls .icon-btn { width: 30px; height: 30px; }
.reader .zoom-controls .icon-btn:disabled { opacity: .35; }
.zoom-value {
  min-width: 50px;
  height: 28px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--reader-ink);
  font: 600 12.5px/1 var(--font);
  font-variant-numeric: tabular-nums;
}
.zoom-value:hover { background: rgb(255 255 255 / .08); }
.chip-arrow .icon { width: 16px; height: 16px; color: var(--accent-reader); }

.stage {
  position: relative;
  overflow: hidden;
  direction: ltr;           /* the flipbook does its own direction handling */
  user-select: none;
  -webkit-user-select: none;
}

/* Scroll area: centres the book, and scrolls when it is zoomed. */
.stage-scroll {
  position: absolute;
  inset: 0;
  display: flex;
  overflow: hidden;
  touch-action: pan-x pan-y;    /* pinch is handled by the reader */
  scrollbar-width: thin;
  scrollbar-color: rgb(255 255 255 / .28) transparent;
}
.stage.is-zoomed .stage-scroll { overflow: auto; }
.stage.is-zoomed .book-sizer { cursor: grab; }
.stage.is-zoomed.is-panning .book-sizer { cursor: grabbing; }
.stage.is-zoomed .flipbook,
.stage.is-zoomed .flipbook * { touch-action: pan-x pan-y !important; }

.book-sizer {
  position: relative;
  flex: none;
  margin: auto;             /* centred, but never clipped when larger than the stage */
}

/* Edge of a page that turns it when clicked: hint on hover. */
.book-sizer::after {
  content: "";
  position: absolute;
  z-index: 30;
  top: 0;
  bottom: 0;
  width: var(--edge-zone, 80px);
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s;
  background-repeat: no-repeat;
  background-position: center, 0 0;
  background-size: 30px 30px, 100% 100%;
}
.book-sizer.hover-left::after {
  left: 0;
  opacity: 1;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-opacity='.5' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m15 18-6-6 6-6' stroke='%23fff' stroke-opacity='.7' stroke-width='4.5'/%3E%3Cpath d='m15 18-6-6 6-6'/%3E%3C/svg%3E"),
    linear-gradient(to right, rgb(0 0 0 / .13), transparent);
}
.book-sizer.hover-right::after {
  right: 0;
  opacity: 1;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-opacity='.5' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6' stroke='%23fff' stroke-opacity='.7' stroke-width='4.5'/%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E"),
    linear-gradient(to left, rgb(0 0 0 / .13), transparent);
}
.book-sizer.hover-left,
.book-sizer.hover-right,
.stage.is-zoomed .book-sizer.hover-left,
.stage.is-zoomed .book-sizer.hover-right { cursor: pointer; }
.book-sizer.is-flipping::after { opacity: 0; }
/* Soft shadow under the book; follows the closed cover. */
.book-sizer::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3px;
  box-shadow: 0 34px 60px -22px rgb(0 0 0 / .75), 0 12px 24px -12px rgb(0 0 0 / .55);
  pointer-events: none;
  transition: left .5s ease, right .5s ease;
}
.book-sizer.only-right::before { left: 50%; }
.book-sizer.only-left::before { right: 50%; }

/* isolation keeps StPageFlip's page z-indexes below the edge hint */
.flipbook { margin: 0 auto; isolation: isolate; }

.page {
  background: var(--paper);
  overflow: hidden;
}
.page-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.page canvas { display: block; }
.page-blank { background: #f6f1e7; }

/* Gutter shading towards the spine. */
.page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.page.--left::after {
  background: linear-gradient(to left, rgb(0 0 0 / .2) 0%, rgb(0 0 0 / .06) 3.5%, transparent 10%);
}
.page.--right::after {
  background: linear-gradient(to right, rgb(0 0 0 / .2) 0%, rgb(0 0 0 / .06) 3.5%, transparent 10%);
}
.book-sizer.is-single .page::after {
  background: linear-gradient(to right, rgb(0 0 0 / .14) 0%, transparent 5%);
}
.book-sizer.is-single.is-rtl .page::after {
  background: linear-gradient(to left, rgb(0 0 0 / .14) 0%, transparent 5%);
}

.page-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #c9bba8;
  font: 600 clamp(16px, 2.4vw, 30px)/1 var(--font-serif);
  background:
    linear-gradient(100deg, transparent 30%, rgb(255 255 255 / .55) 50%, transparent 70%) 0 0 / 300% 100%,
    var(--paper);
  animation: shimmer 1.6s ease-in-out infinite;
}
@keyframes shimmer {
  from { background-position: 100% 0, 0 0; }
  to { background-position: -50% 0, 0 0; }
}

/* Page tone, chosen with the "A" button (only CSS: nothing is redrawn).
   Sepia multiplies the page with cream paper: white becomes cream, text stays
   dark. Night inverts the page and turns the hues back, so text is light on
   dark and pictures keep roughly their colours. --paper matches the colour the
   white of a page ends up with, for pages that are not drawn yet. */
.reader[data-tone="sepia"] { --paper: #f4ecd8; }
.reader[data-tone="night"] { --paper: #262523; }
.reader[data-tone] .page { isolation: isolate; }
.reader[data-tone] .page-blank { background: var(--paper); }
.reader[data-tone="sepia"] .page canvas { mix-blend-mode: multiply; }
.reader[data-tone="night"] .page canvas { filter: invert(.86) hue-rotate(180deg) sepia(.2); }
.reader[data-tone="night"] .page-placeholder {
  color: #5c544b;
  background:
    linear-gradient(100deg, transparent 30%, rgb(255 255 255 / .05) 50%, transparent 70%) 0 0 / 300% 100%,
    var(--paper);
}

.tone-swatch {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 1px solid rgb(255 255 255 / .4);
  border-radius: 5px;
  background: #fdfbf6;
  color: #1c1917;
  font: 700 12px/1 var(--font-serif);
}
.reader[data-tone="sepia"] .tone-swatch { background: #f4ecd8; color: #3b2f25; }
.reader[data-tone="night"] .tone-swatch { background: #262523; color: #eae4d8; }

.nav-btn {
  position: absolute;
  top: 50%;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-top: -26px;
  padding: 0;
  border: 1px solid rgb(255 255 255 / .12);
  border-radius: 50%;
  background: rgb(20 15 11 / .45);
  color: var(--reader-ink);
  backdrop-filter: blur(6px);
  transition: background-color .15s, opacity .2s, transform .15s;
}
.nav-btn .icon { width: 26px; height: 26px; }
.nav-btn:hover:not(:disabled) { background: rgb(20 15 11 / .75); transform: scale(1.05); }
.nav-btn:disabled { opacity: 0; pointer-events: none; }
.nav-left { left: 12px; }
.nav-right { right: 12px; }

.stage-loading {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--reader-muted);
  font-size: 14px;
}
.reader.is-loading .book-sizer,
.reader.is-loading .nav-btn { visibility: hidden; }

.indicator {
  flex: none;
  min-width: 96px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  color: var(--reader-ink);
  white-space: nowrap;
}

.slider {
  flex: 1;
  min-width: 60px;
  accent-color: var(--accent-reader);
  cursor: pointer;
}

.goto {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: none;
}
.goto input {
  width: 92px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--reader-line);
  border-radius: 999px;
  background: rgb(255 255 255 / .06);
  color: var(--reader-ink);
  font-size: 13px;
}
.goto input::placeholder { color: var(--reader-muted); font-size: 12px; }
.goto .btn {
  background: var(--accent-reader);
  color: #1d130c;
}

/* ---------------------------------------------------------------- remote books, notes button */

.book-card.is-remote .cover img,
.book-card.is-remote .cover-fallback { opacity: .5; }
.cover-remote {
  position: absolute;
  z-index: 2;
  top: 50%;
  inset-inline: 10px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 8px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow-sm);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
  text-align: center;
}
.cover-remote .icon { width: 22px; height: 22px; color: var(--accent); }
.book-extra { margin-top: -4px; }

.notes-btn { gap: 7px; }
.notes-btn .count-pill { padding: 0 7px; font-size: 11.5px; }

/* ---------------------------------------------------------------- account */

.account-btn.is-signed-in {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 15px/1 var(--font);
}
.account-btn.is-signed-in:hover .avatar { background: var(--accent-hover); }
.avatar-large { width: 52px; height: 52px; font-size: 22px; }

.sync-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}
.account-btn .sync-dot {
  position: absolute;
  bottom: 3px;
  inset-inline-end: 3px;
  box-sizing: content-box;
  border: 2px solid var(--bg);
}
.sync-synced .sync-dot { background: var(--success); }
.sync-syncing .sync-dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync-error .sync-dot { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

.account-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
.account-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.account-email {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html[dir="rtl"] .account-email { text-align: right; }
.account-provider { color: var(--muted); font-size: 13px; }
.account-status {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink-soft);
  font-size: 13px;
}

.dialog-intro { color: var(--ink-soft); font-size: 14px; }
.dialog-foot-split { justify-content: space-between; align-items: center; flex-wrap: wrap; }

.auth-providers { display: flex; flex-direction: column; gap: 8px; }
.provider-btn { width: 100%; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12.5px;
}
.auth-divider::before,
.auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.link-btn {
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
  text-align: start;
}
.link-btn:hover { text-decoration: underline; }
.auth-forgot { align-self: flex-start; margin-top: -10px; }
.field-hint-inline { color: var(--muted); font-size: 12.5px; }
.form-message {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.form-message.is-error { background: var(--danger-soft); color: var(--danger); }
.form-message.is-info { background: var(--accent-soft); color: var(--ink); }

/* ---------------------------------------------------------------- notes (shared) */

/* Colours come from the surrounding scope: dark in the reader, the page theme in the library. */
.notes-panel {
  --n-ink: var(--reader-ink);
  --n-muted: var(--reader-muted);
  --n-line: var(--reader-line);
  --n-accent: var(--accent-reader);
  --n-surface: rgb(255 255 255 / .05);
  --n-hover: rgb(255 255 255 / .08);
  --n-current: rgb(228 153 107 / .12);
}
.notes-dialog {
  --n-ink: var(--ink);
  --n-muted: var(--muted);
  --n-line: var(--line-strong);
  --n-accent: var(--accent);
  --n-surface: var(--bg-elev);
  --n-hover: var(--surface-2);
  --n-current: var(--accent-soft);
}

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.note-item {
  padding: 8px 12px 11px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--n-surface);
  transition: background-color .15s, border-color .15s, box-shadow .3s;
}
.note-item:hover { background: var(--n-hover); }
.note-item.is-current {
  border-color: color-mix(in srgb, var(--n-accent) 45%, transparent);
  background: var(--n-current);
}
.note-item.is-flash { box-shadow: 0 0 0 2px var(--n-accent); }
.note-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}
.note-page {
  color: var(--n-accent);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
a.note-page:hover { text-decoration: underline; }
.note-page.is-disabled { color: var(--n-muted); }
.note-time { color: var(--n-muted); font-size: 12px; white-space: nowrap; }
.note-actions {
  display: flex;
  gap: 2px;
  margin-inline-start: auto;
  opacity: 0;
  transition: opacity .15s;
}
.note-item:hover .note-actions,
.note-item:focus-within .note-actions { opacity: 1; }
@media (hover: none) {
  .note-actions { opacity: 1; }
}
.note-actions .icon-btn { width: 28px; height: 28px; color: var(--n-muted); }
.note-actions .icon-btn .icon { width: 15px; height: 15px; }
.note-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--n-ink);
  font-size: 14px;
  line-height: 1.5;
}
html[dir="ltr"] .note-body { text-align: left; }
html[dir="rtl"] .note-body { text-align: right; }
.note-input {
  width: 100%;
  min-height: 78px;
  max-height: 40vh;
  padding: 9px 11px;
  border: 1px solid var(--n-line);
  border-radius: var(--radius-sm);
  background: var(--n-surface);
  color: var(--n-ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  resize: vertical;
}
.note-input::placeholder { color: var(--n-muted); }
.note-input:focus-visible { outline: 2px solid var(--n-accent); outline-offset: -1px; }
.note-edit { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.note-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
.notes-empty {
  padding: 24px 16px;
  color: var(--n-muted);
  font-size: 13.5px;
  text-align: center;
}

/* ---------------------------------------------------------------- notes panel (reader) */

.reader-body {
  position: relative;
  display: flex;
  min-height: 0;
}
.reader-body > .stage { flex: 1; min-width: 0; }

.notes-toggle { position: relative; }
.reader .notes-toggle.is-active { color: var(--reader-ink); background: rgb(255 255 255 / .12); }
.icon-count {
  position: absolute;
  top: 1px;
  inset-inline-end: -1px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-reader);
  color: #1d130c;
  font: 700 10.5px/17px var(--font);
  text-align: center;
}

.notes-panel {
  position: relative;
  z-index: 7;
  flex: none;
  width: 340px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-inline-start: 1px solid var(--reader-line);
  background: rgb(22 17 13 / .94);
  color: var(--reader-ink);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.notes-head {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 12px 10px 4px 16px;
}
[dir="rtl"] .notes-head { padding: 12px 16px 4px 10px; }
.notes-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  font: 700 16px/1.2 var(--font-serif);
}
.notes-panel .count-pill { background: rgb(228 153 107 / .18); color: var(--accent-reader); }
.notes-panel .icon-btn:disabled { opacity: .3; }
.notes-panel .icon-btn.danger:hover { color: #ff9b91; background: rgb(255 120 110 / .12); }
.notes-panel .btn-primary { background: var(--accent-reader); color: #1d130c; box-shadow: none; }
.notes-panel .btn-primary:hover:not(:disabled) { background: #eeab82; }

.note-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 16px 14px;
  border-bottom: 1px solid var(--reader-line);
}
.note-pages {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--reader-muted);
  font-size: 12.5px;
}
.page-chips { display: flex; gap: 6px; }
.page-chip {
  min-width: 38px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--reader-line);
  border-radius: 999px;
  background: transparent;
  color: var(--reader-ink);
  font: 600 12.5px/1 var(--font);
  font-variant-numeric: tabular-nums;
}
.page-chip:hover { background: rgb(255 255 255 / .08); }
.page-chip[aria-pressed="true"] {
  border-color: var(--accent-reader);
  background: var(--accent-reader);
  color: #1d130c;
}
.note-hint { flex: 1; color: var(--reader-muted); font-size: 11.5px; }

.notes-search { margin: 12px 16px 0; }
.notes-panel .search input {
  width: 100%;
  height: 34px;
  border-color: var(--reader-line);
  background: rgb(255 255 255 / .05);
  color: var(--reader-ink);
  font-size: 13.5px;
}
.notes-panel .search input::placeholder,
.notes-panel .search > span { color: var(--reader-muted); }
.notes-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 10px 16px;
  scrollbar-width: thin;
  scrollbar-color: rgb(255 255 255 / .25) transparent;
}

/* Badge on pages that have notes. */
.page-note-badge {
  position: absolute;
  z-index: 3;
  top: 2.2%;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 10px 0 8px;
  border: 1px solid rgb(155 74 44 / .3);
  border-radius: 999px;
  background: rgb(255 249 240 / .95);
  color: #9b4a2c;
  font: 700 12px/1 var(--font);
  box-shadow: 0 2px 8px rgb(60 30 10 / .2);
  cursor: pointer;
}
.page-note-badge:hover { background: #fff; }
.page-note-badge * { pointer-events: none; }   /* the page-flip library only lets clicks on buttons through */
.page-note-badge .icon { width: 14px; height: 14px; }

/* ---------------------------------------------------------------- all notes (library) */

.dialog-wide { width: min(720px, calc(100vw - 32px)); }
.dialog-head-actions { display: flex; align-items: center; gap: 6px; }
.notes-dialog .search input { width: 100%; }
.all-notes { display: flex; flex-direction: column; gap: 22px; }
.all-notes:empty { display: none; }
.notes-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.notes-group-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: 700 16px/1.3 var(--font-serif);
}
html[dir="ltr"] .notes-group-title { text-align: left; }
html[dir="rtl"] .notes-group-title { text-align: right; }
.notes-group-count { flex: none; color: var(--muted); font-size: 12.5px; }
.notes-group-hint { margin: -2px 0 8px; color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- copy text from an area */

.reader .icon-btn.is-active { color: var(--reader-ink); background: rgb(255 255 255 / .12); }

.capture-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  background: rgb(0 0 0 / .14);
  cursor: crosshair;
  touch-action: none;
}
.capture-layer:has(.capture-box:not([hidden])) { background: transparent; }
.capture-hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgb(22 17 13 / .9);
  color: var(--reader-ink);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 8px 24px -10px rgb(0 0 0 / .7);
  pointer-events: none;
}
html[dir="rtl"] .capture-hint { direction: rtl; }
.capture-box {
  position: absolute;
  border: 2px solid var(--accent-reader);
  border-radius: 2px;
  background: rgb(228 153 107 / .12);
  box-shadow: 0 0 0 9999px rgb(0 0 0 / .3);   /* dims everything outside the rectangle */
  pointer-events: none;
}

.capture-panel {
  --n-ink: var(--reader-ink);
  --n-muted: var(--reader-muted);
  --n-line: var(--reader-line);
  --n-accent: var(--accent-reader);
  --n-surface: rgb(255 255 255 / .05);
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--reader-line);
  border-radius: 16px;
  background: rgb(22 17 13 / .96);
  color: var(--reader-ink);
  box-shadow: 0 24px 60px -20px rgb(0 0 0 / .85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  user-select: text;
  -webkit-user-select: text;
}
html[dir="rtl"] .capture-panel { direction: rtl; }
.capture-head { display: flex; align-items: flex-start; gap: 10px; }
.capture-icon { padding-top: 2px; color: var(--accent-reader); }
.capture-heading { flex: 1; min-width: 0; }
.capture-title { font: 700 15px/1.3 var(--font-serif); }
.capture-source { color: var(--reader-muted); font-size: 12.5px; }
.capture-source.is-warning { color: #f2c38f; }
.capture-busy {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 64px;
  color: var(--reader-muted);
  font-size: 13.5px;
}
.capture-busy .spinner-small { margin: 0; border-color: rgb(255 255 255 / .2); border-top-color: var(--accent-reader); }
.capture-progress {
  flex-basis: 100%;
  height: 4px;
  border-radius: 999px;
  background: rgb(255 255 255 / .12);
  overflow: hidden;
}
.capture-progress span { display: block; width: 0; height: 100%; background: var(--accent-reader); transition: width .2s; }
.capture-text { min-height: 110px; max-height: 38vh; }
.capture-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}
.capture-lang {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-inline-end: auto;
  color: var(--reader-muted);
  font-size: 12.5px;
}
.capture-select {
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--reader-line);
  border-radius: 8px;
  background: rgb(255 255 255 / .06);
  color: var(--reader-ink);
  font-size: 13px;
}
.capture-select option { color: #2a221d; background: #fff; }
.capture-panel .btn-primary { background: var(--accent-reader); color: #1d130c; box-shadow: none; }
.capture-panel .btn-primary:hover:not(:disabled) { background: #eeab82; }

/* ---------------------------------------------------------------- PDF files in the account */

.cloud-option {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.check:has(input:disabled) { color: var(--muted); cursor: default; }
.check-text { display: inline-flex; align-items: center; gap: 7px; }
.check-text .icon { color: var(--accent); }
.cloud-option-hint { color: var(--muted); font-size: 12.5px; }

.cover-cloud {
  position: absolute;
  z-index: 2;
  top: 8px;
  inset-inline-end: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgb(255 253 249 / .92);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}
.cover-cloud .icon { width: 17px; height: 17px; }
.cover-cloud.is-busy { animation: pulse 1.1s ease-in-out infinite; }
.cover-remote .spinner-small { margin: 0; }

.account-cloud {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.account-cloud-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 650;
}
.account-cloud-title { display: inline-flex; align-items: center; gap: 7px; }
.account-cloud-title .icon { color: var(--accent); }
.account-cloud-count { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.account-cloud-note { color: var(--muted); font-size: 12.5px; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 720px) {
  .tagline { display: none; }
  .btn-label { display: none; }
  #add-btn,
  .account-btn:not(.is-signed-in) { width: 40px; padding: 0; }
  .notes-btn { padding: 0 12px; }
  .note-hint { display: none; }
  .brand h1 { font-size: 18px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 26px 16px; }
  .continue-card { gap: 16px; padding: 14px; }
  .continue-cover { width: 84px; }
  .continue-title { font-size: 17px; }
  .shelf-controls { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .goto { display: none; }
  .nav-btn { width: 40px; height: 40px; margin-top: -20px; opacity: .75; }
  .nav-left { left: 4px; }
  .nav-right { right: 4px; }
  .reader-back { padding: 0 10px; }
  .zoom-value { min-width: 40px; font-size: 11.5px; }
  .reader-top { gap: 6px; }
  .reader-actions { gap: 0; }
}

@media (max-width: 900px) {
  /* The notes panel slides over the book instead of making it smaller. */
  .notes-panel {
    position: absolute;
    inset-block: 0;
    inset-inline-end: 0;
    width: min(380px, 100%);
    box-shadow: -24px 0 48px -24px rgb(0 0 0 / .8);
  }
  [dir="rtl"] .notes-panel { box-shadow: 24px 0 48px -24px rgb(0 0 0 / .8); }
}

/* Phones turned sideways: smaller bars and arrows, so the two pages get more room. */
@media (max-height: 500px) {
  .reader-bar { padding-top: 4px; padding-bottom: 4px; }
  .reader-bottom { padding-bottom: max(4px, env(safe-area-inset-bottom)); }
  .nav-btn { width: 40px; height: 40px; margin-top: -20px; opacity: .75; }
  .nav-left { left: 4px; }
  .nav-right { right: 4px; }
  .goto { display: none; }
}

@media (max-width: 480px) {
  .brand-text { display: none; }   /* the logo stays; the buttons need the room */
  #r-layout { display: none; }     /* phones use the automatic layout */
  #r-zoom-out, #r-zoom-in { display: none; }   /* phones zoom with two fingers; the percentage still resets */
  .reader-title { display: none; }
  .reader-top { justify-content: space-between; }
}

@media (max-width: 350px) {
  .zoom-controls { display: none; }
}

@media (max-width: 420px) {
  .segmented button { min-width: 32px; padding: 0 7px; }
  .topbar { gap: 8px; }
  .brand-mark { width: 32px; height: 32px; }
}

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