:root {
  --bg: #0c0a08;
  --bg-elevated: #15110d;
  --bg-panel: #1a1512;
  --bg-inset: #100d0a;
  --border: #2b241d;
  --text: #e8ddd0;
  --text-muted: #8d7c6a;
  --accent: #e2a253;
  --accent-soft: rgba(226, 162, 83, 0.16);
  --radius: 8px;
  --font: 'Space Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;

  --curve-stroke: var(--accent);
  --curve-fill: rgba(226, 162, 83, 0.14);
  --curve-grid: #2b241d;
  --curve-point: var(--accent);
  --curve-playhead: #e8ddd0;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.4;
  padding: 16px;
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* ---- header ---- */

.header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  flex-shrink: 0;
}

.song-name {
  flex: 1 1 180px;
  min-width: 0;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  color: var(--text);
}

.song-name:focus {
  outline: 1px solid var(--accent);
}

.seed-display {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.seed-display span {
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- shared controls ---- */

.btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
}

.btn-accent {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
}

.select {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 6px 8px;
  min-width: 0;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  background: transparent;
}

output {
  color: var(--text-muted);
  min-width: 3ch;
  text-align: right;
  flex-shrink: 0;
}

/* segmented toggle */

.segmented {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg-btn {
  flex: 1;
  background: var(--bg-inset);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 8px;
  cursor: pointer;
}

.seg-btn:last-child {
  border-right: none;
}

.seg-btn:hover {
  color: var(--text);
}

.seg-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---- curve ---- */

.curve-wrap {
  width: 100%;
  aspect-ratio: 16 / 6;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.curve-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- main layout ---- */

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
  gap: 12px;
  align-items: start;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.group {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0;
  min-width: 0;
}

.group legend {
  padding: 0 6px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  min-width: 0;
}

.field > span:first-child {
  width: 110px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.field > .select,
.field > input[type="range"] {
  flex: 1;
  min-width: 0;
}

.field > .segmented {
  flex: 1;
  min-width: 0;
}

/* ---- layers strip ---- */

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

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.layer-name {
  width: 70px;
  flex-shrink: 0;
  text-transform: capitalize;
  color: var(--text-muted);
}

.toggle-btn {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  padding: 4px 10px;
  cursor: pointer;
  font-size: 12px;
}

.toggle-btn.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.layer-vol {
  flex: 1;
  min-width: 50px;
}

.layer-vol-out {
  width: 5ch;
  font-size: 12px;
  white-space: nowrap;
  min-width: 4.5em;
  text-align: right;
}

/* ---- transport ---- */

.transport-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.transport-position {
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}

.progression {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  word-break: break-word;
}

/* ---- render ---- */

.render-buttons {
  display: flex;
  gap: 8px;
}

.render-buttons .btn {
  flex: 1;
}

.progress-bar {
  margin-top: 10px;
  height: 6px;
  background: var(--bg-inset);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s linear;
}

.render-status {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ---- library ---- */

.library-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.library-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  min-width: 0;
}

.library-row:last-child {
  border-bottom: none;
}

.library-info {
  min-width: 0;
}

.library-name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.library-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.empty {
  color: var(--text-muted);
  font-size: 12px;
}

/* ---- log ---- */

.log-actions {
  display: flex;
  gap: 8px;
}

.log-list {
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  font-size: 11px;
  line-height: 1.5;
}

.log-row {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
}

.log-row.log-warn {
  color: var(--accent);
}

.log-row.log-error {
  color: #e5484d;
}

/* ---- mobile (secondary) ---- */

@media (max-width: 720px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .field {
    flex-wrap: wrap;
  }

  .field > span:first-child {
    width: auto;
  }
}
