/* ============================================================
   timeline.css
   Three tiers:
     1. the vertical timeline — a narrow date sidebar on the left,
        one row per calendar month, paired with a wide content
        column where that month's bundles/photos/notes are laid out
        by day (y) and a scattered percentage (x). Bundles and
        photos are free to overlap each other; notes always keep
        clear space around them. Months with nothing in them still
        get a tick on the sidebar, just no height in the content
        column.
     2. a bundle opened — its photos fan out across a dimmed
        overlay, each pickable.
     3. a single photo, full view with its extended caption.
   ============================================================ */

.manuscript-header { text-align: center; margin-bottom: 3rem; }

/* style.css widens .manuscript-wrapper and shifts it right at wide
   viewports so blog posts have a left margin for hung dates (see
   "hung marginal date" in style.css). The timeline has its own
   sidebar and wants no part of that shift, so cancel it here — the
   body.page-timeline class comes from base.njk's navKey. Specificity
   (two classes) beats the site rule regardless of media query. */
body.page-timeline .manuscript-wrapper {
  max-width: var(--measure);
  padding-left: 0;
}

/* The content column (where cards live) is centred on the page at
   its own fixed measure; the date sidebar hangs in a gutter to its
   left, mirrored by equal empty space on the right (see
   .timeline-body below) so the whole composition reads as centred
   rather than skewed by the sidebar's own width. */
.timeline-wrap {
  position: relative;
  max-width: min(46rem, 92vw);
  margin-inline: auto;
}

/* ---------- chapter marker ---------- */
.timeline-current-year {
  position: sticky;
  top: 0.5rem;
  z-index: 3;
  width: fit-content;
  margin-inline: auto;
  margin-bottom: 1rem;
  padding: 0.1rem 1.4rem;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-top-color: #efe9d7;
  border-left-color: #efe9d7;
  box-shadow: 3px 3px 0 rgba(30, 26, 21, 0.2);
  font-family: var(--body);
  font-size: 2rem;
  color: var(--oxblood);
}

/* ---------- tier 1: the timeline ---------- */
/* The sidebar sits in a left gutter reserved by padding-left; that
   same amount is left empty on the right (nothing rendered there —
   just padding-inline, not padding-left) so the content column stays
   centred within .timeline-wrap regardless of viewport width. This
   is deliberately NOT a "sidebar takes real width, content fills the
   rest" layout — that skews the visual mass toward whichever side
   has no sidebar. A gutter-based min-width media query would also
   have skewed things below its breakpoint, so the gutter width just
   scales with viewport instead of switching layouts outright. */
.timeline-body {
  position: relative;
  padding-inline: clamp(3.2rem, 6vw, 4.8rem);
}

.month-block {
  position: relative;
  min-height: var(--h);
  border-left: 1px dotted var(--rule-soft);
  padding-left: 1.2rem;
}
.month-block.is-empty { opacity: 0.6; }

.sidebar-month {
  position: absolute;
  left: clamp(-4.8rem, -6vw, -3.2rem);
  top: 0.15rem;
  width: clamp(2.7rem, 5vw, 3.8rem);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  text-align: right;
  opacity: 0.55;
  transition: opacity 200ms ease;
}
.sidebar-month.is-empty { opacity: 0.28; }
.sidebar-month.is-current { opacity: 1; }

.sidebar-tick { width: 0.7rem; height: 1px; background: var(--rule); }
.sidebar-month.is-current .sidebar-tick { background: var(--oxblood); width: 0.95rem; height: 2px; }

.sidebar-label {
  font-family: var(--utility);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  white-space: nowrap;
}
.sidebar-month.is-current .sidebar-label { color: var(--oxblood); font-weight: 700; }

.track-beat {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 0);
  transform: translateX(-50%);
  z-index: 1;
}
/* bring a card's whole footprint (image + caption) above any
   neighbour it overlaps while it's being looked at */
.track-beat:has(.bundle:hover),
.track-beat:has(.bundle:focus-visible),
.track-beat:has(.single-photo:hover),
.track-beat:has(.single-photo:focus-visible) {
  z-index: 10;
}

/* ---------- a bundle: a small jumbled pile with a name ---------- */
.bundle {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  cursor: pointer;
}

.bundle-stack {
  position: relative;
  width: 7.8rem;
  height: 7.8rem;
}

