/* SAFE-Hair project page. Centered single-column academic layout: white ground, soft grey alternating sections, rounded figure cards. */

:root {
  --bg: #ffffff;
  --soft: #f8f9fa;
  --ink: #1a1a1a;
  --heading: #111111;
  --muted: #4a4a4a;
  --faint: #6b6b6b;
  --line: #eeeeee;
  --line-strong: #dddddd;
  --pill: #363636;
  --pill-hover: #1f1f1f;
  --accent: #2c5fb3;
  --accent-soft: #eef3fb;

  --font-head: "Google Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-text: var(--font-head);

  --fs-small: 0.875rem;
  --fs-body: 1.0625rem;
  --fs-h3: 1.125rem;
  --fs-sub: 1.375rem;
  --fs-head: clamp(1.75rem, 3vw, 2.25rem);
  --measure: 46rem;

  --w: 960px;
  --w-wide: 1100px;
  --pad-x: clamp(1rem, 3vw, 1.5rem);
  --section-y: clamp(3rem, 5vw, 4.5rem);
  --radius: 16px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-press: 140ms;
  --t-hover: 180ms;
  --t-ui: 240ms;
}

/* ---------------- reset ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font-text); font-size: var(--fs-body); line-height: 1.65;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, p, figure, ul, ol, pre { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, canvas { display: block; max-width: 100%; }
img { height: auto; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.2em; }
b { font-weight: 600; color: var(--heading); }
:target { scroll-margin-top: 1.5rem; }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
h1, h2, h3 { font-family: var(--font-head); color: var(--heading); text-wrap: balance; }
p { text-wrap: pretty; }
pre, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.container { max-width: calc(var(--w) + 2 * var(--pad-x)); margin-inline: auto; padding-inline: var(--pad-x); }
.container-wide { max-width: calc(var(--w-wide) + 2 * var(--pad-x)); margin-inline: auto; padding-inline: var(--pad-x); }

/* ---------------- hero ---------------- */
.hero { padding-block: clamp(2.5rem, 6vw, 4rem) var(--section-y); text-align: center; }
.venue {
  display: inline-block; padding: 0.2rem 0.85rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--font-head); font-weight: 500; font-size: var(--fs-small); letter-spacing: 0.02em;
}
.title {
  margin-top: 0.9rem; font-family: Fraunces, Georgia, "Times New Roman", serif;
  font-size: clamp(3.4rem, 8vw, 6.2rem); line-height: 0.95; font-weight: 560;
  font-optical-sizing: auto; letter-spacing: -0.03em;
}
.subtitle {
  margin: 0.6rem auto 0; max-width: 22em;
  font-family: var(--font-head); font-weight: 500; color: #2f2f2f;
  font-size: var(--fs-head); line-height: 1.25; letter-spacing: -0.01em; text-wrap: balance;
}
.authors {
  margin-top: 1.6rem; font-size: var(--fs-h3); line-height: 1.7;
  font-family: var(--font-head); color: var(--accent);
}
.authors .author { white-space: nowrap; }
.authors a { color: inherit; text-decoration-color: transparent; text-underline-offset: 0.18em; }
.authors a:hover { text-decoration-color: currentColor; }
.authors sup, .affil sup, .corr sup { font-size: 0.7em; }
.affil { margin-top: 0.5rem; color: var(--ink); }
.corr { margin-top: 0.25rem; font-size: var(--fs-small); font-weight: 600; color: var(--ink); }

.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; margin-top: 1.5rem; }
.pill {
  display: inline-flex; align-items: center; gap: 0.45rem; min-height: 2.5rem; padding: 0 1.25rem;
  border-radius: 999px; background: var(--pill); color: #fff;
  font-family: var(--font-head); font-weight: 500; white-space: nowrap;
  transition: background-color var(--t-hover) ease, transform var(--t-press) var(--ease-out);
}
.pill:hover { text-decoration: none; background: var(--pill-hover); }
.pill:active { transform: scale(0.97); }
.pill .ico { width: 1.05rem; height: 1.05rem; fill: currentColor; flex: none; }

