/* X-Foresight project page — minimalist academic style modeled on x-cache-1.github.io */

:root {
  --accent: #1a3a5c;
  --accent-soft: #e7edf3;
  --ink: #1c1c1c;
  --ink-soft: #4a4a4a;
  --muted: #767676;
  --rule: #e3e3e3;
  --bg: #ffffff;
  --bg-alt: #fafafa;
  --code-bg: #f5f5f5;
  --max-w: 1080px;
  --nav-h: 60px;
  --serif: "Source Serif 4", "Iowan Old Style", "Charter", "Times New Roman", "Noto Sans SC", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: var(--nav-h); }

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Restore monospace only for code-like content. */
code, pre, .bibtex { font-family: var(--mono); }

/* ----- Reading-progress bar (top of viewport) --------------------------- */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 100;
  transition: width 80ms linear;
  will-change: width;
  pointer-events: none;
}

/* ----- Scroll-triggered section fade-in --------------------------------- */
/* Scoped to .js so non-JS users see content immediately. Respects
   prefers-reduced-motion by short-circuiting the rule. */
.js section {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity .65s ease-out, transform .65s ease-out;
  will-change: opacity, transform;
}
.js section.in-view {
  opacity: 1;
  transform: none;
}
@media (prefers-reduced-motion: reduce) {
  .js section {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

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

/* ----- Top navigation ---------------------------------------------------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--rule);
}
.nav .brand {
  margin-right: auto;
  color: var(--ink);
  display: flex; align-items: center; gap: 10px;
}
.nav .brand img { display: block; width: auto; }
.nav .brand .brand-full { height: 39px; }
.nav ul {
  list-style: none;
  display: flex;
  gap: 20px;
  margin: 0; padding: 0;
}
.nav ul a {
  font-family: var(--serif);
  color: var(--ink-soft);
  font-size: 15px;
  padding: 4px 2px;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.nav ul a:hover { color: var(--accent); text-decoration: none; }
.nav ul a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
@media (max-width: 760px) {
  .nav { padding: 0 12px; overflow-x: auto; }
  .nav ul { gap: 12px; }
  .nav ul a { font-size: 13px; }
  .nav .brand .brand-full { height: 31px; }
}

/* ----- Layout shell ------------------------------------------------------ */
main { display: block; }
section {
  position: relative;
  padding: 64px 24px;
  border-top: 1px solid var(--rule);
  overflow: hidden;
}
section:first-of-type { border-top: none; }
section.alt { background: var(--bg-alt); }

/* Big editorial section numeral, painted as a faint background accent. */
section[data-num]::before {
  content: attr(data-num);
  position: absolute;
  top: 24px;
  right: clamp(16px, 4vw, 48px);
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(80px, 14vw, 200px);
  line-height: 1;
  color: var(--accent);
  opacity: 0.05;
  pointer-events: none;
  z-index: 0;
  letter-spacing: -0.04em;
}

.container {
  position: relative;
  z-index: 1;
  max-width: var(--max-w);
  margin: 0 auto;
}
.section-label {
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}
section h2 {
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  margin: 0 0 24px;
  color: var(--ink);
  letter-spacing: -0.015em;
  line-height: 1.15;
}
section h3 {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  margin: 32px 0 8px;
  color: var(--ink);
  letter-spacing: -0.005em;
}

/* ----- Hero -------------------------------------------------------------- */
.hero {
  position: relative;
  padding: clamp(72px, 10vw, 128px) 24px clamp(56px, 7vw, 96px);
  text-align: center;
  background: radial-gradient(ellipse 90% 60% at 50% 0%, #f1f5f9 0%, #ffffff 70%);
  border-top: none;
  overflow: hidden;
}
.hero::before {
  /* Faint X-butterfly watermark behind the title — uses the existing logo asset. */
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: clamp(420px, 65vw, 720px);
  aspect-ratio: 1.9 / 1;
  transform: translate(-50%, -50%);
  background: url("../img/logo.png") center/contain no-repeat;
  opacity: 0.035;
  pointer-events: none;
  z-index: 0;
}
.hero > * { position: relative; z-index: 1; }
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(28px, 4.5vw, 56px);
  font-weight: 600;
  line-height: 1.15;
  margin: 0 auto 24px;
  max-width: 880px;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.hero .authors {
  font-family: var(--serif);
  font-size: 17px;
  color: var(--ink-soft);
  margin-bottom: 8px;
}
.hero .affil {
  font-family: var(--serif);
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 28px;
  display: inline-flex; align-items: center; gap: 6px;
}
.hero .affil img { height: 16px; width: auto; vertical-align: middle; }
.hero .badges {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
  margin-bottom: 36px;
}
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.badge:hover { background: var(--accent); color: #fff; text-decoration: none; }
.badge.muted {
  border-color: var(--rule); color: var(--muted);
  cursor: not-allowed; pointer-events: none;
}
.hero-fig {
  max-width: 1080px;
  margin: 0 auto;
}
.hero-fig img { width: 100%; height: auto; border-radius: 6px; }

@media (max-width: 760px) {
  .hero { padding: 56px 16px 40px; }
}

/* ----- Prose / abstract -------------------------------------------------- */
/* Default every <p> to serif so anything outside .prose stays consistent. */
p { font-family: var(--serif); }

.prose p {
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.6;
  margin: 0 0 16px;
  color: var(--ink-soft);
}
.prose strong { color: var(--ink); }
.abstract {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding: 24px 28px;
  border-radius: 4px;
  font-size: 17px;
  line-height: 1.7;
}
.abstract p {
  font-family: var(--serif);
  color: var(--ink);
  margin: 0;
}

ul.bullets { padding-left: 20px; margin: 16px 0; }
ul.bullets li {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.6;
  margin: 8px 0;
  color: var(--ink-soft);
}
ul.bullets li strong { color: var(--ink); }

/* ----- Figures ----------------------------------------------------------- */
figure {
  margin: 28px 0;
  padding: 0;
}
figure img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
}
figcaption {
  font-family: var(--serif);
  font-size: 14.5px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.55;
}
figcaption strong { color: var(--ink-soft); }

/* Utility: render a figure 20% narrower than the column, centered. */
figure.fig-small img { max-width: 80%; margin: 0 auto; }
figure.fig-small figcaption { max-width: 80%; margin-left: auto; margin-right: auto; }

.figrow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 760px) {
  .figrow { grid-template-columns: 1fr; }
}

/* ----- Two-column ------------------------------------------------------- */
.cols2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}
@media (max-width: 760px) { .cols2 { grid-template-columns: 1fr; gap: 16px; } }

.card {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 22px 24px;
  background: #fff;
}
.card h3 { margin-top: 0; }
.card p {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  margin: 0 0 10px;
}

/* ----- Tables ----------------------------------------------------------- */
.tablewrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0 8px;
}
table.results {
  border-collapse: collapse;
  width: 100%;
  /* Keep columns from squashing on narrow viewports — .tablewrap scrolls. */
  min-width: 720px;
  font-size: 14px;
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  table-layout: fixed;
}
table.results th, table.results td {
  border-bottom: 1px solid var(--rule);
  padding: 8px 12px;
  text-align: center;
  white-space: nowrap;
}
table.results th {
  background: var(--bg-alt);
  font-weight: 600;
  color: var(--ink);
  text-align: center;
}
/* Width and left-alignment for the Method column.
   The selector deliberately scopes to thead's FIRST row only, so the
   sub-header row's first <th> (e.g. "1 s", which lives in column 2 due to
   the Method cell's rowspan above) does not get treated as a column-width
   anchor and shift the data underneath it. */
