html,
body {
  overflow: hidden;
}

:root {
  --top-h: calc(62px + env(safe-area-inset-top, 0px));
  --bar-h: calc(70px + env(safe-area-inset-bottom, 0px));
  --nav-w: 360px;
}

/* Which screen is showing */

body[data-view="boot"] > :not(svg):not(script),
body[data-view="empty"] .appbar,
body[data-view="empty"] #stage,
body[data-view="empty"] .toolbar,
body[data-view="empty"] .side-arrow,
body[data-view="empty"] .panel,
body[data-view="empty"] .loader,
body:not([data-view="empty"]) .empty {
  display: none !important;
}

/* ============================================================================================
 * Start screen
 * ========================================================================================== */

.empty {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  overflow-y: auto;
  background:
    radial-gradient(520px 380px at 12% 8%, color-mix(in srgb, var(--coral) 13%, transparent), transparent 70%),
    radial-gradient(560px 420px at 92% 18%, color-mix(in srgb, var(--indigo) 11%, transparent), transparent 70%),
    radial-gradient(620px 460px at 80% 100%, color-mix(in srgb, var(--teal) 12%, transparent), transparent 70%),
    radial-gradient(480px 360px at 5% 95%, color-mix(in srgb, var(--saffron-bright) 13%, transparent), transparent 70%),
    var(--bg);
}

.theme-chip {
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
}

.hero {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* A fan of paper sheets in the palette, like swatches from a colour book. */
.fan {
  position: relative;
  width: 120px;
  height: 128px;
  margin-bottom: 30px;
}

.sheet {
  position: absolute;
  left: 22px;
  top: 6px;
  width: 76px;
  height: 104px;
  border-radius: 12px;
  transform-origin: 50% 110%;
  box-shadow: 0 10px 24px rgb(40 30 20 / 16%);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.s1 { background: var(--teal); transform: rotate(-24deg); }
.s2 { background: var(--saffron-bright); transform: rotate(-10deg); }
.s3 { background: var(--coral); transform: rotate(5deg); }

.s4 {
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--indigo);
  transform: rotate(18deg);
  border: 1px solid var(--line);
}

.s4 .ico {
  width: 34px;
  height: 34px;
  stroke-width: 1.6;
}

.hero:hover .s1 { transform: rotate(-32deg); }
.hero:hover .s2 { transform: rotate(-15deg); }
.hero:hover .s3 { transform: rotate(6deg); }
.hero:hover .s4 { transform: rotate(24deg); }

.hero h1 {
  font-size: clamp(32px, 6vw, 48px);
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.04em;
  max-width: 12ch;
}

.hero h1 em {
  font-style: normal;
  background: linear-gradient(95deg, var(--coral), var(--saffron-bright) 55%, var(--plum));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  margin-top: 14px;
  font-size: 17px;
  color: var(--muted);
}

.drop {
  margin-top: 30px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 30px 20px 26px;
  border: 1.5px dashed color-mix(in srgb, var(--muted) 45%, transparent);
  border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(6px);
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.drop:hover {
  border-color: var(--accent);
  background: var(--surface);
}

.drop-hint {
  font-size: 13.5px;
  color: var(--muted);
}

.badges {
  margin-top: 22px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.d-teal { background: var(--teal); }
.d-saffron { background: var(--saffron-bright); }
.d-coral { background: var(--coral); }

.empty-error {
  margin-top: 18px;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--coral-soft);
  color: var(--danger);
  font-weight: 550;
  font-size: 14px;
}

.dropveil {
  position: fixed;
  inset: 12px;
  z-index: 100;
  display: grid;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 26px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

.dropveil div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--accent);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.dropveil .ico {
  width: 46px;
  height: 46px;
}

/* ============================================================================================
 * Reader chrome
 * ========================================================================================== */

.appbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--top-h);
  padding: env(safe-area-inset-top, 0px) max(16px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--indigo-soft);
  color: var(--indigo);
}

.mark .ico {
  width: 20px;
  height: 20px;
  stroke-width: 1.9;
}

.doc {
  flex: 1;
  min-width: 0;
}

