:root {
  color-scheme: dark;
  --bg: #0d0f13;
  --panel: #171a21;
  --panel-2: #20242d;
  --line: #343a46;
  --text: #f3f6fb;
  --muted: #9aa5b5;
  --accent: #31d3a3;
  --accent-2: #f2c14e;
  --warn: #ff7a59;
  --focus: #7dd3fc;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  padding-bottom: 96px;
  background:
    radial-gradient(circle at 78% 12%, rgba(49, 211, 163, 0.16), transparent 28rem),
    linear-gradient(135deg, #0d0f13 0%, #141820 46%, #111318 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(13, 15, 19, 0.88);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #08110e;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.quota span,
.eyebrow,
.track-card span,
.section-title span {
  color: var(--muted);
  font-size: 0.82rem;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item,
.track-actions button,
.secondary,
.primary,
.mode-tab {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  border-radius: 8px;
  min-height: 42px;
}

.nav-item {
  text-align: left;
  padding: 0 14px;
}

.nav-item.active,
.mode-tab.active,
.track-card.selected {
  border-color: rgba(49, 211, 163, 0.8);
  background: rgba(49, 211, 163, 0.12);
}

.quota {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.quota strong {
  display: block;
  font-size: 2rem;
  margin: 5px 0 12px;
}

.workspace {
  padding: 26px;
  min-width: 0;
}

.topbar,
.section-title,
.track-meta,
.player-controls,
.prompt-tools,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.2rem;
}

.top-actions,
.track-actions,
.mode-tabs {
  display: flex;
  gap: 8px;
}

.primary {
  background: var(--accent);
  color: #07100d;
  border-color: transparent;
  font-weight: 800;
  padding: 0 16px;
}

.small {
  min-height: 38px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  border-radius: 8px;
  font-size: 1.15rem;
}

.icon-button.large {
  width: 68px;
  height: 68px;
  font-size: 1.7rem;
  background: var(--accent);
  color: #06100d;
  border-color: transparent;
  box-shadow: 0 12px 32px rgba(49, 211, 163, 0.22);
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.studio-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.88fr) minmax(320px, 1.12fr);
  gap: 18px;
}

.creator-panel,
.now-playing,
.track-card,
.library-item,
.settings-grid {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(23, 26, 33, 0.88);
}

.creator-panel,
.now-playing {
  padding: 18px;
  overflow: hidden;
}

textarea {
  width: 100%;
  min-height: 180px;
  margin: 16px 0 12px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1218;
  color: var(--text);
  padding: 14px;
  line-height: 1.45;
}

.preset-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 12px;
}

.preset-button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10131a;
  color: var(--text);
  padding: 0 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-button:hover,
.preset-button.active {
  border-color: rgba(49, 211, 163, 0.8);
  background: rgba(49, 211, 163, 0.12);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  min-height: 34px;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.advanced {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
}

select,
input[type="number"],
input[type="text"] {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1218;
  color: var(--text);
  padding: 0 12px;
}

.generate-button {
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  color: #06100d;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.sticky-generate {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 12px max(14px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: linear-gradient(180deg, transparent, rgba(8, 10, 14, 0.94) 28%);
}

.sticky-generate-button {
  position: relative;
  max-width: 760px;
  margin: 0 auto;
  overflow: hidden;
  justify-content: space-between;
  padding: 0 18px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.36);
}

.sticky-generate-button:disabled {
  cursor: wait;
}

.sticky-progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: rgba(255, 255, 255, 0.28);
  transition: width 240ms ease;
}

.sticky-generate-copy,
.sticky-generate-button em {
  position: relative;
  z-index: 1;
}

.sticky-generate-copy {
  display: grid;
  gap: 2px;
  text-align: left;
}

.sticky-generate-copy strong,
.sticky-generate-copy small {
  display: block;
}

.sticky-generate-copy small {
  color: rgba(6, 16, 13, 0.72);
}

.sticky-generate-button em {
  min-width: 46px;
  text-align: right;
  font-style: normal;
  font-weight: 950;
}

.generate-button small {
  font-weight: 800;
  opacity: 0.7;
}

#coverCanvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 410px;
  border-radius: 8px;
  object-fit: cover;
  background: #0c0e12;
}

.track-meta {
  margin: 16px 0 10px;
}

.waveform {
  display: grid;
  grid-template-columns: repeat(48, 1fr);
  align-items: center;
  gap: 3px;
  height: 72px;
  padding: 0 2px;
}

