:root {
  --bg-app: #090b10;
  --bg-panel: #111520;
  --bg-elevated: #171c2b;
  --border: #252c3f;
  --text: #eef2ff;
  --text-muted: #93a0ba;
  --accent: #6366f1;
  --accent-hover: #7c7ff6;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: 58px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

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

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
}

.brand-tag {
  font-size: 11px;
  color: var(--text-muted);
}

.plan-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  margin-left: 6px;
}

.plan-pill.free {
  background: rgba(147, 160, 186, 0.14);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.plan-pill.pro {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
}

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

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

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: #3b4664;
}

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

.btn-ghost:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 365px 1fr;
  min-height: 0;
}

.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  padding: 6px;
  gap: 6px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
}

.tab-panel {
  display: none;
  padding: 14px 16px 24px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  flex: 1;
}

.tab-panel.active {
  display: block;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-header h3 {
  margin: 0;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.template-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-app);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: 0.14s ease;
}

.template-chip:hover {
  border-color: #424e73;
  background: var(--bg-elevated);
}

.template-chip.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.14);
}

.tpl-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpl-badge {
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 4px;
  flex-shrink: 0;
}

.scene-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.scene-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
}

.scene-item.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.14);
}

.scene-item-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  min-width: 0;
}

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

.scene-item-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.scene-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.scene-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 5px;
  border-radius: 4px;
}

.scene-icon-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.scene-delete:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.14);
}

.form-group {
  margin-bottom: 11px;
}

.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

textarea {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.48;
  resize: vertical;
}

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

.project-io {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.chip-btn {
  padding: 7px 6px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.chip-btn.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(99, 102, 241, 0.16);
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 7px;
}

.swatch-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  min-width: 0;
}

.swatch-btn.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.14);
}

.swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.swatch-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lock-tag {
  margin-left: auto;
  font-size: 10px;
  color: var(--warning);
  font-weight: 700;
  flex-shrink: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
}

.pro-callout {
  margin-top: 16px;
  padding: 14px;
  border-radius: 10px;
  background: linear-gradient(145deg, rgba(99, 102, 241, 0.16), rgba(236, 72, 153, 0.1));
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.pro-callout-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.pro-callout h4 {
  margin: 0;
  font-size: 13.5px;
}

.price-tag {
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.pro-callout-note {
  margin: 0 0 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.pro-callout ul {
  margin: 0 0 12px;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
}

.stage-area {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: radial-gradient(circle at center, #131826 0%, #090b10 75%);
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  display: grid;
  place-items: center;
  padding: 22px;
  min-height: 0;
}

#previewCanvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
  background: #000;
}

.transport-bar {
  height: 58px;
  padding: 0 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  align-items: center;
  gap: 18px;
  flex-shrink: 0;
}

.transport-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scrubber-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.scene-counter {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
}

.time-readout {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 96px;
  text-align: right;
}

.export-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9, 11, 16, 0.78);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
}

.export-card {
  width: 340px;
  padding: 22px;
  border-radius: 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  text-align: center;
}

.engine-badge {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid rgba(99, 102, 241, 0.35);
  padding: 2px 8px;
  border-radius: 999px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-track {
  height: 7px;
  background: var(--bg-app);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1, #ec4899);
  transition: width 0.08s linear;
}

.cancel-export-btn {
  margin-top: 14px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 12, 0.75);
  backdrop-filter: blur(5px);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 680px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
}

.modal-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-title-row h2 {
  margin: 0;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.modal-sub {
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

.modal-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 18px;
}

.modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-box h3 {
  margin: 0;
  font-size: 14px;
}

.modal-box ul {
  margin: 0;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.6;
  flex: 1;
}

.small-muted, .checkout-note {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.feedback-msg {
  margin: 0;
  font-size: 12px;
  min-height: 16px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 72px;
  z-index: 80;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.toast.error {
  border-color: #f87171;
  color: #fca5a5;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 48% 52%;
  }
  .modal-columns {
    grid-template-columns: 1fr;
  }
}
