/* ==========================================================================
   TopoPT project page
   Color roles follow the paper's figures:
     orange = LitePT-S (teacher), green = TrimPT, red = TopoPT (ours)
   ========================================================================== */

:root {
  --paper: #f4f6f8;
  --surface: #ffffff;
  --ink: #14202e;
  --ink-2: #44546a;
  --line: #d5dbe3;

  --teacher: #d77a25;
  --teacher-ink: #a65a12;
  --trim: #2f7d4e;
  --trim-ink: #25643e;
  --topo: #9e1b2c;
  --topo-soft: #f8e8ea;

  --focus: #1b6ef3;

  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --gutter: 16px;
  --measure: 40rem;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.125rem;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--topo); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 0 var(--gutter); }

p { margin: 0 0 1em; max-width: var(--measure); }
.wide { max-width: none; }

h1, h2, h3 { font-family: var(--serif); font-weight: 500; line-height: 1.15; margin: 0; }
h2 { font-size: clamp(1.6rem, 3.4vw, 2.1rem); letter-spacing: -0.01em; }
h3 { font-size: 1.3rem; margin-top: 2.2rem; margin-bottom: 0.6rem; }

code, pre, kbd { font-family: var(--mono); }
:not(pre) > code {
  font-size: 0.86em; background: #e8ecf1; padding: 0.1em 0.38em; border-radius: 4px;
}

/* ---------- top bar ---------- */

