/* MV_Chronicle — full-screen tree-wide chronicle overlay (#133).
   Sibling to MV_Timeline: same sticky-rail + scrolling-stream layout, but
   tree-wide rather than per-person. Cards carry subject chips so a reader
   always knows whose moment they're reading; clicking a chip jumps to
   that person's panel. Heritage palette and serif voice match the
   timeline so the chronicle feels like the same reading surface viewed
   from a higher altitude. */

.chronicle-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--color-bg);
  z-index: var(--z-reading-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-base);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chronicle-overlay--open {
  opacity: 1;
  pointer-events: auto;
}

.chronicle {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse at top, var(--color-bg-tint) 0%, var(--color-bg) 60%);
}

/* ---------------- header ---------------- */

.chronicle__header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  background: linear-gradient(to bottom,
    var(--color-surface) 0%,
    var(--color-surface-elevated) 100%);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.chronicle__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  justify-self: start;
}

.chronicle__back:hover,
.chronicle__back:focus-visible {
  color: var(--color-text);
  background-color: var(--color-surface-alt);
}

.chronicle__back-arrow {
  font-size: var(--font-size-md);
  line-height: 1;
}

.chronicle__title {
  text-align: center;
}

.chronicle__title-name {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-xl);
  color: var(--color-text);
  margin: 0;
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-tight);
}

.chronicle__title-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-xxs);
  font-style: italic;
}

.chronicle__close {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  justify-self: end;
}

.chronicle__close:hover,
.chronicle__close:focus-visible {
  color: var(--color-text);
  background-color: var(--color-surface-alt);
}

/* ---------------- layout ---------------- */

.chronicle__layout {
  flex: 1;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: var(--space-xl);
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-lg) var(--space-xl) var(--space-xxl);
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  /* Scrollbar styling is global — the heritage scrollbar born here (#278)
     moved to reset.css when it became the app-wide default (#414). */
}

/* ---------------- rail ---------------- */

.chronicle__rail {
  position: sticky;
  top: var(--space-md);
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
  padding: var(--space-md) var(--space-md) var(--space-md) 0;
  border-right: 1px solid var(--color-border);
  font-family: var(--font-serif);
}

.chronicle__rail-link {
  display: block;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-md);
  font-style: italic;
  font-weight: var(--font-weight-medium);
  color: var(--color-text-muted);
  text-decoration: none;
  text-align: right;
  letter-spacing: var(--letter-spacing-wide);
  border-radius: var(--radius-md);
  border-right: 2px solid transparent;
  transition:
    color var(--transition-fast),
    background-color var(--transition-fast),
    border-color var(--transition-fast);
}

.chronicle__rail-link:hover,
.chronicle__rail-link:focus-visible {
  color: var(--color-highlight);
  background-color: var(--color-highlight-soft);
}

.chronicle__rail-link--active {
  color: var(--color-accent);
  font-weight: var(--font-weight-bold);
  border-right-color: var(--color-accent);
  background-color: var(--color-accent-soft);
}

.chronicle__rail-link--undated {
  font-size: var(--font-size-sm);
  font-style: normal;
  color: var(--color-text-faint);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  margin-top: var(--space-sm);
}

.chronicle__rail-gap {
  display: block;
  padding: 0 var(--space-sm);
  text-align: right;
  color: var(--color-text-faint);
  font-size: var(--font-size-sm);
  letter-spacing: 0.4em;
  line-height: 1.2;
}

/* ---------------- stream + decade sections ---------------- */

.chronicle__stream {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
  padding-bottom: var(--space-xxl);
  min-width: 0;
}

.chronicle__decade {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scroll-margin-top: var(--space-md);
}

.chronicle__decade-marker {
  position: relative;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-medium);
  color: var(--color-text);
  margin: 0;
  padding: 0 0 var(--space-sm);
  letter-spacing: var(--letter-spacing-wide);
}

/* A short warm rule under each decade — a "chapter" accent rather than a full
   hairline across the column (#278). */
.chronicle__decade-marker::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 46px;
  height: 3px;
  border-radius: var(--radius-sm);
  background-color: var(--color-highlight);
}

/* ---------------- event cards ---------------- */

/* Cards carry no border (#278) — the kind colour does the work the old
   left/dashed border used to. Authored stories + moments are the white
   "hero" cards with a lift; synthesised life beats are softer tinted cards. */
