/* MapFun — timeline widget (src/time/timeline.js). Observatory: thin luminous track. Atlas: ink ruler. */

#timeline.timeline {
  width: min(880px, calc(100vw - 24px)); height: auto;
  display: flex; flex-direction: column; gap: 0;
  padding: 6px 10px 6px 8px;
  z-index: 13; /* above coords/attribution (12), below the info card (14) */
  --tl-ink: var(--ink); --tl-muted: var(--ink-muted); --tl-accent: var(--accent);
  transition: background-color var(--t-theme), border-color var(--t-theme), color var(--t-theme), width var(--t-med), padding var(--t-med);
}
#timeline.timeline[data-mode="now"] { width: max-content; max-width: calc(100vw - 24px); padding-right: 10px; }

/* ---- bar: modes · sentence · actions ------------------------------------ */
.tl-bar { display: flex; align-items: center; gap: 12px; min-height: 36px; }
.tl-spacer { flex: 1 1 8px; min-width: 0; }

.tl-modes { position: relative; display: inline-flex; padding: 3px; border-radius: 9px; background: color-mix(in srgb, var(--ink) 6%, transparent); gap: 2px; flex: none; }
.tl-mode {
  position: relative; z-index: 1; height: 28px; padding: 0 12px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--ink-muted);
  transition: color var(--t-fast);
}
.tl-mode:hover { color: var(--ink); }
.tl-mode[aria-selected="true"] { color: var(--ink); }
.tl-mode:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.tl-mode-glow {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: 0; border-radius: 6px; background: var(--panel-solid);
  box-shadow: 0 1px 3px rgba(0,0,0,.28), 0 0 0 1px color-mix(in srgb, var(--accent) 22%, transparent) inset;
  transition: left 260ms cubic-bezier(.2,.7,.2,1), width 260ms cubic-bezier(.2,.7,.2,1);
}
:root[data-theme="observatory"] .tl-mode[aria-selected="true"] { text-shadow: 0 0 12px color-mix(in srgb, var(--accent) 45%, transparent); }

.tl-sentence {
  display: inline-flex; align-items: baseline; gap: 7px; flex-wrap: nowrap; white-space: nowrap;
  font-family: var(--font-display); font-size: 15px; font-weight: 500; color: var(--ink); letter-spacing: -.005em; min-width: 0;
}
.tl-sent-a, .tl-sent-b { flex: none; }
:root[data-theme="atlas"] .tl-sentence { font-size: 17px; font-style: italic; font-weight: 400; }
.tl-pick {
  position: relative; display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 6px 0 9px; border-radius: 7px;
  color: var(--accent); font-weight: 600; font-style: normal; font-variant-numeric: tabular-nums;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  transition: background-color var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
.tl-pick:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.tl-pick:focus-within { box-shadow: 0 0 0 2px var(--panel-solid), 0 0 0 4px var(--accent); }
.tl-pick .chev { opacity: .7; }
.tl-pick-text { line-height: 1; }
.tl-select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; appearance: none; -webkit-appearance: none; }
.tl-select option { font-family: var(--font-ui); font-size: 13px; color: var(--ink); background: var(--panel-solid); }

.tl-actions { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.tl-actions .btn { height: 30px; font-size: 12.5px; padding: 0 10px; }
.tl-actions .btn.icon { width: 30px; }
.tl-speed {
  height: 24px; min-width: 30px; padding: 0 6px; border-radius: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--ink-muted);
  background: color-mix(in srgb, var(--ink) 6%, transparent); transition: background-color var(--t-fast), color var(--t-fast);
}
.tl-speed:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 11%, transparent); }