.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  font-family: var(--sans);
}
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; }
.brand { font-weight: 700; font-size: 1.05rem; text-decoration: none; letter-spacing: 0.01em; }
.brand span { color: var(--topo); }
.top nav { display: flex; gap: 4px; overflow-x: auto; }
.top nav a {
  font-size: 0.92rem; font-weight: 500; text-decoration: none; color: var(--ink-2);
  padding: 6px 10px; border-radius: 6px; white-space: nowrap;
}
.top nav a:hover { background: #e6eaef; color: var(--ink); }

/* ---------- hero ---------- */

.hero { padding: clamp(40px, 7vw, 84px) 0 clamp(24px, 4vw, 40px); }
.venue {
  display: inline-block; font-family: var(--sans); font-weight: 600; font-size: 0.9rem;
  color: var(--topo); background: var(--topo-soft); padding: 4px 12px; border-radius: 999px;
  margin: 0 0 20px;
}
.hero h1 {
  font-size: clamp(2rem, 5.2vw, 3.35rem); letter-spacing: -0.02em; line-height: 1.08;
  max-width: 20em;
}
.authors { font-family: var(--sans); font-size: 1.02rem; margin: 22px 0 4px; max-width: none; }
.authors a { text-decoration: none; font-weight: 600; }
.authors a:hover { text-decoration: underline; }
.affil { font-family: var(--sans); font-size: 0.92rem; color: var(--ink-2); margin: 0 0 24px; max-width: none; }

.links { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 28px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--sans); font-weight: 600; font-size: 0.96rem; text-decoration: none;
  padding: 10px 18px; border-radius: 8px; border: 1.5px solid var(--ink);
  color: var(--ink); background: transparent; cursor: pointer;
}
.btn:hover { background: var(--ink); color: #fff; }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--topo); border-color: var(--topo); }
.btn svg { width: 17px; height: 17px; fill: currentColor; flex: none; }
.btn.primary.is-soon, .btn.is-soon { background: transparent; border-style: dashed; color: var(--ink-2); border-color: var(--ink-2); pointer-events: none; }

.lede { font-size: 1.28rem; line-height: 1.55; max-width: 38rem; }

.facts {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0;
  margin: 36px 0 0; padding: 0; border-top: 1px solid var(--ink);
}
.facts > div { padding: 16px 20px 4px 0; }
.facts > div + div { padding-left: 20px; border-left: 1px solid var(--line); }
.facts dt { font-family: var(--sans); font-size: 0.92rem; color: var(--ink-2); order: 2; }
.facts dd { margin: 0; font-size: clamp(1.9rem, 4vw, 2.7rem); line-height: 1.1; font-weight: 500; letter-spacing: -0.01em; }
.facts dd small { font-size: 0.45em; font-family: var(--sans); font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
.facts > div { display: flex; flex-direction: column; }

/* ---------- sections ---------- */

section { padding: clamp(40px, 6vw, 72px) 0; border-top: 1px solid var(--line); }
.hero + section { border-top: 0; }
.sec-head { margin-bottom: 24px; }
.sec-head p { color: var(--ink-2); margin: 10px 0 0; }

figure { margin: 28px 0; }
figure img { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 6px; }
figcaption { font-family: var(--sans); font-size: 0.92rem; color: var(--ink-2); margin-top: 10px; max-width: 46rem; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; }
.cols figure { margin: 0; }

/* ---------- relational demo (the one memorable element) ---------- */

.demo {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: clamp(16px, 3vw, 28px); font-family: var(--sans);
}
.demo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(12px, 3vw, 32px); }
.panel h3 { margin: 0 0 2px; font-family: var(--sans); font-size: 1rem; font-weight: 700; }
.panel .sub { margin: 0 0 10px; font-size: 0.88rem; color: var(--ink-2); max-width: none; line-height: 1.4; }
.panel .teacher-tag { color: var(--teacher-ink); }
.panel .student-tag { color: var(--topo); }
.panel canvas {
  width: 100%; aspect-ratio: 1; display: block; border: 1px solid var(--line); border-radius: 4px;
  image-rendering: pixelated;
}
.demo-controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px 20px;
  margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line);
}
.demo-controls .btn { padding: 7px 14px; font-size: 0.9rem; }
.slider { flex: 1 1 220px; display: flex; align-items: center; gap: 12px; font-size: 0.9rem; color: var(--ink-2); }
.slider input { flex: 1; accent-color: var(--topo); min-width: 120px; }
.readout { font-variant-numeric: tabular-nums; font-size: 0.95rem; min-width: 14.5em; }
.readout b { font-weight: 700; color: var(--topo); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-2); margin-top: 14px; }
.legend i {
  display: block; width: 160px; height: 10px; border-radius: 2px; border: 1px solid var(--line);
  background: linear-gradient(90deg, #2f6fde, #ffffff, #e8892b);
}
.demo-note { font-size: 0.86rem; color: var(--ink-2); margin: 14px 0 0; max-width: none; line-height: 1.5; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; margin: 16px 0 8px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 0.94rem; min-width: 560px; }
caption { text-align: left; font-weight: 600; padding: 0 0 8px; }
th, td { text-align: left; padding: 10px 14px 10px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { border-bottom: 1.5px solid var(--ink); font-weight: 700; font-size: 0.88rem; color: var(--ink); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; padding-right: 18px; }
tbody tr:hover { background: #eef1f5; }
tr.ours { background: var(--topo-soft); }
tr.ours td:first-child { font-weight: 700; color: var(--topo); }
tr.ours:hover { background: #f4dde0; }
tr.teacher td:first-child { color: var(--teacher-ink); font-weight: 600; }
td a { font-weight: 600; text-decoration: none; border-bottom: 1px solid var(--line); }
td a:hover { border-bottom-color: var(--topo); }
.muted { color: var(--ink-2); }

/* gain table with delta bars */
.gain-bar { display: block; height: 10px; border-radius: 2px; background: var(--topo); width: calc(var(--v) * 1%); min-width: 3px; }
.gain-cell { min-width: 150px; }
.gain-cell span { display: block; font-variant-numeric: tabular-nums; font-weight: 700; color: var(--topo); margin-bottom: 4px; }

/* ---------- tabs ---------- */

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 24px 0 8px; font-family: var(--sans); }
.tabs button {
  font: inherit; font-weight: 600; font-size: 0.94rem; cursor: pointer;
  padding: 8px 16px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.tabs button[aria-selected="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }
.tabs button:hover:not([aria-selected="true"]) { border-color: var(--ink-2); color: var(--ink); }
.js .tab-panel[hidden] { display: none; }

/* ---------- efficiency bars ---------- */

.eff { display: grid; gap: 22px; margin: 20px 0 8px; font-family: var(--sans); }
.eff-row { display: grid; grid-template-columns: 150px 1fr; gap: 8px 20px; align-items: center; }
.eff-row h3 { margin: 0; font-size: 1rem; font-weight: 700; font-family: var(--sans); }
.eff-row h3 small { display: block; font-weight: 500; color: var(--ink-2); font-size: 0.84rem; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 12px; font-size: 0.88rem; }
.bar .track { height: 14px; background: #e6eaef; border-radius: 2px; overflow: hidden; }
.bar .fill { display: block; height: 100%; width: calc(var(--v) * 1%); border-radius: 2px; }
.bar.t .fill { background: var(--teacher); }
.bar.o .fill { background: var(--topo); }
.bar span.val { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar.o span.val { font-weight: 700; color: var(--topo); }
.key { display: flex; gap: 20px; font-family: var(--sans); font-size: 0.88rem; color: var(--ink-2); margin: 6px 0 0; }
.key i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* ---------- code ---------- */

.code { position: relative; margin: 12px 0 22px; }
.code pre {
  margin: 0; background: #101c2b; color: #e6edf5; padding: 16px 18px; border-radius: 8px;
  overflow-x: auto; font-size: 0.86rem; line-height: 1.6; tab-size: 2;
}
.code .copy {
  position: absolute; top: 8px; right: 8px; font-family: var(--sans); font-size: 0.8rem; font-weight: 600;
  padding: 4px 10px; border-radius: 6px; border: 1px solid #3a4a5e; background: #1b2a3d; color: #cfd9e4; cursor: pointer;
}
.code .copy:hover { background: #26384e; color: #fff; }
.code pre .c { color: #7f93a8; }
.step-label { font-family: var(--sans); font-weight: 700; font-size: 1rem; margin: 26px 0 0; }
.note { font-family: var(--sans); font-size: 0.92rem; color: var(--ink-2); max-width: var(--measure); }

/* ---------- formula ---------- */

.formula {
  font-family: var(--serif); font-size: clamp(1.15rem, 2.6vw, 1.5rem); font-style: italic;
  border-left: 3px solid var(--topo); padding: 6px 0 6px 18px; margin: 20px 0 26px;
}
.formula sub { font-size: 0.65em; }
.formula .p { font-style: normal; font-family: var(--sans); font-size: 0.7em; color: var(--ink-2); margin-left: 14px; }

ul.tight { padding-left: 1.2em; max-width: var(--measure); }
ul.tight li { margin-bottom: 0.5em; }

/* ---------- footer ---------- */

footer { border-top: 1px solid var(--line); padding: 36px 0 56px; font-family: var(--sans); font-size: 0.92rem; color: var(--ink-2); }
footer p { max-width: 46rem; }

/* ---------- responsive ---------- */

@media (max-width: 780px) {
  .facts { grid-template-columns: 1fr; }
  .facts > div + div { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
  .demo-grid { grid-template-columns: 1fr; max-width: 340px; }
  .cols { grid-template-columns: 1fr; }
  .eff-row { grid-template-columns: 1fr; }
  .bar { grid-template-columns: 1fr 105px; }
  .top nav a { padding: 6px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

.sr-caption {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   Additions: skip link, news, contributions, lightbox, talk / slides / poster
   ========================================================================== */

[hidden] { display: none !important; }

.skip {
  position: absolute; left: -9999px; top: 8px; z-index: 100;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 6px; font-family: var(--sans);
}
.skip:focus { left: var(--gutter); color: #fff; }

.top nav a[aria-current="true"] { color: var(--ink); background: #e6eaef; font-weight: 600; }

.sec-head h2 .anchor {
  margin-left: 0.45em; opacity: 0; font-family: var(--sans); font-size: 0.6em;
  text-decoration: none; color: var(--ink-2);
}
.sec-head h2:hover .anchor, .sec-head h2 .anchor:focus-visible { opacity: 1; }

.news { font-family: var(--sans); font-size: 0.95rem; margin: 28px 0 0; display: flex; gap: 12px; align-items: baseline; max-width: none; }
.news b { font-weight: 700; color: var(--topo); white-space: nowrap; }

.contrib { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 0 12px; padding: 0; list-style: none; }
.contrib li { padding: 0 24px 0 0; }
.contrib li + li { padding-left: 24px; border-left: 1px solid var(--line); }
.contrib h3 { font-family: var(--sans); font-size: 1rem; font-weight: 700; margin: 0 0 6px; }
.contrib p { font-size: 1rem; line-height: 1.55; margin: 0; }

img[data-zoom] { cursor: zoom-in; }

.icon-btn {
  font-family: var(--sans); font-size: 0.9rem; font-weight: 600; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; text-decoration: none; line-height: 1.3; display: inline-block;
}
.icon-btn:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }

/* lightbox */
.lb { position: fixed; inset: 0; z-index: 50; background: rgba(10, 18, 28, 0.93); display: flex; flex-direction: column; }
.lb-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 10px var(--gutter); }
.lb-body { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 0 var(--gutter) var(--gutter); }
.lb-body img { max-width: 100%; max-height: 100%; background: #fff; border-radius: 4px; border: 0; cursor: default; }
.lb.is-full .lb-body { display: block; }
.lb.is-full .lb-body img { max-width: none; max-height: none; margin: 0 auto; }

/* talk */
.video { margin: 0 0 8px; }
.video-stage {
  position: relative; aspect-ratio: 16 / 9; background: #101c2b; border-radius: 10px;
  overflow: hidden; border: 1px solid var(--line);
}
.video-stage .video-poster {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  border: 0; border-radius: 0; opacity: 0.28;
}
.video[data-state="ready"] .video-poster { opacity: 1; }
.video-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: #fff; font-family: var(--sans); padding: 24px;
}
.video-msg strong { font-size: 1.15rem; margin-bottom: 6px; }
.video-msg span { font-size: 0.95rem; color: #cfd9e4; max-width: 30em; }
.video[data-state="ready"] .video-msg, .video[data-state="playing"] .video-msg { display: none; }
.video-play {
  position: absolute; inset: 0; margin: auto; width: 84px; height: 84px; border-radius: 50%; border: 0;
  background: var(--topo); cursor: pointer; display: grid; place-items: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.video-play:hover { background: #b4213a; }
.video-play svg { width: 34px; height: 34px; fill: #fff; margin-left: 5px; }
.video-stage iframe, .video-stage video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }

/* slides */
.slides { border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.slides-stage {
  position: relative; background: #e9edf2; display: flex; align-items: center; justify-content: center;
  aspect-ratio: var(--ar, 16 / 9);
}
.slides-stage canvas { display: block; background: #fff; box-shadow: 0 1px 8px rgba(0, 0, 0, 0.18); touch-action: pan-y; }
.slides-msg {
  max-width: none; margin: 0; position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px;
  font-family: var(--sans); color: var(--ink-2);
}
.slides-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 14px;
  border-top: 1px solid var(--line); font-family: var(--sans);
}
.slides-bar .s-count { min-width: 5.5em; text-align: center; font-variant-numeric: tabular-nums; font-size: 0.92rem; color: var(--ink-2); }
.slides-bar .spacer { flex: 1; }
.slides:fullscreen { display: flex; flex-direction: column; border-radius: 0; border: 0; background: #101c2b; }
.slides:fullscreen .slides-stage { flex: 1; aspect-ratio: auto; background: #101c2b; }
.slides:fullscreen .slides-bar { background: #fff; }

/* poster */
.poster { margin: 12px 0 0; }
.poster-missing { display: none; }
.poster[data-state="missing"] img { display: none; }
.poster[data-state="missing"] .poster-missing {
  display: grid; place-items: center; aspect-ratio: 140 / 90; background: #e9edf2; border: 1px dashed var(--ink-2);
  border-radius: 6px; font-family: var(--sans); color: var(--ink-2); text-align: center; padding: 20px;
}
.poster-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

@media (max-width: 780px) {
  .contrib { grid-template-columns: 1fr; gap: 18px; }
  .contrib li, .contrib li + li { padding: 0; border-left: 0; }
  .contrib li + li { padding-top: 18px; border-top: 1px solid var(--line); }
  .news { flex-direction: column; gap: 2px; }
  .video-play { width: 68px; height: 68px; }
  .slides-bar .spacer { display: none; }
}
