/* Galley — editorial base stylesheet. Palette and type per STYLE.md. */

:root {
  --paper: #FBF9F4;
  --paper-sunk: #F2EEE3;
  --surface: #FFFFFF;
  --ink: #211C16;
  --ink-muted: #6F6657;
  --rule: #E4DCC9;
  --burgundy: #7C2D2D;
  --burgundy-dark: #5E2020;
  --gold: #B07D2B;
  --success: #3F6B4F;
  --error: #9A3434;

  --serif: 'Spectral', Georgia, 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --app-width: 1100px;
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 0.4em;
}

a { color: var(--burgundy); }
a:hover { color: var(--burgundy-dark); }

/* ---- Top bar ---------------------------------------------------------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

.topbar-inner {
  max-width: var(--app-width);
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}
.wordmark-logo {
  height: 64px;
  width: auto;
  display: block;
}
.wordmark-text {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topnav {
  display: flex;
  align-items: baseline;
  gap: 18px;
}

.topnav-link { text-decoration: none; font-size: 14px; }
.topnav-user { color: var(--ink-muted); font-size: 14px; }
.topnav-form { margin: 0; }

.linkbtn {
  background: none;
  border: none;
  color: var(--burgundy);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  padding: 0;
}
.linkbtn:hover { color: var(--burgundy-dark); }

/* ---- Layout ----------------------------------------------------------- */

.app {
  max-width: var(--app-width);
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.hero {
  text-align: center;
  padding: 80px 24px;
}
.hero-title { font-size: 44px; }
.hero-lede { font-size: 19px; color: var(--ink-muted); max-width: 46ch; margin: 0 auto 8px; }
.hero-note { font-size: 15px; color: var(--ink-muted); }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-title { font-size: 30px; margin: 0; }
.page-sub { color: var(--ink-muted); margin: 4px 0 0; }

/* ---- Cards ------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px;
}

.card + .card { margin-top: 16px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* ---- Buttons ---------------------------------------------------------- */

.btn {
  display: inline-block;
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background-color 0.12s ease;
}
.btn-primary {
  background: var(--burgundy);
  color: #fff;
}
.btn-primary:hover { background: var(--burgundy-dark); color: #fff; }
.btn-secondary {
  background: var(--surface);
  border-color: var(--rule);
  color: var(--ink);
}
.btn-secondary:hover { background: var(--paper-sunk); color: var(--ink); }
.btn:disabled, .btn[aria-disabled='true'] {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #7d2a2a; color: #fff; }

/* ---- Forms ------------------------------------------------------------ */

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 5px;
}
.input, .textarea, .select {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  color: var(--ink);
}
.textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus {
  outline: 2px solid var(--burgundy);
  outline-offset: -1px;
  border-color: var(--burgundy);
}

.form-narrow { max-width: 380px; }
.form-actions { display: flex; gap: 10px; align-items: center; }

/* ---- Messages --------------------------------------------------------- */

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 16px;
}
.flash-error { background: #f6e3e3; color: var(--error); border: 1px solid #e3c4c4; }
.flash-success { background: #e3efe6; color: var(--success); border: 1px solid #c4ddca; }

/* ---- Badges ----------------------------------------------------------- */

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--paper-sunk);
  color: var(--ink-muted);
}
.badge-format { background: #f3e7cf; color: var(--gold); }

/* ---- Meta text -------------------------------------------------------- */

.meta { color: var(--ink-muted); font-size: 13px; }
.muted { color: var(--ink-muted); }

/* ---- Rendered review content ----------------------------------------- */

.prose {
  max-width: 70ch;
}
.prose h1 { font-size: 32px; margin-top: 0; }
.prose h2 { font-size: 23px; margin-top: 1.4em; }
.prose h3 { font-size: 18px; margin-top: 1.2em; }
.prose p { margin: 0 0 1em; }
.prose strong { font-weight: 600; }
.prose ul, .prose ol { padding-left: 1.4em; }

/* Pitch-angle line — gold left rule, per STYLE.md. */
.prose p strong:first-child { color: var(--ink); }
.prose blockquote,
.prose .pitch {
  border-left: 3px solid var(--gold);
  padding-left: 14px;
  margin-left: 0;
  color: var(--ink);
}

/* ---- Streaming caret -------------------------------------------------- */

.caret::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1.05em;
  background: var(--burgundy);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: caret-blink 1s step-end infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

/* ---- Utility ---------------------------------------------------------- */

.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 12px; align-items: center; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---- Auth pages ------------------------------------------------------- */

.auth {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
}
.auth-title { font-size: 26px; margin-bottom: 2px; }
.auth-sub { color: var(--ink-muted); margin: 0 0 20px; font-size: 15px; }
.auth-submit { width: 100%; }
.auth-alt {
  margin: 18px 0 0;
  font-size: 14px;
  color: var(--ink-muted);
  text-align: center;
}
.auth-card-centered { text-align: center; }
.auth-card-centered .auth-sub { margin-bottom: 22px; }
.auth-card-centered .auth-submit { margin-top: 4px; }

/* ---- Manuscripts ------------------------------------------------------ */

.upload-card { margin-bottom: 24px; }
.upload-card h3 { margin-bottom: 14px; }
.upload-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 14px;
}
.upload-row .field { margin-bottom: 14px; }
input[type='file'].input { padding: 7px; }

.manuscript-card {
  display: block;
  text-decoration: none;
  color: var(--ink);
  transition: border-color 0.12s ease;
}
.manuscript-card:hover { border-color: var(--burgundy); color: var(--ink); }
.manuscript-card-title { margin: 8px 0 6px; font-size: 19px; }

@media (max-width: 720px) {
  .upload-row { grid-template-columns: 1fr; }
}

/* ---- Document view ---------------------------------------------------- */

.doc-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.doc-view { padding: 32px 36px; }
.doc-view .prose { margin: 0 auto; }

/* ---- Generate panel --------------------------------------------------- */

.generate-panel { margin-bottom: 28px; }
.generate-panel h2 { margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
}
.field-hint { margin: 5px 0 0; font-size: 12px; }
.format-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.format-option {
  display: block;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.format-option:hover { border-color: var(--ink-muted); }
.format-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.format-option:has(input:checked) {
  border-color: var(--burgundy);
  background: #f7ecec;
}
.format-option-label {
  display: block;
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 2px;
}
.format-option-desc {
  display: block;
  font-size: 13px;
  color: var(--ink-muted);
  line-height: 1.45;
}
.gen-preview {
  margin-top: 18px;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
}
.gen-status { margin: 0 0 8px; }
.gen-preview-text {
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.6;
  max-height: 320px;
  overflow-y: auto;
  background: var(--paper-sunk);
  border-radius: var(--radius-sm);
  padding: 14px;
  color: var(--ink);
}

/* ---- Document list ---------------------------------------------------- */

.doc-list-section { margin-bottom: 28px; }
.doc-list-section h2 { margin-bottom: 12px; }
.doc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.doc-row + .doc-row { margin-top: 10px; }
.doc-row-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: var(--ink);
}
.doc-row-main:hover .doc-row-title { color: var(--burgundy); }
.doc-row-title {
  font-weight: 500;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Campaign chat ---------------------------------------------------- */

.chat-section { margin-bottom: 28px; }
.chat-section h2 { margin-bottom: 4px; }
.chat-thread {
  max-height: 460px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 16px 0;
  padding: 4px;
}
.chat-msg { display: flex; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-assistant { justify-content: flex-start; }
.chat-msg-body {
  max-width: 82%;
  padding: 10px 15px;
  border-radius: 12px;
  font-size: 15px;
}
.chat-msg-user .chat-msg-body {
  background: var(--burgundy);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-msg-assistant .chat-msg-body {
  background: var(--paper-sunk);
  color: var(--ink);
  border-bottom-left-radius: 3px;
}
.chat-msg-text { white-space: pre-wrap; }
.chat-msg-body.prose { max-width: 82%; }
.chat-msg-body.prose > :first-child { margin-top: 0; }
.chat-msg-body.prose > :last-child { margin-bottom: 0; }
.chat-empty { text-align: center; padding: 24px 0; }
.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  min-height: 48px;
}

/* ---- Book memory ------------------------------------------------------ */

.memory-section { margin-bottom: 28px; }
.memory-section h2 { margin-bottom: 4px; }
.memory-intro { margin-top: 0; margin-bottom: 14px; }
.memory-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}
.memory-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--rule);
}
.memory-item:first-child { border-top: 1px solid var(--rule); }
.memory-item-body { flex: 1; }
.memory-item-meta {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-shrink: 0;
}
.memory-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.memory-form .textarea {
  flex: 1;
  min-height: 46px;
}