table.results thead > tr:first-child > th:first-child {
  text-align: left;
  width: 24%;
  white-space: normal;
}
table.results tbody td:first-child {
  text-align: left;
  white-space: normal;
}
table.results tbody tr:hover { background: var(--bg-alt); }
table.results .best { font-weight: 700; color: var(--accent); }
table.results .grp { color: var(--muted); font-weight: 500; }

/* On narrow viewports the table is wider than the column and scrolls
   horizontally inside .tablewrap. A small hint label tells users that. */
@media (max-width: 760px) {
  .tablewrap { position: relative; }
  .tablewrap::before {
    content: "← swipe →";
    display: block;
    font-family: var(--sans);
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--muted);
    text-align: right;
    padding: 0 2px 4px;
  }
  /* Localized hint for the Chinese page. */
  html[lang^="zh"] .tablewrap::before { content: "← 左右滑动 →"; }
  table.results {
    font-size: 13px;
    /* Let each column size to its widest content so wide headers like
       "Comfort ↓" don't overflow a fixed cell and drift left of the value
       below. Width is content-driven; .tablewrap still scrolls horizontally. */
    table-layout: auto;
    width: max-content;
    min-width: 100%;
  }
  /* Generous horizontal padding so the ↓ glyph has real space before the next column. */
  table.results th, table.results td { padding: 8px 20px; }
  /* On mobile let the Method column size naturally instead of locking to 24%
     (the fixed-layout-only constraint that crowded the other 10 columns). */
  table.results thead > tr:first-child > th:first-child { width: auto; }
  /* Visible vertical separators between columns — adjacent cells only,
     so the first column doesn't get an extra left border. */
  table.results th + th,
  table.results td + td { border-left: 1px solid var(--rule); }
}

