/* ── Variables ───────────────────────────────────────────── */

:root {
  --color-bg:             #edf2f4; /* page background */
  --color-text-on-dark:   #f5f8fa; /* light text and icons on dark or image backgrounds */
  --color-text:           #2b2d42; /* primary text and dark solid surfaces */
  --color-muted:          #8d99ae; /* secondary text and subdued details */
  --color-border:         #ccd2d8; /* dividers, outlines, and image placeholders */
  --color-map-coast:      #2b2d42; /* coastline line work on a route map */
  --color-map-water:      #4d9de0; /* rivers, canals, and streams on a route map */
  --color-map-wash:       #eaf2f9; /* pale halo behind the coast and the waterways */
  --color-map-panel:      #1b1d21; /* backdrop under the map on a narrow screen */
  --font: "Bricolage Grotesque", sans-serif;
  --fs-caption: 0.73rem;
  --fs-ui:      0.85rem;
  --fs-body:    1.0625rem;
  --fs-subhead: 1.2rem;
  --fs-heading: 1.55rem;
  --timeline-w: 5rem;
  --timeline-center: 2.4rem;
  --radius-sm: 3px;
  --radius-md: 6px;
  --transition: 0.15s;
  --nav-h: 3.5rem;
  --content-max-w: 1440px;
  /* layered shadow keeping white text legible over any photo background */
  --text-halo: 0 1px 3px rgba(0,0,0,0.9), 0 2px 16px rgba(0,0,0,0.6), 0 4px 40px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-optical-sizing: auto;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.75;
  font-size: var(--fs-body);
}

/* ── Activity header (full-screen) ───────────────────────── */

.activity-header {
  position: relative;
  max-width: var(--content-max-w);
  margin: 0 auto;
  aspect-ratio: 16 / 9;
  min-height: 320px;
  color: var(--color-text-on-dark);
  overflow: hidden;

  /* Gradient overlay: dark at top (nav) and bottom (stats) */
  .header-overlay {
    position: absolute;
    inset: 0;
    background:
      linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, rgba(0,0,0,0.1) 22%, transparent 40%),
      linear-gradient(to top,   rgba(0,0,0,0.75) 0%, rgba(0,0,0,0.15) 35%, transparent 55%);
    pointer-events: none;
  }
}

/* The photo fills the header on a wide screen; on a narrow one it becomes the
   first block of the stacked header. */
.header-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
}

/* ── Site tagline ────────────────────────────────────────── */

.site-tagline {
  font-family: var(--font);
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-text-on-dark);
  text-decoration: none;
  letter-spacing: 0.04em;

  &:hover { opacity: 0.8; }
}


/* ── Header title + stats block ──────────────────────────── */

/* title-style from frontmatter controls positioning and size */
.header-title {
  position: absolute;
  z-index: 10;

  h1 {
    font-family: var(--font);
    font-size: clamp(2.5rem, 6vw, 4.75rem);
    font-weight: 800;
    color: var(--color-text-on-dark);
    line-height: 1.05;
    /* tight halo → mid blur → wide glow: legible over any background */
    text-shadow: var(--text-halo);
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
  }
}

/* map-style (frontmatter) positions the route map directly on the header,
   independently of the title block. The inline style supplies the offsets;
   this class supplies the default width and keeps the map behind the title
   when the two overlap. */
.header-map {
  position: absolute;
  z-index: 5;
  width: clamp(200px, 30vw, 26rem);
}

.header-caption {
  position: absolute;
  bottom: 0.8rem;
  left: 1rem;
  z-index: 11;
  font-family: var(--font);
  font-size: var(--fs-ui);
  color: color-mix(in srgb, var(--color-text-on-dark) 80%, transparent);
  margin: 0;

  & a {
    color: inherit;
    text-decoration: underline;
  }
}

/* Column inline-flex: the block is only as wide as its widest child (the
   stats row), so the Strava link sits beneath the row instead of stretching. */
.header-stats {
  display: inline-flex;
  flex-direction: column;
}

