:root {
  --ink: #1A1A1A;
  --body: #262626;
  --soft: #4A4A4A;
  --grey: #7A7A7A;
  --red: #A4262C;
  --red-dark: #86191F;
  --hair: #D6D6D6;
  --paper: #FFFFFF;
  --desk: #F1F0ED;
  --mark: rgba(164, 38, 44, 0.16);
  --mark-strong: rgba(164, 38, 44, 0.32);
  --serif: "EB Garamond", Garamond, "Adobe Garamond Pro", Georgia, serif;
  --sans: "Gill Sans", "Gill Sans MT", Calibri, "Segoe UI", system-ui, sans-serif;
  --topbar-h: 52px;
  --notes-w: 320px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--desk);
  color: var(--body);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  background: var(--paper);
  border-bottom: 1px solid var(--hair);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-rule { width: 28px; height: 2px; background: var(--red); flex: none; }
.brand-label {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.link-btn {
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--soft);
  background: none;
  border: 0;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.link-btn:hover { color: var(--red); }
.link-btn .short { display: none; }
.link-btn:focus-visible, .text-btn:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
#btn-notify { color: var(--red); }

.count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 2px;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  color: var(--paper);
  background: var(--grey);
  border-radius: 9px;
}
.count.has { background: var(--red); }

/* ---------- first-visit hint ---------- */

.hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 20px;
  background: var(--ink);
  color: #F3F3F3;
  font-family: var(--sans);
  font-size: 14px;
}
.hint p { margin: 0; }
.hint[hidden] { display: none; }

.hint-close {
  background: none;
  border: 0;
  color: inherit;
  font-size: 22px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  opacity: 0.75;
}
.hint-close:hover { opacity: 1; }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--notes-w);
  align-items: start;
}

.reader { padding: 28px 24px 80px; min-width: 0; }

.status {
  max-width: 560px;
  margin: 40px auto;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--grey);
  text-align: center;
}
.status[hidden] { display: none; }
.status.error { color: var(--red); }

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* ---------- a PDF page ---------- */

.page {
  position: relative;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 4px 18px rgba(0, 0, 0, 0.06);
  flex: none;
}
.page canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.page .hl-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.page .hl {
  position: absolute;
  background: var(--mark);
  border-bottom: 1.5px solid var(--red);
  border-radius: 1px;
}
.page .hl.pending { background: var(--mark-strong); border-bottom-style: dashed; }
.page .hl.flash { animation: flash 1.4s ease-out; }
@keyframes flash {
  0%, 30% { background: rgba(164, 38, 44, 0.45); }
  100% { background: var(--mark); }
}

/* pdf.js 4.10 text layer, trimmed from web/pdf_viewer.css */
.textLayer {
  position: absolute;
  text-align: initial;
  inset: 0;
  overflow: clip;
  opacity: 1;
  line-height: 1;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  z-index: 0;
}
.textLayer :is(span, br) {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.textLayer > :not(.markedContent),
.textLayer .markedContent span:not(.markedContent) { z-index: 1; }
.textLayer span.markedContent { top: 0; height: 0; }
.textLayer ::selection { background: rgba(164, 38, 44, 0.28); }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent {
  display: block;
  position: absolute;
  inset: 100% 0 0;
  z-index: 0;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
}
.textLayer.selecting .endOfContent { top: 0; }

/* ---------- notes panel ---------- */

.notes {
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
  padding: 24px 22px 40px;
  background: var(--paper);
  border-left: 1px solid var(--hair);
}
.notes-head { display: flex; align-items: center; justify-content: space-between; }
.notes h2 {
  margin: 0;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
}
.notes-close { display: none; color: var(--soft); }
.notes-intro { margin: 12px 0 10px; font-size: 16px; color: var(--soft); }

.text-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--red);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 13px;
}

