/* ================================================================
   THE RETURNED MANUSCRIPT
   A manila envelope, a leather clipboard, red pilot fine-liner markup,
   and yellow sticky notes. Click a red mark to review.
   ================================================================ */

/* ------------------------------------------------------------
   1. Variables
   ------------------------------------------------------------ */
:root {
  --desk:           #2a2219;
  --desk-dark:      #1c160f;
  --paper:          #f4ecd8;
  --paper-hi:       #f8f1de;
  --paper-lo:       #ecdfc3;
  --paper-edge:     #e3d4ae;
  --rule-baseline:  #d4c4a0;
  --rule-red:       #b5281e;   /* was #c41e1e — more editorial, less alarming */
  --rule-red-hi:    #d4321e;
  --ink-body:       #1f1a12;
  --ink-faded:      #3b3223;
  --ink-gray:       #6a5c42;   /* darkened from #8a7a5c for 4.5:1 contrast */
  --leather:        #4a3a28;
  --leather-dark:   #3a2d1e;
  --leather-hi:     #5a4a32;
  --kraft:          #c9a970;
  --kraft-dark:     #9b8048;
  --sticky-yellow:  #fef08a;   /* real 3M Post-it, less fluorescent */
  --sticky-shadow:  #f5e36b;
  --sticky-top:     #f1e05a;
  --sticky-ink:     #2c2416;
  --tape:           #f4e9c6;
  --approve:        #1e6038;   /* deeper legal-pad green */
  --reject:         #993340;   /* cranberry — distinct from rule-red */
  --blue-ink:       #2c5282;   /* Prussian blue, reserved for queries */

  --font-body:      'Crimson Pro', 'Crimson Text', Georgia, 'Times New Roman', serif;
  --font-display:   'Cormorant Garamond', 'Crimson Pro', Georgia, serif;
  --font-hand:      'Shadows Into Light Two', 'Caveat', cursive;
  --font-hand-alt:  'Caveat', 'Shadows Into Light Two', cursive;
  --font-signature: 'Homemade Apple', 'Caveat', cursive;
  --font-typewriter:'Special Elite', 'Courier Prime', 'Courier New', monospace;
}

/* ------------------------------------------------------------
   2. Reset
   ------------------------------------------------------------ */
*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

html { scroll-behavior: smooth; }

body {
  background: var(--desk);
  color: var(--ink-body);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
}
/* Desk texture as a fixed pseudo — avoids background-attachment: fixed
   which forces full-page repaints during scroll (jank on iOS/Android). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 20% 10%, rgba(80, 60, 30, 0.35) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 90%, rgba(0, 0, 0, 0.45) 0%, transparent 60%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' seed='7'/><feColorMatrix values='0 0 0 0 0.12  0 0 0 0 0.08  0 0 0 0 0.04  0 0 0 0.25 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>") var(--desk);
}

button {
  font-family: inherit;
  border: none;
  background: none;
  cursor: pointer;
  color: inherit;
}

a { color: inherit; text-decoration: none; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

.hidden { display: none !important; }

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Skip link: hidden until focused */
.skip-link {
  position: fixed;
  top: -40px;
  left: 4px;
  z-index: 999;
  padding: 10px 16px;
  background: var(--rule-red);
  color: #fff;
  border-radius: 6px;
  font-family: var(--font-typewriter);
  font-size: 13px;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 8px;
}

