/*
 * Shared styles for arXiv paper summaries (output/{id}/summary/summary.html).
 *
 * Link from any summary HTML (no Python required):
 *   <link rel="stylesheet" href="../../../summary.css">
 *
 * Paper-agnostic: typography, layout, figure sizing, tables, code blocks.
 */

:root {
  color-scheme: light dark;
  --text: #1a1a1a;
  --text-muted: #555;
  --bg: #fafafa;
  --surface: #fff;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --figure-bg: #f4f4f5;
  --code-bg: #f1f5f9;
  --max-content: min(72rem, 96vw);
  /* Fixed caps — avoids % resolving against viewport width */
  --max-figure-width: 30rem;
  --max-figure-height: 22rem;
  --max-video-width: 34rem;
  --radius: 6px;
  --space: 1.25rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #e8e8e8;
    --text-muted: #a1a1aa;
    --bg: #111;
    --surface: #1a1a1a;
    --border: #333;
    --accent: #60a5fa;
    --accent-hover: #93c5fd;
    --figure-bg: #222;
    --code-bg: #1e293b;
  }
}

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

.research-paper-body {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}

.research-paper-body {
  margin: 0;
  padding: 2rem max(1rem, 2vw) 3rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
}

/* Readable column; figures may use full inner width of this column */
.research-paper-body > :not(script) {
  max-width: var(--max-content);
  margin-left: auto;
  margin-right: auto;
}

/* Injected paper card (metadata + links + abstract) */
.paper-header {
  margin-bottom: 0.5rem;
}

.paper-header > h1 {
  margin-bottom: 0.75rem;
}

.paper-header .paper-meta {
  margin: 0.35rem 0;
  font-size: 0.95rem;
}

.paper-header .paper-dates {
  color: var(--text-muted);
}

.paper-links__title,
.paper-abstract h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1.25rem 0 0.75rem;
  padding-bottom: 0;
  border-bottom: none;
}

/* Links panel — inline chips with optional metrics */
.paper-links {
  margin: 0.35rem 0 0.75rem;
}

