/* ==========================================================================
   Pilcrow — a proof sheet
   The subject is typesetting, not security: en quads, thin spaces, joiners,
   variation selectors. So the page is a manuscript being marked up. Warm
   stock, ink, one red pencil and one blue. Marks sit in the text where the
   hidden character sits; the note sits in the margin on the same line.
   The lamp is the one dark moment, and it has to be switched on.
   ========================================================================== */

@font-face {
  font-family: "Newsreader";
  src: url("fonts/newsreader-roman.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: "Newsreader";
  src: url("fonts/newsreader-italic.woff2") format("woff2");
  font-weight: 300 700;
  font-style: italic;
  font-display: block;
}
@font-face {
  font-family: "Courier Prime";
  src: url("fonts/courier-prime-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: "Courier Prime";
  src: url("fonts/courier-prime-italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: block;
}

:root {
  --paper: #f1ece0;
  --paper-2: #e8e1d1;
  --ink: #1c1813;
  --ink-2: #6a6154;
  --rule: #cdc4b0;
  --rule-2: #ddd5c3;

  --pencil: #b62d1c;      /* the red pencil: something is hiding here */
  --blue: #23507e;        /* the blue pencil: an encoding oddity      */
  --graphite: #6f6759;    /* graphite: cosmetic whitespace            */
  --sunk: #1c1813;        /* the specimen's own visible text           */

  --bloom: 0 0 0 transparent;

  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --type: "Courier Prime", "Courier New", Courier, monospace;

  --page: clamp(1.25rem, 5vw, 4.5rem);
  --swap: 420ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* The lamp. Paper falls away, ink sinks to almost nothing, marks fluoresce. */
/* The lamp is pointed at the sheet, not at the room: the page furniture
   stays readable and it is the specimen's own text that sinks away. */
body.uv {
  --paper: #070d0c;
  --paper-2: #0b1412;
  --ink: #84a89d;
  --ink-2: #6d8d84;
  --sunk: #1e332e;
  --rule: #1e3a34;
  --rule-2: #162b26;
  --pencil: #ff6a4a;
  --blue: #57d8ff;
  --graphite: #688d81;
  --bloom: 0 0 10px currentColor;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0 auto;
  max-width: 64rem;
  padding: 0 var(--page) 5rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 380;
  line-height: 1.55;
  font-variant-numeric: oldstyle-nums;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--swap), color var(--swap);
}

::selection { background: var(--pencil); color: var(--paper); }
:focus-visible { outline: 2px solid var(--pencil); outline-offset: 3px; }
* { scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--rule); border: 4px solid var(--paper); }

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

/* --- head ---------------------------------------------------------------- */

.head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.6rem 2rem;
  padding: clamp(2rem, 5vw, 3.4rem) 0 1.5rem;
}

h1 {
  grid-column: 1;
  margin: 0;
  font-size: clamp(2.1rem, 4.6vw, 3rem);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.018em;
  transition: color var(--swap);
}
.pilcrow {
  color: var(--pencil);
  margin-right: 0.2em;
  vertical-align: -0.09em;
  filter: drop-shadow(var(--bloom));
  transition: color var(--swap);
}
.standfirst {
  grid-column: 1;
  margin: 0.85rem 0 0;
  max-width: 58ch;
  font-style: italic;
  font-size: 1.02rem;
  line-height: 1.5;
  color: var(--ink-2);
  transition: color var(--swap);
}

/* the lamp switch, drawn in ink */
.lamp {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  user-select: none;
  padding-top: 0.35rem;
}
.lamp input { position: absolute; opacity: 0; pointer-events: none; }
.lamp-body {
  position: relative;
  width: 40px; height: 18px;
  border: 1px solid var(--ink-2);
  background: transparent;
  flex: none;
  transition: border-color var(--swap), background-color var(--swap);
}
.lamp-body i {
  position: absolute;
  inset: 3px auto 3px 3px;
  width: 12px;
  background: var(--ink-2);
  transition: transform 260ms cubic-bezier(0.4, 0, 0.2, 1),
              background-color var(--swap), box-shadow var(--swap);
}
.lamp-name {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--ink-2);
  white-space: nowrap;
  transition: color var(--swap);
}
.lamp:hover .lamp-body { border-color: var(--pencil); }
.lamp input:checked ~ .lamp-body { border-color: var(--pencil); }
.lamp input:checked ~ .lamp-body i {
  transform: translateX(19px);
  background: var(--pencil);
  box-shadow: var(--bloom);
}
.lamp input:checked ~ .lamp-name { color: var(--pencil); font-style: normal; }
.lamp input:focus-visible ~ .lamp-body { outline: 2px solid var(--pencil); outline-offset: 3px; }

