/* ==========================================================================
   MemGuard project page
   ========================================================================== */

:root {
  --ink: #16181d;
  --body: #333a45;
  --muted: #6b7382;
  --line: #e4e7ec;
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --accent: #2f5d9e;         /* semantic / primary blue  */
  --accent-dark: #22457a;
  --episodic: #3f7fd1;
  --semantic: #4f9d69;
  --procedural: #d8a13a;
  --max: 1080px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--body);
  font-family: "Noto Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

.wrap { max-width: var(--max); margin: 0 auto; padding: 0 24px; }
.narrow { max-width: 820px; margin-left: auto; margin-right: auto; }

/* ---------- top navigation ---------- */

.nav {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav-inner {
  max-width: var(--max); margin: 0 auto; padding: 0 24px;
  height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.nav-brand { font-weight: 700; color: var(--ink); letter-spacing: -.01em; }
.nav-brand span { color: var(--accent); }
.nav-links { display: flex; gap: 22px; flex-wrap: wrap; }
.nav-links a {
  color: var(--muted); font-size: 14.5px; font-weight: 500; text-decoration: none;
}
.nav-links a:hover { color: var(--ink); }

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

.hero { padding: 62px 0 26px; text-align: center; }

.badge {
  display: inline-block; font-size: 13px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent);
  background: #eef3fb; border: 1px solid #dbe6f7;
  padding: 5px 12px; border-radius: 999px; margin-bottom: 20px;
}

.title {
  font-size: clamp(30px, 4.6vw, 46px);
  line-height: 1.18; letter-spacing: -.022em; font-weight: 700;
  color: var(--ink); margin: 0 0 6px;
}
.title .mark { color: var(--accent); }
.subtitle {
  font-size: clamp(17px, 2.1vw, 21px); font-weight: 500;
  color: var(--muted); margin: 0 auto 26px; max-width: 760px; line-height: 1.45;
}

.authors { font-size: 17px; margin: 0 auto 8px; max-width: 900px; }
.authors a, .authors span.author { color: var(--ink); }
.authors sup { color: var(--muted); font-size: 12px; }
.affils { font-size: 15.5px; color: var(--muted); margin: 0 auto 4px; max-width: 820px; }
.affils sup { font-size: 12px; }
.contact { font-size: 14.5px; color: var(--muted); margin: 0 0 26px; }
.contact code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; }