.bundle-peek {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: var(--z, 1);
  transform: translate(calc(-50% + var(--x, 0)), calc(-50% + var(--y, 0))) rotate(var(--tilt, 0deg));
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
  padding: 4px;
  background: var(--parchment);
  border: 1px solid var(--rule);
  box-shadow: 2px 3px 0 var(--panel-deep), 2px 3px 0 1px var(--rule),
              0 5px 10px rgba(30, 26, 21, 0.35);
}
.bundle-peek picture,
.bundle-peek img,
.bundle-peek .image-missing {
  display: block;
  width: 8.52rem;
  height: 8.52rem;
  min-height: 0; /* .image-missing's base 9rem min-height would otherwise blow this out and cover the caption below */
  margin: 0; /* .image-missing's base 1.7rem margin-block doesn't show on its own box, but it does inflate this peek's auto height */
  object-fit: cover;
  filter: saturate(0.92) contrast(1.03);
}
.bundle-peek .image-missing {
  font-size: 0.42rem;
  gap: 0.15rem;
  overflow: hidden;
}

/* hover/focus: the pile loosens a little, hinting there's more than one photo */
.bundle:hover .bundle-peek,
.bundle:focus-visible .bundle-peek {
  transform: translate(calc(-50% + var(--x, 0) * 1.9), calc(-50% + var(--y, 0) * 1.9)) rotate(var(--tilt, 0deg));
}
.bundle:hover .bundle-peek:last-child,
.bundle:focus-visible .bundle-peek:last-child {
  transform: translate(-50%, -50%) rotate(0deg) scale(1.06);
  box-shadow: 3px 4px 0 var(--panel-deep), 3px 4px 0 1px var(--rule),
              0 8px 14px rgba(30, 26, 21, 0.4);
}

.bundle-caption { text-align: center; max-width: 9.5rem; }
.bundle-title {
  display: block;
  font-family: var(--body);
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.2;
  color: var(--ink);
  margin-top: 1.95rem;
}
.bundle-subtitle {
  display: block;
  font-family: var(--utility);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-top: 0.15rem;
}

/* ---------- a standalone photo ---------- */
.single-photo {
  cursor: pointer;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 220ms ease;
}
.single-photo:hover,
.single-photo:focus-visible {
  transform: rotate(0deg) scale(1.08) translateY(-6px);
  z-index: 5;
}

/* shared card chrome for both the standalone photo and the
   fanned-out photos in an opened bundle */
.single-photo,
.fan-photo {
  padding: 6px 6px 1.7rem;
  text-align: left;
  background: var(--parchment);
  border: 1px solid var(--rule);
  box-shadow: 3px 4px 0 var(--panel-deep), 3px 4px 0 1px var(--rule),
              0 8px 16px rgba(30, 26, 21, 0.35);
  cursor: pointer;
}
.single-photo.size-sm, .fan-photo.size-sm { width: 7.5rem; }
.single-photo.size-md, .fan-photo.size-md { width: 9.5rem; }
.single-photo.size-lg, .fan-photo.size-lg { width: 12.5rem; }

.single-photo picture, .single-photo img, .single-photo .image-missing,
.fan-photo picture, .fan-photo img, .fan-photo .image-missing {
  width: 100%;
  margin: 0;
  filter: saturate(0.92) contrast(1.03);
}
.single-photo .image-missing, .fan-photo .image-missing { min-height: 6rem; margin: 0; }

.card-caption {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 0.3rem;
  display: block;
  background: var(--parchment);
  font-family: var(--utility);
  font-size: 0.6rem;
  line-height: 1.3;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- a plain-text aside, kept clear of everything else ---------- */
.timeline-note {
  width: min(85%, 28rem);
  z-index: 2;
}
.timeline-note-text {
  font-family: var(--body);
  font-style: italic;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink-dim);
  text-align: center;
  padding-inline: 0.25rem;
}

/* ---------- tier 2: a bundle opened ---------- */
.bundle-dialog {
  margin: auto;
  position: relative;
  width: min(76rem, calc(100vw - 2rem));
  height: min(50rem, calc(100vh - 3rem));
  max-width: none;
  max-height: none;
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-top-color: #efe9d7;
  border-left-color: #efe9d7;
  box-shadow: 6px 6px 0 rgba(30, 26, 21, 0.25);
}
/* A native <dialog> is display:none until it has an [open] attribute
   (set by showModal()/close()) — setting display unconditionally
   here would defeat that, leaving the dialog visibly stuck open
   (and impossible to actually close) even before it's ever opened. */
