/* ===================================================================== tokens
   Cool neutral surfaces, one blue accent, hairline borders and very light
   shadows. Light is defined on bare :root so it is always the fallback; dark
   only redefines the same names. */

:root {
  --bg: #fafbfc;
  --surface: #ffffff;
  --surface-2: #f3f5f7;
  --surface-3: #e6e9ed;
  --text: #14171a;
  --text-soft: #3d444d;
  --muted: #767e8a;
  --line: #e8eaee;
  --line-strong: #d2d7de;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: rgb(37 99 235 / 0.1);
  --good: #12805c;
  --good-soft: rgb(18 128 92 / 0.1);
  --danger: #dc2626;
  --page-bg: #ffffff;
  --ink: #1b1d21;
  --ink-fg: #ffffff;

  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.05);
  --shadow-md: 0 4px 12px rgb(16 24 40 / 0.08), 0 1px 3px rgb(16 24 40 / 0.05);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 0.14), 0 2px 8px rgb(16 24 40 / 0.06);
  --shadow-page: 0 1px 3px rgb(16 24 40 / 0.1), 0 8px 28px rgb(16 24 40 / 0.08);

  --radius: 8px;
  --radius-lg: 12px;
  --appbar-h: 46px;
  --toolrow-h: 42px;
  --rail-w: 128px;

  /* Mark palette, taken from the reference toolbar. Its black pen colour is
     left out: a black highlight buries the text underneath it. */
  --c-amber: 245 158 11;
  --c-green: 34 197 94;
  --c-blue: 37 99 235;
  --c-red: 239 68 68;
  --c-purple: 168 85 247;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --surface: #171a1f;
    --surface-2: #1e2229;
    --surface-3: #272c34;
    --text: #eef1f5;
    --text-soft: #c3cad4;
    --muted: #8d95a1;
    --line: #262b33;
    --line-strong: #363d47;
    --accent: #6c9bff;
    --accent-ink: #0b1524;
    --accent-soft: rgb(108 155 255 / 0.15);
    --good: #4ec99b;
    --good-soft: rgb(78 201 155 / 0.14);
    --danger: #ff8a80;
    --page-bg: #ffffff;
    --ink: #e8ecf2;
    --ink-fg: #12151a;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 14px rgb(0 0 0 / 0.45);
    --shadow-lg: 0 14px 38px rgb(0 0 0 / 0.6);
    --shadow-page: 0 1px 3px rgb(0 0 0 / 0.5), 0 10px 30px rgb(0 0 0 / 0.45);

    color-scheme: dark;
  }
}

/* ====================================================================== base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The UA rule for [hidden] is display:none, which any author `display` beats.
   Several components here set display on the same elements they hide. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  display: block;
  overflow: visible;
}

kbd {
  display: inline-block;
  min-width: 19px;
  padding: 2px 5px;
  font: 600 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
}

.view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* =================================================================== buttons */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font: 500 13.5px/1 inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

.btn .icon {
  width: 17px;
  height: 17px;
}

.btn:hover {
  background: var(--surface-2);
}

.btn-primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: transparent;
}

.btn-primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

.btn-quiet {
  background: transparent;
  border-color: transparent;
}

.btn-quiet:hover {
  background: var(--surface-2);
  border-color: transparent;
}

.btn-small {
  padding: 5px 10px;
  font-size: 12.5px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--text-soft);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.icon-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.icon-danger:hover {
  color: var(--danger);
  background: rgb(220 38 38 / 0.1);
}

.linkish {
  padding: 2px;
  font: 500 13px/1.4 inherit;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

.linkish:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ===================================================================== auth */

.boot {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2.5px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.auth-view {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(370px, 100%);
  padding: 30px 30px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.mark,
.brand-badge {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--ink-fg);
  background: var(--ink);
  border-radius: 9px;
}

.mark {
  width: 40px;
  height: 40px;
  margin-bottom: 16px;
  border-radius: 10px;
}

.auth-card h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 640;
  letter-spacing: -0.015em;
}

.auth-sub {
  margin: 4px 0 20px;
  color: var(--muted);
  font-size: 13.5px;
}

.auth-card form {
  display: grid;
  gap: 9px;
}

.auth-card input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: border-color 0.14s, box-shadow 0.14s;
}