.waveform span {
  display: block;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), #7dd3fc);
  min-height: 6px;
}

.timebar {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  gap: 10px;
  align-items: center;
  flex: 1 1 240px;
  width: 100%;
  color: var(--muted);
}

.player-controls {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.transport {
  min-width: 44px;
  font-size: 0.82rem;
  font-weight: 900;
}

.volume-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

input[type="range"] {
  width: 100%;
  min-height: 32px;
  accent-color: var(--accent);
  cursor: pointer;
  touch-action: pan-x;
}

.track-actions {
  margin-top: 14px;
}

.track-breakdown {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10131a;
  padding: 12px;
  position: relative;
  overflow: hidden;
}

.breakdown-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.breakdown-head h3 {
  margin: 2px 0 0;
  font-size: 1rem;
}

.breakdown-head span {
  color: var(--muted);
  font-size: 0.78rem;
}

.arrangement-grid {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  cursor: crosshair;
  max-width: 100%;
  overscroll-behavior-x: contain;
}

.playlist-shell {
  min-width: min(640px, calc(100vw - 58px));
}

.playlist-timeline {
  display: grid;
  grid-template-columns: repeat(var(--playlist-bars, 24), minmax(22px, 1fr));
  margin-left: 104px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.68rem;
  user-select: none;
}

.playlist-timeline span {
  min-height: 18px;
  border-left: 1px solid #273040;
  padding-left: 4px;
}

.playlist-body {
  position: relative;
  display: grid;
  gap: 8px;
  --playhead: 0;
}

.arrangement-lane {
  display: grid;
  grid-template-columns: 96px minmax(480px, 1fr);
  gap: 8px;
  align-items: stretch;
}

.lane-label {
  display: flex;
  align-items: center;
  min-height: 46px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.lane-clips {
  display: grid;
  gap: 4px;
  min-height: 46px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.055) 0 1px, transparent 1px calc(100% / var(--playlist-bars, 24))),
    #0d1016;
  border-radius: 6px;
  padding: 4px;
}

.arrangement-clip {
  min-width: 0;
  border: 1px solid #232a36;
  border-radius: 6px;
  background: #151a23;
  padding: 6px;
  opacity: 0.38;
  overflow: hidden;
}

.arrangement-clip.active {
  opacity: 1;
}

.arrangement-clip strong,
.arrangement-clip span,
.arrangement-clip em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arrangement-clip strong {
  font-size: 0.68rem;
  color: var(--text);
}

.arrangement-clip span,
.arrangement-clip em {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.64rem;
  font-style: normal;
}

.arrangement-clip.piano.active {
  background: rgba(49, 211, 163, 0.18);
  border-color: rgba(49, 211, 163, 0.42);
}

.arrangement-clip.lead.active {
  background: rgba(242, 193, 78, 0.18);
  border-color: rgba(242, 193, 78, 0.48);
}

.arrangement-clip.counter.active {
  background: rgba(125, 211, 252, 0.16);
  border-color: rgba(125, 211, 252, 0.42);
}

.arrangement-clip.guitar.active {
  background: rgba(248, 113, 113, 0.16);
  border-color: rgba(248, 113, 113, 0.42);
}

.arrangement-clip.bass.active,
.arrangement-clip.drums.active {
  background: rgba(168, 85, 247, 0.16);
  border-color: rgba(168, 85, 247, 0.42);
}

.arrangement-clip.fx.active {
  background: rgba(148, 163, 184, 0.16);
  border-color: rgba(148, 163, 184, 0.38);
}

.arrangement-clip.voice.active {
  background: rgba(236, 72, 153, 0.18);
  border-color: rgba(236, 72, 153, 0.44);
}

.playlist-playhead {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(104px + (100% - 104px) * var(--playhead));
  width: 2px;
  background: #ff4d6d;
  box-shadow: 0 0 0 1px rgba(255, 77, 109, 0.22), 0 0 18px rgba(255, 77, 109, 0.42);
  pointer-events: none;
  z-index: 5;
}

.playlist-playhead::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 50%;
  width: 12px;
  height: 12px;
  transform: translateX(-50%) rotate(45deg);
  background: #ff4d6d;
  border-radius: 3px;
}

.native-audio {
  width: 100%;
  margin-top: 12px;
  min-height: 40px;
  display: block;
  accent-color: var(--accent);
}

.track-actions button,
.secondary {
  padding: 0 14px;
}

