:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f8fafc;
  --muted: #cbd5e1;
  --primary: #6d5bd0;
  --primary-hover: #5b49be;
  --primary-soft: rgba(139, 121, 237, 0.18);
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --focus: #c4b5fd;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  font-size: 14px;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.studio-ui button,
.studio-ui input:not([type="checkbox"]):not([type="range"]):not([type="color"]),
.studio-ui select,
.studio-ui textarea,
.studio-ui a.btn {
  font: inherit;
  min-height: 36px;
  border-radius: 8px;
}

.studio-ui button,
.studio-ui a.btn {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 11px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}

.studio-ui button.sm { min-height: 30px; padding: 0 9px; font-size: 12px; }
.studio-ui button.icon-btn { min-width: 34px; padding: 0 8px; }
.studio-ui button:hover:not(:disabled),
.studio-ui a.btn:hover { border-color: var(--focus); }
.studio-ui button:disabled { opacity: 0.45; cursor: not-allowed; }
.studio-ui button.primary,
.studio-ui a.btn.primary { background: var(--primary); border-color: var(--primary); color: #ffffff; }
.studio-ui button.primary:hover:not(:disabled),
.studio-ui a.btn.primary:hover { background: var(--primary-hover); }
.studio-ui button.active-pill { background: var(--primary-soft); border-color: var(--focus); }
.studio-ui button.danger { background: #7f1d1d; border-color: #991b1b; color: #ffffff; }

.studio-ui input:not([type="checkbox"]):not([type="range"]):not([type="color"]),
.studio-ui select,
.studio-ui textarea {
  width: 100%;
  background: #0b1220;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
}

.studio-ui input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0b1220;
  cursor: pointer;
}

.studio-ui textarea { min-height: 74px; resize: vertical; }

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.nav a {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
}

.nav a.active { background: var(--primary-soft); color: var(--text); border-color: var(--primary); }
.page { max-width: 1360px; margin: 0 auto; padding: 20px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }

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

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge.ok { background: #14532d; border-color: #166534; color: #dcfce7; }
.badge.warn { background: #78350f; border-color: #92400e; color: #fef3c7; }
.badge.err { background: #7f1d1d; border-color: #991b1b; color: #fee2e2; }

.alert {
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.alert.err { border-color: var(--danger); background: rgba(220, 38, 38, 0.14); }
.alert.ok { border-color: var(--success); background: rgba(22, 163, 74, 0.14); }

.editor-shell { display: flex; flex-direction: column; min-height: calc(100vh - 57px); }
.editor-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px; padding: 8px 14px; background: #141d2f; border-bottom: 1px solid var(--border);
}
.toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.mobile-tabs { display: none; padding: 8px 12px; gap: 8px; background: var(--surface); border-bottom: 1px solid var(--border); }
.editor-main { display: grid; grid-template-columns: 272px 1fr 352px; gap: 0; flex: 1; min-height: 0; }
.editor-main.focus-mode { grid-template-columns: 1fr; }

.panel {
  background: var(--surface); border-right: 1px solid var(--border); padding: 12px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 10px; font-size: 13px;
}
.panel.right { border-right: none; border-left: 1px solid var(--border); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; }
.panel-heading strong { font-size: 13px; white-space: nowrap; }
.section-divider { border: 0; border-top: 1px solid var(--border); width: 100%; margin: 2px 0; }

.stage-center {
  background: #090e1a; display: flex; flex-direction: column; align-items: center;
  justify-content: space-between; padding: 10px 14px; gap: 8px; min-width: 0; min-height: 0;
}
.zoom-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; width: 100%; flex-shrink: 0; }
.stage-viewport { flex: 1; min-height: 0; width: 100%; overflow: auto; display: flex; align-items: center; justify-content: center; }
.player-frame {
  background: #20232b; border: 2px solid var(--border); border-radius: 10px; overflow: hidden;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; margin: auto;
}
.player-controls-bar {
  width: 100%; max-width: 680px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-shrink: 0;
}
.seek-slider { flex: 1; min-width: 110px; accent-color: var(--primary); cursor: pointer; }
.volume-slider { width: 68px; accent-color: var(--primary); cursor: pointer; }
.time-readout { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }

.scene-item { width: 100%; text-align: left; justify-content: space-between; padding: 6px 10px; background: var(--surface-2); }
.scene-item.active { border-color: var(--focus); background: var(--primary-soft); }
.actor-card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.actor-card-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.actor-card-meta strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actor-card-summary { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actor-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.timeline-bar { background: #141d2f; border-top: 1px solid var(--border); padding: 6px 14px; display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.timeline-track { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.timeline-clip {
  min-width: 120px; min-height: 48px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 6px 10px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px;
}
.timeline-clip.active { border-color: var(--focus); background: var(--primary-soft); }
.props-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.prop-chip { font-size: 12px; justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; }
.prop-chip.on { background: var(--primary-soft); border-color: var(--focus); }

@media (min-width: 1024px) {
  .editor-shell { height: calc(100vh - 57px); overflow: hidden; }
  .editor-main { overflow: hidden; }
  .panel, .stage-center { height: 100%; }
}
@media (max-width: 1023px) {
  .studio-ui button, .studio-ui input:not([type="checkbox"]):not([type="range"]):not([type="color"]),
  .studio-ui select, .studio-ui textarea, .studio-ui a.btn { min-height: 44px; }
  .mobile-tabs { display: flex; flex-wrap: wrap; }
  .editor-main, .editor-main.focus-mode { grid-template-columns: 1fr; }
  .panel.hidden-mobile, .stage-center.hidden-mobile, .timeline-bar.hidden-mobile { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.auth-shell {
  min-height: calc(100vh - 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card { width: 100%; max-width: 440px; }

.user-pill {
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  min-height: 30px;
  border-radius: 999px;
  background: var(--primary-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.asset-thumb {
  width: 100%;
  height: 130px;
  object-fit: contain;
  background: #0b1120;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
}

.progress-modal-backdrop { position: fixed; inset: 0; background: rgba(8, 13, 25, 0.74); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 60; }
.progress-modal-card { width: 100%; max-width: 440px; background: #131c31; border: 1px solid rgba(148, 163, 184, 0.25); border-radius: 16px; padding: 24px 20px; text-align: center; box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5); }
.progress-modal-title { margin: 0 0 14px; font-size: 1.08rem; color: #f8fafc; }
.progress-ring-wrap { position: relative; width: 128px; height: 128px; margin: 0 auto 14px; display: flex; align-items: center; justify-content: center; }
.progress-ring-svg { transform: rotate(-90deg); }
.progress-ring-track { fill: none; stroke: rgba(148, 163, 184, 0.18); stroke-width: 10; }
.progress-ring-fill { fill: none; stroke: #8b5cf6; stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.35s ease, stroke 0.25s ease; }
.progress-ring-wrap.done .progress-ring-fill { stroke: #22c55e; }
.progress-ring-wrap.error .progress-ring-fill { stroke: #ef4444; }
.progress-ring-center { position: absolute; display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.progress-ring-center strong { font-size: 26px; color: #f8fafc; }
.progress-ring-center span { font-size: 12px; color: #94a3b8; }
.progress-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.progress-step { font-size: 0.72rem; padding: 5px 4px; border-radius: 999px; background: rgba(148, 163, 184, 0.12); color: #94a3b8; }
.progress-step.active { background: rgba(139, 92, 246, 0.25); color: #e9d5ff; font-weight: 600; }
.progress-step.done { background: rgba(34, 197, 94, 0.2); color: #bbf7d0; }
.progress-stage-note { margin: 6px 0 0; font-size: 0.82rem; color: #cbd5e1; }
.progress-modal-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
@media (prefers-reduced-motion: reduce) { .progress-ring-fill { transition: none; } }

.toast-viewport { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); pointer-events: none; }
.toast-card { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; background: #0f172a; color: #f8fafc; border: 1px solid rgba(148, 163, 184, 0.35); box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45); font-size: 0.86rem; line-height: 1.35; animation: toast-in 0.18s ease-out; }
.toast-ok { border-color: #22c55e; }
.toast-ok .toast-icon { color: #4ade80; font-weight: 800; }
.toast-err { border-color: #ef4444; background: #261218; }
.toast-err .toast-icon { color: #f87171; font-weight: 800; }
.toast-info { border-color: #38bdf8; }
.toast-info .toast-icon { color: #38bdf8; font-weight: 800; }
.toast-msg { flex: 1; word-break: break-word; }
.toast-close { background: transparent; border: none; color: #cbd5e1; cursor: pointer; font-size: 16px; min-width: 28px; min-height: 28px; padding: 0; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; }
.toast-close:hover { background: rgba(148, 163, 184, 0.2); color: #ffffff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .toast-card { animation: none; } }