/* Visible focus for keyboard users */
.correction:focus-visible {
  outline: 2px dashed var(--rule-red);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ------------------------------------------------------------
   3. Top auth bar — dark desk edge
   ------------------------------------------------------------ */
.auth-bar {
  position: fixed;
  top: 0;
  left: 296px;
  right: 0;
  height: 52px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: linear-gradient(180deg, #1a140c 0%, #140f08 100%);
  border-bottom: 1px solid #000;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 1px 0 rgba(255,255,255,0.05) inset;
  color: #d4c4a0;
  font-family: var(--font-typewriter);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.auth-bar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #e6d7b3;
  text-transform: uppercase;
}

.auth-bar__quill { font-size: 16px; color: var(--rule-red); }

.auth-bar__stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 10px;
}

.stats-item { display: inline-flex; align-items: baseline; gap: 5px; }

.stats-num {
  font-size: 14px;
  font-weight: bold;
  color: #e6d7b3;
}

.stats-item--approved .stats-num { color: #7fc79a; }
.stats-item--rejected .stats-num { color: #e08a8a; }
.stats-item--pending  .stats-num { color: #e3c57a; }

.stats-label { text-transform: uppercase; opacity: 0.6; }
.stats-sep   { opacity: 0.3; }

.auth-bar__user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.auth-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
}

.auth-username {
  font-family: var(--font-hand-alt);
  font-size: 16px;
  color: #e6d7b3;
  letter-spacing: 0;
}

.auth-btn {
  font-family: var(--font-typewriter);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 12px;
  border: 1px solid #5a4a32;
  color: #e6d7b3;
  background: rgba(255,255,255,0.03);
  transition: all 0.15s ease;
}
.auth-btn:hover { background: rgba(255,255,255,0.08); border-color: #8a7a5c; }

.auth-btn--submit {
  background: linear-gradient(180deg, #4a2020 0%, #3a1616 100%);
  border-color: var(--rule-red);
  color: #ffe5e5;
}
.auth-btn--submit:hover {
  background: linear-gradient(180deg, #6a2828 0%, #4a1c1c 100%);
  box-shadow: 0 0 10px rgba(196,30,30,0.3);
}

/* ------------------------------------------------------------
   4. Mobile menu toggle
   ------------------------------------------------------------ */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  width: 42px;
  height: 42px;
  background: var(--leather-dark);
  color: #e6d7b3;
  border: 1px solid #000;
  font-size: 20px;
  border-radius: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ------------------------------------------------------------
   5. Sidebar — brown leather clipboard
   ------------------------------------------------------------ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 296px;
  padding: 74px 18px 20px;
  overflow-y: auto;
  z-index: 50;
  background: linear-gradient(180deg, #4a3a28 0%, #3a2d1e 100%);
  box-shadow:
    inset -1px 0 0 rgba(255,255,255,0.04),
    6px 0 14px -4px rgba(0,0,0,0.55),
    1px 0 0 rgba(0,0,0,0.5);
  color: #e6d7b3;
}
.sidebar::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='500' height='500'><filter id='l'><feTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='3' seed='3'/><feColorMatrix values='0 0 0 0 0.15  0 0 0 0 0.10  0 0 0 0 0.05  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23l)'/></svg>");
  mix-blend-mode: overlay;
  opacity: 0.45;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* Silver chrome clip at top */
.clipboard-clip {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 54px;
  z-index: 4;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,0.5));
}

/* Taped title card */
.clipboard-title-card {
  position: relative;
  width: 230px;
  min-height: 70px;
  margin: 16px auto 22px;
  background: #f4ecd8;
  background-image: linear-gradient(180deg, #f8f1de 0%, #ecdfc3 100%);
  border: 1px solid #c9b889;
  color: #2a2219;
  font-family: var(--font-typewriter);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 14px 8px 10px;
  transform: rotate(-0.6deg);
  box-shadow: 0 3px 6px rgba(0,0,0,0.3), 0 1px 0 rgba(255,255,255,0.4) inset;
  z-index: 3;
}

.tape {
  position: absolute;
  width: 58px;
  height: 18px;
  background: rgba(244, 233, 198, 0.72);
  border: 1px solid rgba(180, 160, 100, 0.35);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.tape-left  { top: -9px; left: -14px;  transform: rotate(-12deg); }
.tape-right { top: -9px; right: -14px; transform: rotate(14deg); }

.clipboard-title-text { font-weight: bold; }
.clipboard-author,
.clipboard-draft {
  display: inline-block;
  font-weight: normal;
  font-size: 10px;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

.clipboard-stats {
  position: relative;
  z-index: 2;
  text-align: center;
  margin-bottom: 18px;
  padding: 10px 0;
  border-top: 1px solid rgba(230, 215, 179, 0.18);
  border-bottom: 1px solid rgba(230, 215, 179, 0.18);
}
.clipboard-stat-num {
  display: block;
  font-family: var(--font-hand-alt);
  font-size: 32px;
  color: var(--rule-red);
  line-height: 1;
  text-shadow: 0 0 0.4px var(--rule-red);
}
.clipboard-stat-label {
  display: block;
  font-family: var(--font-typewriter);
  font-size: 9px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.65;
  margin-top: 4px;
}

/* TOC */
.toc {
  position: relative;
  z-index: 2;
}
.toc-label {
  font-family: var(--font-typewriter);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.5;
  margin: 0 0 8px 4px;
}

.toc-item {
  position: relative;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 7px 10px 7px 14px;
  margin-bottom: 2px;
  border-left: 2px solid transparent;
  color: #d4c4a0;
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.3;
  transition: transform 0.18s ease, background 0.18s ease, color 0.18s ease;
}
.toc-item::before {
  content: "\2713";
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-hand-alt);
  font-size: 18px;
  color: var(--rule-red);
  opacity: 0;
  transition: opacity 0.18s ease;
  pointer-events: none;
}
.toc-item:hover {
  transform: translateX(3px);
  color: #f4ecd8;
  background: rgba(244, 236, 216, 0.05);
}
.toc-item:hover::before { opacity: 0.7; }

.correction-count {
  display: inline-block;
  min-width: 22px;
  padding: 0 6px;
  text-align: center;
  font-family: var(--font-hand-alt);
  font-size: 14px;
  color: #fae6c8;                              /* high contrast on leather */
  background: rgba(181, 40, 30, 0.8);          /* semi-opaque red pill */
  border: 1.5px solid #d4321e;
  border-radius: 50%;
  line-height: 18px;
  margin-left: 8px;
  font-weight: 600;
}
.correction-count--done {
  background: var(--approve);
  border-color: var(--approve);
  color: #f4ecd8;
}
/* Zero-correction chapters recede — makes the TOC a priority queue */
.toc-item:not(.has-corrections) {
  opacity: 0.5;
}

.clipboard-footer {
  position: relative;
  z-index: 2;
  margin-top: 28px;
  padding-top: 20px;
  text-align: center;
}
.reviewed-stamp {
  display: inline-block;
  padding: 8px 18px;
  border: 2px solid rgba(196, 30, 30, 0.55);
  color: rgba(196, 30, 30, 0.75);
  transform: rotate(-3deg);
  font-family: var(--font-typewriter);
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.7;
}
.reviewed-stamp-line2 {
  font-family: var(--font-hand-alt);
  font-size: 14px;
  letter-spacing: 0;
  margin-top: 3px;
  opacity: 0.6;
}

/* ------------------------------------------------------------
   6. Main scroll area
   ------------------------------------------------------------ */
.main {
  margin-left: 296px;
  padding: 86px 0 80px;
  min-height: 100vh;
}

/* ------------------------------------------------------------
   7. Sheet — manuscript page
   ------------------------------------------------------------ */
.sheet,
.chapter {
  position: relative;
  width: 820px;
  max-width: calc(100vw - 340px);
  margin: 0 auto 48px;
  min-height: 1060px;
  padding: 90px 70px 80px;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 28px 15%, #0a0704 0 6.5px, transparent 7.5px),
    radial-gradient(circle at 28px 50%, #0a0704 0 6.5px, transparent 7.5px),
    radial-gradient(circle at 28px 85%, #0a0704 0 6.5px, transparent 7.5px),
    radial-gradient(ellipse at 30% 20%, #f8f1de 0%, #f1e8d0 55%, #ecdfc3 100%);
  background-repeat: no-repeat;
  background-size: auto, auto, auto, 100% 100%;
  box-shadow:
    0 2px 1px rgba(0,0,0,0.04),
    0 18px 28px -12px rgba(20,14,4,0.45),
    0 1px 0 rgba(255,255,255,0.6) inset,
    /* faint inner shadow around the hole-punches */
    28px calc(15% + 6px) 2px 0 rgba(0,0,0,0.0);
  color: var(--ink-body);
}

/* Paper texture overlay + baseline rules (via ::before and ::after) */
.sheet::before,
.chapter::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='2' seed='11'/><feColorMatrix values='0 0 0 0 0.3  0 0 0 0 0.2  0 0 0 0 0.1  0 0 0 0.5 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
  opacity: 0.06;
  z-index: 1;
}

.sheet::after,
.chapter::after {
  content: "";
  position: absolute;
  left: 56px;
  right: 30px;
  top: 90px;
  bottom: 80px;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 28.8px,
    var(--rule-baseline) 28.8px,
    var(--rule-baseline) 29px
  );
  opacity: 0.35;
  z-index: 1;
}

/* Red margin rule — drawn via a child so it doesn't conflict with ::before/::after */
.sheet-margin-rule {
  position: absolute;
  left: 68px;
  top: 0;
  bottom: 0;
  width: 1.5px;
  background: var(--rule-red);
  opacity: 0.55;
  pointer-events: none;
  z-index: 2;
}

.chapter::before { z-index: 1; }
.chapter > .chapter-title-block { z-index: 4; }

/* The red vertical margin rule for chapters — use an extra rule via .chapter */
.chapter > .manuscript-text {
  position: relative;
  z-index: 4;
}

/* Actual chapter margin rule — apply via a dedicated overlay */
.chapter::before {
  background-image:
    linear-gradient(to right, transparent 67.25px, rgba(196,30,30,0.55) 67.25px, rgba(196,30,30,0.55) 68.75px, transparent 68.75px),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='2' seed='11'/><feColorMatrix values='0 0 0 0 0.3  0 0 0 0 0.2  0 0 0 0 0.1  0 0 0 0.5 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: normal, multiply;
  background-repeat: repeat-y, repeat;
  background-size: auto, 300px 300px;
  opacity: 1;
}
.sheet::before {
  background-image:
    linear-gradient(to right, transparent 67.25px, rgba(196,30,30,0.55) 67.25px, rgba(196,30,30,0.55) 68.75px, transparent 68.75px),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='2' seed='11'/><feColorMatrix values='0 0 0 0 0.3  0 0 0 0 0.2  0 0 0 0 0.1  0 0 0 0.5 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: normal, multiply;
  background-repeat: repeat-y, repeat;
  background-size: auto, 300px 300px;
  opacity: 1;
}

/* Sheets are stacked square — no rotation (caused horizontal jitter on scroll). */

/* Three hole punches — already drawn via background on .sheet/.chapter */

/* Running header */
.sheet-header {
  position: absolute;
  top: 34px;
  left: 100px;
  right: 60px;
  display: flex;
  justify-content: space-between;
  font-family: var(--font-typewriter);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-gray);
  opacity: 0.85;
  z-index: 5;
}

/* Running footer */
.sheet-footer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 42px;
  text-align: center;
  font-family: var(--font-typewriter);
  font-size: 9px;
  color: var(--ink-gray);
  letter-spacing: 0.15em;
  z-index: 5;
}

.sheet-body {
  position: relative;
  z-index: 4;
  max-width: 33em;
  margin: 0 auto;
}

/* ------------------------------------------------------------
   8. Chapter title block — first page of each chapter only
   ------------------------------------------------------------ */
.chapter-title-block {
  position: relative;
  z-index: 4;
  max-width: 33em;
  margin: 60px auto 44px;
  text-align: center;
  padding-bottom: 10px;
}
.chapter-title-block .chapter-number {
  font-family: var(--font-typewriter);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-gray);
  margin-bottom: 18px;
}
.chapter-title-block .chapter-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  font-variant: small-caps;
  letter-spacing: 0.14em;
  color: var(--ink-body);
  line-height: 1.2;
}
.chapter-title-block .chapter-rule {
  width: 140px;
  height: 14px;
  margin: 18px auto 4px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 14'><path d='M 2 7 Q 20 1, 40 7 T 80 7 T 120 7 L 138 7' fill='none' stroke='%23c41e1e' stroke-width='1.3' stroke-linecap='round'/><circle cx='70' cy='7' r='2' fill='%23c41e1e'/></svg>") center center no-repeat;
}
.chapter-correction-summary {
  margin-top: 6px;
  font-family: var(--font-hand-alt);
  font-size: 17px;
  color: var(--rule-red);
  opacity: 0.78;
  text-shadow: 0 0 0.4px var(--rule-red);
}

/* Manuscript body */
.manuscript-text {
  position: relative;
  z-index: 4;
  max-width: 33em;
  margin: 0 auto;
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.62;
  color: var(--ink-body);
}
.manuscript-text p {
  margin: 0;
  text-indent: 1.4em;
  text-align: justify;
  hyphens: auto;
}
/* First paragraph of chapter (any page that opens with chapter-opener) */
.manuscript-text p.chapter-opener { text-indent: 0; }
.manuscript-text p.chapter-opener::first-letter {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 72px;
  float: left;
  line-height: 0.85;
  padding: 6px 8px 0 0;
  color: var(--ink-body);
}
/* Backward-compat: also style the first paragraph if no chapter-opener class */
.manuscript-text p:first-of-type:not(.chapter-opener) {
  text-indent: 1.4em;
}

/* ------------------------------------------------------------
   9. Correction markup — red pilot fine-liner substitutions
   ------------------------------------------------------------ */
.correction {
  position: relative;
  display: inline;
  cursor: pointer;
}
/* provide headroom above the baseline for the handwritten insert */
.correction .original {
  position: relative;
  display: inline-block;
  vertical-align: baseline;
  text-decoration: line-through;
  text-decoration-color: var(--rule-red);
  text-decoration-thickness: 1.5px;
  text-decoration-skip-ink: none;
  color: var(--ink-body);
  background: transparent;
}

.correction .corrected {
  position: absolute;
  left: 50%;
  top: -0.9em;
  transform: translate(-50%, 0) rotate(-1.2deg);
  font-family: var(--font-hand);
  font-size: 15px;
  line-height: 1;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
  white-space: nowrap;
  pointer-events: none;
  padding: 0 2px;
  z-index: 2;
}
.correction .corrected::before {
  content: "\2038";
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, -5px) scaleX(1.2);
  color: var(--rule-red);
  font-size: 13px;
  line-height: 0;
}
.correction .margin-note { display: none; }

.correction:hover .original {
  text-decoration-color: #e62020;
  background: rgba(255, 235, 130, 0.28);
}
.correction:hover .corrected {
  transform: translate(-50%, -2px) rotate(-1.2deg);
}

/* Post-decision states */
.correction--approved .original {
  text-decoration-color: rgba(196, 30, 30, 0.35);
  color: rgba(31, 26, 18, 0.45);
}
.correction--approved .corrected {
  color: var(--approve);
  text-shadow: 0 0 0.4px var(--approve);
}
.correction--approved .corrected::before { color: var(--approve); }

.correction--rejected .original { text-decoration: none; color: var(--ink-body); }
.correction--rejected .corrected {
  text-decoration: line-through;
  text-decoration-color: #c41e1e;
  text-decoration-thickness: 1px;
  opacity: 0.5;
}

/* The handwritten insertion above the original overlaps the previous
   line's descender space. Bumping line-height a touch on paragraphs
   containing corrections keeps things readable. */
.manuscript-text p { line-height: 1.75; }
.letter-para { line-height: 1.62; }

/* ------------------------------------------------------------
   10. Hero sheet — envelope label + cover letter
   ------------------------------------------------------------ */
.sheet--hero { padding-top: 76px; }

.envelope-label {
  position: relative;
  width: 520px;
  max-width: 100%;
  min-height: 180px;
  margin: 0 auto 48px;
  padding: 26px 34px;
  background: var(--kraft);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='400' height='400'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='2.0' numOctaves='3' seed='5'/><feColorMatrix values='0 0 0 0 0.45  0 0 0 0 0.30  0 0 0 0 0.12  0 0 0 0.35 0'/></filter><rect width='100%25' height='100%25' filter='url(%23f)'/></svg>");
  background-blend-mode: multiply;
  border: 1px solid var(--kraft-dark);
  box-shadow:
    0 2px 4px rgba(0,0,0,0.15),
    0 10px 18px -6px rgba(30,20,10,0.4),
    0 1px 0 rgba(255,255,255,0.25) inset;
  color: #2a1f0c;
  font-family: var(--font-typewriter);
  font-size: 13px;
  line-height: 1.65;
  transform: rotate(-0.4deg);
}

.envelope-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}
.envelope-row:last-child { margin-bottom: 0; }
.envelope-key {
  flex: 0 0 56px;
  letter-spacing: 0.1em;
}
.envelope-val { flex: 1; }

.airmail-stamp {
  position: absolute;
  top: 14px;
  right: 18px;
  width: 44px;
  height: 52px;
  padding: 3px;
  background: #f4ecd8;
  border: 1px dashed rgba(0,0,0,0.4);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transform: rotate(3deg);
}
.airmail-stamp-inner {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #7a1818 0%, #a82828 55%, #7a1818 100%);
  color: #fff089;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-typewriter);
  font-size: 7px;
  letter-spacing: 0.08em;
  text-align: center;
  line-height: 1;
}
.airmail-stamp-top { margin-top: 2px; }
.airmail-stamp-cents { font-size: 11px; margin-top: 4px; }

.reviewed-rubber-stamp {
  position: absolute;
  right: 18px;
  bottom: 14px;
  padding: 6px 14px;
  border: 2.5px solid var(--rule-red);
  color: var(--rule-red);
  font-family: var(--font-typewriter);
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 0.22em;
  opacity: 0.78;
  transform: rotate(-6deg);
  text-shadow: 0 0 0.4px var(--rule-red);
  box-shadow: 0 0 0 1px var(--rule-red) inset;
}

/* Cover letter */
.cover-letter {
  position: relative;
  max-width: 34em;
  margin: 0 auto;
  padding: 20px 6px 20px;
}
.paperclip {
  position: absolute;
  top: -38px;
  left: 4px;
  filter: drop-shadow(3px 5px 3px rgba(0,0,0,0.28));
  transform: rotate(-8deg);
  z-index: 5;
}

.letterhead {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  font-variant: small-caps;
  letter-spacing: 0.18em;
  text-align: center;
  color: var(--ink-body);
}
.letterhead-rule {
  width: 60%;
  max-width: 280px;
  height: 1px;
  margin: 6px auto 2px;
  background: var(--rule-red);
  opacity: 0.7;
}
.letter-date {
  text-align: right;
  font-family: var(--font-hand);
  font-size: 18px;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
  margin: 14px 0 26px;
  transform: rotate(-0.4deg);
}
.letter-greeting {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
  margin-bottom: 14px;
  transform: rotate(-0.3deg);
}

.letter-para {
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.62;
  text-indent: 1.4em;
  margin-bottom: 6px;
  text-align: justify;
}
.letter-para:first-of-type { text-indent: 0; }
.letter-para strong { color: var(--rule-red); font-weight: 600; }

.letter-closing { margin-top: 28px; }
.closing-line {
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
}
.signature {
  display: inline-block;
  font-family: var(--font-signature);
  font-size: 34px;
  color: var(--rule-red);
  margin: 6px 0 2px 10px;
  line-height: 1;
  text-shadow: 0 0 0.5px var(--rule-red);
  transform: rotate(-1.5deg);
}
.closing-role {
  font-family: var(--font-typewriter);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--ink-faded);
  opacity: 0.7;
  margin-top: 8px;
}