.bundle-dialog[open] {
  display: flex;
  flex-direction: column;
}
.bundle-dialog::backdrop { background: rgba(30, 26, 21, 0.7); }

.bundle-dialog-header {
  flex: 0 0 auto;
  padding: 1.2rem 3rem 0.8rem 1.6rem;
  border-bottom: 1px dotted var(--rule);
}
.bundle-dialog-header h2 {
  font-family: var(--body);
  font-weight: 600;
  font-size: 1.3rem;
}
.bundle-dialog-header p {
  font-family: var(--utility);
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--oxblood);
  margin-top: 0.2rem;
}

.fan-area {
  position: relative;
  flex: 1 1 auto;
  overflow: auto;
}

.fan-photo {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 50%);
  z-index: var(--z, 1);
  transform: translate(-50%, -50%) scale(0.2) rotate(0deg);
  opacity: 0;
  transition: transform 420ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 320ms ease, box-shadow 220ms ease;
  transition-delay: calc(var(--i, 0) * 25ms);
}
.fan-area.is-open .fan-photo {
  transform: translate(-50%, -50%) rotate(var(--tilt, 0deg));
  opacity: 1;
}
.fan-photo:hover,
.fan-photo:focus-visible {
  transform: translate(-50%, -50%) rotate(0deg) scale(1.15) !important;
  z-index: 50;
  box-shadow: 4px 6px 0 var(--panel-deep), 4px 6px 0 1px var(--rule),
              0 16px 28px rgba(30, 26, 21, 0.45);
  transition-delay: 0ms;
}

/* ---------- tier 3: single photo ---------- */
.photo-dialog {
  margin: auto;
  position: relative;
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 4rem);
  padding: 0;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-top-color: #efe9d7;
  border-left-color: #efe9d7;
  box-shadow: 6px 6px 0 rgba(30, 26, 21, 0.25);
}
.photo-dialog::backdrop { background: rgba(30, 26, 21, 0.62); }
.photo-dialog-inner { padding: 1.6rem; }
.photo-dialog-inner picture,
.photo-dialog-inner img,
.photo-dialog-inner .image-missing {
  width: 100%;
  margin-bottom: 1rem;
  padding: 6px;
  background: var(--parchment);
  border: 1px solid var(--rule);
}
.photo-dialog-inner .meta {
  font-family: var(--utility);
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--oxblood);
  margin-bottom: 0.5rem;
}
.photo-dialog-inner p:not(.meta) {
  font-family: var(--body);
  font-size: 1.05rem;
  line-height: 1.5;
}

/* ---------- shared dialog chrome ---------- */
.bundle-dialog .dialog-close,
.photo-dialog .dialog-close {
  position: absolute;
  top: 0.45rem;
  right: 0.6rem;
  z-index: 2;
  font-family: var(--utility);
  font-size: 0.95rem;
  line-height: 1;
  color: var(--ink-dim);
  padding: 0.35rem 0.5rem;
  border: 1px solid transparent;
}
.bundle-dialog .dialog-close:hover,
.photo-dialog .dialog-close:hover {
  color: var(--oxblood);
  border-color: var(--rule);
  background: var(--panel-deep);
}

/* ---------- mobile ---------- */
@media (max-width: 34rem) {
  .timeline-wrap { max-width: 100%; }
  .sidebar-label { font-size: 0.56rem; letter-spacing: 0.03em; }
  .month-block { padding-left: 0.9rem; }
  .timeline-current-year { font-size: 1.5rem; }
  .bundle-stack { width: 6.5rem; height: 6.5rem; }
  .bundle-peek picture, .bundle-peek img, .bundle-peek .image-missing { width: 4.6rem; height: 4.6rem; }
  .timeline-note { width: min(96%, 22rem); }
}

@media (prefers-reduced-motion: reduce) {
  .single-photo, .bundle-peek, .fan-photo { transition: none; }
  .single-photo:hover { transform: rotate(var(--tilt, 0deg)); }
  .fan-area .fan-photo { opacity: 1; transform: translate(-50%, -50%) rotate(var(--tilt, 0deg)); }
}
