:root {
  --primary: #2d2a26;
  --accent: #d4af37;
  --bg: #f5f2eb;
  --card: #fff;
  --text: #333;
  --soft-orange: #f4b251;
  --danger: #a33;
  --muted: #777;
  --story-teal: #3d7a6e;
  --story-teal-soft: #e6f2ef;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Georgia, serif; background: var(--bg); color: var(--text); min-height: 100vh; }
input, textarea, select {
  width: 100%;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin: 0 0 14px;
  font-size: 1rem;
  background: #fff;
  font-family: Georgia, serif;
}
label {
  display: block;
  font-family: Arial, sans-serif;
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 6px;
}
button { font-family: Arial, sans-serif; cursor: pointer; }
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#lock-screen {
  position: fixed;
  inset: 0;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  color: #fff;
  padding: 20px;
}
.lock-box {
  background: rgba(255, 255, 255, 0.1);
  padding: 34px;
  border-radius: 14px;
  text-align: center;
  max-width: 420px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
.lock-box button {
  padding: 12px 20px;
  border: 0;
  border-radius: 30px;
  background: var(--soft-orange);
  color: var(--primary);
  font-weight: bold;
  width: 100%;
}

.site-header {
  background: var(--card);
  padding: 16px 18px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.site-header h1 { font-size: 1.75rem; color: var(--primary); margin: 8px 0 4px; }
.tagline { color: var(--muted); font-size: 0.95rem; margin-bottom: 14px; }
.top-nav { display: flex; gap: 8px; }
.btn-nav {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: #eee;
  color: var(--primary);
  font-weight: bold;
  font-size: 0.82rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#app-shell { max-width: 900px; margin: 0 auto; padding: 18px; }
.status {
  margin-bottom: 18px;
  padding: 12px;
  border-radius: 10px;
  background: #fff8df;
  border: 1px solid #ead28c;
  font-family: Arial, sans-serif;
  font-size: 0.9rem;
}
.panel {
  background: var(--card);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 20px;
  border: 1px dashed #ddd;
}
.panel-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  background: transparent;
  border: 0;
  font: inherit;
  font-weight: bold;
  color: var(--primary);
  min-height: 44px;
  align-items: center;
}
.section-head {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 8px 0 16px;
  align-items: center;
}
.section-head h2 { font-size: 1.35rem; color: var(--primary); }
.user-line { font-family: Arial, sans-serif; font-size: 0.85rem; color: var(--muted); }

.filter-bar {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 12px;
  margin-bottom: 16px;
  background: var(--card);
  padding: 14px;
  border-radius: 12px;
  border: 1px solid #eee;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
  border: 1px solid #eee;
}
.stat-num {
  display: block;
  font-size: 1.5rem;
  font-weight: bold;
  font-family: Arial, sans-serif;
  color: var(--primary);
}
.stat-label {
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
}

.vault-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.story-card {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
  border: 1px solid #eee;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
  margin-bottom: 14px;
}
.story-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.story-title { font-size: 1.15rem; color: var(--primary); }
.story-meta {
  font-family: Arial, sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 4px;
}
.story-theme {
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
  color: #555;
  margin-bottom: 12px;
  line-height: 1.45;
}
.story-card-status {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.story-card-status label {
  margin: 0;
  white-space: nowrap;
}
.story-card-status select { margin: 0; }
.story-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  font-weight: bold;
  background: #f0ebe3;
  white-space: nowrap;
}
.status-draft { background: #f0ebe3; color: #5c5346; }
.status-interview_complete { background: var(--story-teal-soft); color: var(--story-teal); }
.status-ready_for_ai { background: #e8f0fe; color: #1e4d8c; }
.status-story_generated { background: #f3e8ff; color: #6b21a8; }
.status-awaiting_review { background: #fff3d6; color: #8a6d1a; }
.status-ready_for_print { background: #e3f4ea; color: #2f6b45; }
.status-complete { background: #dbeafe; color: #1e3a5f; }

.btn {
  padding: 11px 18px;
  border: 0;
  border-radius: 999px;
  font-weight: bold;
  min-height: 44px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-gold { background: var(--soft-orange); color: var(--primary); }
.btn-ghost { background: #eee; color: var(--primary); }
.btn-danger { background: #f4dddd; color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; min-height: 36px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
  line-height: 1.6;
}
.empty-hint { font-family: Arial, sans-serif; font-size: 0.9rem; }

/* Interview */
.interview-shell {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid #eee;
}
.interview-prompt {
  font-size: 1.05rem;
  color: #444;
  margin: 8px 0 18px;
  line-height: 1.5;
}
.field-block { margin-bottom: 4px; }
.field-hint {
  font-family: Arial, sans-serif;
  font-size: 0.8rem;
  color: var(--muted);
  margin: -2px 0 8px;
  line-height: 1.4;
}
.req { color: var(--danger); }

.progress-bar-wrap {
  height: 8px;
  background: #eee;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--story-teal), var(--soft-orange));
  border-radius: 999px;
  transition: width 0.35s ease;
}
.progress-count {
  font-family: Arial, sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.progress-steps {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.progress-step {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: Arial, sans-serif;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 999px;
  background: #f5f0e8;
}
.progress-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ccc;
}
.progress-done .progress-dot { background: var(--story-teal); }
.progress-current {
  background: var(--story-teal-soft);
  color: var(--story-teal);
  font-weight: bold;
}
.progress-current .progress-dot { background: var(--story-teal); }

.interview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #eee;
}

.review-intro { margin-bottom: 14px; line-height: 1.5; }
.review-list { display: grid; gap: 10px; }
.review-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #f0ebe3;
}
.review-row dt {
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: bold;
  color: var(--muted);
  text-transform: uppercase;
}
.review-row dd {
  font-size: 0.98rem;
  line-height: 1.45;
  white-space: pre-wrap;
}
.future-note {
  margin-top: 18px;
  padding: 12px;
  border-radius: 10px;
  background: var(--story-teal-soft);
  font-family: Arial, sans-serif;
  font-size: 0.85rem;
  color: #2f5c53;
  line-height: 1.45;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 20px;
}
.modal-panel {
  background: var(--card);
  border-radius: 14px;
  padding: 22px;
  max-width: 420px;
  width: 100%;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.welcome-blurb {
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
  color: #555;
  line-height: 1.5;
  margin-bottom: 16px;
  padding: 14px;
  background: linear-gradient(135deg, #fff9f0, var(--story-teal-soft));
  border-radius: 12px;
}

/* —— Story Vault generation pipeline —— */
.pipeline-shell {
  max-width: 920px;
  margin: 0 auto;
  padding: 8px 0 40px;
}
.pipeline-head { margin-bottom: 14px; }
.pipeline-subtitle {
  font-family: Arial, sans-serif;
  font-size: 0.9rem;
  color: var(--muted);
  margin-top: 6px;
}
.pipeline-busy {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fff6e8;
  border: 1px solid #f0d9a8;
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
  color: #7a5a18;
}
.pipeline-error {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #fceeee;
  border: 1px solid #e8c1c1;
  font-family: Arial, sans-serif;
  font-size: 0.92rem;
  color: var(--danger);
  white-space: pre-wrap;
}
.pipeline-stage-list {
  list-style: none;
  display: grid;
  gap: 10px;
  margin: 16px 0 20px;
}
.pipeline-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid #ebe4d8;
}
.pipeline-stage-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  flex: 1 1 220px;
}
.pipeline-stage-marker {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  background: #ccc;
  flex-shrink: 0;
}
.pipeline-stage-complete .pipeline-stage-marker { background: var(--story-teal); }
.pipeline-stage-ready .pipeline-stage-marker { background: var(--soft-orange); }
.pipeline-stage-generating .pipeline-stage-marker {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(212, 175, 55, 0.25);
  animation: pipeline-pulse 1.2s ease-in-out infinite;
}
.pipeline-stage-label {
  font-family: Arial, sans-serif;
  font-weight: bold;
  color: var(--primary);
  margin-bottom: 2px;
}
.pipeline-stage-state {
  font-family: Arial, sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
}
.pipeline-stage-action { flex: 0 0 auto; }
.pipeline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 22px;
}
.pipeline-artifacts-empty,
.next-actions-note {
  font-family: Arial, sans-serif;
  font-size: 0.9rem;
  color: #555;
  line-height: 1.5;
}
.artifact-block {
  margin-bottom: 22px;
  padding: 16px;
  background: var(--card);
  border-radius: 12px;
  border: 1px solid #ebe4d8;
}
.artifact-block h3 {
  font-family: Arial, sans-serif;
  font-size: 1.05rem;
  color: var(--primary);
  margin-bottom: 10px;
}
.artifact-book-title {
  font-size: 1.15rem;
  margin-bottom: 14px;
  color: var(--story-teal);
}
.manuscript-pages { display: grid; gap: 12px; }
.manuscript-page {
  padding: 12px 0;
  border-top: 1px solid #f0ebe3;
}
.manuscript-page:first-child { border-top: 0; padding-top: 0; }
.manuscript-page-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: Arial, sans-serif;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.manuscript-page p {
  line-height: 1.55;
  white-space: pre-wrap;
}
.illustration-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.illustration-card {
  margin: 0;
  background: #faf7f1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #ebe4d8;
}
.illustration-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #eee;
}
.illustration-placeholder {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
  color: var(--muted);
  gap: 6px;
}
.illustration-card figcaption {
  padding: 8px 10px;
  font-family: Arial, sans-serif;
  font-size: 0.75rem;
  color: var(--muted);
}
@keyframes pipeline-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.75; }
}

@media (max-width: 768px) {
  .filter-bar { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .review-row { grid-template-columns: 1fr; gap: 4px; }
  .progress-label { display: none; }
  .progress-current .progress-label { display: inline; }
  .interview-actions .btn { flex: 1 1 calc(50% - 10px); }
  .pipeline-stage { align-items: stretch; }
  .pipeline-stage-action { width: 100%; }
  .pipeline-stage-action .btn { width: 100%; }
}
