:root{
  --ink-950:#101113;
  --ink-900:#17191d;
  --ink-850:#1c1f24;
  --ink-800:#22252b;
  --ink-700:#30343c;
  --mint-500:#26c6a1;
  --mint-600:#10a987;
  --mint-dim:#174138;
  --blue-500:#6ea8ff;
  --blue-dim:#1d2f4d;
  --text:#f4f5f7;
  --muted:#8b939f;
  --muted-dim:#616873;
  --line:#282c33;
  --danger:#ef4444;
  --warn:#facc15;
  --ui: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*{ box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html,body{ height:100%; margin:0; }
body{
  background:var(--ink-950); color:var(--text);
  font-family:var(--ui); font-size:14px; line-height:1.45;
  overscroll-behavior:none;
}
button,input,select,textarea{ font:inherit; color:inherit; }
button{ background:none; border:0; cursor:pointer; }
input,textarea,select{ font-size:16px; } /* stops iOS zoom-on-focus */
[hidden]{ display:none !important; }

#app{
  display:flex; flex-direction:column;
  height:100dvh; overflow:hidden;
  padding-bottom:env(safe-area-inset-bottom);
}

/* ─── top bar ─────────────────────────────────────────────────── */
.topbar{
  flex:0 0 auto;
  display:flex; align-items:center; gap:8px;
  padding:8px 12px; padding-top:calc(8px + env(safe-area-inset-top));
  background:var(--ink-900);
  border-bottom:1px solid var(--line);
}
.brand{ display:flex; align-items:center; gap:7px; font-weight:700; letter-spacing:-0.01em; flex:0 0 auto; }
.brand .mark{
  width:22px; height:22px; border-radius:6px;
  background:linear-gradient(145deg,var(--mint-500),var(--mint-600));
  display:grid; place-items:center; color:#06231c; font-size:11px;
}
.brand em{ font-style:normal; color:var(--muted); font-weight:500; }
.spacer{ flex:1; }
.projbtn{
  display:flex; align-items:center; gap:6px; min-width:0;
  padding:7px 9px; border-radius:9px;
  font-size:13px; font-weight:600; color:var(--text);
  border:1px solid transparent;
}
.projbtn:hover{ background:var(--ink-800); border-color:var(--line); }
.projbtn #projName{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:34vw; }
.projbtn svg{ width:12px; height:12px; color:var(--muted); flex:0 0 auto; }
.savedot{ width:7px; height:7px; border-radius:50%; background:var(--ink-700); flex:0 0 auto; }
.savedot[data-s="saved"]{ background:var(--mint-500); }
.savedot[data-s="saving"]{ background:var(--warn); }
.savedot[data-s="error"]{ background:var(--danger); }

.btn{
  border-radius:9px; padding:8px 13px;
  background:var(--ink-800); border:1px solid var(--line);
  font-weight:600; font-size:13px; text-decoration:none; color:var(--text);
  transition:background .12s, border-color .12s, opacity .12s;
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
}
.btn:hover{ border-color:var(--ink-700); }
.btn:active{ background:var(--ink-700); }
.btn.primary{ background:var(--mint-600); border-color:var(--mint-500); color:#04201a; }
.btn.primary:active{ background:var(--mint-500); }
.btn.danger{ color:var(--danger); }
.btn.small{ padding:6px 10px; font-size:12px; }
.btn[data-on="true"]{ background:var(--mint-dim); color:var(--mint-500); border-color:var(--mint-600); }
.btn:disabled{ opacity:.35; cursor:default; }

select.chip{
  -webkit-appearance:none; appearance:none;
  background:var(--ink-800); border:1px solid var(--line);
  border-radius:9px; padding:8px 26px 8px 11px;
  font-size:13px; font-weight:600;
  background-image:linear-gradient(45deg,transparent 50%,var(--muted) 50%),linear-gradient(135deg,var(--muted) 50%,transparent 50%);
  background-position:calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size:5px 5px, 5px 5px;
  background-repeat:no-repeat;
}

/* ─── preview stage ───────────────────────────────────────────── */
.stage{
  flex:1 0 27dvh; min-height:120px;
  display:grid; place-items:center;
  background:var(--ink-950);
  padding:12px;
  position:relative; overflow:hidden;
}
.canvas-wrap{ position:relative; max-width:100%; max-height:100%; }
#preview{
  display:block; max-width:100%; max-height:100%;
  background:#000; border-radius:10px; border:1px solid var(--line);
  touch-action:none;
}
#preview.dragging{ cursor:grabbing; }
#preview.picking{ cursor:crosshair; }

.empty{
  position:absolute; inset:0; background:var(--ink-950);
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:12px;
  text-align:center; padding:22px; color:var(--muted);
}
.empty h2{ margin:0; font-size:17px; color:var(--text); }
.empty p{ margin:0; max-width:40ch; font-size:13px; }
.tool-link{ color:var(--mint-500); text-underline-offset:.2em; }
.badge{
  position:absolute; top:8px; left:8px;
  background:rgba(16,17,19,.72); backdrop-filter:blur(6px);
  border:1px solid var(--line); border-radius:6px;
  padding:3px 7px; font-size:10px; font-weight:600; color:var(--muted);
  pointer-events:none;
}
.pickhint{
  position:absolute; left:50%; bottom:10px; transform:translateX(-50%);
  background:rgba(16,17,19,.85); border:1px solid var(--mint-600); border-radius:8px;
  padding:6px 10px; font-size:12px; color:var(--mint-500); white-space:nowrap; pointer-events:none;
}
.notice{
  position:absolute; top:10px; left:50%; transform:translateX(-50%);
  display:flex; align-items:center; gap:10px; flex-wrap:wrap; justify-content:center;
  max-width:calc(100% - 24px);
  background:var(--ink-800); border:1px solid var(--line); border-left:3px solid var(--warn);
  border-radius:9px; padding:8px 10px; font-size:12px; color:var(--text); z-index:5;
}

/* ─── transport ───────────────────────────────────────────────── */
.transport{
  flex:0 0 auto; display:flex; align-items:center; gap:10px;
  padding:7px 12px; background:var(--ink-900); border-top:1px solid var(--line);
}
.playbtn{
  width:38px; height:38px; flex:0 0 auto; border-radius:50%;
  background:var(--mint-600); color:#04201a; display:grid; place-items:center;
}
.playbtn:active{ background:var(--mint-500); }
.playbtn svg{ width:16px; height:16px; }
.time{ font-variant-numeric:tabular-nums; font-size:12px; color:var(--muted); flex:0 0 auto; min-width:82px; }
.scrub{ -webkit-appearance:none; appearance:none; flex:1; height:26px; background:none; touch-action:none; min-width:0; }
.scrub::-webkit-slider-runnable-track{ height:4px; border-radius:2px; background:var(--ink-700); }
.scrub::-webkit-slider-thumb{ -webkit-appearance:none; width:15px; height:15px; border-radius:50%; background:var(--text); margin-top:-5.5px; border:0; }
.scrub::-moz-range-track{ height:4px; border-radius:2px; background:var(--ink-700); }
.scrub::-moz-range-thumb{ width:15px; height:15px; border:0; border-radius:50%; background:var(--text); }

/* ─── toolbar ─────────────────────────────────────────────────── */
.toolbar{
  flex:0 0 auto; display:flex; gap:4px; align-items:stretch;
  padding:7px 9px; background:var(--ink-900); border-top:1px solid var(--line);
  overflow-x:auto; scrollbar-width:none;
}
.toolbar::-webkit-scrollbar{ display:none; }
.tool{
  flex:0 0 auto;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
  padding:6px 8px; border-radius:9px;
  background:var(--ink-800); border:1px solid var(--line);
  font-size:9.5px; font-weight:600; color:var(--muted);
  min-width:50px; white-space:nowrap;
}
.tool svg{ width:17px; height:17px; }
.tool:hover:not(:disabled){ color:var(--text); }
.tool:active{ background:var(--ink-700); }
.tool[data-accent]{ color:var(--mint-500); }
.tool:disabled{ opacity:.3; cursor:default; }
.tool.mini{ min-width:38px; padding:6px; }
.tb-gap{ flex:1 0 8px; }

/* ─── timeline ────────────────────────────────────────────────── */
.timeline{
  flex:0 1 auto; min-height:92px; background:var(--ink-900); border-top:1px solid var(--line);
  overflow-x:auto; overflow-y:auto; max-height:30dvh;
  scrollbar-width:thin; scrollbar-color:var(--ink-700) transparent;
  -webkit-overflow-scrolling:touch;
  position:relative;
}
.tl-inner{ position:relative; min-width:100%; padding:0 0 10px; user-select:none; -webkit-user-select:none; }
.ruler{
  position:sticky; top:0; z-index:6;
  height:22px; background:var(--ink-900); border-bottom:1px solid var(--line);
  touch-action:none; cursor:ew-resize;
}
.ruler .tick{
  position:absolute; top:0; bottom:0; border-left:1px solid var(--ink-700);
  padding-left:4px; font-size:9.5px; line-height:20px; color:var(--muted-dim);
  font-variant-numeric:tabular-nums; pointer-events:none; white-space:nowrap;
}
.lane{ position:relative; margin-top:5px; }
.lane-video{ height:54px; }
.lane:empty{ display:none; }
.lane-video:empty{ display:block; }
.lane-over{ margin-top:4px; }
.clip.over{ height:42px; }
.spare{
  position:absolute; left:12px; width:calc(100% - 24px); max-width:420px; height:14px;
  border:1px dashed var(--ink-700); border-radius:5px;
  font-size:9px; line-height:12px; font-weight:600; color:var(--muted-dim); padding-left:6px;
  cursor:pointer; white-space:nowrap; overflow:hidden;
}
.spare:hover{ color:var(--mint-500); border-color:var(--mint-600); }
.tl-empty{ position:absolute; left:12px; top:16px; color:var(--muted-dim); font-size:12px; white-space:nowrap; }

.clip{
  position:absolute; top:0; height:54px;
  border-radius:7px; overflow:hidden;
  background:var(--ink-800) left center / auto 100% repeat-x;
  border:1px solid var(--line);
  display:flex; align-items:flex-end;
  cursor:grab;
}
.clip::before{ content:""; position:absolute; inset:0; background:rgba(16,17,19,.42); }
.clip .lbl{
  position:relative; z-index:1; width:100%; padding:2px 6px;
  font-size:9.5px; font-weight:600;
  background:linear-gradient(transparent,rgba(16,17,19,.9));
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.clip .tags{ position:absolute; top:3px; left:4px; right:4px; z-index:1; display:flex; gap:3px; overflow:hidden; pointer-events:none; }
.tag{
  font-size:8.5px; font-weight:700; line-height:13px; padding:0 4px; border-radius:4px;
  background:rgba(16,17,19,.78); color:var(--mint-500); white-space:nowrap;
}
.tag.warn{ color:var(--warn); }
[data-selected="true"].clip{ border-color:var(--mint-500); box-shadow:0 0 0 1px var(--mint-500); z-index:2; }
.clip[data-offline="true"]{ background-image:repeating-linear-gradient(45deg,#2a1d1d 0 8px,#221a1a 8px 16px); }
.clip.dragging{ opacity:.92; border-color:var(--mint-500); box-shadow:0 8px 22px rgba(0,0,0,.55); z-index:4; cursor:grabbing; }

.aclip{
  position:absolute; height:30px; border-radius:6px; overflow:hidden;
  background:var(--blue-dim); border:1px solid #2c4672; cursor:grab;
}
.aclip canvas{ position:absolute; inset:0; width:100%; height:100%; opacity:.85; }
.aclip .lbl{
  position:absolute; left:6px; top:2px; right:6px; font-size:9px; font-weight:600; color:#cfe0ff;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; text-shadow:0 1px 2px rgba(0,0,0,.8); pointer-events:none;
}
.aclip[data-selected="true"]{ border-color:var(--blue-500); box-shadow:0 0 0 1px var(--blue-500); z-index:2; }
.aclip[data-clipped="true"]{ opacity:.55; }
.aclip.dragging{ box-shadow:0 8px 22px rgba(0,0,0,.55); z-index:4; cursor:grabbing; }

.tblock{
  position:absolute; height:20px; border-radius:5px;
  background:var(--mint-dim); border:1px solid var(--mint-600);
  font-size:9px; font-weight:600; color:var(--mint-500);
  padding:0 7px; line-height:18px; cursor:grab;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.tblock[data-selected="true"]{ background:var(--mint-600); color:#04201a; z-index:2; }

.hdl{
  position:absolute; top:0; bottom:0; width:14px; z-index:3;
  touch-action:none; cursor:ew-resize; display:none;
}
.hdl::after{ content:""; position:absolute; top:22%; bottom:22%; width:4px; border-radius:2px; background:#fff; opacity:.9; }
.hdl.l{ left:0; } .hdl.l::after{ left:3px; }
.hdl.r{ right:0; } .hdl.r::after{ right:3px; }
[data-selected="true"] > .hdl{ display:block; }
@media (pointer:coarse){ .hdl{ width:22px; } }

.playhead{
  position:absolute; top:0; bottom:0; width:2px; z-index:7;
  background:var(--warn); pointer-events:none; border-radius:1px;
}
.playhead::before{
  content:""; position:absolute; top:0; left:-5px;
  border-left:6px solid transparent; border-right:6px solid transparent; border-top:8px solid var(--warn);
}
.dropline{ position:absolute; height:54px; width:3px; background:var(--mint-500); border-radius:2px; pointer-events:none; z-index:5; }

/* ─── inspector ───────────────────────────────────────────────── */
.inspector{
  flex:0 1 auto; min-height:44px; max-height:33dvh; overflow-y:auto;
  background:var(--ink-850); border-top:1px solid var(--line);
  padding:0 12px 16px;
  scrollbar-width:thin; scrollbar-color:var(--ink-700) transparent;
}
.inspector[data-collapsed="true"] > :not(.insp-head){ display:none; }
.inspector[data-collapsed="true"]{ padding-bottom:0; }
.insp-head{
  position:sticky; top:0; z-index:3; background:var(--ink-850);
  display:flex; align-items:center; gap:8px; padding:10px 0 8px;
}
.insp-head h3{ margin:0; font-size:12px; font-weight:700; letter-spacing:.02em; text-transform:uppercase; color:var(--muted); flex:0 0 auto; }
.insp-head .name{ flex:1; min-width:0; font-size:11px; color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.collapse{ width:30px; height:26px; border-radius:7px; color:var(--muted); display:grid; place-items:center; flex:0 0 auto; }
.collapse svg{ width:14px; height:14px; transition:transform .15s; }
.inspector[data-collapsed="true"] .collapse svg{ transform:rotate(180deg); }
.tabs{ display:flex; gap:0; border:1px solid var(--line); border-radius:9px; overflow:hidden; margin-bottom:12px; }
.tabs button{ flex:1; padding:8px 4px; font-size:12px; font-weight:600; background:var(--ink-900); color:var(--muted); position:relative; }
.tabs button[data-on="true"]{ background:var(--mint-dim); color:var(--mint-500); }
.tabs button .dot{ position:absolute; top:5px; right:6px; width:5px; height:5px; border-radius:50%; background:var(--mint-500); }
.row{ display:flex; align-items:center; gap:8px; margin-bottom:8px; min-height:30px; }
.row > label{ font-size:11.5px; color:var(--muted); flex:0 0 82px; }
.row .val{ font-size:11px; color:var(--muted); font-variant-numeric:tabular-nums; flex:0 0 46px; text-align:right; }
.grow{ flex:1; min-width:0; }
.row .io{ flex:1; min-width:0; font-size:11px; color:var(--muted); font-variant-numeric:tabular-nums; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.group{ margin:14px 0 8px; font-size:10.5px; font-weight:700; letter-spacing:.06em; text-transform:uppercase; color:var(--muted-dim); }

.field{ width:100%; background:var(--ink-900); border:1px solid var(--line); border-radius:8px; padding:7px 10px; font-size:14px; }
select.field{ padding-right:6px; }
textarea.field{ resize:vertical; min-height:56px; line-height:1.35; }
input[type=range]{ -webkit-appearance:none; appearance:none; width:100%; height:24px; background:none; touch-action:none; }
input[type=range]::-webkit-slider-runnable-track{ height:3px; border-radius:2px; background:var(--ink-700); }
input[type=range]::-webkit-slider-thumb{ -webkit-appearance:none; width:16px; height:16px; border-radius:50%; background:var(--mint-500); margin-top:-6.5px; border:0; }
input[type=range]::-moz-range-track{ height:3px; border-radius:2px; background:var(--ink-700); }
input[type=range]::-moz-range-thumb{ width:16px; height:16px; border:0; border-radius:50%; background:var(--mint-500); }
input[type=range]:disabled{ opacity:.35; }
input[type=color]{ -webkit-appearance:none; appearance:none; width:38px; height:32px; padding:0; background:none; border:1px solid var(--line); border-radius:8px; flex:0 0 auto; }
input[type=color]::-webkit-color-swatch-wrapper{ padding:3px; }
input[type=color]::-webkit-color-swatch{ border:0; border-radius:5px; }

.seg{ display:flex; gap:0; border:1px solid var(--line); border-radius:8px; overflow:hidden; }
.seg button{ flex:1; padding:7px 8px; font-size:12px; font-weight:600; background:var(--ink-900); color:var(--muted); white-space:nowrap; }
.seg button[data-on="true"]{ background:var(--mint-dim); color:var(--mint-500); }

.trim{ position:relative; height:44px; background:var(--ink-900); border:1px solid var(--line); border-radius:8px; overflow:hidden; touch-action:none; margin-bottom:8px; }
.trim .keep{ position:absolute; top:0; bottom:0; background:var(--mint-dim); border-left:2px solid var(--mint-500); border-right:2px solid var(--mint-500); }
.trim .handle{ position:absolute; top:0; bottom:0; width:26px; display:grid; place-items:center; touch-action:none; cursor:ew-resize; }
.trim .handle::after{ content:""; width:4px; height:20px; border-radius:2px; background:var(--mint-500); }
.trim .hint{ position:absolute; inset:0; display:grid; place-items:center; font-size:10px; color:var(--muted-dim); pointer-events:none; }

.hint-text{ font-size:11.5px; color:var(--muted-dim); margin:4px 0 8px; }
.hint-text b{ color:var(--muted); font-weight:600; }
.btnrow{ display:flex; gap:6px; flex-wrap:wrap; margin:4px 0 8px; }
.btnrow .btn{ flex:1 0 auto; }
kbd{ font:inherit; font-size:10.5px; background:var(--ink-800); border:1px solid var(--line); border-radius:4px; padding:0 4px; color:var(--muted); }

/* ─── sheets ──────────────────────────────────────────────────── */
.overlay{
  position:fixed; inset:0; z-index:50;
  background:rgba(16,17,19,.9); backdrop-filter:blur(4px);
  display:flex; align-items:center; justify-content:center; padding:20px;
}
.sheet{
  width:100%; max-width:440px;
  background:var(--ink-900); border:1px solid var(--line); border-radius:14px;
  padding:18px; max-height:88dvh; overflow-y:auto;
}
.sheet h2{ margin:0 0 4px; font-size:16px; }
.sheet p{ margin:0 0 14px; font-size:12px; color:var(--muted); }
.sheet p.sheet-tool-link{ margin:12px 0 0; font-size:13px; }
.bar{ height:6px; border-radius:3px; background:var(--ink-700); overflow:hidden; margin:14px 0 8px; }
.bar span{ display:block; height:100%; width:0%; background:var(--mint-500); transition:width .2s; }
.sheet video, .sheet audio{ width:100%; border-radius:9px; background:#000; margin-bottom:12px; }
.warnbox{
  background:var(--ink-800); border:1px solid var(--line); border-left:3px solid var(--warn);
  border-radius:7px; padding:9px 11px; font-size:11.5px; color:var(--muted); margin-bottom:12px;
}
.warnbox.ok{ border-left-color:var(--mint-500); }
.plist{ display:flex; flex-direction:column; gap:6px; margin:10px 0 14px; }
.pitem{
  display:flex; align-items:center; gap:10px; padding:8px; border-radius:10px;
  background:var(--ink-850); border:1px solid var(--line);
}
.pitem[data-current="true"]{ border-color:var(--mint-600); }
.pitem .thumb{ width:64px; height:40px; border-radius:6px; background:#000 center/cover no-repeat; flex:0 0 auto; }
.pitem .meta{ flex:1; min-width:0; cursor:pointer; }
.pitem .meta b{ display:block; font-size:13px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.pitem .meta span{ font-size:11px; color:var(--muted); }
.iconbtn{ width:32px; height:32px; border-radius:8px; display:grid; place-items:center; color:var(--muted); flex:0 0 auto; }
.iconbtn:hover{ background:var(--ink-800); color:var(--text); }
.iconbtn svg{ width:16px; height:16px; }
.meter{ height:5px; border-radius:3px; background:var(--ink-700); overflow:hidden; margin:6px 0 4px; }
.meter span{ display:block; height:100%; background:var(--mint-600); }

.toast{
  position:fixed; left:50%; bottom:calc(24px + env(safe-area-inset-bottom)); transform:translateX(-50%);
  background:var(--ink-800); border:1px solid var(--line); color:var(--text);
  padding:9px 14px; border-radius:9px; font-size:12.5px; z-index:99; pointer-events:none;
  opacity:0; transition:opacity .18s; max-width:82vw; text-align:center;
}

/* ─── desktop: preview and timeline on the left, inspector down the right ─── */
@media (min-width:1000px){
  #app{
    display:grid;
    grid-template-columns:minmax(0,1fr) 372px;
    grid-template-rows:auto minmax(0,1fr) auto auto auto;
  }
  .topbar{ grid-column:1 / 3; padding:9px 16px; }
  .stage{ grid-column:1; grid-row:2; padding:20px; min-height:0; }
  .transport{ grid-column:1; grid-row:3; }
  .toolbar{ grid-column:1; grid-row:4; }
  .timeline{ grid-column:1; grid-row:5; max-height:38vh; min-height:128px; }
  .inspector{
    grid-column:2; grid-row:2 / 6; max-height:none;
    border-top:0; border-left:1px solid var(--line); padding:4px 16px 24px;
  }
  .inspector[data-collapsed="true"] > :not(.insp-head){ display:revert; }
  .collapse{ display:none; }
  .lane-video{ height:64px; }
  .clip{ height:64px; }
  .clip.over{ height:48px; }
  .dropline{ height:64px; }
  .aclip{ height:34px; }
  .tool{ flex-direction:row; gap:6px; font-size:11.5px; padding:7px 10px; min-width:0; }
  .tool svg{ width:15px; height:15px; }
  .projbtn #projName{ max-width:320px; }
  .sheet{ max-width:480px; }
}
@media (max-width:420px){
  .brand-name{ display:none; }
  .row > label{ flex-basis:70px; }
}
