/* ==========================================================================
   Reader notes: highlights, notes and sticky notes for visitors.
   The behaviour is in annotate.js.

   Kept out of styles.css on purpose. The baseline-grid checkers read that
   file, and nothing here belongs on the grid: highlights are inline (they
   add no height to a line) and everything else is positioned, so it takes no
   space in the flow. Either way the ruling cannot move.

   No borders anywhere. The only lines on the page are the ruling, the red
   margin rule and the footnote separator, so the menus are cards of paper
   with a shadow, the way the post-its are.
   ========================================================================== */

:root {
  /* Half the size of the site's own post-its: a visitor's note sits on top of
     the writing, and a full 392px one would bury most of a screen. */
  --reader-sticky-size: 196px;
  --reader-card: #fbf7ec;
  --reader-shadow:
    0 1px 1px rgba(32, 32, 32, 0.10),
    0 12px 24px -12px rgba(32, 32, 32, 0.45);
}

/* --------------------------------------------------------------------------
   Highlights. The same pens as the site's own highlighter strokes (the
   .highlight-pink and .highlight-mint classes supply the drawn SVG), with
   the overshoot cancelled exactly by a negative margin. The site's own
   .highlight adds a little width; doing that here would re-wrap a paragraph
   the moment a visitor highlighted something in it.
   -------------------------------------------------------------------------- */

.reader-mark {
  background-repeat: no-repeat;
  background-size: 100% 100%;
  mix-blend-mode: multiply;
  padding: 0.3em 0 0.34em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  cursor: pointer;
  position: relative;
}

/* Overshoot at the outer ends only: a highlight split into pieces by a link
   or an italic word would otherwise show a chisel tip, and a darker overlap,
   at every join. */
.reader-mark.is-first {
  padding-left: 0.3em;
  margin-left: -0.3em;
}

.reader-mark.is-last {
  padding-right: 0.3em;
  margin-right: -0.3em;
}

/* A highlight inside a link stays a link. */
a .reader-mark {
  cursor: inherit;
}

/* A small pencil mark where there is a note to read. Absolutely positioned
   so it never grows the line it sits on. */
.reader-mark.has-note::after {
  content: "✎";
  position: absolute;
  top: -0.75em;
  right: -0.35em;
  font-size: 11px;
  line-height: 1;
  color: var(--ink-soft);
  pointer-events: none;
}

.reader-notes-hidden .reader-mark {
  background: none;
  cursor: auto;
}

.reader-notes-hidden .reader-mark::after,
.reader-notes-hidden .reader-sticky {
  display: none;
}

/* --------------------------------------------------------------------------
   Buttons, shared by every menu. Labels, not boxes: a highlighter stroke for
   the colours, plain text for the rest, weight on hover like every link.
   -------------------------------------------------------------------------- */

.reader-chip {
  font: inherit;
  font-size: 13px;
  line-height: 20px;
  letter-spacing: 0.03em;
  color: var(--ink);
  background-color: transparent;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  border: 0;
  padding: 4px 8px;
  margin: 0;
  cursor: pointer;
}

.reader-chip:hover,
.reader-chip-strong {
  font-weight: 600;
}

.reader-chip:focus-visible,
.reader-toggle:focus-visible,
.reader-sticky-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* --------------------------------------------------------------------------
   The menu under a selection, and the note editor.
   -------------------------------------------------------------------------- */

.reader-pop,
.reader-editor {
  position: absolute;
  z-index: 60;
  background: var(--reader-card);
  box-shadow: var(--reader-shadow);
  padding: 4px;
}

.reader-pop {
  display: flex;
  gap: 2px;
  white-space: nowrap;
}

.reader-editor {
  width: 280px;
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
  padding: 10px;
}

.reader-editor-text {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 84px;
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink);
  background: transparent;
  border: 0;
  resize: vertical;
  padding: 2px;
}

.reader-editor-text:focus {
  outline: none;
}

.reader-editor-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 2px;
  margin-top: 6px;
}

/* --------------------------------------------------------------------------
   Sticky notes, in the yellow of the site's own pack, with the same gummed
   strip and the same lift at the bottom edge.
   -------------------------------------------------------------------------- */

.reader-sticky {
  position: absolute;
  z-index: 50;
  box-sizing: border-box;
  width: var(--reader-sticky-size);
  height: var(--reader-sticky-size);
  display: flex;
  flex-direction: column;
  background: linear-gradient(172deg, #f6f0d8 0%, #f0e8c8 62%, #ebe2bd 100%);
  box-shadow: var(--reader-shadow);
}

.reader-sticky::after {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: -3px;
  height: 10px;
  border-radius: 50%;
  background: rgba(32, 32, 32, 0.16);
  filter: blur(5px);
  z-index: -1;
  pointer-events: none;
}

.reader-sticky.is-dragging {
  box-shadow:
    0 2px 2px rgba(32, 32, 32, 0.10),
    0 18px 30px -12px rgba(32, 32, 32, 0.5);
}

/* The gummed strip doubles as the handle. touch-action: none stops a phone
   scrolling the page instead of moving the note. */
.reader-sticky-bar {
  flex: 0 0 26px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  background: linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.06));
  cursor: grab;
  touch-action: none;
}

.reader-sticky.is-dragging .reader-sticky-bar {
  cursor: grabbing;
}

.reader-sticky-close {
  font: inherit;
  font-size: 18px;
  line-height: 1;
  color: var(--ink-soft);
  background: none;
  border: 0;
  padding: 2px 8px;
  cursor: pointer;
}

.reader-sticky-close:hover {
  color: var(--ink);
  font-weight: 600;
}

.reader-sticky-text {
  flex: 1;
  min-height: 0;
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink);
  background: transparent;
  border: 0;
  resize: none;
  padding: 4px 14px 14px;
}

.reader-sticky-text:focus {
  outline: none;
}

/* --------------------------------------------------------------------------
   The tab in the bottom-right corner, and the panel it opens.
   -------------------------------------------------------------------------- */

.reader-dock {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.reader-toggle {
  font: inherit;
  font-size: 14px;
  line-height: 20px;
  color: var(--ink);
  background: var(--reader-card);
  box-shadow: var(--reader-shadow);
  border: 0;
  padding: 8px 14px;
  cursor: pointer;
  transform: rotate(-1.4deg);
}

.reader-toggle:hover,
.reader-toggle[aria-expanded="true"] {
  font-weight: 600;
}

.reader-panel {
  width: 240px;
  max-width: calc(100vw - 32px);
  box-sizing: border-box;
  background: var(--reader-card);
  box-shadow: var(--reader-shadow);
  padding: 12px 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.reader-help {
  font-size: 13px;
  line-height: 19px;
  color: var(--ink-soft);
  margin: 0 8px 6px;
}

/* The [hidden] attribute loses to the display rules above without this. */
.reader-pop[hidden],
.reader-editor[hidden],
.reader-panel[hidden] {
  display: none;
}

@media print {
  .reader-pop,
  .reader-editor,
  .reader-dock,
  .reader-sticky {
    display: none;
  }
}
