/* Timeline island. Geometry comes from src/islands/timeline.js as unitless
   custom properties (--x, --y, --w in CSS px); this file only draws. */

.timeline {
  --tl-color: var(--accent);
  --tl-fill: var(--paper);
  --tl-rails-w: 150px;
  display: block;
}

.tl-empty {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-sans);
}

/* ---------------------------------------------------------------- toolbar */

.tl-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px 18px;
  margin-bottom: 10px;
}

.tl-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0;
  padding: 0;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  line-height: 1.5;
  list-style: none;
}

.tl-legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tl-swatch {
  position: relative;
  display: inline-block;
  flex: none;
  background: var(--tl-color);
}

.tl-nav {
  display: flex;
  flex: none;
  gap: 6px;
}

.tl-arrow {
  display: inline-flex;
  width: var(--tap);
  height: 32px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}

.tl-arrow:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.tl-arrow:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}

.tl-arrow-glyph {
  pointer-events: none;
}

/* ---------------------------------------------------------------- frame */

.tl-body {
  display: flex;
  overflow: hidden;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--paper) 0%, color-mix(in srgb, var(--bg) 65%, var(--paper)) 100%);
  box-shadow: var(--shadow);
}

.tl-rails {
  position: relative;
  flex: none;
  width: var(--tl-rails-w);
  height: calc(var(--tl-h, 400) * 1px);
  border-right: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
}

.tl-rail-label {
  position: absolute;
  top: calc(var(--y) * 1px);
  right: 10px;
  left: 12px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.2;
  text-transform: uppercase;
  transform: translateY(-50%);
}

.tl-rail-name.is-short {
  display: none;
}

.tl-scroll {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.tl-scroll:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: -3px;
}

.tl-plot {
  position: relative;
  width: calc(var(--tl-w, 1000) * 1px);
  height: calc(var(--tl-h, 400) * 1px);
}

/* ---------------------------------------------------------------- axis */

.tl-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--x) * 1px);
  width: 0;
  pointer-events: none;
}

.tl-tick::before {
  position: absolute;
  top: 28px;
  bottom: 4px;
  left: 0;
  width: 1px;
  background: color-mix(in srgb, var(--line) 55%, transparent);
  content: "";
}

.tl-tick.is-year::before {
  background: var(--line);
}

.tl-tick-label {
  position: absolute;
  top: 8px;
  left: 0;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1;
  transform: translateX(-50%);
}

.tl-rail {
  position: absolute;
  top: calc(var(--y) * 1px);
  right: 8px;
  left: 8px;
  height: 2px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 80%, transparent);
  pointer-events: none;
  transform: translateY(-1px);
}

.tl-now {
  position: absolute;
  top: 26px;
  bottom: 6px;
  left: calc(var(--x) * 1px);
  z-index: 2;
  width: 1px;
  background: color-mix(in srgb, var(--accent-2) 45%, transparent);
  pointer-events: none;
}

.tl-now-label {
  position: absolute;
  top: -18px;
  left: 50%;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--accent-2);
  font-family: var(--font-sans);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  line-height: 1;
  text-transform: uppercase;
  transform: translateX(-50%);
}

/* ---------------------------------------------------------------- relations */

.tl-links {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}

.tl-links line {
  stroke: var(--muted);
  stroke-width: 1;
  opacity: 0.22;
  transition: opacity 150ms ease, stroke-width 150ms ease;
}

.tl-links line.is-lit {
  stroke: var(--accent-ink);
  stroke-width: 1.6;
  opacity: 0.9;
}

/* ---------------------------------------------------------------- markers */

.tl-point,
.tl-bar {
  position: absolute;
  top: calc(var(--y) * 1px);
  left: calc(var(--x) * 1px);
  z-index: 4;
  padding: 0;
  border: 0;
  appearance: none;
  background: none;
  cursor: pointer;
}

.tl-point {
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
}

.tl-point::after {
  position: absolute;
  border-radius: 50%;
  box-shadow: 0 0 0 0 transparent;
  content: "";
  inset: 3px;
  transition: box-shadow 150ms ease;
}

.tl-point:hover::after {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tl-color) 18%, transparent);
}

.tl-point.is-selected::after {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tl-color) 42%, transparent);
}

.tl-point.is-selected,
.tl-bar.is-selected,
.tl-point:focus-visible,
.tl-bar:focus-visible {
  z-index: 6;
}

.tl-point:focus-visible,
.tl-bar:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 1px;
}

.tl-shape {
  position: absolute;
  top: 50%;
  left: 50%;
  background: var(--tl-color);
  transform: translate(-50%, -50%);
}

.shape-disc {
  width: 13px;
  height: 13px;
  border-radius: 50%;
}

.shape-ring {
  width: 13px;
  height: 13px;
  border: 2.5px solid var(--tl-color);
  border-radius: 50%;
  background: var(--tl-fill);
  box-sizing: border-box;
}

