/* paper.css — Gwern-inspired typography and layout */

:root {
  --bg: #fcfcf8;
  --text: #1a1a1a;
  --text-secondary: #555;
  --accent: #b33;
  --link: #256;
  --border: #ddd;
  --code-bg: #f5f5f0;
  --max-width: 1500px;
  --sidebar-width: 300px;
  --margin-width: 240px;
}

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

html {
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

figure[id] {
  scroll-margin-top: 1rem;
}

body {
  font-family: 'Merriweather', 'Georgia', serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  margin: 0;
  padding: 0;
}

/* --- Layout: sidebar + centered article --- */

/* --- Article --- */
article {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 2.5rem 6rem;
}

@media (min-width: 900px) {
  article {
    /* Center in viewport, but always clear the sidebar */
    margin-left: max(var(--sidebar-width), calc(50vw - 400px));
    margin-right: 0;
  }
}

/* --- Header --- */
header {
  margin-bottom: 1rem;
  padding-bottom: 0;
}

header h1 {
  font-size: 1.75rem;
  line-height: 1.3;
  font-weight: 700;
  margin: 0 0 0.75rem;
  letter-spacing: -0.01em;
}

.authors {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.draft-notice {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.3em 0.7em;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 3px;
  font-size: 0.78rem;
  color: #856404;
  font-family: 'IBM Plex Mono', 'Menlo', 'Consolas', monospace;
}

/* --- Headings --- */
h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-top: 2.5em;
  margin-bottom: 0.75em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.01em;
}

h3 {
  font-size: 1.08rem;
  font-weight: 700;
  margin-top: 2em;
  margin-bottom: 0.5em;
  font-style: italic;
}

/* --- Body text --- */
p {
  margin: 0 0 1.3em;
  text-align: left;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* --- Sub/superscripts: prevent line-height jitter --- */
sub, sup {
  line-height: 0;
}

/* --- Links --- */
a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
a:hover {
  border-bottom-color: var(--link);
}

/* --- Citations --- */
cite {
  cursor: pointer;
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dotted var(--link);
  font-style: normal;
  font-size: 0.82em;
  vertical-align: super;
  line-height: 0;
  padding: 0 1px;
  transition: color 0.15s;
}
cite:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Figures --- */
figure {
  margin: 2em 0;
  padding: 0;
}

figure img, figure svg {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
  cursor: zoom-in;
}

figcaption {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.75em;
  line-height: 1.7;
}

figcaption strong {
  color: var(--text);
}

/* --- Placeholder markers --- */
.placeholder {
  background: #fff3cd;
  padding: 0.05em 0.3em;
  border-radius: 2px;
  font-family: 'IBM Plex Mono', 'Menlo', monospace;
  font-size: 0.88em;
  color: #856404;
  white-space: nowrap;
}

/* --- View code button --- */
.view-code-btn {
  display: inline-block;
  margin-top: 0.5em;
  padding: 0.25em 0.75em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: 'IBM Plex Mono', 'Menlo', monospace;
  transition: background 0.15s, color 0.15s;
}
.view-code-btn:hover {
  background: #eeeee8;
  color: var(--text);
}

/* --- Lists --- */
ul, ol {
  margin: 0 0 1em;
  padding-left: 1.5em;
}
li {
  margin-bottom: 0.25em;
}

/* --- Methods section: smaller subsection headers --- */
.methods-sub {
  font-size: 1rem;
  font-style: italic;
  font-weight: 600;
  margin-top: 1.5em;
  margin-bottom: 0.4em;
  border-bottom: none;
  padding-bottom: 0;
}

/* --- Math / equations --- */
.equation {
  display: block;
  text-align: center;
  margin: 1.5em 0;
  font-style: italic;
}
.equation-params {
  margin: 0.5em 0 1em 2em;
  font-size: 0.92rem;
}
.equation-params li {
  margin-bottom: 0.15em;
}

/* --- Reference list --- */
.reference-list {
  font-size: 0.85rem;
  line-height: 1.55;
  counter-reset: ref;
  list-style: none;
  padding-left: 0;
}
.reference-list li {
  counter-increment: ref;
  margin-bottom: 0.9em;
  padding-left: 2.5em;
  text-indent: -2.5em;
}
.reference-list li::before {
  content: "(" counter(ref) ") ";
  font-weight: 600;
  color: var(--text-secondary);
}
.reference-list .ref-title {
  /* title is not specially styled — just inline text */
}
.reference-list .ref-journal {
  font-style: italic;
}
.reference-list a {
  word-break: break-all;
  font-size: 0.92em;
}

/* --- TOC Sidebar --- */
#toc-sidebar {
  display: none;
}

@media (min-width: 900px) {
  #toc-sidebar {
    display: block;
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    height: 100vh;
    padding: 2rem 1rem 2rem 1.5rem;
    font-size: 0.78rem;
    line-height: 1.6;
    overflow-y: auto;
  }
  #toc-sidebar .toc-title {
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 0.5em;
  }
  #toc-sidebar ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  #toc-sidebar li {
    margin-bottom: 0.15em;
  }
  #toc-sidebar a {
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: none;
    display: block;
    padding: 0.15em 0 0.15em 0.5em;
    border-left: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
  }
  #toc-sidebar a:hover {
    color: var(--text);
  }
  #toc-sidebar a.active {
    color: var(--text);
    font-weight: 600;
    border-left-color: var(--accent);
  }
  #toc-sidebar .toc-h3 a {
    padding-left: 2em;
    font-size: 0.95em;
  }
}