/* PS block with folded-in legend */
.ps-block {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px dashed rgba(196, 30, 30, 0.42);
}
.ps-header {
  font-family: var(--font-hand);
  font-size: 19px;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
  margin-bottom: 14px;
}
.ps-legend {
  display: grid;
  grid-template-columns: minmax(150px, auto) 1fr;
  gap: 12px 24px;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
}
.ps-legend li { display: contents; }
.legend-demo {
  position: relative;
  padding: 1em 6px 2px;
  color: var(--ink-body);
  white-space: nowrap;
}
.legend-desc {
  color: var(--ink-faded);
  font-style: italic;
  padding: 1em 0 2px;
}

.legend-correction { position: relative; display: inline-block; }
.legend-correction .original {
  text-decoration: line-through;
  text-decoration-color: var(--rule-red);
  text-decoration-thickness: 1.5px;
  text-decoration-skip-ink: none;
}
.legend-correction .corrected {
  position: absolute;
  left: 50%;
  top: -0.9em;
  transform: translate(-50%, 0) rotate(-1.2deg);
  font-family: var(--font-hand);
  font-size: 15px;
  line-height: 1;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
  white-space: nowrap;
}
.legend-strike {
  text-decoration: line-through;
  text-decoration-color: var(--rule-red);
  text-decoration-thickness: 1.5px;
  text-decoration-skip-ink: none;
}
.legend-caret {
  position: relative;
  color: var(--rule-red);
  font-family: var(--font-hand);
  font-size: 14px;
  padding: 0 3px;
}
.legend-insert {
  position: absolute;
  left: 50%;
  top: -0.9em;
  transform: translate(-50%, 0) rotate(-1.2deg);
  font-family: var(--font-hand);
  font-size: 15px;
  line-height: 1;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
  white-space: nowrap;
}
.legend-note-num {
  display: inline-block;
  font-family: var(--font-hand-alt);
  font-size: 15px;
  color: var(--rule-red);
  margin-left: 2px;
  text-shadow: 0 0 0.4px var(--rule-red);
}
.legend-query {
  display: inline-block;
  margin-left: 6px;
  width: 20px;
  height: 20px;
  line-height: 17px;
  text-align: center;
  color: var(--rule-red);
  border: 1.5px solid var(--rule-red);
  border-radius: 50%;
  font-family: var(--font-hand);
  font-size: 14px;
  font-weight: bold;
  text-shadow: 0 0 0.4px var(--rule-red);
  transform: rotate(-4deg);
}

