/* ============================================================================
   WorldTrace project page stylesheet
   - Adapted from the SIL/MOTIVE template (gitlab-master.nvidia.com/sil/motive)
     but rewritten as a single self-contained file with a mobile-first reset
     and BEM-ish class names. No external CSS deps; system fonts only.
   - Colour tokens are NVIDIA SIL convention:
       --green        #76B900   NVIDIA Green (primary accent, "ours")
       --amber        #B8600A   "ours" amber, shared with the figures' .ours rows
       --red          #B91C1C   reserved for divergence / warning markers
       --gray-1 .. -5            neutral text + chrome
   - The figure HTMLs at figures/<name>/<name>.html ship with their own scoped
     CSS; iframes give us perfect isolation without inlining or rewrites.
   ============================================================================ */

:root {
    --green: #76B900;
    --green-tint: rgba(118, 185, 0, 0.10);
    --green-bg-from: #f0fff0;
    --green-bg-to:   #e8f8e8;
    --amber: #B8600A;
    --red:   #B91C1C;
    --gray-0: #ffffff;
    --gray-1: #f8f8f8;
    --gray-2: #eeeeee;
    --gray-3: #cbd5e0;
    --gray-4: #555555;
    --gray-5: #222222;

    --max-w: 1100px;
    --max-w-prose: 900px;
    --radius: 10px;
    --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-fig:  0 4px 12px rgba(0, 0, 0, 0.10);

    --font-body: "Helvetica Neue", Helvetica, Arial, sans-serif;
    --font-serif: "Times New Roman", Times, "Liberation Serif", "DejaVu Serif", serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New", monospace;
}

/* Reset (light touch) */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--font-body);
    font-weight: 300;
    font-size: 18px;
    line-height: 1.55;
    color: var(--gray-5);
    background: var(--gray-1);
}
b, strong { font-weight: 700; }
em, i    { font-style: italic; }
a {
    color: #1a73e8;
    text-decoration: none;
}
a:hover, a:focus-visible { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }
hr { border: 0; height: 1.5px; margin: 0; background-image: linear-gradient(to right, rgba(0,0,0,0), rgba(0,0,0,0.5), rgba(0,0,0,0)); }

/* Skip link for keyboard users */
.skiplink {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
    background: var(--gray-5);
    color: var(--gray-0);
    padding: 6px 12px;
    border-radius: 4px;
    z-index: 1000;
}
.skiplink:focus {
    left: 12px;
    top: 12px;
    width: auto;
    height: auto;
    outline: 2px solid var(--green);
    outline-offset: 2px;
}
.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0);
    white-space: nowrap; border: 0;
}

/* Layout containers */
main {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 16px;
    background: var(--gray-0);
}

/* Top nav */
.topnav {
    background: var(--gray-2);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
}
.topnav a {
    color: #000;
    text-decoration: none;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
}
.topnav a:hover, .topnav a:focus-visible {
    background: rgba(0, 0, 0, 0.06);
    text-decoration: none;
}
.topnav-logo {
    width: 110px;
    height: auto;
}
.topnav-lab {
    margin-right: auto;
    font-weight: 600;
}
.topnav-sections {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}
.topnav-sections a { font-size: 14px; }

/* Hero (title + authors + resource buttons) */
.hero {
    text-align: center;
    padding: 28px 0 8px;
}
/* "WorldTrace: Addressable Memory for Video World Models" on a single line.
   Both halves render at the same size (~28px desktop). The method-name span
   is the green eyebrow that reads as a label preceding the descriptive title. */
.hero-title {
    font-size: clamp(20px, 2.6vw, 30px);
    font-weight: 700;
    line-height: 1.2;
    margin: 0 0 22px;
    color: var(--gray-5);
}
.hero-title .method-name {
    margin-right: 6px;
}
.method-name {
    font-weight: 700;
    color: var(--green);
}

