/* ip-theme.css — Shared theme for Interactive Papers
   Supports dark (default) and light themes via [data-theme] */

:root, [data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2128;
  --border: #30363d;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent2: #7ee787;
  --accent3: #f0883e;
  --heading: #e6edf3;
  --pnum: #484f58;
  --btn-hover: #21262d;
  --btn-active-text: #0d1117;
  --blank-hover: #3d444d;
}

[data-theme="light"] {
  --bg: #faf9f6;
  --surface: #f0eeeb;
  --surface2: #e6e4e0;
  --border: #d0cdc8;
  --text: #2c2c2c;
  --text-dim: #6b6b6b;
  --accent: #2563eb;
  --accent2: #16a34a;
  --accent3: #dc6b16;
  --heading: #1a1a1a;
  --pnum: #9e9b96;
  --btn-hover: #e8e6e2;
  --btn-active-text: #ffffff;
  --blank-hover: #c5c2bd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.75;
  max-width: 720px;
  margin: 0 auto;
  padding: 80px 24px 80px;
  position: relative;
  overflow-x: visible;
}

/* ── Header ── */
header {
  text-align: center;
  margin-bottom: 16px;
}
header h1 {
  font-size: 1.8rem;
  color: var(--heading);
  margin-bottom: 6px;
  line-height: 1.3;
}
header .author {
  font-size: 1rem;
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
}

/* ── Headings ── */
h2 {
  font-size: 1.1rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 36px 0 16px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Body text ── */
p {
  margin-bottom: 14px;
  text-align: justify;
  hyphens: auto;
}
em { color: var(--heading); }

/* ── Code ── */
pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  overflow-x: auto;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text);
  margin: 20px 0;
  white-space: pre-wrap;
}
code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.85em;
  background: var(--surface);
  padding: 2px 5px;
  border-radius: 3px;
}

/* ── Superscripts / footnotes ── */
sup {
  font-size: 0.7em;
  line-height: 0;
  vertical-align: super;
}
sup a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
sup a:hover { text-decoration: underline; }

/* ── Figures ── */
figure {
  margin: 28px 0;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
figure img {
  max-width: 100%;
  height: auto;
}
figcaption {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-top: 12px;
  line-height: 1.5;
  text-align: left;
  font-style: italic;
}

/* ── Sections ── */
section { position: relative; }

/* ── Footnotes / References ── */
.footnotes, .references {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}
.references p {
  margin-bottom: 8px;
  text-indent: -2em;
  padding-left: 2em;
  font-size: 0.9rem;
}

/* ── Article footer ── */
.article-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.6;
}
.article-footer p { margin-bottom: 4px; }

/* ── Top bar ── */
#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 40px;
  z-index: 200;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 max(16px, calc(50vw - 360px));
}
#top-bar .mode-toggle {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}
/* Left group: study actions */
#top-bar .fc-quiz-toggle { order: 1; }
#top-bar .fc-study-toggle { order: 2; }
/* Right group — margin-left:auto pushes to right */
#top-bar .fc-author-toggle { order: 10; margin-left: auto; }
#top-bar .fc-anno-nav-btn { order: 11; }
#top-bar .para-picker-btn { order: 12; }
#top-bar .settings-gear { order: 13; }
#top-bar .ip-theme-toggle { order: 14; }

/* ── Paragraph numbers in margin ── */
p[data-pnum] { position: relative; }
p[data-pnum]::before {
  content: attr(data-pnum);
  position: absolute;
  right: calc(100% + 8px);
  top: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: inherit;
  line-height: inherit;
  color: var(--pnum);
  white-space: nowrap;
}

/* ── Theme toggle ── */
.ip-theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  color: var(--text-dim);
  transition: border-color 0.15s, color 0.15s;
}
.ip-theme-toggle:hover {
  border-color: var(--text-dim);
  color: var(--text);
}

/* ── Responsive ── */
@media (max-width: 600px) {
  body { padding: 20px 16px 60px; }
  header h1 { font-size: 1.4rem; }
  pre { font-size: 0.7rem; padding: 12px; }
}