/* ----- Demos placeholder ------------------------------------------------ */
.demo-placeholder {
  border: 1px dashed var(--rule);
  border-radius: 6px;
  padding: 56px 24px;
  text-align: center;
  color: var(--muted);
  background: var(--bg-alt);
}
.demo-placeholder .label {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.demo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.demo-grid video {
  width: 100%; height: auto; border-radius: 4px; background: #000;
}

/* Single-player demo gallery with a button-row selector.
   .qual-picker shares the same look — used for the qualitative figure switcher. */
.demo-picker, .qual-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.demo-picker button, .qual-picker button {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  background: #fff;
  color: var(--ink-soft);
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.demo-picker button:hover, .qual-picker button:hover { border-color: var(--accent); color: var(--accent); }
.demo-picker button.active, .qual-picker button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.demo-player {
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #000;
  overflow: hidden;
  line-height: 0;
}
.demo-player video {
  width: 100%;
  height: auto;
  max-height: 70vh;
  display: block;
}
.demo-caption {
  font-family: var(--serif);
  font-size: 14.5px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.55;
}

/* ----- Citation / BibTeX ------------------------------------------------ */
.bibtex {
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 13px;
  white-space: pre;
  overflow-x: auto;
  color: var(--ink);
  margin: 12px 0;
}

.contributors dt {
  font-family: var(--serif);
  font-weight: 600;
  color: var(--ink);
  margin-top: 8px;
}
.contributors dd {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.6;
  margin: 0 0 4px;
  color: var(--ink-soft);
}

.acknowledgments {
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  border-left: 2px solid var(--rule);
  padding: 4px 0 4px 18px;
  margin-top: 24px;
}

/* ----- Footer ----------------------------------------------------------- */
footer {
  padding: 32px 24px 48px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--rule);
}
footer img { height: 14px; vertical-align: middle; margin-right: 4px; }

/* ----- Misc ------------------------------------------------------------- */
.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 16px 0 24px;
}
.kv .stat {
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 14px 16px;
}
.kv .stat .num {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.kv .stat .lbl {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
  letter-spacing: 0.02em;
}

/* ----- v3: depth pass --------------------------------------------------- */
figure img {
  box-shadow: 0 6px 24px rgba(15, 23, 42, 0.06);
  transition: transform .2s ease-out, box-shadow .2s ease-out;
  cursor: zoom-in;
}
figure img:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 32px rgba(15, 23, 42, 0.10);
}
.card {
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.04);
  transition: transform .2s ease-out, box-shadow .2s ease-out;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}
.demo-player {
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.08);
}
@media (prefers-reduced-motion: reduce) {
  figure img, .card { transition: none; }
  figure img:hover, .card:hover { transform: none; }
}

/* ----- v3: figure lightbox ---------------------------------------------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease-out;
  cursor: zoom-out;
}
.lightbox.open { opacity: 1; pointer-events: auto; }
.lightbox img {
  max-width: 95vw;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--sans);
  line-height: 1;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }

/* ----- v3: mobile nav hamburger ----------------------------------------- */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 22px;
  padding: 6px 10px;
  color: var(--ink);
  margin-left: auto;
}
@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .nav ul.sections {
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    flex-direction: column;
    background: #fff;
    padding: 12px 20px 16px;
    border-bottom: 1px solid var(--rule);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.08);
    display: none;
    gap: 6px;
  }
  .nav ul.sections.open { display: flex; }
  .nav ul.sections a { font-size: 15px; padding: 10px 0; }
}

/* ----- v3: BibTeX copy button ------------------------------------------ */
.bibtex-wrap { position: relative; }
.bibtex-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 12px;
  background: #fff;
  color: var(--ink-soft);
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.bibtex-copy:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.bibtex-copy.copied {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ----- v3: winning-row tint -------------------------------------------- */
/* Uses :has() — modern browser feature, silently no-op on older Safari. */
table.results tbody tr:has(td.best) {
  background: rgba(26, 58, 92, 0.04);
}
table.results tbody tr:has(td.best):hover {
  background: rgba(26, 58, 92, 0.08);
}
