:root {
  --bg: #05060a;
  --bg-elevated: #111321;
  --bg-elevated-2: #181b2b;
  --accent: #6b8bff;
  --accent-soft: rgba(107, 139, 255, 0.15);
  --accent-strong: #9fd27b;
  --border-subtle: #262b40;
  --text: #f5f7ff;
  --text-muted: #a1a4c0;
  --error: #ff5c7c;
  --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.55);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --transition-fast: 0.15s ease-out;
  --transition-med: 0.22s ease-out;
  --grid-cols: 16;
}

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

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #131626 0, #05060a 55%);
  color: var(--text);
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.app-header {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  backdrop-filter: blur(12px);
  background: linear-gradient(to bottom, rgba(5, 6, 10, 0.96), rgba(5, 6, 10, 0.86));
  position: sticky;
  top: 0;
  z-index: 20;
}

.logo-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-dot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: radial-gradient(circle at 30% 20%, #9fd27b, #6b8bff);
  box-shadow: 0 0 18px rgba(159, 210, 123, 0.8);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}

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

.header-links {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}

.header-links a {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(18, 20, 33, 0.85);
}
.header-links a:hover {
  background: rgba(31, 36, 61, 0.95);
}

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
  max-width: 1320px;
  margin: 0 auto 18px;
}

.card {
  background: radial-gradient(circle at top left, rgba(107, 139, 255, 0.12), rgba(10, 11, 17, 0.96));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 16px 18px 16px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

/* Left panel */
.left-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-panel h2,
.project-panel h2,
.daw-panel h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.help-text {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

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

input[type="text"],
input[type="number"],
select,
textarea {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: rgba(9, 10, 18, 0.9);
  color: var(--text);
  padding: 7px 9px;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}
input:focus,
select:focus,
textarea:focus {
  border-color: rgba(107, 139, 255, 0.8);
  box-shadow: 0 0 0 1px rgba(107, 139, 255, 0.45);
  background: rgba(6, 7, 14, 1);
}

textarea {
  resize: vertical;
}

/* Buttons */
button {
  font-family: inherit;
  font-size: 13px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  padding: 7px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--transition-med), box-shadow var(--transition-med), transform var(--transition-med), border-color var(--transition-med), color var(--transition-med);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.primary-btn {
  background: linear-gradient(135deg, #6b8bff, #9fd27b);
  color: #05060a;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(54, 89, 255, 0.35);
  margin: 4px 0 6px;
}
.primary-btn:hover:not(:disabled) {
  box-shadow: 0 16px 36px rgba(54, 89, 255, 0.45);
  transform: translateY(-1px);
}

.secondary-btn {
  background: rgba(15, 17, 27, 0.9);
  color: var(--text);
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
}
.secondary-btn:hover:not(:disabled) {
  background: rgba(33, 38, 60, 0.9);
  border-color: rgba(107, 139, 255, 0.55);
}

.secondary-btn.small {
  padding: 4px 10px;
  font-size: 12px;
}

/* Status & progress */
.status {
  font-size: 12px;
  margin: 4px 0 4px;
}
.status-loading {
  color: var(--text-muted);
}
.status-ok {
  color: var(--accent-strong);
}
.status-error {
  color: var(--error);
}

.progress-container {
  margin: 4px 0 6px;
}
.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.progress-bar {
  width: 100%;
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
#model-progress-bar-inner {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6b8bff, #9fd27b);
  transition: width 0.08s linear;
}

/* Chips */
.ai-quick-examples {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
}
.chip {
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
  background: rgba(13, 15, 26, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.05);
  color: var(--text);
}
.chip:hover {
  background: rgba(36, 41, 69, 0.95);
}

/* Project panel */
.small-text {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* DAW panel */
.daw-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 14px 12px;
}

.daw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.transport {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(9, 10, 19, 0.9);
  color: var(--text);
  font-size: 13px;
}
.icon-btn:hover {
  background: rgba(30, 34, 55, 0.95);
  border-color: rgba(107, 139, 255, 0.6);
}
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.timeline-meta {
  display: flex;
  gap: 14px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Tracks & grid */
.tracks-container {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 10px;
  margin-top: 8px;
}

.tracks-sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.track-strip {
  background: var(--bg-elevated-2);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  border: 1px solid var(--border-subtle);
}

.track-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.track-name {
  font-size: 13px;
}

.track-controls {
  display: flex;
  gap: 4px;
}
.mute-btn,
.solo-btn {
  background: rgba(6, 7, 15, 0.9);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
  font-size: 11px;
  width: 22px;
  height: 22px;
  padding: 0;
}
.mute-btn.active {
  background: rgba(255, 92, 124, 0.18);
  border-color: rgba(255, 92, 124, 0.8);
  color: #ffc0d0;
}
.solo-btn.active {
  background: rgba(159, 210, 123, 0.2);
  border-color: rgba(159, 210, 123, 0.85);
  color: #e5ffd6;
}

.track-faders {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.track-faders input[type="range"] {
  width: 100%;
}

/* Grid & editors */
.grid-and-editors {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-grid-container,
.piano-roll-container {
  background: var(--bg-elevated-2);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  padding: 8px 10px 10px;
}

.step-grid-header,
.piano-roll-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.step-grid-header .label,
.piano-roll-header .label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Step grid */
.step-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), 1fr);
  gap: 2px;
}

.step-row {
  display: contents;
}

.step-cell {
  position: relative;
  height: 24px;
  border-radius: 5px;
  background: rgba(9, 10, 18, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.03);
  cursor: pointer;
  overflow: hidden;
}
.step-cell::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: linear-gradient(135deg, rgba(107, 139, 255, 0.15), rgba(159, 210, 123, 0.08));
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.step-cell.active::before {
  opacity: 1;
}
.step-cell:nth-child(4n + 1) {
  box-shadow: inset 1px 0 0 rgba(255, 255, 255, 0.05);
}

.footer-hint {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

/* Melody notes textarea */
#melody-notes {
  width: 100%;
  min-height: 80px;
}

/* Utility classes */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 960px) {
  .app-main {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 600px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .header-links {
    align-self: stretch;
    justify-content: space-between;
  }
  .tracks-container {
    grid-template-columns: 150px minmax(0, 1fr);
  }
}