:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #2a2e38;
  --text: #e7e9ee;
  --muted: #9aa1b0;
  --accent: #7c5cff;
  --accent-2: #4dd0e1;
  font-family: "Iowan Old Style", "Georgia", ui-serif, serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

.app-header {
  padding: 2rem 1.5rem 1rem;
  text-align: center;
}
.app-header h1 { margin: 0 0 0.25rem; font-size: 2rem; }
.subtitle { color: var(--muted); margin: 0; }

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  max-width: 1100px;
  margin: 1rem auto;
  padding: 0 1.5rem;
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem 1.5rem;
  max-width: 1100px;
  margin: 0 auto 1rem;
}
.layout .panel { margin: 0; }

.panel h2 { margin-top: 0; font-size: 1.1rem; }

label { display: block; margin: 0.75rem 0 0.25rem; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: #0c0e13;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  font-size: 0.95rem;
}
textarea { font-family: ui-monospace, monospace; resize: vertical; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
}
.checkbox-row input { width: auto; margin: 0; }

button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  margin-top: 0.75rem;
  margin-right: 0.5rem;
}
button:disabled { background: #3a3d47; cursor: not-allowed; }
button:hover:not(:disabled) { filter: brightness(1.1); }

.status { color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem; white-space: pre-line; }
progress { width: 100%; margin-top: 0.5rem; }

hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

#preview-wrap { max-width: 900px; }
.hint { color: var(--muted); font-size: 0.85rem; }

/* ---- Booklet content (also what gets rendered to PDF) ---- */
#booklet {
  background: white;
  color: #1a1a1a;
  border-radius: 8px;
  padding: 0;
  max-height: 70vh;
  overflow: auto;
  font-family: "Iowan Old Style", Georgia, serif;
}

.booklet-page {
  padding: 2.5rem 2.5rem 1rem;
}

.cover-page {
  text-align: center;
  padding: 4rem 2rem;
  page-break-after: always;
}
.cover-page img.avatar, .cover-page .avatar-fallback {
  width: 96px; height: 96px; border-radius: 50%; object-fit: cover;
  margin: 0 auto 1rem;
}
.cover-page .avatar-fallback {
  display: flex; align-items: center; justify-content: center;
  background: #333; color: white; font-size: 2rem; font-weight: 600;
}
.cover-page h1 { font-size: 2.2rem; margin: 0.25rem 0; }
.cover-page .nip05 { color: #5b3fd6; font-size: 0.9rem; margin-bottom: 0.15rem; }
.cover-page .npub { color: #666; font-size: 0.85rem; word-break: break-all; }
.cover-page .about { max-width: 500px; margin: 1rem auto; color: #444; }
.cover-page .stats {
  display: flex; justify-content: center; gap: 2rem;
  margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid #ddd;
}
.cover-page .stats div { text-align: center; }
.cover-page .stats .stat-value { font-size: 1.3rem; font-weight: 600; display: block; }
.cover-page .stats .stat-label { font-size: 0.75rem; color: #888; text-transform: uppercase; letter-spacing: 0.03em; }
.cover-page .meta { color: #777; margin-top: 1.5rem; font-size: 0.8rem; }

/* Running account header, repeated on every printed page (screen: hidden) */
.print-header {
  display: none;
}

.toc { page-break-after: always; }
.toc h2 { border-bottom: 2px solid #ccc; padding-bottom: 0.4rem; }
.toc ul { list-style: none; padding: 0; }
.toc li { display: flex; justify-content: space-between; border-bottom: 1px dotted #ccc; padding: 0.3rem 0; }

.month-section { page-break-before: always; }
.month-heading {
  font-size: 1.6rem;
  border-bottom: 3px solid #333;
  padding-bottom: 0.3rem;
  margin-bottom: 1.25rem;
  break-after: avoid;
  page-break-after: avoid;
}

.post {
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid #e3e3e3;
  break-inside: avoid;
  page-break-inside: avoid;
}
.post.parent-post {
  background: #f6f6f8;
  border-left: 3px solid #bbb;
  padding: 0.75rem 1rem;
  margin-bottom: 0.25rem;
  border-radius: 4px;
  font-size: 0.92rem;
}
.post.parent-post .post-meta { color: #888; }
.reply-connector {
  margin: 0.15rem 0 0.5rem 1.1rem;
  color: #999;
  font-size: 0.85rem;
}

/* Keeps a parent post + its "reply below" connector + the reply itself
   together as one unit, so the pair never splits across a page break. */
.post-group {
  break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 1.5rem;
}
.post-group .post { margin-bottom: 0; }

.post-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.post-header .post-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.post-header .avatar-fallback.post-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #333;
  color: white;
  font-size: 0.55rem;
  font-weight: 600;
}
.post-author {
  font-weight: 600;
  font-size: 0.9rem;
  color: #222;
}

.post-meta {
  font-size: 0.8rem;
  color: #777;
}
.post-content {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 1rem;
}
.post-content a { color: #5b3fd6; }

.post-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.post-images img {
  max-width: 100%;
  border-radius: 6px;
  display: block;
}

.post-extra {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #666;
}

.embedded-quote {
  margin-top: 0.6rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  background: #fafafa;
  font-size: 0.92rem;
  break-inside: avoid;
  page-break-inside: avoid;
}
.embedded-quote .post {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}
.embedded-quote.quote-missing {
  color: #999;
  font-style: italic;
  font-size: 0.85rem;
}
.replies-block {
  margin-top: 0.5rem;
  padding-left: 1rem;
  border-left: 2px solid #eee;
}
.replies-block .post {
  border-bottom: none;
  margin-bottom: 0.6rem;
  padding-bottom: 0;
}
.replies-block .post-content { font-size: 0.9rem; }

.empty-state { color: #888; padding: 2rem; text-align: center; }

/* ---- Print / Save-as-PDF ---- */
@media print {
  @page { margin: 0.9in 0.75in 0.6in; }

  .app-header, .layout, .app-footer, #preview-wrap h2, #preview-wrap .hint {
    display: none !important;
  }
  body { background: white; }
  #preview-wrap { max-width: none; padding: 0; margin: 0; }
  #booklet {
    max-height: none;
    overflow: visible;
    border-radius: 0;
  }

  /* Repeats on every printed page (Chromium prints position:fixed elements
     once per page) so the account stays identifiable throughout the booklet. */
  .print-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    position: fixed;
    top: -0.65in;
    left: 0;
    right: 0;
    height: 0.5in;
    border-bottom: 1px solid #ccc;
    font-size: 0.8rem;
    color: #555;
  }
  .print-header img, .print-header .avatar-fallback {
    width: 22px; height: 22px; border-radius: 50%; object-fit: cover;
    background: #333; color: white; font-size: 0.7rem; font-weight: 600;
    display: flex; align-items: center; justify-content: center;
  }

  .cover-page, .toc, .month-section { page-break-after: always; }
  .post, .parent-post, .post-group, .embedded-quote, .replies-block {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .month-heading { break-after: avoid; page-break-after: avoid; }
  a { color: inherit; text-decoration: none; }
}
