/* ============================================================
   Timeline History — three-pane responsive layout
   Year strip on top, image stage left, event sidebar right.
   Design tokens follow project frontend-design system.
   ============================================================ */

:root {
    --th-primary:        #1a5b8a;
    --th-primary-600:    #14486e;
    --th-primary-700:    #0f3a59;
    --th-primary-300:    #2e8acb;
    --th-primary-100:    #e6eef5;
    --th-primary-050:    #f1f6fb;
    --th-surface:        #ffffff;
    --th-bg:             #f4f7fa;
    --th-text:           #1a2733;
    --th-text-muted:     #5a6b7a;
    --th-text-subtle:    #8595a3;
    --th-border:         rgba(15, 60, 91, 0.08);
    --th-border-strong:  rgba(15, 60, 91, 0.16);

    --th-radius-sm:  4px;
    --th-radius-md:  8px;
    --th-radius-lg:  12px;
    --th-radius-pill: 9999px;

    --th-shadow-xs: 0 1px 2px rgba(15, 60, 91, 0.06);
    --th-shadow-sm: 0 1px 3px rgba(15, 60, 91, 0.10), 0 1px 2px rgba(15, 60, 91, 0.06);
    --th-shadow-md: 0 4px 12px rgba(15, 60, 91, 0.12), 0 2px 4px rgba(15, 60, 91, 0.06);
    --th-shadow-lg: 0 10px 30px rgba(15, 60, 91, 0.18);

    --th-ease:        cubic-bezier(0.4, 0.0, 0.2, 1);
    --th-duration:    180ms;
}

/* ----- Page shell ------------------------------------------- */
.th-page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 16px 64px;
    color: var(--th-text);
}

/* ----- Header ----------------------------------------------- */
.th-header {
    margin-bottom: 32px;
    text-align: start;
}
.th-header h1 {
    margin: 0 0 12px;
    font-size: clamp(1.75rem, 1.2rem + 1.6vw, 2.5rem);
    font-weight: 800;
    line-height: 1.2;
    color: var(--th-primary-700);
    letter-spacing: -0.01em;
    position: relative;
    padding-bottom: 16px;
}
.th-header h1::after {
    content: "";
    position: absolute;
    bottom: 0;
    inset-inline-start: 0;
    width: 56px;
    height: 4px;
    border-radius: var(--th-radius-pill);
    background: linear-gradient(90deg, var(--th-primary), var(--th-primary-300));
}
.th-intro {
    margin: 0;
    max-width: 70ch;
    color: var(--th-text-muted);
    font-size: 1.0625rem;
    line-height: 1.7;
}

.th-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--th-text-subtle);
    font-size: 1rem;
}

/* ----- Year strip ------------------------------------------- */
.th-years {
    position: relative;
    display: flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, var(--th-primary) 0%, var(--th-primary-600) 100%);
    padding: 8px;
    border-radius: var(--th-radius-md);
    margin-bottom: 24px;
    box-shadow: var(--th-shadow-sm);
}
.th-years-track {
    flex: 1 1 auto;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    scroll-behavior: smooth;
    padding: 2px;
}
.th-years-track::-webkit-scrollbar { display: none; }

.th-year {
    flex: 0 0 auto;
    scroll-snap-align: start;
    min-width: 96px;
    padding: 10px 20px;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    border: none;
    border-radius: var(--th-radius-sm);
    cursor: pointer;
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    transition: background var(--th-duration) var(--th-ease),
                color var(--th-duration) var(--th-ease),
                transform var(--th-duration) var(--th-ease);
    content-visibility: auto;
    contain-intrinsic-size: 96px 40px;
}
.th-year:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}
.th-year:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
.th-year.is-active {
    background: var(--th-surface);
    color: var(--th-primary-700);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.th-years-arrow {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
    border-radius: var(--th-radius-pill);
    transition: background var(--th-duration) var(--th-ease),
                transform var(--th-duration) var(--th-ease);
}
.th-years-arrow:hover {
    background: rgba(255, 255, 255, 0.22);
    transform: scale(1.05);
}
.th-years-arrow:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ----- Body grid -------------------------------------------- */
.th-body {
    display: grid;
    grid-template-columns: 320px 1fr;
    grid-template-areas: "events stage";
    gap: 24px;
    align-items: stretch;
}
.th-stage  { grid-area: stage; }
.th-events { grid-area: events; }

/* ----- Image stage ------------------------------------------ */
.th-stage {
    display: flex;
    flex-direction: column;
    background: var(--th-surface);
    border: 1px solid var(--th-border);
    border-radius: var(--th-radius-lg);
    overflow: hidden;
    box-shadow: var(--th-shadow-sm);
}
.th-stage-frame {
    position: relative;
    aspect-ratio: 16 / 10;
    max-height: 520px;
    background: #0f1a24;
    overflow: hidden;
    touch-action: pan-y;
}
.th-stage-frame--empty {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 16 / 10;
    background: var(--th-primary-050);
}
.th-stage-frame--empty .th-empty { color: var(--th-text-muted); padding: 0; }

.th-stage-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transition: opacity var(--th-duration) var(--th-ease);
}