/* --- specimens + running text -------------------------------------------- */

.specimens {
  margin: 0 0 2.2rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.95rem;
  color: var(--ink-2);
  transition: border-color var(--swap), color var(--swap);
}
.lede { font-style: italic; margin-right: 0.7em; }

.specimens button {
  font: inherit;
  font-style: normal;
  color: var(--ink);
  background: none;
  border: 0;
  padding: 0 0 1px;
  margin-right: 0.85em;
  cursor: pointer;
  border-bottom: 1px dotted var(--rule);
  transition: color 120ms, border-color 120ms;
}
.specimens button:hover { color: var(--pencil); border-bottom-color: var(--pencil); }
.specimens button[aria-pressed="true"] {
  color: var(--pencil);
  border-bottom: 1px solid var(--pencil);
}

/* the editorial note: the verdict, as a sentence */
.note {
  margin: 0 0 2rem;
  max-width: 54ch;
  font-size: clamp(1.2rem, 2.1vw, 1.45rem);
  line-height: 1.4;
  font-weight: 380;
  text-wrap: pretty;
  transition: color var(--swap);
}
.note em { font-style: italic; }
.note .fig { font-variant-numeric: lining-nums; }
.note.found .fig, .note.found b { color: var(--pencil); font-weight: 500; }
.note.found b { font-weight: 400; }
.note.idle { color: var(--ink-2); }

/* --- the proof ------------------------------------------------------------ */

.proof {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 13rem;
  gap: 0 2.4rem;
  align-items: stretch;
}

.sheet { display: grid; min-width: 0; }
.sheet > * { grid-area: 1 / 1; }
.sheet[data-mode="edit"] #film { display: none; }
.sheet[data-mode="proof"] #raw { display: none; }

#raw, .film {
  font-family: var(--type);
  font-size: 0.95rem;
  line-height: 2.05;
  min-height: 11rem;
  padding: 0;
  margin: 0;
  color: var(--ink);
  transition: color var(--swap);
}

#raw {
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  overflow: hidden;
  outline: none;
  caret-color: var(--pencil);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#raw::placeholder { color: var(--graphite); font-style: italic; }

.film {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
  outline-offset: 4px;
}
.vis { color: var(--sunk); transition: color var(--swap); }

/* the proofreader's caret, standing where the invisible character stands */
.mark {
  position: relative;
  display: inline-block;
  width: 0.56em;
  height: 1em;
  padding: 0;
  border: 0;
  background: none;
  vertical-align: -0.16em;
  cursor: pointer;
  color: var(--pencil);
  animation: ink 220ms ease-out backwards;
  animation-delay: min(calc(var(--n, 0) * 9ms), 260ms);
  transition: color var(--swap);
}

.mark.warn::before { border-left-width: 1.1px; }
.mark.warn::after { border-right-width: 1.1px; }
.mark.ice, .mark.uv { color: var(--blue); }
.mark.bone { color: var(--graphite); }

/* An insertion caret, squat and sitting on the baseline — the mark a
   proofreader puts where something belongs that is not showing. */
.mark::before {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0.02em;
  height: 0.58em;
  border-left: 1.7px solid currentColor;
  transform: skewX(-26deg);
  transform-origin: bottom left;
  filter: drop-shadow(var(--bloom));
}
.mark::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0.02em;
  height: 0.58em;
  border-right: 1.7px solid currentColor;
  transform: skewX(26deg);
  transform-origin: bottom right;
  filter: drop-shadow(var(--bloom));
}
@keyframes ink { from { opacity: 0; transform: translateY(-2px); } }

.mark:hover::before, .mark.active::before,
.mark:hover::after, .mark.active::after { border-width: 2.6px; }
.mark.active { background: color-mix(in srgb, currentColor 16%, transparent); }

/* the margin: one note per line of the proof, set against it */
.margin {
  position: relative;
  min-width: 0;
  border-left: 1px solid var(--rule);
  padding-left: 1.4rem;
  transition: border-color var(--swap);
}
/* An unmarked sheet has no margin rule — there is nothing to rule off. */
.margin:empty { border-left-color: transparent; }
.mnote {
  position: absolute;
  left: 1.4rem;
  right: 0;
  font-family: var(--type);
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--pencil);
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
  animation: slip 300ms cubic-bezier(0.2, 0, 0, 1) backwards;
  animation-delay: min(calc(var(--n, 0) * 26ms), 340ms);
  transition: color var(--swap);
}
.mnote.ice, .mnote.uv { color: var(--blue); }
.mnote.bone { color: var(--graphite); }
.mnote:hover, .mnote.active { text-decoration: underline; text-underline-offset: 3px; }
.mnote .more { font-style: italic; }
@keyframes slip { from { opacity: 0; transform: translateX(6px); } }