/* Authors row: targets a single barely-fitting line at desktop widths
   (~1100px). With 8 names and superscript markers the natural width is
   ~960-1020 px at 16px / 14px-gap, so we use that combination as the
   default and let it wrap on narrower viewports. */
.authors, .affiliations {
    list-style: none;
    padding: 0;
    margin: 0 auto 8px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px 14px;
    max-width: 100%;
}
.authors li, .affiliations li {
    font-size: 16px;
    white-space: nowrap;
}
.authors a, .affiliations a {
    color: var(--gray-5);
    text-decoration: underline;
    text-decoration-color: rgba(0,0,0,0.12);
    text-underline-offset: 3px;
}
.authors a:hover, .authors a:focus-visible,
.affiliations a:hover, .affiliations a:focus-visible {
    color: var(--green);
    text-decoration-color: var(--green);
}
.affiliations { margin-top: 4px; gap: 4px 22px; font-size: 16px; color: var(--gray-4); }
.authors sup, .affiliations sup { font-size: 0.8em; }

/* Resource buttons */
.resource-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 24px 0 8px;
}
.resource-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #777;
    color: #fff;
    padding: 10px 18px;
    border-radius: 22px;
    text-decoration: none;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    transition: background-color 0.15s ease;
}
.resource-button:hover, .resource-button:focus-visible {
    background: #555;
    text-decoration: none;
    color: #fff;
}
.resource-button img { width: 18px; height: 18px; }
.resource-button.is-todo {
    background: #aaa;
    cursor: default;
    opacity: 0.85;
}
.resource-button small { font-size: 11px; font-weight: 400; opacity: 0.85; }

/* TL;DR callout */
.tldr {
    max-width: var(--max-w-prose);
    margin: 28px auto;
    padding: 18px 22px;
    background: linear-gradient(135deg, var(--green-bg-from) 0%, var(--green-bg-to) 100%);
    border: 2px solid var(--green);
    border-radius: var(--radius);
}
.tldr p {
    margin: 0;
    font-size: 16px;
    line-height: 1.55;
    font-style: italic;
}

/* 1-min video block */
.video-block { margin: 28px auto 36px; max-width: var(--max-w-prose); }
.video-wrap {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
    border-radius: var(--radius);
    box-shadow: var(--shadow-fig);
    background: #000;
}
.video-wrap iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}
.video-caption {
    font-size: 13px;
    color: #777;
    text-align: center;
    margin: 8px 0 0;
}

/* Prose sections */
.prose {
    max-width: var(--max-w);
    margin: 24px auto;
    padding: 0;
}
.prose > h2 {
    font-size: 26px;
    font-weight: 700;
    margin: 36px 0 14px;
    color: var(--gray-5);
}
.prose > h3 {
    font-size: 20px;
    font-weight: 700;
    margin: 22px 0 10px;
    color: var(--gray-5);
}
.prose p, .prose ul, .prose ol {
    margin: 0 0 14px;
    font-size: 18px;
    line-height: 1.6;
    text-align: left;
}
.prose ul, .prose ol { padding-left: 22px; }
.prose ul li, .prose ol li { margin-bottom: 6px; }

/* Two-column / three-column card grids */
.two-col, .three-col {
    display: grid;
    gap: 20px;
    margin: 16px 0;
}
.two-col   { grid-template-columns: 1fr 1fr; }
.three-col { grid-template-columns: 1fr 1fr 1fr; }
.card {
    background: var(--gray-0);
    border: 2px solid var(--gray-2);
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: var(--shadow-card);
}
.card h3 {
    margin: 0 0 10px;
    font-size: 18px;
    color: var(--green);
    text-align: center;
}
.card p, .card ul {
    font-size: 15px;
    line-height: 1.55;
    text-align: left;
}
.card ul { padding-left: 18px; margin: 0; }
.card ul li { margin-bottom: 8px; }