.header-stats-row {
  display: flex;
  gap: 1.5rem 2rem;
  flex-wrap: wrap;

  .header-stat {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    align-items: center;

    .header-stat-label {
      font-family: var(--font);
      font-size: 0.75rem;
      font-weight: 500;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      color: var(--color-text-on-dark);
      text-shadow:
        0 1px 3px rgba(0,0,0,0.9),
        0 2px 16px rgba(0,0,0,0.6),
        0 4px 40px rgba(0,0,0,0.4);
    }

    .header-stat-value {
      font-family: var(--font);
      font-size: 1.3rem;
      font-weight: 600;
      color: var(--color-text-on-dark);
      line-height: 1;
      text-shadow:
        0 1px 3px rgba(0,0,0,0.9),
        0 2px 16px rgba(0,0,0,0.6),
        0 4px 40px rgba(0,0,0,0.4);
    }
  }
}

/* ── Site nav ────────────────────────────────────────────── */

.site-header--nav {
  background: var(--color-text);
  padding: 0 2rem;
  height: var(--nav-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font);
}

body:has(.activity-header) .site-header--nav {
  position: absolute;
  top: 0; left: 0; right: 0;
  background: transparent;
  z-index: 10;
}

/* When the header image top is bright, switch nav to dark text */
body:has(.activity-header[data-nav-theme="light"]) {
  .site-tagline { color: var(--color-text); }
}

/* ── Route SVG (inside activity header) ─────────────────── */

.route-svg {
  display: block;
  width: 100%;
  color: #f5f8fa; /* shared border, road, and label colour */
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5));
}

/* SVG element styles — applied to inline SVG children.
   The coastline is dark line work and the waterways are blue, so the two read
   as shore and water, each over a pale wash that keeps an edge against the
   photo; everything else stays on the map's currentColor. */
.route-wash {
  stroke: var(--color-map-wash);
}

.route-coastline {
  stroke: var(--color-map-coast);
}

.route-waterway {
  stroke: var(--color-map-water);
}

.route-border {
  stroke: currentColor;
  stroke-width: 3;
  stroke-dasharray: 10 6;
  opacity: 0.85;
}

.route-line {
  stroke: #ef233c;
}

.route-dot {
  fill: #ef233c;
}

.route-label {
  fill: currentColor;
  font-family: var(--font);
  text-shadow: var(--text-halo);
}

.route-label--city {
  font-weight: 600;
}

.strava-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.6rem;
  font-family: var(--font);
  font-size: var(--fs-caption);
  font-weight: 500;
  color: var(--color-text-on-dark);
  text-decoration: none;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  transition: color var(--transition);

  &:hover { opacity: 0.8; }
}

/* ── Travelogue body ──────────────────────────────────────── */

.travelogue {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 2rem 5rem calc(var(--timeline-w) + 2rem);

  /* Continuous timeline line */
  &::before {
    content: '';
    position: absolute;
    left: calc(var(--timeline-center) + 2rem);
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--color-border);
  }
}

/* ── Stage ───────────────────────────────────────────────── */

.stage {
  position: relative;
  padding-top: 1.5rem;
}

/* ── Stage timeline marker ───────────────────────────────── */

.stage-marker {
  position: absolute;
  left: calc(-1 * var(--timeline-w));
  top: 2.5rem;
  width: var(--timeline-w);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.2rem;
  padding-right: calc(var(--timeline-w) - var(--timeline-center) + 0.7rem);

  /* Dot on the timeline */
  &::before {
    content: '';
    position: absolute;
    left: calc(var(--timeline-center) - 0.25rem);
    top: 0.3rem;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-text);
    border: 2px solid var(--color-bg);
  }

  .marker-time,
  .marker-distance {
    font-family: var(--font);
    display: block;
    line-height: 1;
    white-space: nowrap;
  }

  .marker-time {
    font-style: normal;
    font-size: 1.25rem;
    font-weight: 700;
    font-variant-caps: all-small-caps;
    color: var(--color-text);
  }

  .marker-distance {
    font-size: 0.9rem;
    color: var(--color-muted);
  }
}

/* ── Stage body ──────────────────────────────────────────── */