/* ------------------------------------------------------------
   11. Footer
   ------------------------------------------------------------ */
.footer {
  text-align: center;
  padding: 30px 20px 10px;
  font-family: var(--font-typewriter);
  font-size: 10px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: #c4b48c;
  opacity: 0.55;
}

/* ------------------------------------------------------------
   12. Sticky note popover
   ------------------------------------------------------------ */
.sticky-popover {
  position: absolute;
  width: 320px;
  min-height: 200px;
  padding: 30px 22px 22px;
  background: var(--sticky-yellow);
  background-image: linear-gradient(180deg, var(--sticky-top) 0 14px, var(--sticky-yellow) 14px 100%);
  color: var(--sticky-ink);
  font-family: var(--font-body);
  transform: rotate(-1.4deg);
  transform-origin: top left;
  box-shadow:
    0 1px 1px rgba(0,0,0,0.1),
    0 10px 20px -4px rgba(60,40,10,0.35),
    0 20px 40px -12px rgba(0,0,0,0.2);
  clip-path: polygon(0 0, 100% 0, 100% 92%, 94% 100%, 0 100%);
  z-index: 150;
  transition: opacity 0.24s ease, transform 0.24s ease;
}
.sticky-popover[hidden] { display: none !important; }
.sticky-popover.dismissing {
  opacity: 0;
  transform: rotate(-8deg) translate(30px, -10px);
}
.sticky-popover::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, transparent 50%, rgba(60,40,10,0.22) 50%);
  z-index: 0;
  pointer-events: none;
}