/* Poster-derived callouts */
.poster-panel {
    max-width: var(--max-w);
    margin: 28px auto;
    padding: 0;
}
.poster-panel h2 {
    margin: 0 0 14px;
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-5);
}
.motivation-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    align-items: stretch;
}
.poster-card,
.research-question,
.formula-card,
.mini-card {
    border-radius: 12px;
    box-shadow: var(--shadow-card);
}
.poster-card {
    background: var(--gray-0);
    border: 2px solid var(--gray-2);
    padding: 20px 22px;
}
.poster-card-soft {
    background: linear-gradient(135deg, var(--green-bg-from) 0%, var(--green-bg-to) 100%);
    border-color: var(--green);
}
.poster-card p,
.research-question p,
.mini-card p {
    margin: 0;
    text-align: left;
}
.research-question {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--green);
    color: #fff;
    padding: 24px;
    text-align: center;
}
.research-question p {
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.45;
    text-align: center;
}
.formula-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    align-items: stretch;
    margin: 12px 0 24px;
    padding: 14px;
    background: #f8fafc;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    box-shadow: var(--shadow-card);
}
.formula-card:first-child {
    grid-column: 1 / -1;
    max-width: 620px;
    justify-self: center;
    width: 100%;
}
.formula-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--gray-0);
    border: 1px solid #e2e8f0;
    padding: 16px;
    box-shadow: none;
}
.formula-card:not(:first-child) {
    display: grid;
    grid-template-rows: auto 104px 1fr;
}
.formula-card h3 {
    margin: 0 0 10px;
    font-size: 16px;
    color: var(--gray-5);
    text-align: left;
}
.formula-card p {
    margin: 0 0 8px;
    font-size: 14px;
    line-height: 1.5;
    text-align: left;
}
.formula-card .formula-note {
    color: var(--gray-4);
    margin-bottom: 0;
}
.math-block {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    overflow-x: auto;
    margin: 8px 0 10px;
    padding: 8px 10px;
    min-height: 66px;
    background: var(--gray-0);
    border: 1px solid var(--gray-2);
    border-radius: 8px;
}
.math-block mjx-container {
    max-width: 100%;
    margin: 0 !important;
}
.benchmark-axes {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin: 16px 0 20px;
}
.mini-card {
    background: var(--gray-0);
    border: 1px solid var(--gray-2);
    padding: 14px 16px;
}
.mini-card h4 {
    margin: 0 0 6px;
    color: var(--green);
    font-size: 15px;
    line-height: 1.3;
}
.mini-card p {
    font-size: 14px;
    line-height: 1.45;
}
.loopmem-benchmark-img {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    border-radius: 10px;
    box-shadow: var(--shadow-fig);
}

/* Result pill */
.result-pill {
    display: inline-block;
    background: var(--green);
    color: #fff;
    padding: 2px 10px;
    border-radius: 14px;
    font-weight: 700;
    font-size: 14px;
    line-height: 1.6;
}

/* Figure blocks. Tighter than the prose-section default so the figure
   sits close to its heading + lede sentence (no large gaps above/below). */
.figure-block { margin: 28px 0 24px; }
.figure-block > h2 {
    font-size: 24px;
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--gray-5);
}
.figure-block > .figure-lede {
    margin: 0 0 14px;
    font-size: 17px;
    line-height: 1.55;
}
.figure-block > figure { margin: 0; }
figure { margin: 18px 0; padding: 0; }
figcaption {
    font-size: 14px;
    color: var(--gray-4);
    line-height: 1.5;
    text-align: center;
    margin: 8px 12px 0;
    font-style: italic;
}
.figure-iframe {
    width: 100%;
    border: 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: var(--shadow-fig);
    display: block;
}
.pac-svg {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    border-radius: 6px;
    background: #fff;
    box-shadow: var(--shadow-fig);
}

