/* Inline annotation marker — uniform across layers, soft underline. */
.anno {
  text-decoration: underline solid rgba(127, 127, 127, 0.35);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: help;
  transition: text-decoration-color 0.15s ease;
}
.anno:hover, .anno:focus-visible {
  text-decoration-color: var(--color-ink);
  background: var(--color-shade);
}

/* Hide underline when an annotation has no remaining visible layers.
   data-anno-layers lists the layer keys present in the annotation; if
   none of them are in the body's data-layers attr, the JS adds .anno-empty. */
.anno.anno-empty {
  text-decoration: none;
  cursor: default;
}

/* Tippy theme override */
.tippy-box[data-theme~="ulysses"] {
  background: var(--color-bg);
  color: var(--color-ink);
  border: 1px solid var(--color-rule);
  border-radius: 0.35rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
  font-family: var(--font-ui);
  font-size: 0.92rem;
  line-height: 1.55;
}
.tippy-box[data-theme~="ulysses"] .tippy-content {
  padding: 0.85rem 1rem;
  max-height: min(70vh, 32rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Subtle scrollbar inside the popover (WebKit-only; non-WebKit gets default). */
.tippy-box[data-theme~="ulysses"] .tippy-content::-webkit-scrollbar {
  width: 6px;
}
.tippy-box[data-theme~="ulysses"] .tippy-content::-webkit-scrollbar-thumb {
  background: var(--color-rule);
  border-radius: 3px;
}
.tippy-box[data-theme~="ulysses"] .tippy-arrow {
  color: var(--color-bg);
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-card .phrase {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1rem;
  color: var(--color-ink);
  border-bottom: 1px solid var(--color-rule);
  padding-bottom: 0.4rem;
  margin-bottom: 0.5rem;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-section {
  border-left: 3px solid var(--anno-section-color, var(--color-rule));
  padding: 0.15rem 0 0.15rem 0.65rem;
  margin: 0.55rem 0;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-section .label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--anno-section-color, var(--color-ink-soft));
  margin-bottom: 0.2rem;
  font-weight: 500;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-section .content {
  margin: 0;
  color: var(--color-ink);
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-section .source {
  font-size: 0.78rem;
  color: var(--color-ink-soft);
  margin-top: 0.3rem;
  font-style: italic;
}

/* Cross-references inlined from other Gifford notes — collapsible block.
   The recursive cross-ref inliner (scripts/inline-gifford-crossrefs.mjs) wraps
   resolved targets in sentinel markers; tippy-init.js parses those out and
   renders them as the structure below. */
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xrefs {
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--color-rule);
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xrefs > summary {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 0.1rem 0;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xrefs > summary::-webkit-details-marker {
  display: none;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xrefs > summary::before {
  content: "▸ ";
  display: inline-block;
  width: 0.9em;
  transition: transform 0.15s ease;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xrefs[open] > summary::before {
  content: "▾ ";
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xrefs > summary:hover {
  color: var(--color-ink);
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xrefs ul {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xref {
  margin: 0.45rem 0;
  padding-left: 0.65rem;
  border-left: 2px solid var(--color-rule);
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xref-header {
  font-size: 0.74rem;
  color: var(--color-ink-soft);
  font-family: var(--font-ui);
  margin-bottom: 0.18rem;
}
/* Reader-friendly cross-ref header: target lemma on top, then a hoverable
   "Episode N.line · Source p.N" location line. */
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xref-lemma {
  display: block;
  font-family: var(--font-body);
  font-style: italic;
  font-size: 0.95rem;
  color: var(--color-ink);
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xref-loc {
  display: block;
  font-size: 0.72rem;
  color: var(--color-ink-soft);
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xref-via {
  display: block;
  font-size: 0.68rem;
  color: var(--color-ink-soft);
  opacity: 0.8;
  margin-top: 0.1rem;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .anno-xref-body {
  font-size: 0.88rem;
  color: var(--color-ink);
  line-height: 1.5;
}

/* Layer dot used in controls */
.dot {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  vertical-align: middle;
  margin: 0 0.3rem;
}
.dot-vocabulary { background: var(--color-layer-vocabulary); }
.dot-foreign    { background: var(--color-layer-foreign); }
.dot-gifford    { background: var(--color-layer-gifford); }
.dot-slote      { background: var(--color-layer-slote); }
.dot-dolan      { background: var(--color-layer-dolan); }

/* Gabler page-number markers — injected at build time as the first child
   of the <p> that opens each PDF page. Absolute-positioned in the right
   outer margin of the chapter, baseline-aligned to the paragraph's first
   line. Hidden by default; controls panel toggles `data-pagenumbers` on
   the html element to show. */
.gabler-page {
  display: none;
  position: absolute;
  right: -6ch;
  top: 0;
  font-family: var(--font-ui);
  font-size: 0.78em;
  font-weight: 400;
  color: var(--color-ink-soft);
  font-variant-numeric: tabular-nums;
  /* Match the body's line-height so the marker's baseline aligns with
     the paragraph's first-line baseline. Body uses 1.65 (typography.css);
     keeping that here means top:0 puts both baselines on the same row. */
  line-height: 1.65;
  user-select: none;
  text-align: left;
  opacity: 0.75;
  pointer-events: none;
}

.episode-body p { position: relative; }

[data-pagenumbers="on"] .gabler-page { display: inline-block; }

/* The right gutter inside .content is small (~3ch by default); widen the
   page on wide viewports when page numbers are on so the markers don't
   crowd the body text. */
@media (min-width: 1024px) {
  [data-pagenumbers="on"] .page { max-width: calc(var(--measure) + 28rem); }
}

/* On narrow viewports there's no outer margin to render markers in.
   The marker would either overlap the body text (ugly) or get clipped.
   Hide instead — page numbers are a scholarly aid, not core reading. */
@media (max-width: 1023px) {
  [data-pagenumbers="on"] .gabler-page { display: none; }
}

/* ── Line-reference chips (passages.js) ──────────────────────────────────
   tippy-init.js wraps Gabler line references (e.g. "9.1048-50") inside
   annotation popovers in `.line-ref`. They get a dotted underline to read as
   "hover me for the passage", distinct from the body text's anno underline. */
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .line-ref {
  text-decoration: underline dotted var(--color-layer-vocabulary);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  cursor: help;
  white-space: nowrap;
}
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .line-ref:hover,
:is(.tippy-box[data-theme~="ulysses"], .sidenote-card) .line-ref:focus-visible {
  color: var(--color-layer-vocabulary);
  outline: none;
}

/* ── Passage preview popover (passages.js) ───────────────────────────────
   Reuses the ulysses tippy shell; the `ulysses-passage` modifier renders the
   actual Ulysses lines as serif reading text with a small citation header. */
.tippy-box[data-theme~="ulysses-passage"] .passage-cite {
  font-family: var(--font-ui);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-ink-soft);
  margin-bottom: 0.4rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--color-rule);
}
.tippy-box[data-theme~="ulysses-passage"] .passage-text {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-ink);
}
.tippy-box[data-theme~="ulysses-passage"] .passage-none {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-style: italic;
  color: var(--color-ink-soft);
}

/* ── Click-to-define dictionary popover (dictionary.js) ──────────────────
   `.dict-anchor` is a zero-size element whose getReferenceClientRect is set
   to the clicked word; it carries no visible box of its own. */
.dict-anchor {
  position: fixed;
  width: 0;
  height: 0;
  pointer-events: none;
}
.tippy-box[data-theme~="ulysses-dict"] .dict-head {
  font-family: var(--font-body);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--color-ink);
  margin-bottom: 0.35rem;
}
.tippy-box[data-theme~="ulysses-dict"] .dict-phon {
  font-family: var(--font-ui);
  font-style: normal;
  font-size: 0.8rem;
  color: var(--color-ink-soft);
}
.tippy-box[data-theme~="ulysses-dict"] .dict-source-label {
  font-family: var(--font-ui);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-layer-dolan);
  margin-bottom: 0.4rem;
}
.tippy-box[data-theme~="ulysses-dict"] .dict-pos {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-style: italic;
  color: var(--color-ink-soft);
}
.tippy-box[data-theme~="ulysses-dict"] .dict-sense {
  margin: 0.35rem 0;
}
.tippy-box[data-theme~="ulysses-dict"] .dict-sense ul {
  margin: 0.15rem 0 0;
  padding-left: 1.1rem;
}
.tippy-box[data-theme~="ulysses-dict"] .dict-sense li {
  margin: 0.15rem 0;
  font-size: 0.9rem;
  line-height: 1.45;
}
.tippy-box[data-theme~="ulysses-dict"] .dict-status {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-style: italic;
  color: var(--color-ink-soft);
}

/* ── Sidenote rail (optional "notes beside text" mode) ───────────────────
   Instead of a transient popover, the annotation you hover shows as a single
   persistent, independently-scrollable note in the right margin (replaced when
   you hover another). Deliberately *unframed* — same page background, no panel
   border or shadow — so the note reads as part of the margin, not a separate
   window. Toggled via data-sidenotes="on" on <html>. */
.sidenote-rail { display: none; }
[data-sidenotes="on"] .sidenote-rail {
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 0 0 auto;
  width: 30rem;
  z-index: 50;
  background: var(--color-bg); /* matches page → seamless, no visible edge */
  font-family: var(--font-ui);
  padding-top: 2.5rem; /* clear the controls gear in the corner */
}
.sidenote-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.5rem 1.6rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}
.sidenote-empty {
  color: var(--color-ink-soft);
  font-size: 0.95rem;
  font-style: italic;
  line-height: 1.5;
  padding: 1.5rem 0.25rem;
}
.sidenote-list .sidenote-empty:not(:only-child) { display: none; }

/* Unframed note: no card box. A faint hairline above each (except the first)
   separates notes the way footnotes are separated, without boxing them in. */
.sidenote-card {
  position: relative;
  border: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
  padding-top: 1.4rem;
  border-top: 1px solid var(--color-rule);
  animation: sidenote-in 0.18s ease;
}
.sidenote-list > .sidenote-card:first-of-type {
  border-top: none;
  padding-top: 0;
}
@keyframes sidenote-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}
.sidenote-card-body {
  max-height: 60vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 0.3rem;
  font-size: 1.05rem;
  line-height: 1.6;
}
.sidenote-card-body::-webkit-scrollbar { width: 5px; }
.sidenote-card-body::-webkit-scrollbar-thumb {
  background: var(--color-rule);
  border-radius: 3px;
}
/* Scale the note's inner type up from the popover's compact sizing. */
.sidenote-card .anno-card .phrase {
  font-size: 1.25rem;
  padding-right: 1.4rem;
}
.sidenote-card .anno-section .content { font-size: 1.05rem; }
.sidenote-card .anno-section .label { font-size: 0.74rem; }
.sidenote-card .anno-section .source { font-size: 0.86rem; }
.sidenote-card .anno-xref-lemma { font-size: 1.05rem; }
.sidenote-card .anno-xref-body { font-size: 0.98rem; }
.sidenote-close {
  position: absolute;
  top: 1.1rem;
  right: -0.2rem;
  z-index: 1;
  width: 1.5rem;
  height: 1.5rem;
  line-height: 1;
  font-size: 1.2rem;
  border: none;
  background: none;
  color: var(--color-ink-soft);
  cursor: pointer;
  opacity: 0.4;
}
.sidenote-list > .sidenote-card:first-of-type .sidenote-close { top: -0.2rem; }
.sidenote-close:hover { opacity: 1; color: var(--color-ink); }

/* Shift the centred page left to clear the margin column, on viewports wide
   enough to host both. Narrower screens let the rail overlay (still usable);
   the toggle is best left off there. */
@media (min-width: 1280px) {
  [data-sidenotes="on"] body { padding-right: 31rem; }
}
