/* ============================================================
   Literary Timeline — "River of Time"
   Era-sectioned vertical timeline of authors across history.
   Uses global design tokens (main.css); dark-mode + RTL aware.
   ============================================================ */

.timeline-page {
    --tl-spine: var(--border-color, #e5e7eb);
    --tl-accent: var(--color-primary, #2563eb);
    --tl-tooltip-bg: #1f2632;
    --tl-tooltip-fg: #f6f6f4;
    padding-top: 80px; /* clear the fixed nav — matches other pages */
    min-height: 100vh;
    background: var(--bg-primary);
    /* Prevent hidden tooltips / edge elements from creating a horizontal
       scrollbar. `clip` (not `hidden`) avoids creating a scroll container,
       so the sticky controls bar keeps working. */
    overflow-x: clip;
}

/* Compact fixed header on tablet/mobile (~66px) — keep the hero gap balanced */
@media (max-width: 1200px) {
    .timeline-page { padding-top: 72px; }
    .timeline-hero { padding: 2rem 1.5rem 2rem; }
}
/* Desktop app embeds the page without the site nav */
body.desktop-app-mode .timeline-page { padding-top: 0; }
[data-theme="dark"] .timeline-page {
    --tl-tooltip-bg: #2b3242;
    --tl-tooltip-fg: #f3f4f6;
}

/* Per-era accent hues (light, refined literary palette) */
.era-antiquity     { --era: #b0894f; }
.era-medieval      { --era: #8a6d3b; }
.era-renaissance   { --era: #9c5f3c; }
.era-reason        { --era: #7c6aa8; }
.era-enlightenment { --era: #4f7cac; }
.era-romantic      { --era: #b0526b; }
.era-victorian     { --era: #3f8f7b; }
.era-modern        { --era: #5566c9; }
.era-undated       { --era: #8a8f99; }

/* ---------- Hero ---------- */
.timeline-hero {
    position: relative;
    padding: 4rem 1.5rem 3rem;
    text-align: center;
    overflow: hidden;
}
.timeline-hero-bg {
    position: absolute;
    inset: 0;
    margin-top: 20px;
    background: linear-gradient(135deg, #1e3a5f 0%, #2d1b69 50%, #1a1a2e 100%);
    opacity: 0.06;
    z-index: 0;
    pointer-events: none;
}
[data-theme="dark"] .timeline-hero-bg {
    opacity: 0.3;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0c0a09 100%);
}
.timeline-hero .container { position: relative; z-index: 1; }
.timeline-hero-title {
    font-size: clamp(1.75rem, 3.5vw, 2.25rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin: 0 0 0.85rem;
    color: var(--text-primary);
}
.timeline-view-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1.25rem;
    padding: 0.6rem 1.3rem;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--tl-accent) 40%, var(--border-color));
    background: color-mix(in srgb, var(--tl-accent) 10%, transparent);
    color: var(--tl-accent);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background .2s, transform .15s, box-shadow .2s;
}
.timeline-view-switch:hover {
    background: color-mix(in srgb, var(--tl-accent) 20%, transparent);
    transform: translateY(-2px);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--tl-accent) 30%, transparent);
}
.timeline-hero-subtitle {
    font-size: clamp(1rem, 2vw, 1.15rem);
    color: var(--text-secondary);
    max-width: 640px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ---------- Controls ---------- */
.timeline-controls {
    position: sticky;
    top: 64px;
    transition: top 0.35s ease;
    z-index: 40;
    padding: 0.9rem 0;
    background: color-mix(in srgb, var(--bg-primary) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border-color);
}
/* When the nav auto-hides on scroll-down, let the controls stick to the very top edge */
body:has(.main-nav.nav-hidden) .timeline-controls { top: 0; }
/* Desktop app embeds the page without the site nav — always stick to the top */
body.desktop-app-mode .timeline-controls { top: 0; }
.timeline-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.timeline-search-wrapper {
    position: relative;
    flex: 1 1 240px;
    min-width: 200px;
}
.timeline-search-icon {
    position: absolute;
    top: 50%;
    inset-inline-start: 14px;
    transform: translateY(-50%);
    color: var(--text-muted, #9ca3af);
    pointer-events: none;
}
.timeline-search-input {
    width: 100%;
    padding: 0.7rem 1rem 0.7rem 2.75rem;
    padding-inline-start: 2.75rem;
    padding-inline-end: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color .2s, box-shadow .2s;
}
.timeline-search-input:focus {
    outline: none;
    border-color: var(--tl-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--tl-accent) 18%, transparent);
}

/* Filter dropdowns */
.timeline-filter { position: relative; }
.tl-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 0.95rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .2s, background .2s;
}
.tl-filter-btn:hover { border-color: var(--tl-accent); }
.timeline-filter.has-value .tl-filter-btn {
    border-color: var(--tl-accent);
    color: var(--tl-accent);
}
.tl-filter-arrow { transition: transform .2s; opacity: .7; }
.timeline-filter.open .tl-filter-arrow { transform: rotate(180deg); }
.tl-filter-menu {
    position: absolute;
    top: calc(100% + 8px);
    inset-inline-start: 0;
    min-width: 200px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 14px 40px rgba(0,0,0,.14);
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity .18s, transform .18s, visibility .18s;
    z-index: 50;
}
.timeline-filter.open .tl-filter-menu { opacity: 1; visibility: visible; transform: translateY(0); }
/* Subtle themed scrollbar (replaces the default white bar) */
.tl-filter-menu {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--text-secondary) 40%, transparent) transparent;
}
.tl-filter-menu::-webkit-scrollbar { width: 8px; }
.tl-filter-menu::-webkit-scrollbar-track { background: transparent; }
.tl-filter-menu::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--text-secondary) 35%, transparent);
    border-radius: 999px;
}
.tl-filter-menu::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--text-secondary) 55%, transparent);
}

