/**
 * Interactive Annotations for The Long Road Home
 * Dunlap Family Saga - Historical Fiction
 *
 * Provides hover (desktop) and tap (mobile) popups
 * for historical facts and period maps.
 */

/* ==========================================================================
   CSS Variables (fallbacks for pages without root vars)
   ========================================================================== */
:root {
  --annotation-parchment: #F9F7F1;
  --annotation-sepia: #8b7355;
  --annotation-ink: #2F2D2B;
  --annotation-wax-red: #8A3324;
  --annotation-shadow: rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   Annotated Keywords
   ========================================================================== */
.annotation {
  border-bottom: 1px dotted var(--sepia, var(--annotation-sepia));
  cursor: help;
  position: relative;
  display: inline;
  text-decoration: none;
}

.annotation:hover {
  border-bottom-color: var(--wax-red, var(--annotation-wax-red));
}

.annotation:focus {
  outline: 2px solid var(--sepia, var(--annotation-sepia));
  outline-offset: 2px;
  border-radius: 2px;
}

/* Make annotations focusable for keyboard users */
.annotation[tabindex] {
  outline: none;
}

.annotation[tabindex]:focus-visible {
  outline: 2px solid var(--sepia, var(--annotation-sepia));
  outline-offset: 2px;
}

/* ==========================================================================
   Popup Container
   ========================================================================== */
.annotation-popup {
  position: absolute;
  background: var(--parchment, var(--annotation-parchment));
  border: 1px solid var(--sepia, var(--annotation-sepia));
  box-shadow: 0 4px 16px var(--annotation-shadow);
  padding: 1rem 1.25rem;
  max-width: 340px;
  min-width: 240px;
  z-index: 1000;
  border-radius: 4px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
  transform: translateY(8px);
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--ink, var(--annotation-ink));
}

.annotation-popup.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.annotation-popup.pinned {
  /* Slight visual difference for pinned state */
  box-shadow: 0 6px 24px var(--annotation-shadow);
}

/* ==========================================================================
   Popup Header & Close Button
   ========================================================================== */
.annotation-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}

.annotation-popup h4 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--wax-red, var(--annotation-wax-red));
  flex: 1;
}

.annotation-popup-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: var(--sepia, var(--annotation-sepia));
  padding: 0.25rem;
  margin: -0.25rem -0.25rem 0 0;
  border-radius: 4px;
  transition: background-color 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.annotation-popup-close:hover {
  background-color: rgba(139, 115, 85, 0.1);
  color: var(--wax-red, var(--annotation-wax-red));
}

.annotation-popup-close:focus {
  outline: 2px solid var(--sepia, var(--annotation-sepia));
  outline-offset: 1px;
}

/* ==========================================================================
   Popup Content
   ========================================================================== */
.annotation-popup p {
  margin: 0 0 0.75rem 0;
  font-size: 0.9rem;
}

.annotation-popup p:last-child {
  margin-bottom: 0;
}

/* Map images in popups */
.annotation-popup img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--sepia, var(--annotation-sepia));
  border-radius: 2px;
  margin: 0.5rem 0;
  display: block;
}

.annotation-popup .map-caption {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--sepia, var(--annotation-sepia));
  margin-top: 0.25rem;
}

/* Future: Audio player placeholder */
.annotation-popup audio {
  width: 100%;
  margin-top: 0.5rem;
}

/* ==========================================================================
   Backdrop Overlay (for mobile)
   ========================================================================== */
.annotation-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.annotation-backdrop.visible {
  opacity: 1;
  visibility: visible;
}

/* ==========================================================================
   Mobile Styles (Bottom Drawer)
   ========================================================================== */
@media (max-width: 768px) {
  .annotation-popup {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    min-width: 100%;
    border-radius: 16px 16px 0 0;
    padding: 1.25rem 1.5rem 2rem;
    transform: translateY(100%);
    max-height: 70vh;
    overflow-y: auto;
  }

  .annotation-popup.visible {
    transform: translateY(0);
  }

  /* Drag handle indicator */
  .annotation-popup::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--sepia, var(--annotation-sepia));
    border-radius: 2px;
    opacity: 0.4;
  }

  .annotation-popup-header {
    margin-top: 0.5rem;
  }

  .annotation-popup h4 {
    font-size: 1.15rem;
  }

  .annotation-popup p {
    font-size: 1rem;
  }

  .annotation-popup-close {
    font-size: 1.5rem;
    padding: 0.5rem;
  }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {

  .annotation-popup,
  .annotation-backdrop {
    transition: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .annotation {
    border-bottom-width: 2px;
    border-bottom-style: solid;
  }

  .annotation-popup {
    border-width: 2px;
  }
}

/* ==========================================================================
   Hidden Annotation Data Section
   ========================================================================== */
#annotation-data {
  display: none !important;
}