:root {
  --bg0: #1a1410;
  --bg1: #2a211a;
  --bg2: #3a2f24;
  --ink: #f4ebe0;
  --muted: #c4b4a2;
  --accent: #e8a84a;
  --accent-ink: #1a1410;
  --line: rgba(244, 235, 224, 0.12);
  --danger: #e07a6a;
  --ok: #8fbc8f;
  --radius: 14px;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Spectral", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #4a3420 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #2d3a2a 0%, transparent 50%),
    var(--bg0);
  color: var(--ink);
  font-family: var(--font);
}

body {
  min-height: 100dvh;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.view[hidden] { display: none !important; }

.brand {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 700;
}

h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 2rem;
  margin: 0.2rem 0 0.4rem;
}

.lead { color: var(--muted); margin: 0 0 1.5rem; }

.login-panel {
  margin: auto;
  width: 100%;
  max-width: 380px;
  padding: 28px 24px;
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

input, textarea, button {
  font: inherit;
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
  color: var(--ink);
  border-radius: 10px;
  padding: 12px 14px;
}

textarea { resize: vertical; min-height: 56px; }

button {
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: wait; }

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 8px 0 0;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.chat-top { align-items: center; }

.chat-title-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.title-input {
  text-align: right;
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 600;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 4px 0;
  border-radius: 0;
}

.title-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.status-pill {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg2);
  color: var(--muted);
}

.status-pill.suno_ready { color: var(--ok); }
.status-pill.lyrics_ok { color: var(--accent); }

.new-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 16px;
}

.project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.project-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: stretch;
}

.project-list button.card {
  width: 100%;
  text-align: left;
  border-radius: var(--radius);
  background: linear-gradient(120deg, rgba(42,33,26,0.9), rgba(58,47,36,0.7));
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 14px 16px;
  display: grid;
  gap: 4px;
}

.project-list .name { font-weight: 700; font-size: 1.05rem; }
.project-list .meta { color: var(--muted); font-size: 0.8rem; }

.project-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-action {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 12px;
  font-size: 1.15rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.project-action-danger {
  color: var(--danger);
  border-color: rgba(224, 122, 106, 0.35);
}

.project-action-danger:hover {
  border-color: rgba(224, 122, 106, 0.7);
}

.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 0 12px;
  min-height: 200px;
}

.bubble {
  max-width: 92%;
  padding: 12px 14px;
  border-radius: 16px;
  word-break: break-word;
  line-height: 1.5;
  font-size: 0.95rem;
}

.bubble.user {
  white-space: pre-wrap;
}

.bubble .md > *:first-child { margin-top: 0; }
.bubble .md > *:last-child { margin-bottom: 0; }

.bubble .md h1,
.bubble .md h2,
.bubble .md h3 {
  font-family: var(--display);
  font-weight: 600;
  line-height: 1.25;
  margin: 0.9em 0 0.35em;
  color: var(--ink);
}

.bubble .md h1 { font-size: 1.25rem; }
.bubble .md h2 { font-size: 1.12rem; color: var(--accent); }
.bubble .md h3 { font-size: 1.02rem; }

.bubble .md p {
  margin: 0.45em 0;
}

.bubble .md ul,
.bubble .md ol {
  margin: 0.4em 0 0.5em;
  padding-left: 1.25em;
}

.bubble .md li {
  margin: 0.2em 0;
}

.bubble .md strong {
  font-weight: 700;
  color: #fff8ee;
}

.bubble .md em {
  font-style: italic;
  color: var(--muted);
}

.bubble .md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
  background: rgba(0,0,0,0.28);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}

.bubble .md pre {
  margin: 0.55em 0;
  padding: 10px 12px;
  background: rgba(0,0,0,0.32);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  white-space: pre-wrap;
}

.bubble .md pre code {
  background: none;
  padding: 0;
  font-size: 0.88em;
}


.bubble .bubble-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

.bubble .md .suno-block,
.bubble .md .copyable {
  position: relative;
  margin: 0.65em 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: rgba(232, 168, 74, 0.08);
  border-radius: 0 10px 10px 0;
}

.bubble .md .suno-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.bubble .md .suno-block .label,
.bubble .md .copyable .label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  font-weight: 700;
}

.copy-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  min-width: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.copy-btn:hover {
  color: var(--accent);
  border-color: rgba(232, 168, 74, 0.5);
}

.copy-btn.is-copied {
  color: var(--ok);
  border-color: rgba(143, 188, 143, 0.55);
}

.bubble .md .suno-block .body,
.bubble .md .copyable .body {
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.86em;
  line-height: 1.4;
  color: inherit;
  overflow-x: auto;
}

.bubble.user {
  align-self: flex-end;
  background: #4a3a28;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.bubble.assistant {
  position: relative;
  padding-top: 36px;
  align-self: flex-start;
  background: rgba(244, 235, 224, 0.08);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.choice-panel {
  margin: 0 0 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(42,33,26,0.95), rgba(58,47,36,0.8));
  border: 1px solid var(--line);
  display: grid;
  gap: 12px;
}

.choice-panel[hidden] { display: none !important; }

.choice-panel .choice-title {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}

.choice-panel .pick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-panel .pick-row button {
  min-width: 44px;
}

.choice-panel .pick-row button.is-active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.choice-panel .line-grid {
  display: grid;
  gap: 8px;
}

.choice-panel .line-row {
  display: grid;
  grid-template-columns: 28px 64px 1fr;
  gap: 8px;
  align-items: center;
}

.choice-panel .line-row .n {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.choice-panel .line-row select {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,0.28);
  color: var(--ink);
  padding: 8px;
}

.choice-panel .line-row input {
  margin: 0;
  padding: 8px 10px;
}

.choice-panel .hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.choice-panel textarea {
  min-height: 64px;
}

.choice-panel .choice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 520px) {
  .choice-panel .line-row {
    grid-template-columns: 24px 56px 1fr;
  }
}

.run-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(232, 168, 74, 0.12);
  border: 1px solid rgba(232, 168, 74, 0.35);
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

.run-status[hidden] { display: none !important; }

.run-status.is-error {
  background: rgba(224, 122, 106, 0.12);
  border-color: rgba(224, 122, 106, 0.4);
  color: var(--danger);
}

.run-status.is-done {
  background: rgba(143, 188, 143, 0.12);
  border-color: rgba(143, 188, 143, 0.35);
  color: var(--ok);
}

.run-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(232, 168, 74, 0.55);
  animation: pulse-dot 1.2s ease-out infinite;
}

.run-status.is-error .run-dot,
.run-status.is-done .run-dot {
  animation: none;
  box-shadow: none;
}

.run-status.is-error .run-dot { background: var(--danger); }
.run-status.is-done .run-dot { background: var(--ok); }

@keyframes pulse-dot {
  0% { box-shadow: 0 0 0 0 rgba(232, 168, 74, 0.55); }
  70% { box-shadow: 0 0 0 10px rgba(232, 168, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(232, 168, 74, 0); }
}

.bubble.thinking {
  color: var(--muted);
  font-style: italic;
  border-style: dashed;
}

@media (max-width: 520px) {
  .actions button { flex: 1 1 auto; }
  .composer { grid-template-columns: 1fr; }
}