/* Result sections and videos */
.result-part {
    margin: 26px 0 34px;
    padding: 22px;
    border: 1px solid var(--gray-2);
    border-radius: 14px;
    background: #fcfcfc;
    box-shadow: var(--shadow-card);
}
.result-part > h3 {
    margin-top: 0;
    padding-bottom: 8px;
    border-bottom: 3px solid var(--green);
}
.result-part > h4 {
    margin: 22px 0 10px;
    font-size: 17px;
    line-height: 1.35;
    color: var(--gray-5);
}
.video-grid,
.video-pair-grid,
.video-triplet-grid {
    display: grid;
    gap: 16px;
    margin: 14px 0 26px;
}
.video-grid.four-col {
    grid-template-columns: repeat(4, 1fr);
}
.video-pair-grid {
    grid-template-columns: repeat(2, 1fr);
}
.video-triplet-grid {
    grid-template-columns: repeat(3, 1fr);
}
.video-sync-control {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    margin-top: 4px;
    background: var(--green-tint);
    border: 1px solid rgba(118, 185, 0, 0.35);
    border-radius: 10px;
}
.video-sync-control p {
    margin: 0;
    color: var(--gray-5);
    font-size: 13px;
    line-height: 1.4;
    text-align: left;
}
.video-sync-buttons {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
}
.video-sync-button {
    border: 0;
    border-radius: 999px;
    padding: 7px 12px;
    background: var(--green);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
}
.video-sync-button.secondary {
    background: #64748b;
}
.video-sync-button:hover,
.video-sync-button:focus-visible {
    filter: brightness(0.92);
    outline: 2px solid rgba(118, 185, 0, 0.35);
    outline-offset: 2px;
}
.video-card {
    background: var(--gray-0);
    border: 1px solid var(--gray-2);
    border-radius: 10px;
    padding: 10px;
    box-shadow: var(--shadow-card);
}
.video-card h4,
.video-card h5 {
    margin: 0 0 8px;
    font-size: 14px;
    line-height: 1.3;
    color: var(--gray-5);
    text-align: center;
    font-weight: 700;
}
.video-card video,
.video-card img {
    display: block;
    width: 100%;
    border-radius: 8px;
}
.video-card video {
    background: #000;
}
.video-card img {
    background: var(--gray-1);
}
.video-shell {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}
.video-shell video {
    border-radius: 0;
}
.route-card .video-shell {
    aspect-ratio: 640 / 352;
    background: #fff;
}
.route-card .video-shell video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
}
.recall-video-panel {
    margin: 24px 0 30px;
    padding: 20px;
    background: linear-gradient(135deg, rgba(118, 185, 0, 0.08), rgba(118, 185, 0, 0.02));
    border: 1px solid rgba(118, 185, 0, 0.28);
    border-radius: 16px;
    box-shadow: var(--shadow-card);
}
.recall-video-heading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    margin: 0 0 18px;
    text-align: center;
}
.recall-video-heading > h4 {
    margin: 0;
    font-size: 19px;
    line-height: 1.35;
    color: var(--gray-5);
}
.recall-demo-card {
    width: min(300px, 100%);
    margin: 0;
}
.recall-comparison-grid {
    margin-bottom: 0;
}
.video-poster-button {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    padding: 0;
    background-color: #000;
    background-position: center;
    background-size: cover;
    cursor: pointer;
}
.video-poster-image {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 0;
}
.route-card .video-poster-image {
    object-fit: contain;
    background: #fff;
}
.video-poster-button::before {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.06);
    z-index: 1;
}
.video-poster-play {
    position: relative;
    z-index: 2;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.62);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.24);
}
.video-poster-play::before {
    content: "";
    position: absolute;
    left: 23px;
    top: 17px;
    width: 0;
    height: 0;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    border-left: 18px solid #fff;
}
.video-shell.is-playing .video-poster-button,
.video-shell.is-loading .video-poster-button {
    display: none;
}
.video-triplet-grid > article:nth-of-type(3n + 2) {
    border-color: rgba(185, 28, 28, 0.35);
}
.video-triplet-grid > article:nth-of-type(3n) {
    border-color: rgba(118, 185, 0, 0.55);
}
.video-triplet-grid > article:nth-of-type(3n + 2) h5 {
    color: var(--red);
}
.video-triplet-grid > article:nth-of-type(3n) h5 {
    color: #4d7c0f;
}