.th-stage-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.94);
    color: var(--th-primary-700);
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    border-radius: var(--th-radius-pill);
    z-index: 2;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    transition: background var(--th-duration) var(--th-ease),
                transform var(--th-duration) var(--th-ease),
                box-shadow var(--th-duration) var(--th-ease);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.th-stage-arrow:hover {
    background: #fff;
    transform: translateY(-50%) scale(1.06);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.30);
}
.th-stage-arrow:focus-visible {
    outline: 2px solid var(--th-primary);
    outline-offset: 2px;
}
.th-stage-arrow:active { transform: translateY(-50%) scale(0.98); }
.th-stage-arrow--prev { inset-inline-start: 12px; }
.th-stage-arrow--next { inset-inline-end:   12px; }

.th-stage-counter {
    position: absolute;
    top: 12px;
    inset-inline-end: 12px;
    color: #fff;
    background: rgba(15, 23, 32, 0.65);
    padding: 6px 12px;
    border-radius: var(--th-radius-pill);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 2;
}

.th-stage-caption {
    background: linear-gradient(180deg, #1d2a37 0%, #0f1a24 100%);
    color: #fff;
    padding: 20px 24px 22px;
}
.th-stage-title {
    margin: 0 0 8px;
    font-size: 1.375rem;
    font-weight: 700;
    line-height: 1.3;
    color: #fff;
}
.th-stage-desc {
    margin: 0;
    font-size: 0.9375rem;
    line-height: 1.65;
    color: rgba(255, 255, 255, 0.82);
}

/* ----- Events sidebar --------------------------------------- */
.th-events {
    background: var(--th-primary-050);
    border: 1px solid var(--th-border);
    border-radius: var(--th-radius-lg);
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-height: 0;
    box-shadow: var(--th-shadow-sm);
}
.th-events-list {
    flex: 1 1 0;
    min-height: 0;
    width: 100%;
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.th-events-list::-webkit-scrollbar { display: none; width: 0; height: 0; }

.th-event {
    position: relative;
    width: 100%;
    padding: 12px 16px;
    background: var(--th-surface);
    color: var(--th-text);
    border: 1px solid var(--th-border);
    border-radius: var(--th-radius-md);
    cursor: pointer;
    text-align: start;
    min-height: 44px;
    content-visibility: auto;
    contain-intrinsic-size: 280px 56px;
    font: inherit;
    font-size: 0.9375rem;
    font-weight: 500;
    line-height: 1.45;
    transition: background var(--th-duration) var(--th-ease),
                color var(--th-duration) var(--th-ease),
                border-color var(--th-duration) var(--th-ease),
                transform var(--th-duration) var(--th-ease),
                box-shadow var(--th-duration) var(--th-ease);
    box-shadow: var(--th-shadow-xs);
}
.th-event:hover {
    background: var(--th-primary-100);
    border-color: var(--th-primary-300);
    transform: translateY(-1px);
    box-shadow: var(--th-shadow-sm);
}
.th-event:focus-visible {
    outline: 2px solid var(--th-primary);
    outline-offset: 2px;
}
.th-event.is-active {
    background: linear-gradient(135deg, var(--th-primary) 0%, var(--th-primary-600) 100%);
    border-color: var(--th-primary-600);
    color: #fff;
    font-weight: 600;
    box-shadow: var(--th-shadow-md);
    padding-inline-start: 20px;
}
.th-event.is-active::before {
    content: "";
    position: absolute;
    inset-block: 10px;
    inset-inline-start: 6px;
    width: 3px;
    border-radius: var(--th-radius-pill);
    background: #fff;
}

.th-events-arrow {
    flex: 0 0 auto;
    width: 100%;
    height: 28px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    margin: 0;
    font-size: 1.125rem;
    line-height: 1;
    color: var(--th-primary);
    border-radius: var(--th-radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--th-duration) var(--th-ease),
                color var(--th-duration) var(--th-ease),
                transform var(--th-duration) var(--th-ease);
}
.th-events-arrow--prev,
.th-events-arrow--next {
    /* In vertical desktop layout, rotate chevrons so they point up/down. */
    transform: rotate(90deg);
}
.th-events-arrow:hover {
    background: transparent;
    color: var(--th-primary-700);
}
.th-events-arrow:focus-visible {
    outline: 2px solid var(--th-primary);
    outline-offset: 2px;
}

/* ----- Tablet ----------------------------------------------- */
@media (max-width: 1023px) {
    .th-body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "stage"
            "events";
        align-items: start;
        gap: 16px;
    }
    .th-events {
        max-height: none;
        height: auto;
        padding: 10px;
        flex-direction: row;
        align-items: stretch;
        gap: 8px;
    }
    .th-events-list {
        flex: 1 1 0;
        min-width: 0;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        gap: 8px;
        min-height: 0;
        padding-bottom: 6px;
        /* Visible thin scrollbar — discoverability in horizontal mode */
        scrollbar-width: thin;
        scrollbar-color: rgba(26, 91, 138, 0.45) rgba(26, 91, 138, 0.10);
    }
    .th-events-list::-webkit-scrollbar {
        display: block;
        height: 6px;
        width: auto;
    }
    .th-events-list::-webkit-scrollbar-track {
        background: rgba(26, 91, 138, 0.10);
        border-radius: var(--th-radius-pill);
    }
    .th-events-list::-webkit-scrollbar-thumb {
        background: rgba(26, 91, 138, 0.45);
        border-radius: var(--th-radius-pill);
    }
    .th-events-list::-webkit-scrollbar-thumb:hover {
        background: rgba(26, 91, 138, 0.7);
    }
    .th-event {
        width: auto;
        flex: 0 0 auto;
        scroll-snap-align: start;
        min-width: 200px;
        max-width: 260px;
    }
    .th-event.is-active::before {
        inset-block: auto;
        inset-inline: 10px;
        bottom: 4px;
        height: 3px;
        width: auto;
    }
    .th-event.is-active { padding-inline-start: 16px; }

    /* Side arrows in horizontal layout — visible and prominent */
    .th-events-arrow {
        display: inline-flex;
        flex: 0 0 36px;
        width: 36px;
        height: auto;
        min-height: 56px;
        align-self: stretch;
        background: var(--th-primary-100);
        color: var(--th-primary-700);
        border-radius: var(--th-radius-md);
        font-size: 1.5rem;
        font-weight: 700;
        transform: none;    /* chevrons naturally point left/right here */
    }
    .th-events-arrow:hover {
        background: var(--th-primary);
        color: #fff;
        transform: none;
    }
}

/* ----- Mobile ----------------------------------------------- */
@media (max-width: 767px) {
    .th-page { padding: 16px 12px 32px; }
    .th-header { margin-bottom: 16px; }
    .th-header h1 { padding-bottom: 10px; }
    .th-intro { font-size: 0.9375rem; }
    .th-years { padding: 6px; gap: 2px; margin-bottom: 16px; }
    .th-year {
        min-width: 64px;
        padding: 8px 12px;
        font-size: 0.875rem;
    }
    .th-years-arrow { width: 30px; height: 30px; font-size: 1rem; }
    .th-stage-frame {
        aspect-ratio: 4 / 3;
        min-height: 240px;
    }
    .th-stage-arrow { width: 36px; height: 36px; font-size: 1.15rem; }
    .th-stage-arrow--prev { inset-inline-start: 8px; }
    .th-stage-arrow--next { inset-inline-end:   8px; }
    .th-stage-caption { padding: 14px 16px 16px; }
    .th-stage-title { font-size: 1.0625rem; }
    .th-stage-desc  { font-size: 0.875rem; line-height: 1.55; }
    .th-stage-counter { top: 8px; inset-inline-end: 8px; padding: 4px 10px; font-size: 0.75rem; }

    .th-events { padding: 8px; gap: 6px; }
    .th-events-arrow {
        flex: 0 0 32px;
        width: 32px;
        min-height: 52px;
        font-size: 1.25rem;
    }
    /* Card width = viewport - page padding(12+12) - events padding(8+8)
       - arrows(32+32) - flex gaps(6+6) = 100vw - 116px.
       Use vw math because % min/max-width on a flex child does NOT resolve
       reliably when the flex parent uses `flex: 1 1 0` (indefinite main-axis). */
    .th-event {
        flex: 0 0 calc(100vw - 116px);
        width: calc(100vw - 116px);
        min-width: calc(100vw - 116px);
        max-width: calc(100vw - 116px);
        height: 64px;
        min-height: 64px;
        padding: 10px 16px;
        font-size: 0.9375rem;
        line-height: 1.35;
        text-align: center;
        display: -webkit-box;
        -webkit-box-pack: center;
        -webkit-box-align: center;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        overflow: hidden;
        word-break: break-word;
    }
    .th-event.is-active {
        padding-inline-start: 16px;
    }
}

/* ----- Extra-small (≤ 360px) -------------------------------- */
@media (max-width: 360px) {
    .th-page { padding: 12px 8px 24px; }
    .th-years { padding: 4px; }
    .th-year { min-width: 56px; padding: 6px 10px; font-size: 0.8125rem; }
    .th-years-arrow { width: 26px; height: 26px; }
    .th-stage-frame { aspect-ratio: 1 / 1; min-height: 220px; }
    .th-events-arrow { flex: 0 0 28px; width: 28px; min-height: 48px; font-size: 1.125rem; }
    /* XS: page padding 8+8, events padding 8+8, arrows 28+28, gaps 6+6 = 100px */
    .th-event {
        flex: 0 0 calc(100vw - 100px);
        width: calc(100vw - 100px);
        min-width: calc(100vw - 100px);
        max-width: calc(100vw - 100px);
    }
}

/* ----- Reduced motion --------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
