/* ==========================================================================
   COMPONENT: Timeline — Ajalugu / Meie lugu
   Vertical timeline with year markers, consistent left-to-right layout.
   Image always on the right when present.
   ========================================================================== */

/*
  --tl-dot-top: offset from top of .c-timeline__marker to the dot's top edge.
  Formula: marker padding-top + half the year font-size (line-height:1) - half dot height.
  = var(--space-1) + 1rem - 5px   →  centers 10px dot with the year label.
  Adjusted at the 640px breakpoint when year font-size drops to 1.25rem.

  --tl-line-x: the left offset (from entry edge) of the vertical line.
  = container gutter + year column width. Matches the right edge of the marker.
*/
.c-timeline {
  --tl-dot-top:  calc(var(--space-1) + 1rem - 5px);
  /* Line must align with the dot, which lives inside the centered container.
     On narrow viewports the container fills the width → gutter + 100px.
     On wide viewports the container centres → add the centering offset. */
  --tl-line-x:   max(
    calc(var(--gutter) + 100px),
    calc(50% - var(--container-max) / 2 + var(--gutter) + 100px)
  );
}


/* ------------------------------------------------------------------
   ENTRY WRAPPER
   ------------------------------------------------------------------ */

.c-timeline__entry {
  position: relative;
  background-color: var(--color-surface);
  padding-block: var(--space-12);
}

/* Vertical line — on the entry so it spans full height including padding-block,
   creating an unbroken line across adjacent entries */
.c-timeline__entry::before {
  content: '';
  position: absolute;
  left: var(--tl-line-x);
  top: 0;
  bottom: 0;
  width: 1px;
  background-color: var(--color-outline-variant);
  z-index: 0;
}

/* First milestone per segment: line starts at dot centre, not the very top */
.c-timeline__entry--first::before {
  top: calc(var(--space-12) + var(--tl-dot-top) + 5px);
}

/* Last milestone per segment: line fades out toward the bottom — "to be continued" */
.c-timeline__entry--last::before {
  background: linear-gradient(
    to bottom,
    var(--color-outline-variant) 0%,
    var(--color-outline-variant) 60%,
    transparent 100%
  );
}

/* Alternate subtle background for visual rhythm */
.c-timeline__entry:nth-of-type(even) {
  background-color: var(--color-surface-container-low);
}


/* ------------------------------------------------------------------
   ROW — year column | body column
   ------------------------------------------------------------------ */

.c-timeline__row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 0 var(--space-10);
  align-items: start;
}


/* ------------------------------------------------------------------
   MARKER — year label + vertical line + dot
   ------------------------------------------------------------------ */

.c-timeline__marker {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-3);
  padding-right: var(--space-6);
  padding-top: var(--space-1);
  align-self: stretch;
  position: relative;
}


.c-timeline__year {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.2vw, 2rem);
  font-weight: 400;
  font-style: italic;
  color: var(--color-secondary);
  line-height: 1;
}

/* Dot sitting on the timeline line, centred on it */
.c-timeline__node {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-full);
  background-color: var(--color-primary);
  position: absolute;
  right: -5px;               /* half of 10px dot, centres it on the right edge of the marker */
  top: var(--tl-dot-top);
  z-index: 1;                /* sits above the ::before line */
}


/* ------------------------------------------------------------------
   BODY — content text + optional image
   ------------------------------------------------------------------ */

.c-timeline__body {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-8);
  padding-top: var(--space-1);
}

/* When there is an image: content left, image right */
.c-timeline__entry--has-image .c-timeline__body {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

.c-timeline__content {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.c-timeline__title {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  font-weight: 400;
  line-height: 1.2;
  color: var(--color-on-surface);
}

.c-timeline__text {
  color: var(--color-on-surface-variant);
}

.c-timeline__text.prose p {
  font-size: var(--text-body-lg);
  line-height: var(--text-body-lg-lh);
}


/* ------------------------------------------------------------------
   IMAGE
   ------------------------------------------------------------------ */

.c-timeline__image {
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.c-timeline__img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-lg);
}


/* ------------------------------------------------------------------
   CHAPTER BREAK — Dark green full-width divider
   ------------------------------------------------------------------ */

.c-timeline__break {
  background-color: var(--color-primary);
  padding-block: var(--space-16);
  text-align: center;
}

.c-timeline__break .container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.c-timeline__break-label {
  color: var(--color-on-primary-container);
}

.c-timeline__break-headline {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 3.5vw, 2.75rem);
  font-weight: 400;
  font-style: italic;
  line-height: 1.15;
  color: var(--color-on-primary);
  max-width: 24ch;
}

.c-timeline__break-headline em {
  font-style: italic;
}


/* ------------------------------------------------------------------
   RESPONSIVE
   ------------------------------------------------------------------ */

@media (max-width: 900px) {
  .c-timeline__entry--has-image .c-timeline__body {
    grid-template-columns: 1fr;
  }

  .c-timeline__image {
    max-width: 480px;
  }
}

@media (max-width: 640px) {
  .c-timeline {
    /* year font-size drops to 1.25rem; year column narrows to 70px */
    --tl-dot-top: calc(var(--space-1) + 0.625rem - 5px);
    --tl-line-x:  max(
      calc(var(--gutter) + 70px),
      calc(50% - var(--container-max) / 2 + var(--gutter) + 70px)
    );
  }

  .c-timeline__entry {
    padding-block: var(--space-8);
  }

  /* Adjust first-entry line start for smaller padding and font */
  .c-timeline__entry--first::before {
    top: calc(var(--space-8) + var(--tl-dot-top) + 5px);
  }

  .c-timeline__row {
    grid-template-columns: 70px 1fr;
    gap: 0 var(--space-6);
  }

  .c-timeline__marker {
    padding-right: var(--space-4);
  }

  .c-timeline__year {
    font-size: 1.25rem;
  }

  .c-timeline__break {
    padding-block: var(--space-10);
  }
}