/* --- Mobile TOC --- */
@media (max-width: 899px) {
  #toc-mobile {
    margin: 0 0 2em;
    padding: 1em;
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.82rem;
  }
  #toc-mobile .toc-title {
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 0.5em;
    cursor: pointer;
  }
  #toc-mobile ul {
    list-style: none;
    padding: 0;
    margin: 0;
  }
  #toc-mobile li {
    margin-bottom: 0.1em;
  }
  #toc-mobile a {
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: none;
  }
  #toc-mobile a:hover {
    color: var(--text);
  }
  #toc-mobile .toc-h3 {
    padding-left: 1em;
  }
}

/* --- Sidenotes --- */
.sidenote {
  position: relative;
}
.sidenote-number {
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
  color: var(--accent);
  cursor: default;
}
.sidenote-content {
  display: none;
}

@media (min-width: 900px) {
  .sidenote-content {
    display: block;
    float: right;
    clear: right;
    margin-right: calc(-1 * var(--margin-width) - 1rem);
    width: calc(var(--margin-width) - 2rem);
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
    padding-left: 1rem;
    border-left: 1px solid var(--border);
  }
}

@media (max-width: 899px) {
  .sidenote-content {
    display: block;
    margin: 0.5em 0 0.5em 1.5em;
    padding: 0.5em 0.75em;
    border-left: 2px solid var(--border);
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.45;
    background: var(--code-bg);
  }
}

/* --- Lightbox --- */
.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  cursor: zoom-out;
  justify-content: center;
  align-items: center;
}
.lightbox-overlay.active {
  display: flex;
}
.lightbox-overlay img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  cursor: zoom-out;
}

/* --- Responsive --- */
@media (max-width: 600px) {
  html { font-size: 16px; }
  article { padding: 1rem 1rem 4rem; }
  header h1 { font-size: 1.45rem; }
  h2 { font-size: 1.2rem; }
  figure { margin: 1.5em -0.5em; }
  figcaption { padding: 0 0.5em; }
}

/* --- Print --- */
@media print {
  body { font-size: 11pt; }
  #toc-sidebar, #toc-mobile, .view-code-btn, .draft-notice { display: none; }
  article { max-width: none; padding: 0; }
  a { color: var(--text); border: none; }
  cite { color: var(--text); border: none; }
}
