:root {
  --bg:        #0f0f13;
  --surface:   #1a1a24;
  --surface2:  #242433;
  --border:    #2e2e45;
  --accent1:   #7c3aed;
  --accent2:   #06b6d4;
  --text:      #e2e2f0;
  --muted:     #888899;
  --success:   #22c55e;
  --error:     #ef4444;
  --warning:   #f59e0b;
  --radius:    12px;
  --radius-sm: 6px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────── */
header {
  text-align: center;
  padding: 3rem 1rem 2rem;
  background: linear-gradient(180deg, #16162a 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

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

/* ── Layout ──────────────────────────────── */
main { max-width: 720px; margin: 0 auto; padding: 2rem 1rem 5rem; }

section { margin-bottom: 2.5rem; }

h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

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

/* ── Form ────────────────────────────────── */
.form-row { margin-bottom: 1.25rem; }

.form-row label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.optional { font-weight: 400; text-transform: none; letter-spacing: 0; opacity: 0.7; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 560px) { .two-col { grid-template-columns: 1fr; } }

input[type="text"],
input[type="email"],
textarea,
select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 0.65rem 0.9rem;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

textarea { resize: vertical; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23888899'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
  cursor: pointer;
}

input[type="text"]:focus,
input[type="email"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent1);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.15);
}

/* ── Lyric Helper ────────────────────────── */
.lyric-helper-row { margin-bottom: 1.25rem; }

.lyric-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.lyric-header label {
  /* override the block display from .form-row label */
  display: inline;
  margin-bottom: 0;
}

.lyric-tools {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.scheme-select {
  width: auto;
  min-width: 160px;
  padding: 0.4rem 2rem 0.4rem 0.65rem;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
}

.gen-lyrics-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.42rem 0.9rem;
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s, transform 0.1s;
}

.gen-lyrics-btn:hover { opacity: 0.88; }
.gen-lyrics-btn:active { transform: scale(0.97); }
.gen-lyrics-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-icon { font-size: 0.9rem; }

.lyrics-wrap { position: relative; }

.lyrics-wrap textarea {
  display: block;
  transition: opacity 0.2s;
}

.lyrics-wrap textarea.blurred { opacity: 0.3; pointer-events: none; }

.lyrics-spinner {
  position: absolute;
  inset: 0;
  display: none;          /* hidden by default; JS sets display:flex to show */
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(26,26,36,0.7);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.9rem;
  backdrop-filter: blur(2px);
  flex-direction: column;
}

.lyrics-spinner.visible { display: flex; }

.spinner-ring {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

.spinner-sub { font-size: 0.75rem; color: var(--muted); opacity: 0.7; }

.scheme-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.4rem;
  min-height: 1.1em;
  transition: opacity 0.2s;
}

/* ── Checkbox ────────────────────────────── */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.95rem;
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

.checkbox-label input[type="checkbox"] { display: none; }

.checkmark {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--surface2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.checkbox-label input:checked + .checkmark {
  background: var(--accent1);
  border-color: var(--accent1);
}

.checkbox-label input:checked + .checkmark::after {
  content: '';
  width: 5px; height: 9px;
  border: 2px solid white;
  border-top: none; border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

button[type="submit"] {
  margin-top: 0.25rem;
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: opacity 0.2s, transform 0.1s;
}

button[type="submit"]:hover  { opacity: 0.88; }
button[type="submit"]:active { transform: scale(0.99); }
button[type="submit"]:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.error-msg { color: var(--error); font-size: 0.88rem; margin-top: 0.6rem; }

/* ── Result Section ──────────────────────── */
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.result-header h2 { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }

.ghost-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.ghost-btn:hover { border-color: var(--accent1); color: var(--text); }

/* Generating card */
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
}

.generating-card { border-color: var(--accent1); }

.gen-animation {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.note-pulse {
  font-size: 2rem;
  animation: noteBounce 1.4s ease-in-out infinite;
  display: inline-block;
  color: var(--accent1);
}

.note-pulse.delay-1 { animation-delay: 0.2s; color: var(--accent2); }
.note-pulse.delay-2 { animation-delay: 0.4s; color: var(--accent1); }

@keyframes noteBounce {
  0%, 100% { transform: translateY(0) scale(1); opacity: 0.6; }
  50%       { transform: translateY(-10px) scale(1.15); opacity: 1; }
}

.gen-status-text {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.gen-status-sub { color: var(--muted); font-size: 0.88rem; }

.error-card { border-color: var(--error); }
.error-card p { color: var(--muted); margin-bottom: 1rem; }

/* Song cards in result */
.result-songs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.song-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.song-card:hover {
  border-color: var(--accent1);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(124,58,237,0.12);
}

.song-cover {
  width: 100%; aspect-ratio: 1; object-fit: cover; display: block;
}

.song-cover-placeholder {
  width: 100%; aspect-ratio: 1;
  background: linear-gradient(135deg, #16162a, #1e1e30);
  display: flex; align-items: center; justify-content: center;
  font-size: 3.5rem; color: var(--muted);
}

.song-body { padding: 1rem; }

.song-title {
  font-weight: 700; font-size: 1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 0.2rem;
}

.song-meta { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.65rem; }

.song-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.75rem; }

.tag {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 4px; padding: 0.1rem 0.45rem;
  font-size: 0.73rem; color: var(--muted);
}

.preview-label {
  font-size: 0.72rem; color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase; letter-spacing: 0.05em;
}

audio {
  width: 100%; height: 36px;
  accent-color: var(--accent1);
  display: block; margin-bottom: 0.75rem;
}

.download-btn {
  width: 100%; padding: 0.6rem;
  background: transparent;
  border: 1px solid var(--accent1);
  border-radius: var(--radius-sm);
  color: var(--accent1);
  font-size: 0.88rem; font-weight: 600;
  cursor: pointer; letter-spacing: 0.02em;
  transition: background 0.18s, color 0.18s;
}

.download-btn:hover:not(:disabled) { background: var(--accent1); color: white; }

.download-btn:disabled {
  opacity: 0.45; cursor: not-allowed;
  border-color: var(--muted); color: var(--muted);
}

/* ── Modal ───────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 1rem;
}

.modal-overlay[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem; width: 100%; max-width: 420px;
  position: relative;
}

.modal-close {
  position: absolute; top: 1rem; right: 1rem;
  background: none; border: none;
  color: var(--muted); font-size: 1.5rem;
  cursor: pointer; line-height: 1;
  padding: 0.2rem 0.4rem; border-radius: 4px;
  transition: color 0.15s;
}

.modal-close:hover { color: var(--text); }

.modal-box h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 0.3rem; }
.modal-song-name { font-size: 0.95rem; color: var(--accent2); margin-bottom: 0.75rem; font-weight: 600; }
.modal-desc { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.25rem; }
.modal-box .form-row { margin-bottom: 0.75rem; }

.pay-btn {
  margin-top: 1rem; width: 100%; padding: 0.85rem;
  background: linear-gradient(135deg, var(--accent1), var(--accent2));
  border: none; border-radius: var(--radius-sm);
  color: white; font-size: 1rem; font-weight: 700;
  cursor: pointer; letter-spacing: 0.02em; transition: opacity 0.2s;
}

.pay-btn:hover    { opacity: 0.88; }
.pay-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Success Banner ──────────────────────── */
.success-banner {
  position: fixed; bottom: 1.5rem; left: 50%;
  transform: translateX(-50%);
  background: var(--success); color: white;
  padding: 0.8rem 1.5rem 0.8rem 1.25rem;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.95rem;
  display: flex; align-items: center; gap: 0.75rem;
  box-shadow: 0 4px 16px rgba(34,197,94,0.3);
  z-index: 200; white-space: nowrap;
}

.success-banner[hidden] { display: none; }

.banner-close {
  background: none; border: none; color: white;
  font-size: 1.2rem; cursor: pointer;
  line-height: 1; padding: 0; opacity: 0.8;
}

.banner-close:hover { opacity: 1; }