.chronicle__event {
  background-color: var(--color-surface-elevated);
  border: none;
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.chronicle__event--moment {
  background-color: var(--color-surface);
}

/* "Life" cards (synthesised birth / union / remembrance) read as compact
   tinted cards — each kind in its own heritage hue (see the Chronicle kind
   palette in variables.css). Lighter shadow so authored stories + moments
   stay the visual heroes, but never transparent: a birth must read as a
   moment that happened, not as floating text on the stream. */
.chronicle__event--life {
  box-shadow: var(--shadow-sm);
  padding: var(--space-md) var(--space-lg);
}

.chronicle__event--birth {
  background-color: var(--color-accent-soft);
}

.chronicle__event--wedding {
  background-color: var(--color-union-soft);
}

.chronicle__event--death {
  background-color: var(--color-remembrance-soft);
}

/* ---- the leading row: kind medallion + date ---- */

/* The medallion itself is the shared MV_Medallion component (#281,
   css/medallion.css); the chronicle only lays out the head row. */
.chronicle__event-head {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* Date inherits the kind hue so the colour system reads even before the eye
   reaches the medallion. */
.chronicle__event-date {
  font-size: var(--font-size-xs);
  color: var(--color-highlight);
  font-weight: var(--font-weight-bold);
  letter-spacing: var(--letter-spacing-wider);
  text-transform: uppercase;
}

.chronicle__event--birth .chronicle__event-date { color: var(--color-accent); }
.chronicle__event--wedding .chronicle__event-date { color: var(--color-union); }
.chronicle__event--death .chronicle__event-date { color: var(--color-remembrance-deep); }
.chronicle__event--story .chronicle__event-date { color: var(--color-highlight-hover); }
.chronicle__event--moment .chronicle__event-date { color: var(--color-moment); }

.chronicle__event-title {
  font-family: var(--font-serif);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  margin: 0;
  line-height: var(--line-height-tight);
}

.chronicle__subjects {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-xxs);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.chronicle__subject-sep {
  color: var(--color-text-faint);
  white-space: pre;
}

/* The chronicle keeps the .mv-multiselect__chip class for the shared pill
   shape + sizing (per #133's acceptance criterion — enforced by the smoke
   test), but overrides the fill: a person reads as a crisp white name-pill so
   it lifts off *any* kind tint (#278 — the old accent-soft chip vanished on the
   green birth card; green-on-green). Name text stays accent green to match the
   tree's "people = green" identity. */
.chronicle__subject-chip {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  color: var(--color-accent);
  box-shadow: var(--shadow-sm);
  font-weight: var(--font-weight-bold);
  padding: 2px var(--space-sm);
  cursor: pointer;
  font-family: inherit;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    background-color var(--transition-fast);
}

.chronicle__subject-chip:hover,
.chronicle__subject-chip:focus-visible {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.chronicle__subject-chip:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.chronicle__subject-chip:disabled:hover {
  transform: none;
  box-shadow: none;
}

.chronicle__life-sentence {
  font-family: var(--font-serif);
  font-size: var(--font-size-base);
  font-style: italic;
  color: var(--color-text);
  margin: 0;
  line-height: var(--line-height-loose);
  display: inline;
}

.chronicle__life-sentence .chronicle__subject-chip {
  font-family: var(--font-sans);
  font-style: normal;
  font-size: var(--font-size-sm);
  vertical-align: baseline;
}

.chronicle__event-body {
  font-size: var(--font-size-base);
  line-height: var(--line-height-loose);
  color: var(--color-text);
}

.chronicle__event-body p {
  margin: 0 0 var(--space-sm);
}

.chronicle__event-body p:last-child {
  margin-bottom: 0;
}

.chronicle__event-body h3 {
  font-family: var(--font-serif);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-bold);
  margin: var(--space-sm) 0 var(--space-xxs);
}

.chronicle__event-body h4 {
  font-family: var(--font-serif);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-bold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
  color: var(--color-text-muted);
  margin: var(--space-sm) 0 var(--space-xxs);
}

.chronicle__event-body ul,
.chronicle__event-body ol {
  margin: var(--space-xs) 0;
  padding-left: var(--space-lg);
}

.chronicle__event-body ul { list-style: disc; }
.chronicle__event-body ol { list-style: decimal; }

.chronicle__event-body blockquote {
  margin: var(--space-sm) 0;
  padding: var(--space-xs) var(--space-md);
  border-left: 3px solid var(--color-highlight);
  background-color: var(--color-surface-alt);
  color: var(--color-text-muted);
  font-style: italic;
}

.chronicle__event-body a {
  color: var(--color-accent);
  text-decoration: underline;
}

.chronicle__event-body a:hover {
  color: var(--color-accent-hover);
}

.chronicle__event-caption {
  font-size: var(--font-size-base);
  color: var(--color-text);
  font-style: italic;
  margin: 0;
  line-height: var(--line-height-normal);
}

/* Photo layouts mirror the timeline: stories use a wrap grid, moments use
   a horizontal scroll strip so the photo-first character reads at a
   glance. */

.chronicle__event-photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-sm);
}