.shape-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.shape-square {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.shape-diamond {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  transform: translate(-50%, -50%) rotate(45deg);
}

.shape-triangle {
  width: 12px;
  height: 11px;
  clip-path: polygon(50% 0%, 100% 100%, 0% 100%);
}

.shape-star {
  width: 15px;
  height: 15px;
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.shape-rect {
  width: 12px;
  height: 8px;
  border-radius: 2px;
}

.shape-hex {
  width: 12px;
  height: 11px;
  clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.shape-bar {
  width: 22px;
  height: 6px;
  border-radius: 999px;
}

.tl-point.is-tentative .tl-shape {
  background: var(--tl-fill);
  box-shadow: inset 0 0 0 1.6px var(--tl-color);
  opacity: 0.9;
}

.tl-point.is-tentative .shape-ring {
  background: var(--tl-fill);
  box-shadow: none;
}

/* Interval bars: the button is 24px tall for the target size, the visible
   bar is the ::before inside it. */

.tl-bar {
  width: calc(var(--w) * 1px);
  height: 24px;
  margin-top: -12px;
}

.tl-bar::before {
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  height: 6px;
  border-radius: 999px;
  background: var(--tl-color);
  content: "";
  transform: translateY(-50%);
  transition: box-shadow 150ms ease;
}

.tl-bar.is-primary::before {
  height: 10px;
}

.tl-bar:hover::before {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--tl-color) 16%, transparent);
}

.tl-bar.is-selected::before {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--tl-color) 38%, transparent);
}

/* Still running: the bar fades out and a chevron points onwards. */
.tl-bar.is-open::before {
  border-radius: 999px 0 0 999px;
  mask-image: linear-gradient(90deg, #000 62%, transparent 100%);
  -webkit-mask-image: linear-gradient(90deg, #000 62%, transparent 100%);
}

.tl-bar.is-open::after {
  position: absolute;
  top: 50%;
  right: 0;
  width: 7px;
  height: 7px;
  border-top: 2px solid var(--tl-color);
  border-right: 2px solid var(--tl-color);
  content: "";
  transform: translateY(-50%) rotate(45deg);
}

.tl-bar.is-published::after {
  position: absolute;
  top: 50%;
  right: -2px;
  width: 9px;
  height: 9px;
  border: 2px solid var(--tl-color);
  border-radius: 50%;
  background: var(--paper);
  content: "";
  transform: translateY(-50%);
}

/* Secondary interval (a stay abroad, a funded stretch) drawn as a thin underline. */
.tl-sub {
  position: absolute;
  top: calc(var(--y) * 1px);
  left: calc(var(--x) * 1px);
  z-index: 3;
  width: calc(var(--w) * 1px);
  height: 2px;
  margin-top: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tl-color) 65%, var(--paper));
  pointer-events: none;
}

/* ---------------------------------------------------------------- status */

.tl-status {
  display: block;
  margin-top: 12px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--tl-color);
  border-radius: var(--radius);
  background: var(--paper);
}

.tl-status-kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  line-height: 1.35;
  text-transform: uppercase;
}

.tl-status-title {
  display: block;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.35;
}

a.tl-status-title {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a.tl-status-title:hover {
  color: var(--accent-ink);
}

a.tl-status-title:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}

.tl-status-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  line-height: 1.45;
}

/* ---------------------------------------------------------------- list view */

.tl-list {
  display: none;
  margin-top: 10px;
}

.tl-list-summary {
  padding: 8px 4px;
  color: var(--accent-ink);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 700;
}

.tl-list-summary:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: 2px;
}

.tl-list-items {
  max-height: 60vh;
  margin: 6px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.tl-list-item {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 10px;
  border: 0;
  border-left: 3px solid var(--tl-color);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--paper);
  cursor: pointer;
  text-align: left;
}

.tl-list-items li + li .tl-list-item {
  margin-top: 4px;
}

.tl-list-item.is-selected {
  background: color-mix(in srgb, var(--tl-color) 10%, var(--paper));
}

.tl-list-item:focus-visible {
  outline: 2px solid var(--accent-ink);
  outline-offset: -2px;
}

.tl-list-kicker {
  display: block;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tl-list-title {
  display: block;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 0.92rem;
  line-height: 1.35;
}

.tl-list-meta {
  display: block;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  line-height: 1.4;
}

/* ---------------------------------------------------------------- narrow */

@media (max-width: 700px) {
  .timeline {
    --tl-rails-w: 82px;
  }

  .tl-rail-label {
    right: 6px;
    left: 8px;
    font-size: 0.64rem;
    letter-spacing: 0.05em;
  }

  .tl-rail-name.is-long {
    display: none;
  }

  .tl-rail-name.is-short {
    display: inline;
  }

  .tl-legend {
    font-size: 0.72rem;
    gap: 2px 10px;
  }

  .tl-list {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tl-scroll {
    scroll-behavior: auto;
  }

  .tl-point::after,
  .tl-bar::before,
  .tl-links line {
    transition: none;
  }
}