.sticky-adhesive { display: none; }

.sticky-close {
  position: absolute;
  top: 20px;
  right: 10px;
  width: 24px;
  height: 24px;
  font-family: var(--font-hand-alt);
  font-size: 24px;
  color: #5a4a20;
  line-height: 0;
  z-index: 3;
  transition: transform 0.15s ease, color 0.15s ease;
}
.sticky-close:hover { transform: rotate(90deg) scale(1.1); color: var(--rule-red); }

.sticky-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--font-typewriter);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: #5a4a20;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-right: 28px;
}
.sticky-header-id { opacity: 0.65; font-size: 9px; }

.sticky-correction { margin-bottom: 12px; }
.sticky-original-row {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  color: var(--sticky-ink);
}
.sticky-original {
  text-decoration: line-through;
  text-decoration-color: var(--rule-red);
  text-decoration-thickness: 1.5px;
  text-decoration-skip-ink: none;
}
.sticky-corrected-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 6px;
  font-family: var(--font-body);
  font-size: 17px;
  color: var(--sticky-ink);
}
.sticky-arrow {
  color: var(--rule-red);
  font-size: 18px;
  font-weight: bold;
}
.sticky-corrected {
  font-family: var(--font-hand);
  font-size: 22px;
  color: var(--rule-red);
  text-shadow: 0 0 0.4px var(--rule-red);
}