/* ---- Sharing ---------------------------------------------------------- */

.shared-section { margin-top: 32px; }
.shared-section h2 { margin-bottom: 12px; }
.shared-note {
  background: var(--paper-sunk);
  color: var(--ink-muted);
  border: 1px solid var(--rule);
}
.collaborators-section { margin-bottom: 28px; }
.collaborators-section h2 { margin-bottom: 4px; }

/* ---- Footer + sticky layout ------------------------------------------ */

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.app { flex: 1 0 auto; }

.sitefooter {
  flex-shrink: 0;
  border-top: 1px solid var(--rule);
  margin-top: 48px;
  background: var(--surface);
}
.sitefooter-inner {
  max-width: var(--app-width);
  margin: 0 auto;
  padding: 22px 24px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
.sitefooter-mark {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
}
.sitefooter-tag { color: var(--ink-muted); font-size: 13px; }

/* ---- Accessibility ---------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--burgundy);
  outline-offset: 2px;
  border-radius: 2px;
}
.format-option:has(input:focus-visible) {
  outline: 2px solid var(--burgundy);
  outline-offset: 2px;
}

/* ---- Responsive ------------------------------------------------------- */

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 6px 14px; }
  .app { padding: 24px 16px 48px; }
  .hero { padding: 56px 16px; }
  .hero-title { font-size: 34px; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .page-title { font-size: 25px; }
  .doc-view { padding: 22px 18px; }
  .chat-msg-body { max-width: 90%; }
  .doc-row { flex-wrap: wrap; }
}

/* ---- Print: document view -------------------------------------------- */

@media print {
  .topbar,
  .sitefooter,
  .doc-actions,
  .page-head .btn {
    display: none !important;
  }
  body { background: #fff; }
  .app { padding: 0; }
  .card,
  .doc-view {
    border: none;
    padding: 0;
  }
  .prose { max-width: none; }
}