.doc-title {
  font-weight: 600;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-sub {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.appbar-actions {
  display: flex;
  gap: 8px;
}

#stage {
  position: fixed;
  top: var(--top-h);
  left: 0;
  right: 0;
  bottom: var(--bar-h);
  /* The engine stylesheet gives its container 100% width and height, which would ignore the insets. */
  width: auto;
  height: auto;
  background: var(--stage);
}

.side-arrow {
  position: fixed;
  top: calc(var(--top-h) + (100dvh - var(--top-h) - var(--bar-h)) / 2);
  z-index: 15;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  margin-top: -25px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: opacity 0.2s, transform 0.15s, color 0.15s;
}

.side-arrow:hover:not(:disabled) {
  color: var(--accent);
  transform: scale(1.06);
}

.side-arrow:disabled {
  opacity: 0;
  pointer-events: none;
}

.side-arrow .ico {
  width: 22px;
  height: 22px;
  stroke-width: 2.2;
}

.side-prev {
  left: max(18px, env(safe-area-inset-left));
}

.side-next {
  right: max(18px, env(safe-area-inset-right));
}

/* Loading and errors */

.loader,
.notice {
  position: fixed;
  top: var(--top-h);
  left: 0;
  right: 0;
  bottom: var(--bar-h);
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--stage);
  transition: opacity 0.35s ease;
}

.loader.done {
  opacity: 0;
  pointer-events: none;
}

.loader-card {
  width: min(300px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
}

.loader-title {
  margin-top: 14px;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loader-detail {
  font-size: 13px;
  color: var(--muted);
  min-height: 1.5em;
  font-variant-numeric: tabular-nums;
}

.loader .meter {
  width: 100%;
  margin-top: 6px;
}

/* A ring in the palette's colours. */
.ring {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: conic-gradient(var(--coral), var(--saffron-bright), var(--teal), var(--indigo), var(--plum), var(--coral));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  animation: spin 0.9s linear infinite;
}

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

.notice {
  z-index: 13;
  align-content: center;
  gap: 18px;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

#loadbar {
  position: fixed;
  top: var(--top-h);
  left: 0;
  right: 0;
  height: 3px;
  z-index: 31;
  overflow: hidden;
  pointer-events: none;
}

#loadbar::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 35%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--coral), var(--saffron-bright));
  animation: load 1.1s ease-in-out infinite;
}

@keyframes load {
  from {
    left: -35%;
  }
  to {
    left: 100%;
  }
}

/* Toolbar */

.toolbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--bar-h);
  padding: 0 max(12px, env(safe-area-inset-right)) env(safe-area-inset-bottom, 0px) max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 30;
}

.tool-group {
  display: flex;
  gap: 4px;
  min-width: 0;
}

.tool-group-end {
  justify-content: flex-end;
}

.tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px 0 10px;
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}

.tool .ico {
  color: var(--c, var(--text));
  stroke-width: 1.9;
}

.tool:hover:not(:disabled) {
  background: var(--hover);
}

.tool[aria-expanded="true"],
.tool.active {
  background: var(--c-soft, var(--hover));
  color: var(--c, var(--text));
}

.tool:disabled {
  opacity: 0.35;
  cursor: default;
}

.pager {
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-pill {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 44px;
  padding: 0 14px 0 5px;
  border-radius: 999px;
  background: var(--surface-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: text;
}

.page-pill input {
  width: 62px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  text-align: center;
  font-weight: 650;
  box-shadow: var(--shadow-sm);
}

.page-pill input:focus {
  outline: 2px solid var(--accent);
}

#pageTotal {
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

/* ============================================================================================
 * Drawers
 * ========================================================================================== */

.panel {
  position: fixed;
  top: var(--top-h);
  bottom: var(--bar-h);
  width: var(--nav-w);
  z-index: 25;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.28s;
  will-change: transform;
}

.panel.open {
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

.panel-nav {
  left: 0;
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
}

.panel-settings {
  right: 0;
  border-left: 1px solid var(--line);
  transform: translateX(100%);
}

.grab {
  display: none;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 10px 16px;
}

.panel-title {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.025em;
}

#scrim {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgb(20 14 8 / 34%);
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface-2);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs button {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 550;
  white-space: nowrap;
}

.tabs button:hover {
  color: var(--text);
}

.tabs button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.pane {
  flex: 1;
  min-height: 0;
}

/* Thumbnails */

.thumbs {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 16px 18px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 18px 14px;
  align-content: start;
}

.thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.thumb-frame {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: var(--page-aspect, 0.75);
  border-radius: 8px;
  background: #f3efe9;
  box-shadow: 0 0 0 1px var(--line), var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s;
}

.thumb-frame img,
.thumb-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.thumb-frame:empty::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 2.5px solid rgb(0 0 0 / 8%);
  border-top-color: var(--coral);
  animation: spin 0.8s linear infinite;
}

.thumb:hover .thumb-frame {
  transform: translateY(-2px);
  box-shadow: 0 0 0 1px var(--line), var(--shadow);
}

.thumb[aria-current="true"] {
  color: var(--coral);
  font-weight: 650;
}

.thumb[aria-current="true"] .thumb-frame {
  box-shadow: 0 0 0 2.5px var(--coral), var(--shadow);
}

/* Contents */

.outline {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 10px 20px;
}

.outline ol {
  list-style: none;
  margin: 0;
  padding: 0 0 0 14px;
}

.outline > ol {
  padding-left: 0;
}

.outline button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  text-align: left;
  font-weight: 500;
}

