:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --green: #4ecca3;
  --amber: #c9a227;
  --text: #eaeaea;
  --muted: #888;
  --radius: 12px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container { max-width: 900px; margin: 0 auto; }

header { text-align: center; margin-bottom: 2rem; }

h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--accent), #ff9a76);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle { color: var(--muted); margin-top: 0.25rem; }

/* ── Pipeline Steps ────────────────────────── */
.steps {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 2rem;
  justify-content: center;
  flex-wrap: wrap;
}

.step {
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--muted);
  transition: all 0.3s;
  user-select: none;
}

.step.active { background: var(--accent); color: white; }
.step.done { background: var(--green); color: var(--bg); }
.step.clickable { cursor: pointer; }
.step.clickable:hover { filter: brightness(1.2); transform: scale(1.05); }
.step.stale { background: var(--amber); color: var(--bg); }
.step.stale.clickable:hover { filter: brightness(1.2); transform: scale(1.05); }
.step.skipped { opacity: 0.45; cursor: default; font-style: italic; }

/* ── Common ────────────────────────────────── */
.section-title { font-size: 1.3rem; margin-bottom: 0.5rem; }
.section-desc { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.help-text { font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem; }
.error { color: var(--accent); margin-top: 1rem; font-size: 0.9rem; }
.hidden { display: none !important; }

.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: #333; color: var(--text); }
.btn-secondary:hover { background: #444; }
.btn-green { background: var(--green); color: var(--bg); }
.btn-green:hover { background: #6fe8bb; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Suggest Box ───────────────────────────── */
.suggest-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.suggest-box textarea, .chat-input textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #333;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  min-height: 80px;
  resize: vertical;
  margin-bottom: 0.75rem;
}

.suggest-box textarea:focus, .chat-input textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Suggestions ───────────────────────────── */
.suggestions { margin-top: 1.5rem; }

.suggestion {
  background: var(--surface2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.suggestion:hover { border-color: var(--accent); }
.suggestion .top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.4rem; }
.suggestion .name { font-weight: 700; font-size: 1rem; }

.confidence {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  background: var(--accent);
  color: white;
}

.suggestion .reasoning { color: var(--muted); font-size: 0.85rem; line-height: 1.4; }

.modifier-tag {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  background: #333;
  border-radius: 8px;
  color: var(--green);
}

/* ── Archetype Grid ────────────────────────── */
.archetype-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.archetype-card {
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: all 0.2s;
}

.archetype-card:hover { border-color: #444; transform: translateY(-2px); }
.archetype-card.selected { border-color: var(--accent); box-shadow: 0 0 20px rgba(233,69,96,0.2); }
.archetype-card.modifier-selected { border-color: var(--green); box-shadow: 0 0 20px rgba(78,204,163,0.2); }
.archetype-card .emoji { font-size: 1.8rem; margin-bottom: 0.5rem; }
.archetype-card .card-name { font-weight: 700; margin-bottom: 0.3rem; }
.archetype-card .emotional { color: var(--accent); font-size: 0.8rem; margin-bottom: 0.4rem; }
.archetype-card .desc { color: var(--muted); font-size: 0.8rem; line-height: 1.4; }

/* ── Selection Bar ─────────────────────────── */
.selection-bar {
  position: sticky;
  bottom: 1rem;
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  display: none;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
}

.selection-bar.visible { display: flex; }
.selection-bar .sel-text { font-size: 0.9rem; }
.selection-bar .sel-text strong { color: var(--accent); }
.selection-bar .sel-text .mod { color: var(--green); }

/* ── Chat (Intention Stage) ────────────────── */
.chat-container {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-height: 500px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.chat-msg {
  margin-bottom: 1rem;
  display: flex;
  gap: 0.75rem;
}

.chat-msg.assistant { flex-direction: row; }
.chat-msg.user { flex-direction: row-reverse; }

.chat-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.chat-msg.assistant .chat-avatar { background: var(--accent); }
.chat-msg.user .chat-avatar { background: var(--green); color: var(--bg); }

.chat-bubble {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.chat-msg.assistant .chat-bubble { background: var(--surface2); }
.chat-msg.user .chat-bubble { background: #1e3a5f; }

.chat-input {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

.chat-input textarea { min-height: 50px; margin-bottom: 0; flex: 1; }

.resolve-bar {
  background: var(--surface2);
  border: 1px solid var(--green);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.resolve-bar .resolve-text { color: var(--green); font-size: 0.9rem; }

/* ── Intention Summary ─────────────────────── */
.intention-summary {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1rem;
}

.intention-summary h3 { margin-bottom: 1rem; color: var(--green); }

.intent-field {
  margin-bottom: 0.75rem;
}

.intent-field .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.2rem;
}

.intent-field .value { font-size: 0.95rem; }

.anchor-tag {
  display: inline-block;
  background: var(--surface2);
  border: 1px solid #333;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  margin: 0.2rem;
  color: var(--accent);
  font-style: italic;
}

/* ── Footer ────────────────────────────────── */
footer {
  text-align: center;
  margin-top: 3rem;
  color: var(--muted);
  font-size: 0.8rem;
}

footer button {
  background: #333;
  border: none;
  color: var(--muted);
  padding: 0.3rem 0.8rem;
  border-radius: 6px;
  font-size: 0.7rem;
  cursor: pointer;
  margin-left: 0.5rem;
}

footer button:hover { background: var(--accent); color: white; }

/* ── Structure Stage ───────────────────────── */
.structure-header {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.struct-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.struct-meta .meta-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  display: block;
}

.structure-timeline {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.struct-section {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: grid;
  grid-template-columns: 140px 1fr 60px;
  align-items: center;
  gap: 0.75rem;
  position: relative;
  overflow: hidden;
}

.struct-section::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--accent);
  opacity: var(--energy, 0.5);
}

.struct-section .sec-label {
  font-weight: 600;
  font-size: 0.9rem;
}

.struct-section .sec-function {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.struct-section .sec-bars {
  text-align: right;
  font-size: 0.75rem;
  color: var(--muted);
}

.energy-bar {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--green), var(--accent));
  margin-top: 0.3rem;
  transition: width 0.3s;
}

/* ── Lyrics Stage ──────────────────────────── */
.lyrics-display {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
}

.lyrics-display .song-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--accent);
  text-align: center;
}

.lyric-section {
  margin-bottom: 1.5rem;
}

.lyric-section .sec-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.lyric-section .lyric-line {
  font-size: 1.05rem;
  line-height: 1.7;
  padding: 0.1rem 0;
}

.lyric-section .mood-note {
  font-size: 0.75rem;
  color: var(--green);
  font-style: italic;
  margin-top: 0.4rem;
}

/* ── Evaluation ────────────────────────────── */
.eval-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.eval-score {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.75rem;
  text-align: center;
}

.eval-score .score-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.eval-score .score-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.score-low { color: var(--accent); }
.score-mid { color: #f0c040; }
.score-high { color: var(--green); }

.eval-list {
  background: var(--surface);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.eval-list h4 {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.eval-list li {
  font-size: 0.85rem;
  line-height: 1.5;
  margin-left: 1rem;
  margin-bottom: 0.25rem;
}

.eval-list li.cliche { color: var(--accent); }
.eval-list li.strength { color: var(--green); }

/* -- Inline Edit Forms -------------------- */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.edit-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.edit-field label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.edit-select,
.edit-input,
.edit-textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid #333;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.edit-select:focus,
.edit-input:focus,
.edit-textarea:focus {
  outline: none;
  border-color: var(--green);
}

.edit-textarea {
  resize: vertical;
  min-height: 60px;
}

.edit-lyrics-area {
  min-height: 400px;
  line-height: 1.7;
  font-size: 1rem;
  white-space: pre-wrap;
}

/* ── Stale Stage Banner ────────────────────── */
.stale-banner {
  background: var(--amber);
  color: var(--bg);
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
}

.stale-banner .btn { font-size: 0.8rem; padding: 0.4rem 0.8rem; }

/* Back to songs button */
.step-back-btn {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.step-back-btn:hover {
  background: rgba(255,255,255,0.12);
  color: var(--text);
}