.note-list { list-style: none; margin: 20px 0 0; padding: 0; }
.note {
  padding: 14px 0;
  border-top: 1px solid var(--hair);
}
.note-quote {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: 0 0 0 10px;
  border-left: 2px solid var(--red);
  font-style: italic;
  font-size: 15px;
  color: var(--soft);
  cursor: pointer;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-quote:hover { color: var(--ink); }
.note-text { margin: 8px 0 0; font-size: 16px; color: var(--body); white-space: pre-wrap; overflow-wrap: anywhere; }
.note-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 8px;
  font-family: var(--sans);
  font-size: 12px;
  color: var(--grey);
}
.note-meta .sent { color: var(--soft); }
.note-meta .failed { color: var(--red); }
.notes-empty { margin-top: 20px; font-size: 15px; color: var(--grey); font-style: italic; }
.notes-empty[hidden] { display: none; }

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

.primary, .ghost {
  font-family: var(--sans);
  font-size: 14px;
  letter-spacing: 0.03em;
  border-radius: 4px;
  padding: 10px 16px;
  cursor: pointer;
}
.primary { background: var(--red); color: #fff; border: 1px solid var(--red); }
.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.primary:disabled { opacity: 0.6; cursor: progress; }
.ghost { background: none; color: var(--soft); border: 1px solid var(--hair); }
.ghost:hover { color: var(--ink); border-color: var(--grey); }
.wide { width: 100%; }

.float-btn {
  position: fixed;
  z-index: 30;
  font-family: var(--sans);
  font-size: 13px;
  letter-spacing: 0.03em;
  color: #fff;
  background: var(--ink);
  border: 0;
  border-radius: 4px;
  padding: 9px 13px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}
.float-btn:hover { background: var(--red); }
.float-btn[hidden] { display: none; }

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

.modal {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  border: 0;
  border-top: 3px solid var(--red);
  border-radius: 4px;
  padding: 28px 28px 24px;
  background: var(--paper);
  color: var(--body);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.modal::backdrop { background: rgba(26, 26, 26, 0.45); }
.modal h2 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 28px;
  line-height: 1.15;
  color: var(--ink);
}
.eyebrow {
  margin: 0 0 8px;
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--red);
}
.lede { margin: 0 0 18px; font-size: 18px; color: var(--body); }
.fine { margin: 10px 0 0; font-family: var(--sans); font-size: 12px; color: var(--grey); }

.quote {
  margin: 0 0 16px;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--red);
  font-style: italic;
  color: var(--soft);
  max-height: 7.5em;
  overflow: auto;
}
.quote[hidden] { display: none; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  margin-bottom: 5px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--soft);
}
.field em { font-style: normal; color: var(--grey); }
.field input, .field textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 17px;
  background: var(--paper);
  border: 1px solid var(--hair);
  border-radius: 4px;
  resize: vertical;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(164, 38, 44, 0.12); }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.form-error { margin: 0 0 10px; font-family: var(--sans); font-size: 13px; color: var(--red); }
.form-error[hidden] { display: none; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.thanks[hidden] { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 40;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  font-family: var(--sans);
  font-size: 14px;
  color: #fff;
  background: var(--ink);
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.toast[hidden] { display: none; }

/* ---------- narrow screens: notes become a bottom sheet ---------- */

@media (max-width: 1023px) {
  .layout { display: block; }
  .reader { padding: 16px 8px 80px; }
  .pages { gap: 12px; }
  .notes {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    z-index: 25;
    height: auto;
    max-height: 72dvh;
    border-left: 0;
    border-top: 1px solid var(--hair);
    border-radius: 10px 10px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.18);
    transform: translateY(105%);
    transition: transform 0.22s ease;
    visibility: hidden;
  }
  .notes.open { transform: none; visibility: visible; }
  .notes-close { display: block; }
}

@media (min-width: 1024px) {
  .notes-toggle { display: none; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 8px 0 14px; }
  .brand-rule { display: none; }
  .brand-label { font-size: 11px; letter-spacing: 0.12em; }
  .link-btn { padding: 8px 6px; font-size: 13px; letter-spacing: 0.02em; }
  .link-btn .long { display: none; }
  .link-btn .short { display: inline; }
  .hint { font-size: 13px; padding: 8px 12px; }
  .modal { padding: 24px 20px 20px; }
  .modal h2 { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .notes { transition: none; }
  .page .hl.flash { animation: none; }
}
