:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #152033;
  --muted: #66758c;
  --line: #d8e0ec;
  --cyan: #00ffff;
  --pink: #ff69b4;
  --blue: #6495ed;
  --gray: #a9a9a9;
  --green: #1f8a62;
  --shadow: 0 18px 45px rgba(21, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 32px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 247, 251, 0.92);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow,
.section-kicker,
.panel-kicker {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1;
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.nav a:hover {
  background: #e9eef6;
  color: var(--ink);
}

main {
  padding: 28px 32px 40px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 0.58fr) minmax(620px, 1.42fr);
  gap: 24px;
  align-items: start;
}

.story,
.viewer-shell {
  min-width: 0;
}

.story {
  display: grid;
  gap: 18px;
}

.story-block {
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(21, 32, 51, 0.06);
}

.story-block h2 {
  margin-bottom: 14px;
  font-size: 26px;
  line-height: 1.15;
}

.story-block p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.innovation-grid {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.innovation-grid div {
  padding: 13px 14px;
  border-left: 3px solid var(--green);
  background: #f7fafc;
  border-radius: 6px;
}

.innovation-grid strong,
.innovation-grid span {
  display: block;
}

.innovation-grid strong {
  margin-bottom: 3px;
  font-size: 14px;
}

.innovation-grid span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.viewer-shell {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.viewer-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.selector-group {
  display: grid;
  gap: 6px;
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  min-width: 190px;
  height: 40px;
  padding: 0 36px 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
}

.mode-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mode-button {
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
}

.mode-button:hover,
.mode-button.active {
  border-color: #a8c0dd;
  background: #edf5fb;
  color: var(--ink);
}

.viewer-layout {
  display: grid;
  grid-template-columns: minmax(460px, 1fr) 230px;
  gap: 16px;
}

.viewer-panel {
  position: relative;
  min-height: 630px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f8;
}

.viewer {
  width: 100%;
  height: 630px;
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(238, 243, 248, 0.86);
  color: var(--muted);
  font-weight: 800;
}

.loading.hidden {
  display: none;
}

.metrics-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.metrics-panel h2 {
  margin-bottom: 0;
  font-size: 28px;
}

.metrics {
  display: grid;
  gap: 10px;
  margin: 0;
}

.metrics div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.metrics dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.metrics dd {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
}

.legend {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.legend p {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(21, 32, 51, 0.18);
  flex: 0 0 auto;
}

.gen-heavy {
  background: var(--cyan);
}

.gen-light {
  background: var(--pink);
}

.ref-ab {
  background: var(--blue);
}

.ref-ag {
  background: var(--gray);
}

.viewer-status {
  margin-top: auto;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.figures-section,
.edge-dynamics-section {
  margin-top: 32px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(21, 32, 51, 0.06);
}

.section-heading {
  max-width: 900px;
  margin-bottom: 24px;
}

.section-heading h2 {
  margin-bottom: 10px;
  font-size: 30px;
  line-height: 1.16;
}

.section-heading p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.figure-card {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(270px, 0.55fr);
  gap: 22px;
  align-items: center;
  margin: 0;
  padding: 24px 0;
  border-top: 1px solid var(--line);
}

.figure-card.reverse {
  grid-template-columns: minmax(270px, 0.55fr) minmax(0, 1.45fr);
}

.figure-card.reverse a {
  order: 2;
}

.figure-card.reverse figcaption {
  order: 1;
}

.figure-card a {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.figure-card img {
  display: block;
  width: 100%;
  height: auto;
}

.figure-card figcaption {
  min-width: 0;
}

.figure-label {
  margin-bottom: 8px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.figure-card h3 {
  margin: 0 0 12px;
  font-size: 23px;
  line-height: 1.2;
}

.figure-card figcaption p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.edge-dynamics-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.6fr);
  gap: 24px;
  align-items: start;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}

.edge-animation-card {
  min-width: 0;
  margin: 0;
}

.edge-animation-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.edge-gif-metrics {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.edge-animation-frame {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  aspect-ratio: 1458 / 768;
}

.edge-animation-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.edge-animation-card figcaption {
  padding-top: 16px;
}

.edge-animation-card h3,
.mechanism-callout h3 {
  margin: 0 0 10px;
  font-size: 22px;
  line-height: 1.2;
}

.edge-animation-card figcaption p,
.mechanism-callout p,
.edge-summary {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.edge-explanation {
  display: grid;
  gap: 16px;
}

.mechanism-callout {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.edge-evidence-grid {
  display: grid;
  gap: 10px;
}

.edge-evidence-grid article {
  padding: 14px;
  border-left: 3px solid var(--green);
  border-radius: 6px;
  background: #fbfcfe;
}

.edge-evidence-grid strong,
.edge-evidence-grid span {
  display: block;
}

.edge-evidence-grid strong {
  margin-bottom: 5px;
  font-size: 14px;
}

.edge-evidence-grid span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.edge-summary {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.paper-code-section {
  margin-top: 32px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 12px 30px rgba(21, 32, 51, 0.06);
}

.method-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.method-summary article {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafc;
}

.method-summary h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.method-summary p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.formula-code-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(480px, 1.1fr);
  gap: 18px;
  align-items: start;
}

.formula-list {
  display: grid;
  gap: 10px;
}

.formula-card {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.formula-card:hover,
.formula-card.active {
  border-color: #8fb5d6;
  background: #edf5fb;
}

.formula-card span {
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.formula-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.45;
}

.formula-card small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.code-link-panel {
  position: sticky;
  top: 92px;
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111827;
  color: #eef3f8;
  box-shadow: 0 18px 45px rgba(21, 32, 51, 0.16);
}

.code-panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.code-panel-header h3 {
  margin: 0;
  color: #ffffff;
  font-size: 20px;
}

.code-explanation {
  margin-bottom: 14px;
  color: #b8c6d8;
  font-size: 14px;
  line-height: 1.6;
}

.code-link-panel pre {
  max-height: 560px;
  margin: 0;
  overflow: auto;
  padding: 14px;
  border-radius: 8px;
  background: #0b1020;
  border: 1px solid rgba(238, 243, 248, 0.12);
}

.code-link-panel code {
  color: #dce7f7;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
}

@media (max-width: 1100px) {
  .workspace,
  .viewer-layout,
  .figure-card,
  .figure-card.reverse,
  .edge-dynamics-layout,
  .method-summary,
  .formula-code-layout {
    grid-template-columns: 1fr;
  }

  .figure-card.reverse a,
  .figure-card.reverse figcaption {
    order: initial;
  }

  .viewer-panel,
  .viewer {
    min-height: 560px;
    height: 560px;
  }

  .code-link-panel {
    position: static;
  }
}

@media (max-width: 760px) {
  .topbar,
  .viewer-toolbar,
  .edge-animation-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .nav {
    overflow-x: auto;
  }

  main,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .story-block,
  .viewer-shell,
  .figures-section,
  .edge-dynamics-section,
  .paper-code-section {
    padding: 16px;
  }

  .story-block h2,
  .section-heading h2 {
    font-size: 22px;
  }

  .mode-button {
    flex: 1 1 auto;
  }

  .viewer-panel,
  .viewer {
    min-height: 430px;
    height: 430px;
  }
}
