:root {
  --bg: #0f0f17;
  --card: #1a1a26;
  --card-2: #222230;
  --text: #ececf4;
  --muted: #9a9ab0;
  --accent: #8b5cf6;
  --accent-2: #6d28d9;
  --error: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: rgba(15, 15, 23, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #26263a;
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.banner {
  max-width: 640px;
  margin: 12px auto 0;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: #2a2140;
  border: 1px solid var(--accent-2);
  font-size: 0.9rem;
}

.banner.error { background: #3a1d22; border-color: var(--error); }

.card {
  background: var(--card);
  border: 1px solid #26263a;
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field span { font-size: 0.85rem; color: var(--muted); }
.field em { font-style: normal; opacity: 0.7; }

.field-label { display: flex; align-items: center; gap: 6px; }

.help-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--card-2);
  border: 1px solid #32324a;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
}

/* Style preset chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 6px;
}

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #32324a;
  background: var(--card-2);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip.selected { border-color: var(--accent); background: #2a2140; }

.chip .chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
}

.chip .chip-x:hover { color: var(--error); }

.chip-add {
  border-style: dashed;
  color: var(--accent);
  font-weight: 600;
}

input[type="text"], textarea, select {
  width: 100%;
  background: var(--card-2);
  color: var(--text);
  border: 1px solid #32324a;
  border-radius: 10px;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
}

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

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

.segmented {
  display: flex;
  background: var(--card-2);
  border-radius: 10px;
  padding: 4px;
  gap: 4px;
}

.seg {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.seg.active { background: var(--accent-2); color: #fff; }

.panel { display: flex; flex-direction: column; gap: 14px; }

.tool-row { display: flex; gap: 10px; }
.tool-row button { flex: 1; }
.btn-label-short { display: none; }
@media (max-width: 420px) {
  .btn-label-full { display: none; }
  .btn-label-short { display: inline; }
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.advanced-panel, .style-panel { border: none; padding: 0; }

.advanced-panel > summary, .style-panel > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  user-select: none;
}

.advanced-panel > summary::before, .style-panel > summary::before {
  content: "▶";
  font-size: 0.65rem;
  transition: transform 0.15s;
  color: var(--accent);
}

.advanced-panel[open] > summary::before,
.style-panel[open] > summary::before { transform: rotate(90deg); }

/* The style + negative boxes wrap and grow to fit their content (autosized
   in app.js) rather than scrolling a single line horizontally. */
#style, #style-negative { resize: none; overflow: hidden; min-height: 0; }

.advanced-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #26263a;
  border-radius: 10px;
  background: var(--card-2);
}

button.primary {
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}

button.primary:disabled { opacity: 0.45; cursor: not-allowed; }

button.secondary {
  padding: 11px;
  border-radius: 12px;
  border: 1px solid var(--accent-2);
  background: transparent;
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button.secondary:disabled { opacity: 0.45; cursor: not-allowed; }

button.small { padding: 9px 16px; font-size: 0.9rem; }

/* Format preview */
.preview {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--accent-2);
  border-radius: 12px;
  background: #221c33;
}

.preview-title { font-size: 0.85rem; font-weight: 700; color: var(--accent); }

.preview pre {
  margin: 0;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 40vh;
  overflow-y: auto;
}

.preview-actions { display: flex; gap: 10px; }
.preview-actions button { flex: 1; }

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

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }

/* Active job */
.job { flex-direction: row; align-items: center; gap: 14px; }

.job-info { display: flex; flex-direction: column; gap: 2px; font-size: 0.95rem; }

.spinner {
  width: 28px;
  height: 28px;
  flex: none;
  border: 3px solid #32324a;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

/* Library */
.library h2 { font-size: 1.05rem; margin: 4px 0 12px; }

.song {
  background: var(--card);
  border: 1px solid #26263a;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.song.flash { animation: flash 1.6s ease-out; }

@keyframes flash {
  0% { border-color: var(--accent); box-shadow: 0 0 18px rgba(139, 92, 246, 0.45); }
  100% { border-color: #26263a; box-shadow: none; }
}

.song-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.song-head strong { font-size: 1rem; word-break: break-word; }
.song-head time { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }

.song audio { width: 100%; height: 40px; }

.song-meta {
  color: var(--muted);
  font-size: 0.82rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Blocking modal overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 16, 0.7);
  backdrop-filter: blur(3px);
}

.overlay-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 26px 34px;
  background: var(--card);
  border: 1px solid var(--accent-2);
  border-radius: var(--radius);
  font-size: 0.95rem;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

/* Details modal */
.modal-card {
  width: min(560px, 92vw);
  max-height: 86vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  background: var(--card);
  border: 1px solid #32324a;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 1.05rem; }

.modal-x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.title-row { display: flex; gap: 10px; }
.title-row input { flex: 1; }
.title-row button { flex: none; }

.detail-section { margin-top: 6px; }
.detail-section h4 {
  margin: 0 0 6px;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.detail-section pre {
  margin: 0;
  padding: 10px;
  background: var(--card-2);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 32vh;
  overflow-y: auto;
}

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 4px 14px; font-size: 0.88rem; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; word-break: break-word; }

/* Lyrics */
.lyrics summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  user-select: none;
}

.lyrics pre {
  margin: 8px 0 0;
  padding: 12px;
  background: var(--card-2);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 45vh;
  overflow-y: auto;
}

.song-actions { display: flex; justify-content: flex-end; gap: 4px; }

.song-actions button,
.song-actions a {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
  padding: 4px 8px;
  text-decoration: none;
}

.song-actions button:hover, .song-actions a:hover { color: var(--accent); }
.song-actions .danger:hover { color: var(--error); }

/* Remix panel */
.remix-src-box {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px dashed #32324a;
  border-radius: 10px;
  gap: 10px;
}

.remix-src-box .muted { margin: 0; font-size: 0.88rem; }

.remix-src-chosen {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.remix-src-name {
  flex: 1;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.remix-file-input { display: none; }

/* Remix intensity slider */
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row input[type="range"] {
  flex: 1;
  width: auto;
  height: 6px;
  appearance: none;
  background: #32324a;
  border: none;
  border-radius: 3px;
  padding: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.slider-row input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}

.slider-row input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--accent);
}

.slider-label {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  flex: none;
}
