/* paper.css -- Academic paper stylesheet for AI Papers project */

:root {
  --text:        #2c2416;
  --text-muted:  #6b5d4f;
  --bg:          #faf8f5;
  --bg-surface:  #f3efe9;
  --bg-code:     #eee9e0;
  --border:      #d9d0c3;
  --accent:      #8b4513;
  --accent-light:#c4956a;
  --link:        #7c3a12;
  --link-hover:  #5c2d0e;
  --max-width:   46rem;
}

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

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 3rem 1.5rem 5rem;
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-size: 1rem;
  line-height: 1.72;
  color: var(--text);
  background-color: var(--bg);
  max-width: var(--max-width);
  margin-left: auto;
  margin-right: auto;
  font-feature-settings: "kern" 1, "liga" 1, "onum" 1;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-family: 'Source Serif 4', 'Georgia', serif;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
}

h1 {
  font-size: 2rem;
  margin-top: 0;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
}

h2 {
  font-size: 1.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}

h3 {
  font-size: 1.2rem;
  color: var(--accent);
}

h4 {
  font-size: 1.05rem;
  font-style: italic;
}

/* Body text */
p {
  margin: 0 0 1.2rem;
}

strong {
  font-weight: 700;
  color: var(--text);
}

em {
  font-style: italic;
}

/* Links */
a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.15s;
}

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

/* Lists */
ul, ol {
  margin: 0 0 1.2rem;
  padding-left: 1.8rem;
}

li {
  margin-bottom: 0.35rem;
}

li > p {
  margin-bottom: 0.5rem;
}

/* Block quotes */
blockquote {
  margin: 1.5rem 0;
  padding: 0.8rem 1.2rem;
  border-left: 3px solid var(--accent-light);
  background: var(--bg-surface);
  color: var(--text-muted);
  font-style: italic;
}

blockquote p:last-child {
  margin-bottom: 0;
}

/* Horizontal rules */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem 0;
}

/* Code */
code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.85em;
  background: var(--bg-code);
  padding: 0.15em 0.35em;
  border-radius: 3px;
}

pre {
  margin: 1.5rem 0;
  padding: 1.2rem 1.4rem;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-x: auto;
  line-height: 1.5;
}

pre code {
  background: none;
  padding: 0;
  font-size: 0.82em;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: 0.92rem;
}

thead {
  border-bottom: 2px solid var(--accent);
}

th {
  font-weight: 700;
  text-align: left;
  padding: 0.6rem 0.8rem;
  color: var(--text);
}

td {
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}

tbody tr:hover {
  background: var(--bg-surface);
}

/* Images and figures */
img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 4px;
  border: 1px solid var(--border);
}

figure {
  margin: 2rem 0;
  text-align: center;
}

figcaption, img + em,
p:has(> img) + p > em:only-child {
  display: block;
  text-align: center;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  line-height: 1.5;
}

/* Caption paragraphs: italic text immediately after an image */
p > img:only-child {
  margin-bottom: 0.3rem;
}

/* Math display blocks */
.math.display {
  overflow-x: auto;
  margin: 1.5rem 0;
  padding: 0.3rem 0;
}

/* Metadata block (author, year, source) */
p > strong:first-child:only-of-type {
  color: var(--text-muted);
}

/* First paragraph after h1 -- metadata styling */
h1 + p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* Print styles */
@media print {
  body {
    font-size: 11pt;
    max-width: none;
    padding: 0;
    color: #000;
    background: #fff;
  }

  h1 {
    border-bottom-color: #000;
  }

  h2 {
    border-bottom-color: #666;
  }

  a {
    color: #000;
    text-decoration: none;
  }

  pre, code {
    background: #f5f5f5;
    border-color: #ccc;
  }

  img {
    border: none;
  }
}

/* Responsive */
@media (max-width: 600px) {
  html {
    font-size: 16px;
  }

  body {
    padding: 1.5rem 1rem 3rem;
  }

  h1 {
    font-size: 1.6rem;
  }

  h2 {
    font-size: 1.3rem;
  }

  pre {
    padding: 0.8rem 1rem;
    font-size: 0.8em;
  }

  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 0.4rem 0.5rem;
  }
}
