:root {
  --bg: #f3f4ee;
  --panel: #fffefa;
  --panel-soft: #e9ece2;
  --text: #171814;
  --muted: #686b61;
  --line: #d9ddcf;
  --accent: #246b53;
  --accent-strong: #164532;
  --signal: #b64c3a;
  --amber: #c4852c;
  --ink-soft: rgba(23, 24, 20, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(36, 107, 83, 0.09), transparent 260px),
    linear-gradient(140deg, rgba(182, 76, 58, 0.08), transparent 420px),
    var(--bg);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

.stem-shell {
  width: min(1100px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(88px + max(18px, env(safe-area-inset-top))) 16px max(28px, env(safe-area-inset-bottom));
}

.stem-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(255, 254, 250, 0.94);
  text-decoration: none;
  box-shadow: 0 12px 24px var(--ink-soft);
}

.stem-title {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.stem-title img {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  box-shadow: 0 14px 26px rgba(36, 107, 83, 0.18);
}

.stem-title p,
.stem-title h1 {
  margin: 0;
}

.stem-title p,
.output-heading p,
.stem-track p {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.stem-title h1 {
  overflow-wrap: anywhere;
  font-size: clamp(1.7rem, 6vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

.stem-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.stem-meta div {
  min-height: 72px;
  padding: 13px;
  background: rgba(255, 254, 250, 0.92);
}

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

.stem-meta strong {
  font-size: 1.04rem;
}

.stem-meta span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.8rem;
}

.stem-workspace {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.05fr);
  gap: 14px;
  align-items: start;
}

.input-panel,
.output-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.94);
  box-shadow: 0 18px 38px rgba(23, 24, 20, 0.08);
}

.input-panel {
  display: grid;
  gap: 12px;
  padding: 15px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.field input {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfaf6;
  outline: 0;
}

.field input:focus {
  border-color: color-mix(in srgb, var(--accent) 58%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent);
}

.source-actions,
.action-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.primary-button,
.secondary-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
  text-decoration: none;
}

.primary-button {
  border: 1px solid var(--accent);
  color: #fff;
  background: var(--accent);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.secondary-button,
.download-button {
  border: 1px solid color-mix(in srgb, var(--accent) 26%, var(--line));
  color: var(--accent-strong);
  background: color-mix(in srgb, var(--accent) 7%, #fff);
}

.drop-zone {
  display: grid;
  gap: 7px;
  min-height: 140px;
  padding: 16px;
  border: 1px dashed color-mix(in srgb, var(--accent) 42%, var(--line));
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(36, 107, 83, 0.08), rgba(255, 254, 250, 0.95)),
    var(--panel);
  cursor: pointer;
}

.drop-zone.is-hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, #fff);
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.drop-zone span,
.drop-zone small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.drop-zone strong {
  align-self: end;
  overflow-wrap: anywhere;
  font-size: 1.25rem;
  line-height: 1.15;
}

.engine-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.engine-card {
  min-height: 78px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 42%, #fff);
}

.engine-card.is-active {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--accent) 8%, #fff);
}

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

.engine-card strong {
  font-size: 0.94rem;
}

.engine-card span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.status-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.status-line.is-error {
  color: var(--signal);
}

.output-panel {
  display: grid;
  gap: 13px;
  min-height: 430px;
  padding: 15px;
}

.output-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.output-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.output-heading p,
.output-heading h2 {
  margin: 0;
}

.output-heading h2 {
  margin-top: 2px;
  font-size: 1.45rem;
  line-height: 1.1;
  letter-spacing: 0;
}

#jobBadge {
  flex: 0 0 auto;
  max-width: 42%;
  overflow: hidden;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--amber);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
  font-weight: 850;
  background: color-mix(in srgb, var(--amber) 7%, #fff);
}

#openFolderButton {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.global-seek {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 36%, #fff);
}

#globalSeekSlider {
  width: 100%;
  accent-color: var(--accent);
}

#globalSeekTime {
  min-width: 86px;
  color: var(--muted);
  text-align: right;
  font-size: 0.78rem;
  font-weight: 780;
  font-variant-numeric: tabular-nums;
}

.stem-stack {
  display: grid;
  gap: 10px;
}

.stem-track {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 116px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel-soft) 32%, #fff);
}

.stem-track[data-state="ready"] {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
  background: color-mix(in srgb, var(--accent) 5%, #fff);
}

.stem-track[data-state="processing"] {
  border-color: color-mix(in srgb, var(--amber) 42%, var(--line));
}

.stem-track p,
.stem-track h3 {
  margin: 0;
}

.stem-track h3 {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.stem-track audio {
  display: none;
}

.track-play-button,
.download-button {
  min-width: 78px;
  padding: 0 12px;
}

@media (max-width: 820px) {
  .stem-shell {
    padding-inline: 12px;
  }

  .stem-meta,
  .stem-workspace,
  .field-grid,
  .engine-panel {
    grid-template-columns: 1fr;
  }

  .stem-meta div {
    min-height: 62px;
  }

  .source-actions,
  .action-row {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .output-heading {
    display: grid;
  }

  .output-tools {
    justify-content: stretch;
  }

  .global-seek,
  .stem-track {
    grid-template-columns: 1fr;
  }

  #globalSeekTime {
    text-align: left;
  }
}
