:root {
  --bg: #0b0e14;
  --surface: #131822;
  --surface-2: #1b2230;
  --border: #283246;
  --text: #eef2f8;
  --muted: #98a4b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #ffd166;
  --danger: #ef4444;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.logo-badge {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #ec4899);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

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

.pill-free {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.14);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.3);
  white-space: nowrap;
}

.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 420px);
  gap: 20px;
  max-width: 1380px;
  margin: 20px auto;
  padding: 0 20px 40px;
  align-items: start;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.card-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

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

.chip {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: 0.15s ease;
}

.chip:hover {
  border-color: var(--primary);
  color: #fff;
}

textarea,
input[type="text"],
input[type="number"],
select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13.5px;
}

textarea:focus,
input:focus,
select:focus {
  outline: 2px solid rgba(59, 130, 246, 0.45);
  border-color: var(--primary);
}

input[type="color"] {
  width: 100%;
  height: 40px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
}

input[type="file"] {
  font-size: 12px;
  color: var(--muted);
  max-width: 100%;
}

.row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.inline-field input {
  width: 78px;
  padding: 6px 10px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-2);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.scenes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scene-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scene-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.scene-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.scene-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.scene-controls input[type="number"] {
  width: 70px;
  padding: 4px 8px;
  font-size: 12px;
}

.scene-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 12.5px;
  color: var(--muted);
}

.sub-hint {
  font-size: 11.5px;
  color: var(--muted);
}

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

.ai-box {
  background: rgba(59, 130, 246, 0.06);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: 12px;
  padding: 12px;
}

.api-details {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.api-details summary {
  cursor: pointer;
  color: #93c5fd;
}

.sticker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sticker-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: 0.15s ease;
}

.sticker-pill:has(input:checked) {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.18);
  color: #fff;
}

.music-results {
  margin-top: 8px;
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.music-results.hidden {
  display: none;
}

.music-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid transparent;
}

.music-item img {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.music-meta {
  flex: 1;
  min-width: 0;
}

.music-title {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-artist {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.preview-panel {
  position: sticky;
  top: 84px;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
  font-weight: 600;
}

.phone-frame {
  position: relative;
  width: 100%;
  max-width: 290px;
  aspect-ratio: 9 / 16;
  margin: 0 auto 14px;
  border-radius: 18px;
  overflow: hidden;
  border: 3px solid #2b3548;
  background: #000;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

#reelsCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.safe-zone-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: 10px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
}

.safe-zone-overlay.hidden {
  display: none;
}

.sz-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 11%;
  background: rgba(239, 68, 68, 0.18);
  border-bottom: 1px dashed rgba(239, 68, 68, 0.6);
  display: grid;
  place-items: center;
}

.sz-right {
  position: absolute;
  right: 0;
  bottom: 22%;
  width: 18%;
  padding: 8px 4px;
  background: rgba(239, 68, 68, 0.18);
  border-left: 1px dashed rgba(239, 68, 68, 0.6);
  border-top: 1px dashed rgba(239, 68, 68, 0.6);
  text-align: center;
  line-height: 1.5;
}

.sz-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 22%;
  background: rgba(239, 68, 68, 0.18);
  border-top: 1px dashed rgba(239, 68, 68, 0.6);
  display: grid;
  place-items: center;
}

.preview-controls {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
}

.render-status {
  margin-top: 12px;
}

.render-status.hidden {
  display: none;
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  transition: width 0.1s linear;
}

#renderStatusText {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.hint-text {
  margin: 10px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 960px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }
  .preview-panel {
    position: static;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
}