.outline button:hover {
  background: var(--hover);
  color: var(--coral);
}

/* Search */

.search,
.text {
  display: flex;
  flex-direction: column;
}

.search-form {
  position: relative;
  padding: 6px 16px 0;
}

.search-form .ico {
  position: absolute;
  left: 30px;
  top: 19px;
  color: var(--teal);
  stroke-width: 2;
  pointer-events: none;
}

.search-form .field {
  padding-left: 42px;
  background: var(--surface-2);
  border-color: transparent;
}

.search-form .field:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px var(--teal-soft);
}

.search-status {
  margin: 12px 20px 8px;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.5em;
}

.search-results {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 12px 18px;
}

.result {
  display: block;
  width: 100%;
  margin-bottom: 6px;
  padding: 11px 13px;
  border-radius: 14px;
  background: var(--surface-2);
  text-align: left;
  transition: background-color 0.15s, box-shadow 0.15s;
}

.result:hover,
.result[aria-current="true"] {
  background: var(--teal-soft);
}

.result[aria-current="true"] {
  box-shadow: inset 0 0 0 1.5px var(--teal);
}

.result-page {
  display: block;
  font-size: 12px;
  font-weight: 650;
  color: var(--teal);
}

.result-snippet {
  display: block;
  margin-top: 3px;
  font-size: 13.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.result-snippet mark {
  background: color-mix(in srgb, var(--saffron-bright) 40%, transparent);
  color: inherit;
  border-radius: 4px;
  padding: 0 2px;
}

/* Text */

.text-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 10px 20px;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.text-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 20px 28px;
  user-select: text;
  -webkit-user-select: text;
  line-height: 1.7;
}

.text-body h3 {
  margin: 20px 0 6px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--plum);
}

.text-body h3:first-child {
  margin-top: 0;
}

.text-body p {
  margin: 0 0 0.85em;
}

.text-body .empty-line {
  color: var(--muted);
}

/* Settings */

.settings-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 2px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setting-head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.setting-switch {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}

.hint {
  display: block;
  font-size: 12.5px;
  font-weight: 450;
  color: var(--muted);
  letter-spacing: 0;
}

input[type="range"] {
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  accent-color: var(--plum);
}

.actions-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.action {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 0 8px 0 6px;
  border-radius: 14px;
  color: var(--text);
  text-decoration: none;
  font-weight: 550;
  cursor: pointer;
}

.action > span:not(.tile) {
  flex: 1;
  text-align: left;
}

.action .chev {
  color: var(--muted);
  width: 18px;
  height: 18px;
}

.action:hover {
  background: var(--hover);
}

/* ============================================================================================
 * Dialogs
 * ========================================================================================== */

.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 80px rgb(20 14 8 / 30%);
}

.modal::backdrop {
  background: rgb(20 14 8 / 45%);
  backdrop-filter: blur(3px);
}

.card {
  margin: 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-head {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 6px;
}

.modal-head h2 {
  font-size: 21px;
}

.modal-head p {
  margin-top: 2px;
  font-size: 14px;
  color: var(--muted);
}

.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
}

.file-row .ico {
  width: 24px;
  height: 24px;
  color: var(--indigo);
}

.file-meta {
  min-width: 0;
}

.file-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.status {
  font-size: 13.5px;
}

.status.error {
  color: var(--danger);
  font-weight: 550;
}

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

.link-row .field {
  flex: 1;
  min-width: 0;
  background: var(--surface-2);
  border-color: transparent;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
}