.tl-filter-item {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    border: none;
    background: none;
    border-radius: 9px;
    color: var(--text-primary);
    font-size: 0.9rem;
    text-align: start;
    cursor: pointer;
    transition: background .15s;
}
.tl-filter-item:hover { background: var(--bg-secondary); }
.tl-filter-item.active { background: color-mix(in srgb, var(--tl-accent) 14%, transparent); color: var(--tl-accent); font-weight: 600; }

.timeline-count {
    margin-inline-start: auto;
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* ---------- Era ribbon (overview + nav) ---------- */
.timeline-ribbon {
    display: flex;
    gap: 4px;
    margin-top: 0.9rem;
    width: 100%;
}
.tl-ribbon-seg {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0.5rem 0.35rem;
    border: none;
    border-radius: 9px;
    background: color-mix(in srgb, var(--era) 16%, var(--bg-secondary));
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background .2s, transform .15s, border-color .2s, opacity .2s;
}
.tl-ribbon-seg:hover { transform: translateY(-2px); background: color-mix(in srgb, var(--era) 30%, var(--bg-secondary)); }
.tl-ribbon-seg.active {
    border-bottom-color: var(--era);
    background: color-mix(in srgb, var(--era) 34%, var(--bg-secondary));
}
.tl-ribbon-seg.is-dim { opacity: 0.35; }
.tl-ribbon-name {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.tl-ribbon-count {
    font-size: 0.68rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--era) 60%, var(--text-secondary));
    font-variant-numeric: tabular-nums;
}

