:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #d9d6cf;
  --border-strong: #b9b5ac;
  --accent: #0ea5e9;
  --accent-strong: #0369a1;   /* white text on it passes 4.5:1 */
  --accent-hover: #075985;
  --accent-text: #0369a1;     /* accent used as text on surfaces */
  --accent-soft: rgba(14, 165, 233, 0.14);
  --live: #dc2626;            /* camera is on */
  --focus: #0284c7;
  --page-shadow: 0 1px 2px rgba(31, 35, 40, 0.08), 0 6px 20px rgba(31, 35, 40, 0.10);
  --raised-shadow: 0 2px 6px rgba(31, 35, 40, 0.08), 0 16px 40px rgba(31, 35, 40, 0.16);
  --radius: 8px;
  --control-h: 36px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191c;
    --surface: #212429;
    --surface-2: #1c1f23;
    --text: #e6e8eb;
    --muted: #a0a7af;
    --border: #353a41;
    --border-strong: #4b525b;
    --accent-text: #7dd3fc;
    --accent-soft: rgba(56, 189, 248, 0.16);
    --live: #f87171;
    --focus: #38bdf8;
    --page-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
    --raised-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), 0 20px 48px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

/* A column: toolbar, settings (when open), the book, status bar.
   Flex rather than grid, so hiding the settings panel can't shift rows. */
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-soft); color: inherit; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Buttons ---------- */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--control-h);
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 120ms, border-color 120ms, color 120ms, box-shadow 120ms;
}
button:hover:not(:disabled) { border-color: var(--border-strong); background: var(--surface-2); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; }

button.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.large { min-height: 44px; padding: 0 22px; font-size: 16px; }

.icon-btn {
  width: var(--control-h);
  padding: 0;
  color: var(--muted);
}
.icon-btn:hover:not(:disabled) { color: var(--text); }
.icon-btn[aria-expanded="true"] {
  color: var(--accent-text);
  background: var(--accent-soft);
  border-color: transparent;
}

/* Start/stop gestures: a camera icon when off, a live dot when the camera is on */
.gesture-btn { min-width: 150px; }
.gesture-btn::before {
  content: "";
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: var(--camera-icon) center / contain no-repeat;
  mask: var(--camera-icon) center / contain no-repeat;
  --camera-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='6' width='12' height='12' rx='2'/%3E%3Cpath d='M15 10.5l6-3.5v10l-6-3.5'/%3E%3C/svg%3E");
}
.gesture-btn.active,
.gesture-btn.active:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.gesture-btn.active::before {
  -webkit-mask: none;
  mask: none;
  width: 8px;
  height: 8px;
  margin: 0 5px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--live) 22%, transparent);
}
.gesture-btn:disabled { opacity: 0.85; cursor: progress; }
.gesture-btn:disabled::before {
  -webkit-mask: none;
  mask: none;
  width: 14px;
  height: 14px;
  margin: 0 2px;
  border-radius: 50%;
  background: none;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toolbar ---------- */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand-mark { width: 22px; height: 22px; }
.brand-mark rect:first-child { fill: var(--accent); }
.brand-mark rect:last-child { fill: #7dd3fc; }
/* Three zones, left to right: your books, where you are in this one, and
   the hands-free controls. How the page is shown (zoom, full screen) lives
   in the bar at the bottom. */
.library, .nav, .actions { display: flex; align-items: center; gap: 8px; }
.library { gap: 12px; min-width: 0; }
@media (max-width: 1000px) {
  .brand-text { display: none; }
}
@media (max-width: 860px) {
  #open-btn { width: var(--control-h); padding: 0; }
  #open-btn .btn-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .gesture-btn { min-width: 0; }
}
.nav { gap: 4px; }
.nav:has(.page-label:empty) { visibility: hidden; } /* no book open yet */
.nav .icon-btn { border-color: transparent; background: transparent; }
.nav .icon-btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border); }
.actions { justify-content: flex-end; }
.page-btn {
  min-width: 132px;
  padding: 0 8px;
  border-color: transparent;
  background: transparent;
}
.page-btn:hover:not(:disabled) .page-label,
.page-btn:focus-visible .page-label { color: var(--text); }
.page-label {
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: color 120ms;
}

