:root {
  color-scheme: dark;
  --bg: #050607;
  --panel: #111418;
  --panel-2: #171b21;
  --line: #2f3843;
  --line-strong: #60748c;
  --text: #f6f8fb;
  --muted: #9aa6b5;
  --accent: #4f9dde;
  --accent-2: #67d0a5;
  --warning: #f2b15b;
  --danger: #ef767a;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(79, 157, 222, 0.12), transparent 320px),
    radial-gradient(circle at 78% 18%, rgba(103, 208, 165, 0.12), transparent 320px),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1680px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 20px 0 28px;
}

.app-header,
.audio-strip,
.panel {
  border: 1px solid rgba(96, 116, 140, 0.58);
  background: rgba(17, 20, 24, 0.88);
  box-shadow: var(--shadow);
}

.app-header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 18px;
  min-height: 96px;
  padding: 18px 20px;
  border-radius: 8px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(1.55rem, 2.1vw, 2.45rem);
}

h2 {
  font-size: 1.05rem;
}

.transport {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  gap: 8px;
}

.icon-button,
.text-button {
  border: 1px solid var(--line-strong);
  background: #1c222a;
  color: var(--text);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  font-size: 1.2rem;
}

.icon-button:hover,
.text-button:hover {
  border-color: var(--accent);
  background: #243140;
}

.text-button:disabled,
.icon-button:disabled {
  cursor: progress;
  opacity: 0.62;
}

.icon-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #041018;
}

.session-readout {
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, auto));
  gap: 8px;
}

.session-readout div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d10;
}

.readout-label {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.session-readout strong {
  display: block;
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
  font-size: 1.35rem;
}

.audio-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr) minmax(140px, 0.45fr);
  gap: 14px;
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
}

.audio-strip label {
  display: grid;
  grid-template-columns: 82px 1fr;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.audio-strip span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

select,
input[type="search"],
input[type="text"],
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080a0d;
  color: var(--text);
  outline: none;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 157, 222, 0.18);
}

select {
  height: 38px;
  padding: 0 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(560px, 1fr) minmax(280px, 340px);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  min-width: 0;
  border-radius: 8px;
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.text-button {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 800;
}

.search-box {
  display: block;
}

input[type="search"] {
  height: 42px;
  padding: 0 12px;
}

.group-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 14px;
}

.group-pill {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d10;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.group-pill.active {
  border-color: var(--accent);
  background: rgba(79, 157, 222, 0.2);
  color: var(--text);
}

.mix-list {
  display: grid;
  gap: 9px;
  max-height: calc(100vh - 294px);
  overflow: auto;
  padding-right: 4px;
}

.mix-card {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d10;
  color: var(--text);
  text-align: left;
}

.mix-card.active {
  border-color: var(--accent);
  background: #162334;
}

.mix-card strong {
  display: block;
  margin-bottom: 5px;
  line-height: 1.2;
}

.mix-card span {
  color: var(--muted);
  font-size: 0.83rem;
}

.editor-heading {
  align-items: start;
}

.editor-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.title-input {
  min-height: 42px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: clamp(1.35rem, 1.8vw, 2rem);
  font-weight: 850;
  line-height: 1.1;
}

.intent-input {
  min-height: 72px;
  resize: vertical;
  padding: 12px;
  color: #dce4ef;
  line-height: 1.45;
}

.timeline-card {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080a0d;
  overflow: hidden;
}

.timeline-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

#timelineCanvas {
  display: block;
  width: 100%;
  height: auto;
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 999px;
}

.delta {
  background: #7a89ff;
}

.theta {
  background: #7bd6ff;
}

.alpha {
  background: #67d0a5;
}

.beta {
  background: #f2b15b;
}

.gamma {
  background: #ef767a;
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
}

.stage-table {
  display: grid;
  gap: 9px;
  margin-top: 10px;
}

.stage-header {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 64px 64px 64px minmax(180px, 1.35fr) 38px;
  gap: 8px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.stage-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 64px 64px 64px minmax(180px, 1.35fr) 38px;
  gap: 8px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0d10;
}

.stage-row.selected {
  border-color: var(--accent);
  background: #111d2a;
}

.stage-row input {
  min-width: 0;
  height: 38px;
  padding: 0 9px;
}

.stage-row input[readonly] {
  border-color: rgba(103, 208, 165, 0.5);
  color: #d8f6eb;
}

.stage-tone-select {
  grid-column: 1 / -1;
  min-height: 36px;
}

.delete-stage {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #171b21;
  color: var(--muted);
}

.delete-stage:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.details-panel {
  display: grid;
  align-content: start;
  gap: 18px;
}

.details-panel section {
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.details-panel section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.details-panel select {
  margin-top: 12px;
}

.tone-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.tone-form label,
.saved-tone-picker {
  display: grid;
  gap: 6px;
}

.tone-form span,
.saved-tone-picker span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.tone-form input,
.tone-form select {
  min-height: 38px;
  padding: 0 9px;
}

.tone-form input[type="range"] {
  padding: 0;
}

.tone-number-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tone-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.saved-tone-picker {
  margin-top: 14px;
}

.support-text {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.wav-status {
  font-size: 0.82rem;
}

.band-readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #080a0d;
}

.band-readout strong {
  font-size: 1.2rem;
}

.band-readout span {
  color: var(--muted);
  font-weight: 800;
}

.json-output {
  height: 210px;
  margin-top: 12px;
  padding: 10px;
  resize: vertical;
  color: #c8d4e2;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.35;
}

.import-row {
  display: flex;
  gap: 8px;
  margin-top: 9px;
}

.file-button {
  display: inline-grid;
  place-items: center;
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(260px, 320px) minmax(520px, 1fr);
  }

  .details-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  }

  .details-panel section {
    padding: 0;
    border: 0;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding-top: 10px;
  }

  .app-header {
    grid-template-columns: 1fr;
  }

  .transport {
    grid-template-columns: repeat(3, 1fr);
  }

  .icon-button {
    width: 100%;
  }

  .session-readout,
  .audio-strip,
  .workspace,
  .details-panel {
    grid-template-columns: 1fr;
  }

  .mix-list {
    max-height: 360px;
  }

  .stage-row {
    grid-template-columns: 1fr 64px 64px 64px 38px;
  }

  .stage-header {
    display: none;
  }

  .stage-row input[data-field="state"] {
    grid-column: 1 / -1;
  }

  .tone-number-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .audio-strip label {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .panel-heading,
  .stage-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-actions {
    justify-content: stretch;
  }

  .editor-actions .text-button,
  .panel-heading .text-button {
    width: 100%;
  }

  .stage-row {
    grid-template-columns: 1fr 1fr;
  }

  .stage-row input[data-field="name"],
  .stage-row input[data-field="state"] {
    grid-column: 1 / -1;
  }
}
