:root {
  --timeline-icon-bg: #f6f8fa;
  --timeline-card-bg: #ffffff;
  --timeline-card-shadow: rgba(27, 31, 35, 0.05);

  --timeline-title: #24292e;
  --timeline-date-bg: #0366d6;
  --timeline-date-color: #ffffff;
  --timeline-text: #586069;
  --timeline-reference: #6a737d;

  --timeline-distort: none;
  --timeline-background-shadow-color: none;

  /* Archival theme colors. Parchment style */
  --archive-background: #ecd8b3;
  --archive-border: #7f6a40;
  --archive-heading: #2a2315;

  /* Override basic timelines styles with archival theme */
  --timeline-line: var(--archive-border, #d1d5da);
  --timeline-icon-border: var(--archive-border, #0366d6);

  --timeline-card-bg: color-mix(in srgb, white 70%, var(--archive-background) 30%);
  --timeline-card-border: var(--archive-border, #e1e4e8);
  --timeline-arrow-bg: var(--archive-border, #e1e4e8);
  --timeline-heading: var(--archive-heading, #15171a);
  --timeline-background: var(--archive-background, inherit);
  --timeline-distort: url('data:image/svg+xml, \ <svg xmlns="http://www.w3.org/2000/svg">\ <defs>\ <filter id="archive-distort">\ <feTurbulence\ baseFrequency="0.01 0.01"\ numOctaves="4"\ result="noise" />\ <feDisplacementMap\ in="SourceGraphic"\ in2="noise"\ scale="2"\ xChannelSelector="R"\ yChannelSelector="R" />\ </filter>\ </defs>\ </svg>#archive-distort');
  --timeline-background-image: url("data:image/svg+xml, \ <svg xmlns='http://www.w3.org/2000/svg'>\ <filter id='noiseFilter'>\ <feTurbulence type='fractalNoise' baseFrequency='0.35' numOctaves='1' stitchTiles='stitch'/>\ <feColorMatrix type='saturate' values='0'/>\ <feComponentTransfer>\ <feFuncA type='linear' slope='0.3' intercept='0'/>\ </feComponentTransfer>\ </filter>\ <rect width='100%' height='100%' filter='url(%23noiseFilter)'/>\ </svg>");
  --timeline-background-shadow-color: rgba(236 197 120);
  --timeline-link: var(--archive-border, inherit);
  --timeline-blockquote: var(--archive-background, initial);
  --timeline-count-bg: var(--archive-border, #0366d6);
  --timeline-card-shadow: color-mix(in srgb, white 50%, var(--archive-border) 50%);
}

body {
  background-color: #282828;
}

select,
::picker(select) {
  appearance: base-select;
}

select {
  position: sticky;
  float: right;
  /* margin-top: -100px; */
  backdrop-filter: blur(4px);
  z-index: 1;
  top: 20px;
}

option {
  display: flex;

  .label-count {
    font-size: 0.6em;
    border-radius: 2px;
    background-color: var(--timeline-count-bg);
    line-height: 1em;
    padding: 2px;
    color: white;
  }
  .label-name {
    flex-grow: 1;
  }
}

main {
  position: relative;
  background-color: var(--timeline-background);
  background-image: var(--timeline-background-image);
  box-shadow: inset 0 0 100px var(--timeline-background-shadow-color);
  /* prevent background moves on resize due to relative padding */
  background-origin: border-box;
  border-width: 0 1px 0 1px;
  border-style: solid;

  h1 {
    color: var(--timeline-heading);
  }
}

#timeline-container {
  position: relative;
  /* max-width: 900px; */
  margin: 0 auto;
  line-height: normal;

  &::after {
    content: '';
    position: absolute;
    width: 4px;
    background-color: var(--timeline-background);
    top: 0;
    bottom: 0;
    left: 50%;
    margin-left: -2px;
    /* z-index: 1; */
    filter: var(--timeline-distort);
    background-image: linear-gradient(to bottom, transparent 0%, var(--timeline-line) 50px) !important;
    margin-top: -20px;
  }

  .timeline-item {
    padding: 5px 40px;
    position: relative;
    background-color: inherit;
    width: 50%;
    box-sizing: border-box;
    transition: all 0.3s ease;

    &.hidden {
      display: none;
    }

    &:nth-child(odd of :not(&.hidden)) {
      left: 0;

      .timeline-icon {
        right: -12px;
      }

      img {
        float: right;
        margin-left: 8px;
      }

      .reference {
        clear: right;
      }

      &::before {
        right: 30px;
        border-width: 10px 0 10px 10px;
        border-color: transparent transparent transparent var(--timeline-arrow-bg);
      }
    }

    &:nth-child(even of :not(&.hidden)) {
      left: 50%;

      .timeline-icon {
        left: -12px;
      }

      img {
        float: left;
        margin-right: 8px;
      }

      .reference {
        clear: left;
      }

      &::before {
        left: 30px;
        border-width: 10px 10px 10px 0;
        border-color: transparent var(--timeline-arrow-bg) transparent transparent;
      }
    }

    .timeline-icon {
      position: absolute;
      width: 16px;
      height: 16px;
      right: -8px;
      background-color: var(--timeline-icon-bg);
      border: 4px solid var(--timeline-icon-border);
      top: 25px;
      border-radius: 50%;
      z-index: 2;
      filter: var(--timeline-distort);
    }

    &::before {
      content: ' ';
      height: 0;
      position: absolute;
      top: 28px;
      width: 0;
      /* z-index: 2; */
      border: medium solid var(--timeline-arrow-bg);
    }

    .timeline-content {
      padding: 20px;
      background-color: var(--timeline-card-bg);
      position: relative;
      border: 1px solid var(--timeline-card-border);
      border-radius: 6px;
      box-shadow: 0 0 13px var(--timeline-card-shadow);
      filter: var(--timeline-distort);
      overflow: hidden;

      h2 {
        margin-top: 0;
        font-size: 1.2em;
        color: var(--timeline-title);
      }

      img {
        max-height: 150px;
        border-radius: 4px;
        object-fit: contain;
      }

      .date {
        background-color: var(--timeline-date-bg);
        color: var(--timeline-date-color);
        padding: 3px 8px;
        border-radius: 4px;
        font-size: 0.85em;
        margin-right: 10px;
        font-weight: 600;
      }

      p {
        margin: 10px 0 0;
        line-height: 1.6;
        color: var(--timeline-text);
      }

      .reference {
        display: block;
        margin-top: 12px;
        font-size: 0.8em;
        font-style: italic;
        color: var(--timeline-reference);
        text-align: right;
      }
    }
  }
}

a {
  color: var(--timeline-link);
}

blockquote {
  border-left-color: var(--timeline-blockquote);
}

/* Responsive design for smaller screens */
@media screen and (max-width: 768px) {
  h1 {
    font-size: 2em;
  }

  #timeline-container {
    &::after {
      left: 31px;
    }

    .timeline-item {
      width: 100%;
      padding-left: 70px;
      padding-right: 25px;

      /* Superficial unnecessary duplication due to CSS specificity rules */
      &:nth-child(odd of :not(&.hidden)),
      &:nth-child(even of :not(&.hidden)) {
        left: 0;
      }

      &:nth-child(odd of :not(&.hidden)) .timeline-icon,
      &:nth-child(even of :not(&.hidden)) .timeline-icon {
        left: 19px;
      }

      &:nth-child(odd of :not(&.hidden)):before,
      &:nth-child(even of :not(&.hidden)):before {
        left: 60px;
        border-width: 10px 10px 10px 0;
        border-color: transparent var(--timeline-arrow-bg) transparent transparent;
      }
    }
  }
}

main + footer {
  margin-top: 0;
}

/* Scroll to top button color variables */
:root {
  --scroll-btn-bg: color(srgb 1 1 1 / 0.25);
  --scroll-btn-border: color(srgb 0 0.482 1 / 0.3);
  --scroll-btn-shadow: color(srgb 0 0 0 / 0.15);
  --scroll-btn-text: #007bff;
  --scroll-btn-text-shadow: color(srgb 0 0 0 / 0.2);
  --scroll-btn-hover-bg: color(srgb 0 0.482 1 / 0.15);
  --scroll-btn-hover-border: color(srgb 0 0.482 1 / 0.4);
  --scroll-btn-hover-text: #0056b3;
}

/* Scroll to top button styles with CSS scroll-driven animation */
#scroll-to-top {
  position: fixed;
  top: 20px;
  left: max(30px, calc(50% - min(590px, 50vw - 30px)));
  z-index: 1000;
  background: var(--scroll-btn-bg);
  backdrop-filter: blur(15px);
  border: 2px solid var(--scroll-btn-border);
  border-radius: 50%;
  width: 45px;
  height: 45px;
  cursor: pointer;
  box-shadow: 0 8px 32px var(--scroll-btn-shadow);
  transition: all 0.3s ease;
  display: flex !important;
  align-items: center;
  justify-content: center;
  font-size: 25px;
  font-weight: 900;
  color: var(--scroll-btn-text);
  text-shadow: 0 2px 4px var(--scroll-btn-text-shadow);
  font-family: Arial, sans-serif;
  line-height: 1;

  /* CSS Scroll-driven animation for visibility */
  animation: scroll-button-visibility linear both;
  animation-timeline: scroll(root);
  animation-range: 0px 800px;

  &:hover {
    background: var(--scroll-btn-hover-bg);
    border-color: var(--scroll-btn-hover-border);
    transform: scale(1.05);
    box-shadow: 0 12px 48px var(--scroll-btn-shadow);
    color: var(--scroll-btn-hover-text);
  }

  @media (max-width: 768px) {
    top: 30px;
    left: 20px;
    width: 38px;
    height: 38px;
    font-size: 21px;
  }

  @media (max-width: 480px) {
    top: 25px;
    left: 15px;
    width: 35px;
    height: 35px;
    font-size: 20px;
  }
}

/* Keyframes for scroll-driven visibility animation */
@keyframes scroll-button-visibility {
  0%,
  80% {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
}

/* Anniversaries Styles */
@keyframes anniversaries-entrance {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
    max-height: 0;
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    max-height: 2000px; /* Large enough value */
  }
}

#anniversaries-container.anniversaries-container {
  animation: anniversaries-entrance 0.8s ease-out forwards;
  background: var(--archive-background, #ecd8b3);
  background-image: var(--timeline-background-image);
  padding: 20px;
  margin: 20px 0;
  border: 2px solid var(--archive-border, #7f6a40);
  border-radius: 6px;
  box-shadow: 0 0 13px var(--timeline-card-shadow);
  filter: var(--timeline-distort);
  position: relative;

  /* Heading & intro text */
  .anniversaries-heading {
    color: var(--archive-heading, #2a2315);
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.4em;
    font-weight: 700;
    font-variant-emoji: text;
  }
  .anniversaries-date-intro {
    margin-bottom: 15px;
    color: var(--timeline-text, #586069);
    line-height: 1.6;
  }

  .anniversary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 20px;
  }

  /* Tile - styled like timeline cards */
  .anniversary-tile {
    display: block;
    text-decoration: none;
    background: var(--timeline-card-bg);
    padding: 18px;
    border: 1px solid var(--timeline-card-border);
    border-left: 4px solid var(--archive-border, #7f6a40);
    border-radius: 6px;
    box-shadow: 0 0 13px var(--timeline-card-shadow);
    transition:
      transform 0.3s ease,
      box-shadow 0.3s ease;
    cursor: pointer;
    filter: var(--timeline-distort);
    position: relative;

    &:hover {
      transform: translateY(-3px);
      box-shadow: 0 8px 20px var(--timeline-card-shadow);
    }

    .anniversary-date-label {
      color: var(--archive-border, #7f6a40);
      font-weight: bold;
      font-size: 0.9em;
      margin-bottom: 8px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }
    .anniversary-title {
      color: var(--timeline-title, var(--archive-heading));
      font-weight: 700;
      margin-bottom: 8px;
      line-height: 1.3;
      font-size: 1.1em;
    }
    .anniversary-meta {
      color: var(--timeline-reference, #6a737d);
      font-size: 0.85em;
      font-style: italic;
      margin-top: 8px;
    }
  }

  /* No results message */
  .no-anniversaries {
    color: var(--timeline-reference, #666);
    font-style: italic;
    text-align: center;
    margin: 20px 0;
  }

  /* Responsive grid adjustments */
  @media (max-width: 768px) {
    .anniversary-grid {
      grid-template-columns: 1fr !important;
      gap: 12px;
    }
    padding: 16px;
  }
  @media (min-width: 769px) and (max-width: 1200px) {
    .anniversary-grid {
      grid-template-columns: repeat(2, 1fr) !important;
    }
  }
}

/* Image Lightbox Popover Styles */
#image-lightbox {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: auto;
  height: auto;
  max-width: min(90vw, 800px);
  max-height: min(85vh, 600px);
  background: rgb(0 0 0 / 0.95);
  backdrop-filter: blur(5px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem 2rem 2rem;
  box-sizing: border-box;
  z-index: 1000;
  margin: 0;
  border: none;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.8);
  pointer-events: none;
}

#image-lightbox:popover-open {
  pointer-events: auto;
}

#image-lightbox::backdrop {
  background: rgb(0 0 0 / 0.6);
}

.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgb(255 255 255 / 0.1);
  border: 2px solid rgb(255 255 255 / 0.3);
  color: white;
  font-size: 2rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 1001;
}

.lightbox-close:hover,
.lightbox-close:focus {
  background: rgb(255 255 255 / 0.2);
  border-color: rgb(255 255 255 / 0.5);
  transform: scale(1.1);
}

#lightbox-image {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.5);
}

#lightbox-caption {
  color: white;
  text-align: center;
  margin-top: 1rem;
  font-size: 1.1rem;
  font-weight: 500;
  max-width: 100%;
  text-shadow: 0 2px 4px rgb(0 0 0 / 0.8);
}

/* Timeline image cursor to indicate clickability */
.timeline-image-link {
  cursor: zoom-in;
  transition: opacity 0.2s ease;
}

.timeline-image-link:hover {
  opacity: 0.8;
}

/* Popover animation */
#image-lightbox {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.8);
  transition:
    opacity 0.3s ease,
    transform 0.3s ease,
    overlay 0.3s ease allow-discrete,
    display 0.3s ease allow-discrete;
}

#image-lightbox:popover-open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* Starting style for entrance animation */
@starting-style {
  #image-lightbox:popover-open {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }
}