/* Takeaways */
.takeaways {
    max-width: var(--max-w);
    margin: 36px auto;
    padding: 0;
}
.takeaways h2 {
    text-align: center;
    margin: 0 0 18px;
    font-size: 26px;
    font-weight: 700;
}

/* BibTeX */
.bibtex-card {
    position: relative;
    background: var(--gray-1);
    border: 2px solid var(--green);
    border-radius: 8px;
    padding: 20px;
}
.bibtex-card pre {
    margin: 0;
    overflow-x: auto;
    background: transparent;
    padding-right: 110px;
}
.bibtex-card code {
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.55;
    color: #000;
    white-space: pre;
}
.bibtex-copy {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--green);
    color: #fff;
    border: 0;
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}
.bibtex-copy:hover, .bibtex-copy:focus-visible {
    background: #5e9b00;
    outline: 2px solid var(--green);
    outline-offset: 2px;
}

.ack { color: var(--gray-4); }

/* Footer */
.site-footer {
    border-top: 1px solid var(--gray-2);
    margin-top: 48px;
    padding: 22px 16px 32px;
    text-align: center;
    font-size: 14px;
    color: var(--gray-4);
}
.site-footer p { margin: 0; }
.site-footer a { color: var(--gray-4); text-decoration: underline; }
.site-footer a:hover { color: var(--green); }

/* ----- Responsive breakpoints ----- */

/* Tablet */
@media (max-width: 960px) {
    .three-col { grid-template-columns: 1fr 1fr; }
    .formula-grid,
    .benchmark-axes { grid-template-columns: 1fr 1fr; }
    .video-grid.four-col,
    .video-triplet-grid { grid-template-columns: repeat(2, 1fr); }
    .topnav-sections a { font-size: 13px; padding: 4px 6px; }
}

/* Phone */
@media (max-width: 640px) {
    body { font-size: 16px; }
    main { padding: 0 12px; }
    .hero { padding: 22px 0 8px; }
    .topnav { padding: 8px 12px; }
    .topnav-logo { width: 92px; }
    .topnav-sections { width: 100%; }
    .hero-title { font-size: 20px; }
    .authors, .affiliations { gap: 3px 10px; }
    .authors li, .affiliations li { font-size: 14px; }
    .two-col, .three-col, .motivation-grid, .formula-grid, .benchmark-axes, .video-grid.four-col, .video-pair-grid { grid-template-columns: 1fr; }
    .video-triplet-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .recall-video-heading {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }
    .recall-demo-card {
        flex-basis: auto;
        width: 100%;
    }
    .video-sync-control {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
    }
    .video-sync-buttons {
        width: 100%;
    }
    .video-sync-button {
        flex: 1 1 0;
    }
    .video-card { padding: 6px; }
    .video-card h5 { font-size: 11px; }
    .resource-button { padding: 8px 14px; font-size: 14px; }
    .resource-button small { display: none; }
    .prose > h2 { font-size: 22px; }
    .prose > h3 { font-size: 18px; }
    .prose p, .prose ul, .prose ol {
        text-align: left;
    }
    .prose figure {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .figure-iframe {
        width: 760px;
        max-width: none;
        height: 300px !important;
    }
    .figure-block > h2 { font-size: 20px; }
    .bibtex-card pre { padding-right: 0; }
    .bibtex-copy {
        position: static;
        display: block;
        width: 100%;
        margin-bottom: 10px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

/* Print: hide TODO panel + nav, expand to ink-friendly width */
@media print {
    .topnav, .todo-panel, .resource-buttons, .video-block, .site-footer { display: none !important; }
    body, main { background: #fff !important; box-shadow: none !important; }
    .figure-iframe { box-shadow: none; border: 1px solid var(--gray-3); }
}
