/* =========================================================
   shared/css/markup.css
   Visual styles for all classes emitted by renderMarkup()
   and the ref/popup system.

   All visual properties use CSS variables with sensible
   fallbacks. No scoped selectors. No hardcoded values.

   Variable contract — set per-context in surface.css or
   per-app in :root (see surface.css and app stylesheets):

     --nwm-size     font-size for markup content  (default: 1rem)
     --nwm-text     body text color               (default: #444)
     --nwm-muted    secondary / muted text color  (default: #888)
     --nwm-accent   ref / accent color            (default: #c9a84c — gold)
     --nwm-brand    subheading / section color    (default: var(--nwm-accent))
     --nwm-border   separator / border color      (default: #e0e0e0)
     --nwm-surface  popup / card background       (default: #faf7f2)
     --nwm-shadow   popup box-shadow              (default: 0 4px 16px rgba(0,0,0,.08))
     --nwm-focus    focus ring color              (default: var(--nwm-accent))

   Fallback values match the reading-surface defaults set by
   surface.css, since that is the primary rendering context.
   ========================================================= */

/* ── Block elements ────────────────────────────────────── */

.nwm-entry {
  margin-bottom: 0.75em;
  padding-bottom: 0;
  border-bottom: none;
}

.nwm-head {
  font-size: var(--nwm-size, 1rem);
  font-weight: normal;
  color: var(--nwm-text, #444);
  line-height: 1.6;
  margin-bottom: 0;
}

.nwm-head strong {
  font-weight: 600;
}

.nwm-line,
.nwm-para {
  font-size: var(--nwm-size, 1rem);
  color: var(--nwm-text, #444);
  line-height: 1.6;
}

.nwm-line {
  margin: 0 0 0.5em;
}

.nwm-para {
  margin: 0 0 0.75em;
}

.nwm-subhead {
  font-size: var(--nwm-size, 1rem);
  font-weight: 600;
  color: var(--nwm-brand, var(--nwm-accent, #c9a84c));
  margin: 1.25em 0 0;
  padding: 0.75em 0 0;
  border-top: 1px solid var(--nwm-border, #e0e0e0);
  border-bottom: none;
  line-height: 1.6;
}

.nwm-blockquote {
  font-size: var(--nwm-size, 1rem);
  color: var(--nwm-muted, #888);
  border-left: 3px solid var(--nwm-accent, #c9a84c);
  margin: 0.5em 0;
  padding: 0 0 0 0.75em;
  font-style: italic;
  line-height: 1.6;
}

.nwm-list-item {
  font-size: var(--nwm-size, 1rem);
  color: var(--nwm-text, #444);
  line-height: 1.6;
  margin: 0.25em 0;
  padding-left: 1em;
  position: relative;
}

.nwm-list-item::before {
  content: '\2013\00a0'; /* – followed by nbsp */
  color: var(--nwm-muted, #888);
  position: absolute;
  left: 0;
}

/* Ordered list items: CSS counter resets on first item in a sequence */
.nwm-list-item--ol:not(.nwm-list-item--ol ~ .nwm-list-item--ol) {
  counter-reset: nwm-ol;
}

.nwm-list-item--ol {
  counter-increment: nwm-ol;
}

.nwm-list-item--ol::before {
  content: counter(nwm-ol) '.';
  color: var(--nwm-muted, #888);
}

/* ── Inline spans ───────────────────────────────────────── */

.nwm-sc {
  font-variant: small-caps;
}

/* nwm-char: structural only — spans from {N}…{/N} DOCX char styles */
.nwm-char {
}

/* ── Reference elements ─────────────────────────────────── */
/* Produced by the caller's renderRef callback; both variants
   use nwm-accent for visual consistency across apps.         */

.cross-ref-link {
  color: var(--nwm-accent, #c9a84c);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.cross-ref-link:hover {
  opacity: 0.8;
}

.ref-link {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  font-weight: 600;
  color: var(--nwm-accent, #c9a84c);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ref-link:hover {
  opacity: 0.85;
}

.ref-link:focus {
  outline: none;
}

.ref-link:focus-visible {
  outline: 2px solid var(--nwm-focus, var(--nwm-accent, #c9a84c));
  outline-offset: 1px;
}

/* ── Scripture popup ────────────────────────────────────── */
/* NOTE: #scripture-popup is position:fixed — it does not inherit
   --nwm-* variables from .layer-pane-content or #preview-body.
   It inherits from :root instead. Apps must map --nwm-surface,
   --nwm-border, and --nwm-shadow in their :root NWM block.    */

#scripture-popup {
  position: fixed;
  z-index: 900;
  width: 280px;
  max-width: calc(100vw - 24px);
  background: var(--nwm-surface, #faf7f2);
  border: 1px solid var(--nwm-border, #e0e0e0);
  border-radius: 10px;
  box-shadow: var(--nwm-shadow, 0 4px 16px rgba(0, 0, 0, .08));
  padding: 12px 14px;
  display: none;
  font-size: var(--nwm-size, 1rem);
  line-height: 1.55;
}

#scripture-popup.is-visible {
  display: block;
}

/* Tooltip arrow — shared base */
#scripture-popup::before,
#scripture-popup::after {
  content: '';
  position: absolute;
  left: 20px;
  width: 0;
  height: 0;
  pointer-events: none;
}

/* Arrow pointing down (popup is above the anchor) */
#scripture-popup.scripture-popup--above::before {
  bottom: -9px;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 9px solid var(--nwm-border, #e0e0e0);
}
#scripture-popup.scripture-popup--above::after {
  bottom: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 7px solid var(--nwm-surface, #faf7f2);
  left: 22px;
}

/* Arrow pointing up (popup is below the anchor) */
#scripture-popup.scripture-popup--below::before {
  top: -9px;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 9px solid var(--nwm-border, #e0e0e0);
}
#scripture-popup.scripture-popup--below::after {
  top: -7px;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 7px solid var(--nwm-surface, #faf7f2);
  left: 22px;
}

/* Reference label — small muted book/verse header */
.scripture-popup-ref {
  font-size: 0.75em;
  font-weight: 600;
  color: var(--nwm-muted, #888);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

/* Verse body — clamp to 4 lines for single-verse display */
.scripture-popup-body {
  font-size: var(--nwm-size, 1rem);
  color: var(--nwm-text, #444);
  line-height: 1.55;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
}

.scripture-popup-body p {
  margin: 0;
}

.scripture-popup-loading {
  color: var(--nwm-muted, #888);
  font-style: italic;
  font-size: 0.9em;
  margin: 0;
}

/* Footer — right-aligned "Show more" link */
.scripture-popup-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--nwm-border, #e0e0e0);
}

.scripture-popup-more {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  font-size: 0.8em;
  color: var(--nwm-accent, #c9a84c);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.scripture-popup-more:hover {
  opacity: 0.8;
}

/* Ellipsis between non-consecutive verses */
.scripture-popup-ellipsis {
  text-align: center;
  color: var(--nwm-muted, #888);
  font-size: 0.85em;
  margin: 0.25em 0;
}

/* ── Scripture popup modal ──────────────────────────────── */

.scripture-modal-body {
  color: var(--nwm-text, #444);
  font-size: var(--nwm-size, 1rem);
  line-height: 1.6;
}

.scripture-modal-body p {
  margin: 0 0 0.75em;
}

.scripture-modal-body p:last-child {
  margin-bottom: 0;
}

.scripture-modal-vnum {
  font-size: 0.7em;
  font-weight: 600;
  color: var(--nwm-muted, #888);
  vertical-align: super;
  margin-right: 0.2em;
  line-height: 1;
}

/* ── Hidden attribute enforcement ────────────────────────────────────────── */
/* Author-level display rules (e.g. display:flex) override the UA stylesheet's
   [hidden] rule without !important. This ensures [hidden] always wins. */
[hidden] { display: none !important; }

/* ── Shared modal system ──────────────────────────────────────────────────── */
/* Core backdrop + sheet layout used by both NetWord and Studio via modal.js  */

.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal-sheet {
  width: 100%;
  max-height: 85vh;
  background: var(--bg-raised, #fff);
  border-radius: var(--radius, 12px) var(--radius, 12px) 0 0;
  box-shadow: var(--shadow-modal, 0 8px 32px rgba(0,0,0,.25));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 480px) {
  .modal {
    align-items: center;
  }
  .modal-sheet {
    max-width: 420px;
    max-height: 80vh;
    border-radius: var(--radius, 12px);
    margin: auto;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border, #e0e0e0);
  gap: 10px;
  flex-shrink: 0;
}

.modal-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text, #111);
}

.modal-back {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs, 6px);
  color: var(--text-2, #555);
  transition: background 0.12s;
}

.modal-back img {
  width: 16px;
  height: 16px;
  opacity: 0.6;
}

.modal-back:hover { background: var(--accent-soft, rgba(0,0,0,.06)); }

.modal-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs, 6px);
  font-size: 14px;
  color: var(--text-3, #888);
  transition: background 0.12s, color 0.12s;
}

.modal-close:hover {
  background: var(--accent-soft, rgba(0,0,0,.06));
  color: var(--accent-text, #111);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Standard modal — centered card, 90% width on mobile */
.modal--standard {
  align-items: center;
  justify-content: center;
  padding: 5vh 16px;
}

.modal--standard .modal-sheet {
  width: 100%;
  max-height: 100%;
  border-radius: var(--radius, 12px);
}

@media (min-width: 480px) {
  .modal--standard {
    padding: 0;
  }
  .modal--standard .modal-sheet {
    width: 420px;
    max-height: 80vh;
  }
}