.teaser { margin-top: clamp(2rem, 4vw, 2.75rem); }

/* ---------------- sections ---------------- */
.section { padding-block: var(--section-y); }
.section.soft { background: var(--soft); }
.section-title {
  text-align: center; font-size: var(--fs-head); font-weight: 700;
  line-height: 1.15; letter-spacing: -0.01em; margin-bottom: 1.25rem;
}
.sub-title {
  text-align: center; font-size: var(--fs-sub); font-weight: 700;
  line-height: 1.25; margin: clamp(2.5rem, 4vw, 3.25rem) 0 0.85rem;
}
.section-lead {
  max-width: 58rem; margin: 0 auto 2rem; text-align: center;
  font-size: 1.1875rem; line-height: 1.7; color: #383838;
}
.nowrap { white-space: nowrap; }
.prose { max-width: var(--measure); margin-inline: auto; }
.prose p, .section-lead, .caption, .card p, .stats p { text-wrap: balance; }
.prose p { color: #333; }
.prose p + p { margin-top: 1rem; }
.contrib { padding: 1.35rem 1.5rem 1.55rem; margin-bottom: 1.75rem; }
.contrib-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem 2rem; }
.contrib-grid h3 {
  font-family: Fraunces, Georgia, "Times New Roman", serif; font-weight: 560;
  font-size: clamp(1.4rem, 2vw, 1.7rem); letter-spacing: -0.02em; line-height: 1.15; margin-bottom: 0.4rem;
}
.contrib-grid p { color: var(--muted); text-wrap: balance; }
.caption { max-width: var(--measure); margin: 1rem auto 0; text-align: center; font-size: var(--fs-small); color: var(--muted); }
.caption-left { text-align: left; }

