/* ============================================================
   PGR-3D project page — Seeing Before Generating
   ============================================================ */

:root {
    --bg: #ffffff;
    --bg-alt: #f7f8fa;
    --bg-card: #ffffff;
    --fg: #101828;
    --fg-soft: #475467;
    --fg-faint: #98a2b3;
    --border: #e4e7ec;
    --accent: #4f46e5;        /* indigo */
    --accent-soft: #eef2ff;
    --good: #15803d;          /* rescue = green */
    --good-soft: #dcfce7;
    --bad: #dc2626;           /* failure = red */
    --bad-soft: #fee2e2;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.06);
    --shadow-lg: 0 8px 32px rgba(16,24,40,.12);
    --radius: 16px;
    --maxw: 1160px;
    --font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme="dark"] {
    --bg: #0b0f19;
    --bg-alt: #121826;
    --bg-card: #161d2e;
    --fg: #f2f4f8;
    --fg-soft: #b3bccd;
    --fg-faint: #7a869c;
    --border: #263145;
    --accent: #818cf8;
    --accent-soft: #1c2438;
    --good: #4ade80;
    --good-soft: #123020;
    --bad: #f87171;
    --bad-soft: #3a1a1c;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; scroll-padding-top: 72px; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--fg);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    transition: background .3s ease, color .3s ease;
}

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
.narrow { max-width: 780px; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- NAV ---------- */
.nav {
    position: sticky; top: 0; z-index: 50;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.nav-inner { display: flex; align-items: center; justify-content: space-between; height: 60px; }
.nav-logo { font-weight: 800; letter-spacing: -.02em; color: var(--fg); font-size: 1.05rem; }
.nav-logo:hover { text-decoration: none; }
.nav-links { display: flex; gap: 28px; }
.nav-links a { color: var(--fg-soft); font-size: .92rem; font-weight: 500; }
.nav-links a:hover { color: var(--accent); text-decoration: none; }
.theme-toggle {
    background: var(--bg-alt); border: 1px solid var(--border); color: var(--fg);
    width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 1.1rem;
    display: grid; place-items: center; transition: background .2s;
}
.theme-toggle:hover { background: var(--accent-soft); }

/* ---------- HERO ---------- */
.hero {
    text-align: center;
    padding: 64px 0 48px;
    background: radial-gradient(1200px 400px at 50% -80px, var(--accent-soft), transparent 70%);
}
.eyebrow {
    display: inline-block; font-weight: 600; font-size: .88rem; letter-spacing: .01em;
    color: var(--accent); background: var(--accent-soft);
    padding: 6px 14px; border-radius: 999px; margin-bottom: 22px;
    border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.title {
    font-size: clamp(2.2rem, 6vw, 4rem); font-weight: 900; letter-spacing: -.03em;
    line-height: 1.2; padding-bottom: .15em; overflow: visible;
    color: var(--fg);
}
.title .accent { color: var(--accent); }
.subtitle {
    font-size: clamp(1.05rem, 2.4vw, 1.5rem); font-weight: 500; color: var(--fg-soft);
    margin-top: 14px; letter-spacing: -.01em;
}
.authors { margin-top: 26px; font-weight: 600; color: var(--fg); line-height: 1.7; }
.authors a { color: var(--fg); text-decoration: none; }
.authors a:hover { color: var(--accent); text-decoration: underline; }
.authors sup { color: var(--fg-faint); font-weight: 500; font-size: .7em; }
.affil { color: var(--fg-soft); font-size: .9rem; margin-top: 8px; line-height: 1.6; }
.affil sup { color: var(--fg-faint); font-size: .75em; }
.venue { color: var(--fg-faint); font-size: .95rem; margin-top: 4px; }

.links { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin: 30px 0 10px; }
.link-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--fg); color: var(--bg); font-weight: 600; font-size: .95rem;
    padding: 11px 20px; border-radius: 999px; transition: transform .15s, box-shadow .2s;
    box-shadow: var(--shadow);
}
.link-btn:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.link-btn[aria-disabled="true"] { background: var(--bg-alt); color: var(--fg-faint); border: 1px solid var(--border); box-shadow: none; }
.link-btn .soon { font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; opacity: .8; }
.code-btn { display: inline-flex; align-items: center; gap: .5em; }
.code-btn svg { flex: 0 0 auto; }
.code-btn .soon { font-size: .82rem; text-transform: none; letter-spacing: 0; opacity: 1;
    color: var(--accent); font-weight: 600; }

/* ---------- TEASER ---------- */
.teaser { margin-top: 40px; }
.teaser img {
    width: 100%; max-width: 1080px; height: auto; border-radius: var(--radius);
    border: 1px solid var(--border); box-shadow: var(--shadow-lg); background: #fff;
}
.teaser figcaption {
    max-width: 820px; margin: 20px auto 0; color: var(--fg-soft); font-size: .98rem; text-align: center;
}
.bad { color: var(--bad); font-weight: 600; }
.good { color: var(--good); font-weight: 700; }

/* ---------- Section scaffolding ---------- */
section { padding: 72px 0; border-top: 1px solid var(--border); }
.hero, .tldr { border-top: none; }
.section-label {
    font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; text-align: center; margin-bottom: 12px;
}
.lede { color: var(--fg-soft); text-align: center; margin: 0 auto 36px; font-size: 1.05rem; }
.sub-head { font-size: 1.4rem; font-weight: 700; text-align: center; margin: 56px 0 6px; }

/* ---------- TL;DR ---------- */
.tldr { background: var(--bg-alt); text-align: center; }
.big-quote {
    font-size: clamp(1.4rem, 3.4vw, 2.1rem); font-weight: 700; letter-spacing: -.02em;
    max-width: 820px; margin: 8px auto 44px; line-height: 1.35;
}
.big-quote em { color: var(--accent); font-style: normal; }
.key-numbers {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; max-width: 960px; margin: 0 auto;
}
.number {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 28px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.number .value { font-size: clamp(1.8rem, 4vw, 2.6rem); font-weight: 900; letter-spacing: -.03em; line-height: 1; }
.number .value.neg { color: var(--good); }
.number .label { font-size: .86rem; color: var(--fg-soft); font-weight: 500; }

/* ---------- Abstract ---------- */
.abstract p { font-size: 1.08rem; color: var(--fg-soft); }
.abstract strong { color: var(--fg); }

/* ---------- Method ---------- */
.method-diagram {
    margin: 8px auto 44px; background: #fff; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); overflow-x: auto;
}
.method-diagram img { width: 100%; min-width: 720px; height: auto; display: block; }
.method-details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; }
.detail-block {
    position: relative; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 28px 22px 22px; box-shadow: var(--shadow);
}
.step-num {
    position: absolute; top: -16px; left: 22px;
    width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff;
    display: grid; place-items: center; font-weight: 800; box-shadow: var(--shadow);
}
.detail-block h3 { font-size: 1.08rem; margin: 6px 0 8px; letter-spacing: -.01em; }
.detail-block p { color: var(--fg-soft); font-size: .96rem; }
.detail-block strong { color: var(--fg); }

/* ---------- Results table ---------- */
.results-table { max-width: 860px; margin: 0 auto; }
table { width: 100%; border-collapse: collapse; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
thead th {
    text-align: right; font-size: .82rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--fg-faint); padding: 14px 18px; background: var(--bg-alt); border-bottom: 1px solid var(--border);
}
thead th:first-child { text-align: left; }
.dir { color: var(--accent); }
tbody td { padding: 13px 18px; text-align: right; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: none; }
tbody td:first-child { text-align: left; font-weight: 500; }
.indent { padding-left: 30px !important; color: var(--fg-soft); }
.base-row td { font-weight: 700; }
tr.ours { background: var(--good-soft); }
tr.ours td { color: var(--fg); }
.tag {
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: #fff; background: var(--good); padding: 2px 8px; border-radius: 999px; margin-left: 8px; vertical-align: middle;
}
.better { color: var(--good); font-weight: 700; }
.better.big { font-size: 1.05rem; }
.dash { color: var(--fg-faint); }
.table-note { text-align: center; color: var(--fg-faint); font-size: .85rem; margin-top: 14px; }

/* ---------- Interactive gallery ---------- */
.gallery-controls { display: flex; justify-content: center; margin: 24px 0 28px; }
.gallery-objects { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.gobj {
    display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer;
    background: var(--bg-card); border: 2px solid var(--border); border-radius: 14px;
    padding: 8px 8px 6px; width: 96px; transition: border-color .15s, transform .15s;
}
.gobj:hover { transform: translateY(-2px); }
.gobj img { width: 74px; height: 74px; object-fit: contain; border-radius: 8px; background: var(--bg-alt); }
.gobj span { font-size: .78rem; font-weight: 600; color: var(--fg-soft); }
.gobj.active { border-color: var(--accent); }
.gobj.active span { color: var(--accent); }

.gallery-viewer {
    display: grid; grid-template-columns: 200px 1fr; gap: 28px; align-items: start;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 26px; box-shadow: var(--shadow); max-width: 900px; margin: 0 auto;
}
.viewer-fixed { display: flex; flex-direction: column; gap: 18px; }
.viewer-fixed figure, .viewer-stage { text-align: center; }
.viewer-fixed img {
    width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--bg-alt);
    border: 1px solid var(--border); border-radius: 12px;
}
.viewer-fixed figcaption, .viewer-stage figcaption { margin-top: 6px; font-size: .82rem; color: var(--fg-faint); font-weight: 500; }

.viewer-condition-tabs { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.cond-tab {
    border: 1px solid var(--border); background: var(--bg-alt); color: var(--fg-soft);
    padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: .86rem; font-weight: 600; transition: all .15s;
}
.cond-tab:hover { border-color: var(--accent); }
.cond-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.cond-tab.active.is-ours { background: var(--good); border-color: var(--good); }

.viewer-stage img {
    width: 100%; max-width: 360px; aspect-ratio: 1; object-fit: contain; margin: 0 auto;
    background: var(--bg-alt); border: 1px solid var(--border); border-radius: 12px; display: block;
    transition: opacity .15s;
}
.viewer-stage figcaption { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 10px; font-size: .92rem; color: var(--fg); }
.cd-badge { font-family: var(--mono); font-size: .8rem; padding: 2px 9px; border-radius: 999px; background: var(--bg-alt); border: 1px solid var(--border); color: var(--fg-soft); }
.cd-badge.win { background: var(--good-soft); color: var(--good); border-color: transparent; font-weight: 600; }
.cd-badge:empty { display: none; }
.viewer-modes { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.mode-btn {
    border: 1px solid var(--border); background: var(--bg); color: var(--fg-soft);
    padding: 7px 16px; border-radius: 10px; cursor: pointer; font-size: .85rem; font-weight: 600;
}
.mode-btn.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ---------- Qualitative ---------- */
.qual-fig { margin: 0 auto 40px; max-width: 1000px; text-align: center; }
.qual-fig img { width: 100%; height: auto; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); background: #fff; }
.qual-fig figcaption { margin-top: 14px; color: var(--fg-soft); font-size: .95rem; }
.qual-fig em { color: var(--fg); font-style: italic; }
.qual-more { max-width: 1000px; margin: 0 auto; text-align: center; }
.qual-more summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: 10px; }

/* ---------- Insights ---------- */
.insights { background: var(--bg-alt); }
.insight-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 22px; max-width: 940px; margin: 0 auto; }
.card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 26px; box-shadow: var(--shadow); transition: transform .15s, box-shadow .2s;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card-icon { font-size: 1.8rem; margin-bottom: 10px; }
.card h3 { font-size: 1.12rem; letter-spacing: -.01em; margin-bottom: 8px; }
.card p { color: var(--fg-soft); font-size: .96rem; }
.card em { color: var(--accent); font-style: normal; font-weight: 600; }
.card strong { color: var(--fg); }

/* ---------- BibTeX ---------- */
.code-wrap { position: relative; }
.bibtex pre {
    background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 24px; overflow-x: auto; font-family: var(--mono); font-size: .88rem; color: var(--fg); line-height: 1.7;
}
.copy-btn {
    position: absolute; top: 12px; right: 12px; z-index: 2;
    background: var(--fg); color: var(--bg); border: none; border-radius: 8px;
    padding: 6px 14px; font-size: .8rem; font-weight: 600; cursor: pointer;
}
.copy-btn:hover { opacity: .88; }

/* ---------- Footer ---------- */
footer { text-align: center; padding: 40px 0; border-top: 1px solid var(--border); color: var(--fg-soft); font-size: .9rem; }
footer .muted { color: var(--fg-faint); margin-top: 6px; font-size: .84rem; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .key-numbers { grid-template-columns: repeat(2, 1fr); }
    .method-details { grid-template-columns: 1fr; gap: 30px; }
    .insight-cards { grid-template-columns: 1fr; }
    .gallery-viewer { grid-template-columns: 1fr; }
    .viewer-fixed { flex-direction: row; }
    .nav-links { display: none; }
}
@media (max-width: 480px) {
    .key-numbers { grid-template-columns: 1fr; }
    section { padding: 52px 0; }
}

/* ---------- What Does Perception See? ---------- */
.perception { background: var(--bg-alt); }
.pemoji { margin-right: 6px; }

/* Aligned 2-column grid: column-flow with 5 explicit rows so each object's
   caption cell and its depth-strip cell share a grid row (equal height). */
.perception-grid2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(5, auto);
    grid-auto-flow: column;
    max-width: 1040px; margin: 0 auto;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.pg-cell { padding: 18px 22px; }
.perception-grid2 > .pg-cell:nth-child(-n+5) { border-right: 1px solid var(--border); }   /* divider */
.perception-grid2 > .pg-cell:not(:nth-child(1)):not(:nth-child(6)) { border-top: 1px solid var(--border); } /* row rules */

.pg-head h3 { font-size: 1.1rem; letter-spacing: -.01em; margin-bottom: 8px; }
.pg-head h3 em { color: var(--accent); font-style: italic; }
.pg-head p { color: var(--fg-soft); font-size: .93rem; }
.pg-head code { font-family: var(--mono); font-size: .82rem; background: var(--bg-alt); padding: 1px 5px; border-radius: 5px; }

/* column labels above the geometric strips (aligns with the 4 panels) */
.depth-colhead { display: flex; gap: 10px; margin-top: 14px; }
.depth-colhead span {
    flex: 1; text-align: center; font-size: .82rem; font-weight: 700; color: var(--fg);
    display: flex; flex-direction: column; line-height: 1.2;
}
.depth-colhead small { font-family: var(--mono); font-size: .66rem; font-weight: 500; color: var(--fg-faint); margin-top: 2px; }

/* semantic caption row */
.pg-sem { display: flex; align-items: center; gap: 14px; }
.pg-sem img {
    width: 62px; height: 62px; flex: 0 0 62px; object-fit: contain;
    background: var(--bg-alt); border: 1px solid var(--border); border-radius: 10px;
}
.sem-cap { font-size: .86rem; color: var(--fg-soft); line-height: 1.5; margin: 0; }
.sem-cap strong { color: var(--accent); }

/* geometric strip row */
.pg-geo { display: flex; align-items: center; }
.pg-geo img { width: 100%; height: auto; border-radius: 8px; display: block; }

/* pipeline chips row */
.pg-pipe {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    font-size: .8rem; color: var(--fg-faint); font-weight: 600;
}
.pg-pipe span { background: var(--bg-alt); border: 1px solid var(--border); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pg-pipe .sem-vec { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }

.perception-note {
    max-width: 820px; margin: 32px auto 0; text-align: center; color: var(--fg-soft);
    font-size: 1rem; line-height: 1.6;
}
.perception-note strong { color: var(--fg); }

@media (max-width: 860px) {
    /* stack: DOM order is full semantic column then full geometric column */
    .perception-grid2 { grid-auto-flow: row; grid-template-columns: 1fr; grid-template-rows: none; }
    .perception-grid2 > .pg-cell:nth-child(-n+5) { border-right: none; }
    .perception-grid2 > .pg-cell:nth-child(6) { border-top: 1px solid var(--border); }
}

/* ---------- Watch the Six Views Emerge ---------- */
.traj-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; max-width: 1000px; margin: 0 auto; }
/* wide two-row videos: stack in a single column */
.traj-grid-1 { display: flex; flex-direction: column; gap: 30px; max-width: 1040px; margin: 0 auto; }
.traj-fig { margin: 0; }
.traj-fig video, .traj-fig img {
    width: 100%; height: auto; display: block; border-radius: var(--radius);
    border: 1px solid var(--border); box-shadow: var(--shadow); background: #fff;
}
.traj-fig figcaption { margin-top: 12px; color: var(--fg-soft); font-size: .95rem; text-align: center; }
.traj-note { max-width: 820px; margin: 26px auto 0; text-align: center; color: var(--fg-faint); font-size: .85rem; }

@media (max-width: 860px) {
    .traj-grid { grid-template-columns: 1fr; }
}

/* ---------- Interactive 3D gallery (model-viewer) ---------- */
.model-objects { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.mobj {
    display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer;
    background: var(--bg-card); border: 2px solid var(--border); border-radius: 14px;
    padding: 8px 8px 6px; width: 96px; transition: border-color .15s, transform .15s;
}
.mobj:hover { transform: translateY(-2px); }
.mobj img { width: 74px; height: 74px; object-fit: contain; border-radius: 8px; background: var(--bg-alt); }
.mobj span { font-size: .78rem; font-weight: 600; color: var(--fg-soft); text-align: center; }
.mobj.active { border-color: var(--accent); }
.mobj.active span { color: var(--accent); }

.model-viewer-row { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; max-width: 900px; margin: 26px auto 0; }
.mv-fig { margin: 0; text-align: center; }
.mv-fig model-viewer {
    width: 100%; height: 360px; background: var(--bg-alt);
    border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
    --poster-color: transparent;
}
.mv-fig figcaption { margin-top: 10px; font-weight: 600; color: var(--fg); font-size: .95rem; }
.mv-acc { color: var(--good); }
.mv-note { max-width: 760px; margin: 18px auto 0; text-align: center; color: var(--fg-faint); font-size: .85rem; }
.mv-note strong { color: var(--fg-soft); }

@media (max-width: 860px) {
    .model-viewer-row { grid-template-columns: 1fr; }
    .mv-fig model-viewer { height: 300px; }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none !important; }
}