.sticky-divider {
  height: 0;
  border-top: 1.5px dashed #c9b248;
  margin: 14px 0 12px;
}
.sticky-divider[hidden] { display: none !important; }

.sticky-comment {
  font-family: var(--font-hand);
  font-size: 18px;
  line-height: 1.45;
  color: var(--sticky-ink);
  padding: 2px 0 6px;
}
.sticky-comment[hidden] { display: none !important; }

.sticky-reviewers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 4px;
}
.sticky-reviewers[hidden] { display: none !important; }
.no-reviews {
  font-family: var(--font-typewriter);
  font-size: 9px;
  color: #8a7a3c;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.reviewer-pill {
  display: inline-block;
  padding: 2px 8px 1px;
  font-family: var(--font-typewriter);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid rgba(0,0,0,0.18);
  background: rgba(255,255,255,0.25);
  color: #5a4a20;
}
.reviewer-pill--approved { border-color: var(--approve); color: var(--approve); }
.reviewer-pill--rejected { border-color: var(--reject); color: var(--reject); }

.sticky-actions {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  padding-top: 4px;
  flex-wrap: wrap;
  align-items: baseline;
}

.sticky-btn {
  font-family: var(--font-hand-alt);
  font-size: 22px;
  line-height: 1;
  padding: 2px 4px;
  background: none;
  border: none;
  color: #5a4e3a;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.sticky-btn:hover { transform: translateY(-1px) rotate(-1deg); }
.sticky-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.sticky-btn--approve { color: var(--approve); }
.sticky-btn--reject  { color: var(--reject); }
.sticky-btn--comment { color: #5a4e3a; }
.sticky-btn--send    { color: var(--approve); font-size: 20px; }

.sticky-btn.active {
  text-decoration: underline wavy;
  text-underline-offset: 4px;
  text-decoration-thickness: 1.2px;
}

.sticky-thread {
  margin-top: 10px;
  max-height: 140px;
  overflow-y: auto;
  padding-right: 4px;
}
.thread-bubble {
  margin-bottom: 6px;
  padding: 6px 0;
  border-top: 1px dotted rgba(90, 74, 32, 0.4);
}
.thread-bubble:first-child { border-top: none; }
.thread-author {
  font-family: var(--font-typewriter);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #5a4a20;
  display: flex;
  justify-content: space-between;
}
.thread-time { opacity: 0.6; font-size: 8px; }
.thread-text {
  font-family: var(--font-hand);
  font-size: 17px;
  color: var(--sticky-ink);
  line-height: 1.35;
  margin-top: 2px;
}

.sticky-input-row {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  align-items: flex-end;
}
.sticky-input-row textarea {
  flex: 1;
  background: rgba(255,255,255,0.35);
  border: 1px dashed rgba(90, 74, 32, 0.45);
  color: var(--sticky-ink);
  font-family: var(--font-hand);
  font-size: 17px;
  padding: 6px 8px;
  resize: none;
  outline: none;
  line-height: 1.3;
}
.sticky-input-row textarea::placeholder { color: rgba(90, 74, 32, 0.6); }

/* Backdrop (click-away) */
.popover-backdrop {
  position: fixed;
  inset: 0;
  z-index: 140;
  background: transparent;
}
.popover-backdrop[hidden] { display: none; }

/* ------------------------------------------------------------
   13. Login modal
   ------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 7, 4, 0.72);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  width: 100%;
  max-width: 440px;
  padding: 32px 32px 24px;
  background: var(--paper);
  background-image: radial-gradient(ellipse at 30% 20%, #f8f1de 0%, #f1e8d0 55%, #ecdfc3 100%);
  color: var(--ink-body);
  box-shadow:
    0 20px 60px rgba(0,0,0,0.5),
    0 1px 0 rgba(255,255,255,0.6) inset;
  transform: rotate(-0.4deg);
  font-family: var(--font-body);
}
.modal h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  font-variant: small-caps;
  letter-spacing: 0.12em;
  text-align: center;
}
.modal p { margin: 0 0 10px; font-size: 15px; line-height: 1.55; }
.modal label {
  display: block;
  font-family: var(--font-typewriter);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faded);
  margin: 14px 0 6px;
}
.modal input[type=text] {
  width: 100%;
  padding: 10px 12px;
  font-family: var(--font-typewriter);
  font-size: 13px;
  background: rgba(255,255,255,0.4);
  border: 1px solid rgba(0,0,0,0.25);
  color: var(--ink-body);
  outline: none;
}

.btn-primary,
.btn-secondary {
  display: inline-block;
  margin-top: 10px;
  padding: 10px 18px;
  font-family: var(--font-typewriter);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #3a2d1e 0%, #2a2219 100%);
  color: #f4ecd8;
  border: 1px solid #5a4a32;
  transition: all 0.15s ease;
}
.btn-primary:hover { background: linear-gradient(180deg, #5a4a32 0%, #3a2d1e 100%); }
.btn-secondary {
  background: none;
  color: var(--ink-faded);
  border: 1px solid rgba(0,0,0,0.15);
}
.btn-secondary:hover { background: rgba(0,0,0,0.04); }

.modal-divider {
  position: relative;
  text-align: center;
  margin: 20px 0 10px;
  font-family: var(--font-typewriter);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faded);
}
.modal-divider::before,
.modal-divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 35%;
  height: 1px;
  background: rgba(0,0,0,0.15);
}
.modal-divider::before { left: 0; }
.modal-divider::after  { right: 0; }

.device-code {
  font-family: var(--font-typewriter);
  font-size: 26px;
  letter-spacing: 0.25em;
  text-align: center;
  padding: 10px;
  background: rgba(255,255,255,0.4);
  border: 1px dashed rgba(0,0,0,0.3);
  margin: 8px 0;
}
.device-flow-status {
  font-size: 12px;
  color: var(--ink-faded);
  text-align: center;
  font-style: italic;
}
.modal-error {
  display: none;
  color: var(--reject);
  font-size: 13px;
  margin-top: 12px;
  font-style: italic;
}
#patDetails { margin-top: 4px; }
#patDetails summary {
  cursor: pointer;
  font-family: var(--font-typewriter);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faded);
  padding: 6px 0;
}
.pat-content { padding: 8px 0; }
.device-flow-instructions { margin-top: 12px; }

/* ------------------------------------------------------------
   14. Toasts
   ------------------------------------------------------------ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  background: var(--sticky-yellow);
  color: var(--sticky-ink);
  font-family: var(--font-hand);
  font-size: 17px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  transform: rotate(-1deg);
  border-left: 3px solid var(--rule-red);
  max-width: 300px;
}
.toast--success { border-left-color: var(--approve); }
.toast--error   { border-left-color: var(--reject); }
.toast--info    { border-left-color: #5a4e3a; }

/* ------------------------------------------------------------
   15. Back to top
   ------------------------------------------------------------ */
.back-to-top {
  position: fixed;
  bottom: 24px;
  left: 316px;
  z-index: 80;
  width: 44px;
  height: 44px;
  background: var(--leather-dark);
  color: #e6d7b3;
  border: 1px solid #000;
  font-size: 18px;
  border-radius: 50%;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
}
.back-to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.back-to-top:hover { background: var(--leather-hi); }

/* ------------------------------------------------------------
   16. Responsive
   ------------------------------------------------------------ */

/* Scroll perf — virtualize off-screen sheets */
.sheet, .chapter {
  content-visibility: auto;
  contain-intrinsic-size: 0 1060px;
}

/* Expanded tap targets on corrections, no 300ms ghost tap */
.correction {
  padding: 6px 2px;
  margin: -6px -2px;
  touch-action: manipulation;
}

@media (max-width: 1100px) {
  .sheet, .chapter { max-width: calc(100vw - 330px); }
}

@media (max-width: 900px) {
  body { font-size: 17px; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .auth-bar { left: 0; padding-left: 60px; }
  .main { margin-left: 0; }
  .menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    top: 4px;
    left: 4px;
    background: var(--rule-red);
    color: #fff;
    border: none;
    border-radius: 8px;
    z-index: 220;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  }
  .back-to-top { left: auto; right: 24px; }
  .sheet, .chapter {
    width: 100%;
    max-width: 100%;
    padding: 80px 44px 64px;
    min-height: auto;
  }
  .sheet-header { left: 74px; right: 44px; }
  .manuscript-text,
  .sheet-body { max-width: 100%; }
  .manuscript-text { font-size: 17px; }
  /* Bigger TOC tap targets */
  .toc-item {
    padding: 12px 14px;
    min-height: 44px;
  }
}

@media (max-width: 600px) {
  .sheet, .chapter {
    padding: 64px 20px 48px;
  }
  .sheet-header {
    left: 20px;
    right: 20px;
    font-size: 9px;
  }
  .sheet-header-left { max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sheet-header-right { text-align: right; }
  .chapter-title-block .chapter-title {
    font-size: clamp(20px, 6vw, 28px);
    letter-spacing: 0.08em;
  }
  /* Kill drop cap at small widths — creates ugly staircase */
  .manuscript-text p.chapter-opener::first-letter {
    font-size: 1em;
    float: none;
    padding: 0;
  }
  .manuscript-text p,
  .manuscript-text p.chapter-opener {
    text-align: left;
    hyphens: none;
  }
  /* Bottom-sheet popover on mobile — always fits */
  .sticky-popover {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    transform: none !important;
    clip-path: none !important;
    border-radius: 14px 14px 0 0;
    max-height: 70vh;
    overflow-y: auto;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.35);
  }
  .sticky-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 8px 12px;
  }
  /* Hero cover letter mobile adjustments (if the hero is re-enabled) */
  .envelope-row { flex-direction: column; gap: 2px; }
  .envelope-key { flex: none; }
  .letter-para { text-align: left; }
  .ps-legend { grid-template-columns: 1fr; gap: 2px; }
  .legend-desc { padding-top: 0; padding-bottom: 12px; }
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