/* ---------- Styled CSS tooltip (replaces native title) ---------- */
.timeline-page [data-tooltip] { position: relative; }
.timeline-page [data-tooltip]::after,
.timeline-page [data-tooltip]::before {
    position: absolute;
    top: calc(100% + 9px);
    inset-inline-start: 50%;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-50%) translateY(-4px);
    transition: opacity .16s ease, transform .16s ease;
    z-index: 70;
}
[dir="rtl"] .timeline-page [data-tooltip]::after,
[dir="rtl"] .timeline-page [data-tooltip]::before { transform: translateX(50%) translateY(-4px); }
.timeline-page [data-tooltip]::after {
    content: attr(data-tooltip);
    background: var(--tl-tooltip-bg);
    color: var(--tl-tooltip-fg);
    padding: 7px 11px;
    border-radius: 9px;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: normal;
    line-height: 1.25;
    white-space: nowrap;
    max-width: 260px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
}
.timeline-page [data-tooltip]::before {
    content: "";
    top: calc(100% + 3px);
    border: 6px solid transparent;
    border-bottom-color: var(--tl-tooltip-bg);
}
.timeline-page [data-tooltip]:hover::after,
.timeline-page [data-tooltip]:hover::before,
.timeline-page [data-tooltip]:focus-visible::after,
.timeline-page [data-tooltip]:focus-visible::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}
[dir="rtl"] .timeline-page [data-tooltip]:hover::after,
[dir="rtl"] .timeline-page [data-tooltip]:hover::before,
[dir="rtl"] .timeline-page [data-tooltip]:focus-visible::after,
[dir="rtl"] .timeline-page [data-tooltip]:focus-visible::before { transform: translateX(50%) translateY(0); }

/* ---------- Timeline track ---------- */
.timeline-track-section { padding: 2.5rem 0 4rem; }
.timeline-track {
    position: relative;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1rem;
}
/* central spine */
.timeline-track::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    inset-inline-start: 50%;
    width: 2px;
    transform: translateX(-50%);
    background: linear-gradient(to bottom, transparent, var(--tl-spine) 4%, var(--tl-spine) 96%, transparent);
}

/* ---------- Era block ---------- */
.tl-era { position: relative; margin: 0 0 1.5rem; }
.tl-era.is-hidden { display: none; }