.stage-body {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: flex-start;

  /* Headings and bare paragraphs span full width */
  & > h1, & > h2, & > h3, & > h4,
  & > p,
  & > .footnote-list,
  & > .citation-list,
  & > .system-message,
  & > .line-block {
    flex: 0 0 100%;
  }

  /* Drop cap — two lines tall. */
  & > .container > p:first-child::first-letter,
  & > .container > h3 + p::first-letter {
    font-family: var(--font);
    font-size: 4.25rem;
    font-weight: 700;
    line-height: 0.74;
    float: left;
    margin-right: 0.07em;
    margin-top: 0.05em;
  }

  /* Container children become columns */
  & > .container {
    flex: 1;
    min-width: min(260px, 100%);

    /* Column title (from :title: option) */
    & > h3 {
      font-family: var(--font);
      font-size: 1.15rem;
      font-weight: 700;
      color: var(--color-text);
      display: flex;
      align-items: center;
      gap: 0.65rem;
      margin-top: 0;
      margin-bottom: 0.75rem;

      &::before, &::after {
        content: '';
        flex: 1;
        height: 1px;
        background: var(--color-border);
      }
    }
  }

  /* Full-width column (class via .. column:: full-width) — takes the whole
     row, so following/preceding columns wrap above and below it. */
  & > .container.full-width {
    flex: 0 0 100%;
  }

  /* Two-column text layout (via :text-columns: option on .. container:: / .. column::) */
  & > .container.text-columns {
    flex: 0 0 100%;
    columns: 2;
    column-gap: 2rem;

    & > h1, & > h2, & > h3, & > h4 { column-span: all; }
  }

  & p {
    margin-bottom: 1.2rem;
    text-wrap: pretty; /* avoids a single orphaned word on the last line */
    orphans: 2;        /* min lines to keep at the bottom of a column */
    widows: 2;         /* min lines to keep at the top of a column */

    &:last-child { margin-bottom: 0; }
  }

  & em { font-style: italic; }
  & strong { font-weight: 700; }
  & a { color: var(--color-text); }

  & h2, & h3 {
    font-family: var(--font);
    font-weight: 700;
    margin-bottom: 0.75rem;
    line-height: 1.2;
  }

  & h2 { font-size: var(--fs-heading); margin-top: 1.5rem; }
  & h3 { font-size: var(--fs-subhead); margin-top: 1.25rem; }

  & figure {
    margin: 0 0 0.75rem;

    &:last-child { margin-bottom: 0; }
  }

  & img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius-sm);
  }

  & figcaption {
    font-family: var(--font);
    font-size: var(--fs-caption);
    color: var(--color-muted);
    margin-top: 0.35rem;
    font-style: italic;
    line-height: 1.4;
  }

  /* Footnotes/citations: docutils wraps each group in a .footnote-list /
     .citation-list element and puts the label in a <span> before a block
     <p> — make the first paragraph inline so label and text share a line. */
  .footnote-list,
  .citation-list {
    font-size: var(--fs-ui);
    color: var(--color-muted);
    margin-top: 2rem;

    & p { margin: 0; }
    & .footnote, & .citation { margin-bottom: 0.5rem; }
    & .footnote:last-child, & .citation:last-child { margin-bottom: 0; }
    & .label { margin-right: 0.35rem; }
    & .footnote > p:first-of-type, & .citation > p:first-of-type { display: inline; }
  }

  /* A list that is a stage's own is spaced by the row gap above it, which the
     margin above would double. The margin earns its keep only for a list
     nested in a column, where there is no gap. */
  & > .footnote-list,
  & > .citation-list {
    margin-top: 0;
  }

  /* docutils system messages (RST warnings) */
  .system-message { display: none; }

  .epigraph {
    font-family: var(--font);
    font-size: 1.35rem;
    font-style: italic;
    color: var(--color-text);
    text-align: center;
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);

    & p {
      margin: 0 0 0.25rem;

      &:last-child { margin-bottom: 0; }
    }

    .attribution {
      font-family: var(--font);
      font-size: 0.78rem;
      font-style: normal;
      color: var(--color-muted);
    }
  }
}

/* ── End of activity ──────────────────────────────────────── */

