/* In-content typography: highlight, sidenotes, quotes, beispiel box. */

/* --- Justified prose text --------------------------------------------- */
/* Applied to paragraphs inside .prose, welcome sections, and static pages.
   Verse environments and headings opt out explicitly. */
.prose p,
.welcome p,
.static-page p,
.beispiel-body p {
  text-align: justify;
  hyphens: auto;
}
/* Poetry and verse must never be justified */
.cita.verse,
.cita.verse .verse-block,
.prose .verse-block { text-align: left; hyphens: none; }
/* Headings don't look right justified */
.prose h2, .prose h3, .prose h4 { text-align: left; }

/* --- Orange highlight (\hl) ------------------------------------------- */
.prose mark {
  background: var(--rapsoda);
  color: var(--ink);
  padding: 0 0.12em;
  border-radius: 1px;
}

/* --- Bibliographic small-caps -----------------------------------------
   `font-variant: small-caps` is the universal way and falls back to
   synthesised small-caps when the font has no OpenType smcp feature.
   `font-feature-settings: 'smcp' 1` picks up the real glyphs if they
   are available in the font. */
.bibliografia {
  font-family: var(--caps);
  font-variant-caps: small-caps;
  font-feature-settings: 'smcp' 1;
  letter-spacing: 0.04em;
}

/* --- Standalone language section (\begin{ling}[code] … \end{ling}) ---
   Quiet styling: lang attribute set for hyphenation / font picking,
   tiny lang tag in the corner. Use OUTSIDE a \begin{linguae} wrapper. */
.welcome .ling, .prose .ling {
  position: relative;
  padding: 0.6em 0.9em 0.4em;
  margin: 0;
  border-left: 0.5pt solid var(--rapsoda);
}
.welcome .ling-tag, .prose .ling-tag {
  position: absolute; top: 0.4em; right: 0.6em;
  font-family: var(--mono); font-size: 0.7rem;
  color: var(--rapsoda); letter-spacing: 0.08em;
}

/* --- Multilingual tab widget (\begin{linguae} … \end{linguae}) --------
   Dark transparent box matching the header overlay. Vertical strip of
   tabs on the left (one per language), only the checked panel shows.
   Pure HTML/CSS — no JS needed for tab switching. */