/* loop / once — the current mode is written on the button, not implied by a lit icon */
.tl-loop {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 7px 0 5px; border-radius: 6px;
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .01em; color: var(--ink-muted);
  background: color-mix(in srgb, var(--ink) 6%, transparent); transition: background-color var(--t-fast), color var(--t-fast);
}
.tl-loop:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 11%, transparent); }
.tl-loop[data-play="loop"] { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.tl-loop[data-play="loop"]:hover { background: color-mix(in srgb, var(--accent) 24%, transparent); }
.tl-loop svg { flex: none; }
.tl-play[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.tl-play[aria-pressed="true"]:hover { filter: brightness(1.08); }
.timeline.playing .tl-thumb-dot { animation: tl-pulse 1.2s ease-in-out infinite; }
@keyframes tl-pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 22%, transparent), 0 0 18px var(--accent); } }

/* ---- track ------------------------------------------------------------------- */
.tl-trackwrap { padding: 2px 2px 0; }
.tl-track { position: relative; height: 62px; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 8px; outline: none; }
.tl-track:focus-visible { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent) inset; }
.tl-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }

.tl-rail { stroke: color-mix(in srgb, var(--ink) 22%, transparent); stroke-width: 1.5; stroke-linecap: round; }
.tl-rail-glow { stroke: color-mix(in srgb, var(--accent) 35%, transparent); stroke-width: 3; stroke-linecap: round; filter: blur(3px); opacity: .55; }
:root[data-theme="atlas"] .tl-rail { stroke: color-mix(in srgb, var(--ink) 70%, transparent); stroke-width: 1; }
:root[data-theme="atlas"] .tl-rail-glow { display: none; }

.tl-snap { stroke: color-mix(in srgb, var(--accent) 55%, transparent); stroke-width: 1; opacity: .8; }
:root[data-theme="atlas"] .tl-snap { stroke: color-mix(in srgb, var(--ink) 60%, transparent); stroke-width: 1; opacity: .9; }
.tl-tick.major line { stroke: color-mix(in srgb, var(--ink) 55%, transparent); stroke-width: 1; }
:root[data-theme="atlas"] .tl-tick.major line { stroke: var(--ink); }
.tl-tick text { font-family: var(--font-mono); font-size: 10.5px; fill: var(--ink-faint); letter-spacing: .02em; }
:root[data-theme="atlas"] .tl-tick text { font-family: var(--font-ui); font-size: 12px; fill: var(--ink-muted); font-variant-numeric: oldstyle-nums; letter-spacing: 0; }

.tl-pin { stroke: color-mix(in srgb, var(--ink) 34%, transparent); stroke-width: 1; }
.tl-pin.treaty { stroke: color-mix(in srgb, var(--accent) 70%, transparent); }
.tl-nodata { fill: repeating-linear-gradient(45deg, transparent 0 3px, currentColor 3px 4px); fill: color-mix(in srgb, var(--ink) 5%, transparent); }

.tl-band rect { opacity: .78; transition: opacity var(--t-fast); }
.tl-band.dim rect { opacity: .28; }
:root[data-theme="observatory"] .tl-band rect { opacity: .62; }
:root[data-theme="observatory"] .tl-band.dim rect { opacity: .22; }
.tl-band-label { font-family: var(--font-ui); font-size: 9.5px; fill: var(--ink-faint); letter-spacing: .06em; text-transform: uppercase; }
.tl-band-label.abbr { letter-spacing: 0; }
:root[data-theme="atlas"] .tl-band-label { font-size: 10.5px; letter-spacing: .03em; text-transform: none; font-style: italic; fill: var(--ink-muted); }
.tl-band:hover rect { opacity: 1; }

/* thumb: glowing dot (observatory) / ink pointer (atlas) */
.tl-thumb { position: absolute; top: 50%; left: 0; width: 0; height: 0; pointer-events: none; transition: left 90ms cubic-bezier(.2,.7,.2,1); }
.timeline.scrubbing .tl-thumb { transition: none; }
.tl-thumb-dot {
  position: absolute; left: -7px; top: -7px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent), 0 0 14px var(--accent);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.tl-track:hover .tl-thumb-dot, .timeline.scrubbing .tl-thumb-dot { transform: scale(1.18); }