.auth-card input::placeholder {
  color: var(--muted);
}

.auth-card input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.auth-card .btn {
  justify-content: center;
  padding: 10px 12px;
  font-size: 14px;
}

.auth-message {
  margin: 13px 0 0;
  padding: 8px 11px;
  font-size: 13px;
  color: var(--danger);
  background: rgb(220 38 38 / 0.08);
  border-radius: 7px;
}

.auth-message.is-good {
  color: var(--good);
  background: var(--good-soft);
}

.auth-links {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

/* =================================================================== appbar */

.appbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--appbar-h);
  padding: 0 12px;
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.appbar-spacer {
  flex: 1;
}

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

.appbar-back {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: none;
  color: var(--ink-fg);
  background: var(--ink);
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

.appbar-back .icon {
  width: 17px;
  height: 17px;
}

.appbar-back:hover {
  filter: brightness(1.1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 640;
  letter-spacing: -0.01em;
}

.doc-title {
  min-width: 0;
  margin: 0;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-pages {
  flex: none;
  color: var(--muted);
  font-size: 12.5px;
}

.doc-pages:empty {
  display: none;
}

.saved-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  padding: 3px 8px 3px 6px;
  font-size: 11.5px;
  font-weight: 550;
  color: var(--good);
  background: var(--good-soft);
  border-radius: 20px;
}

.saved-dot {
  width: 5px;
  height: 5px;
  background: currentColor;
  border-radius: 50%;
}

.account-email {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12.5px;
}

.account-email:empty {
  display: none;
}

/* ================================================================== toolrow */

.toolrow {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--toolrow-h);
  padding: 0 10px;
  flex: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.toolrow > * {
  flex: none;
}

.toolrow-spacer {
  flex: 1 1 auto;
}

.tool-cluster {
  display: flex;
  align-items: center;
  gap: 1px;
}

.tool-sep {
  width: 1px;
  height: 20px;
  margin: 0 3px;
  background: var(--line);
}

.zoom-level {
  min-width: 42px;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text-soft);
}

.pager-field {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 7px 0 3px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 7px;
}

.pager-field input {
  width: 30px;
  padding: 5px 2px;
  font: 550 12.5px/1 inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 5px;
}

.pager-field input:focus {
  outline: none;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent);
}

/* Reading position, along the bottom edge of the tool row. */
.read-progress {
  position: absolute;
  inset: auto 0 -1px 0;
  height: 2px;
  pointer-events: none;
}

.read-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s ease;
}

/* ============================================================ colour swatches
   Plain circles in a row; the active one takes a ring. */

.swatches {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 2px;
}

.swatch {
  position: relative;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.swatch .chip {
  width: 13px;
  height: 13px;
  background: rgb(var(--dot));
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12);
  transition: transform 0.12s;
}

.swatch .key {
  display: none;
}

.swatch:hover .chip {
  transform: scale(1.15);
}

.swatch.is-active {
  box-shadow: 0 0 0 1.5px rgb(var(--dot));
}

.swatch.is-active .chip {
  width: 14px;
  height: 14px;
}

/* Absolutely centred so it sits on the toolbar's midline regardless of how
   wide the clusters either side happen to be. */
.tool-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
}

.weights {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 2px;
}

.weight-dot {
  display: grid;
  place-items: center;
  width: 20px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.weight-dot span {
  background: var(--muted);
  border-radius: 50%;
  transition: background 0.12s, transform 0.12s;
}

.weight-dot.w-1 span { width: 4px; height: 4px; }
.weight-dot.w-2 span { width: 6px; height: 6px; }
.weight-dot.w-3 span { width: 8px; height: 8px; }
.weight-dot.w-4 span { width: 10px; height: 10px; }

.weight-dot:hover span {
  background: var(--text-soft);
}

.weight-dot.is-active span {
  background: var(--text);
  transform: scale(1.1);
}

.style-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.style-btn .icon {
  width: 19px;
  height: 19px;
}

.style-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.style-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* =================================================================== library */

.library-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.library-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 24px 22px 60px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  padding: 26px 24px;
  font: inherit;
  color: var(--muted);
  text-align: center;
  background: var(--surface);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, color 0.14s;
}