.full-width {
  width: 100%;
  margin-top: 10px;
}

.generation-process {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10131a;
  padding: 12px;
  opacity: 0.78;
}

.generation-process.active {
  opacity: 1;
}

.process-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 800;
}

.process-head span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.process-head strong {
  flex: 0 0 auto;
  color: var(--accent);
}

.process-bar {
  height: 7px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #202633;
}

.process-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 220ms ease;
}

.process-steps {
  display: grid;
  gap: 7px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 0.82rem;
}

.process-steps li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
}

.process-steps li::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 999px;
  background: #3a4354;
}

.process-steps li.current {
  color: var(--text);
  font-weight: 800;
}

.process-steps li.current::before,
.process-steps li.done::before {
  background: var(--accent);
}

.agent-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10131a;
  padding: 12px;
}

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

.agent-head h3 {
  margin: 2px 0 0;
  font-size: 1rem;
}

.agent-head strong {
  color: var(--accent);
  font-size: 1.2rem;
}

.agent-grid {
  display: grid;
  gap: 8px;
}

.agent-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 54px;
  border: 1px solid #252c38;
  border-radius: 8px;
  background: #151a23;
  padding: 10px;
}

.agent-card strong,
.agent-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-card strong {
  font-size: 0.86rem;
}

.agent-card span {
  color: var(--muted);
  font-size: 0.74rem;
  margin-top: 3px;
}

.agent-card em {
  display: none;
}

.agent-card.piano {
  border-color: rgba(49, 211, 163, 0.34);
}

.agent-card.melody {
  border-color: rgba(242, 193, 78, 0.38);
}

.agent-card.orchestrator {
  background: rgba(125, 211, 252, 0.08);
  border-color: rgba(125, 211, 252, 0.42);
}

.results-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.track-card {
  padding: 14px;
  min-height: 76px;
}

.track-card strong,
.track-card span {
  display: block;
}

.library-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.library-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
}

.mini-cover {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: linear-gradient(135deg, #31d3a3, #f2c14e);
}

.library-item strong,
.library-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-item span {
  color: var(--muted);
  font-size: 0.88rem;
}

#lyricsOutput {
  margin: 14px 0 0;
  white-space: pre-wrap;
  line-height: 1.55;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10131a;
  padding: 18px;
  min-height: 430px;
  overflow: auto;
}

.engine-output {
  margin: 14px 0 0;
  white-space: pre-wrap;
  line-height: 1.45;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10131a;
  color: var(--muted);
  padding: 12px;
  max-height: 172px;
  overflow: auto;
  font-size: 0.84rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.wide {
  grid-column: 1 / -1;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%) translateY(120%);
  background: #f3f6fb;
  color: #0d0f13;
  border-radius: 8px;
  padding: 12px 16px;
  font-weight: 800;
  transition: transform 160ms ease;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px;
  }

  .nav-list {
    grid-template-columns: repeat(4, 1fr);
  }

  .nav-item {
    text-align: center;
    padding: 0 8px;
  }

  .quota {
    display: none;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .studio-grid,
  .results-row,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .studio-grid,
  .results-row {
    display: grid;
  }

  #coverCanvas {
    max-height: 340px;
  }
}

@media (max-width: 560px) {
  .topbar,
  .panel-head,
  .prompt-tools,
  .track-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .track-actions,
  .mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .advanced,
  .preset-strip {
    grid-template-columns: 1fr;
  }

  .nav-list {
    grid-template-columns: repeat(2, 1fr);
  }

  .track-actions button,
  .top-actions button,
  .mode-tab {
    width: 100%;
  }

  .workspace,
  .creator-panel,
  .now-playing {
    padding: 12px;
  }

  textarea {
    min-height: 138px;
  }

  .player-controls {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: center;
    gap: 8px;
  }

  .player-controls .icon-button {
    width: 100%;
    height: 46px;
  }

  .player-controls .icon-button.large {
    width: 100%;
    height: 58px;
    font-size: 1.55rem;
  }

  .timebar {
    grid-column: 1 / -1;
    grid-template-columns: 38px minmax(0, 1fr) 38px;
  }

  .arrangement-lane {
    grid-template-columns: 74px minmax(360px, 1fr);
  }

  .lane-label {
    font-size: 0.7rem;
  }

  .agent-card {
    grid-template-columns: minmax(0, 1fr);
  }

  .engine-output {
    max-height: 132px;
  }
}
