:root {
  color-scheme: dark;
  --bg:           #0f1420;
  --panel:        #161d2d;
  --line:         #2a3447;
  --text:         #e6ebf5;
  --muted:        #a0adc5;
  --brand:        #2f6fdd;
  --brand-strong: #2457ad;
  --panel-soft:   #1b2436;
  --panel-hover:  #232f45;
  --chip-bg:      #1b2436;
  --chip-text:    #d8e0ef;
  --input-bg:     #121a29;
  --placeholder:  rgba(230, 235, 245, 0.14);
  --overlay:      rgba(5, 10, 18, 0.72);
}

[data-theme="light"] {
  color-scheme: light;
  --bg:           #f5f6f8;
  --panel:        #ffffff;
  --line:         #d9dce2;
  --text:         #1f2530;
  --muted:        #667085;
  --panel-soft:   #fafbfc;
  --panel-hover:  #eef1f6;
  --chip-bg:      #ffffff;
  --chip-text:    #273042;
  --input-bg:     #ffffff;
  --placeholder:  rgba(102, 112, 133, 0.75);
  --overlay:      rgba(15, 20, 30, 0.55);
}

* { box-sizing: border-box; }

[x-cloak] { display: none !important; }

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ── App shell ──────────────────────────────────────────────────────────── */

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Left rail ──────────────────────────────────────────────────────────── */

.left-rail {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.rail-brand {
  padding: 14px 14px 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-wordmark {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.new-creation {
  margin: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}

.new-creation:hover {
  background: var(--panel-hover);
}

.new-creation:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rail-section-header {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.creation-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  flex: 1;
}

.creation-list li {
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}

.creation-list li:hover {
  background: var(--panel-hover);
}

.creation-list li.active {
  border: 1px solid color-mix(in srgb, var(--brand) 45%, var(--line));
  background: color-mix(in srgb, var(--brand) 18%, var(--panel));
  color: #ffffff;
}

.creation-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.creation-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 600;
  flex-shrink: 0;
}

.badge-queued     { background: #fff3cd; color: #7a5800; }
.badge-processing { background: #dbeafe; color: #1e40af; }
.badge-finalizing { background: #ede9fe; color: #5b21b6; }
.badge-error      { background: #fee2e2; color: #991b1b; }
.badge-cancelled  { background: #f3f4f6; color: #6b7280; }

.rail-footer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.rail-footer button { flex: 1; }

.rail-footer button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.login-modal-lead {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.45;
}

.login-modal-hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── Main panel ─────────────────────────────────────────────────────────── */

.main-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Scrollable content area between header and footer */
.main-panel > div[x-show] {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}

.auth-state {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  padding: 24px;
  text-align: center;
}

.auth-card h3 {
  margin: 0 0 10px;
  font-size: 22px;
}

.auth-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.auth-card-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}

.auth-card-actions .primary {
  width: 100%;
}

.auth-card-actions button:not(.primary) {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.auth-card-actions button:not(.primary):hover {
  background: var(--panel-hover);
  color: var(--text);
}

.pre-start-state {
  position: relative;
  display: block;
  overflow: hidden;
}

.pre-start-state::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("./logo.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: min(44vw, 360px);
  opacity: 0.08;
  filter: grayscale(1) contrast(1.1);
  pointer-events: none;
}

[data-theme="light"] .pre-start-state::before {
  opacity: 0.06;
}

.pre-start-content {
  position: relative;
  position: absolute;
  left: 0;
  right: 0;
  bottom: clamp(22px, 6vh, 54px);
  z-index: 1;
  display: flex;
  justify-content: center;
  padding: 0 16px;
}

.pre-start-btn {
  font-size: 14px;
  padding: 12px 20px;
  min-width: 170px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}

/* ── Cards ──────────────────────────────────────────────────────────────── */

.composer-card,
.prompt-card,
.spec-card {
  margin: 16px 20px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.state-banner,
.result-details-card {
  margin: 16px 20px 0;
}

.state-banner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.state-banner.in-progress {
  color: #8dccff;
  background: rgba(79, 149, 241, 0.14);
}

.state-banner.is-done {
  color: #8af2c0;
  background: rgba(27, 168, 112, 0.17);
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #8dccff;
  box-shadow: 0 0 0 0 rgba(141, 204, 255, 0.6);
  animation: livePulse 1.5s ease-out infinite;
}

.done-check {
  width: 14px;
  height: 14px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(138, 242, 192, 0.3);
  color: #8af2c0;
  font-size: 11px;
}

@keyframes livePulse {
  0%   { box-shadow: 0 0 0 0 rgba(141, 204, 255, 0.6); }
  100% { box-shadow: 0 0 0 10px rgba(141, 204, 255, 0); }
}

.result-details-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px 16px;
}

.result-detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.result-detail-label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.arrangement-preview {
  margin-top: 6px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  background: var(--input-bg);
}

.prompt-card p {
  margin: 0;
  font-size: 20px;
  color: var(--text);
  line-height: 1.4;
}

.hero-play-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  color: #eef4ff;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.hero-play-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}

.hero-play-btn.centered {
  display: block;
  margin: 14px auto 0;
}

.spec-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 600;
  font-size: 14px;
}

.spec-card ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  font-size: 14px;
}

/* ── Form ───────────────────────────────────────────────────────────────── */

.field-row {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field-row label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.label-unit {
  font-weight: 400;
  font-size: 12px;
  opacity: 0.7;
}

.field-row textarea,
.field-row input[type="text"],
.field-row input[type="number"],
.field-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--input-bg);
  font-family: inherit;
  color: var(--text);
}

.field-row textarea::placeholder,
.field-row input[type="text"]::placeholder,
.modal-body input[type="text"]::placeholder {
  color: var(--placeholder);
  opacity: 1;
}

/* Safari/WebKit + older engines */
.field-row textarea::-webkit-input-placeholder,
.field-row input[type="text"]::-webkit-input-placeholder,
.modal-body input[type="text"]::-webkit-input-placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.field-row textarea::-moz-placeholder,
.field-row input[type="text"]::-moz-placeholder,
.modal-body input[type="text"]::-moz-placeholder {
  color: var(--placeholder);
  opacity: 1;
}

.field-row textarea {
  min-height: 80px;
  resize: vertical;
}

.field-row textarea:focus,
.field-row input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 111, 221, 0.1);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segment,
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.segment button,
.chips button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--chip-text);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

.segment button.active,
.chips button.active {
  color: #fff;
  border-color: var(--brand);
  background: var(--brand);
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */

button, .btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--chip-bg);
  color: var(--chip-text);
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
}

button:hover, .btn:hover { background: var(--panel-hover); }

.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }

/* ── Bottom panels ──────────────────────────────────────────────────────── */

.bottom-panel {
  margin-top: auto;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #202736 0%, #1a2231 100%);
  color: #f3f6fb;
  padding: 18px 18px;
  min-height: 112px;
  flex-shrink: 0;
}

.bottom-panel button,
.bottom-panel .btn {
  border-color: rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #f3f6fb;
}

.bottom-panel button:hover,
.bottom-panel .btn:hover {
  background: rgba(255,255,255,0.15);
}

.bottom-panel .primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.bottom-create {
  display: flex;
  align-items: center;
}

.status-line {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
}

.bottom-progress { display: grid; }
.bottom-done     { display: grid; }

.bottom-progress {
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
}

.progress-main {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.bottom-eta {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.55);
}

[data-theme="light"] .bottom-eta {
  color: rgba(0, 0, 0, 0.5);
}

.bottom-done {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 12px;
}

/* ── Stepper ────────────────────────────────────────────────────────────── */

.progress-group { margin-bottom: 12px; }

.progress-main .progress-group {
  margin-bottom: 0;
}

.stepper {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: flex-start;
}

.step {
  position: relative;
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 8px;
  text-align: center;
}

.step:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 13px;
  left: calc(50% + 18px);
  right: calc(-50% + 18px);
  height: 2px;
  background: rgba(255,255,255,0.2);
}

.step-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.06);
}

.step-label {
  font-size: 12px;
  color: rgba(255,255,255,0.65);
  line-height: 1.2;
}