/* Zoom: out, the level (click for "fit"), in */
.zoom { display: flex; align-items: center; }
.zoom-label {
  min-width: 52px;
  padding: 0 6px;
  border-color: transparent;
  background: transparent;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.zoom-label:hover:not(:disabled) { color: var(--text); }
.zoom-label.zoomed { color: var(--accent-text); }
.view .fs-exit { display: none; }
.view #fullscreen-btn[aria-pressed="true"] .fs-enter { display: none; }
.view #fullscreen-btn[aria-pressed="true"] .fs-exit { display: block; }

/* Open PDF, with an arrow for recent books joined on when there are some */
.split { display: flex; }
.split #open-btn:has(+ .split-more:not([hidden])) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-more {
  width: 28px;
  padding: 0;
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  color: var(--muted);
}
.split-more[hidden] { display: none; }
.split-more:hover:not(:disabled) { color: var(--text); }
.split-more .icon { width: 16px; height: 16px; transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1); }
.split-more[aria-expanded="true"] { color: var(--accent-text); background: var(--accent-soft); }
.split-more[aria-expanded="true"] .icon { transform: rotate(180deg); }

/* ---------- Panels: settings, contents, recent books ----------
   Popovers that float over the book, so opening one never reflows the page.
   Settings and recent books sit under the buttons on the right, contents on
   the left. */
.panel {
  position: fixed;
  inset: 60px 16px auto auto;
  width: 340px;
  max-height: calc(100dvh - 76px);
  overflow: auto;
  margin: 0;
  padding: 0 0 8px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--raised-shadow);
  accent-color: var(--accent-strong);
}
.panel:popover-open { animation: rise 200ms cubic-bezier(0.16, 1, 0.3, 1); }
.panel::backdrop { background: transparent; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 4px 20px;
}
.panel h2 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }
.icon-btn.ghost { border-color: transparent; background: transparent; }

/* Contents: a sidebar on the left that makes room for itself, so the book
   moves over instead of being covered. Go to a page, then the chapters. */
.workspace { flex: 1; display: flex; min-height: 0; }
.sidebar {
  flex: none;
  width: 0;
  overflow: hidden;
  background: var(--surface);
  border-right: 1px solid transparent;
  transition: width 300ms cubic-bezier(0.16, 1, 0.3, 1), border-color 300ms;
}
.sidebar.open { width: 300px; border-right-color: var(--border); }
.sidebar-inner {
  width: 300px;
  height: 100%;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateX(-12px);
  transition: opacity 160ms ease, transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
.sidebar.open .sidebar-inner { opacity: 1; transform: none; transition-delay: 60ms; }
.sidebar h2 { margin: 0; font-size: 16px; letter-spacing: -0.01em; }
.sidebar .panel-head { padding-left: 16px; }
.sidebar .goto { padding-left: 16px; padding-right: 16px; }
.sidebar .toc-tree { flex: 1; padding-left: 4px; }
.sidebar .toc-empty { padding-left: 16px; }
.toc-btn[aria-expanded="true"] { color: var(--accent-text); background: var(--accent-soft); border-color: transparent; }
body:has(.page-label:empty) .toc-btn { display: none; }
.library .brand { margin-right: 8px; }
.stage { min-width: 0; }

.goto { display: grid; gap: 6px; padding: 8px 20px 16px; border-bottom: 1px solid var(--border); }
.goto label { font-size: 13px; color: var(--muted); }
.goto-row { display: flex; align-items: center; gap: 8px; }
.goto input {
  width: 88px;
  height: var(--control-h);
  padding: 0 10px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  caret-color: var(--accent-strong);
  -moz-appearance: textfield;
}
.goto input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.goto input:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.goto input[aria-invalid="true"] { border-color: var(--live); }
.goto-total { flex: 1; color: var(--muted); font-variant-numeric: tabular-nums; }
.goto .primary { padding: 0 16px; }

.toc-tree { overflow: auto; padding: 8px 8px 12px; overscroll-behavior: contain; }
.toc-tree:empty { display: none; }
.toc-tree ol { list-style: none; margin: 0; padding: 0; }
.toc-tree ol ol { padding-left: 18px; }
.toc-tree ol[hidden] { display: none; }
.toc-row { display: flex; align-items: flex-start; }
.toc-toggle {
  flex: none;
  width: 24px;
  min-height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
}
.toc-toggle:hover:not(:disabled) { background: transparent; color: var(--text); }
.toc-toggle .icon { width: 14px; height: 14px; transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1); }
.toc-toggle[aria-expanded="true"] .icon { transform: rotate(90deg); }
.toc-spacer { flex: none; width: 24px; }
.toc-link {
  flex: 1;
  min-width: 0;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  min-height: 34px;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  font-weight: 400;
  text-align: left;
  white-space: normal;
}
.toc-link:hover:not(:disabled) { background: var(--surface-2); }
.toc-link:disabled { opacity: 0.5; }
.toc-title { text-wrap: pretty; }
.toc-page { flex: none; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.toc-link[aria-current="true"],
.toc-link[aria-current="true"]:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent-text); font-weight: 550; }
.toc-link[aria-current="true"] .toc-page { color: inherit; }
.toc-empty { margin: 0; padding: 16px 20px 20px; color: var(--muted); font-size: 14px; }