/* link buttons */
.links { display: flex; flex-wrap: wrap; gap: 11px; justify-content: center; margin-bottom: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background-color: var(--ink); color: #fff; border: 1px solid var(--ink);
  padding: 9px 20px; border-radius: 999px;
  font-size: 15px; font-weight: 600; text-decoration: none;
  transition: transform .12s ease, background-color .12s ease, box-shadow .12s ease;
}
.btn:hover { background-color: #2b2f38; text-decoration: none; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn.ghost { background-color: #fff; color: var(--ink); border-color: #d6dae1; }
.btn.ghost:hover { background-color: var(--bg-soft); }
.btn.disabled { background-color: #fff; color: var(--muted); border-color: var(--line); cursor: default; }
.btn.disabled:hover { transform: none; box-shadow: none; background-color: #fff; }
.btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ---------- stat strip ---------- */

.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
  margin: 40px auto 0; max-width: 960px;
}
.stat {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 14px; text-align: center;
}
.stat .num { font-size: 26px; font-weight: 700; color: var(--ink); letter-spacing: -.02em; line-height: 1.2; }
.stat .num small { font-size: 15px; font-weight: 600; color: var(--semantic); display: block; }
.stat .lab { font-size: 13.5px; color: var(--muted); line-height: 1.4; margin-top: 4px; }

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

section { padding: 56px 0; border-top: 1px solid var(--line); }
section:first-of-type { border-top: none; }
.section-kicker {
  font-size: 13px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 8px; text-align: center;
}
h2 {
  font-size: clamp(25px, 3.2vw, 33px); line-height: 1.25; letter-spacing: -.02em;
  font-weight: 700; color: var(--ink); margin: 0 0 10px; text-align: center;
}
h3 {
  font-size: 20px; font-weight: 700; color: var(--ink);
  letter-spacing: -.01em; margin: 34px 0 8px;
}
h4 { font-size: 17px; font-weight: 700; color: var(--ink); margin: 22px 0 6px; }
/* headline that must stay on one line on desktop widths */
h2.one-line { white-space: nowrap; font-size: min(2.45vw, 32px); }
@media (max-width: 680px) { h2.one-line { white-space: normal; font-size: 23px; } }
.lede { text-align: center; color: var(--muted); font-size: 17.5px; max-width: 760px; margin: 0 auto 30px; }
p { margin: 0 0 16px; }
strong { color: var(--ink); font-weight: 650; }

/* ---------- figures ---------- */

figure { margin: 26px 0; }
figure img { width: 100%; height: auto; display: block; border-radius: 8px; }
figure.framed img { border: 1px solid var(--line); background: #fff; padding: 10px; }
figcaption { font-size: 14.5px; color: var(--muted); line-height: 1.6; margin-top: 12px; }
figcaption b { color: var(--ink); }

.fig-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; align-items: end; }
.fig-grid figure { margin: 0; }
.fig-grid figcaption { text-align: center; }

/* ---------- callouts / cards ---------- */

.callout {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 18px 22px; margin: 24px 0;
  font-size: 16.5px;
}
.callout p:last-child { margin-bottom: 0; }

.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 28px 0 4px; }
.cards.two,
.cards.four { grid-template-columns: repeat(2, 1fr); max-width: 900px; margin-left: auto; margin-right: auto; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.card h4 { margin: 10px 0 6px; font-size: 17px; }
.card p { font-size: 15.5px; color: var(--body); margin: 0; }
.card .tag {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; padding: 3px 9px; border-radius: 999px;
}
.tag.sem { color: #2f6b45; background: #e8f4ec; }
.tag.epi { color: #27538f; background: #e9f0fa; }
.tag.pro { color: #8a6412; background: #fbf2dd; }
.tag.step { color: var(--accent); background: #eef3fb; }

/* takeaway list */
.takeaways { list-style: none; padding: 0; margin: 26px 0 0; }
.takeaways li {
  position: relative; padding: 0 0 0 42px; margin-bottom: 20px; font-size: 16.5px;
}
.takeaways li:before {
  counter-increment: tk; content: counter(tk);
  position: absolute; left: 0; top: 2px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 13.5px; font-weight: 700; line-height: 26px; text-align: center;
}
.takeaways { counter-reset: tk; }

/* ---------- video ---------- */

.video-box {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #0f1116; border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow);
}
.video-box video, .video-box iframe {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block;
}
.video-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: #c7ccd6; text-align: center; padding: 24px;
  background:
    radial-gradient(60% 80% at 50% 0%, #1d2230 0%, #0f1116 70%);
}
.video-placeholder .play {
  width: 62px; height: 62px; border-radius: 50%;
  border: 2px solid #3b4252; display: grid; place-items: center; margin-bottom: 4px;
}
.video-placeholder .play:after {
  content: ""; width: 0; height: 0;
  border-left: 16px solid #8892a4; border-top: 10px solid transparent; border-bottom: 10px solid transparent;
  margin-left: 4px;
}
.video-placeholder .big { font-size: 18px; font-weight: 600; color: #e6e9ef; }
.video-placeholder .small { font-size: 14px; color: #8892a4; max-width: 460px; line-height: 1.6; }

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

.table-wrap { overflow-x: auto; margin: 22px 0 6px; -webkit-overflow-scrolling: touch; }
table {
  width: 100%; border-collapse: collapse; font-size: 14px;
  font-variant-numeric: tabular-nums; min-width: 700px;
}
caption {
  caption-side: top; text-align: left; font-size: 14.5px; color: var(--muted);
  padding-bottom: 12px; line-height: 1.6;
}
caption b { color: var(--ink); }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-weight: 650; color: var(--ink); font-size: 13px; }
thead tr:first-child th { border-bottom: 1px solid #c9cfd8; }
th:first-child, td:first-child { text-align: left; }
tbody tr.ours { background: #eef3fb; }
tbody tr.ours td { font-weight: 600; color: var(--ink); }
tbody tr.group td {
  background: var(--bg-soft); font-size: 12.5px; font-weight: 700; color: var(--muted);
  letter-spacing: .05em; text-transform: uppercase; text-align: left;
}
td.best, th.best { font-weight: 700; color: var(--ink); }
.tbl-note { font-size: 13.5px; color: var(--muted); margin-top: 10px; line-height: 1.6; }
table.ablation th:first-child, table.ablation td:first-child,
table.ablation th:nth-child(2), table.ablation td:nth-child(2) { text-align: center; }
.check { color: var(--semantic); font-weight: 700; }
.cross { color: #c05b4d; font-weight: 700; }

/* ---------- bibtex ---------- */

pre.bibtex {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; overflow-x: auto; font-size: 13.5px; line-height: 1.65;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #2c313a; margin: 0;
}

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

footer {
  border-top: 1px solid var(--line); padding: 34px 0 48px;
  font-size: 14px; color: var(--muted); text-align: center;
}
footer a { color: var(--muted); text-decoration: underline; }

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

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .cards { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .nav-links { display: none; }
  .hero { padding: 40px 0 18px; }
  .fig-grid { grid-template-columns: 1fr; gap: 20px; }
  section { padding: 44px 0; }
}

/* ==========================================================================
   Content components adopted from the project-page draft
   ========================================================================== */

/* ---- motivation cards ---- */
.mot-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 30px 0 4px; }
.mot-card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px 22px; box-shadow: var(--shadow);
}
.mot-card .step-num {
  font-size: 12px; font-weight: 800; letter-spacing: .12em; color: var(--accent);
  background: #eef3fb; border-radius: 999px; padding: 4px 11px; display: inline-block;
}
.mot-card h4 { margin: 14px 0 8px; font-size: 18px; }
.mot-card p { font-size: 15.5px; color: var(--body); margin: 0; }
.mini-transform {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px;
  font-size: 12.5px; font-weight: 700;
}
.mini-transform .pill { padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.mini-transform .pill.s { background: #e8f4ec; color: #2f6b45; }
.mini-transform .pill.e { background: #e9f0fa; color: #27538f; }
.mini-transform .pill.p { background: #fbf2dd; color: #8a6412; }
.mini-transform .pill.err { background: #fceeeb; color: #a4483b; }
.mini-transform .arrow { color: var(--muted); }

/* ---- method flow ---- */
.flow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 28px 0 6px; }
.flow > article {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.flow .step-num {
  font-size: 11.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}
.flow h4 { margin: 10px 0 8px; font-size: 18px; }
.flow p { font-size: 15.5px; margin: 0 0 14px; }
.flow .micro { font-size: 13px; color: var(--muted); margin: 12px 0 0; }

.store-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.store-box { border-radius: 10px; padding: 10px 9px; text-align: center; border: 1px solid; }
.store-box b { display: block; font-size: 13px; }
.store-box span { font-size: 11.5px; opacity: .85; }
.store-box.s { background: #eaf5ee; border-color: #cfe6d8; color: #2f6b45; }
.store-box.e { background: #eef4fa; border-color: #d3e0f2; color: #27538f; }
.store-box.p { background: #fdf8ec; border-color: #eedebe; color: #8a6412; }

.route-bars { display: grid; gap: 9px; }
.route-bars div { display: grid; grid-template-columns: 78px 1fr 42px; align-items: center; gap: 10px; font-size: 13px; }
.route-bars i { display: block; height: 9px; border-radius: 999px; background: #eef1f5; position: relative; }
.route-bars i::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w);
  border-radius: 999px; background: var(--bar);
}
.route-bars b { text-align: right; font-size: 13px; color: var(--ink); }

.tiny-graph { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; font-size: 13px; }
.tiny-graph .node { border-radius: 9px; padding: 8px 11px; font-weight: 600; line-height: 1.35; }
.tiny-graph .node.e { background: #eef4fa; color: #27538f; }
.tiny-graph .node.s { background: #eaf5ee; color: #2f6b45; }
.tiny-graph .node.p { background: #fdf8ec; color: #8a6412; }
.tiny-graph .rel { font-size: 11.5px; font-weight: 800; color: #2c7a53; white-space: nowrap; }

/* ---- demo: chapters, question, answers ---- */
.chapters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.chapters .chapter {
  appearance: none; -webkit-appearance: none;
  text-align: left; background-color: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; font: inherit; font-size: 12.5px; font-weight: 700; color: var(--muted);
  cursor: pointer; transition: border-color .12s ease, color .12s ease, background-color .12s ease;
}
.chapters .chapter span { display: block; font-weight: 500; color: var(--ink); font-size: 13.5px; margin-top: 2px; }
.chapters .chapter:hover { border-color: #c3ccd8; }
.chapters .chapter.active { border-color: var(--accent); background-color: #eef3fb; color: var(--accent); }
.asset-links { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; font-size: 14px; }

.case-question {
  background: var(--bg-soft); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 18px 22px; margin-top: 26px;
}
.case-question .small-label { font-size: 11.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.case-question p { font-size: 19px; font-weight: 600; color: var(--ink); margin: 8px 0 6px; }
.case-question .gt { font-size: 15px; color: var(--muted); }
.case-question .gt b { color: #2c7a53; }

.answer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.answer-card { border-radius: var(--radius); padding: 20px 22px; border: 1px solid; }
.answer-card .card-label { display: flex; justify-content: space-between; font-size: 11.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
.answer-card h4 { font-size: 20px; margin: 12px 0 8px; letter-spacing: -.01em; }
.answer-card p { font-size: 15px; margin: 0; }
.answer-card.wrong { background: #fdf7f6; border-color: #f0cdc6; }
.answer-card.wrong .card-label, .answer-card.wrong h4 { color: #a4483b; }
.answer-card.right { background: #f5faf7; border-color: #c6e3d2; }
.answer-card.right .card-label, .answer-card.right h4 { color: #256b48; }

/* ---- results: metrics, tabs ---- */
.metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin: 28px 0 26px; }
.metric-grid article { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 22px; box-shadow: var(--shadow); }
.metric-grid .metric { font-size: 44px; font-weight: 800; letter-spacing: -.035em; color: var(--ink); line-height: 1; }
.metric-grid .metric span { font-size: 22px; margin-left: 2px; }
.metric-grid h4 { font-size: 17px; margin: 12px 0 6px; }
.metric-grid p { font-size: 13.5px; color: var(--muted); margin: 0; line-height: 1.5; }

.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.tabs button {
  appearance: none; -webkit-appearance: none;
  font: inherit; font-size: 14.5px; font-weight: 650; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 8px 18px; color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.result-panel[hidden] { display: none; }

.analysis-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 26px; }
.analysis-grid article { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.analysis-grid .small-label { font-size: 11.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.analysis-grid h4 { font-size: 18px; margin: 10px 0 8px; }
.analysis-grid p { font-size: 15px; margin: 0; }
.source-note { font-size: 13.5px; color: var(--muted); line-height: 1.6; margin-top: 18px; }

/* ---- citation copy ---- */
.cite-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cite-top span { font-size: 11.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.cite-top button {
  appearance: none; -webkit-appearance: none;
  font: inherit; font-size: 14px; font-weight: 650; cursor: pointer; color: var(--ink);
  background: #fff; border: 1px solid #d6dae1; border-radius: 999px; padding: 7px 16px;
}
.cite-top button:hover { background: var(--bg-soft); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 900px) {
  .mot-grid, .flow, .metric-grid, .answer-grid, .analysis-grid { grid-template-columns: 1fr; }
  .chapters { grid-template-columns: repeat(2, 1fr); }
}