.step.completed .step-dot {
  border-color: #7bc2ff;
  color: #fff;
  background: linear-gradient(180deg, #4e9cff, #3478e0);
}

.step.completed .step-label { color: #deecff; }

.step.completed:not(:last-child)::after {
  background: linear-gradient(90deg, #5faeff, #4f95f1);
}

.step.active .step-dot {
  border-color: #8dccff;
  color: #fff;
  background: linear-gradient(180deg, #6cb8ff, #4b93f0);
  animation: pulse 1.8s ease-in-out infinite;
}

.step.active .step-label { color: #fff; font-weight: 600; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 5px rgba(108,184,255,0.18); }
  50%       { box-shadow: 0 0 0 9px rgba(108,184,255,0.08); }
}

.bottom-progress .actions,
.bottom-done .actions {
  display: flex;
  gap: 8px;
  margin-top: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.bottom-progress .progress-group,
.bottom-done .audio-row {
  margin-bottom: 0;
}

.bottom-done .actions {
  justify-content: flex-start;
}

.bottom-done .actions.split-actions {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  justify-content: initial;
}

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

.actions-right {
  justify-content: flex-end;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  padding: 9px 12px;
}

.action-btn::before { flex-shrink: 0; }

.btn-mp3,
.btn-zip {
  border-color: rgba(147, 197, 253, 0.45) !important;
  background: rgba(96, 165, 250, 0.14) !important;
}

.btn-mp3:hover,
.btn-zip:hover {
  background: rgba(96, 165, 250, 0.22) !important;
}

.btn-mp3::before,
.btn-zip::before {
  content: "⬇";
  font-size: 12px;
  line-height: 1;
  color: #bfdbfe;
}

.btn-archive {
  border-color: rgba(255,255,255,0.28) !important;
}

.btn-archive::before {
  content: "🗂";
  font-size: 12px;
  line-height: 1;
}

.btn-delete {
  border-color: rgba(252, 165, 165, 0.5) !important;
  color: #fecaca !important;
}

.btn-delete:hover {
  background: rgba(248, 113, 113, 0.18) !important;
}

.btn-delete::before {
  content: "🗑";
  font-size: 12px;
  line-height: 1;
}

/* ── Audio player ───────────────────────────────────────────────────────── */

.audio-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.audio-meta {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 6px;
}

.audio-duration {
  font-size: 11px;
  color: rgba(243, 246, 251, 0.72);
  letter-spacing: 0.02em;
}

.play {
  min-width: 56px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.wave {
  height: 34px;
  border-radius: 4px;
  background: repeating-linear-gradient(
    90deg,
    rgba(255,255,255,0.9) 0,
    rgba(255,255,255,0.9) 2px,
    rgba(255,255,255,0.22) 2px,
    rgba(255,255,255,0.22) 5px
  );
  opacity: 0.8;
}

/* ── Modals ─────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body .field-row { margin-bottom: 16px; }

.modal-body input[type="text"],
.modal-body input[type="email"],
.modal-body input[type="password"],
.modal-body select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  background: var(--input-bg);
  font-family: inherit;
  color: var(--text);
}

.modal-auth-error {
  margin: 0 0 8px;
  font-size: 13px;
  color: #f87171;
  line-height: 1.35;
}

.auth-modal-switch {
  margin: 14px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  text-align: center;
}

.link-like {
  display: inline;
  background: none;
  border: none;
  padding: 2px 0;
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.4;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--muted) 28%, transparent);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.link-like:hover {
  color: var(--text);
  border-bottom-color: color-mix(in srgb, var(--brand) 55%, transparent);
}

.link-like:focus-visible {
  outline: none;
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.login-modal-hint code {
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--input-bg);
  border: 1px solid var(--line);
}

.modal-body input[readonly] {
  background: var(--bg);
  color: var(--muted);
}

.modal-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 10px;
}

.modal-section-label:first-child { margin-top: 0; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.danger {
  background: var(--chip-bg);
  border-color: #fca5a5;
  color: #dc2626;
}

.danger:hover { background: #fef2f2; }

/* ── Plan cards ─────────────────────────────────────────────────────────── */

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

.plan-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.plan-active {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  background: color-mix(in srgb, var(--brand) 18%, var(--panel));
}

.plan-disabled {
  background: var(--panel-soft);
  opacity: 0.6;
}

.plan-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
}

.plan-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.plan-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.plan-active .plan-badge {
  background: var(--brand);
  color: #fff;
}

.plan-disabled .plan-badge {
  background: #e5e7eb;
  color: #6b7280;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: row;
}

.coming-soon-inline {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

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

  .left-rail {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }

  .field-grid { grid-template-columns: 1fr; }

  .main-panel > div[x-show] { overflow-y: visible; }

  .bottom-progress,
  .bottom-done {
    grid-template-columns: 1fr;
  }

  .bottom-progress .actions,
  .bottom-done .actions {
    justify-content: flex-start;
  }

  .split-actions {
    grid-template-columns: 1fr;
  }

  .actions-right {
    justify-content: flex-start;
  }
}
