Browse Source

Add Cine Studio, a Premiere-like timeline video editor webapp (#263)

A new dark macOS-style video editor under src/web/Cine Studio with:

- Media bin importing from the ArozOS file system (file selector +
  File Manager drag-drop) and from the local device (uploaded to
  user:/Cine Studio/Media so projects stay portable), with probed
  durations, filmstrip thumbnails and decoded waveform peaks
- Multi-track timeline (video/audio) with drag-move, edge trimming,
  blade splitting, snapping, track visibility/mute toggles, zoomable
  timecode ruler and undo/redo history
- Canvas compositing preview player with per-clip transform, crop
  mode, opacity, color controls (exposure/contrast/saturation/presets)
  and a WebAudio mix bus for synced audio playback
- .cine project format (open/save/save-as via ao_module file selector,
  registered as a file association with its own icon)
- Export pipeline: real-time MediaRecorder render to WebM uploaded to
  the ArozOS storage, with optional server-side MP4 conversion through
  the AGI ffmpeg library when the host has ffmpeg installed

Backend AGI scripts create the per-user app folders and expose the
ffmpeg availability check / conversion / cleanup actions.


Claude-Session: https://claude.ai/code/session_01BSxJni7aDMU5MFoWG2SSa4

Co-authored-by: Claude <noreply@anthropic.com>
Alan Yeung 4 months ago
parent
commit
f862850bb3

+ 32 - 0
src/web/Cine Studio/backend/ensuredir.js

@@ -0,0 +1,32 @@
+/*
+	Cine Studio - Ensure app folders exist
+
+	Creates the per-user folder structure used to store imported
+	media and exported renders.
+
+	Parameters:
+	  (none)
+
+	Returns { ok: true, root: "user:/Cine Studio" }
+*/
+
+requirelib("filelib");
+
+var root = "user:/Cine Studio";
+var subfolders = ["Media", "Exports", "Projects"];
+
+if (!filelib.fileExists(root)) {
+	filelib.mkdir(root);
+}
+
+for (var i = 0; i < subfolders.length; i++) {
+	var target = root + "/" + subfolders[i];
+	if (!filelib.fileExists(target)) {
+		filelib.mkdir(target);
+	}
+}
+
+sendJSONResp(JSON.stringify({
+	ok: true,
+	root: root
+}));

+ 93 - 0
src/web/Cine Studio/backend/ffmpegtools.js

@@ -0,0 +1,93 @@
+/*
+	Cine Studio - Server side ffmpeg helpers
+
+	The browser export pipeline records the timeline as a WebM file.
+	When the host has ffmpeg installed, this script converts the
+	uploaded WebM into an MP4 (H.264) file next to it.
+
+	Parameters:
+	  action = "check"                    - report whether ffmpeg is available
+	  action = "convert", src, dst        - convert virtual path src into dst
+	  action = "cleanup", target          - delete a temporary file owned by the export
+
+	All paths are ArozOS virtual paths (e.g. user:/Cine Studio/Exports/out.webm)
+*/
+
+var hasFFmpeg = false;
+try {
+	hasFFmpeg = requirelib("ffmpeg");
+} catch (e) {
+	hasFFmpeg = false;
+}
+
+function main() {
+	if (typeof(action) == "undefined") {
+		sendJSONResp(JSON.stringify({ error: "action parameter is required" }));
+		return;
+	}
+
+	if (action == "check") {
+		sendJSONResp(JSON.stringify({ ffmpeg: hasFFmpeg }));
+		return;
+	}
+
+	if (action == "convert") {
+		if (!hasFFmpeg) {
+			sendJSONResp(JSON.stringify({ error: "ffmpeg is not available on this host" }));
+			return;
+		}
+		if (typeof(src) == "undefined" || typeof(dst) == "undefined") {
+			sendJSONResp(JSON.stringify({ error: "src and dst parameters are required" }));
+			return;
+		}
+
+		requirelib("filelib");
+		if (!filelib.fileExists(src)) {
+			sendJSONResp(JSON.stringify({ error: "source file not found" }));
+			return;
+		}
+
+		var progressFile = "tmp:/cinestudio_" + Math.floor(Math.random() * 100000000) + ".progress.json";
+		var ok = false;
+		var errMsg = "";
+		try {
+			ok = ffmpeg.convertWithProgress(src, dst, progressFile);
+		} catch (e) {
+			errMsg = e.toString();
+			ok = false;
+		}
+
+		if (filelib.fileExists(progressFile)) {
+			filelib.deleteFile(progressFile);
+		}
+
+		sendJSONResp(JSON.stringify({
+			success: ok,
+			output: dst,
+			error: errMsg
+		}));
+		return;
+	}
+
+	if (action == "cleanup") {
+		if (typeof(target) == "undefined") {
+			sendJSONResp(JSON.stringify({ error: "target parameter is required" }));
+			return;
+		}
+		requirelib("filelib");
+		//Only allow deleting temporary export artifacts inside the app folder
+		if (target.indexOf("user:/Cine Studio/") != 0) {
+			sendJSONResp(JSON.stringify({ error: "target outside of Cine Studio folder" }));
+			return;
+		}
+		if (filelib.fileExists(target)) {
+			filelib.deleteFile(target);
+		}
+		sendJSONResp(JSON.stringify({ ok: true }));
+		return;
+	}
+
+	sendJSONResp(JSON.stringify({ error: "unknown action: " + action }));
+}
+
+main();

+ 991 - 0
src/web/Cine Studio/css/style.css

@@ -0,0 +1,991 @@
+/*
+    Cine Studio - Premiere-like dark editor theme
+    Layout: topbar / (navrail | mediabin | preview | inspector) / tl-toolbar / timeline
+*/
+
+:root {
+    --bg: #0a0a0c;
+    --bg-panel: #141419;
+    --bg-panel-2: #17171d;
+    --bg-elev: #1e1e25;
+    --bg-hover: #26262e;
+    --bg-active: #2c2c35;
+    --border: #232329;
+    --border-soft: #1c1c22;
+    --text: #e9e9ec;
+    --text-dim: #9a9aa3;
+    --text-faint: #62626b;
+    --accent: #2e7cf6;
+    --accent-soft: rgba(46, 124, 246, 0.16);
+    --green: #21a366;
+    --green-dark: #0e5c3a;
+    --blue-clip: #2f6fed;
+    --blue-clip-dark: #1c4dbb;
+    --danger: #e5484d;
+    --radius: 8px;
+    --tl-header-w: 180px;
+    --ruler-h: 34px;
+    --track-h: 62px;
+    --track-h-audio: 52px;
+}
+
+* { margin: 0; padding: 0; box-sizing: border-box; }
+
+html, body {
+    width: 100%;
+    height: 100%;
+    overflow: hidden;
+    background: var(--bg);
+    color: var(--text);
+    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
+    font-size: 13px;
+    -webkit-font-smoothing: antialiased;
+    user-select: none;
+}
+
+body {
+    display: flex;
+    flex-direction: column;
+}
+
+button {
+    font-family: inherit;
+    background: none;
+    border: none;
+    color: inherit;
+    cursor: pointer;
+    -webkit-appearance: none;
+}
+
+input { font-family: inherit; }
+
+/* every glyph in the app is a stroke-based inline SVG */
+svg {
+    display: block;
+    stroke: currentColor;
+    fill: none;
+    stroke-width: 1.6;
+    stroke-linecap: round;
+    stroke-linejoin: round;
+}
+
+[data-icon] { display: inline-flex; align-items: center; justify-content: center; }
+[data-icon] svg { width: 17px; height: 17px; }
+[data-icon].mini svg { width: 11px; height: 11px; stroke-width: 2; }
+[data-icon].big svg { width: 46px; height: 46px; stroke-width: 1.2; }
+
+/* ======================= Top bar ======================= */
+
+#topbar {
+    height: 52px;
+    min-height: 52px;
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    padding: 0 14px;
+    background: #0d0d10;
+    border-bottom: 1px solid var(--border-soft);
+    position: relative;
+    z-index: 30;
+}
+
+.tb-left, .tb-right { display: flex; align-items: center; gap: 6px; }
+
+#traffic-lights { display: flex; align-items: center; gap: 8px; margin-right: 14px; }
+.tl {
+    width: 12px; height: 12px;
+    border-radius: 50%;
+    display: inline-block;
+    cursor: pointer;
+}
+.tl-close { background: #ff5f57; }
+.tl-min   { background: #febc2e; }
+.tl-max   { background: #28c840; }
+#traffic-lights:hover .tl { filter: brightness(0.85); }
+
+.tb-btn {
+    height: 30px;
+    min-width: 32px;
+    padding: 0 7px;
+    display: inline-flex;
+    align-items: center;
+    justify-content: center;
+    gap: 3px;
+    border-radius: 7px;
+    color: var(--text-dim);
+}
+.tb-btn:hover { background: var(--bg-hover); color: var(--text); }
+
+.tb-center {
+    position: absolute;
+    left: 50%;
+    transform: translateX(-50%);
+}
+#project-name-btn {
+    display: flex;
+    align-items: center;
+    gap: 6px;
+    height: 30px;
+    padding: 0 12px;
+    border-radius: 7px;
+    color: var(--text);
+    font-size: 13.5px;
+    font-weight: 600;
+}
+#project-name-btn:hover { background: var(--bg-hover); }
+#project-name-btn [data-icon] { color: var(--text-dim); }
+
+#export-split {
+    display: flex;
+    align-items: stretch;
+    margin-left: 8px;
+    border-radius: 8px;
+    overflow: hidden;
+    background: var(--accent);
+}
+#btn-export {
+    display: flex;
+    align-items: center;
+    gap: 7px;
+    padding: 0 14px;
+    height: 32px;
+    color: #fff;
+    font-weight: 600;
+    font-size: 13px;
+}
+#btn-export-menu {
+    display: flex;
+    align-items: center;
+    padding: 0 8px;
+    color: #fff;
+    border-left: 1px solid rgba(255,255,255,0.25);
+}
+#btn-export:hover, #btn-export-menu:hover { background: #3d89ff; }
+#btn-export [data-icon] svg { width: 15px; height: 15px; stroke-width: 1.9; }
+
+/* ======================= Workspace ======================= */
+
+#workspace {
+    flex: 1;
+    display: flex;
+    min-height: 0;
+    background: var(--bg);
+}
+
+/* ---------- Nav rail ---------- */
+
+#navrail {
+    width: 92px;
+    min-width: 92px;
+    background: #101014;
+    border-right: 1px solid var(--border-soft);
+    display: flex;
+    flex-direction: column;
+    justify-content: space-between;
+    padding: 10px 8px;
+    overflow-y: auto;
+}
+.nav-items { display: flex; flex-direction: column; gap: 2px; }
+.nav-item {
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    gap: 5px;
+    padding: 9px 2px 8px 2px;
+    border-radius: 9px;
+    color: var(--text-dim);
+}
+.nav-item label { font-size: 11px; cursor: pointer; letter-spacing: 0.1px; }
+.nav-item:hover { background: var(--bg-hover); color: var(--text); }
+.nav-item.active { background: var(--bg-active); color: var(--text); }
+.nav-item [data-icon] svg { width: 18px; height: 18px; }
+.nav-bottom { display: flex; justify-content: center; padding-bottom: 2px; }
+.nav-bottom .nav-item { padding: 8px; }
+
+/* ---------- Media bin ---------- */
+
+#mediabin {
+    width: 272px;
+    min-width: 272px;
+    background: var(--bg-panel);
+    border-right: 1px solid var(--border-soft);
+    display: flex;
+    flex-direction: column;
+    min-height: 0;
+}
+
+.bin-header {
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    padding: 12px 12px 8px 12px;
+}
+#import-split {
+    display: flex;
+    align-items: stretch;
+    border-radius: 7px;
+    overflow: hidden;
+    background: var(--bg-elev);
+    border: 1px solid var(--border);
+}
+#btn-import {
+    padding: 0 16px;
+    height: 28px;
+    font-size: 12.5px;
+    font-weight: 600;
+    color: var(--text);
+}
+#btn-import-menu {
+    display: flex;
+    align-items: center;
+    padding: 0 7px;
+    color: var(--text-dim);
+    border-left: 1px solid var(--border);
+}
+#btn-import:hover, #btn-import-menu:hover { background: var(--bg-hover); }
+
+.bin-header-right { display: flex; gap: 2px; }
+.bin-tool {
+    width: 28px; height: 28px;
+    display: inline-flex; align-items: center; justify-content: center;
+    border-radius: 6px;
+    color: var(--text-dim);
+}
+.bin-tool:hover { background: var(--bg-hover); color: var(--text); }
+.bin-tool [data-icon] svg { width: 15px; height: 15px; }
+
+.bin-subheader {
+    display: flex;
+    align-items: center;
+    gap: 8px;
+    padding: 2px 12px 10px 12px;
+}
+#bin-kind-btn {
+    display: flex;
+    align-items: center;
+    gap: 5px;
+    height: 26px;
+    padding: 0 8px;
+    border-radius: 6px;
+    color: var(--text-dim);
+    font-size: 12.5px;
+    white-space: nowrap;
+}
+#bin-kind-btn:hover { background: var(--bg-hover); color: var(--text); }
+.bin-search {
+    flex: 1;
+    display: flex;
+    align-items: center;
+    gap: 6px;
+    height: 27px;
+    padding: 0 9px;
+    background: var(--bg-elev);
+    border-radius: 14px;
+    color: var(--text-faint);
+    min-width: 0;
+}
+.bin-search [data-icon] svg { width: 13px; height: 13px; }
+.bin-search input {
+    flex: 1;
+    min-width: 0;
+    background: transparent;
+    border: none;
+    outline: none;
+    color: var(--text);
+    font-size: 12.5px;
+}
+.bin-search input::placeholder { color: var(--text-faint); }
+
+#bin-grid {
+    flex: 1;
+    overflow-y: auto;
+    padding: 2px 12px 8px 12px;
+    display: grid;
+    grid-template-columns: 1fr 1fr;
+    gap: 12px 10px;
+    align-content: start;
+}
+
+.bin-item { cursor: grab; }
+.bin-item:active { cursor: grabbing; }
+.bin-thumb {
+    position: relative;
+    width: 100%;
+    aspect-ratio: 16 / 10;
+    border-radius: 8px;
+    background: #000;
+    background-size: cover;
+    background-position: center;
+    overflow: hidden;
+    border: 1px solid transparent;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    color: var(--text-faint);
+}
+.bin-item:hover .bin-thumb { border-color: #3a3a44; }
+.bin-item.selected .bin-thumb { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
+.bin-thumb .duration {
+    position: absolute;
+    right: 5px;
+    bottom: 5px;
+    padding: 1px 5px;
+    border-radius: 4px;
+    background: rgba(0,0,0,0.65);
+    color: #fff;
+    font-size: 10.5px;
+    font-variant-numeric: tabular-nums;
+}
+.bin-thumb .offline-badge {
+    position: absolute;
+    left: 5px;
+    top: 5px;
+    color: var(--danger);
+}
+.bin-thumb .offline-badge svg { width: 13px; height: 13px; }
+.bin-thumb.audio-thumb { background: linear-gradient(180deg, #1c2b22, #14201a); }
+.bin-thumb.audio-thumb canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
+.bin-name {
+    margin-top: 5px;
+    font-size: 11.5px;
+    color: var(--text-dim);
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    text-align: center;
+}
+.bin-item.selected .bin-name { color: var(--text); }
+
+.bin-footer {
+    padding: 8px 0 10px 0;
+    text-align: center;
+    color: var(--text-faint);
+    font-size: 11.5px;
+    border-top: 1px solid var(--border-soft);
+}
+
+.bin-empty-hint {
+    grid-column: 1 / -1;
+    padding: 34px 10px;
+    text-align: center;
+    color: var(--text-faint);
+    font-size: 12px;
+    line-height: 1.6;
+}
+
+/* ---------- Preview ---------- */
+
+#preview {
+    flex: 1;
+    min-width: 0;
+    display: flex;
+    flex-direction: column;
+    background: #060607;
+}
+#preview-stage {
+    flex: 1;
+    min-height: 0;
+    position: relative;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    overflow: hidden;
+    padding: 18px;
+}
+#preview-canvas {
+    max-width: 100%;
+    max-height: 100%;
+    background: #000;
+    border-radius: 6px;
+    box-shadow: 0 0 0 1px rgba(255,255,255,0.05);
+}
+#preview-empty {
+    position: absolute;
+    inset: 0;
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    justify-content: center;
+    gap: 12px;
+    color: var(--text-faint);
+    pointer-events: none;
+}
+#preview-empty p { font-size: 12.5px; }
+
+#preview-bar {
+    height: 46px;
+    min-height: 46px;
+    display: flex;
+    align-items: center;
+    padding: 0 14px;
+    position: relative;
+}
+.pb-left {
+    display: flex;
+    align-items: baseline;
+    gap: 6px;
+    font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
+    font-size: 12.5px;
+    font-variant-numeric: tabular-nums;
+}
+#tc-current { color: var(--accent); }
+.tc-sep { color: var(--text-faint); }
+#tc-total { color: var(--text-dim); }
+
+.pb-center {
+    position: absolute;
+    left: 50%;
+    transform: translateX(-50%);
+    display: flex;
+    align-items: center;
+    gap: 4px;
+}
+.pb-right { margin-left: auto; display: flex; align-items: center; gap: 2px; }
+.pb-btn {
+    width: 32px; height: 32px;
+    display: inline-flex; align-items: center; justify-content: center;
+    border-radius: 7px;
+    color: var(--text-dim);
+}
+.pb-btn:hover { background: var(--bg-hover); color: var(--text); }
+.pb-btn.active { color: var(--accent); }
+.pb-btn.play { color: var(--text); }
+.pb-btn.play svg { fill: currentColor; stroke: none; width: 18px; height: 18px; }
+.pb-btn.wide { width: auto; padding: 0 8px; gap: 5px; font-size: 12px; }
+
+/* ---------- Inspector ---------- */
+
+#inspector {
+    width: 300px;
+    min-width: 300px;
+    background: var(--bg-panel);
+    border-left: 1px solid var(--border-soft);
+    display: flex;
+    flex-direction: column;
+    min-height: 0;
+}
+#inspector.hidden { display: none; }
+
+#inspector-tabs {
+    display: flex;
+    align-items: center;
+    gap: 4px;
+    padding: 10px 14px 0 14px;
+}
+.itab {
+    padding: 6px 9px 9px 9px;
+    font-size: 12.5px;
+    color: var(--text-dim);
+    border-bottom: 2px solid transparent;
+}
+.itab:hover { color: var(--text); }
+.itab.active { color: var(--accent); border-bottom-color: var(--accent); }
+
+#inspector-body {
+    flex: 1;
+    overflow-y: auto;
+    padding: 6px 14px 14px 14px;
+}
+
+.insp-placeholder {
+    padding: 40px 12px;
+    color: var(--text-faint);
+    font-size: 12px;
+    text-align: center;
+    line-height: 1.6;
+}
+
+.insp-section { border-bottom: 1px solid var(--border-soft); padding-bottom: 12px; margin-bottom: 4px; }
+.insp-section:last-child { border-bottom: none; }
+.insp-section-head {
+    display: flex;
+    align-items: center;
+    gap: 6px;
+    padding: 10px 0 8px 0;
+    cursor: pointer;
+}
+.insp-section-head .caret svg { width: 11px; height: 11px; stroke-width: 2.2; color: var(--text-dim); transition: transform 0.12s; }
+.insp-section.collapsed .caret svg { transform: rotate(-90deg); }
+.insp-section-head .sec-title { font-size: 12.5px; font-weight: 600; flex: 1; }
+.insp-section-head .sec-reset {
+    width: 22px; height: 22px;
+    display: inline-flex; align-items: center; justify-content: center;
+    border-radius: 5px;
+    color: var(--text-faint);
+}
+.insp-section-head .sec-reset:hover { background: var(--bg-hover); color: var(--text); }
+.insp-section-head .sec-reset svg { width: 13px; height: 13px; }
+.insp-section.collapsed .insp-rows { display: none; }
+
+.insp-row {
+    display: flex;
+    align-items: center;
+    min-height: 30px;
+    gap: 8px;
+    padding: 2px 0;
+}
+.insp-label {
+    width: 64px;
+    min-width: 64px;
+    font-size: 12px;
+    color: var(--text-dim);
+}
+.insp-control { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
+
+.num-chip {
+    display: flex;
+    align-items: center;
+    gap: 4px;
+    height: 24px;
+    padding: 0 6px;
+    background: var(--bg-elev);
+    border-radius: 6px;
+    font-size: 11.5px;
+    color: var(--text);
+}
+.num-chip label { color: var(--text-faint); font-size: 11px; }
+.num-chip input {
+    width: 34px;
+    background: transparent;
+    border: none;
+    outline: none;
+    color: var(--text);
+    font-size: 11.5px;
+    text-align: right;
+    font-variant-numeric: tabular-nums;
+}
+.num-chip .unit { color: var(--text-faint); font-size: 11px; }
+
+/* sliders */
+input[type="range"].insp-slider, #tl-zoom {
+    -webkit-appearance: none;
+    appearance: none;
+    height: 3px;
+    border-radius: 2px;
+    background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--fill, 50%), #3a3a44 var(--fill, 50%), #3a3a44 100%);
+    outline: none;
+    flex: 1;
+    min-width: 0;
+}
+input[type="range"].insp-slider::-webkit-slider-thumb, #tl-zoom::-webkit-slider-thumb {
+    -webkit-appearance: none;
+    appearance: none;
+    width: 12px; height: 12px;
+    border-radius: 50%;
+    background: #fff;
+    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
+    cursor: pointer;
+}
+input[type="range"].insp-slider::-moz-range-thumb, #tl-zoom::-moz-range-thumb {
+    width: 12px; height: 12px;
+    border: none;
+    border-radius: 50%;
+    background: #fff;
+    cursor: pointer;
+}
+
+/* rotation dial */
+.dial {
+    width: 26px; height: 26px;
+    border-radius: 50%;
+    background: var(--bg-elev);
+    border: 1px solid var(--border);
+    position: relative;
+    cursor: ns-resize;
+}
+.dial .tick {
+    position: absolute;
+    left: 50%; top: 1px;
+    width: 2px; height: 9px;
+    margin-left: -1px;
+    border-radius: 1px;
+    background: var(--text-dim);
+    transform-origin: 1px 12px;
+}
+
+/* select-like buttons */
+.insp-select {
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    gap: 8px;
+    height: 26px;
+    min-width: 110px;
+    padding: 0 9px;
+    background: var(--bg-elev);
+    border-radius: 6px;
+    font-size: 12px;
+    color: var(--text);
+}
+.insp-select:hover { background: var(--bg-hover); }
+.insp-select [data-icon] { color: var(--text-faint); }
+
+.insp-reset-all {
+    width: 100%;
+    height: 30px;
+    margin-top: 12px;
+    border-radius: 7px;
+    background: var(--bg-elev);
+    color: var(--text);
+    font-size: 12.5px;
+}
+.insp-reset-all:hover { background: var(--bg-hover); }
+
+/* ======================= Timeline toolbar ======================= */
+
+#tl-toolbar {
+    height: 42px;
+    min-height: 42px;
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    padding: 0 12px;
+    background: #0f0f13;
+    border-top: 1px solid var(--border-soft);
+    border-bottom: 1px solid var(--border-soft);
+}
+.tlt-left, .tlt-right { display: flex; align-items: center; gap: 3px; }
+.tlt-btn {
+    width: 30px; height: 30px;
+    display: inline-flex; align-items: center; justify-content: center;
+    border-radius: 7px;
+    color: var(--text-dim);
+}
+.tlt-btn:hover { background: var(--bg-hover); color: var(--text); }
+.tlt-btn.active { background: var(--accent-soft); color: var(--accent); }
+.tlt-btn:disabled { opacity: 0.35; pointer-events: none; }
+.tlt-sep { width: 1px; height: 18px; background: var(--border); margin: 0 8px; }
+#tl-zoom { width: 110px; }
+
+/* ======================= Timeline ======================= */
+
+#timeline {
+    height: 268px;
+    min-height: 130px;
+    display: flex;
+    background: #0d0d11;
+    position: relative;
+    overflow: hidden;
+}
+
+#tl-headers {
+    width: var(--tl-header-w);
+    min-width: var(--tl-header-w);
+    border-right: 1px solid var(--border);
+    display: flex;
+    flex-direction: column;
+    background: #0d0d11;
+    z-index: 5;
+}
+#tl-corner { height: var(--ruler-h); min-height: var(--ruler-h); border-bottom: 1px solid var(--border-soft); }
+#tl-track-headers { flex: 1; overflow: hidden; }
+
+.track-header {
+    display: flex;
+    align-items: center;
+    gap: 8px;
+    padding: 0 12px;
+    border-bottom: 1px solid var(--border-soft);
+    color: var(--text-dim);
+}
+.track-header .th-icon svg { width: 15px; height: 15px; }
+.track-header .th-name { flex: 1; font-size: 12px; }
+.track-header .th-toggle {
+    width: 24px; height: 24px;
+    display: inline-flex; align-items: center; justify-content: center;
+    border-radius: 5px;
+    color: var(--text-dim);
+}
+.track-header .th-toggle:hover { background: var(--bg-hover); color: var(--text); }
+.track-header .th-toggle.off { color: var(--text-faint); }
+.track-header .th-toggle svg { width: 14px; height: 14px; }
+
+#tl-scroll {
+    flex: 1;
+    overflow: auto;
+    position: relative;
+}
+#tl-content {
+    position: relative;
+    min-width: 100%;
+    min-height: 100%;
+}
+#tl-ruler {
+    display: block;
+    height: var(--ruler-h);
+    position: sticky;
+    top: 0;
+    left: 0;
+    z-index: 4;
+    background: #0d0d11;
+    cursor: pointer;
+}
+#tl-tracks { position: relative; }
+
+.tl-track {
+    position: relative;
+    border-bottom: 1px solid var(--border-soft);
+    background:
+        repeating-linear-gradient(to right, transparent 0, transparent 100%);
+}
+.tl-track.drop-target { background: rgba(46, 124, 246, 0.07); }
+
+.tl-clip {
+    position: absolute;
+    top: 5px;
+    bottom: 5px;
+    border-radius: 7px;
+    overflow: hidden;
+    cursor: grab;
+    background: var(--bg-elev);
+    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.08);
+}
+.tl-clip:active { cursor: grabbing; }
+.tl-clip.selected { box-shadow: inset 0 0 0 2px #fff, 0 0 0 1px rgba(0,0,0,0.6); }
+.tl-clip .clip-strip {
+    position: absolute;
+    inset: 0;
+    background-repeat: repeat-x;
+    background-size: auto 100%;
+    pointer-events: none;
+}
+.tl-clip .clip-label {
+    position: absolute;
+    left: 8px;
+    top: 4px;
+    right: 8px;
+    font-size: 11px;
+    color: rgba(255,255,255,0.92);
+    white-space: nowrap;
+    overflow: hidden;
+    text-overflow: ellipsis;
+    pointer-events: none;
+    text-shadow: 0 1px 2px rgba(0,0,0,0.6);
+}
+.tl-clip .clip-wave {
+    position: absolute;
+    inset: 0;
+    pointer-events: none;
+}
+.tl-clip.audio-clip { background: var(--green); }
+.tl-clip.audio-clip.alt { background: var(--blue-clip); }
+.tl-clip.offline {
+    background: repeating-linear-gradient(45deg, #3a2326, #3a2326 8px, #2c1b1d 8px, #2c1b1d 16px);
+}
+.tl-clip .trim-handle {
+    position: absolute;
+    top: 0;
+    bottom: 0;
+    width: 8px;
+    cursor: ew-resize;
+    z-index: 2;
+}
+.tl-clip .trim-handle.left { left: 0; }
+.tl-clip .trim-handle.right { right: 0; }
+.tl-clip.selected .trim-handle::after {
+    content: "";
+    position: absolute;
+    top: 50%;
+    width: 3px;
+    height: 14px;
+    margin-top: -7px;
+    border-radius: 2px;
+    background: rgba(255,255,255,0.9);
+}
+.tl-clip.selected .trim-handle.left::after { left: 3px; }
+.tl-clip.selected .trim-handle.right::after { right: 3px; }
+
+#tl-playhead {
+    position: absolute;
+    top: 0;
+    bottom: 0;
+    width: 0;
+    z-index: 6;
+    pointer-events: none;
+}
+#tl-playhead .ph-line {
+    position: absolute;
+    top: 0; bottom: 0;
+    left: -1px;
+    width: 2px;
+    background: var(--accent);
+}
+#tl-playhead .ph-handle {
+    position: absolute;
+    top: 2px;
+    left: -6px;
+    width: 12px;
+    height: 16px;
+    background: var(--accent);
+    border-radius: 4px 4px 6px 6px;
+    clip-path: polygon(0 0, 100% 0, 100% 60%, 50% 100%, 0 60%);
+}
+
+.snap-guide {
+    position: absolute;
+    top: 0; bottom: 0;
+    width: 1px;
+    background: #f6c945;
+    z-index: 5;
+    pointer-events: none;
+}
+
+/* ======================= Toasts ======================= */
+
+#toast-holder {
+    position: fixed;
+    bottom: 290px;
+    left: 50%;
+    transform: translateX(-50%);
+    display: flex;
+    flex-direction: column;
+    align-items: center;
+    gap: 8px;
+    z-index: 300;
+    pointer-events: none;
+}
+.toast {
+    padding: 8px 16px;
+    border-radius: 8px;
+    background: rgba(30, 30, 37, 0.96);
+    border: 1px solid var(--border);
+    box-shadow: 0 6px 24px rgba(0,0,0,0.5);
+    font-size: 12.5px;
+    color: var(--text);
+    animation: toast-in 0.18s ease-out;
+}
+.toast.error { border-color: rgba(229, 72, 77, 0.6); color: #ff9498; }
+@keyframes toast-in {
+    from { opacity: 0; transform: translateY(8px); }
+    to   { opacity: 1; transform: translateY(0); }
+}
+
+/* ======================= Menus ======================= */
+
+.ctx-menu {
+    position: fixed;
+    min-width: 200px;
+    background: rgba(28, 28, 34, 0.98);
+    border: 1px solid var(--border);
+    border-radius: 10px;
+    box-shadow: 0 12px 40px rgba(0,0,0,0.55);
+    padding: 5px;
+    z-index: 400;
+    backdrop-filter: blur(18px);
+}
+.ctx-item {
+    display: flex;
+    align-items: center;
+    gap: 9px;
+    width: 100%;
+    padding: 7px 10px;
+    border-radius: 6px;
+    font-size: 12.5px;
+    color: var(--text);
+    text-align: left;
+}
+.ctx-item:hover { background: var(--accent); color: #fff; }
+.ctx-item:hover [data-icon] { color: #fff; }
+.ctx-item [data-icon] { color: var(--text-dim); }
+.ctx-item [data-icon] svg { width: 14px; height: 14px; }
+.ctx-item.checked::after { content: ""; margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
+.ctx-item.checked:hover::after { background: #fff; }
+.ctx-item:disabled { opacity: 0.4; pointer-events: none; }
+.ctx-sep { height: 1px; margin: 5px 8px; background: var(--border); }
+
+/* ======================= Modals ======================= */
+
+#modal-holder:not(:empty) {
+    position: fixed;
+    inset: 0;
+    background: rgba(0,0,0,0.55);
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    z-index: 350;
+}
+.modal {
+    width: 380px;
+    max-width: calc(100vw - 40px);
+    background: #1a1a20;
+    border: 1px solid var(--border);
+    border-radius: 12px;
+    box-shadow: 0 24px 80px rgba(0,0,0,0.6);
+    overflow: hidden;
+}
+.modal-title {
+    padding: 14px 18px 6px 18px;
+    font-size: 14px;
+    font-weight: 600;
+}
+.modal-body { padding: 8px 18px 14px 18px; }
+.modal-row {
+    display: flex;
+    align-items: center;
+    justify-content: space-between;
+    gap: 12px;
+    padding: 7px 0;
+    font-size: 12.5px;
+    color: var(--text-dim);
+}
+.modal-row > *:last-child { flex: 0 0 auto; }
+.modal-row input[type="text"], .modal-row input[type="number"], .modal-row select {
+    width: 170px;
+    height: 28px;
+    padding: 0 9px;
+    background: var(--bg-elev);
+    border: 1px solid var(--border);
+    border-radius: 6px;
+    color: var(--text);
+    font-size: 12.5px;
+    outline: none;
+}
+.modal-row input:focus, .modal-row select:focus { border-color: var(--accent); }
+.modal-row select { -webkit-appearance: none; appearance: none; }
+.modal-buttons {
+    display: flex;
+    justify-content: flex-end;
+    gap: 8px;
+    padding: 10px 18px 16px 18px;
+}
+.modal-btn {
+    height: 30px;
+    padding: 0 16px;
+    border-radius: 7px;
+    background: var(--bg-elev);
+    color: var(--text);
+    font-size: 12.5px;
+}
+.modal-btn:hover { background: var(--bg-hover); }
+.modal-btn.primary { background: var(--accent); color: #fff; font-weight: 600; }
+.modal-btn.primary:hover { background: #3d89ff; }
+.modal-btn:disabled { opacity: 0.5; pointer-events: none; }
+
+.modal-progress {
+    height: 6px;
+    border-radius: 3px;
+    background: var(--bg-elev);
+    overflow: hidden;
+    margin: 10px 0 4px 0;
+}
+.modal-progress .fill {
+    height: 100%;
+    width: 0;
+    background: var(--accent);
+    border-radius: 3px;
+    transition: width 0.2s linear;
+}
+.modal-note { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; padding-top: 4px; }
+
+/* ======================= Scrollbars ======================= */
+
+::-webkit-scrollbar { width: 10px; height: 10px; }
+::-webkit-scrollbar-track { background: transparent; }
+::-webkit-scrollbar-thumb {
+    background: #2e2e37;
+    border-radius: 5px;
+    border: 2px solid transparent;
+    background-clip: content-box;
+}
+::-webkit-scrollbar-thumb:hover { background-color: #3d3d48; }
+::-webkit-scrollbar-corner { background: transparent; }

BIN
src/web/Cine Studio/img/desktop_icon.png


BIN
src/web/Cine Studio/img/file_icon.png


BIN
src/web/Cine Studio/img/module_icon.png


+ 194 - 0
src/web/Cine Studio/index.html

@@ -0,0 +1,194 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Cine Studio</title>
+    <link rel="icon" href="img/module_icon.png">
+    <script src="../script/jquery.min.js"></script>
+    <script src="../script/ao_module.js"></script>
+    <link rel="stylesheet" href="css/style.css">
+</head>
+<body>
+    <!-- ======================= Top bar ======================= -->
+    <div id="topbar">
+        <div class="tb-left">
+            <div id="traffic-lights">
+                <span class="tl tl-close" title="Close"></span>
+                <span class="tl tl-min" title="Minimize"></span>
+                <span class="tl tl-max" title="Zoom"></span>
+            </div>
+            <button class="tb-btn" id="btn-open-project" title="Open project">
+                <span data-icon="folder"></span><span data-icon="chevron-down" class="mini"></span>
+            </button>
+            <button class="tb-btn" id="btn-save-project" title="Save project (Ctrl+S)">
+                <span data-icon="save"></span>
+            </button>
+            <button class="tb-btn" id="btn-save-state" title="Project state">
+                <span data-icon="check-circle" id="save-state-icon"></span>
+            </button>
+        </div>
+        <div class="tb-center">
+            <button id="project-name-btn" title="Project menu">
+                <span id="project-name">My Project</span>
+                <span data-icon="chevron-down" class="mini"></span>
+            </button>
+        </div>
+        <div class="tb-right">
+            <button class="tb-btn" id="btn-toggle-inspector" title="Toggle inspector">
+                <span data-icon="panel-right"></span>
+            </button>
+            <button class="tb-btn" id="btn-share" title="Share / open export folder">
+                <span data-icon="share"></span>
+            </button>
+            <div id="export-split">
+                <button id="btn-export" title="Export video">
+                    <span data-icon="export-up"></span><span>Export</span>
+                </button>
+                <button id="btn-export-menu" title="Export options">
+                    <span data-icon="chevron-down" class="mini"></span>
+                </button>
+            </div>
+        </div>
+    </div>
+
+    <!-- ======================= Upper workspace ======================= -->
+    <div id="workspace">
+        <!-- Left navigation rail -->
+        <div id="navrail">
+            <div class="nav-items">
+                <button class="nav-item active" data-nav="media"><span data-icon="nav-media"></span><label>Media</label></button>
+                <button class="nav-item" data-nav="audio"><span data-icon="nav-audio"></span><label>Audio</label></button>
+                <button class="nav-item" data-nav="titles"><span data-icon="nav-titles"></span><label>Titles</label></button>
+                <button class="nav-item" data-nav="transitions"><span data-icon="nav-transitions"></span><label>Transitions</label></button>
+                <button class="nav-item" data-nav="effects"><span data-icon="nav-effects"></span><label>Effects</label></button>
+                <button class="nav-item" data-nav="elements"><span data-icon="nav-elements"></span><label>Elements</label></button>
+                <button class="nav-item" data-nav="text"><span data-icon="nav-text"></span><label>Text</label></button>
+                <button class="nav-item" data-nav="filters"><span data-icon="nav-filters"></span><label>Filters</label></button>
+                <button class="nav-item" data-nav="libraries"><span data-icon="nav-libraries"></span><label>Libraries</label></button>
+            </div>
+            <div class="nav-bottom">
+                <button class="nav-item" id="btn-settings" title="Project settings"><span data-icon="gear"></span></button>
+            </div>
+        </div>
+
+        <!-- Media bin -->
+        <div id="mediabin">
+            <div class="bin-header">
+                <div id="import-split">
+                    <button id="btn-import">Import</button>
+                    <button id="btn-import-menu"><span data-icon="chevron-down" class="mini"></span></button>
+                </div>
+                <div class="bin-header-right">
+                    <button class="bin-tool" id="btn-bin-filter" title="Filter"><span data-icon="funnel"></span></button>
+                    <button class="bin-tool" id="btn-bin-view" title="View"><span data-icon="list-view"></span></button>
+                </div>
+            </div>
+            <div class="bin-subheader">
+                <button id="bin-kind-btn"><span id="bin-kind-label">All Clips</span><span data-icon="chevron-down" class="mini"></span></button>
+                <div class="bin-search">
+                    <span data-icon="search"></span>
+                    <input type="text" id="bin-search-input" placeholder="Search" autocomplete="off">
+                </div>
+            </div>
+            <div id="bin-grid"></div>
+            <div class="bin-footer"><span id="bin-count">0 items</span></div>
+        </div>
+
+        <!-- Preview player -->
+        <div id="preview">
+            <div id="preview-stage">
+                <canvas id="preview-canvas" width="1920" height="1080"></canvas>
+                <div id="preview-empty">
+                    <span data-icon="nav-media" class="big"></span>
+                    <p>Import media and drag it to the timeline</p>
+                </div>
+            </div>
+            <div id="preview-bar">
+                <div class="pb-left">
+                    <span id="tc-current">00:00:00:00</span>
+                    <span class="tc-sep">/</span>
+                    <span id="tc-total">00:00:00:00</span>
+                </div>
+                <div class="pb-center">
+                    <button class="pb-btn" id="btn-prev-edit" title="Previous edit point"><span data-icon="skip-back"></span></button>
+                    <button class="pb-btn play" id="btn-play" title="Play / Pause (Space)"><span data-icon="play" id="play-icon"></span></button>
+                    <button class="pb-btn" id="btn-next-edit" title="Next edit point"><span data-icon="skip-fwd"></span></button>
+                </div>
+                <div class="pb-right">
+                    <button class="pb-btn wide" id="btn-preview-zoom"><span id="preview-zoom-label">Fit</span><span data-icon="chevron-down" class="mini"></span></button>
+                    <button class="pb-btn" id="btn-safe-area" title="Toggle safe area"><span data-icon="display"></span></button>
+                    <button class="pb-btn" id="btn-fullscreen" title="Fullscreen preview"><span data-icon="fullscreen"></span></button>
+                </div>
+            </div>
+        </div>
+
+        <!-- Inspector -->
+        <div id="inspector">
+            <div id="inspector-tabs">
+                <button class="itab active" data-itab="video">Video</button>
+                <button class="itab" data-itab="audio">Audio</button>
+                <button class="itab" data-itab="effects">Effects</button>
+                <button class="itab" data-itab="transition">Transition</button>
+            </div>
+            <div id="inspector-body"></div>
+        </div>
+    </div>
+
+    <!-- ======================= Timeline toolbar ======================= -->
+    <div id="tl-toolbar">
+        <div class="tlt-left">
+            <button class="tlt-btn active" id="tool-select" title="Selection tool (V)"><span data-icon="cursor"></span></button>
+            <button class="tlt-btn" id="tool-blade" title="Blade tool (B)"><span data-icon="blade"></span></button>
+            <button class="tlt-btn" id="tool-crop" title="Crop"><span data-icon="crop"></span></button>
+            <button class="tlt-btn" id="tool-text" title="Text"><span data-icon="nav-text"></span></button>
+            <button class="tlt-btn" id="tool-audio" title="Audio mixer"><span data-icon="waveform"></span></button>
+        </div>
+        <div class="tlt-right">
+            <button class="tlt-btn" id="btn-undo" title="Undo (Ctrl+Z)"><span data-icon="undo"></span></button>
+            <button class="tlt-btn" id="btn-redo" title="Redo (Ctrl+Shift+Z)"><span data-icon="redo"></span></button>
+            <button class="tlt-btn" id="btn-delete-clip" title="Delete selected clip (Del)"><span data-icon="trash"></span></button>
+            <button class="tlt-btn" id="btn-split-clip" title="Split at playhead (S)"><span data-icon="sliders"></span></button>
+            <span class="tlt-sep"></span>
+            <button class="tlt-btn" id="btn-zoom-out" title="Zoom out"><span data-icon="minus"></span></button>
+            <input type="range" id="tl-zoom" min="4" max="200" value="40" title="Timeline zoom">
+            <button class="tlt-btn" id="btn-zoom-in" title="Zoom in"><span data-icon="plus"></span></button>
+            <button class="tlt-btn" id="btn-add-track" title="Add track"><span data-icon="plus-square"></span></button>
+        </div>
+    </div>
+
+    <!-- ======================= Timeline ======================= -->
+    <div id="timeline">
+        <div id="tl-headers">
+            <div id="tl-corner"></div>
+            <div id="tl-track-headers"></div>
+        </div>
+        <div id="tl-scroll">
+            <div id="tl-content">
+                <canvas id="tl-ruler"></canvas>
+                <div id="tl-tracks"></div>
+                <div id="tl-playhead"><div class="ph-handle"></div><div class="ph-line"></div></div>
+            </div>
+        </div>
+    </div>
+
+    <!-- Hidden helpers -->
+    <input type="file" id="local-file-input" multiple accept="video/*,audio/*,image/*" style="display:none;">
+    <div id="element-pool" style="display:none;"></div>
+    <div id="toast-holder"></div>
+    <div id="modal-holder"></div>
+    <div id="menu-holder"></div>
+
+    <script src="js/icons.js"></script>
+    <script src="js/ui.js"></script>
+    <script src="js/main.js"></script>
+    <script src="js/media.js"></script>
+    <script src="js/player.js"></script>
+    <script src="js/timeline.js"></script>
+    <script src="js/inspector.js"></script>
+    <script src="js/fileio.js"></script>
+    <script src="js/exporter.js"></script>
+    <script src="js/boot.js"></script>
+</body>
+</html>

+ 27 - 0
src/web/Cine Studio/init.agi

@@ -0,0 +1,27 @@
+/*
+	Cine Studio - Premiere-like video editor for ArozOS
+	Module registration script
+
+	Do not call any user / filepath functions in this script.
+*/
+
+//Define the launchInfo for the module
+var moduleLaunchInfo = {
+	Name: "Cine Studio",
+	Desc: "Minimalistic timeline video editor",
+	Group: "Media",
+	IconPath: "Cine Studio/img/module_icon.png",
+	Version: "1.0",
+	StartDir: "Cine Studio/index.html",
+	SupportFW: true,
+	LaunchFWDir: "Cine Studio/index.html",
+	SupportEmb: false,
+	InitFWSize: [1280, 850],
+	SupportedExt: [".cine"]
+}
+
+//Register the module
+registerModule(JSON.stringify(moduleLaunchInfo));
+
+//Register a custom icon for .cine project files
+registerExtensionIcon(".cine", "img/file_icon.png");

+ 159 - 0
src/web/Cine Studio/js/boot.js

@@ -0,0 +1,159 @@
+/*
+    Cine Studio - bootstrap and global chrome wiring
+*/
+"use strict";
+
+document.addEventListener("DOMContentLoaded", function () {
+
+    CS.applyIcons(document);
+    CS.newProject({});
+
+    CS.media.init();
+    CS.player.init();
+    CS.timeline.init();
+    CS.inspector.init();
+
+    /* ---------- top bar ---------- */
+
+    document.getElementById("btn-open-project").addEventListener("click", CS.fileio.openDialog);
+    document.getElementById("btn-save-project").addEventListener("click", CS.fileio.saveProject);
+    document.getElementById("btn-save-state").addEventListener("click", function () {
+        CS.toast(CS.state.dirty ? "Project has unsaved changes" : "Project is saved");
+    });
+    document.getElementById("project-name-btn").addEventListener("click", function (ev) {
+        CS.fileio.projectMenu(ev.currentTarget);
+    });
+    document.getElementById("btn-export").addEventListener("click", CS.exporter.dialog);
+    document.getElementById("btn-export-menu").addEventListener("click", function (ev) {
+        CS.exporter.quickMenu(ev.currentTarget.parentNode);
+    });
+    document.getElementById("btn-share").addEventListener("click", function () {
+        if (CS.inArozOS()) {
+            ao_module_openPath(CS.APP_ROOT + "/Exports");
+        } else {
+            CS.toast("Available inside ArozOS only");
+        }
+    });
+    document.getElementById("btn-settings").addEventListener("click", CS.fileio.settingsDialog);
+
+    //macOS traffic lights: red closes the float window
+    document.querySelector(".tl-close").addEventListener("click", function () {
+        function doClose() {
+            if (typeof ao_module_close !== "undefined") { ao_module_close(); }
+        }
+        if (CS.state.dirty) {
+            CS.confirm("Unsaved changes", "Close Cine Studio and discard unsaved changes?", doClose);
+        } else {
+            doClose();
+        }
+    });
+    document.querySelector(".tl-min").addEventListener("click", function () {
+        CS.toast("Use the desktop window controls to minimize");
+    });
+    document.querySelector(".tl-max").addEventListener("click", function () {
+        var stage = document.getElementById("preview-stage");
+        if (stage.requestFullscreen && !document.fullscreenElement) { stage.requestFullscreen(); }
+        else if (document.fullscreenElement) { document.exitFullscreen(); }
+    });
+
+    /* ---------- nav rail ---------- */
+
+    var navItems = document.querySelectorAll("#navrail .nav-item[data-nav]");
+    function activateNav(nav) {
+        for (var i = 0; i < navItems.length; i++) {
+            navItems[i].classList.toggle("active", navItems[i].getAttribute("data-nav") === nav);
+        }
+    }
+    for (var i = 0; i < navItems.length; i++) {
+        navItems[i].addEventListener("click", function () {
+            var nav = this.getAttribute("data-nav");
+            var kindLabel = document.getElementById("bin-kind-label");
+            if (nav === "media") {
+                activateNav(nav);
+                CS.state.binKind = "all";
+                kindLabel.textContent = "All Clips";
+                CS.media.renderBin();
+            } else if (nav === "audio") {
+                activateNav(nav);
+                CS.state.binKind = "audio";
+                kindLabel.textContent = "Audio";
+                CS.media.renderBin();
+            } else {
+                CS.toast(this.querySelector("label").textContent + " is not available in this version");
+            }
+        });
+    }
+
+    /* ---------- selection hook: keep inspector tab sensible ---------- */
+
+    var origSelect = CS.selectClip;
+    CS.selectClip = function (clipId) {
+        origSelect(clipId);
+        CS.inspector.autoTab();
+        CS.inspector.render();
+    };
+
+    /* ---------- keyboard shortcuts ---------- */
+
+    document.addEventListener("keydown", function (ev) {
+        var tag = (ev.target.tagName || "").toLowerCase();
+        if (tag === "input" || tag === "textarea" || tag === "select") { return; }
+
+        var fps = CS.project.settings.fps;
+        if (ev.code === "Space") {
+            ev.preventDefault();
+            CS.player.toggle();
+        } else if ((ev.ctrlKey || ev.metaKey) && ev.key.toLowerCase() === "s") {
+            ev.preventDefault();
+            CS.fileio.saveProject();
+        } else if ((ev.ctrlKey || ev.metaKey) && ev.key.toLowerCase() === "o") {
+            ev.preventDefault();
+            CS.fileio.openDialog();
+        } else if ((ev.ctrlKey || ev.metaKey) && ((ev.key.toLowerCase() === "z" && ev.shiftKey) || ev.key.toLowerCase() === "y")) {
+            ev.preventDefault();
+            CS.redo();
+        } else if ((ev.ctrlKey || ev.metaKey) && ev.key.toLowerCase() === "z") {
+            ev.preventDefault();
+            CS.undo();
+        } else if (ev.key === "Delete" || ev.key === "Backspace") {
+            if (CS.state.selectedClipId) {
+                ev.preventDefault();
+                CS.deleteSelectedClip();
+            }
+        } else if (ev.key.toLowerCase() === "v") {
+            CS.timeline.setTool("select");
+        } else if (ev.key.toLowerCase() === "b") {
+            CS.timeline.setTool("blade");
+        } else if (ev.key.toLowerCase() === "s" && !ev.ctrlKey && !ev.metaKey) {
+            CS.splitAtPlayhead();
+        } else if (ev.key === "ArrowLeft") {
+            ev.preventDefault();
+            CS.player.seek(CS.state.playhead - (ev.shiftKey ? 10 : 1) / fps);
+        } else if (ev.key === "ArrowRight") {
+            ev.preventDefault();
+            CS.player.seek(CS.state.playhead + (ev.shiftKey ? 10 : 1) / fps);
+        } else if (ev.key === "Home") {
+            ev.preventDefault();
+            CS.player.seek(0);
+        } else if (ev.key === "End") {
+            ev.preventDefault();
+            CS.player.seek(CS.timelineDuration());
+        }
+    });
+
+    /* ---------- ArozOS bootstrap ---------- */
+
+    CS.ensureAppFolders();
+    CS.checkServerFFmpeg();
+
+    /* ---------- initial paint ---------- */
+
+    CS.media.renderBin();
+    CS.timeline.render();
+    CS.inspector.render();
+    CS.player.invalidate();
+    CS.updateSaveState();
+
+    //Open a project / media passed by the desktop (double-click on .cine)
+    CS.fileio.openLaunchFiles();
+});

+ 325 - 0
src/web/Cine Studio/js/exporter.js

@@ -0,0 +1,325 @@
+/*
+    Cine Studio - export pipeline
+
+    Renders the timeline in real time: the preview canvas is captured
+    with captureStream and the WebAudio mix bus with a
+    MediaStreamDestination, both recorded by a MediaRecorder into WebM.
+    The result is uploaded to the ArozOS file system (or downloaded in
+    standalone mode). When the host has ffmpeg, the WebM can be
+    converted to MP4 server side.
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.exporter = {
+    active: false,
+    recorder: null,
+    chunks: [],
+    progressTimer: 0,
+    settings: null,
+    ui: null,
+
+    /* ---------- dialog ---------- */
+
+    dialog: function () {
+        if (CS.timelineDuration() <= 0) {
+            CS.toast("The timeline is empty - nothing to export", true);
+            return;
+        }
+        if (typeof MediaRecorder === "undefined") {
+            CS.toast("This browser does not support MediaRecorder export", true);
+            return;
+        }
+
+        var nameIn, formatIn, destRow;
+        var dest = { dir: CS.APP_ROOT + "/Exports", label: "Cine Studio/Exports" };
+        var inAroz = CS.inArozOS();
+
+        CS.modal({
+            title: "Export Video",
+            build: function (body) {
+                nameIn = CS.modalRow(body, "Filename", CS.textInput(CS.project.name || "Export"));
+
+                var formats = [{ v: "webm", l: "WebM (VP9)" }];
+                if (inAroz) {
+                    formats.push({ v: "mp4", l: CS.serverFFmpeg ? "MP4 (server ffmpeg)" : "MP4 (unavailable - no ffmpeg)" });
+                }
+                formatIn = CS.modalRow(body, "Format", CS.selectInput(formats, "webm"));
+
+                if (inAroz) {
+                    var destBtn = document.createElement("button");
+                    destBtn.className = "modal-btn";
+                    destBtn.textContent = dest.label;
+                    destBtn.title = "Choose destination folder";
+                    destBtn.addEventListener("click", function () {
+                        window.csExportDestCallback = function csExportDestCallback(filedata) {
+                            if (!filedata || !filedata.length) { return; }
+                            dest.dir = filedata[0].filepath;
+                            destBtn.textContent = filedata[0].filename || dest.dir;
+                        };
+                        ao_module_openFileSelector(window.csExportDestCallback, CS.APP_ROOT + "/Exports", "folder", false);
+                    });
+                    destRow = CS.modalRow(body, "Save to", destBtn);
+                }
+
+                var note = document.createElement("div");
+                note.className = "modal-note";
+                note.textContent = "The timeline is rendered in real time at "
+                    + CS.project.settings.width + " x " + CS.project.settings.height
+                    + ". Keep this window visible during export.";
+                body.appendChild(note);
+            },
+            buttons: [
+                { label: "Cancel" },
+                {
+                    label: "Export", primary: true,
+                    action: function () {
+                        var format = formatIn.value;
+                        if (format === "mp4" && !CS.serverFFmpeg) {
+                            CS.toast("MP4 export needs ffmpeg on the ArozOS host", true);
+                            return false;
+                        }
+                        var base = (nameIn.value.trim() || "Export").replace(/[\\/:*?"<>|]/g, "_");
+                        CS.exporter.start({
+                            base: base,
+                            format: format,
+                            destDir: dest.dir,
+                            toDevice: !inAroz
+                        });
+                        //start() swapped this dialog for the progress modal
+                        return false;
+                    }
+                }
+            ]
+        });
+    },
+
+    quickMenu: function (anchorEl) {
+        CS.showMenuUnder(anchorEl, [
+            { label: "Export Video...", icon: "export-up", action: CS.exporter.dialog },
+            { sep: true },
+            { label: "Save Project", icon: "save", action: CS.fileio.saveProject },
+            { label: "Save Project As...", icon: "save", action: CS.fileio.saveProjectAs }
+        ]);
+    },
+
+    /* ---------- recording ---------- */
+
+    pickMimeType: function () {
+        var candidates = [
+            "video/webm;codecs=vp9,opus",
+            "video/webm;codecs=vp8,opus",
+            "video/webm"
+        ];
+        for (var i = 0; i < candidates.length; i++) {
+            if (MediaRecorder.isTypeSupported(candidates[i])) { return candidates[i]; }
+        }
+        return "";
+    },
+
+    start: function (settings) {
+        CS.exporter.settings = settings;
+        CS.exporter.chunks = [];
+        CS.player.pause();
+        CS.player.initAudioBus();
+
+        //Video: capture the compositing canvas
+        var fps = CS.project.settings.fps;
+        var stream;
+        try {
+            stream = CS.player.canvas.captureStream(fps);
+        } catch (e) {
+            CS.toast("Canvas capture is not supported in this browser", true);
+            return;
+        }
+
+        //Audio: tap the master mix bus
+        if (CS.player.audioCtx && CS.player.masterGain) {
+            try {
+                CS.exporter.audioDest = CS.player.audioCtx.createMediaStreamDestination();
+                CS.player.masterGain.connect(CS.exporter.audioDest);
+                CS.exporter.audioDest.stream.getAudioTracks().forEach(function (t) {
+                    stream.addTrack(t);
+                });
+            } catch (e) { /* silent export */ }
+        }
+
+        var mime = CS.exporter.pickMimeType();
+        try {
+            CS.exporter.recorder = new MediaRecorder(stream, mime ? {
+                mimeType: mime,
+                videoBitsPerSecond: 12000000,
+                audioBitsPerSecond: 192000
+            } : undefined);
+        } catch (e) {
+            CS.toast("Cannot start recorder: " + e.message, true);
+            return;
+        }
+
+        CS.exporter.recorder.ondataavailable = function (ev) {
+            if (ev.data && ev.data.size) { CS.exporter.chunks.push(ev.data); }
+        };
+        CS.exporter.recorder.onstop = CS.exporter.onRecorderStop;
+
+        CS.exporter.active = true;
+        CS.exporter.showProgress();
+
+        //Roll from the very beginning and let the player drive the frames
+        CS.player.seek(0);
+        CS.exporter.recorder.start(250);
+        CS.player.play();
+    },
+
+    showProgress: function () {
+        var fill, label;
+        var ui = CS.modal({
+            title: "Exporting...",
+            build: function (body) {
+                var bar = document.createElement("div");
+                bar.className = "modal-progress";
+                fill = document.createElement("div");
+                fill.className = "fill";
+                bar.appendChild(fill);
+                body.appendChild(bar);
+                label = document.createElement("div");
+                label.className = "modal-note";
+                label.textContent = "Rendering timeline in real time...";
+                body.appendChild(label);
+            },
+            buttons: [
+                {
+                    label: "Cancel", action: function () {
+                        CS.exporter.cancel();
+                    }
+                }
+            ]
+        });
+        CS.exporter.ui = { fill: fill, label: label };
+        CS.exporter.progressTimer = setInterval(function () {
+            var dur = CS.timelineDuration();
+            var pct = dur > 0 ? Math.min(100, (CS.state.playhead / dur) * 100) : 0;
+            fill.style.width = pct.toFixed(1) + "%";
+            label.textContent = "Rendering " + CS.timecode(CS.state.playhead) + " / " + CS.timecode(dur);
+        }, 200);
+    },
+
+    //Player calls this whenever playback stops; only meaningful mid-export
+    onPlaybackStopped: function () {
+        if (!CS.exporter.active) { return; }
+        CS.exporter.active = false;
+        clearInterval(CS.exporter.progressTimer);
+        if (CS.exporter.ui) {
+            CS.exporter.ui.fill.style.width = "100%";
+            CS.exporter.ui.label.textContent = "Finalizing...";
+        }
+        if (CS.exporter.recorder && CS.exporter.recorder.state !== "inactive") {
+            CS.exporter.recorder.stop();
+        }
+    },
+
+    cancel: function () {
+        clearInterval(CS.exporter.progressTimer);
+        if (!CS.exporter.active) { return; }
+        CS.exporter.active = false;
+        CS.exporter.cancelled = true;
+        if (CS.exporter.recorder && CS.exporter.recorder.state !== "inactive") {
+            CS.exporter.recorder.stop();
+        }
+        CS.player.pause();
+        CS.toast("Export cancelled");
+    },
+
+    detachAudioTap: function () {
+        if (CS.exporter.audioDest && CS.player.masterGain) {
+            try { CS.player.masterGain.disconnect(CS.exporter.audioDest); } catch (e) {}
+            CS.exporter.audioDest = null;
+        }
+    },
+
+    onRecorderStop: function () {
+        CS.exporter.detachAudioTap();
+        var wasCancelled = CS.exporter.cancelled;
+        CS.exporter.cancelled = false;
+        var chunks = CS.exporter.chunks;
+        CS.exporter.chunks = [];
+        CS.exporter.recorder = null;
+        if (wasCancelled) { CS.closeModal(); return; }
+
+        var blob = new Blob(chunks, { type: "video/webm" });
+        var s = CS.exporter.settings;
+
+        if (s.toDevice) {
+            CS.fileio.downloadBlob(blob, s.base + ".webm");
+            CS.closeModal();
+            CS.toast("Export downloaded");
+            return;
+        }
+
+        if (s.format === "mp4") {
+            CS.exporter.uploadAndConvert(blob, s);
+        } else {
+            CS.exporter.upload(blob, s.base + ".webm", s.destDir, function () {
+                CS.closeModal();
+                CS.exporter.finished(s.destDir, s.base + ".webm");
+            });
+        }
+    },
+
+    upload: function (blob, filename, destDir, done) {
+        if (CS.exporter.ui) { CS.exporter.ui.label.textContent = "Uploading " + filename + "..."; }
+        var file = new File([blob], filename, { type: blob.type });
+        ao_module_uploadFile(file, destDir, function () {
+            done();
+        }, function (pct) {
+            if (CS.exporter.ui) { CS.exporter.ui.label.textContent = "Uploading " + filename + " (" + Math.round(pct) + "%)"; }
+        }, function () {
+            CS.closeModal();
+            CS.toast("Upload failed - check permissions", true);
+        });
+    },
+
+    uploadAndConvert: function (blob, s) {
+        var tempName = s.base + ".render.webm";
+        CS.exporter.upload(blob, tempName, s.destDir, function () {
+            if (CS.exporter.ui) { CS.exporter.ui.label.textContent = "Converting to MP4 on the server..."; }
+            var src = s.destDir + "/" + tempName;
+            var dst = s.destDir + "/" + s.base + ".mp4";
+            ao_module_agirun("Cine Studio/backend/ffmpegtools.js", {
+                action: "convert",
+                src: src,
+                dst: dst
+            }, function (resp) {
+                var data;
+                try { data = typeof resp === "string" ? JSON.parse(resp) : resp; }
+                catch (e) { data = { error: "bad response" }; }
+
+                //Remove the temporary webm regardless of the outcome
+                ao_module_agirun("Cine Studio/backend/ffmpegtools.js", {
+                    action: "cleanup",
+                    target: src
+                }, function () {}, function () {});
+
+                CS.closeModal();
+                if (data && data.success) {
+                    CS.exporter.finished(s.destDir, s.base + ".mp4");
+                } else {
+                    CS.toast("MP4 conversion failed: " + ((data && data.error) || "unknown error"), true);
+                }
+            }, function () {
+                CS.closeModal();
+                CS.toast("MP4 conversion request failed", true);
+            }, 0);
+        });
+    },
+
+    finished: function (destDir, filename) {
+        CS.toast("Exported " + filename);
+        CS.showMenu([
+            { label: "Reveal in File Manager", icon: "folder", action: function () {
+                ao_module_openPath(destDir, filename);
+            } },
+            { label: "Done", icon: "check-circle", action: function () {} }
+        ], window.innerWidth / 2 - 100, 80);
+    }
+};

+ 341 - 0
src/web/Cine Studio/js/fileio.js

@@ -0,0 +1,341 @@
+/*
+    Cine Studio - project file I/O
+
+    Native project format: .cine (JSON). Media is stored as ArozOS
+    virtual path references; thumbnails, filmstrips and waveforms are
+    re-probed when the project is opened. Files are read through the
+    /media endpoint and written with ao_module_uploadFile, falling back
+    to browser download / picker outside ArozOS.
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.fileio = {
+
+    /* ---------- serialization ---------- */
+
+    serializeProject: function () {
+        return JSON.stringify({
+            app: "CineStudio",
+            version: 1,
+            name: CS.project.name,
+            settings: CS.project.settings,
+            media: CS.project.media.map(function (m) {
+                return { id: m.id, name: m.name, vpath: m.vpath || "", type: m.type };
+            }),
+            tracks: CS.project.tracks,
+            clips: CS.project.clips
+        }, null, 1);
+    },
+
+    loadProject: function (data, filepath, filename) {
+        if (!data || data.app !== "CineStudio" || !Array.isArray(data.clips)) {
+            CS.toast("Not a Cine Studio project file", true);
+            return;
+        }
+
+        CS.newProject({
+            name: data.name || CS.baseName(filename || "My Project"),
+            width: (data.settings && data.settings.width) || 1920,
+            height: (data.settings && data.settings.height) || 1080,
+            fps: (data.settings && data.settings.fps) || 30
+        });
+        CS.project.filePath = filepath || "";
+        CS.project.fileName = filename || "";
+
+        if (Array.isArray(data.tracks) && data.tracks.length) {
+            CS.project.tracks = data.tracks;
+        }
+
+        //Restore media references and start probing them again
+        (data.media || []).forEach(function (m) {
+            var media = {
+                id: m.id,
+                name: m.name,
+                vpath: m.vpath || "",
+                blobUrl: "",
+                type: m.type,
+                duration: m.type === "image" ? CS.IMAGE_DEFAULT_DURATION : 0,
+                width: 0,
+                height: 0,
+                thumbs: [],
+                peaks: null,
+                offline: false,
+                probed: false
+            };
+            CS.project.media.push(media);
+            if (media.vpath && CS.inArozOS()) {
+                CS.media.probe(media);
+            } else if (media.vpath && !CS.inArozOS()) {
+                CS.media.markOffline(media);
+            } else {
+                //Media that was imported from the device without upload
+                CS.media.markOffline(media);
+            }
+        });
+
+        //Restore clips, keeping only ones whose media still exists
+        CS.project.clips = (data.clips || []).filter(function (c) {
+            return CS.getMedia(c.mediaId);
+        }).map(function (c) {
+            var props = CS.defaultClipProps();
+            Object.keys(c.props || {}).forEach(function (k) { props[k] = c.props[k]; });
+            c.props = props;
+            return c;
+        });
+
+        CS.history = { stack: [], index: -1 };
+        CS.pushHistory("Open Project");
+        CS.markClean();
+        CS.player.applyProjectSize();
+        CS.media.renderBin();
+        CS.timeline.render();
+        CS.inspector.render();
+        CS.player.invalidate();
+        CS.toast("Opened " + (filename || CS.project.name));
+    },
+
+    /* ---------- open ---------- */
+
+    confirmDiscard: function (next) {
+        if (!CS.state.dirty) { next(); return; }
+        CS.confirm("Unsaved changes", "The current project has unsaved changes. Continue and discard them?", next);
+    },
+
+    openDialog: function () {
+        CS.fileio.confirmDiscard(function () {
+            if (CS.inArozOS() && typeof ao_module_openFileSelector !== "undefined") {
+                window.csOpenCallback = function csOpenCallback(filedata) {
+                    if (!filedata || !filedata.length) { return; }
+                    CS.fileio.openFromPath(filedata[0].filepath, filedata[0].filename);
+                };
+                ao_module_openFileSelector(window.csOpenCallback, CS.APP_ROOT + "/Projects", "file", false, {
+                    filter: [CS.PROJECT_EXT]
+                });
+            } else {
+                var inp = document.createElement("input");
+                inp.type = "file";
+                inp.accept = "." + CS.PROJECT_EXT;
+                inp.addEventListener("change", function () {
+                    if (!inp.files.length) { return; }
+                    inp.files[0].text().then(function (txt) {
+                        try { CS.fileio.loadProject(JSON.parse(txt), "", inp.files[0].name); }
+                        catch (e) { CS.toast("Invalid project file", true); }
+                    });
+                });
+                inp.click();
+            }
+        });
+    },
+
+    openFromPath: function (filepath, filename) {
+        fetch("../media?file=" + encodeURIComponent(filepath))
+            .then(function (r) {
+                if (!r.ok) { throw new Error("HTTP " + r.status); }
+                return r.json();
+            })
+            .then(function (data) { CS.fileio.loadProject(data, filepath, filename); })
+            .catch(function (err) {
+                CS.toast("Cannot open project: " + err.message, true);
+            });
+    },
+
+    //Files passed by the desktop when the app is launched as an opener
+    openLaunchFiles: function () {
+        var inputFiles = null;
+        try {
+            if (typeof ao_module_loadInputFiles !== "undefined") {
+                inputFiles = ao_module_loadInputFiles();
+            }
+        } catch (e) { inputFiles = null; }
+        if (inputFiles && inputFiles.length > 0) {
+            var f = inputFiles[0];
+            if (CS.extOf(f.filename) === CS.PROJECT_EXT) {
+                CS.fileio.openFromPath(f.filepath, f.filename);
+            } else {
+                CS.media.addFromVpath(f.filepath, f.filename);
+            }
+            return true;
+        }
+        return false;
+    },
+
+    /* ---------- save ---------- */
+
+    saveProject: function () {
+        //Warn about media that cannot be re-opened later
+        var volatile = CS.project.media.filter(function (m) { return !m.vpath; });
+        if (volatile.length) {
+            CS.toast(volatile.length + " media item(s) are not stored on the server and will be offline when reopened", true);
+        }
+        if (!CS.project.filePath) { CS.fileio.saveProjectAs(); return; }
+        CS.fileio.writeProjectTo(CS.project.filePath, CS.project.fileName);
+    },
+
+    saveProjectAs: function () {
+        var defaultName = (CS.project.name || "My Project") + "." + CS.PROJECT_EXT;
+        if (CS.inArozOS() && typeof ao_module_openFileSelector !== "undefined") {
+            window.csSaveAsCallback = function csSaveAsCallback(filedata) {
+                if (!filedata || !filedata.length) { return; }
+                var f = filedata[0];
+                var filepath = f.filepath;
+                var filename = f.filename;
+                if (CS.extOf(filename) !== CS.PROJECT_EXT) {
+                    filename += "." + CS.PROJECT_EXT;
+                    filepath += "." + CS.PROJECT_EXT;
+                }
+                CS.fileio.writeProjectTo(filepath, filename);
+            };
+            ao_module_openFileSelector(window.csSaveAsCallback, CS.APP_ROOT + "/Projects", "new", false, {
+                defaultName: defaultName
+            });
+        } else {
+            var blob = new Blob([CS.fileio.serializeProject()], { type: "application/json" });
+            CS.fileio.downloadBlob(blob, defaultName);
+            CS.markClean();
+        }
+    },
+
+    writeProjectTo: function (filepath, filename) {
+        var blob = new Blob([CS.fileio.serializeProject()], { type: "application/json" });
+        var file = new File([blob], filename, { type: "application/json" });
+        try {
+            ao_module_uploadFile(file, CS.dirOf(filepath), function () {
+                CS.project.filePath = filepath;
+                CS.project.fileName = filename;
+                CS.project.name = CS.baseName(filename);
+                CS.markClean();
+                CS.toast("Saved " + filename);
+            }, undefined, function () {
+                CS.toast("Save failed - check permissions", true);
+            });
+        } catch (e) {
+            CS.fileio.downloadBlob(blob, filename);
+            CS.markClean();
+        }
+    },
+
+    downloadBlob: function (blob, filename) {
+        var a = document.createElement("a");
+        a.href = URL.createObjectURL(blob);
+        a.download = filename;
+        a.click();
+        setTimeout(function () { URL.revokeObjectURL(a.href); }, 5000);
+    },
+
+    /* ---------- project dialogs ---------- */
+
+    newProjectDialog: function () {
+        CS.fileio.confirmDiscard(function () {
+            var nameIn, resIn, fpsIn;
+            CS.modal({
+                title: "New Project",
+                build: function (body) {
+                    nameIn = CS.modalRow(body, "Name", CS.textInput("My Project"));
+                    resIn = CS.modalRow(body, "Resolution", CS.selectInput([
+                        { v: "1920x1080", l: "1920 x 1080 (Full HD)" },
+                        { v: "1280x720", l: "1280 x 720 (HD)" },
+                        { v: "3840x2160", l: "3840 x 2160 (4K)" },
+                        { v: "1080x1920", l: "1080 x 1920 (Vertical)" },
+                        { v: "1080x1080", l: "1080 x 1080 (Square)" }
+                    ], "1920x1080"));
+                    fpsIn = CS.modalRow(body, "Frame rate", CS.selectInput([
+                        { v: "24", l: "24 fps" },
+                        { v: "25", l: "25 fps" },
+                        { v: "30", l: "30 fps" },
+                        { v: "60", l: "60 fps" }
+                    ], "30"));
+                },
+                buttons: [
+                    { label: "Cancel" },
+                    {
+                        label: "Create", primary: true,
+                        action: function () {
+                            var res = resIn.value.split("x");
+                            CS.newProject({
+                                name: nameIn.value.trim() || "My Project",
+                                width: parseInt(res[0], 10),
+                                height: parseInt(res[1], 10),
+                                fps: parseInt(fpsIn.value, 10)
+                            });
+                            CS.player.applyProjectSize();
+                            CS.media.renderBin();
+                            CS.timeline.render();
+                            CS.inspector.render();
+                            CS.player.invalidate();
+                            CS.updateSaveState();
+                        }
+                    }
+                ]
+            });
+        });
+    },
+
+    renameDialog: function () {
+        var nameIn;
+        CS.modal({
+            title: "Rename Project",
+            build: function (body) {
+                nameIn = CS.modalRow(body, "Name", CS.textInput(CS.project.name));
+            },
+            buttons: [
+                { label: "Cancel" },
+                {
+                    label: "Rename", primary: true,
+                    action: function () {
+                        var v = nameIn.value.trim();
+                        if (v) {
+                            CS.project.name = v;
+                            CS.markDirty();
+                        }
+                    }
+                }
+            ]
+        });
+    },
+
+    settingsDialog: function () {
+        var wIn, hIn, fpsIn;
+        CS.modal({
+            title: "Project Settings",
+            build: function (body) {
+                wIn = CS.modalRow(body, "Width (px)", CS.textInput(String(CS.project.settings.width)));
+                hIn = CS.modalRow(body, "Height (px)", CS.textInput(String(CS.project.settings.height)));
+                fpsIn = CS.modalRow(body, "Frame rate", CS.selectInput([
+                    { v: "24", l: "24 fps" },
+                    { v: "25", l: "25 fps" },
+                    { v: "30", l: "30 fps" },
+                    { v: "60", l: "60 fps" }
+                ], String(CS.project.settings.fps)));
+            },
+            buttons: [
+                { label: "Cancel" },
+                {
+                    label: "Apply", primary: true,
+                    action: function () {
+                        CS.project.settings.width = CS.clamp(parseInt(wIn.value, 10) || 1920, 16, 7680);
+                        CS.project.settings.height = CS.clamp(parseInt(hIn.value, 10) || 1080, 16, 4320);
+                        CS.project.settings.fps = parseInt(fpsIn.value, 10) || 30;
+                        CS.player.applyProjectSize();
+                        CS.markDirty();
+                        CS.player.invalidate();
+                    }
+                }
+            ]
+        });
+    },
+
+    projectMenu: function (anchorEl) {
+        CS.showMenuUnder(anchorEl, [
+            { label: "New Project...", icon: "file", action: CS.fileio.newProjectDialog },
+            { label: "Open Project...", icon: "folder", action: CS.fileio.openDialog },
+            { sep: true },
+            { label: "Save", icon: "save", action: CS.fileio.saveProject },
+            { label: "Save As...", icon: "save", action: CS.fileio.saveProjectAs },
+            { sep: true },
+            { label: "Rename...", icon: "nav-text", action: CS.fileio.renameDialog },
+            { label: "Project Settings...", icon: "gear", action: CS.fileio.settingsDialog }
+        ]);
+    }
+};

+ 91 - 0
src/web/Cine Studio/js/icons.js

@@ -0,0 +1,91 @@
+/*
+    Cine Studio - inline SVG icon registry
+
+    All glyphs are drawn as inline SVG (24x24 stroke paths) per the
+    project convention of never using literal emoji. Elements declare
+    an icon with data-icon="name"; CS.applyIcons() injects the markup.
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.iconPaths = {
+    "folder":        '<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7z"/>',
+    "chevron-down":  '<path d="M6 9l6 6 6-6"/>',
+    "chevron-right": '<path d="M9 6l6 6-6 6"/>',
+    "save":          '<path d="M12 3v12"/><path d="M7 10l5 5 5-5"/><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"/>',
+    "check-circle":  '<circle cx="12" cy="12" r="9"/><path d="M8.5 12.2l2.4 2.4 4.6-5"/>',
+    "dot-circle":    '<circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="3" style="fill:currentColor;stroke:none"/>',
+    "panel-right":   '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M15 4v16"/>',
+    "share":         '<rect x="4" y="9" width="16" height="12" rx="2"/><path d="M12 2v11"/><path d="M8 6l4-4 4 4"/>',
+    "export-up":     '<path d="M12 15V4"/><path d="M8 8l4-4 4 4"/><path d="M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3"/>',
+
+    "nav-media":     '<rect x="3" y="5" width="18" height="14" rx="2.5"/><path d="M3 9h18"/><path d="M7 5v4"/><path d="M12 5v4"/><path d="M17 5v4"/>',
+    "nav-audio":     '<circle cx="7" cy="17" r="3"/><circle cx="17" cy="15" r="3"/><path d="M10 17V6l10-2v11"/>',
+    "nav-titles":    '<rect x="3" y="5" width="18" height="14" rx="2.5"/><path d="M8 10h8"/><path d="M12 10v5"/>',
+    "nav-transitions": '<rect x="3" y="6" width="8" height="12" rx="2"/><rect x="13" y="6" width="8" height="12" rx="2" stroke-dasharray="2.5 2.5"/>',
+    "nav-effects":   '<path d="M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9L12 3z"/><path d="M18.5 15.5l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8.8-2.2z"/>',
+    "nav-elements":  '<rect x="4" y="4" width="7" height="7" rx="1.8"/><rect x="13" y="4" width="7" height="7" rx="1.8"/><rect x="4" y="13" width="7" height="7" rx="1.8"/><rect x="13" y="13" width="7" height="7" rx="1.8"/>',
+    "nav-text":      '<path d="M5 6V4h14v2"/><path d="M12 4v16"/><path d="M9 20h6"/>',
+    "nav-filters":   '<circle cx="9" cy="9" r="5.5"/><circle cx="15" cy="15" r="5.5"/>',
+    "nav-libraries": '<path d="M6 3h12a1 1 0 0 1 1 1v17l-7-4-7 4V4a1 1 0 0 1 1-1z"/>',
+    "gear":          '<circle cx="12" cy="12" r="3.2"/><path d="M12 2.8l1.2 2.5 2.7-.6 1 2.5 2.7.7-.6 2.7 2 1.9-2 1.9.6 2.7-2.7.7-1 2.5-2.7-.6L12 21.2l-1.2-2.5-2.7.6-1-2.5-2.7-.7.6-2.7-2-1.9 2-1.9-.6-2.7 2.7-.7 1-2.5 2.7.6L12 2.8z"/>',
+
+    "funnel":        '<path d="M4 5h16l-6.2 7.4V19l-3.6-2v-4.6L4 5z"/>',
+    "list-view":     '<path d="M9 6h11"/><path d="M9 12h11"/><path d="M9 18h11"/><path d="M4 6h1"/><path d="M4 12h1"/><path d="M4 18h1"/>',
+    "search":        '<circle cx="11" cy="11" r="7"/><path d="M16.5 16.5L21 21"/>',
+
+    "skip-back":     '<path d="M7 5v14"/><path d="M18 6.5v11L10 12l8-5.5z"/>',
+    "skip-fwd":      '<path d="M17 5v14"/><path d="M6 6.5v11L14 12 6 6.5z"/>',
+    "play":          '<path d="M7.5 5.2v13.6c0 .8.9 1.3 1.6.9l10.5-6.8c.6-.4.6-1.4 0-1.8L9.1 4.3c-.7-.4-1.6.1-1.6.9z"/>',
+    "pause":         '<rect x="6.5" y="5" width="3.6" height="14" rx="1.2"/><rect x="13.9" y="5" width="3.6" height="14" rx="1.2"/>',
+    "display":       '<rect x="3" y="5" width="18" height="12" rx="2"/><path d="M9 21h6"/><path d="M12 17v4"/>',
+    "fullscreen":    '<path d="M4 9V5a1 1 0 0 1 1-1h4"/><path d="M20 9V5a1 1 0 0 0-1-1h-4"/><path d="M4 15v4a1 1 0 0 0 1 1h4"/><path d="M20 15v4a1 1 0 0 1-1 1h-4"/>',
+
+    "cursor":        '<path d="M6 3.5l12 7.6-5.2 1.2-2.6 4.9L6 3.5z"/>',
+    "blade":         '<path d="M4 17L17 4l3 3L7 20H4v-3z"/><path d="M14 7l3 3"/>',
+    "crop":          '<path d="M7 2v15a1 1 0 0 0 1 1h14"/><path d="M2 7h15a1 1 0 0 1 1 1v14"/>',
+    "waveform":      '<path d="M4 10v4"/><path d="M8 7v10"/><path d="M12 4v16"/><path d="M16 8v8"/><path d="M20 10v4"/>',
+    "undo":          '<path d="M8 5L3 10l5 5"/><path d="M3 10h11a6 6 0 0 1 6 6v1"/>',
+    "redo":          '<path d="M16 5l5 5-5 5"/><path d="M21 10H10a6 6 0 0 0-6 6v1"/>',
+    "trash":         '<path d="M4 7h16"/><path d="M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2"/><path d="M6 7l1 13a1 1 0 0 0 1 .9h8a1 1 0 0 0 1-.9L18 7"/><path d="M10 11v6"/><path d="M14 11v6"/>',
+    "sliders":       '<path d="M4 8h10"/><path d="M18 8h2"/><circle cx="16" cy="8" r="2"/><path d="M4 16h2"/><path d="M10 16h10"/><circle cx="8" cy="16" r="2"/>',
+    "minus":         '<path d="M5 12h14"/>',
+    "plus":          '<path d="M12 5v14"/><path d="M5 12h14"/>',
+    "plus-square":   '<rect x="4" y="4" width="16" height="16" rx="3"/><path d="M12 9v6"/><path d="M9 12h6"/>',
+
+    "film":          '<rect x="3" y="4" width="18" height="16" rx="2"/><path d="M8 4v16"/><path d="M16 4v16"/><path d="M3 9h5"/><path d="M3 15h5"/><path d="M16 9h5"/><path d="M16 15h5"/>',
+    "speaker":       '<path d="M4 10v4h3l5 4V6L7 10H4z"/><path d="M15.5 9.5a4 4 0 0 1 0 5"/><path d="M18 7a7.5 7.5 0 0 1 0 10"/>',
+    "eye":           '<path d="M2.5 12S6 5.8 12 5.8 21.5 12 21.5 12 18 18.2 12 18.2 2.5 12 2.5 12z"/><circle cx="12" cy="12" r="2.8"/>',
+    "eye-off":       '<path d="M2.5 12S6 5.8 12 5.8c1.9 0 3.6.6 5 1.5M21.5 12S18 18.2 12 18.2c-1.9 0-3.6-.6-5-1.5"/><path d="M4 20L20 4"/>',
+    "lock":          '<rect x="5" y="11" width="14" height="9" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/>',
+    "rotate-ccw":    '<path d="M3 4v5h5"/><path d="M3.5 9a8.5 8.5 0 1 1-1 6"/>',
+    "warning":       '<path d="M12 3L2.5 20h19L12 3z"/><path d="M12 9.5V14"/><path d="M12 16.8v.4"/>',
+    "music":         '<circle cx="7" cy="17" r="3"/><path d="M10 17V5l9-2v11"/><circle cx="16" cy="14" r="3"/>',
+    "image":         '<rect x="3" y="4" width="18" height="16" rx="2"/><circle cx="9" cy="10" r="1.8"/><path d="M3 17l5.5-5 4.5 4 3-2.5 5 4"/>',
+    "upload":        '<path d="M12 15V4"/><path d="M8 8l4-4 4 4"/><path d="M4 16v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2"/>',
+    "server":        '<rect x="3" y="4" width="18" height="7" rx="2"/><rect x="3" y="13" width="18" height="7" rx="2"/><path d="M7 7.5h.01"/><path d="M7 16.5h.01"/>',
+    "file":          '<path d="M6 2h8l5 5v13a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z"/><path d="M14 2v5h5"/>',
+    "scissors":      '<circle cx="6" cy="6" r="2.5"/><circle cx="6" cy="18" r="2.5"/><path d="M8.2 7.6L20 19"/><path d="M20 5L8.2 16.4"/>'
+};
+
+CS.iconSVG = function (name, extraClass) {
+    var path = CS.iconPaths[name] || "";
+    return '<svg viewBox="0 0 24 24"' + (extraClass ? ' class="' + extraClass + '"' : "") + ">" + path + "</svg>";
+};
+
+//Replace every [data-icon] element's content with its SVG glyph
+CS.applyIcons = function (rootEl) {
+    var scope = rootEl || document;
+    var nodes = scope.querySelectorAll("[data-icon]");
+    for (var i = 0; i < nodes.length; i++) {
+        var name = nodes[i].getAttribute("data-icon");
+        nodes[i].innerHTML = CS.iconSVG(name);
+    }
+};
+
+//Swap the icon of a single element in place
+CS.setIcon = function (el, name) {
+    el.setAttribute("data-icon", name);
+    el.innerHTML = CS.iconSVG(name);
+};

+ 364 - 0
src/web/Cine Studio/js/inspector.js

@@ -0,0 +1,364 @@
+/*
+    Cine Studio - inspector panel
+
+    Property editor for the selected clip: Transform / Crop / Color on
+    the Video tab, volume on the Audio tab. Values live-update the
+    preview; history is committed when the gesture ends.
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.inspector = {
+    activeTab: "video",
+    _collapsed: {},
+
+    init: function () {
+        var tabs = document.querySelectorAll(".itab");
+        for (var i = 0; i < tabs.length; i++) {
+            tabs[i].addEventListener("click", function () {
+                CS.inspector.activeTab = this.getAttribute("data-itab");
+                CS.inspector.updateTabs();
+                CS.inspector.render();
+            });
+        }
+        document.getElementById("btn-toggle-inspector").addEventListener("click", function () {
+            document.getElementById("inspector").classList.toggle("hidden");
+        });
+    },
+
+    updateTabs: function () {
+        var tabs = document.querySelectorAll(".itab");
+        for (var i = 0; i < tabs.length; i++) {
+            tabs[i].classList.toggle("active", tabs[i].getAttribute("data-itab") === CS.inspector.activeTab);
+        }
+    },
+
+    //Called when the selection changes: pick a sensible tab automatically
+    autoTab: function () {
+        var clip = CS.selectedClip();
+        if (!clip) { return; }
+        var track = CS.getTrack(clip.trackId);
+        if (track && track.kind === "audio" && CS.inspector.activeTab === "video") {
+            CS.inspector.activeTab = "audio";
+            CS.inspector.updateTabs();
+        }
+        if (track && track.kind === "video" && CS.inspector.activeTab === "audio") {
+            CS.inspector.activeTab = "video";
+            CS.inspector.updateTabs();
+        }
+    },
+
+    render: function () {
+        var body = document.getElementById("inspector-body");
+        body.innerHTML = "";
+        var clip = CS.selectedClip();
+
+        if (CS.inspector.activeTab === "effects") {
+            CS.inspector.placeholder(body, "Effects are not available in this version. Use the Color section on the Video tab for exposure, contrast and saturation.");
+            return;
+        }
+        if (CS.inspector.activeTab === "transition") {
+            CS.inspector.placeholder(body, "Transitions are not available in this version. Clips cut from one to the next.");
+            return;
+        }
+
+        if (!clip) {
+            CS.inspector.placeholder(body, "Select a clip on the timeline to edit its properties.");
+            return;
+        }
+        var track = CS.getTrack(clip.trackId);
+        var media = CS.getMedia(clip.mediaId);
+
+        if (CS.inspector.activeTab === "audio") {
+            CS.inspector.renderAudioTab(body, clip, media, track);
+            return;
+        }
+
+        if (track && track.kind === "audio") {
+            CS.inspector.placeholder(body, "This is an audio clip. Use the Audio tab to adjust it.");
+            return;
+        }
+
+        CS.inspector.renderVideoTab(body, clip);
+    },
+
+    placeholder: function (body, text) {
+        var el = document.createElement("div");
+        el.className = "insp-placeholder";
+        el.textContent = text;
+        body.appendChild(el);
+    },
+
+    /* ---------- video tab ---------- */
+
+    renderVideoTab: function (body, clip) {
+        var p = clip.props;
+
+        //---- Transform ----
+        var transform = CS.inspector.section(body, "Transform", function () {
+            p.x = 0; p.y = 0; p.scale = 100; p.rotation = 0; p.opacity = 100;
+            CS.commit("Reset Transform");
+        });
+
+        var xChip = CS.inspector.numChip("X", p.x, "", function (v) { p.x = v; }, 1);
+        var yChip = CS.inspector.numChip("Y", p.y, "", function (v) { p.y = v; }, 1);
+        CS.inspector.row(transform, "Position", [xChip, yChip]);
+
+        CS.inspector.row(transform, "Scale", [
+            CS.inspector.slider(10, 300, 1, p.scale, function (v) { p.scale = v; }),
+            CS.inspector.numChip(null, p.scale, "%", function (v) { p.scale = CS.clamp(v, 1, 1000); }, 1)
+        ]);
+
+        CS.inspector.row(transform, "Rotation", [
+            CS.inspector.dial(p.rotation, function (v) { p.rotation = v; }),
+            CS.inspector.numChip(null, p.rotation, "°", function (v) { p.rotation = ((v % 360) + 360) % 360; }, 1)
+        ]);
+
+        CS.inspector.row(transform, "Opacity", [
+            CS.inspector.slider(0, 100, 1, p.opacity, function (v) { p.opacity = v; }),
+            CS.inspector.numChip(null, p.opacity, "%", function (v) { p.opacity = CS.clamp(v, 0, 100); }, 1)
+        ]);
+
+        //---- Crop ----
+        var crop = CS.inspector.section(body, "Crop", function () {
+            p.crop = "fit";
+            CS.commit("Reset Crop");
+        });
+        CS.inspector.row(crop, "Type", [
+            CS.inspector.select([
+                { v: "fit", l: "Fit" },
+                { v: "fill", l: "Fill" },
+                { v: "stretch", l: "Stretch" }
+            ], p.crop, function (v) {
+                p.crop = v;
+                CS.commit("Change Crop");
+            })
+        ]);
+
+        //---- Color ----
+        var color = CS.inspector.section(body, "Color", function () {
+            p.preset = "default"; p.exposure = 0; p.contrast = 0; p.saturation = 1;
+            CS.commit("Reset Color");
+        });
+        CS.inspector.row(color, "Preset", [
+            CS.inspector.select([
+                { v: "default", l: "Default" },
+                { v: "mono", l: "Monochrome" },
+                { v: "warm", l: "Warm" },
+                { v: "cool", l: "Cool" },
+                { v: "vivid", l: "Vivid" }
+            ], p.preset || "default", function (v) {
+                p.preset = v;
+                if (v === "mono") { p.saturation = 0; }
+                if (v === "vivid") { p.saturation = 1.35; p.contrast = 10; }
+                if (v === "default") { p.exposure = 0; p.contrast = 0; p.saturation = 1; }
+                CS.commit("Color Preset");
+            })
+        ]);
+        CS.inspector.row(color, "Exposure", [
+            CS.inspector.slider(-1, 1, 0.01, p.exposure, function (v) { p.exposure = v; }),
+            CS.inspector.numChip(null, p.exposure, "", function (v) { p.exposure = CS.clamp(v, -1, 1); }, 0.01, 2)
+        ]);
+        CS.inspector.row(color, "Contrast", [
+            CS.inspector.slider(-50, 50, 1, p.contrast, function (v) { p.contrast = v; }),
+            CS.inspector.numChip(null, p.contrast, "", function (v) { p.contrast = CS.clamp(v, -50, 50); }, 1)
+        ]);
+        CS.inspector.row(color, "Saturation", [
+            CS.inspector.slider(0, 2, 0.01, p.saturation, function (v) { p.saturation = v; }),
+            CS.inspector.numChip(null, p.saturation, "", function (v) { p.saturation = CS.clamp(v, 0, 2); }, 0.01, 2)
+        ]);
+
+        //---- Reset all ----
+        var reset = document.createElement("button");
+        reset.className = "insp-reset-all";
+        reset.textContent = "Reset All";
+        reset.addEventListener("click", function () {
+            clip.props = CS.defaultClipProps();
+            CS.commit("Reset All");
+        });
+        body.appendChild(reset);
+
+        CS.applyIcons(body);
+    },
+
+    /* ---------- audio tab ---------- */
+
+    renderAudioTab: function (body, clip, media, track) {
+        var p = clip.props;
+        var hasAudio = media && (media.type === "audio" || media.type === "video");
+        if (!hasAudio) {
+            CS.inspector.placeholder(body, "The selected clip has no audio.");
+            return;
+        }
+
+        var sec = CS.inspector.section(body, "Audio", function () {
+            p.volume = 100;
+            CS.commit("Reset Audio");
+        });
+        CS.inspector.row(sec, "Volume", [
+            CS.inspector.slider(0, 200, 1, (p.volume === undefined ? 100 : p.volume), function (v) { p.volume = v; }),
+            CS.inspector.numChip(null, (p.volume === undefined ? 100 : p.volume), "%", function (v) { p.volume = CS.clamp(v, 0, 200); }, 1)
+        ]);
+
+        var note = document.createElement("div");
+        note.className = "modal-note";
+        note.textContent = track && track.kind === "audio"
+            ? "Tip: the eye toggle on the track header mutes the whole track."
+            : "This controls the audio embedded in the video clip.";
+        sec.appendChild(note);
+
+        CS.applyIcons(body);
+    },
+
+    /* ---------- widget builders ---------- */
+
+    section: function (body, title, onReset) {
+        var sec = document.createElement("div");
+        sec.className = "insp-section" + (CS.inspector._collapsed[title] ? " collapsed" : "");
+
+        var head = document.createElement("div");
+        head.className = "insp-section-head";
+        head.innerHTML = '<span class="caret">' + CS.iconSVG("chevron-down") + '</span>' +
+            '<span class="sec-title"></span>' +
+            '<button class="sec-reset" title="Reset section">' + CS.iconSVG("rotate-ccw") + "</button>";
+        head.querySelector(".sec-title").textContent = title;
+        head.addEventListener("click", function (ev) {
+            if (ev.target.closest(".sec-reset")) { return; }
+            CS.inspector._collapsed[title] = !CS.inspector._collapsed[title];
+            sec.classList.toggle("collapsed", CS.inspector._collapsed[title]);
+        });
+        head.querySelector(".sec-reset").addEventListener("click", function () {
+            if (onReset) { onReset(); }
+        });
+
+        var rows = document.createElement("div");
+        rows.className = "insp-rows";
+
+        sec.appendChild(head);
+        sec.appendChild(rows);
+        body.appendChild(sec);
+        return rows;
+    },
+
+    row: function (rowsEl, labelText, controls) {
+        var row = document.createElement("div");
+        row.className = "insp-row";
+        var label = document.createElement("span");
+        label.className = "insp-label";
+        label.textContent = labelText;
+        var holder = document.createElement("div");
+        holder.className = "insp-control";
+        controls.forEach(function (c) { holder.appendChild(c); });
+        row.appendChild(label);
+        row.appendChild(holder);
+        rowsEl.appendChild(row);
+        return row;
+    },
+
+    liveUpdate: function () {
+        CS.player.syncElements();
+        CS.player.render();
+    },
+
+    slider: function (min, max, step, value, apply) {
+        var s = document.createElement("input");
+        s.type = "range";
+        s.className = "insp-slider";
+        s.min = min;
+        s.max = max;
+        s.step = step;
+        s.value = value;
+        CS.paintSlider(s);
+        s.addEventListener("input", function () {
+            apply(parseFloat(s.value));
+            CS.paintSlider(s);
+            CS.inspector.liveUpdate();
+        });
+        s.addEventListener("change", function () {
+            CS.commit("Adjust Property");
+        });
+        return s;
+    },
+
+    numChip: function (labelText, value, unit, apply, step, decimals) {
+        var chip = document.createElement("span");
+        chip.className = "num-chip";
+        var html = "";
+        if (labelText) { html += "<label></label>"; }
+        html += '<input type="text">';
+        if (unit) { html += '<span class="unit"></span>'; }
+        chip.innerHTML = html;
+        if (labelText) { chip.querySelector("label").textContent = labelText; }
+        if (unit) { chip.querySelector(".unit").textContent = unit; }
+        var inp = chip.querySelector("input");
+        var dec = (decimals === undefined) ? 0 : decimals;
+        inp.value = Number(value).toFixed(dec);
+        inp.addEventListener("change", function () {
+            var v = parseFloat(inp.value);
+            if (isNaN(v)) { return; }
+            apply(v);
+            CS.commit("Adjust Property");
+        });
+        //Drag vertically on the chip to scrub the value
+        inp.addEventListener("keydown", function (ev) {
+            var delta = (ev.key === "ArrowUp") ? (step || 1) : (ev.key === "ArrowDown") ? -(step || 1) : 0;
+            if (delta) {
+                ev.preventDefault();
+                var v = (parseFloat(inp.value) || 0) + delta;
+                inp.value = v.toFixed(dec);
+                apply(v);
+                CS.inspector.liveUpdate();
+            }
+        });
+        return chip;
+    },
+
+    dial: function (value, apply) {
+        var dial = document.createElement("div");
+        dial.className = "dial";
+        var tick = document.createElement("div");
+        tick.className = "tick";
+        dial.appendChild(tick);
+        function paint(v) { tick.style.transform = "rotate(" + v + "deg)"; }
+        paint(value);
+        dial.addEventListener("pointerdown", function (ev) {
+            ev.preventDefault();
+            dial.setPointerCapture(ev.pointerId);
+            var startY = ev.clientY;
+            var startV = value;
+            dial.onpointermove = function (mv) {
+                value = Math.round(startV + (startY - mv.clientY));
+                value = ((value % 360) + 360) % 360;
+                paint(value);
+                apply(value);
+                CS.inspector.liveUpdate();
+            };
+            dial.onpointerup = function () {
+                dial.onpointermove = null;
+                dial.onpointerup = null;
+                CS.commit("Rotate Clip");
+            };
+        });
+        dial.title = "Drag up / down to rotate";
+        return dial;
+    },
+
+    select: function (options, value, onChange) {
+        var btn = document.createElement("button");
+        btn.className = "insp-select";
+        var current = options.filter(function (o) { return o.v === value; })[0];
+        btn.innerHTML = "<span></span>" + '<span data-icon="chevron-down" class="mini"></span>';
+        btn.firstChild.textContent = current ? current.l : value;
+        btn.addEventListener("click", function () {
+            CS.showMenuUnder(btn, options.map(function (o) {
+                return {
+                    label: o.l,
+                    checked: o.v === value,
+                    action: function () { onChange(o.v); }
+                };
+            }));
+        });
+        return btn;
+    }
+};

+ 329 - 0
src/web/Cine Studio/js/main.js

@@ -0,0 +1,329 @@
+/*
+    Cine Studio - core state model
+
+    CS.project holds everything that is serialized into a .cine file:
+    media pool, tracks, clips and project settings. CS.state holds
+    transient editor state (playhead, selection, zoom, tool).
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.VIDEO_EXTS = ["mp4", "webm", "mov", "mkv", "m4v", "avi", "ogv"];
+CS.AUDIO_EXTS = ["mp3", "wav", "aac", "flac", "ogg", "m4a", "opus"];
+CS.IMAGE_EXTS = ["png", "jpg", "jpeg", "gif", "webp", "bmp"];
+CS.PROJECT_EXT = "cine";
+CS.APP_ROOT = "user:/Cine Studio";
+CS.IMAGE_DEFAULT_DURATION = 5;
+
+CS.inArozOS = function () {
+    return typeof ao_module_agirun !== "undefined" && window.location.protocol !== "file:" &&
+        !CS._forceStandalone;
+};
+
+/* ---------- project factory ---------- */
+
+CS.defaultClipProps = function () {
+    return {
+        x: 0, y: 0,
+        scale: 100,
+        rotation: 0,
+        opacity: 100,
+        crop: "fit",
+        preset: "default",
+        exposure: 0,
+        contrast: 0,
+        saturation: 1,
+        volume: 100
+    };
+};
+
+CS.newProject = function (opts) {
+    opts = opts || {};
+    CS.project = {
+        app: "CineStudio",
+        version: 1,
+        name: opts.name || "My Project",
+        filePath: "",
+        fileName: "",
+        settings: {
+            width: opts.width || 1920,
+            height: opts.height || 1080,
+            fps: opts.fps || 30
+        },
+        media: [],
+        tracks: [
+            { id: "V1", kind: "video", name: "Video 1", visible: true, muted: false },
+            { id: "A1", kind: "audio", name: "Audio 1", visible: true, muted: false },
+            { id: "A2", kind: "audio", name: "Audio 2", visible: true, muted: false }
+        ],
+        clips: []
+    };
+    CS.state = {
+        playhead: 0,
+        playing: false,
+        selectedClipId: null,
+        selectedMediaId: null,
+        zoom: 40,            // pixels per second
+        tool: "select",
+        previewZoom: "fit",
+        safeArea: false,
+        binKind: "all",
+        binSearch: "",
+        dirty: false
+    };
+    CS.history = { stack: [], index: -1 };
+    CS.pushHistory("New Project");
+    if (CS.player) { CS.player.reset(); }
+};
+
+/* ---------- lookups ---------- */
+
+CS.getMedia = function (id) {
+    for (var i = 0; i < CS.project.media.length; i++) {
+        if (CS.project.media[i].id === id) { return CS.project.media[i]; }
+    }
+    return null;
+};
+
+CS.getClip = function (id) {
+    for (var i = 0; i < CS.project.clips.length; i++) {
+        if (CS.project.clips[i].id === id) { return CS.project.clips[i]; }
+    }
+    return null;
+};
+
+CS.getTrack = function (id) {
+    for (var i = 0; i < CS.project.tracks.length; i++) {
+        if (CS.project.tracks[i].id === id) { return CS.project.tracks[i]; }
+    }
+    return null;
+};
+
+CS.selectedClip = function () {
+    return CS.state.selectedClipId ? CS.getClip(CS.state.selectedClipId) : null;
+};
+
+//Video tracks top-down (V2 above V1), then audio tracks in order (A1, A2, ...)
+CS.tracksInDisplayOrder = function () {
+    var video = CS.project.tracks.filter(function (t) { return t.kind === "video"; });
+    var audio = CS.project.tracks.filter(function (t) { return t.kind === "audio"; });
+    video.sort(function (a, b) { return b.id.localeCompare(a.id, undefined, { numeric: true }); });
+    audio.sort(function (a, b) { return a.id.localeCompare(b.id, undefined, { numeric: true }); });
+    return video.concat(audio);
+};
+
+//Video tracks bottom-up for compositing (V1 first, higher tracks painted over)
+CS.videoTracksInRenderOrder = function () {
+    var video = CS.project.tracks.filter(function (t) { return t.kind === "video"; });
+    video.sort(function (a, b) { return a.id.localeCompare(b.id, undefined, { numeric: true }); });
+    return video;
+};
+
+CS.clipsOnTrack = function (trackId) {
+    return CS.project.clips
+        .filter(function (c) { return c.trackId === trackId; })
+        .sort(function (a, b) { return a.start - b.start; });
+};
+
+CS.clipDuration = function (clip) {
+    return clip.out - clip.in;
+};
+
+CS.clipEnd = function (clip) {
+    return clip.start + CS.clipDuration(clip);
+};
+
+CS.timelineDuration = function () {
+    var end = 0;
+    CS.project.clips.forEach(function (c) {
+        var e = CS.clipEnd(c);
+        if (e > end) { end = e; }
+    });
+    return end;
+};
+
+//Sorted unique clip boundaries, used by prev/next edit point buttons
+CS.editPoints = function () {
+    var pts = [0];
+    CS.project.clips.forEach(function (c) {
+        pts.push(c.start);
+        pts.push(CS.clipEnd(c));
+    });
+    pts.sort(function (a, b) { return a - b; });
+    return pts.filter(function (p, i) { return i === 0 || p - pts[i - 1] > 0.0001; });
+};
+
+/* ---------- history (undo / redo) ---------- */
+
+CS.pushHistory = function (label) {
+    var snap = {
+        label: label,
+        clips: JSON.parse(JSON.stringify(CS.project.clips)),
+        tracks: JSON.parse(JSON.stringify(CS.project.tracks))
+    };
+    CS.history.stack = CS.history.stack.slice(0, CS.history.index + 1);
+    CS.history.stack.push(snap);
+    if (CS.history.stack.length > 100) { CS.history.stack.shift(); }
+    CS.history.index = CS.history.stack.length - 1;
+};
+
+//Call after any timeline mutation: records history and refreshes UI
+CS.commit = function (label) {
+    CS.pushHistory(label);
+    CS.markDirty();
+    CS.timeline.render();
+    CS.inspector.render();
+    CS.player.invalidate();
+};
+
+CS.applySnapshot = function (snap) {
+    CS.project.clips = JSON.parse(JSON.stringify(snap.clips));
+    CS.project.tracks = JSON.parse(JSON.stringify(snap.tracks));
+    if (CS.state.selectedClipId && !CS.getClip(CS.state.selectedClipId)) {
+        CS.state.selectedClipId = null;
+    }
+    CS.markDirty();
+    CS.timeline.render();
+    CS.inspector.render();
+    CS.player.invalidate();
+};
+
+CS.undo = function () {
+    if (CS.history.index <= 0) { CS.toast("Nothing to undo"); return; }
+    CS.history.index--;
+    CS.applySnapshot(CS.history.stack[CS.history.index]);
+};
+
+CS.redo = function () {
+    if (CS.history.index >= CS.history.stack.length - 1) { CS.toast("Nothing to redo"); return; }
+    CS.history.index++;
+    CS.applySnapshot(CS.history.stack[CS.history.index]);
+};
+
+/* ---------- dirty / title state ---------- */
+
+CS.markDirty = function () {
+    CS.state.dirty = true;
+    CS.updateSaveState();
+};
+
+CS.markClean = function () {
+    CS.state.dirty = false;
+    CS.updateSaveState();
+};
+
+CS.updateSaveState = function () {
+    var el = document.getElementById("save-state-icon");
+    if (el) { CS.setIcon(el, CS.state.dirty ? "dot-circle" : "check-circle"); }
+    var nameEl = document.getElementById("project-name");
+    if (nameEl) { nameEl.textContent = CS.project.name; }
+    var title = CS.project.name + (CS.state.dirty ? " (edited)" : "") + " - Cine Studio";
+    if (typeof ao_module_setWindowTitle !== "undefined") {
+        try { ao_module_setWindowTitle(title); } catch (e) { document.title = title; }
+    } else {
+        document.title = title;
+    }
+};
+
+/* ---------- clip operations ---------- */
+
+CS.selectClip = function (clipId) {
+    CS.state.selectedClipId = clipId;
+    CS.timeline.refreshSelection();
+    CS.inspector.render();
+};
+
+CS.deleteSelectedClip = function () {
+    var clip = CS.selectedClip();
+    if (!clip) { CS.toast("No clip selected"); return; }
+    CS.project.clips = CS.project.clips.filter(function (c) { return c.id !== clip.id; });
+    CS.state.selectedClipId = null;
+    CS.commit("Delete Clip");
+};
+
+//Split the clip under the playhead (prefers the selected clip)
+CS.splitAtPlayhead = function () {
+    var t = CS.state.playhead;
+    var candidates = CS.project.clips.filter(function (c) {
+        return t > c.start + 0.02 && t < CS.clipEnd(c) - 0.02;
+    });
+    if (candidates.length === 0) { CS.toast("Playhead is not over a splittable clip"); return; }
+    var clip = null;
+    for (var i = 0; i < candidates.length; i++) {
+        if (candidates[i].id === CS.state.selectedClipId) { clip = candidates[i]; }
+    }
+    if (!clip) { clip = candidates[0]; }
+    CS.splitClip(clip, t);
+    CS.commit("Split Clip");
+};
+
+CS.splitClip = function (clip, t) {
+    var offset = t - clip.start;
+    var right = JSON.parse(JSON.stringify(clip));
+    right.id = CS.uid();
+    right.start = t;
+    right.in = clip.in + offset;
+    clip.out = clip.in + offset;
+    CS.project.clips.push(right);
+    CS.state.selectedClipId = right.id;
+};
+
+//Place a media item on the timeline. Returns the new clip.
+CS.addClipToTimeline = function (media, trackId, startTime) {
+    var track = CS.getTrack(trackId);
+    if (!track) { return null; }
+    var duration = media.type === "image" ? CS.IMAGE_DEFAULT_DURATION : (media.duration || 1);
+    var clip = {
+        id: CS.uid(),
+        mediaId: media.id,
+        trackId: trackId,
+        start: Math.max(0, startTime),
+        in: 0,
+        out: duration,
+        props: CS.defaultClipProps()
+    };
+    clip.start = CS.timeline.resolveOverlap(clip, trackId, clip.start);
+    CS.project.clips.push(clip);
+    return clip;
+};
+
+CS.addTrack = function (kind) {
+    var prefix = kind === "video" ? "V" : "A";
+    var maxN = 0;
+    CS.project.tracks.forEach(function (t) {
+        if (t.kind === kind) {
+            var n = parseInt(t.id.substring(1), 10);
+            if (n > maxN) { maxN = n; }
+        }
+    });
+    var id = prefix + (maxN + 1);
+    CS.project.tracks.push({
+        id: id,
+        kind: kind,
+        name: (kind === "video" ? "Video " : "Audio ") + (maxN + 1),
+        visible: true,
+        muted: false
+    });
+    CS.commit("Add Track");
+};
+
+/* ---------- backend bootstrap ---------- */
+
+//Make sure the per-user app folders exist (no-op outside ArozOS)
+CS.ensureAppFolders = function () {
+    if (!CS.inArozOS()) { return; }
+    ao_module_agirun("Cine Studio/backend/ensuredir.js", {}, function () {}, function () {});
+};
+
+//Ask the server whether ffmpeg is available (enables MP4 export path)
+CS.serverFFmpeg = false;
+CS.checkServerFFmpeg = function () {
+    if (!CS.inArozOS()) { return; }
+    ao_module_agirun("Cine Studio/backend/ffmpegtools.js", { action: "check" }, function (resp) {
+        try {
+            var data = typeof resp === "string" ? JSON.parse(resp) : resp;
+            CS.serverFFmpeg = !!data.ffmpeg;
+        } catch (e) { CS.serverFFmpeg = false; }
+    }, function () { CS.serverFFmpeg = false; });
+};

+ 541 - 0
src/web/Cine Studio/js/media.js

@@ -0,0 +1,541 @@
+/*
+    Cine Studio - media pool
+
+    Imports media from the ArozOS file system (virtual paths streamed
+    through the /media endpoint) or from the local device (uploaded to
+    user:/Cine Studio/Media so projects stay portable). Probes duration,
+    dimensions, filmstrip thumbnails and audio waveform peaks.
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.media = {
+
+    /* ---------- source resolution ---------- */
+
+    mediaURL: function (media) {
+        if (media.vpath) { return "../media?file=" + encodeURIComponent(media.vpath); }
+        return media.blobUrl || "";
+    },
+
+    typeFromExt: function (ext) {
+        if (CS.VIDEO_EXTS.indexOf(ext) >= 0) { return "video"; }
+        if (CS.AUDIO_EXTS.indexOf(ext) >= 0) { return "audio"; }
+        if (CS.IMAGE_EXTS.indexOf(ext) >= 0) { return "image"; }
+        return null;
+    },
+
+    acceptedExts: function () {
+        return CS.VIDEO_EXTS.concat(CS.AUDIO_EXTS).concat(CS.IMAGE_EXTS);
+    },
+
+    /* ---------- import entry points ---------- */
+
+    importDialog: function (anchorEl) {
+        if (!CS.inArozOS()) { CS.media.importLocal(); return; }
+        var items = [
+            { label: "From ArozOS...", icon: "server", action: CS.media.importFromArozOS },
+            { label: "From this device...", icon: "upload", action: CS.media.importLocal }
+        ];
+        if (anchorEl) { CS.showMenuUnder(anchorEl, items); }
+        else { CS.media.importFromArozOS(); }
+    },
+
+    importFromArozOS: function () {
+        window.csImportCallback = function csImportCallback(filedata) {
+            if (!filedata || !filedata.length) { return; }
+            filedata.forEach(function (f) {
+                CS.media.addFromVpath(f.filepath, f.filename);
+            });
+        };
+        ao_module_openFileSelector(window.csImportCallback, "user:/Desktop", "file", true, {
+            filter: CS.media.acceptedExts()
+        });
+    },
+
+    importLocal: function () {
+        var inp = document.getElementById("local-file-input");
+        inp.value = "";
+        inp.onchange = function () {
+            var files = Array.prototype.slice.call(inp.files);
+            if (!files.length) { return; }
+            if (CS.inArozOS()) {
+                CS.media.uploadLocalFiles(files);
+            } else {
+                //Standalone fallback: keep the files in memory as blob URLs
+                files.forEach(function (file) {
+                    var ext = CS.extOf(file.name);
+                    if (!CS.media.typeFromExt(ext)) { return; }
+                    CS.media.register({
+                        name: file.name,
+                        blobUrl: URL.createObjectURL(file),
+                        type: CS.media.typeFromExt(ext)
+                    });
+                });
+            }
+        };
+        inp.click();
+    },
+
+    //Upload device files into the app media folder, then register the vpaths
+    uploadLocalFiles: function (files) {
+        var targetDir = CS.APP_ROOT + "/Media";
+        var remaining = files.length;
+        CS.toast("Uploading " + files.length + " file" + (files.length > 1 ? "s" : "") + "...");
+        files.forEach(function (file) {
+            var ext = CS.extOf(file.name);
+            if (!CS.media.typeFromExt(ext)) {
+                remaining--;
+                CS.toast("Skipped unsupported file: " + file.name, true);
+                return;
+            }
+            ao_module_uploadFile(file, targetDir, function () {
+                remaining--;
+                CS.media.addFromVpath(targetDir + "/" + file.name, file.name);
+                if (remaining === 0) { CS.toast("Upload complete"); }
+            }, undefined, function () {
+                remaining--;
+                CS.toast("Upload failed: " + file.name, true);
+            });
+        });
+    },
+
+    addFromVpath: function (vpath, filename) {
+        //Ignore duplicates of the same virtual path
+        for (var i = 0; i < CS.project.media.length; i++) {
+            if (CS.project.media[i].vpath === vpath) {
+                CS.toast(filename + " is already in the project");
+                return CS.project.media[i];
+            }
+        }
+        var ext = CS.extOf(filename);
+        var type = CS.media.typeFromExt(ext);
+        if (ext === CS.PROJECT_EXT) {
+            CS.fileio.openFromPath(vpath, filename);
+            return null;
+        }
+        if (!type) {
+            CS.toast("Unsupported file type: ." + ext, true);
+            return null;
+        }
+        return CS.media.register({ name: filename, vpath: vpath, type: type });
+    },
+
+    //Create the media entry, kick off probing, refresh the bin
+    register: function (spec) {
+        var media = {
+            id: CS.uid(),
+            name: spec.name,
+            vpath: spec.vpath || "",
+            blobUrl: spec.blobUrl || "",
+            type: spec.type,
+            duration: spec.type === "image" ? CS.IMAGE_DEFAULT_DURATION : 0,
+            width: 0,
+            height: 0,
+            thumbs: [],
+            peaks: null,
+            offline: false,
+            probed: false
+        };
+        CS.project.media.push(media);
+        CS.markDirty();
+        CS.media.renderBin();
+        CS.media.probe(media);
+        return media;
+    },
+
+    /* ---------- probing ---------- */
+
+    probe: function (media) {
+        if (media.type === "video") { CS.media.probeVideo(media); }
+        else if (media.type === "audio") { CS.media.probeAudio(media); }
+        else { CS.media.probeImage(media); }
+    },
+
+    probeImage: function (media) {
+        var img = new Image();
+        img.onload = function () {
+            media.width = img.naturalWidth;
+            media.height = img.naturalHeight;
+            var c = document.createElement("canvas");
+            c.width = 160;
+            c.height = 100;
+            var ctx = c.getContext("2d");
+            CS.media.drawCover(ctx, img, img.naturalWidth, img.naturalHeight, 160, 100);
+            media.thumbs = [c.toDataURL("image/jpeg", 0.72)];
+            media.probed = true;
+            CS.media.renderBin();
+            CS.timeline.render();
+            CS.player.invalidate();
+        };
+        img.onerror = function () { CS.media.markOffline(media); };
+        img.src = CS.media.mediaURL(media);
+    },
+
+    probeVideo: function (media) {
+        var v = document.createElement("video");
+        v.preload = "auto";
+        v.muted = true;
+        var frameTargets = null;
+        var thumbs = [];
+        var canvas = document.createElement("canvas");
+        canvas.width = 160;
+        canvas.height = 100;
+        var ctx = canvas.getContext("2d");
+
+        function beginFrames() {
+            media.duration = v.duration && isFinite(v.duration) ? v.duration : 0;
+            media.width = v.videoWidth;
+            media.height = v.videoHeight;
+            //Grab up to 5 frames spread across the clip for the filmstrip
+            var n = Math.min(5, Math.max(1, Math.floor(media.duration)));
+            frameTargets = [];
+            for (var i = 0; i < n; i++) {
+                frameTargets.push(Math.max(0.01, media.duration * (i + 0.5) / n));
+            }
+            v.currentTime = frameTargets[0];
+        }
+
+        v.addEventListener("loadedmetadata", function () {
+            if (!isFinite(v.duration)) {
+                //Streamed / MediaRecorder-produced webm reports Infinity
+                //until a far seek forces the real duration to be resolved
+                var onDur = function () {
+                    if (isFinite(v.duration) && frameTargets === null) {
+                        v.removeEventListener("durationchange", onDur);
+                        beginFrames();
+                    }
+                };
+                v.addEventListener("durationchange", onDur);
+                v.currentTime = 1e10;
+                return;
+            }
+            beginFrames();
+        });
+        v.addEventListener("seeked", function () {
+            if (frameTargets === null) { return; }
+            try {
+                CS.media.drawCover(ctx, v, v.videoWidth, v.videoHeight, 160, 100);
+                thumbs.push(canvas.toDataURL("image/jpeg", 0.7));
+            } catch (e) { /* tainted or decode issue: keep going */ }
+            media.thumbs = thumbs.slice();
+            CS.media.renderBin();
+            CS.timeline.render();
+            if (thumbs.length < frameTargets.length) {
+                v.currentTime = frameTargets[thumbs.length];
+            } else {
+                media.probed = true;
+                v.removeAttribute("src");
+                v.load();
+                CS.player.invalidate();
+            }
+        });
+        v.addEventListener("error", function () { CS.media.markOffline(media); });
+        v.src = CS.media.mediaURL(media);
+    },
+
+    probeAudio: function (media) {
+        var a = document.createElement("audio");
+        a.preload = "metadata";
+        var done = false;
+        function finish() {
+            if (done) { return; }
+            done = true;
+            media.duration = a.duration && isFinite(a.duration) ? a.duration : 0;
+            media.probed = true;
+            CS.media.renderBin();
+            CS.timeline.render();
+            CS.media.computePeaks(media);
+        }
+        a.addEventListener("loadedmetadata", function () {
+            if (!isFinite(a.duration)) {
+                //Force duration discovery on streamed containers
+                var onDur = function () {
+                    if (isFinite(a.duration)) {
+                        a.removeEventListener("durationchange", onDur);
+                        finish();
+                    }
+                };
+                a.addEventListener("durationchange", onDur);
+                a.currentTime = 1e10;
+                return;
+            }
+            finish();
+        });
+        a.addEventListener("error", function () { CS.media.markOffline(media); });
+        a.src = CS.media.mediaURL(media);
+    },
+
+    //Decode the audio and reduce it to ~600 min/max pairs for waveform drawing
+    computePeaks: function (media) {
+        fetch(CS.media.mediaURL(media))
+            .then(function (r) {
+                if (!r.ok) { throw new Error("HTTP " + r.status); }
+                return r.arrayBuffer();
+            })
+            .then(function (buf) {
+                var AC = window.AudioContext || window.webkitAudioContext;
+                var ctx = new AC();
+                return ctx.decodeAudioData(buf).then(function (audio) {
+                    ctx.close();
+                    return audio;
+                });
+            })
+            .then(function (audio) {
+                //The decoder knows the exact duration - trust it over metadata
+                if (audio.duration && isFinite(audio.duration)) {
+                    media.duration = audio.duration;
+                }
+                var ch = audio.getChannelData(0);
+                var bins = 600;
+                var step = Math.max(1, Math.floor(ch.length / bins));
+                var peaks = new Array(bins);
+                for (var i = 0; i < bins; i++) {
+                    var start = i * step;
+                    var max = 0;
+                    //Sample sparsely inside each bin: enough for a visual waveform
+                    for (var j = start; j < start + step && j < ch.length; j += 16) {
+                        var v = Math.abs(ch[j]);
+                        if (v > max) { max = v; }
+                    }
+                    peaks[i] = max;
+                }
+                media.peaks = peaks;
+                CS.media.renderBin();
+                CS.timeline.render();
+            })
+            .catch(function () {
+                media.peaks = null; //waveform stays flat, playback still works
+            });
+    },
+
+    markOffline: function (media) {
+        media.offline = true;
+        media.probed = true;
+        CS.media.renderBin();
+        CS.timeline.render();
+        CS.toast("Media offline: " + media.name, true);
+    },
+
+    //object-fit: cover for canvas drawing
+    drawCover: function (ctx, src, sw, sh, dw, dh) {
+        if (!sw || !sh) { return; }
+        var scale = Math.max(dw / sw, dh / sh);
+        var w = sw * scale, h = sh * scale;
+        ctx.drawImage(src, (dw - w) / 2, (dh - h) / 2, w, h);
+    },
+
+    /* ---------- media bin rendering ---------- */
+
+    filteredMedia: function () {
+        var kind = CS.state.binKind;
+        var q = (CS.state.binSearch || "").toLowerCase();
+        return CS.project.media.filter(function (m) {
+            if (kind !== "all" && m.type !== kind) { return false; }
+            if (q && m.name.toLowerCase().indexOf(q) < 0) { return false; }
+            return true;
+        });
+    },
+
+    renderBin: function () {
+        var grid = document.getElementById("bin-grid");
+        grid.innerHTML = "";
+        var items = CS.media.filteredMedia();
+
+        if (items.length === 0) {
+            var hint = document.createElement("div");
+            hint.className = "bin-empty-hint";
+            hint.textContent = CS.project.media.length === 0
+                ? "No media yet. Click Import to add video, audio or images from ArozOS or this device."
+                : "No media matches the current filter.";
+            grid.appendChild(hint);
+        }
+
+        items.forEach(function (m) {
+            var item = document.createElement("div");
+            item.className = "bin-item" + (CS.state.selectedMediaId === m.id ? " selected" : "");
+            item.setAttribute("draggable", "true");
+
+            var thumb = document.createElement("div");
+            thumb.className = "bin-thumb";
+            if (m.type === "audio") {
+                thumb.classList.add("audio-thumb");
+                var wave = document.createElement("canvas");
+                wave.width = 156;
+                wave.height = 96;
+                CS.media.drawWave(wave.getContext("2d"), m.peaks, 156, 96, "#35c98b");
+                thumb.appendChild(wave);
+            } else if (m.thumbs.length) {
+                thumb.style.backgroundImage = "url('" + m.thumbs[0] + "')";
+            } else {
+                thumb.innerHTML = '<span data-icon="' + (m.type === "image" ? "image" : "film") + '"></span>';
+            }
+
+            if (m.type !== "image") {
+                var dur = document.createElement("span");
+                dur.className = "duration";
+                dur.textContent = CS.shortDuration(m.duration);
+                thumb.appendChild(dur);
+            }
+            if (m.offline) {
+                var badge = document.createElement("span");
+                badge.className = "offline-badge";
+                badge.innerHTML = CS.iconSVG("warning");
+                thumb.appendChild(badge);
+            }
+
+            var name = document.createElement("div");
+            name.className = "bin-name";
+            name.textContent = m.name;
+            name.title = m.vpath || m.name;
+
+            item.appendChild(thumb);
+            item.appendChild(name);
+
+            item.addEventListener("click", function () {
+                CS.state.selectedMediaId = m.id;
+                CS.media.renderBin();
+            });
+            item.addEventListener("dblclick", function () {
+                CS.media.sendToTimeline(m);
+            });
+            item.addEventListener("dragstart", function (ev) {
+                ev.dataTransfer.setData("cinestudio/media", m.id);
+                ev.dataTransfer.effectAllowed = "copy";
+            });
+            item.addEventListener("contextmenu", function (ev) {
+                ev.preventDefault();
+                CS.media.itemMenu(m, ev.clientX, ev.clientY);
+            });
+
+            grid.appendChild(item);
+        });
+
+        CS.applyIcons(grid);
+        var n = items.length;
+        document.getElementById("bin-count").textContent = n + " item" + (n === 1 ? "" : "s");
+    },
+
+    drawWave: function (ctx, peaks, w, h, color) {
+        ctx.clearRect(0, 0, w, h);
+        ctx.fillStyle = color;
+        var mid = h / 2;
+        if (!peaks || !peaks.length) {
+            ctx.globalAlpha = 0.4;
+            ctx.fillRect(0, mid - 1, w, 2);
+            ctx.globalAlpha = 1;
+            return;
+        }
+        var n = Math.floor(w / 2);
+        for (var i = 0; i < n; i++) {
+            var p = peaks[Math.floor(i * peaks.length / n)] || 0;
+            var bh = Math.max(1, p * (h * 0.86));
+            ctx.fillRect(i * 2, mid - bh / 2, 1.4, bh);
+        }
+    },
+
+    itemMenu: function (media, x, y) {
+        CS.showMenu([
+            { label: "Add to timeline", icon: "plus", action: function () { CS.media.sendToTimeline(media); } },
+            {
+                label: "Reveal in File Manager", icon: "folder", disabled: !media.vpath || !CS.inArozOS(),
+                action: function () { ao_module_openPath(CS.dirOf(media.vpath), media.name); }
+            },
+            { sep: true },
+            {
+                label: "Remove from project", icon: "trash", action: function () {
+                    CS.media.removeMedia(media);
+                }
+            }
+        ], x, y);
+    },
+
+    removeMedia: function (media) {
+        var used = CS.project.clips.some(function (c) { return c.mediaId === media.id; });
+        function doRemove() {
+            CS.project.clips = CS.project.clips.filter(function (c) { return c.mediaId !== media.id; });
+            CS.project.media = CS.project.media.filter(function (m) { return m.id !== media.id; });
+            if (CS.state.selectedMediaId === media.id) { CS.state.selectedMediaId = null; }
+            CS.media.renderBin();
+            CS.commit("Remove Media");
+        }
+        if (used) {
+            CS.confirm("Remove media", media.name + " is used on the timeline. Remove it and all of its clips?", doRemove);
+        } else {
+            doRemove();
+        }
+    },
+
+    //Double click: append at the playhead on the first compatible track
+    sendToTimeline: function (media) {
+        if (media.offline) { CS.toast("Cannot use offline media", true); return; }
+        var kind = media.type === "audio" ? "audio" : "video";
+        var track = null;
+        var tracks = CS.project.tracks.filter(function (t) { return t.kind === kind; });
+        if (tracks.length) { track = tracks[0]; }
+        if (!track) { CS.toast("No compatible track", true); return; }
+        var clip = CS.addClipToTimeline(media, track.id, CS.state.playhead);
+        if (clip) {
+            CS.state.selectedClipId = clip.id;
+            CS.commit("Add Clip");
+        }
+    },
+
+    /* ---------- bin chrome wiring ---------- */
+
+    init: function () {
+        document.getElementById("btn-import").addEventListener("click", function () {
+            CS.media.importDialog(null);
+        });
+        document.getElementById("btn-import-menu").addEventListener("click", function (ev) {
+            CS.media.importDialog(ev.currentTarget.parentNode);
+        });
+
+        var kindBtn = document.getElementById("bin-kind-btn");
+        kindBtn.addEventListener("click", function () {
+            var kinds = [
+                { v: "all", l: "All Clips" },
+                { v: "video", l: "Videos" },
+                { v: "audio", l: "Audio" },
+                { v: "image", l: "Images" }
+            ];
+            CS.showMenuUnder(kindBtn, kinds.map(function (k) {
+                return {
+                    label: k.l,
+                    checked: CS.state.binKind === k.v,
+                    action: function () {
+                        CS.state.binKind = k.v;
+                        document.getElementById("bin-kind-label").textContent = k.l;
+                        CS.media.renderBin();
+                    }
+                };
+            }));
+        });
+
+        document.getElementById("bin-search-input").addEventListener("input", function () {
+            CS.state.binSearch = this.value;
+            CS.media.renderBin();
+        });
+
+        document.getElementById("btn-bin-filter").addEventListener("click", function (ev) {
+            kindBtn.click();
+        });
+        document.getElementById("btn-bin-view").addEventListener("click", function () {
+            CS.toast("Grid view is the only view in this version");
+        });
+
+        //Accept drops from the ArozOS File Manager
+        var bin = document.getElementById("mediabin");
+        bin.addEventListener("dragover", function (ev) { ev.preventDefault(); });
+        bin.addEventListener("drop", function (ev) {
+            ev.preventDefault();
+            if (typeof ao_module_utils === "undefined") { return; }
+            var files = null;
+            try { files = ao_module_utils.getDropFileInfo(ev); } catch (e) { files = null; }
+            if (files) {
+                files.forEach(function (f) { CS.media.addFromVpath(f.filepath, f.filename); });
+            }
+        });
+    }
+};

+ 406 - 0
src/web/Cine Studio/js/player.js

@@ -0,0 +1,406 @@
+/*
+    Cine Studio - preview player and compositor
+
+    Draws the frame under the playhead onto the preview canvas by
+    compositing every visible video-track clip (transform, crop, color
+    filters, opacity) and keeps a pool of hidden <video>/<audio>
+    elements time-synced for playback. The same pipeline is reused by
+    the exporter (canvas captureStream + WebAudio mix bus).
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.player = {
+    canvas: null,
+    ctx: null,
+    pool: {},        // clipId -> media element
+    images: {},      // mediaId -> HTMLImageElement
+    audioCtx: null,
+    masterGain: null,
+    exportDest: null,
+    lastTick: 0,
+    rafId: 0,
+
+    init: function () {
+        CS.player.canvas = document.getElementById("preview-canvas");
+        CS.player.ctx = CS.player.canvas.getContext("2d");
+        CS.player.applyProjectSize();
+
+        document.getElementById("btn-play").addEventListener("click", CS.player.toggle);
+        document.getElementById("btn-prev-edit").addEventListener("click", function () {
+            CS.player.gotoEditPoint(-1);
+        });
+        document.getElementById("btn-next-edit").addEventListener("click", function () {
+            CS.player.gotoEditPoint(1);
+        });
+        document.getElementById("btn-fullscreen").addEventListener("click", function () {
+            var stage = document.getElementById("preview-stage");
+            if (document.fullscreenElement) { document.exitFullscreen(); }
+            else if (stage.requestFullscreen) { stage.requestFullscreen(); }
+        });
+        document.getElementById("btn-safe-area").addEventListener("click", function () {
+            CS.state.safeArea = !CS.state.safeArea;
+            this.classList.toggle("active", CS.state.safeArea);
+            CS.player.render();
+        });
+
+        var zoomBtn = document.getElementById("btn-preview-zoom");
+        zoomBtn.addEventListener("click", function () {
+            var levels = [
+                { v: "fit", l: "Fit" },
+                { v: "0.5", l: "50%" },
+                { v: "1", l: "100%" },
+                { v: "2", l: "200%" }
+            ];
+            CS.showMenuUnder(zoomBtn, levels.map(function (z) {
+                return {
+                    label: z.l,
+                    checked: String(CS.state.previewZoom) === z.v,
+                    action: function () {
+                        CS.state.previewZoom = z.v;
+                        document.getElementById("preview-zoom-label").textContent = z.l;
+                        CS.player.applyPreviewZoom();
+                    }
+                };
+            }));
+        });
+    },
+
+    applyProjectSize: function () {
+        CS.player.canvas.width = CS.project.settings.width;
+        CS.player.canvas.height = CS.project.settings.height;
+        CS.player.applyPreviewZoom();
+        CS.player.render();
+    },
+
+    applyPreviewZoom: function () {
+        var c = CS.player.canvas;
+        var stage = document.getElementById("preview-stage");
+        if (CS.state.previewZoom === "fit") {
+            c.style.width = "";
+            c.style.height = "";
+            c.style.maxWidth = "100%";
+            c.style.maxHeight = "100%";
+            stage.style.overflow = "hidden";
+        } else {
+            var z = parseFloat(CS.state.previewZoom);
+            c.style.maxWidth = "none";
+            c.style.maxHeight = "none";
+            c.style.width = Math.round(CS.project.settings.width * z) + "px";
+            c.style.height = Math.round(CS.project.settings.height * z) + "px";
+            stage.style.overflow = "auto";
+        }
+    },
+
+    reset: function () {
+        CS.player.pause();
+        var pool = document.getElementById("element-pool");
+        if (pool) { pool.innerHTML = ""; }
+        CS.player.pool = {};
+        CS.player.images = {};
+        if (CS.player.canvas) { CS.player.applyProjectSize(); }
+    },
+
+    /* ---------- element pool ---------- */
+
+    ensureElement: function (clip, media) {
+        var el = CS.player.pool[clip.id];
+        if (el) { return el; }
+        el = document.createElement(media.type === "audio" ? "audio" : "video");
+        el.preload = "auto";
+        el.setAttribute("playsinline", "");
+        el.src = CS.media.mediaURL(media);
+        el.addEventListener("seeked", function () {
+            if (!CS.state.playing) { CS.player.render(); }
+        });
+        document.getElementById("element-pool").appendChild(el);
+        CS.player.pool[clip.id] = el;
+        CS.player.attachToMixBus(el);
+        return el;
+    },
+
+    ensureImage: function (media) {
+        var img = CS.player.images[media.id];
+        if (img) { return img; }
+        img = new Image();
+        img.src = CS.media.mediaURL(media);
+        img.onload = function () { if (!CS.state.playing) { CS.player.render(); } };
+        CS.player.images[media.id] = img;
+        return img;
+    },
+
+    //Drop pool entries whose clip no longer exists
+    prunePool: function () {
+        Object.keys(CS.player.pool).forEach(function (clipId) {
+            if (!CS.getClip(clipId)) {
+                var el = CS.player.pool[clipId];
+                el.pause();
+                el.remove();
+                delete CS.player.pool[clipId];
+            }
+        });
+    },
+
+    /* ---------- audio mix bus (playback monitoring + export capture) ---------- */
+
+    initAudioBus: function () {
+        if (CS.player.audioCtx) {
+            if (CS.player.audioCtx.state === "suspended") { CS.player.audioCtx.resume(); }
+            return;
+        }
+        try {
+            var AC = window.AudioContext || window.webkitAudioContext;
+            CS.player.audioCtx = new AC();
+            CS.player.masterGain = CS.player.audioCtx.createGain();
+            CS.player.masterGain.connect(CS.player.audioCtx.destination);
+            //Route the already-created elements through the bus
+            Object.keys(CS.player.pool).forEach(function (clipId) {
+                CS.player.attachToMixBus(CS.player.pool[clipId]);
+            });
+        } catch (e) {
+            CS.player.audioCtx = null;
+        }
+    },
+
+    attachToMixBus: function (el) {
+        if (!CS.player.audioCtx || el._csRouted) { return; }
+        try {
+            var src = CS.player.audioCtx.createMediaElementSource(el);
+            src.connect(CS.player.masterGain);
+            el._csRouted = true;
+        } catch (e) { /* element stays on direct output */ }
+    },
+
+    /* ---------- transport ---------- */
+
+    toggle: function () {
+        if (CS.state.playing) { CS.player.pause(); } else { CS.player.play(); }
+    },
+
+    play: function () {
+        var dur = CS.timelineDuration();
+        if (dur <= 0) { CS.toast("Timeline is empty"); return; }
+        if (CS.state.playhead >= dur - 0.01) { CS.state.playhead = 0; }
+        CS.player.initAudioBus();
+        CS.state.playing = true;
+        CS.player.lastTick = performance.now();
+        CS.setIcon(document.getElementById("play-icon"), "pause");
+        //Start the media elements inside the user gesture so autoplay
+        //policies treat the playback as user initiated
+        CS.player.syncElements();
+        cancelAnimationFrame(CS.player.rafId);
+        CS.player.rafId = requestAnimationFrame(CS.player.tick);
+    },
+
+    pause: function () {
+        CS.state.playing = false;
+        cancelAnimationFrame(CS.player.rafId);
+        Object.keys(CS.player.pool).forEach(function (id) {
+            if (!CS.player.pool[id].paused) { CS.player.pool[id].pause(); }
+        });
+        var icon = document.getElementById("play-icon");
+        if (icon) { CS.setIcon(icon, "play"); }
+        if (CS.exporter && CS.exporter.onPlaybackStopped) { CS.exporter.onPlaybackStopped(); }
+    },
+
+    seek: function (t) {
+        var dur = Math.max(CS.timelineDuration(), 0);
+        CS.state.playhead = CS.clamp(t, 0, Math.max(dur, 0));
+        CS.player.syncElements();
+        CS.player.render();
+        CS.player.updateTransportUI();
+        CS.timeline.updatePlayhead();
+    },
+
+    gotoEditPoint: function (dir) {
+        var pts = CS.editPoints();
+        var t = CS.state.playhead;
+        if (dir < 0) {
+            for (var i = pts.length - 1; i >= 0; i--) {
+                if (pts[i] < t - 0.02) { CS.player.seek(pts[i]); return; }
+            }
+            CS.player.seek(0);
+        } else {
+            for (var j = 0; j < pts.length; j++) {
+                if (pts[j] > t + 0.02) { CS.player.seek(pts[j]); return; }
+            }
+        }
+    },
+
+    tick: function (now) {
+        if (!CS.state.playing) { return; }
+        var dt = (now - CS.player.lastTick) / 1000;
+        CS.player.lastTick = now;
+        CS.state.playhead += dt;
+
+        var dur = CS.timelineDuration();
+        if (CS.state.playhead >= dur) {
+            CS.state.playhead = dur;
+            CS.player.syncElements();
+            CS.player.render();
+            CS.player.updateTransportUI();
+            CS.timeline.updatePlayhead();
+            CS.player.pause();
+            return;
+        }
+
+        CS.player.syncElements();
+        CS.player.render();
+        CS.player.updateTransportUI();
+        CS.timeline.updatePlayhead();
+        CS.player.rafId = requestAnimationFrame(CS.player.tick);
+    },
+
+    updateTransportUI: function () {
+        document.getElementById("tc-current").textContent = CS.timecode(CS.state.playhead);
+        document.getElementById("tc-total").textContent = CS.timecode(CS.timelineDuration());
+    },
+
+    /* ---------- element time sync ---------- */
+
+    activeAt: function (clip, t) {
+        return t >= clip.start && t < CS.clipEnd(clip);
+    },
+
+    syncElements: function () {
+        var t = CS.state.playhead;
+        CS.project.clips.forEach(function (clip) {
+            var media = CS.getMedia(clip.mediaId);
+            if (!media || media.type === "image" || media.offline) { return; }
+            var track = CS.getTrack(clip.trackId);
+            var el = CS.player.ensureElement(clip, media);
+            var active = CS.player.activeAt(clip, t) && track && track.visible;
+            var target = clip.in + (t - clip.start);
+
+            el.volume = CS.clamp((clip.props.volume === undefined ? 100 : clip.props.volume) / 100, 0, 1);
+            el.muted = !!(track && track.muted);
+
+            if (CS.state.playing && active) {
+                if (el.paused) {
+                    try { el.currentTime = target; } catch (e) {}
+                    var p = el.play();
+                    if (p && p.catch) { p.catch(function () {}); }
+                } else if (Math.abs(el.currentTime - target) > 0.14) {
+                    try { el.currentTime = target; } catch (e) {}
+                }
+            } else if (CS.state.playing && !active) {
+                if (!el.paused) { el.pause(); }
+            } else {
+                //Paused scrub: park the element on the exact frame
+                if (!el.paused) { el.pause(); }
+                if (active && Math.abs(el.currentTime - target) > 0.03) {
+                    try { el.currentTime = target; } catch (e) {}
+                }
+            }
+        });
+    },
+
+    /* ---------- rendering ---------- */
+
+    invalidate: function () {
+        CS.player.prunePool();
+        CS.player.syncElements();
+        CS.player.render();
+        CS.player.updateTransportUI();
+        var empty = document.getElementById("preview-empty");
+        empty.style.display = CS.project.clips.length ? "none" : "flex";
+    },
+
+    buildFilter: function (props) {
+        var parts = [];
+        var exposure = props.exposure || 0;
+        var contrast = props.contrast || 0;
+        var saturation = (props.saturation === undefined) ? 1 : props.saturation;
+        if (exposure !== 0) { parts.push("brightness(" + (1 + exposure) + ")"); }
+        if (contrast !== 0) { parts.push("contrast(" + (1 + contrast / 100) + ")"); }
+        if (saturation !== 1) { parts.push("saturate(" + saturation + ")"); }
+        if (props.preset === "warm") { parts.push("sepia(0.28)"); }
+        if (props.preset === "cool") { parts.push("hue-rotate(-18deg)"); }
+        return parts.length ? parts.join(" ") : "none";
+    },
+
+    render: function () {
+        var ctx = CS.player.ctx;
+        if (!ctx) { return; }
+        CS.player.renderFrame(ctx, CS.state.playhead);
+        if (CS.state.safeArea) { CS.player.drawSafeArea(ctx); }
+    },
+
+    //Composite the frame at time t onto the given 2d context
+    renderFrame: function (ctx, t) {
+        var W = CS.project.settings.width;
+        var H = CS.project.settings.height;
+        ctx.filter = "none";
+        ctx.globalAlpha = 1;
+        ctx.fillStyle = "#000";
+        ctx.fillRect(0, 0, W, H);
+
+        CS.videoTracksInRenderOrder().forEach(function (track) {
+            if (!track.visible) { return; }
+            CS.clipsOnTrack(track.id).forEach(function (clip) {
+                if (!CS.player.activeAt(clip, t)) { return; }
+                CS.player.drawClip(ctx, clip, W, H);
+            });
+        });
+
+        ctx.filter = "none";
+        ctx.globalAlpha = 1;
+    },
+
+    drawClip: function (ctx, clip, W, H) {
+        var media = CS.getMedia(clip.mediaId);
+        if (!media || media.offline) { return; }
+
+        var src, sw, sh;
+        if (media.type === "video") {
+            src = CS.player.pool[clip.id];
+            if (!src || src.readyState < 2) { return; }
+            sw = src.videoWidth;
+            sh = src.videoHeight;
+        } else if (media.type === "image") {
+            src = CS.player.ensureImage(media);
+            if (!src.complete || !src.naturalWidth) { return; }
+            sw = src.naturalWidth;
+            sh = src.naturalHeight;
+        } else {
+            return; //audio has no visual
+        }
+        if (!sw || !sh) { return; }
+
+        var p = clip.props;
+        var dw, dh;
+        if (p.crop === "stretch") {
+            dw = W;
+            dh = H;
+        } else {
+            var s = (p.crop === "fill") ? Math.max(W / sw, H / sh) : Math.min(W / sw, H / sh);
+            dw = sw * s;
+            dh = sh * s;
+        }
+        var userScale = (p.scale === undefined ? 100 : p.scale) / 100;
+        dw *= userScale;
+        dh *= userScale;
+
+        ctx.save();
+        ctx.translate(W / 2 + (p.x || 0), H / 2 + (p.y || 0));
+        if (p.rotation) { ctx.rotate(p.rotation * Math.PI / 180); }
+        ctx.globalAlpha = CS.clamp((p.opacity === undefined ? 100 : p.opacity) / 100, 0, 1);
+        ctx.filter = CS.player.buildFilter(p);
+        try {
+            ctx.drawImage(src, -dw / 2, -dh / 2, dw, dh);
+        } catch (e) { /* frame not decodable yet */ }
+        ctx.restore();
+    },
+
+    drawSafeArea: function (ctx) {
+        var W = CS.project.settings.width;
+        var H = CS.project.settings.height;
+        ctx.save();
+        ctx.strokeStyle = "rgba(255,255,255,0.35)";
+        ctx.lineWidth = Math.max(1, W / 960);
+        ctx.strokeRect(W * 0.05, H * 0.05, W * 0.9, H * 0.9);
+        ctx.strokeRect(W * 0.1, H * 0.1, W * 0.8, H * 0.8);
+        ctx.restore();
+    }
+};

+ 675 - 0
src/web/Cine Studio/js/timeline.js

@@ -0,0 +1,675 @@
+/*
+    Cine Studio - timeline
+
+    Renders the ruler, track headers, track lanes and clips; handles
+    scrubbing, drag-move, trim handles, blade splitting, drops from the
+    media bin, snapping and zoom.
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+CS.timeline = {
+    TRACK_H_VIDEO: 62,
+    TRACK_H_AUDIO: 52,
+    MIN_CLIP_DUR: 0.1,
+    TAIL_SECONDS: 30,   //empty space kept after the last clip
+
+    _drag: null,
+
+    init: function () {
+        var scroll = document.getElementById("tl-scroll");
+        scroll.addEventListener("scroll", function () {
+            CS.timeline.drawRuler();
+            CS.timeline.syncHeaderScroll();
+        });
+        window.addEventListener("resize", function () {
+            CS.timeline.drawRuler();
+        });
+
+        //Scrub by pressing / dragging on the ruler
+        var ruler = document.getElementById("tl-ruler");
+        ruler.addEventListener("pointerdown", function (ev) {
+            ruler.setPointerCapture(ev.pointerId);
+            CS.player.pause();
+            CS.timeline.scrubTo(ev);
+            ruler.onpointermove = function (mv) { CS.timeline.scrubTo(mv); };
+            ruler.onpointerup = function () { ruler.onpointermove = null; ruler.onpointerup = null; };
+        });
+
+        //Zoom controls
+        var zoom = document.getElementById("tl-zoom");
+        zoom.addEventListener("input", function () {
+            CS.timeline.setZoom(parseFloat(zoom.value));
+        });
+        document.getElementById("btn-zoom-in").addEventListener("click", function () {
+            CS.timeline.setZoom(CS.state.zoom * 1.35);
+        });
+        document.getElementById("btn-zoom-out").addEventListener("click", function () {
+            CS.timeline.setZoom(CS.state.zoom / 1.35);
+        });
+        CS.paintSlider(zoom);
+
+        //Toolbar
+        document.getElementById("tool-select").addEventListener("click", function () { CS.timeline.setTool("select"); });
+        document.getElementById("tool-blade").addEventListener("click", function () { CS.timeline.setTool("blade"); });
+        document.getElementById("tool-crop").addEventListener("click", function () {
+            CS.toast("Use the Crop section in the inspector");
+        });
+        document.getElementById("tool-text").addEventListener("click", function () {
+            CS.toast("Titles are not available in this version");
+        });
+        document.getElementById("tool-audio").addEventListener("click", function () {
+            CS.toast("Use the Audio tab in the inspector");
+        });
+        document.getElementById("btn-undo").addEventListener("click", CS.undo);
+        document.getElementById("btn-redo").addEventListener("click", CS.redo);
+        document.getElementById("btn-delete-clip").addEventListener("click", CS.deleteSelectedClip);
+        document.getElementById("btn-split-clip").addEventListener("click", CS.splitAtPlayhead);
+        document.getElementById("btn-add-track").addEventListener("click", function (ev) {
+            CS.showMenuUnder(ev.currentTarget, [
+                { label: "Add video track", icon: "film", action: function () { CS.addTrack("video"); } },
+                { label: "Add audio track", icon: "speaker", action: function () { CS.addTrack("audio"); } }
+            ]);
+        });
+    },
+
+    setTool: function (tool) {
+        CS.state.tool = tool;
+        document.getElementById("tool-select").classList.toggle("active", tool === "select");
+        document.getElementById("tool-blade").classList.toggle("active", tool === "blade");
+    },
+
+    setZoom: function (z) {
+        var scroll = document.getElementById("tl-scroll");
+        var anchorTime = (scroll.scrollLeft + scroll.clientWidth / 2) / CS.state.zoom;
+        CS.state.zoom = CS.clamp(z, 4, 200);
+        var slider = document.getElementById("tl-zoom");
+        slider.value = CS.state.zoom;
+        CS.paintSlider(slider);
+        CS.timeline.render();
+        scroll.scrollLeft = anchorTime * CS.state.zoom - scroll.clientWidth / 2;
+    },
+
+    scrubTo: function (ev) {
+        var scroll = document.getElementById("tl-scroll");
+        var rect = scroll.getBoundingClientRect();
+        var x = ev.clientX - rect.left + scroll.scrollLeft;
+        CS.player.seek(x / CS.state.zoom);
+    },
+
+    contentWidth: function () {
+        var scroll = document.getElementById("tl-scroll");
+        var need = (CS.timelineDuration() + CS.timeline.TAIL_SECONDS) * CS.state.zoom;
+        return Math.max(need, scroll ? scroll.clientWidth : 800);
+    },
+
+    trackHeight: function (track) {
+        return track.kind === "video" ? CS.timeline.TRACK_H_VIDEO : CS.timeline.TRACK_H_AUDIO;
+    },
+
+    /* ---------- full render ---------- */
+
+    render: function () {
+        CS.timeline.renderHeaders();
+        CS.timeline.renderTracks();
+        CS.timeline.drawRuler();
+        CS.timeline.updatePlayhead();
+        CS.player.updateTransportUI();
+    },
+
+    renderHeaders: function () {
+        var holder = document.getElementById("tl-track-headers");
+        holder.innerHTML = "";
+        CS.tracksInDisplayOrder().forEach(function (track) {
+            var h = document.createElement("div");
+            h.className = "track-header";
+            h.style.height = CS.timeline.trackHeight(track) + "px";
+
+            var icon = document.createElement("span");
+            icon.className = "th-icon";
+            icon.innerHTML = CS.iconSVG(track.kind === "video" ? "film" : "speaker");
+
+            var name = document.createElement("span");
+            name.className = "th-name";
+            name.textContent = track.name;
+
+            var toggle = document.createElement("button");
+            toggle.className = "th-toggle";
+            var on = track.kind === "video" ? track.visible : !track.muted;
+            toggle.classList.toggle("off", !on);
+            toggle.innerHTML = CS.iconSVG(on ? "eye" : "eye-off");
+            toggle.title = track.kind === "video" ? "Toggle track visibility" : "Toggle track audio";
+            toggle.addEventListener("click", function () {
+                if (track.kind === "video") { track.visible = !track.visible; }
+                else { track.muted = !track.muted; }
+                CS.commit("Toggle Track");
+            });
+
+            h.appendChild(icon);
+            h.appendChild(name);
+            h.appendChild(toggle);
+            h.addEventListener("contextmenu", function (ev) {
+                ev.preventDefault();
+                CS.timeline.trackMenu(track, ev.clientX, ev.clientY);
+            });
+            holder.appendChild(h);
+        });
+    },
+
+    trackMenu: function (track, x, y) {
+        var empty = CS.clipsOnTrack(track.id).length === 0;
+        var sameKind = CS.project.tracks.filter(function (t) { return t.kind === track.kind; }).length;
+        CS.showMenu([
+            {
+                label: "Delete track", icon: "trash", disabled: !empty || sameKind <= 1,
+                action: function () {
+                    CS.project.tracks = CS.project.tracks.filter(function (t) { return t.id !== track.id; });
+                    CS.commit("Delete Track");
+                }
+            }
+        ], x, y);
+    },
+
+    renderTracks: function () {
+        var holder = document.getElementById("tl-tracks");
+        holder.innerHTML = "";
+        var width = CS.timeline.contentWidth();
+        document.getElementById("tl-content").style.width = width + "px";
+
+        CS.tracksInDisplayOrder().forEach(function (track) {
+            var lane = document.createElement("div");
+            lane.className = "tl-track";
+            lane.style.height = CS.timeline.trackHeight(track) + "px";
+            lane.style.width = width + "px";
+            lane.dataset.trackId = track.id;
+
+            CS.timeline.bindLaneDrop(lane, track);
+            lane.addEventListener("pointerdown", function (ev) {
+                if (ev.target === lane) { CS.selectClip(null); }
+            });
+
+            CS.clipsOnTrack(track.id).forEach(function (clip) {
+                lane.appendChild(CS.timeline.buildClipEl(clip, track));
+            });
+
+            holder.appendChild(lane);
+        });
+    },
+
+    /* ---------- clip elements ---------- */
+
+    buildClipEl: function (clip, track) {
+        var media = CS.getMedia(clip.mediaId);
+        var el = document.createElement("div");
+        el.className = "tl-clip";
+        el.dataset.clipId = clip.id;
+        var x = clip.start * CS.state.zoom;
+        var w = Math.max(4, CS.clipDuration(clip) * CS.state.zoom);
+        el.style.left = x + "px";
+        el.style.width = w + "px";
+        if (clip.id === CS.state.selectedClipId) { el.classList.add("selected"); }
+
+        if (!media || media.offline) {
+            el.classList.add("offline");
+            var lbl = document.createElement("span");
+            lbl.className = "clip-label";
+            lbl.textContent = (media ? media.name : "Missing media") + " (offline)";
+            el.appendChild(lbl);
+        } else if (track.kind === "audio") {
+            el.classList.add("audio-clip");
+            var audioIdx = CS.project.tracks.filter(function (t) { return t.kind === "audio"; })
+                .findIndex(function (t) { return t.id === track.id; });
+            if (audioIdx % 2 === 1) { el.classList.add("alt"); }
+
+            var wave = document.createElement("canvas");
+            wave.className = "clip-wave";
+            CS.timeline.drawClipWave(wave, clip, media, w, CS.timeline.trackHeight(track) - 10);
+            el.appendChild(wave);
+
+            var label = document.createElement("span");
+            label.className = "clip-label";
+            label.textContent = media.name;
+            el.appendChild(label);
+        } else {
+            //video / image clip: filmstrip of repeated probe frames
+            var strip = document.createElement("div");
+            strip.className = "clip-strip";
+            CS.timeline.fillFilmstrip(strip, media, w, CS.timeline.trackHeight(track) - 10);
+            el.appendChild(strip);
+        }
+
+        //Trim handles
+        ["left", "right"].forEach(function (side) {
+            var handle = document.createElement("div");
+            handle.className = "trim-handle " + side;
+            handle.addEventListener("pointerdown", function (ev) {
+                ev.stopPropagation();
+                CS.timeline.beginDrag(ev, clip, el, side === "left" ? "trim-l" : "trim-r");
+            });
+            el.appendChild(handle);
+        });
+
+        el.addEventListener("pointerdown", function (ev) {
+            if (ev.button !== 0) { return; }
+            if (CS.state.tool === "blade") {
+                var rect = el.getBoundingClientRect();
+                var t = clip.start + (ev.clientX - rect.left) / CS.state.zoom;
+                if (t > clip.start + 0.05 && t < CS.clipEnd(clip) - 0.05) {
+                    CS.splitClip(clip, t);
+                    CS.commit("Split Clip");
+                }
+                return;
+            }
+            CS.selectClip(clip.id);
+            CS.timeline.beginDrag(ev, clip, el, "move");
+        });
+
+        el.addEventListener("contextmenu", function (ev) {
+            ev.preventDefault();
+            CS.selectClip(clip.id);
+            CS.showMenu([
+                { label: "Split at playhead", icon: "scissors", action: CS.splitAtPlayhead },
+                { label: "Reset properties", icon: "rotate-ccw", action: function () {
+                    clip.props = CS.defaultClipProps();
+                    CS.commit("Reset Clip");
+                } },
+                { sep: true },
+                { label: "Delete", icon: "trash", action: CS.deleteSelectedClip }
+            ], ev.clientX, ev.clientY);
+        });
+
+        return el;
+    },
+
+    fillFilmstrip: function (strip, media, clipW, clipH) {
+        strip.innerHTML = "";
+        if (!media.thumbs || !media.thumbs.length) {
+            strip.style.background = "#2a2a33";
+            return;
+        }
+        var frameW = Math.max(24, Math.round(clipH * 1.6));
+        var count = Math.min(200, Math.ceil(clipW / frameW));
+        var html = "";
+        for (var i = 0; i < count; i++) {
+            var t = media.thumbs[i % media.thumbs.length];
+            html += '<img src="' + t + '" style="width:' + frameW + 'px;height:100%;object-fit:cover;" draggable="false">';
+        }
+        strip.style.display = "flex";
+        strip.innerHTML = html;
+    },
+
+    drawClipWave: function (canvas, clip, media, w, h) {
+        canvas.width = Math.min(4000, Math.max(2, Math.round(w)));
+        canvas.height = Math.max(2, Math.round(h));
+        var ctx = canvas.getContext("2d");
+        var peaks = media.peaks;
+        ctx.clearRect(0, 0, canvas.width, canvas.height);
+        ctx.fillStyle = "rgba(255,255,255,0.55)";
+        var mid = canvas.height * 0.62;
+        if (!peaks || !peaks.length || !media.duration) {
+            ctx.fillRect(0, mid - 1, canvas.width, 2);
+            return;
+        }
+        var i0 = (clip.in / media.duration) * peaks.length;
+        var i1 = (clip.out / media.duration) * peaks.length;
+        var n = Math.floor(canvas.width / 2);
+        for (var i = 0; i < n; i++) {
+            var idx = Math.floor(i0 + (i1 - i0) * (i / n));
+            var p = peaks[CS.clamp(idx, 0, peaks.length - 1)] || 0;
+            var bh = Math.max(1, p * canvas.height * 0.7);
+            ctx.fillRect(i * 2, mid - bh / 2, 1.4, bh);
+        }
+    },
+
+    refreshSelection: function () {
+        var nodes = document.querySelectorAll(".tl-clip");
+        for (var i = 0; i < nodes.length; i++) {
+            nodes[i].classList.toggle("selected", nodes[i].dataset.clipId === CS.state.selectedClipId);
+        }
+    },
+
+    /* ---------- drag: move + trim ---------- */
+
+    beginDrag: function (ev, clip, el, mode) {
+        if (CS.state.tool === "blade") { return; }
+        CS.player.pause();
+        el.setPointerCapture(ev.pointerId);
+        CS.timeline._drag = {
+            mode: mode,
+            clip: clip,
+            el: el,
+            pointerId: ev.pointerId,
+            startX: ev.clientX,
+            startY: ev.clientY,
+            origStart: clip.start,
+            origIn: clip.in,
+            origOut: clip.out,
+            origTrackId: clip.trackId,
+            moved: false
+        };
+        el.onpointermove = CS.timeline.onDragMove;
+        el.onpointerup = CS.timeline.onDragEnd;
+    },
+
+    onDragMove: function (ev) {
+        var d = CS.timeline._drag;
+        if (!d) { return; }
+        var dx = ev.clientX - d.startX;
+        var dy = ev.clientY - d.startY;
+        if (!d.moved && Math.abs(dx) < 3 && Math.abs(dy) < 3) { return; }
+        d.moved = true;
+        var dt = dx / CS.state.zoom;
+        var clip = d.clip;
+        var media = CS.getMedia(clip.mediaId);
+        var isImage = media && media.type === "image";
+
+        if (d.mode === "move") {
+            var target = Math.max(0, d.origStart + dt);
+            target = CS.timeline.applySnap(target, clip, "start");
+            //If no snap on the left edge, try snapping the right edge
+            clip.start = target;
+
+            //Vertical: move across compatible tracks
+            var lane = CS.timeline.laneUnderPointer(ev.clientY);
+            if (lane) {
+                var track = CS.getTrack(lane.dataset.trackId);
+                var kindOk = track && ((track.kind === "audio") === (media && media.type === "audio"));
+                if (kindOk && track.id !== clip.trackId) {
+                    clip.trackId = track.id;
+                    lane.appendChild(d.el);
+                }
+            }
+            d.el.style.left = (clip.start * CS.state.zoom) + "px";
+        } else {
+            var minDur = CS.timeline.MIN_CLIP_DUR;
+            if (d.mode === "trim-l") {
+                var newStart = d.origStart + dt;
+                var maxStart = d.origStart + (d.origOut - d.origIn) - minDur;
+                newStart = CS.clamp(newStart, isImage ? 0 : d.origStart - d.origIn, maxStart);
+                newStart = Math.max(0, CS.timeline.applySnap(newStart, clip, "trim"));
+                var delta = newStart - d.origStart;
+                clip.start = newStart;
+                clip.in = isImage ? 0 : d.origIn + delta;
+                if (isImage) { clip.out = d.origOut - delta; }
+            } else {
+                var newOut = d.origOut + dt;
+                var maxOut = isImage ? 1e9 : (media && media.duration ? media.duration : d.origOut);
+                newOut = CS.clamp(newOut, d.origIn + minDur, maxOut);
+                var endTime = clip.start + (newOut - clip.in);
+                endTime = CS.timeline.applySnap(endTime, clip, "end");
+                newOut = CS.clamp(endTime - clip.start + clip.in, d.origIn + minDur, maxOut);
+                clip.out = newOut;
+            }
+            d.el.style.left = (clip.start * CS.state.zoom) + "px";
+            d.el.style.width = Math.max(4, CS.clipDuration(clip) * CS.state.zoom) + "px";
+            //Live-update strip/wave while trimming
+            var track = CS.getTrack(clip.trackId);
+            var wave = d.el.querySelector(".clip-wave");
+            if (wave && media) {
+                CS.timeline.drawClipWave(wave, clip, media, CS.clipDuration(clip) * CS.state.zoom, CS.timeline.trackHeight(track) - 10);
+            }
+            var strip = d.el.querySelector(".clip-strip");
+            if (strip && media) {
+                CS.timeline.fillFilmstrip(strip, media, CS.clipDuration(clip) * CS.state.zoom, CS.timeline.trackHeight(track) - 10);
+            }
+        }
+    },
+
+    onDragEnd: function (ev) {
+        var d = CS.timeline._drag;
+        if (!d) { return; }
+        d.el.onpointermove = null;
+        d.el.onpointerup = null;
+        CS.timeline._drag = null;
+        CS.timeline.hideSnapGuide();
+
+        if (!d.moved) {
+            CS.timeline.refreshSelection();
+            return;
+        }
+
+        var clip = d.clip;
+        if (d.mode === "move") {
+            clip.start = CS.timeline.resolveOverlap(clip, clip.trackId, clip.start);
+        } else {
+            //Trimming may have created an overlap with the next clip: clamp
+            CS.timeline.clampTrimOverlap(clip);
+        }
+        CS.commit(d.mode === "move" ? "Move Clip" : "Trim Clip");
+    },
+
+    laneUnderPointer: function (clientY) {
+        var lanes = document.querySelectorAll(".tl-track");
+        for (var i = 0; i < lanes.length; i++) {
+            var r = lanes[i].getBoundingClientRect();
+            if (clientY >= r.top && clientY <= r.bottom) { return lanes[i]; }
+        }
+        return null;
+    },
+
+    /* ---------- snapping ---------- */
+
+    snapTargets: function (excludeClip) {
+        var pts = [0, CS.state.playhead];
+        CS.project.clips.forEach(function (c) {
+            if (excludeClip && c.id === excludeClip.id) { return; }
+            pts.push(c.start);
+            pts.push(CS.clipEnd(c));
+        });
+        return pts;
+    },
+
+    //Snap the candidate time (for the given clip edge) to nearby targets
+    applySnap: function (time, clip, edge) {
+        var threshold = 8 / CS.state.zoom;
+        var targets = CS.timeline.snapTargets(clip);
+        var dur = CS.clipDuration(clip);
+        var best = null, bestDist = threshold, guideAt = 0;
+        targets.forEach(function (target) {
+            //Edge being dragged lands on the target
+            var d1 = Math.abs(time - target);
+            if (d1 < bestDist) { best = target; bestDist = d1; guideAt = target; }
+            //When moving the whole clip, the opposite edge can snap too
+            if (edge === "start") {
+                var d2 = Math.abs((time + dur) - target);
+                if (d2 < bestDist) { best = target - dur; bestDist = d2; guideAt = target; }
+            }
+        });
+        if (best !== null) {
+            CS.timeline.showSnapGuide(guideAt);
+            return best;
+        }
+        CS.timeline.hideSnapGuide();
+        return time;
+    },
+
+    showSnapGuide: function (time) {
+        var guide = document.getElementById("snap-guide");
+        if (!guide) {
+            guide = document.createElement("div");
+            guide.id = "snap-guide";
+            guide.className = "snap-guide";
+            document.getElementById("tl-content").appendChild(guide);
+        }
+        guide.style.left = (time * CS.state.zoom) + "px";
+        guide.style.display = "block";
+    },
+
+    hideSnapGuide: function () {
+        var guide = document.getElementById("snap-guide");
+        if (guide) { guide.style.display = "none"; }
+    },
+
+    /* ---------- overlap prevention ---------- */
+
+    //Find the closest legal start position for clip on the track
+    resolveOverlap: function (clip, trackId, desiredStart) {
+        var dur = CS.clipDuration(clip);
+        var others = CS.clipsOnTrack(trackId).filter(function (c) { return c.id !== clip.id; });
+        var start = Math.max(0, desiredStart);
+
+        function collides(s) {
+            for (var i = 0; i < others.length; i++) {
+                var o = others[i];
+                if (s < CS.clipEnd(o) - 0.0001 && s + dur > o.start + 0.0001) { return o; }
+            }
+            return null;
+        }
+
+        var hit = collides(start);
+        var guard = 0;
+        while (hit && guard < 50) {
+            //Choose the nearer side of the colliding clip
+            var before = hit.start - dur;
+            var after = CS.clipEnd(hit);
+            if (before >= 0 && Math.abs(start - before) <= Math.abs(start - after)) {
+                start = before;
+            } else {
+                start = after;
+            }
+            hit = collides(start);
+            guard++;
+        }
+        return Math.max(0, start);
+    },
+
+    clampTrimOverlap: function (clip) {
+        var others = CS.clipsOnTrack(clip.trackId).filter(function (c) { return c.id !== clip.id; });
+        others.forEach(function (o) {
+            //clip's tail overlaps o's head
+            if (clip.start < o.start && CS.clipEnd(clip) > o.start) {
+                clip.out = clip.in + (o.start - clip.start);
+            }
+            //clip's head overlaps o's tail
+            if (clip.start >= o.start && clip.start < CS.clipEnd(o)) {
+                var shift = CS.clipEnd(o) - clip.start;
+                clip.start += shift;
+                clip.in += shift;
+                if (clip.out - clip.in < CS.timeline.MIN_CLIP_DUR) { clip.out = clip.in + CS.timeline.MIN_CLIP_DUR; }
+            }
+        });
+    },
+
+    /* ---------- drops from the media bin ---------- */
+
+    bindLaneDrop: function (lane, track) {
+        lane.addEventListener("dragover", function (ev) {
+            if (!ev.dataTransfer) { return; }
+            ev.preventDefault();
+            lane.classList.add("drop-target");
+        });
+        lane.addEventListener("dragleave", function () {
+            lane.classList.remove("drop-target");
+        });
+        lane.addEventListener("drop", function (ev) {
+            ev.preventDefault();
+            lane.classList.remove("drop-target");
+            var mediaId = ev.dataTransfer.getData("cinestudio/media");
+            var scroll = document.getElementById("tl-scroll");
+            var rect = scroll.getBoundingClientRect();
+            var t = (ev.clientX - rect.left + scroll.scrollLeft) / CS.state.zoom;
+
+            if (mediaId) {
+                var media = CS.getMedia(mediaId);
+                if (!media) { return; }
+                if (media.offline) { CS.toast("Cannot use offline media", true); return; }
+                var isAudio = media.type === "audio";
+                if (isAudio !== (track.kind === "audio")) {
+                    CS.toast(isAudio ? "Audio clips go on audio tracks" : "Video clips go on video tracks", true);
+                    return;
+                }
+                var clip = CS.addClipToTimeline(media, track.id, t);
+                if (clip) {
+                    CS.state.selectedClipId = clip.id;
+                    CS.commit("Add Clip");
+                }
+                return;
+            }
+
+            //Drop straight from the ArozOS File Manager: import then place
+            if (typeof ao_module_utils !== "undefined") {
+                var files = null;
+                try { files = ao_module_utils.getDropFileInfo(ev); } catch (e) { files = null; }
+                if (files && files.length) {
+                    files.forEach(function (f) { CS.media.addFromVpath(f.filepath, f.filename); });
+                    CS.toast("Imported to media bin - drag to the timeline once probed");
+                }
+            }
+        });
+    },
+
+    /* ---------- ruler + playhead ---------- */
+
+    drawRuler: function () {
+        var canvas = document.getElementById("tl-ruler");
+        var scroll = document.getElementById("tl-scroll");
+        if (!canvas || !scroll) { return; }
+        var dpr = window.devicePixelRatio || 1;
+        var w = scroll.clientWidth;
+        var h = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--ruler-h"), 10) || 34;
+        if (canvas.width !== Math.round(w * dpr)) {
+            canvas.width = Math.round(w * dpr);
+            canvas.height = Math.round(h * dpr);
+            canvas.style.width = w + "px";
+            canvas.style.height = h + "px";
+        }
+        var ctx = canvas.getContext("2d");
+        ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
+        ctx.clearRect(0, 0, w, h);
+
+        var zoom = CS.state.zoom;
+        var scrollLeft = scroll.scrollLeft;
+
+        //Pick a label step that keeps labels at least ~90px apart
+        var steps = [0.5, 1, 2, 5, 10, 15, 30, 60, 120, 300, 600, 1800];
+        var step = steps[steps.length - 1];
+        for (var i = 0; i < steps.length; i++) {
+            if (steps[i] * zoom >= 90) { step = steps[i]; break; }
+        }
+        var minor = step / 5;
+
+        ctx.font = "10.5px ui-monospace, SFMono-Regular, Menlo, monospace";
+        ctx.textBaseline = "middle";
+
+        var tStart = Math.floor(scrollLeft / zoom / minor) * minor;
+        var tEnd = (scrollLeft + w) / zoom;
+        for (var t = tStart; t <= tEnd; t += minor) {
+            var x = t * zoom - scrollLeft;
+            var isMajor = Math.abs(t / step - Math.round(t / step)) < 0.001;
+            if (isMajor) {
+                ctx.fillStyle = "#8b8b95";
+                ctx.fillText(CS.timecode(t), x + 6, h / 2);
+                ctx.fillStyle = "#3a3a44";
+                ctx.fillRect(x, h - 10, 1, 10);
+            } else {
+                ctx.fillStyle = "#2a2a32";
+                ctx.fillRect(x, h - 6, 1, 6);
+            }
+        }
+        //bottom hairline
+        ctx.fillStyle = "#1c1c22";
+        ctx.fillRect(0, h - 1, w, 1);
+    },
+
+    updatePlayhead: function () {
+        var ph = document.getElementById("tl-playhead");
+        var x = CS.state.playhead * CS.state.zoom;
+        ph.style.left = x + "px";
+
+        //Keep the playhead visible while playing
+        if (CS.state.playing) {
+            var scroll = document.getElementById("tl-scroll");
+            if (x < scroll.scrollLeft || x > scroll.scrollLeft + scroll.clientWidth - 40) {
+                scroll.scrollLeft = Math.max(0, x - 80);
+            }
+        }
+    },
+
+    syncHeaderScroll: function () {
+        //Keep the header column aligned when many tracks force vertical scroll
+        var scroll = document.getElementById("tl-scroll");
+        var headers = document.getElementById("tl-track-headers");
+        if (scroll && headers) { headers.scrollTop = scroll.scrollTop; }
+    }
+};

+ 240 - 0
src/web/Cine Studio/js/ui.js

@@ -0,0 +1,240 @@
+/*
+    Cine Studio - UI primitives
+    Toasts, anchored dropdown menus, modal dialogs and small helpers.
+*/
+"use strict";
+
+window.CS = window.CS || {};
+
+/* ---------- toast ---------- */
+
+CS.toast = function (message, isError) {
+    var holder = document.getElementById("toast-holder");
+    var el = document.createElement("div");
+    el.className = "toast" + (isError ? " error" : "");
+    el.textContent = message;
+    holder.appendChild(el);
+    setTimeout(function () {
+        el.style.transition = "opacity 0.25s";
+        el.style.opacity = "0";
+        setTimeout(function () { el.remove(); }, 260);
+    }, isError ? 3600 : 2200);
+};
+
+/* ---------- dropdown / context menu ---------- */
+
+// items: [{label, icon, checked, disabled, action}] or {sep:true}
+CS.showMenu = function (items, x, y) {
+    CS.closeMenu();
+    var holder = document.getElementById("menu-holder");
+    var menu = document.createElement("div");
+    menu.className = "ctx-menu";
+
+    items.forEach(function (item) {
+        if (item.sep) {
+            var sep = document.createElement("div");
+            sep.className = "ctx-sep";
+            menu.appendChild(sep);
+            return;
+        }
+        var btn = document.createElement("button");
+        btn.className = "ctx-item" + (item.checked ? " checked" : "");
+        if (item.disabled) { btn.disabled = true; }
+        btn.innerHTML = (item.icon ? '<span data-icon="' + item.icon + '"></span>' : "") +
+            "<span></span>";
+        btn.lastChild.textContent = item.label;
+        btn.addEventListener("click", function (ev) {
+            ev.stopPropagation();
+            CS.closeMenu();
+            if (item.action) { item.action(); }
+        });
+        menu.appendChild(btn);
+    });
+
+    holder.appendChild(menu);
+    CS.applyIcons(menu);
+
+    //Keep inside the viewport
+    var rect = menu.getBoundingClientRect();
+    var px = Math.min(x, window.innerWidth - rect.width - 8);
+    var py = Math.min(y, window.innerHeight - rect.height - 8);
+    menu.style.left = Math.max(4, px) + "px";
+    menu.style.top = Math.max(4, py) + "px";
+
+    setTimeout(function () {
+        document.addEventListener("mousedown", CS._menuDismiss, true);
+    }, 0);
+};
+
+CS.showMenuUnder = function (anchorEl, items) {
+    var r = anchorEl.getBoundingClientRect();
+    CS.showMenu(items, r.left, r.bottom + 6);
+};
+
+CS._menuDismiss = function (ev) {
+    var holder = document.getElementById("menu-holder");
+    if (!holder.contains(ev.target)) { CS.closeMenu(); }
+};
+
+CS.closeMenu = function () {
+    document.getElementById("menu-holder").innerHTML = "";
+    document.removeEventListener("mousedown", CS._menuDismiss, true);
+};
+
+/* ---------- modal dialogs ---------- */
+
+// opts: { title, build(body), buttons:[{label, primary, keepOpen, action(modal)}], onClose }
+CS.modal = function (opts) {
+    CS.closeModal();
+    var holder = document.getElementById("modal-holder");
+    var modal = document.createElement("div");
+    modal.className = "modal";
+
+    var title = document.createElement("div");
+    title.className = "modal-title";
+    title.textContent = opts.title || "";
+    modal.appendChild(title);
+
+    var body = document.createElement("div");
+    body.className = "modal-body";
+    modal.appendChild(body);
+    if (opts.build) { opts.build(body); }
+
+    var btnRow = document.createElement("div");
+    btnRow.className = "modal-buttons";
+    (opts.buttons || [{ label: "Close" }]).forEach(function (b) {
+        var btn = document.createElement("button");
+        btn.className = "modal-btn" + (b.primary ? " primary" : "");
+        btn.textContent = b.label;
+        btn.addEventListener("click", function () {
+            //An action returning false keeps / manages the modal itself
+            var result = b.action ? b.action(modal) : undefined;
+            if (result === false) { return; }
+            if (!b.keepOpen) { CS.closeModal(); }
+        });
+        btnRow.appendChild(btn);
+    });
+    modal.appendChild(btnRow);
+
+    holder.appendChild(modal);
+    CS.applyIcons(modal);
+    CS._modalOnClose = opts.onClose || null;
+    return { modal: modal, body: body, buttons: btnRow };
+};
+
+CS.closeModal = function () {
+    var holder = document.getElementById("modal-holder");
+    if (holder.childNodes.length && CS._modalOnClose) {
+        var cb = CS._modalOnClose;
+        CS._modalOnClose = null;
+        cb();
+    }
+    holder.innerHTML = "";
+};
+
+//Simple labelled row inside a modal body; control is a DOM element
+CS.modalRow = function (body, labelText, control) {
+    var row = document.createElement("div");
+    row.className = "modal-row";
+    var label = document.createElement("span");
+    label.textContent = labelText;
+    row.appendChild(label);
+    row.appendChild(control);
+    body.appendChild(row);
+    return control;
+};
+
+CS.textInput = function (value) {
+    var inp = document.createElement("input");
+    inp.type = "text";
+    inp.value = value || "";
+    inp.setAttribute("autocomplete", "off");
+    return inp;
+};
+
+CS.selectInput = function (options, value) {
+    var sel = document.createElement("select");
+    options.forEach(function (o) {
+        var opt = document.createElement("option");
+        opt.value = o.v;
+        opt.textContent = o.l;
+        sel.appendChild(opt);
+    });
+    sel.value = value;
+    return sel;
+};
+
+CS.confirm = function (title, message, onYes) {
+    CS.modal({
+        title: title,
+        build: function (body) {
+            var p = document.createElement("div");
+            p.className = "modal-note";
+            p.style.fontSize = "12.5px";
+            p.style.color = "var(--text-dim)";
+            p.textContent = message;
+            body.appendChild(p);
+        },
+        buttons: [
+            { label: "Cancel" },
+            { label: "OK", primary: true, action: onYes }
+        ]
+    });
+};
+
+/* ---------- misc helpers ---------- */
+
+CS.clamp = function (v, min, max) { return v < min ? min : (v > max ? max : v); };
+
+CS.uid = function () {
+    return "c" + Date.now().toString(36) + Math.floor(Math.random() * 1e6).toString(36);
+};
+
+CS.extOf = function (name) {
+    var i = name.lastIndexOf(".");
+    return i < 0 ? "" : name.slice(i + 1).toLowerCase();
+};
+
+CS.baseName = function (name) {
+    var i = name.lastIndexOf(".");
+    return i < 0 ? name : name.slice(0, i);
+};
+
+CS.dirOf = function (vpath) {
+    var parts = vpath.split("/");
+    parts.pop();
+    return parts.join("/");
+};
+
+//Format seconds as HH:MM:SS:FF using the project frame rate
+CS.timecode = function (seconds, fps) {
+    fps = fps || (CS.project ? CS.project.settings.fps : 30);
+    if (!isFinite(seconds) || seconds < 0) { seconds = 0; }
+    var totalFrames = Math.round(seconds * fps);
+    var f = totalFrames % fps;
+    var totalSec = Math.floor(totalFrames / fps);
+    var s = totalSec % 60;
+    var m = Math.floor(totalSec / 60) % 60;
+    var h = Math.floor(totalSec / 3600);
+    function p(n) { return (n < 10 ? "0" : "") + n; }
+    return p(h) + ":" + p(m) + ":" + p(s) + ":" + p(f);
+};
+
+//Short mm:ss duration badge used in the media bin
+CS.shortDuration = function (seconds) {
+    if (!isFinite(seconds) || seconds <= 0) { return "00:00"; }
+    var s = Math.round(seconds);
+    var m = Math.floor(s / 60);
+    s = s % 60;
+    function p(n) { return (n < 10 ? "0" : "") + n; }
+    return p(m) + ":" + p(s);
+};
+
+//Update the --fill custom property so the slider track shows its filled part
+CS.paintSlider = function (slider) {
+    var min = parseFloat(slider.min) || 0;
+    var max = parseFloat(slider.max) || 100;
+    var v = parseFloat(slider.value);
+    var pct = ((v - min) / (max - min)) * 100;
+    slider.style.setProperty("--fill", pct + "%");
+};