.link-groups {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.link-group__heading {
  margin: 0 0 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.link-chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.link-chip-item {
  margin: 0;
  max-width: 100%;
}

.research-paper-body .paper-links a.link-chip {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem 0.45rem;
  max-width: 100%;
  padding: 0.32rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 0.82rem;
  line-height: 1.25;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.research-paper-body .paper-links a.link-chip:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  color: var(--text);
}

.link-chip__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

.link-chip__svg {
  display: block;
}

.link-chip__label {
  font-weight: 600;
  white-space: nowrap;
}

.link-chip__metrics {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem 0.35rem;
  padding-left: 0.4rem;
  margin-left: 0.05rem;
  border-left: 1px solid var(--border);
  font-size: 0.74rem;
  color: var(--text-muted);
}

.link-metric {
  display: inline;
  white-space: nowrap;
}

.link-metric__value {
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.link-metric--badge {
  font-weight: 600;
  color: var(--text);
}

.link-metric + .link-metric::before {
  content: "·";
  margin-right: 0.35rem;
  opacity: 0.45;
}

.paper-abstract p {
  margin: 0 0 0.5rem;
}

.paper-header-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0 0;
}

/* Hero: title first, then full-width architecture figure */
.paper-hero {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.paper-hero-heading > h1 {
  margin-bottom: 0.35rem;
}

/* Override global figure caps — hero spans the full content column */
figure.paper-hero-media {
  margin: 0.25rem 0 0.5rem;
  padding: 0;
  width: 100%;
  max-width: none;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  text-align: center;
}

figure.paper-hero-media img.paper-hero-image {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: none;
  height: auto;
  margin: 0;
  border-radius: 8px;
  object-fit: contain;
  background: var(--figure-bg);
  border: 1px solid var(--border);
}

.paper-title-full {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.paper-description {
  margin: 0.75rem 0 0.85rem;
  font-size: 1.05rem;
  line-height: 1.6;
}

.paper-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  list-style: none;
  padding: 0;
  margin: 0;
}

.paper-tags li {
  margin: 0;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  line-height: 1.4;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--figure-bg);
  color: var(--text-muted);
}

/* Project-page demo showcase (below hero, above metadata) */
.paper-demos {
  margin: 1.75rem 0 1.25rem;
  padding-top: 0.25rem;
  border-top: 1px solid var(--border);
}

.paper-demos > h2 {
  font-size: 1.2rem;
  font-weight: 650;
  margin: 0 0 0.75rem;
  padding-bottom: 0;
  border-bottom: none;
}

.demo-snippet {
  margin: 0 0 1.25rem;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
}

.demo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: 1.25rem;
  width: 100%;
}

figure.demo-item {
  margin: 0;
  padding: 0.65rem;
  width: 100%;
  max-width: none;
  background: var(--figure-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

figure.demo-item video,
figure.demo-item img {
  display: block;
  width: 100%;
  max-width: 100%;
  max-height: none;
  height: auto;
  margin: 0;
  border-radius: 4px;
  object-fit: contain;
}

figure.demo-item figcaption {
  margin-top: 0.6rem;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text-muted);
  text-align: left;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.35rem;
  font-weight: 650;
  margin: 2.25rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
}

p {
  margin: 0 0 var(--space);
}

ul,
ol {
  margin: 0 0 var(--space);
  padding-left: 1.4rem;
}

li {
  margin-bottom: 0.35rem;
}

li > ul,
li > ol {
  margin-bottom: 0.35rem;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover {
  color: var(--accent-hover);
}

strong,
b {
  font-weight: 700;
}

em {
  font-style: italic;
}

/* Figures: hard cap on display size (source PNGs are often 2000px+) */
figure {
  margin: 1.75rem auto;
  padding: 0.75rem;
  width: fit-content;
  max-width: calc(var(--max-figure-width) + 1.5rem);
  background: var(--figure-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

figure img {
  display: block;
  max-width: var(--max-figure-width);
  max-height: var(--max-figure-height);
  width: auto;
  height: auto;
  object-fit: contain;
  margin: 0 auto;
  border-radius: 4px;
}

figure video {
  display: block;
  max-width: var(--max-video-width);
  width: auto;
  height: auto;
  margin: 0 auto;
  border-radius: 4px;
}

figcaption {
  margin-top: 0.65rem;
  padding: 0 0.25rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-muted);
  text-align: left;
}

/* Tables (metrics, ablations) */
table {
  width: 100%;
  margin: 1rem 0 var(--space);
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

caption {
  caption-side: top;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: left;
  color: var(--text-muted);
}

th,
td {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  text-align: center;
}

th {
  font-weight: 600;
  background: var(--figure-bg);
}

tr:nth-child(even) td {
  background: color-mix(in srgb, var(--figure-bg) 50%, transparent);
}

/* Equations / inline code in pre blocks */
pre {
  margin: 0 0 var(--space);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.5;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.math-display {
  margin: 1rem 0 var(--space);
  overflow-x: auto;
  text-align: center;
}

pre em {
  font-style: normal;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
    monospace;
}

/* Code analysis section (injected at end of guide) */
.paper-code {
  margin: 2.5rem auto 0;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}

.paper-code > h2 {
  margin-top: 0;
}

.paper-code h3 {
  margin-top: 1.25rem;
}

.paper-code pre {
  margin: 0.75rem 0 var(--space);
  padding: 0.85rem 1rem;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.88rem;
  line-height: 1.5;
}

.paper-code pre code {
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
    monospace;
}

/* Related papers (injected at end of guide) */
.paper-related {
  margin: 2.5rem auto 0;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}

.paper-related > h2 {
  margin-top: 0;
}

.related-paper-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1rem;
}

.related-paper-card {
  padding: 1rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--figure-bg) 40%, transparent);
}

.related-paper-name {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.related-paper-name a {
  color: inherit;
  text-decoration: none;
}

.related-paper-name a:hover {
  color: var(--link);
  text-decoration: underline;
}

.related-paper-title {
  font-size: 0.95rem;
  line-height: 1.45;
  margin-bottom: 0.35rem;
}

.related-paper-title a {
  color: var(--link);
  text-decoration: none;
}

.related-paper-title a:hover {
  text-decoration: underline;
}

.related-paper-id {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.related-paper-desc {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text);
}

/* Resources list at the bottom */
h2:last-of-type + ul {
  list-style: none;
  padding-left: 0;
}

h2:last-of-type + ul li {
  margin-bottom: 0.5rem;
}