.stage.end {
  /* The terminus dot is filled, so the timeline reads as finished rather
     than as one more stage along it. */
  .stage-marker::before {
    background: var(--color-text);
    border-color: var(--color-bg);
    height: 11px;
    width: 11px;
    left: calc(var(--timeline-center) - 0.4rem);
    top: 0.15rem;
  }
}

.end-metrics {
  flex: 0 0 100%;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;

  /* Boxed like an epigraph: a thin rule and a soft radius, so the figures
     read as a panel rather than as loose text. */
  .end-metric {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.1rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);

    dt {
      font-family: var(--font);
      font-size: 0.68rem;
      font-weight: 500;
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--color-muted);
    }

    dd {
      margin: 0;
      font-family: var(--font);
      font-size: 1.1rem;
      font-weight: 600;
      line-height: 1.15;
      color: var(--color-text);
      font-variant-numeric: tabular-nums;
    }
  }
}

/* The trip tier reports secondary figures: the trip as it stands when the
   day ends. Its extra top margin separates it from the day's own metrics.
   An em-dash in a cell means the trip had nothing to add up. */
.end-metrics-trip {
  margin-top: 0.8rem;
}

/* ── Stage quote / kicker ────────────────────────────────── */

.stage-quote {
  font-family: var(--font);
  font-size: 1.25rem;
  font-weight: 400;
  font-style: italic;
  color: var(--color-text);
  border-left: 3px solid var(--color-text);
  padding-left: 0.85rem;
  margin-bottom: 1rem;
  line-height: 1.35;

  & p { margin: 0; }
}

/* ── Stacked images ──────────────────────────────────────── */

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

  & > figure,
  & > img { margin: 0; }
}

/* ── Side-by-side images ─────────────────────────────────── */
/*
 * The renderer stamps each figure with --ar (the image's aspect ratio).
 * flex-grow ∝ --ar with flex-basis 0 splits the row exactly in proportion
 * to the aspect ratios, so both images get the same height at their
 * natural ratio — no cropping. Rows that would grow taller than 75vh are
 * capped, and object-fit: cover absorbs only that excess. Figures without
 * --ar (remote or unreadable images) fall back to an even split.
 */

.side-by-side {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;

  & > figure,
  & > img {
    flex: var(--ar, 1) 1 0%;
    min-width: 0;
    margin: 0;
  }

  & > figure > img,
  & > img {
    width: 100%;
    height: auto;
    max-height: 75vh;
    object-fit: cover;
    display: block;
  }

  & > figure > figcaption {
    contain: inline-size;
    overflow-wrap: break-word;
  }
}

/* ── Carousel ────────────────────────────────────────────── */

.carousel {
  position: relative;

  .carousel-track {
    display: grid;

    & > figure,
    & > img {
      grid-area: 1 / 1;
      width: 100%;
      margin: 0;
      min-height: 0;
    }
  }

  .carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.38);
    color: var(--color-text-on-dark);
    border: none;
    cursor: pointer;
    font-size: 1.8rem;
    line-height: 1;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    z-index: 5;
    transition: background var(--transition);
    font-family: var(--font);

    &:hover { background: rgba(0,0,0,0.6); }
  }

  .carousel-prev { left: 0.4rem; }
  .carousel-next { right: 0.4rem; }

  .carousel-counter {
    position: absolute;
    bottom: 0.4rem;
    right: 0.4rem;
    background: rgba(0,0,0,0.38);
    color: var(--color-text-on-dark);
    font-family: var(--font);
    font-size: 0.68rem;
    padding: 0.15rem 0.45rem;
    border-radius: var(--radius-sm);
  }
}

/* ── Trip navigation (bottom of an activity) ─────────────── */

/* Shares the travelogue's column and gutter, so the rule and the links line up
   with the timeline markers above. */
.trip-nav {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 2rem 4rem calc(var(--timeline-w) + 2rem);
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  gap: 2rem;
}

.trip-nav-link {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-family: var(--font);
  text-decoration: none;
  color: var(--color-text);

  &:hover .trip-nav-title { text-decoration: underline; }
  &:hover .trip-nav-label { color: var(--color-text); }
}

/* The next link sits at the right end of the row, with its text right-aligned,
   whether or not a previous link shares it; the previous link stays at the
   left. The two then read as ends of a line rather than a list.

   Keep this as a top-level rule: in native CSS nesting, a suffix written as
   &--modifier parses as & followed by a type selector, so it never matches. */