.check input {
  width: 18px;
  height: 18px;
  accent-color: var(--saffron);
}

#printCustom {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bar-h) + 16px);
  transform: translateX(-50%);
  z-index: 200;
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 550;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* ============================================================================================
 * Sizes
 * ========================================================================================== */

@media (min-width: 1200px) {
  body.nav-docked #stage {
    left: var(--nav-w);
  }

  body.settings-docked #stage {
    right: var(--nav-w);
  }

  body.nav-docked .side-prev {
    left: calc(var(--nav-w) + 18px);
  }

  body.settings-docked .side-next {
    right: calc(var(--nav-w) + 18px);
  }

  .panel {
    transition: none;
  }
}

@media (max-width: 1199px) {
  .panel-nav {
    box-shadow: 12px 0 40px rgb(20 14 8 / 16%);
  }

  .panel-settings {
    box-shadow: -12px 0 40px rgb(20 14 8 / 16%);
  }
}

@media (max-width: 900px) {
  .tool {
    padding: 0 10px;
  }
}

/* Phones: a tab bar with labels under the icons, and drawers become sheets */

@media (max-width: 699px) {
  :root {
    --top-h: calc(58px + env(safe-area-inset-top, 0px));
    --bar-h: calc(66px + env(safe-area-inset-bottom, 0px));
  }

  .hide-sm,
  .side-arrow {
    display: none !important;
  }

  .mark {
    width: 34px;
    height: 34px;
  }

  .appbar .btn {
    min-height: 38px;
    padding: 0 14px;
  }

  .toolbar {
    display: flex;
    justify-content: space-around;
    gap: 0;
    padding-left: max(4px, env(safe-area-inset-left));
    padding-right: max(4px, env(safe-area-inset-right));
  }

  .tool-group,
  .pager {
    display: contents;
  }

  .tool {
    flex: 1 1 0;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    height: 58px;
    padding: 0 2px;
    font-size: 11px;
    font-weight: 550;
    border-radius: 14px;
  }

  .tool .ico {
    width: 22px;
    height: 22px;
  }

  .tool[aria-expanded="true"],
  .tool.active {
    background: transparent;
  }

  .tool[aria-expanded="true"] .ico,
  .tool.active .ico {
    background: var(--c-soft, var(--hover));
    border-radius: 999px;
    width: 44px;
    padding: 2px 0;
    box-sizing: content-box;
  }

  .page-pill {
    flex: 0 0 auto;
    height: 40px;
    padding: 0 10px 0 4px;
    gap: 3px;
  }

  .page-pill input {
    width: 48px;
    height: 32px;
  }

  #pageTotal {
    font-size: 13px;
  }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 86dvh;
    z-index: 35;
    border: 0;
    border-radius: 26px 26px 0 0;
    box-shadow: 0 -12px 40px rgb(20 14 8 / 22%);
    transform: translateY(100%);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .panel-nav {
    height: 80dvh;
  }

  #scrim {
    z-index: 34;
  }

  .grab {
    display: block;
    width: 38px;
    height: 5px;
    margin: 9px auto 0;
    border-radius: 999px;
    background: var(--line);
  }

  .panel-head {
    padding-top: 8px;
  }

  .thumbs {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px 10px;
  }

  .segmented button {
    font-size: 13.5px;
  }

  .toast {
    bottom: calc(var(--bar-h) + 12px);
  }

  .hero h1 {
    max-width: 11ch;
  }

  .lede {
    font-size: 16px;
  }

  .actions {
    flex-direction: column-reverse;
  }

  .actions .btn {
    width: 100%;
  }
}