.tl-era-header {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin: 2.25rem 0 2rem;
    opacity: 0;
    transform: translateY(16px);
    transition: opacity .6s ease, transform .6s ease;
}
.tl-era-header.revealed { opacity: 1; transform: none; }
.tl-era-marker {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--era);
    box-shadow: 0 0 0 5px color-mix(in srgb, var(--era) 22%, transparent), 0 0 0 9px var(--bg-primary);
    margin-bottom: 0.85rem;
    z-index: 2;
}
.tl-era-title {
    font-size: clamp(1.35rem, 2.6vw, 1.9rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0;
    color: var(--text-primary);
}
.tl-era-range {
    margin: 0.3rem 0 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: color-mix(in srgb, var(--era) 55%, var(--text-secondary));
    font-variant-numeric: tabular-nums;
}

/* ---------- Author nodes (alternating) ---------- */
.tl-era-authors { position: relative; }
.tl-node {
    position: relative;
    width: 50%;
    padding: 0.55rem 2.4rem;
    box-sizing: border-box;
    cursor: pointer;
    opacity: 0;
    transform: translateY(22px);
    transition: opacity .55s ease, transform .55s ease;
}
.tl-node.revealed { opacity: 1; transform: none; }
.tl-node.is-hidden { display: none; }

/* Side A = start side, Side B = end side (logical, RTL-safe) */
.tl-node.side-a { margin-inline-end: 50%; text-align: end; }
.tl-node.side-b { margin-inline-start: 50%; text-align: start; }

/* connector dot on the spine */
.tl-node-dot {
    position: absolute;
    top: 1.5rem;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 3px solid var(--era);
    z-index: 2;
    transition: transform .2s, background .2s;
}
.tl-node.side-a .tl-node-dot { inset-inline-end: -6.5px; }
.tl-node.side-b .tl-node-dot { inset-inline-start: -6.5px; }
.tl-node:hover .tl-node-dot,
.tl-node:focus-visible .tl-node-dot { background: var(--era); transform: scale(1.25); }

/* card */
.tl-node-card {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    text-align: start;
    padding: 0.85rem 0.95rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.tl-node.side-a .tl-node-card { flex-direction: row-reverse; text-align: end; }
.tl-node:hover .tl-node-card,
.tl-node:focus-visible .tl-node-card {
    transform: translateY(-3px);
    border-color: color-mix(in srgb, var(--era) 55%, var(--border-color));
    box-shadow: 0 12px 30px rgba(0,0,0,.12);
}
.tl-node:focus-visible { outline: none; }
.tl-node:focus-visible .tl-node-card { box-shadow: 0 0 0 3px color-mix(in srgb, var(--era) 40%, transparent); }

.tl-node-portrait {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    background: color-mix(in srgb, var(--era) 18%, var(--bg-tertiary, #eee));
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--era) 30%, transparent);
}
.tl-node-portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tl-node-initials {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 700;
    color: var(--era);
}
.tl-node-body { min-width: 0; flex: 1; }
.tl-node-name {
    font-size: 1.02rem;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 0.15rem;
    color: var(--text-primary);
}
.tl-node-life {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 0.55rem;
    align-items: baseline;
    margin: 0 0 0.2rem;
}
.tl-node.side-a .tl-node-life { justify-content: flex-end; }
.tl-node-years {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--era);
    font-variant-numeric: tabular-nums;
}
.tl-node-age { font-size: 0.72rem; color: var(--text-muted); }
.tl-node-nat {
    margin: 0 0 0.35rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.tl-node-bio {
    margin: 0 0 0.5rem;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-secondary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.tl-node-books {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    background: color-mix(in srgb, var(--era) 12%, transparent);
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
}
.tl-node-books svg { color: var(--era); }

/* ---------- Empty state ---------- */
.timeline-empty {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--text-secondary);
}
.timeline-empty svg { margin-bottom: 1rem; }

/* ---------- Responsive: single-sided timeline on smaller screens ---------- */
@media (max-width: 720px) {
    .timeline-page { padding-top: 72px; }
    .timeline-hero { padding: 2rem 1rem 2rem; }
    .timeline-track::before { inset-inline-start: 22px; transform: none; }
    .tl-era-header { align-items: flex-start; text-align: start; padding-inline-start: 46px; }
    .tl-era-marker { position: absolute; inset-inline-start: 22px; top: 4px; transform: translateX(-50%); margin: 0; }
    [dir="rtl"] .tl-era-marker { transform: translateX(50%); }

    .tl-node,
    .tl-node.side-a,
    .tl-node.side-b {
        width: 100%;
        margin: 0;
        padding: 0.5rem 0 0.5rem 46px;
        padding-inline-start: 46px;
        padding-inline-end: 0;
        text-align: start;
    }
    .tl-node.side-a { text-align: start; }
    .tl-node-card,
    .tl-node.side-a .tl-node-card { flex-direction: row; text-align: start; }
    .tl-node.side-a .tl-node-life,
    .tl-node .tl-node-life { justify-content: flex-start; }
    .tl-node-dot,
    .tl-node.side-a .tl-node-dot,
    .tl-node.side-b .tl-node-dot { inset-inline-start: 16px; inset-inline-end: auto; }
}

@media (max-width: 560px) {
    .timeline-controls { top: 56px; }
    .timeline-count { order: 3; margin-inline-start: 0; width: 100%; }
    .tl-ribbon-name { font-size: 0.62rem; }
    .tl-node-portrait { width: 50px; height: 50px; }
}

/* ---------- Dark mode niceties ---------- */
[data-theme="dark"] .tl-node-card { box-shadow: 0 1px 2px rgba(0,0,0,.3); }
[data-theme="dark"] .tl-node:hover .tl-node-card,
[data-theme="dark"] .tl-node:focus-visible .tl-node-card { box-shadow: 0 12px 30px rgba(0,0,0,.5); }
[data-theme="dark"] .timeline-controls { background: color-mix(in srgb, var(--bg-primary) 82%, transparent); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .tl-node, .tl-era-header { opacity: 1 !important; transform: none !important; transition: none; }
    .tl-ribbon-seg, .tl-node-card, .tl-node-dot { transition: none; }
    html { scroll-behavior: auto; }
}