/* Recent books, in the panel and on the start screen */
.panel.recent { inset: 60px auto auto 16px; padding-bottom: 12px; } /* under Open PDF */
.book-list { list-style: none; margin: 0; padding: 4px 8px; }
.book {
  position: relative;
  display: flex;
  align-items: center;
}
.book-open {
  flex: 1;
  min-width: 0;
  justify-content: flex-start;
  gap: 12px;
  min-height: 0;
  padding: 8px 44px 8px 12px;
  border: 0;
  background: transparent;
  font-weight: 400;
  text-align: left;
}
.book-open:hover:not(:disabled) { background: var(--surface-2); }
.book-cover {
  flex: none;
  width: 36px;
  aspect-ratio: 3 / 4;
  border-radius: 2px;
  object-fit: cover;
  object-position: top;
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--border), 0 1px 3px rgba(31, 35, 40, 0.12);
}
.book-text { display: grid; min-width: 0; gap: 1px; }
.book-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.book-meta { font-size: 13px; color: var(--muted); }
.book-meta .progress {
  display: inline-block;
  width: 40px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent-strong) var(--done), var(--border) var(--done));
}
.book-forget {
  position: absolute;
  right: 6px;
  width: 30px;
  min-height: 30px;
  border-color: transparent;
  background: transparent;
  opacity: 0;
}
.book-forget .icon { width: 15px; height: 15px; }
.book:hover .book-forget, .book-forget:focus-visible { opacity: 1; }
@media (hover: none) { .book-forget { opacity: 1; } }
.recent-note { margin: 4px 20px 0; font-size: 12.5px; color: var(--muted); }
.icon-btn.ghost:hover { background: var(--surface-2); }

.settings .group {
  display: grid;
  gap: 14px;
  padding: 14px 20px 16px;
}
.settings .group + .group { border-top: 1px solid var(--border); }
.settings h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.settings fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.settings legend { padding: 0; margin-bottom: 8px; }
.settings .field { display: grid; gap: 8px; }
.settings .field-head { display: flex; justify-content: space-between; align-items: baseline; }
.settings output {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-text);
  font-variant-numeric: tabular-nums;
}
.settings .scale {
  display: flex;
  justify-content: space-between;
  margin-top: -2px;
  font-size: 12px;
  color: var(--muted);
}
.settings .note { font-size: 13px; color: var(--muted); }

/* Slider: a filled track up to the thumb (--fill is set from JS) */
.slider {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent-strong) var(--fill), var(--border) var(--fill));
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border-strong);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 120ms;
}
.slider:hover::-webkit-slider-thumb { transform: scale(1.1); }
.slider::-moz-range-track { height: 4px; border-radius: 999px; background: var(--border); }
.slider::-moz-range-progress { height: 4px; border-radius: 999px; background: var(--accent-strong); }
.slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 1px solid var(--border-strong);
}
.slider:focus-visible { outline: none; }
.slider:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--focus); outline-offset: 2px; }
.slider:disabled { cursor: default; opacity: 0.4; }