@media (max-width: 360px) {
  .page-pill input {
    width: 40px;
  }

  .tool {
    font-size: 10.5px;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  :root {
    --top-h: calc(48px + env(safe-area-inset-top, 0px));
    --bar-h: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  .doc-sub {
    display: none;
  }

  .side-arrow {
    width: 44px;
    height: 44px;
    margin-top: -22px;
  }

  .panel {
    max-height: calc(100dvh - var(--top-h));
  }
}

@media (prefers-reduced-motion: reduce) {
  #loadbar::before,
  .ring {
    animation-duration: 2.4s;
  }
}

/* Touch screens have no hover: a tapped control must not stay highlighted */

@media (hover: none) {
  .tool:hover:not(:disabled) {
    background: transparent;
  }

  .side-arrow:hover:not(:disabled) {
    transform: none;
    color: var(--text);
  }

  .thumb:hover:not([aria-current="true"]) .thumb-frame {
    transform: none;
    box-shadow: 0 0 0 1px var(--line), var(--shadow-sm);
  }

  .action:hover,
  .outline button:hover {
    background: transparent;
    color: inherit;
  }

  .result:hover:not([aria-current="true"]) {
    background: var(--surface-2);
  }

  .hero:hover .sheet {
    transform: none;
  }

  .hero:hover .s1 { transform: rotate(-24deg); }
  .hero:hover .s2 { transform: rotate(-10deg); }
  .hero:hover .s3 { transform: rotate(5deg); }
  .hero:hover .s4 { transform: rotate(18deg); }
}

/* Printing: only the rendered pages */

#printSheet {
  display: none;
}

@media print {
  @page {
    margin: 0;
  }

  html,
  body {
    overflow: visible;
    height: auto;
    background: #fff;
  }

  body > *:not(#printSheet) {
    display: none !important;
  }

  #printSheet {
    display: block;
  }

  .print-page {
    display: block;
    width: 100vw;
    height: 100vh;
    object-fit: contain;
    break-after: page;
  }
}

/* ============================================================================================
 * Calmer colour: neutral icons, colour kept for what is active or important
 * ========================================================================================== */

.settings-body .tile,
.actions-list .tile {
  background: var(--surface-2);
  color: var(--text);
}

.tool .ico {
  color: var(--muted);
}

.tool:hover:not(:disabled) .ico {
  color: var(--text);
}

.tool[aria-expanded="true"],
.tool.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.tool[aria-expanded="true"] .ico,
.tool.active .ico {
  color: var(--accent);
}

.mark {
  background: var(--surface-2);
  color: var(--text);
}

.search-form .ico {
  color: var(--muted);
}

.search-form .field {
  padding-right: 44px;
}

.search-form .field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.search-clear {
  position: absolute;
  right: 24px;
  top: 13px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: var(--muted);
}

.search-clear:hover {
  background: var(--hover);
  color: var(--text);
}

.search-form .search-clear .ico {
  position: static;
  width: 16px;
  height: 16px;
}

.result:hover,
.result[aria-current="true"] {
  background: var(--hover);
}

.result[aria-current="true"] {
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.result-page {
  color: var(--accent);
}

.text-body h3 {
  color: var(--muted);
}

.switch:checked {
  background: var(--accent);
}

.file-row .ico {
  color: var(--muted);
}

.modal {
  overflow: visible;
}

/* ============================================================================================
 * The toolbar: a floating dock on wide screens, a tab bar on phones
 * ========================================================================================== */

@media (min-width: 700px) {
  :root {
    --bar-h: 0px;
  }

  .toolbar {
    left: 50%;
    right: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    height: 60px;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px) saturate(1.2);
    box-shadow: 0 14px 40px rgb(40 30 20 / 16%), 0 2px 6px rgb(40 30 20 / 6%);
    transition: left 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .tool-group,
  .pager {
    gap: 2px;
  }

  .pager {
    padding: 0 6px;
    margin: 0 2px;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .tool {
    min-height: 46px;
    border-radius: 14px;
  }

  .page-pill {
    height: 46px;
    background: transparent;
    padding: 0 10px 0 4px;
  }

  .page-pill input {
    background: var(--surface-2);
    box-shadow: none;
  }

  .toast {
    bottom: 96px;
  }
}

/* With a drawer docked beside the book, the dock stays centred on the book. */
@media (min-width: 1200px) {
  body.nav-docked .toolbar {
    left: calc(50% + var(--nav-w) / 2);
  }

  body.settings-docked .toolbar {
    left: calc(50% - var(--nav-w) / 2);
  }

  body.nav-docked.settings-docked .toolbar {
    left: 50%;
  }
}

@media (max-width: 699px) {
  .tool[aria-expanded="true"],
  .tool.active {
    background: transparent;
  }

  .tool[aria-expanded="true"] .ico,
  .tool.active .ico {
    background: var(--accent-soft);
  }
}

/* Sound toggle */

.sound-btn {
  background: transparent;
}

.sound-btn[aria-pressed="false"] {
  color: var(--muted);
  opacity: 0.75;
}