.dropzone-icon {
  width: 24px;
  height: 24px;
  margin-bottom: 6px;
  color: var(--muted);
  transition: color 0.14s, transform 0.14s;
}

.dropzone-title {
  font-size: 14px;
  font-weight: 550;
  color: var(--text);
}

.dropzone-sub {
  font-size: 12.5px;
}

.dropzone:hover,
.dropzone.is-over {
  color: var(--text-soft);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.dropzone:hover .dropzone-icon,
.dropzone.is-over .dropzone-icon {
  color: var(--accent);
  transform: translateY(-2px);
}

.upload-list:not(:empty) {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.upload-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  padding: 10px 13px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.upload-row .track {
  grid-column: 1 / -1;
  height: 3px;
  background: var(--surface-3);
  border-radius: 2px;
  overflow: hidden;
}

.upload-row .track span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.25s ease;
}

.upload-row.is-error {
  color: var(--danger);
  border-color: currentColor;
}

.library-status {
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 13.5px;
  text-align: center;
}

.library-status:empty {
  display: none;
}

.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 20px 18px;
  margin: 24px 0 0;
  padding: 0;
  list-style: none;
}

.doc-item {
  position: relative;
}

.doc-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  cursor: pointer;
}

/* The cover is the PDF's first page, rendered in the browser at upload time. */
.cover {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  background: var(--page-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s cubic-bezier(0.2, 0, 0.2, 1), box-shadow 0.16s,
    border-color 0.16s;
}

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

.cover-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--line-strong);
}

.cover-fallback .icon {
  width: 30px;
  height: 30px;
}

.doc-card:hover .cover {
  transform: translateY(-3px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.cover-progress {
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: rgb(0 0 0 / 0.1);
}

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

.doc-name {
  font-size: 13.5px;
  font-weight: 550;
  line-height: 1.35;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 7px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11.5px;
}

.doc-meta .dot {
  width: 2.5px;
  height: 2.5px;
  background: currentColor;
  border-radius: 50%;
  opacity: 0.6;
}

.doc-meta .marks {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  font-weight: 550;
}

.doc-meta .marks::before {
  content: "";
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
}

.doc-delete {
  position: absolute;
  top: 7px;
  right: 7px;
  color: var(--text);
  background: rgb(255 255 255 / 0.92);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 0.12s, transform 0.12s;
}

.doc-item:hover .doc-delete,
.doc-delete:focus-visible {
  opacity: 1;
  transform: scale(1);
}

/* ==================================================================== reader */

.reader-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* No `scroll-behavior: smooth` here on purpose: it would override the instant
   jump when reopening a document at the page you left off on. goToPage picks
   smooth or instant per call. */
.viewer {
  position: relative;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--bg);
}

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 22px 14px 70px;
}