.sheet-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin: 1.6rem 0 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--rule);
  transition: border-color var(--swap);
}
.setting {
  font-family: var(--type);
  font-size: 0.74rem;
  color: var(--graphite);
  transition: color var(--swap);
}
.sheet-acts { display: flex; gap: 1.4rem; }
.sheet-acts button {
  font: inherit;
  font-size: 0.95rem;
  background: none;
  border: 0;
  padding: 0 0 2px;
  cursor: pointer;
  color: var(--ink-2);
  border-bottom: 1px solid var(--rule);
  transition: color 120ms, border-color 120ms;
}
.sheet-acts button:hover:not(:disabled) { color: var(--pencil); border-bottom-color: var(--pencil); }
#cleanBtn:not(:disabled) {
  color: var(--pencil);
  border-bottom: 2px solid var(--pencil);
}
.sheet-acts button:disabled { color: var(--graphite); cursor: default; border-bottom-color: var(--rule-2); }

/* --- apparatus: what a book puts after the text --------------------------- */

.apparatus { margin-top: 3.2rem; }
.apparatus > section + section { margin-top: 2.6rem; }

.sidehead {
  margin: 0 0 0.9rem;
  font-size: 0.98rem;
  font-style: italic;
  font-weight: 400;
  color: var(--ink-2);
  transition: color var(--swap);
}

/* the recovered text: the whole point, so it is set out like an epigraph */
.payloads .out {
  max-width: 62ch;
  margin: 0 0 1.4rem;
  padding: 1.1rem 0 1.2rem 1.6rem;
  border-left: 2px solid var(--pencil);
  font-family: var(--type);
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transition: color var(--swap), border-color var(--swap);
}
.payloads .out:last-child { margin-bottom: 0; }
.payloads .src {
  display: block;
  margin-top: 0.7rem;
  font-family: var(--serif);
  font-style: italic;
  font-size: 0.86rem;
  color: var(--ink-2);
}

/* the tally, set with leader dots the way an index is */
.tally ul { list-style: none; margin: 0; padding: 0; max-width: 34rem; }
.tally li {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.28rem 0;
  font-size: 0.95rem;
}
.tally .lead {
  flex: 1;
  border-bottom: 1px dotted var(--rule);
  transform: translateY(-0.28em);
  min-width: 1.5rem;
  transition: border-color var(--swap);
}
.tally .n {
  font-variant-numeric: lining-nums tabular-nums;
  font-size: 0.9rem;
}
.tally li.none { color: var(--graphite); }
.tally li.red .name, .tally li.red .n { color: var(--pencil); }
.tally li.blue .name, .tally li.blue .n { color: var(--blue); }
.tally li.grey .name, .tally li.grey .n { color: var(--ink-2); }

/* the index of occurrences */
.index ul {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2;
  column-gap: 3rem;
  max-width: 58rem;
}
.index li {
  break-inside: avoid;
  padding: 0.18rem 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink-2);
  transition: color var(--swap);
}
.index .name { color: var(--ink); }
.index .cp, .index .at {
  font-family: var(--type);
  font-size: 0.76rem;
  font-variant-numeric: lining-nums;
}
.index .at { color: var(--graphite); }
.index .rest { font-style: italic; }

.colophon {
  margin-top: 3.4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--rule);
  transition: border-color var(--swap);
}
.colophon p {
  margin: 0;
  max-width: 68ch;
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--ink-2);
  transition: color var(--swap);
}

/* --- drop ---------------------------------------------------------------- */

.drop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms;
}
body.dragging .drop { opacity: 1; }
.drop p {
  margin: 0;
  padding: 2.4rem 3.4rem;
  border: 1px dashed var(--pencil);
  color: var(--pencil);
  font-size: 1.3rem;
  font-style: italic;
}

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

/* --- narrow --------------------------------------------------------------- */

@media (max-width: 900px) {
  .head { grid-template-columns: minmax(0, 1fr); }
  .lamp { grid-column: 1; grid-row: auto; padding-top: 0.9rem; }
  .proof { grid-template-columns: minmax(0, 1fr); gap: 0; }
  /* No room for a margin: the notes fall in as a run-on list under the sheet. */
  .margin {
    position: static;
    border-left: 0;
    border-top: 1px solid var(--rule);
    margin-top: 1.4rem;
    padding: 0.9rem 0 0;
    min-height: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem 0.9rem;
  }
  .margin:empty { display: none; }
  .mnote { position: static !important; left: auto; right: auto; }
  .index ul { columns: 1; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  #raw, .film { min-height: 6rem; }
  .sheet-foot { flex-direction: column; gap: 0.7rem; }
}