/* Segmented control: two radios that look like one switch */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 150ms, color 150ms, box-shadow 150ms;
}
.segmented label:hover { color: var(--text); }
.segmented .icon { width: 16px; height: 16px; }
.segmented input:checked + label {
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 0 0 1px var(--border);
}
.segmented input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 1px; }

/* Switch rows: label on the left, toggle on the right */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}
.switch-row > span { display: grid; gap: 1px; }
.switch-row small { font-size: 13px; color: var(--muted); }
.switch {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  position: relative;
  width: 40px;
  height: 24px;
  margin: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  transition: background-color 160ms;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
.switch:checked { background: var(--accent-strong); }
.switch:checked::after { transform: translateX(16px); }

/* Volume: speaker icons either side of the slider */
.settings .volume {
  grid-template-columns: auto 1fr auto 3.5ch;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}
.settings .volume .icon { width: 16px; height: 16px; }
.settings .volume output { text-align: right; font-size: 13px; }
.settings .volume:has(.slider:disabled) { opacity: 0.5; }
.settings .volume:has(.slider:disabled) .slider { opacity: 1; }

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

/* ---------- Reading area ---------- */
.stage {
  position: relative;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.stage.dragging { outline: 2px dashed var(--accent); outline-offset: -12px; background: var(--accent-soft); }

.pages {
  position: absolute;
  inset: 0;
  display: flex;
  /* safe: a zoomed page larger than the window scrolls instead of being cut off */
  align-items: safe center;
  justify-content: safe center;
  gap: 16px;
  padding: 16px;
  overflow: hidden;
}
.pages.zoomed { overflow: auto; overscroll-behavior: contain; }
.pages.zoomed { cursor: grab; }
.pages.zoomed.grabbing { cursor: grabbing; user-select: none; }

/* Pinch to drag: a ring that follows your thumb and index finger while
   zoomed in, and fills when the page is in your hand. */
.pinch-dot {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
  transition: transform 90ms linear;
}
.pinch-dot[hidden] { display: none; }
.pinch-dot::before {
  content: "";
  position: absolute;
  left: -14px;
  top: -14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2), 0 4px 12px rgba(0, 0, 0, 0.18);
  transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1), background-color 160ms, border-color 160ms;
}
.pinch-dot.grab::before {
  transform: scale(0.72);
  background: var(--accent-strong);
  border-color: #fff;
}
.pages .page { flex: none; }
.pages::-webkit-scrollbar { width: 12px; height: 12px; }
.pages::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: var(--border-strong) padding-box;
}
.pages::-webkit-scrollbar-corner { background: transparent; }
.page {
  background: #fff;
  border-radius: 2px;
  box-shadow: var(--page-shadow);
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 16px;
}
.empty[hidden] { display: none; }
.empty h1 {
  font-size: clamp(22px, 3vw, 28px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
  text-wrap: balance;
}
.empty p { color: var(--muted); margin: 0 0 24px; max-width: 400px; text-wrap: pretty; }
.empty .hint { font-size: 13px; margin: 14px 0 0; }
.empty { overflow: auto; }

/* Continue reading: covers of recent books under the start screen */
.shelf { margin-top: 40px; width: min(100%, 640px); }
.shelf[hidden] { display: none; }
.shelf h2 {
  margin: 0 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.shelf-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}
.shelf-book { position: relative; width: 112px; }
.shelf-open {
  display: grid;
  justify-items: center;
  gap: 8px;
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-weight: 400;
  white-space: normal;
}
.shelf-open:hover:not(:disabled) { background: transparent; }
.shelf-open:active:not(:disabled) { transform: none; }
.shelf-open .book-cover {
  width: 96px;
  box-shadow: var(--page-shadow);
  transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
.shelf-open:hover .book-cover { transform: translateY(-3px); box-shadow: var(--raised-shadow); }
.shelf-open:focus-visible { outline: none; }
.shelf-open:focus-visible .book-cover { outline: 2px solid var(--focus); outline-offset: 3px; }
.shelf-open .book-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
}
.shelf-open .book-meta { font-size: 12px; margin-top: -4px; }
.shelf .book-forget {
  top: -8px;
  right: 0;
  width: 26px;
  min-height: 26px;
  border-radius: 50%;
  border-color: var(--border);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(31, 35, 40, 0.15);
}
.shelf-book:hover .book-forget, .shelf .book-forget:focus-visible { opacity: 1; }

/* The empty-state picture: a spread with a hand-swipe stroke across it */
.empty-art { width: 200px; height: 120px; margin-bottom: 20px; overflow: visible; }
.empty-art .sheet { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
.empty-art .lines { stroke: var(--border); stroke-width: 2; stroke-linecap: round; }
.empty-art .swipe, .empty-art .swipe-head {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.empty-art .swipe {
  stroke-dasharray: 150;
  animation: swipe 3.2s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}
.empty-art .swipe-head { animation: swipe-head 3.2s ease-out infinite; }
@keyframes swipe {
  0% { stroke-dashoffset: 150; }
  35%, 80% { stroke-dashoffset: 0; opacity: 1; }
  100% { stroke-dashoffset: 0; opacity: 0; }
}
@keyframes swipe-head {
  0%, 20% { opacity: 0; }
  35%, 80% { opacity: 1; }
  100% { opacity: 0; }
}

/* "Picked up where you left off" note, shown when a book reopens part-way */
.resume {
  position: absolute;
  left: 50%;
  bottom: 20px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 32px);
  padding: 6px 6px 6px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--raised-shadow);
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 180ms, transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
.resume.show { opacity: 1; transform: translate(-50%, 0); }
.resume[hidden] { display: none; }
.resume .icon { width: 16px; height: 16px; color: #7dd3fc; fill: currentColor; stroke: none; }
.resume .ghost-btn {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
  color: inherit;
  background: transparent;
  border-color: color-mix(in srgb, var(--bg) 35%, transparent);
}
.resume .ghost-btn:hover:not(:disabled) {
  background: color-mix(in srgb, var(--bg) 14%, transparent);
  border-color: color-mix(in srgb, var(--bg) 55%, transparent);
}

/* Gesture cue in the middle of the book: a small pill of frosted glass, so
   the page still shows through around and behind it. */
.cue {
  --p: 0;
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 18px 7px 7px;
  border-radius: 999px;
  color: #1f2328;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.2));
  border: 1px solid rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(10px) saturate(1.8);
  backdrop-filter: blur(10px) saturate(1.8);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.75),
    inset 0 -1px 1px rgba(255, 255, 255, 0.2),
    0 1px 2px rgba(31, 35, 40, 0.08),
    0 8px 24px rgba(31, 35, 40, 0.12);
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.94);
  transition: opacity 160ms ease, transform 260ms cubic-bezier(0.16, 1, 0.3, 1);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .cue { background: rgba(255, 255, 255, 0.88); }
}
.cue[hidden] { display: none; }
.cue.show { opacity: 1; transform: translate(-50%, -50%); }
.cue-badge {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}
.cue.holding .cue-badge::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(#dc2626 calc(var(--p) * 360deg), rgba(31, 35, 40, 0.12) 0);
  -webkit-mask: radial-gradient(circle, transparent 17px, #000 17.5px);
  mask: radial-gradient(circle, transparent 17px, #000 17.5px);
}
.cue-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: #0369a1;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.cue-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}

.goto-error { margin: 0; font-size: 13px; color: var(--live); }
.goto-error:empty { display: none; }

/* Before a book is open, opening one is the main action; gestures can wait. */
body:has(.page-label:empty) .gesture-btn:not(.active):not(:disabled) {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

/* Page-turn animation (js/flip.js): one canvas over the book while a page
   curls from its corner and turns over. */
.flip {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- Status bar ---------- */
.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 32px;
  padding: 4px 16px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.status-text { min-width: 0; }
.statusbar .privacy { display: inline-flex; align-items: center; gap: 6px; }
.statusbar .privacy .icon { width: 14px; height: 14px; }
/* The privacy promise fills the bar whenever there's nothing else to say. */
.status-text:has(#status:not(:empty)) .privacy { display: none; }

/* View controls: zoom and full screen, once a book is open */
.view { display: flex; align-items: center; gap: 2px; margin-right: -8px; }
body:has(.page-label:empty) .view { display: none; }
.view .icon-btn, .view .zoom-label { min-height: 28px; height: 28px; border-color: transparent; background: transparent; }
.view .icon-btn { width: 28px; }
.view .icon { width: 16px; height: 16px; }
.view .icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.view .zoom-label { min-width: 48px; font-size: 12.5px; }
/* At "Fit" the level is still a read-out, so keep it legible. */
.view .zoom-label:disabled { opacity: 1; color: var(--muted); }
/* Bigger targets for fingers. */
@media (pointer: coarse) {
  .view .icon-btn, .view .zoom-label { min-height: 40px; height: 40px; }
  .view .icon-btn { width: 40px; }
}

/* ---------- Camera preview ----------
   One card that folds into a small pill: a clip-path morph from the whole
   card to its bottom-right corner, where the pill's dot and button sit. */
.preview {
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --bar: 40px;
  --pill: 76px;
  position: fixed;
  right: 16px;
  bottom: 48px;
  z-index: 5;
  color: #e8eaed;
  font-size: 12.5px;
  /* drop-shadow follows the clipped shape, box-shadow wouldn't */
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.22)) drop-shadow(0 10px 22px rgba(0, 0, 0, 0.26));
}
.preview[hidden] { display: none; }
.preview-card {
  width: 220px;
  overflow: hidden;
  border-radius: 12px;
  background: #16181b;
  clip-path: inset(0 0 0 0 round 12px);
  transition: clip-path 420ms var(--ease-out);
}
.preview.folded .preview-card {
  clip-path: inset(calc(100% - var(--bar)) 0 0 calc(100% - var(--pill)) round 20px);
  transition-duration: 320ms;
}
.preview-view {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #000;
  transition: opacity 200ms ease, filter 300ms ease;
}
.preview.folded .preview-view { opacity: 0; filter: blur(6px); }
.preview video, .preview canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror, so it moves like a mirror */
}
.preview-bar {
  height: var(--bar);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.preview-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 200ms ease;
}
.preview.folded .preview-text { opacity: 0; transition-duration: 120ms; }

/* Live dot, with the fist-to-pause progress drawn as a ring round it */
.live-dot {
  --progress: 0;
  position: relative;
  width: 18px;
  height: 18px;
  flex: none;
  display: grid;
  place-items: center;
}
.live-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f87171;
  transition: background-color 200ms ease, transform 200ms var(--ease-out);
}
.live-dot.hand::before { transform: scale(1.25); background: #fca5a5; }
.live-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(#f87171 calc(var(--progress) * 360deg), rgba(255, 255, 255, 0.14) 0);
  -webkit-mask: radial-gradient(circle, transparent 6.5px, #000 7.5px);
  mask: radial-gradient(circle, transparent 6.5px, #000 7.5px);
  opacity: 0;
  transition: opacity 150ms ease;
}
.live-dot.fist::after { opacity: 1; }
.live-dot.turn::before { animation: dot-tick 320ms var(--ease-out); }
@keyframes dot-tick { 0% { transform: scale(1.9); background: #7dd3fc; } }

.fold-btn {
  all: unset;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #c4c9cf;
  transition: background-color 150ms ease, color 150ms ease;
}
.fold-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); border-color: transparent; color: #fff; }
.fold-btn:active:not(:disabled) { background: rgba(255, 255, 255, 0.16); transform: none; }
.fold-btn:focus-visible { outline: 2px solid #38bdf8; outline-offset: -2px; }
.fold-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 320ms var(--ease-out);
}
.preview.folded .fold-btn svg { transform: rotate(180deg); }

/* Which way the last gesture was read */
.gesture-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 4px);
  transition: opacity 150ms, transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
}
.gesture-hint:empty { display: none; }
.gesture-hint.show { opacity: 1; transform: translate(-50%, 0); }

/* "Can't see your hand": a note by the camera window, in its dark style */
.hand-warning {
  position: fixed;
  right: 16px;
  bottom: 48px;
  z-index: 6;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: max-content;
  max-width: 260px;
  padding: 10px 14px 10px 12px;
  border-radius: 12px;
  background: #16181b;
  color: #f1f3f5;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.22), 0 10px 22px rgba(0, 0, 0, 0.26);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 180ms ease, transform 300ms cubic-bezier(0.16, 1, 0.3, 1), bottom 320ms cubic-bezier(0.16, 1, 0.3, 1);
}
.hand-warning[hidden] { display: none; }
.hand-warning.show { opacity: 1; transform: none; }
.hand-warning .icon { width: 20px; height: 20px; margin-top: 1px; color: #fbbf24; }
.hand-warning span { display: grid; gap: 2px; }
.hand-warning strong { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.hand-warning small { font-size: 12.5px; line-height: 1.35; color: #b8bec6; }

/* ---------- Full screen ----------
   The toolbar floats over the book and slides away while you read; moving
   the mouse brings it back. The book keeps the whole screen either way. */
body.fullscreen .toolbar,
body.fullscreen .statusbar {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 4;
  transition: transform 260ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 260ms;
}
body.fullscreen .toolbar { top: 0; transform: translateY(-100%); box-shadow: var(--raised-shadow); }
body.fullscreen .statusbar { bottom: 0; transform: translateY(100%); }
body.fullscreen.chrome .toolbar,
body.fullscreen.chrome .statusbar { transform: none; }
body.fullscreen:not(.chrome) .toolbar { box-shadow: none; }
body.fullscreen:not(.chrome) { cursor: none; }

/* ---------- How-to dialog ---------- */
.help {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 17, 20, 0.5);
  padding: 16px;
  z-index: 10;
  animation: fade 160ms ease-out;
}
.help[hidden] { display: none; }
.help-card {
  max-width: 480px;
  max-height: 100%;
  overflow: auto;
  background: var(--surface);
  border-radius: 14px;
  padding: 24px 28px;
  box-shadow: var(--raised-shadow);
  animation: rise 220ms cubic-bezier(0.16, 1, 0.3, 1);
}
.help-card:focus { outline: none; }
.help-card h2 { margin: 0 0 16px; font-size: 20px; letter-spacing: -0.01em; }
.help-card ol {
  list-style: none;
  counter-reset: step;
  margin: 0 0 16px;
  padding: 0;
}
.help-card li {
  counter-increment: step;
  position: relative;
  padding-left: 36px;
  margin-bottom: 12px;
}
.help-card li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 650;
}
.help-card .tips {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 14px;
}
.help-card .note { font-size: 14px; margin: 0 0 20px; }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  font: 600 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
  background: var(--surface);
}
.privacy { color: var(--muted); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

@media (max-width: 720px) {
  .toolbar {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand actions" "nav nav";
    padding: 8px 12px;
    row-gap: 6px;
  }
  .library { grid-area: brand; gap: 8px; }
  .brand-text { display: none; }
  .nav { grid-area: nav; justify-content: center; }
  .nav:has(.page-label:empty) { display: none; }
  .nav { gap: 2px; }
  .page-btn { min-width: 0; }
  /* Only when there's a message or a book to zoom */
  body:has(.page-label:empty) .statusbar:has(#status:empty) { display: none; }
  .actions { grid-area: actions; gap: 6px; }
  .panel { inset: auto 8px 8px 8px; width: auto; max-height: calc(100dvh - 16px); }
  .panel::backdrop { background: rgba(15, 17, 20, 0.35); }
  .panel.recent { inset: auto 8px 8px 8px; width: auto; }
  .toolbar { position: relative; z-index: 9; }
  /* No room to share on a phone: the contents slide over the book instead. */
  .sidebar {
    position: fixed;
    inset: var(--toolbar-h, 0px) auto 0 0; /* under the toolbar, so its button still closes it */
    z-index: 8;
    width: min(320px, 86vw);
    transform: translateX(-100%);
    transition: transform 300ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 300ms;
  }
  .sidebar.open { width: min(320px, 86vw); transform: none; box-shadow: var(--raised-shadow); }
  .sidebar-inner { width: 100%; }
  .statusbar .privacy { display: none; }
  .status-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .preview-card { width: 168px; }
  .preview-text { font-size: 11.5px; }
  .hand-warning { max-width: calc(100vw - 32px); }
  .help-card { padding: 20px; }
}

@media (max-width: 480px) {
  .library .brand { display: none; } /* room for the buttons */
}

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