.reader-status {
  position: absolute;
  inset-inline: 0;
  top: 42%;
  margin: 0;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

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

/* One page: canvas + pdf.js text layer + our mark overlay, stacked. */
/* `contain: layout style` and not `content`: paint containment would clip the
   margin badges and the note cards, which live outside the page box. */
.page {
  position: relative;
  background: var(--page-bg);
  border-radius: 2px;
  box-shadow: var(--shadow-page);
  contain: layout style;
}

.page canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

/* A page that has not been rasterised yet is just an empty white box, which
   reads as a blank page rather than a loading one. Mark it. */
.page:not(.is-rendered)::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid rgb(0 0 0 / 0.09);
  border-top-color: rgb(0 0 0 / 0.28);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

body.is-inverted .page canvas {
  filter: invert(1) hue-rotate(180deg);
}

body.is-inverted .page {
  background: #101010;
}

body.is-inverted .page:not(.is-rendered)::after {
  border-color: rgb(255 255 255 / 0.12);
  border-top-color: rgb(255 255 255 / 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .page:not(.is-rendered)::after,
  .spinner {
    animation-duration: 2.4s;
  }
}

.page .textLayer {
  --total-scale-factor: 1;
}

.page .textLayer ::selection {
  background: rgb(var(--c-blue) / 0.28);
}

.hl-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* Marks never take pointer events — otherwise mousedown on one would swallow
   the drag and you could not select text through your own marks. Clicks and
   hover are resolved by hit-testing in app.js instead. */
.hl {
  position: absolute;
  pointer-events: none;
  mix-blend-mode: multiply;
  transition: background 0.12s;
  --alpha: 0.38;
  --hover-alpha: 0.58;
  --bar: 2px;
}

.hl.w-1 { --alpha: 0.2; --hover-alpha: 0.34; --bar: 1px; }
.hl.w-2 { --alpha: 0.38; --hover-alpha: 0.55; --bar: 2px; }
.hl.w-3 { --alpha: 0.54; --hover-alpha: 0.68; --bar: 3px; }
.hl.w-4 { --alpha: 0.7; --hover-alpha: 0.82; --bar: 4px; }

.hl.style-highlight {
  background: rgb(var(--dot) / var(--alpha));
  border-radius: 2px;
}

/* Underline and strike are drawn as a bar inside the same box, so all three
   styles share one element and one set of coordinates. */
.hl.style-underline {
  background: linear-gradient(rgb(var(--dot)), rgb(var(--dot))) 0 calc(100% - 1px) / 100%
    var(--bar) no-repeat;
}

.hl.style-strike {
  background: linear-gradient(rgb(var(--dot)), rgb(var(--dot))) 0 58% / 100% var(--bar) no-repeat;
}

body.is-inverted .hl {
  mix-blend-mode: screen;
  --alpha: 0.3;
  --hover-alpha: 0.48;
}

.hl.style-highlight.is-hover {
  background: rgb(var(--dot) / var(--hover-alpha));
}

.hl.style-underline.is-hover,
.hl.style-strike.is-hover {
  background-color: rgb(var(--dot) / 0.16);
}

.hl.is-pending {
  opacity: 0.55;
}

/* A note shows as a small tag at the end of the mark. */
.note-flag {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4px 0 0 -3px;
  background: rgb(var(--dot));
  border: 1.5px solid var(--page-bg);
  border-radius: 50% 50% 50% 1px;
  pointer-events: none;
  z-index: 1;
}

body.is-inverted .note-flag {
  border-color: #101010;
}

/* ============================================================== page rail */

.rail {
  display: flex;
  flex-direction: column;
  width: var(--rail-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.rail-head {
  padding: 10px 12px;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.thumb-list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 10px 0 24px;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.thumb {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 6px 12px 8px;
}

.thumb-frame {
  display: block;
  width: 100%;
  padding: 0;
  overflow: hidden;
  background: var(--page-bg);
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.thumb-frame canvas {
  display: block;
  width: 100%;
  height: auto;
}

.thumb-frame:hover {
  border-color: var(--accent);
}

.thumb-label {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.thumb {
  position: relative;
}

.thumb.is-current .thumb-frame {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.thumb.is-current::after {
  content: "";
  position: absolute;
  top: 1px;
  right: 7px;
  width: 14px;
  height: 14px;
  background: var(--accent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 6.3 4.8 8.5 9.5 3.8'/%3E%3C/svg%3E")
    center / 9px no-repeat;
  border: 2px solid var(--surface);
  border-radius: 50%;
}

.thumb.is-current .thumb-label {
  color: var(--accent);
  font-weight: 650;
}

body.is-inverted .thumb-frame canvas {
  filter: invert(1) hue-rotate(180deg);
}

/* ==================================================== marks: badge, frame, note

   All three sit in the mark layer and are positioned against the page box, so
   they track the page at any zoom for free. */

.mark-badge {
  position: absolute;
  right: calc(100% + 10px);
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-top: -2px;
  padding: 0;
  font: 600 11px/1 ui-sans-serif, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgb(var(--dot));
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  pointer-events: auto;
  opacity: 0.85;
  transition: opacity 0.12s, transform 0.12s;
}

.mark-badge:hover {
  opacity: 1;
  transform: scale(1.12);
}

.mark-badge.is-selected {
  opacity: 1;
  box-shadow: 0 0 0 3px var(--page-bg), 0 0 0 4.5px rgb(var(--dot));
}

/* The open mark gets a frame with grab handles, as in the reference. */
.mark-frame {
  position: absolute;
  margin: -3px 0 0 -3px;
  padding: 3px;
  border: 1.5px solid var(--accent);
  border-radius: 2px;
  pointer-events: none;
}

.mark-frame .handle {
  position: absolute;
  width: 7px;
  height: 7px;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 1.5px;
}

.handle.h-nw { top: -4px; left: -4px; }
.handle.h-n  { top: -4px; left: calc(50% - 3.5px); }
.handle.h-ne { top: -4px; right: -4px; }
.handle.h-e  { top: calc(50% - 3.5px); right: -4px; }
.handle.h-se { bottom: -4px; right: -4px; }
.handle.h-s  { bottom: -4px; left: calc(50% - 3.5px); }
.handle.h-sw { bottom: -4px; left: -4px; }
.handle.h-w  { top: calc(50% - 3.5px); left: -4px; }

/* Notes sit in the gutter beside the page, anchored to their mark. */
.note-card {
  position: absolute;
  left: calc(100% + 20px);
  width: 232px;
  margin-top: -6px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid rgb(var(--dot));
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  pointer-events: auto;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}

.note-card:hover {
  transform: translateX(-2px);
  box-shadow: var(--shadow-lg);
}

.note-card.is-selected {
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--accent);
}

.note-card-head {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}

.note-card-number {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  flex: none;
  margin-top: 1px;
  font: 600 10.5px/1 inherit;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgb(var(--dot));
  border-radius: 50%;
}

.note-card-quote {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card-body {
  margin: 8px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
}

/* Room for the cards, taken from the page's own centring. */
.pages.has-notes {
  padding-right: 272px;
}

/* =================================================================== sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  width: 300px;
  flex: none;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow: hidden;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  font-size: 13.5px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.pill {
  min-width: 20px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 20px;
}

.pill:empty {
  display: none;
}

.sidebar-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sidebar-empty {
  margin: 0;
  padding: 18px 14px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.9;
}

.hl-list {
  margin: 0;
  padding: 10px;
  list-style: none;
  display: grid;
  gap: 8px;
}

/* Each mark is a card, the way a comment thread would be. */
.hl-item {
  position: relative;
  padding: 11px 12px 10px 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.hl-item::before {
  content: "";
  position: absolute;
  inset: 11px auto 11px 0;
  width: 3px;
  background: rgb(var(--dot));
  border-radius: 0 2px 2px 0;
}

.hl-item:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
}

.hl-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.hl-number {
  float: left;
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  margin: 1px 7px 0 0;
  font: 600 10.5px/1 inherit;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: rgb(var(--dot));
  border-radius: 50%;
}

.hl-quote {
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-soft);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hl-item.style-highlight .hl-quote {
  box-shadow: inset 0 -0.7em 0 rgb(var(--dot) / 0.26);
}

.hl-item.style-underline .hl-quote {
  text-decoration: underline;
  text-decoration-color: rgb(var(--dot));
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

.hl-item.style-strike .hl-quote {
  text-decoration: line-through;
  text-decoration-color: rgb(var(--dot));
  text-decoration-thickness: 2px;
}

.hl-note {
  margin-top: 7px;
  padding: 7px 9px;
  color: var(--text-soft);
  background: var(--surface-2);
  border-radius: 6px;
  font-size: 12px;
}

.hl-page {
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

/* ===================================================== the mark popover */

.hl-popup {
  position: fixed;
  z-index: 60;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  animation: pop 0.12s ease-out;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(3px) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hl-popup {
    animation: none;
  }
}

.popup-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.popup-colors {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 5px;
}

.popup-divider {
  width: 1px;
  height: 20px;
  margin: 0 3px;
  background: var(--line);
}

.popup-dot {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

.popup-dot::before {
  content: "";
  width: 13px;
  height: 13px;
  background: rgb(var(--dot));
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.12);
  transition: transform 0.12s;
}

.popup-dot:hover::before {
  transform: scale(1.18);
}

.popup-dot.is-active {
  box-shadow: 0 0 0 1.5px rgb(var(--dot));
}

.popup-styles {
  display: flex;
  gap: 1px;
}

.note-display {
  max-width: 250px;
  margin: 5px 2px 2px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-soft);
  background: var(--surface-2);
  border-radius: 7px;
  cursor: text;
}

.note-editor {
  display: grid;
  gap: 6px;
  padding: 6px 2px 2px;
}

.note-editor textarea {
  width: 250px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
}

.note-editor textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.note-editor .btn {
  justify-content: center;
}

/* ===================================================================== misc */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 15px;
  font-size: 13px;
  color: var(--surface);
  background: var(--text);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  transform: translateX(-50%);
  animation: pop 0.14s ease-out;
}

.help {
  width: min(430px, calc(100vw - 32px));
  padding: 24px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.help::backdrop {
  background: rgb(12 16 22 / 0.45);
}

.help h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 640;
  letter-spacing: -0.01em;
}

.shortcuts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px 16px;
  margin: 0 0 20px;
  font-size: 12.5px;
}

.shortcuts dt {
  display: flex;
  gap: 3px;
  white-space: nowrap;
}

.shortcuts dd {
  margin: 0;
  color: var(--muted);
  align-self: center;
}

.help > .btn {
  width: 100%;
  justify-content: center;
}

/* =============================================================== responsive */

@media (max-width: 1180px) {
  .rail {
    --rail-w: 112px;
  }
}

@media (max-width: 1000px) {
  .doc-title {
    max-width: 220px;
  }

  .rail {
    position: fixed;
    inset: calc(var(--appbar-h) + var(--toolrow-h)) auto 0 0;
    z-index: 30;
    box-shadow: var(--shadow-lg);
  }

  /* A drawer must not also reserve layout width. */
  .reader-body {
    position: relative;
  }
}

@media (max-width: 940px) {
  /* Absolute centring collides with the clusters either side once the bar gets
     tight, so let the middle join the flow and drop the weight dots, which the
     popover carries anyway. */
  .tool-center {
    position: static;
    transform: none;
  }

  .weights {
    display: none;
  }

  .toolrow {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toolrow::-webkit-scrollbar {
    display: none;
  }

  .toolrow-spacer {
    flex: 1 0 auto;
  }
}

@media (max-width: 860px) {
  .doc-pages,
  .saved-badge {
    display: none;
  }

  /* No margins to live in on a phone: the marks panel carries both the notes
     and the numbering there. */
  .note-card,
  .mark-badge {
    display: none;
  }

  .pages.has-notes {
    padding-right: 14px;
  }

  .zoom-group {
    display: none;
  }

  .sidebar {
    position: fixed;
    inset: calc(var(--appbar-h) + var(--toolrow-h)) 0 0 auto;
    z-index: 30;
    width: min(320px, 88vw);
    box-shadow: var(--shadow-lg);
  }

  .label-wide {
    display: none;
  }

  /* Touch devices have no hover, so the delete button must always show. */
  .doc-delete {
    opacity: 1;
    transform: none;
  }

  .library-inner {
    padding: 16px 14px 52px;
  }

  .doc-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px 14px;
  }
}

@media (max-width: 620px) {
  .doc-title {
    max-width: 130px;
  }

  .pager-total,
  #help-btn {
    display: none;
  }

  .toolrow {
    gap: 4px;
    padding: 0 6px;
  }

  .swatches {
    gap: 5px;
  }

  .tool-sep {
    margin: 0 1px;
  }
}
