/*
 * annotations.css
 * 
 * De Correspondent-style annotation system.
 * Sidenotes on wide screens, expandable inline popups on mobile.
 *
 * Designed to be composable — drop into your existing stylesheet.
 * Relies on CSS custom properties for theming; override as needed.
 */

/* ─── Custom properties ─────────────────────────────────────── */

:root {
  --annotation-accent: #c8622a;          /* The marker dot + key label colour */
  --annotation-bg: #faf8f4;             /* Panel / popup background */
  --annotation-border: #e8e2d9;         /* Subtle rule colour */
  --annotation-text: #3a3530;           /* Body text inside annotations */
  --annotation-text-muted: #8a8178;     /* Secondary / cite text */
  --annotation-link: #c8622a;           /* Source link colour */
  --annotation-radius: 4px;
  --annotation-font-size: 0.875rem;     /* 14px at 16px base */
  --annotation-line-height: 1.6;

  /* Width of the sidenote column on desktop */
  --annotation-sidebar-width: 260px;

  /* Gap between main content and sidenotes */
  --annotation-sidebar-gap: 2.5rem;
}

/* ─── Layout: opt-in wrapper ────────────────────────────────── */
/*
 * Wrap your article content in .annotated-content to activate
 * the sidenote layout. The wrapper uses CSS grid to push the
 * main column left and leave room for sidenotes on the right.
 *
 * <div class="annotated-content">
 *   <div class="annotated-content__body">
 *     ... your rendered markdown ...
 *     {{ annotations | annotationPanel | safe }}
 *   </div>
 * </div>
 */

@media (min-width: 700px) {
  .annotated-content {
    display: grid;
    grid-template-columns: 1fr var(--annotation-sidebar-width);
    gap: 0 var(--annotation-sidebar-gap);
    align-items: start;
  }

  .annotated-content__body {
    grid-column: 1;
    min-width: 0;
  }
}

/* ─── Annotation marker (inline in prose) ───────────────────── */

annotation-marker {
  display: inline-block;
  position: relative;
  width: 0.5em;
  height: 0.5em;
  vertical-align: super;
  cursor: pointer;
  margin-left: 1px;
}

annotation-marker::before {
  content: "";
  display: block;
  width: 0.45em;
  height: 0.45em;
  border-radius: 50%;
  background-color: var(--annotation-accent);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

annotation-marker:hover::before,
annotation-marker[aria-expanded="true"]::before {
  transform: scale(1.3);
}

annotation-marker[aria-expanded="true"]::before {
  opacity: 0.7;
}

/* Focus ring for keyboard navigation */
annotation-marker:focus {
  outline: 2px solid var(--annotation-accent);
  outline-offset: 2px;
  border-radius: 50%;
}

/* ─── Inline popup (mobile / narrow screens) ────────────────── */

.annotation-popup {
  position: absolute;
  z-index: 100;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(100% + 0.5rem);
  width: min(320px, 90vw);
  background: var(--annotation-bg);
  border: 1px solid var(--annotation-border);
  border-radius: var(--annotation-radius);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  padding: 1rem;
  font-size: var(--annotation-font-size);
  line-height: var(--annotation-line-height);
  color: var(--annotation-text);

  /* Animation */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  transform: translateX(-50%) translateY(4px);
}

.annotation-popup.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* Arrow */
.annotation-popup::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--annotation-bg);
  border-right: 1px solid var(--annotation-border);
  border-bottom: 1px solid var(--annotation-border);
}

/* ─── Annotations panel (sidebar / footer) ──────────────────── */

.annotations-panel {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--annotation-border);
}

.annotations-panel__heading {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--annotation-text-muted);
  margin: 0 0 1.25rem;
}

/* On desktop, the panel becomes the sidenote column */
@media (min-width: 700px) {
  .annotations-panel {
    grid-column: 2;
    grid-row: 1;
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    position: sticky;
    top: 2rem;
    align-self: start;
  }

  .annotations-panel__heading {
    margin-bottom: 1rem;
  }
}

/* ─── Individual annotation card ───────────────────────────── */

.annotation {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--annotation-border);
  font-size: var(--annotation-font-size);
  line-height: var(--annotation-line-height);
  color: var(--annotation-text);

  /* Hidden by default on mobile — JS reveals on marker click */
  display: none;
}

.annotation.is-active,
.annotation.is-highlighted {
  display: block;
}

/* On desktop, all annotations are visible */
@media (min-width: 900px) {
  .annotation {
    display: block;
    transition: opacity 0.2s ease;
    opacity: 0.6;
  }

  .annotation.is-highlighted {
    opacity: 1;
  }

  .annotation:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
  }
}

.annotation__inner {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.annotation__key {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--annotation-accent);
}

.annotation__note {
  margin: 0;
}

.annotation__quote {
  margin: 0;
  padding: 0.5rem 0 0.5rem 0.75rem;
  border-left: 2px solid var(--annotation-accent);
  font-style: italic;
  color: var(--annotation-text-muted);
}

.annotation__quote p {
  margin: 0 0 0.25rem;
}

.annotation__quote cite {
  font-size: 0.8em;
  font-style: normal;
}

.annotation__link {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-size: 0.8rem;
  color: var(--annotation-link);
  text-decoration: none;
  font-weight: 500;
}

.annotation__link:hover {
  text-decoration: underline;
}