/* ---------------- cards ---------------- */
.card { background: var(--soft); border-radius: var(--radius); overflow: hidden; }
.soft .card { background: #fff; }
.card-pad { padding: 1.25rem 1.35rem; }
.card h3 { font-size: var(--fs-h3); font-weight: 700; line-height: 1.3; margin-bottom: 0.45rem; }
.card p { color: var(--muted); }
.cards { display: grid; gap: 1rem; }
.cards-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.soft .card-ours, .card-ours { background: var(--accent-soft); }
.card-ours h3 { color: var(--accent); }
.soft .card-miss, .card-miss { background: #f8ecec; }
.card-miss h3 { color: #8f3d3d; }

.figure { padding: clamp(0.5rem, 1.5vw, 1rem); }
.figure img { width: 100%; border-radius: 8px; }
.teaser { padding: clamp(0.5rem, 1.5vw, 1rem); }
.teaser img { width: 100%; border-radius: 8px; }
.fig-caption {
  padding: clamp(0.9rem, 1.8vw, 1.25rem) clamp(0.35rem, 1vw, 0.75rem) clamp(0.35rem, 0.8vw, 0.6rem);
  text-align: left; font-size: 1.125rem; line-height: 1.7; color: #383838; text-wrap: pretty;
}
.fig-caption .fig-label { margin-right: 0.3em; font-weight: 700; color: var(--accent); }

/* ---------------- method ---------------- */
.stages { margin-top: 2rem; }
.stage { display: flex; flex-direction: column; }
.stage .eq {
  margin-top: auto; padding-top: 1rem; overflow-x: auto; overflow-y: hidden;
  color: var(--heading);
}
.eq .katex-display { margin: 0.25rem 0 0; }

/* demo */
.demo { margin-top: 1rem; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: stretch; }
.demo-text { display: flex; flex-direction: column; justify-content: center; padding: 1.75rem 1.6rem; }
.demo-text h3 { margin-bottom: 0.6rem; text-align: center; }
.demo-controls { margin-top: 1.4rem; display: grid; gap: 1.1rem; }
.toggles { display: grid; gap: 0.7rem; margin-top: 0.2rem; }
.demo-controls > label { display: grid; gap: 0.55rem; font-weight: 600; color: var(--heading); }
input[type=range] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px;
  background: #e3e3e3; outline: none; cursor: pointer;
}
input[type=range]:focus-visible { outline: 3px solid var(--accent); outline-offset: 6px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 5px solid var(--pill); cursor: grab;
  transition: transform var(--t-press) var(--ease-out);
}
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.15); cursor: grabbing; }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 5px solid var(--pill); cursor: grab; }
.toggle { display: flex; align-items: center; gap: 0.75rem; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle span { width: 40px; height: 24px; border-radius: 999px; background: #dcdcdc; position: relative; flex-shrink: 0; transition: background-color var(--t-hover) ease; }
.toggle span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform var(--t-ui) var(--ease-out);
}
.toggle input:checked + span { background: var(--pill); }
.toggle input:checked + span::after { transform: translateX(16px); }
.toggle input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 3px; }
.demo-canvas-wrap { position: relative; min-height: 420px; background: #efefed; }
#demo-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.demo-legend {
  position: absolute; left: 1rem; bottom: 0.75rem; font-size: var(--fs-small);
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.demo-legend.warn b { color: #b3261e; }

/* ---------------- qualitative ---------------- */
.panel { display: grid; gap: clamp(0.5rem, 1.5vw, 1rem); padding: clamp(0.75rem, 2vw, 1.25rem); }
.views { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grooms { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.panel p { padding-top: 0.6rem; text-align: center; font-size: var(--fs-small); color: var(--muted); }
.views p b { display: block; }

/* ---------------- quantitative ---------------- */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.5rem; margin: 2.25rem 0 2.5rem; text-align: center; }
.stats p { max-width: 17rem; margin-inline: auto; color: var(--muted); }
.stats .stat {
  font-weight: 700; color: var(--accent); font-size: var(--fs-head); line-height: 1.1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; white-space: nowrap; margin-bottom: 0.35rem;
}

.chart-header { display: flex; flex-wrap: wrap; gap: 0.75rem; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 0.35rem; }
.seg button {
  min-height: 2.1rem; padding: 0 0.9rem; border-radius: 999px;
  font-family: var(--font-head); font-weight: 500; font-size: var(--fs-small); color: var(--muted);
  background: #f1f1f1; transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.seg button:hover { color: var(--heading); background: #e8e8e8; }
.seg button.active { background: var(--pill); color: #fff; }
.seg-light button.active { background: var(--accent-soft); color: var(--accent); }

.bars { display: grid; gap: 0.5rem; }
.bar-row { display: grid; grid-template-columns: minmax(8rem, 12rem) 1fr 4rem; align-items: center; gap: 0.9rem; }
.bar-name { text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 1.35rem; background: #f3f3f3; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: #c3c3c3; border-radius: 6px; transition: width 0.9s var(--ease-out); }
.bar-row.ours .bar-fill { background: var(--accent); }
.bar-row.ours .bar-name, .bar-row.ours .bar-val { font-weight: 600; color: var(--heading); }
.bar-val { font-variant-numeric: tabular-nums; }
.bars-hint { margin-top: 0.75rem; text-align: right; font-size: var(--fs-small); color: var(--faint); }

.table-block .sub-title { margin-top: clamp(2.25rem, 4vw, 3rem); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th {
  text-align: center; font-family: var(--font-head); font-weight: 700; color: var(--heading);
  padding: 0.75rem 0.9rem; border-bottom: 1px solid var(--line-strong); white-space: nowrap; background: #fafafa;
}
td { text-align: center; padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; padding-left: 1.25rem; }
tbody tr:last-child td { border-bottom: 0; }
td.second { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.25em; }
tr.ours td { font-weight: 700; color: var(--heading); background: var(--accent-soft); }

/* ---------------- export ---------------- */
.grooms img { cursor: zoom-in; }
.export-detail {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 1.5rem;
  align-items: stretch; margin-top: 2rem;
}
.bullets {
  display: grid; align-content: center; gap: 0.7rem;
  padding: 1.35rem 1.5rem 1.35rem 2.6rem; list-style: disc;
}
.bullets li { padding-left: 0.2rem; text-wrap: pretty; }
.bullets li::marker { color: var(--accent); }
.record {
  display: flex; align-items: center;
  padding: 1.25rem 1.4rem; background: #fff; border-radius: var(--radius);
  font-size: var(--fs-small); line-height: 1.75; overflow-x: auto; color: #222;
}
.record .k { color: var(--heading); font-weight: 600; } .record .p { color: var(--accent); } .record .n { color: #9a4d00; }

/* ---------------- bibtex ---------------- */
.bib-wrap { position: relative; }
.bib {
  padding: 1.35rem 1.45rem; background: #f5f5f5; border-radius: 12px;
  color: #222; font-size: var(--fs-small); line-height: 1.6; overflow-x: auto;
}
.copy {
  position: absolute; top: 0.75rem; right: 0.75rem; min-height: 2rem; padding: 0 0.9rem; border-radius: 999px;
  background: #e6e6e6; color: var(--ink);
  font-family: var(--font-head); font-weight: 500; font-size: var(--fs-small);
  transition: background-color var(--t-hover) ease, color var(--t-hover) ease;
}
.copy:hover { background: #dadada; }
.copy.done { background: var(--pill); color: #fff; }

/* ---------------- footer ---------------- */
.footer { padding-block: 2rem 2.5rem; background: var(--soft); text-align: center; font-size: var(--fs-small); color: var(--faint); }
.footer p + p { margin-top: 0.35rem; }

/* ---------------- lightbox ---------------- */
.zoomable { cursor: zoom-in; }
.lightbox {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 3vw;
  background: rgba(255, 255, 255, 0.96); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity var(--t-ui) ease, visibility 0s linear var(--t-ui);
}
.lightbox.open { opacity: 1; visibility: visible; pointer-events: auto; transition: opacity var(--t-ui) ease, visibility 0s; }
.lightbox img { max-width: 100%; max-height: 92vh; border-radius: 8px; cursor: zoom-out; transform: scale(0.97); transition: transform 400ms var(--ease-out); }
.lightbox.open img { transform: none; }
.lightbox-close {
  position: absolute; top: 1.25rem; right: 1.25rem; width: 2.75rem; height: 2.75rem; border-radius: 50%;
  background: var(--pill); color: #fff; font-size: 1.6rem; line-height: 1;
}

/* ---------------- motion ---------------- */
@media (prefers-reduced-motion: no-preference) {
  .js [data-reveal] {
    opacity: 0; transform: translateY(16px);
    transition: opacity 600ms var(--ease-out), transform 700ms var(--ease-out);
    transition-delay: calc(var(--i, 0) * 70ms);
  }
  .js [data-reveal].is-in { opacity: 1; transform: none; }
}

/* ---------------- responsive ---------------- */
@media (max-width: 52em) {
  .cards-3, .cards-2, .contrib-grid { grid-template-columns: 1fr; }
  .views { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: 1fr; gap: 1.25rem; }
  .demo { grid-template-columns: 1fr; }
  .demo-canvas-wrap { min-height: 340px; }
  .export-detail { grid-template-columns: 1fr; }
  th, td { padding-inline: 0.5rem; }
}

@media (max-width: 36em) {
  .grooms { gap: 0.4rem; padding: 0.5rem; }
  .grooms p { font-size: 0.8125rem; line-height: 1.35; }
  .subtitle { font-size: var(--fs-sub); }
  .prose p { text-align: left; }
  .section-lead, .caption { text-align: left; }
  .fig-caption, .section-lead { font-size: 1.0625rem; line-height: 1.6; }
  .bar-row { grid-template-columns: 6.5rem 1fr 3.25rem; gap: 0.55rem; font-size: var(--fs-small); }
  .seg button { padding: 0 0.7rem; }
  .bib { padding-top: 3rem; white-space: pre-wrap; word-break: break-word; }
  .stage .eq { font-size: 0.8em; }
  table { font-size: 0.8125rem; }
  th { white-space: normal; padding: 0.55rem 0.3rem; }
  td { padding: 0.5rem 0.3rem; }
  th:first-child, td:first-child { padding-left: 0.6rem; }
  td:first-child { white-space: normal; }
}