:root[data-theme="atlas"] .tl-thumb-dot {
  width: 12px; height: 12px; left: -6px; top: -6px; border-radius: 2px; transform: rotate(45deg); background: var(--accent);
  box-shadow: 0 0 0 2px var(--panel-solid), 0 0 0 3px var(--accent);
}
:root[data-theme="atlas"] .tl-track:hover .tl-thumb-dot, :root[data-theme="atlas"] .timeline.scrubbing .tl-thumb-dot { transform: rotate(45deg) scale(1.15); }
.timeline.busy .tl-thumb-dot { animation: tl-busy 900ms ease-in-out infinite; }
@keyframes tl-busy { 50% { opacity: .45; } }

.tl-hover {
  position: absolute; top: 2px; left: 0; padding: 3px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; pointer-events: none;
  color: var(--ink); background: var(--panel-solid); border: 1px solid var(--panel-border); box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums; z-index: 2;
}
.tl-hover[hidden] { display: none; }
:root[data-theme="atlas"] .tl-hover { font-style: italic; }

/* mode change: the tick layer / bands slide and fade (~300 ms) */
.tl-layer, .tl-bands { transform-box: view-box; }
.tl-layer.enter, .tl-bands.enter { animation: tl-layer-in 300ms cubic-bezier(.2,.7,.2,1) both; }
.tl-layer.exit, .tl-bands.exit { animation: tl-layer-out 300ms cubic-bezier(.2,.7,.2,1) both; pointer-events: none; }
@keyframes tl-layer-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes tl-layer-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(-7px); } }

/* the expanded instrument is wide: quieten the bottom-corner chrome it would overlap on narrower windows */
@media (max-width: 1360px) {
  :root.timeline-open #coords, :root.timeline-open #attribution { opacity: 0; pointer-events: none; transition: opacity var(--t-fast); }
}

/* The instrument owns the bottom of the screen, so everything else on that edge stacks above it. This used to be
   scoped to :root.timeline-open, which meant that in the default "Now" mode — the state every visitor lands in —
   the info-card peek, the skin strip and the timeline were all anchored at bottom: 8px and overlapped. */
@media (max-width: 720px) {
  #infocard,
  #infocard.collapsed { bottom: calc(var(--tl-h, 70px) + var(--sb-h, 0px) + 26px + var(--safe-b)); }
  #infocard { max-height: min(60dvh, calc(100dvh - var(--topbar-h) - var(--tl-h, 70px) - var(--sb-h, 0px) - 44px)); }
}

/* ---- compact bar on phones ------------------------------------------------------- */
@media (max-width: 720px) {
  #timeline.timeline { left: 8px; right: 8px; width: auto; transform: none; bottom: calc(8px + var(--safe-b)); padding: 6px 8px 4px; }
  #timeline.timeline[data-mode="now"] { width: max-content; left: 50%; right: auto; transform: translateX(-50%); }
  .tl-bar { flex-wrap: wrap; gap: 6px 8px; }
  .tl-mode { padding: 0 10px; font-size: 12.5px; height: 26px; }
  .tl-sentence { font-size: 14px; flex: 1 1 100%; order: 3; }
  :root[data-theme="atlas"] .tl-sentence { font-size: 15.5px; }
  .tl-spacer { display: none; }
  .tl-actions { margin-left: auto; }
  .tl-actions .btn span { display: none; }
  .tl-loop-label { display: none; }
  .tl-loop { padding: 0 5px; }
  .tl-actions .btn { padding: 0 8px; }
  .tl-track { height: 50px; }
  .tl-tick text { font-size: 9.5px; }
  .tl-band-label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .tl-thumb, .tl-mode-glow, .tl-loop, .tl-speed { transition: none; }
  .tl-layer.enter, .tl-layer.exit, .tl-bands.enter, .tl-bands.exit { animation: none; }
  .timeline.playing .tl-thumb-dot, .timeline.busy .tl-thumb-dot { animation: none; }
}

/* multi-line event tooltip (history event pins) */
.tl-hover.event { white-space: pre-line; text-align: left; max-width: 280px; line-height: 1.35; padding: 5px 8px; }