.linguae {
  display: grid;
  grid-template-columns: 3.6rem 1fr;
  background: #474747;   /* solid equiv. of rgba(0,0,0,.72) on white */
  color: #ffffff;
  margin: 1.4em 0;
}
.linguae .ling-tabs {
  display: flex; flex-direction: column;
  /* same colour as content area — no extra overlay */
}
/* Radios invisible; appearance:none suppresses native rendering entirely. */
.linguae .ling-radio {
  position: absolute;
  -webkit-appearance: none; appearance: none;
  width: 0; height: 0;
  opacity: 0; pointer-events: none; margin: 0;
}
.linguae .ling-tab {
  display: flex; align-items: center; justify-content: center;
  height: 3.6rem; width: 3.6rem; padding: 0; cursor: pointer;
  font-family: var(--serif); font-size: 0.78rem;
  color: #ffffff;
}
.linguae .ling-radio:checked + .ling-tab {
  background: var(--rapsoda); color: var(--ink);
}
.linguae .ling-radio:focus-visible + .ling-tab {
  outline: 2px solid var(--rapsoda); outline-offset: -2px;
}
.linguae .ling-panels {
  min-height: 0;
  overflow-y: auto;
  padding: 1.1rem 1.6rem;
  scrollbar-width: thin;
  scrollbar-color: #888 transparent;
}
.linguae .ling-panels::-webkit-scrollbar { width: 5px; }
.linguae .ling-panels::-webkit-scrollbar-track { background: transparent; }
.linguae .ling-panels::-webkit-scrollbar-thumb { background: #888; border-radius: 0; }
.linguae .ling-panel { display: none; }
/* Per-panel visibility: the checked radio at index N shows the Nth panel.
   Up to 8 panels per wrapper — plenty for any sane multilingual salutation. */
.linguae:has(.ling-radio[id$="-0"]:checked) .ling-panel:nth-child(1) { display: block; }
.linguae:has(.ling-radio[id$="-1"]:checked) .ling-panel:nth-child(2) { display: block; }
.linguae:has(.ling-radio[id$="-2"]:checked) .ling-panel:nth-child(3) { display: block; }
.linguae:has(.ling-radio[id$="-3"]:checked) .ling-panel:nth-child(4) { display: block; }
.linguae:has(.ling-radio[id$="-4"]:checked) .ling-panel:nth-child(5) { display: block; }
.linguae:has(.ling-radio[id$="-5"]:checked) .ling-panel:nth-child(6) { display: block; }
.linguae:has(.ling-radio[id$="-6"]:checked) .ling-panel:nth-child(7) { display: block; }
.linguae:has(.ling-radio[id$="-7"]:checked) .ling-panel:nth-child(8) { display: block; }

/* Inside the dark panel: borders/quotes/highlights need light tones. */
.linguae .ling-panel a { color: var(--rapsoda); }
.linguae .ling-panel .cita { border-left-color: var(--rapsoda); color: #ffffff; }
.linguae .ling-panel mark  { background: var(--rapsoda); color: var(--ink); }

/* --- Verse environment (\begin{verse}[N]) --------------------------------
   Full-featured verse rendering with optional line numbers and per-line
   indentation. \begin{cita*} remains the simple quoted-verse block.

   Continuation wrapping: when a verse-line is wider than the viewport and
   wraps, the continuation sits 1.5 em to the right of the verse's own
   indent level, making it clear that the wrap is typographic, not a new
   verse. Achieved via the padding/text-indent trick:
     padding-left = line-indent + continuation
     text-indent  = −continuation
   → first character of the line appears at line-indent,
     wrapped lines appear at line-indent + continuation. */

.verse-env {
  margin: 1.4em 0;
}
/* Shift the whole block left so the number column sits in the margin.
   All three values use rem so they cancel exactly regardless of the
   verse-num font-size: margin-left = num-width + gap = 2rem + 0.5rem. */
.verse-env.verse-numbered {
  margin-left: -2.5rem;
}
/* Inside a citation: pull the verse-env left by (cita padding − right gap)
   so the gap from the border to the number equals the gap from the number
   to the verse text. margin-left = -(1.2em − 0.4rem). */
.cita .verse-env.verse-numbered {
  margin-left: calc(-1.2em + 0.1rem);
}
.verse-stanza {
  margin-bottom: 1em;
}
.verse-stanza:last-child { margin-bottom: 0; }

.verse-line {
  display: flex;
  align-items: baseline;
  margin: 0;
  line-height: 1.55;
}
.verse-text {
  flex: 1;
  min-width: 0;
  --continuation: 1.5em;
  padding-left: calc(var(--line-indent, 0em) + var(--continuation));
  text-indent: calc(-1 * var(--continuation));
  text-align: left;
}
.verse-num {
  order: -1;
  flex-shrink: 0;
  width: 2rem;
  margin-right: 0.5rem;
  text-align: right;
  text-indent: 0;
  white-space: nowrap;
  font-size: 0.78rem;
  font-family: var(--serif);
  color: var(--muted);
  line-height: inherit;
  user-select: none;
}
.verse-env:not(.verse-numbered) .verse-num { display: none; }
.verse-num:empty { visibility: hidden; }

/* Synaloepha arc (\sinalefa{a e} / \utie / \Utie).
   Inline SVG quadratic bezier — smooth arc, inherits currentColor. */
.sinalefa {
  position: relative;
  display: inline;
}
.sinalefa-arc {
  position: absolute;
  left: 0.2em;
  width: calc(100% - 0.4em);
  height: 0.28em;
  bottom: -0.24em;
  overflow: visible;
  pointer-events: none;
  display: block;
}

/* --- Quotes ----------------------------------------------------------- */
.cita {
  margin: 1.4em 0; padding: 0.4em 0 0.4em 1.2em;
  border-left: 0.5pt solid var(--rapsoda);
  font-family: var(--serif-i); font-style: normal;
}
.cita.prose p { text-indent: 0; }
.cita.verse .verse-block {
  font-style: normal; line-height: 1.45;
}

/* --- Beispiel box (the LaTeX tcolorbox port) --------------------------
   Boxes / quotes / sections do not flow alongside a floating image; they
   wait for the float to end. (Plain paragraphs still wrap as expected.) */
.prose .beispiel, .prose .cita,
.prose h2.seccion, .prose h3.seccion, .prose h4,
.prose .footnotes { clear: both; }

.beispiel {
  display: block; margin: 1.5em 0; break-inside: avoid;
}
.beispiel-title {
  background: var(--rapsoda); color: var(--ink);
  padding: 0.25em 0.8em; font-family: var(--serif-b); font-weight: normal;
  border-bottom: 0.5pt solid var(--rapsoda);
}
.beispiel-body {
  padding: 0.8em 1em 0.4em;
  border-left: 0.5pt solid var(--rapsoda);
  background: var(--paper);
}
.beispiel-body p:last-child { margin-bottom: 0; }

/* --- Sidenotes --------------------------------------------------------
   Layout strategy:
   * .sidenote-ref is the inline <sup> click target.
   * .sidenote is an <aside> rendered inline right after the ref.
     On desktop it floats right and is pulled out into the reserved
     right gutter via a negative margin. On mobile it collapses and
     is revealed via :target when the user clicks its <sup>.
*/

.sidenote-ref {
  color: var(--rapsoda);
  text-decoration: none;
  font-size: 0.85em;
  vertical-align: super;
  line-height: 0;
  margin-left: 0.1em;
}
.sidenote-ref sup { font-size: inherit; }

.sidenote-num {
  color: var(--rapsoda);
  font-weight: 700;
  margin-right: 0.3em;
}

@media (min-width: 801px) {
  .sidenote {
    /* float makes this span behave as a block; that's expected. */
    float: right;
    clear: right;
    width: var(--side);
    margin: 0 calc(-1 * (var(--side) + var(--gutter))) 0.6em var(--gutter);
    padding-left: 0.7rem;
    border-left: 0.5pt solid var(--rapsoda);
    font-size: 0.85rem;
    line-height: 1.35;
    color: var(--ink);
    /* Lift the float slightly so its first line sits next to the
       reference's baseline rather than below it. */
    transform: translateY(-0.25em);
  }
  .sidenote-close { display: none; }
}

@media (max-width: 800px) {
  .sidenote {
    display: none;
    background: rgba(255, 153, 0, 0.08);
    border-left: 0.5pt solid var(--rapsoda);
    padding: 0.6em 0.8em; margin: 0.5em 0;
    font-size: 0.9rem; color: var(--ink);
  }
  .sidenote:target { display: block; }
  .sidenote-close {
    float: right; text-decoration: none; color: var(--rapsoda);
    font-weight: 700;
  }
}

/* --- Footnote ref styling --------------------------------------------- */
.footnote-ref { color: var(--rapsoda); text-decoration: none; }
.footnote-ref sup { font-size: 0.8em; }

/* --- \imago: inline image, optionally floating, click-to-expand to
       full text column. Text reflows around the float; on expand,
       float clears and following text continues below. ---------------- */

/* Single timing function used by every animatable property in the figure
   so the morph stays in sync. */
:root {
  --imago-anim: 420ms cubic-bezier(0.22, 0.6, 0.36, 1);
}

.prose .imago {
  /* Inline figure that participates in text flow. */
  display: block; width: var(--w, 100%); margin: 0.6em 0;
  break-inside: avoid;
  transition: width var(--imago-anim), margin var(--imago-anim);
}
.prose .imago.float-left  { float: left;  margin: 0.25em 1.25em 0.6em 0; }
.prose .imago.float-right { float: right; margin: 0.25em 0 0.6em 1.25em; }
.prose .imago.float-left,
.prose .imago.float-right { width: var(--w, 40%); }

/* Non-floating, centered, sub-100% width: auto-margins centre it. */
.prose .imago:not(.float-left):not(.float-right) {
  margin-left: auto; margin-right: auto;
}

.imago-toggle { position: absolute; opacity: 0; pointer-events: none; }

/* The frame is a single CSS background. background-size, background-position
   and aspect-ratio all animate together — no transform tricks, so the
   browser renders the bitmap at the correct resolution for each moment
   (no pixelation). */
.imago-frame {
  display: block; position: relative; overflow: hidden;
  background-color: rgba(0, 0, 0, 0.04);
  background-image: var(--bg-url);
  background-repeat: no-repeat;
  background-size:     var(--bg-size, 100% 100%);
  background-position: var(--bg-pos,  0% 0%);
  aspect-ratio:        var(--aspect, 1);
  transition:
    background-size     var(--imago-anim),
    background-position var(--imago-anim),
    aspect-ratio        var(--imago-anim);
}
.imago.toggle .imago-frame { cursor: zoom-in; }

/* The <img> stays present for screen readers, right-click, and SEO, but
   is visually offscreen so it doesn't double the visual. */
.imago-a11y {
  position: absolute; width: 1px; height: 1px;
  opacity: 0; pointer-events: none;
  clip: rect(0 0 0 0);
}

/* Expanded state — bg-size goes to 100% 100%, bg-position to origin,
   aspect to the image's natural pixel aspect; everything morphs. */
.imago.toggle:has(.imago-toggle:checked):not([data-state="collapsed"]),
.imago.toggle[data-state="expanded-ann"],
.imago.toggle[data-state="expanded"] {
  float: none; clear: both;
  width: 100%; margin: 1em 0;
}
.imago.toggle:has(.imago-toggle:checked):not([data-state="collapsed"]) .imago-frame,
.imago.toggle[data-state="expanded-ann"] .imago-frame,
.imago.toggle[data-state="expanded"] .imago-frame {
  cursor: zoom-out;
  background-size: 100% 100%;
  background-position: 0% 0%;
  aspect-ratio: var(--aspect-natural, var(--aspect, 1));
}

/* Caption — only visible when the figure is expanded. We swap height
   instantly and fade opacity so the caption appears with the image. */
.prose .imago figcaption {
  font-size: 0.9rem; font-family: var(--serif-i); font-style: normal; color: var(--ink);
  margin: 0; padding: 0; border: 0;
  max-height: 0; overflow: hidden;
  opacity: 0;
  transition: opacity 180ms ease;
}
.imago.toggle[data-state="expanded-ann"] figcaption,
.imago.toggle[data-state="expanded"] figcaption,
.imago.toggle:has(.imago-toggle:checked):not([data-state="collapsed"]) figcaption,
.imago:not(.toggle) figcaption {
  max-height: none;
  margin-top: 0.4em;
  padding-left: 0.6em;
  border-left: 0.5pt solid var(--rapsoda);
  opacity: 1;
  transition: opacity 220ms ease 260ms;
}

/* Annotations: marker point -> short line -> small text box.
   Visible only in the "expanded-ann" state.

   Visual spec (per your request):
     * Marker circle  — black 72% bg, orange (rapsoda) ring, soft shadow
     * Connector line — orange
     * Text box       — black 72% bg, white text, NO contour, soft shadow
*/
.imago-annotations {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; opacity: 0;
  /* Default (fade-out) is fast and immediate — when leaving expanded-ann
     state the annotations should disappear before the image transforms. */
  transition: opacity 180ms ease;
}
/* Fade IN with a small delay so they appear after the image has finished
   sliding into its expanded position. */
.imago.toggle[data-state="expanded-ann"] .imago-annotations {
  opacity: 1;
  transition: opacity 220ms ease 280ms;
}
.imago.toggle:has(.imago-toggle:checked):not([data-state]) .imago-annotations { opacity: 1; }

.imago-annotations .ann-lines {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}
.imago-annotations .ann-line {
  stroke: var(--rapsoda); stroke-width: 0.35;
  vector-effect: non-scaling-stroke;
}
.imago-annotations .ann-point {
  fill: var(--box-bg);                          /* black ~72% */
  stroke: var(--rapsoda); stroke-width: 0.45;   /* orange ring */
  vector-effect: non-scaling-stroke;
}
.imago-annotations .ann-box {
  position: absolute; transform: translate(-50%, -50%);
  background: var(--box-bg);                    /* black ~72% */
  color: var(--box-text);                       /* white */
  border: 0;
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem; line-height: 1.35;
  max-width: 14rem; min-width: 4rem;
  pointer-events: auto;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
}

/* --- \video --------------------------------------------------------- */
.prose .video { margin: 1.6em 0; }
.prose .video video {
  width: 100%; max-height: 70vh; background: black;
}
.prose .video figcaption {
  font-size: 0.9rem; font-family: var(--serif-i); font-style: normal; color: var(--muted);
  margin-top: 0.4em; padding-left: 0.6em;
  border-left: 0.5pt solid var(--rapsoda);
}

.media-missing {
  border: 0.5pt dashed var(--rapsoda); padding: 1rem;
  color: var(--muted); font-family: var(--serif-i); font-style: normal;
}

/* --- Section headings (\section, \subsection) emitted as h2/h3 -------- */
.prose h2.seccion {
  font-family: var(--caps-b);
  font-size: 1.2rem;
  font-weight: normal;
  letter-spacing: 0.06em;
  text-transform: none;
  margin-top: 2.2em;
  padding-bottom: 0.2em;
  border-bottom: 1px solid var(--rapsoda);
}
.prose h3.seccion {
  font-family: var(--serif-i);
  font-style: normal;
  font-size: 1.05rem;
  margin-top: 1.6em;
}