.trip-nav-link--following {
  margin-left: auto;
  align-items: flex-end;
  text-align: right;
}

.trip-nav-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-muted);
  transition: color var(--transition);
}

.trip-nav-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.25;
  text-wrap: balance;
}

.trip-nav-date {
  font-size: var(--fs-caption);
  color: var(--color-muted);
}

/* ── Site footer ─────────────────────────────────────────── */

.site-footer {
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 2rem;
  font-family: var(--font);
  font-size: var(--fs-ui);
  color: var(--color-muted);
  text-align: center;
}

/* ── Index page ──────────────────────────────────────────── */

.site-header {
  max-width: var(--content-max-w);
  margin: 0 auto;
  padding: 1rem 2rem;
  font-family: var(--font);
}

.index-main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 2.5rem 2rem 5rem;
}

.trip-section {
  margin-bottom: 3.5rem;
}

.trip-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 0.5rem;
}

.trip-year {
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.trip-name-heading {
  font-family: var(--font);
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0;

  a {
    color: var(--color-text);
    text-decoration: none;

    &:hover { opacity: 0.7; }
  }
}

.activity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 1rem;
}

.activity-card {
  display: block;
  text-decoration: none;
  color: var(--color-text);

  &:hover .activity-card-image img { transform: scale(1.03); }
  &:hover .activity-card-title { color: var(--color-muted); }
}

.activity-card-image {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--radius-md);
  background: var(--color-border);

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
  }
}

.activity-card-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.5rem 0.6rem 0.5rem;
  background: linear-gradient(to top, rgba(0,0,0,0.65) 0%, transparent 100%);
  display: flex;
  gap: 0.75rem;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-on-dark);
  letter-spacing: 0.02em;
}

.activity-card-info {
  padding: 0.4rem 0.1rem 0;
  text-align: center;
}

.activity-card-date {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.5rem 0.6rem 1.75rem;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--color-text-on-dark);
  text-shadow: var(--text-halo);
}

.activity-card-title {
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
  transition: color var(--transition);
}

.empty { color: var(--color-muted); font-style: italic; }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 720px) {
  .travelogue {
    padding: 0 1rem 5rem;
  }

  /* The timeline goes away with the column it lived in; the marker moves
     inline above its stage body. */
  .travelogue::before { display: none; }

  .stage-marker {
    position: static;
    width: auto;
    padding: 0;
    flex-direction: row;
    align-items: baseline;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
  }

  .stage-marker::before,
  .stage.end .stage-marker::before { display: none; }

  .stage-marker:empty { display: none; }

  /* Separate the time from the distance only when both are present. */
  .marker-time + .marker-distance::before {
    content: '·';
    margin-right: 0.45rem;
    color: var(--color-muted);
  }

  /* The header stacks: photo, then title and metrics, then the map. */
  .activity-header {
    display: flex;
    flex-direction: column;
    max-width: none;
    margin: 0;
    aspect-ratio: auto;
    min-height: 0;
    overflow: visible;
    color: var(--color-text);
  }

  .header-image {
    position: relative;
    inset: auto;
    aspect-ratio: 4 / 3;
  }

  .header-map {
    order: 2;
    position: static;
    width: auto !important;
    padding: 1rem;
    background: var(--color-map-panel);
  }

  .header-title {
    order: 1;
    position: static;
    max-width: none !important;
    padding: 1.25rem 1rem 0.75rem;

    h1 {
      font-size: clamp(1.8rem, 7vw, 2.8rem);
      color: var(--color-text);
      text-shadow: none;
    }
  }

  .header-stats .header-stats-row .header-stat-label,
  .header-stats .header-stats-row .header-stat-value,
  .strava-link {
    color: var(--color-text);
    text-shadow: none;
  }

  .stage-body > .container { flex: 0 0 100%; }

  /* Three metric boxes across leaves each one too narrow to hold a label like
     "Elevation Gained"; drop to two, then to one. */
  .end-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 420px) {
  .end-metrics { grid-template-columns: minmax(0, 1fr); }
}