.chronicle__event-strip {
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  padding-bottom: var(--space-xs);
  scroll-snap-type: x proximity;
}

.chronicle__event-strip .chronicle__photo {
  flex: 0 0 200px;
  height: 200px;
  aspect-ratio: auto;
  scroll-snap-align: start;
}

.chronicle__photo {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  background-color: var(--color-surface-alt);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--color-border);
  cursor: pointer;
  padding: 0;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.chronicle__photo:hover,
.chronicle__photo:focus-visible {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}

/* ---------------- empty state ---------------- */

.chronicle__empty {
  text-align: center;
  padding: var(--space-xxl) var(--space-lg);
  color: var(--color-text-muted);
  max-width: 720px;
  margin: 0 auto;
}

.chronicle__empty-title {
  font-family: var(--font-serif);
  font-size: var(--font-size-xl);
  font-style: italic;
  margin: 0 0 var(--space-sm);
  color: var(--color-text);
}

.chronicle__empty-body {
  margin: 0 auto;
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--color-text-muted);
}

/* ---------------- responsive ---------------- */

@media (max-width: 720px) {
  .chronicle__header {
    grid-template-columns: auto 1fr auto;
    padding: var(--space-sm) var(--space-md);
  }

  .chronicle__title {
    text-align: left;
  }

  .chronicle__title-name {
    font-size: var(--font-size-lg);
  }

  .chronicle__title-subtitle {
    font-size: var(--font-size-xs);
  }

  .chronicle__layout {
    grid-template-columns: 1fr;
    gap: 0;
    padding: 0 var(--space-md) var(--space-xl);
  }

  .chronicle__rail {
    position: sticky;
    top: 0;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-xs) 0;
    margin: 0 calc(-1 * var(--space-md)) var(--space-md);
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    background-color: var(--color-bg);
    gap: var(--space-xs);
    z-index: 2;
  }

  .chronicle__rail-link {
    flex-shrink: 0;
    text-align: center;
    padding: var(--space-xs) var(--space-md);
    border-right: none;
    border-bottom: 2px solid transparent;
  }

  .chronicle__rail-link--active {
    border-right-color: transparent;
    border-bottom-color: var(--color-highlight);
  }

  .chronicle__rail-link--undated {
    margin-top: 0;
  }

  .chronicle__rail-gap {
    align-self: center;
    padding: 0 var(--space-xs);
    letter-spacing: 0.2em;
  }

  .chronicle__event {
    padding: var(--space-md);
  }

  .chronicle__event-photos {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }

  .chronicle__event-strip .chronicle__photo {
    flex-basis: 160px;
    height: 160px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chronicle-overlay {
    transition: none;
  }
  .chronicle__layout {
    scroll-behavior: auto;
  }
  .chronicle__photo,
  .chronicle__subject-chip {
    transition: none;
  }
}

/* Touch-device-only sizing. See css/layout.css for the strategy note. */
@media (hover: none) and (pointer: coarse) {
  .chronicle__close {
    width: var(--touch-target-min);
    height: var(--touch-target-min);
    touch-action: manipulation;
  }

  .chronicle__back {
    min-height: var(--touch-target-min);
    touch-action: manipulation;
  }

  .chronicle__rail-link {
    min-height: var(--touch-target-min);
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }

  .chronicle__subject-chip {
    min-height: var(--touch-target-min);
    padding: var(--space-xxs) var(--space-sm);
    touch-action: manipulation;
  }

  .chronicle__photo {
    touch-action: manipulation;
  }
}
